Multi-target: NEWS and user manual
[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. For example, here is the
2045 help display for the class @code{status}:
2046
2047 @smallexample
2048 (@value{GDBP}) help status
2049 Status inquiries.
2050
2051 List of commands:
2052
2053 @c Line break in "show" line falsifies real output, but needed
2054 @c to fit in smallbook page size.
2055 info -- Generic command for showing things
2056 about the program being debugged
2057 show -- Generic command for showing things
2058 about the debugger
2059
2060 Type "help" followed by command name for full
2061 documentation.
2062 Command name abbreviations are allowed if unambiguous.
2063 (@value{GDBP})
2064 @end smallexample
2065
2066 @item help @var{command}
2067 With a command name as @code{help} argument, @value{GDBN} displays a
2068 short paragraph on how to use that command.
2069
2070 @kindex apropos
2071 @item apropos [-v] @var{regexp}
2072 The @code{apropos} command searches through all of the @value{GDBN}
2073 commands, and their documentation, for the regular expression specified in
2074 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2075 which stands for @samp{verbose}, indicates to output the full documentation
2076 of the matching commands and highlight the parts of the documentation
2077 matching @var{regexp}. For example:
2078
2079 @smallexample
2080 apropos alias
2081 @end smallexample
2082
2083 @noindent
2084 results in:
2085
2086 @smallexample
2087 @group
2088 alias -- Define a new command that is an alias of an existing command
2089 aliases -- Aliases of other commands
2090 d -- Delete some breakpoints or auto-display expressions
2091 del -- Delete some breakpoints or auto-display expressions
2092 delete -- Delete some breakpoints or auto-display expressions
2093 @end group
2094 @end smallexample
2095
2096 @noindent
2097 while
2098
2099 @smallexample
2100 apropos -v cut.*thread apply
2101 @end smallexample
2102
2103 @noindent
2104 results in the below output, where @samp{cut for 'thread apply}
2105 is highlighted if styling is enabled.
2106
2107 @smallexample
2108 @group
2109 taas -- Apply a command to all threads (ignoring errors
2110 and empty output).
2111 Usage: taas COMMAND
2112 shortcut for 'thread apply all -s COMMAND'
2113
2114 tfaas -- Apply a command to all frames of all threads
2115 (ignoring errors and empty output).
2116 Usage: tfaas COMMAND
2117 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2118 @end group
2119 @end smallexample
2120
2121 @kindex complete
2122 @item complete @var{args}
2123 The @code{complete @var{args}} command lists all the possible completions
2124 for the beginning of a command. Use @var{args} to specify the beginning of the
2125 command you want completed. For example:
2126
2127 @smallexample
2128 complete i
2129 @end smallexample
2130
2131 @noindent results in:
2132
2133 @smallexample
2134 @group
2135 if
2136 ignore
2137 info
2138 inspect
2139 @end group
2140 @end smallexample
2141
2142 @noindent This is intended for use by @sc{gnu} Emacs.
2143 @end table
2144
2145 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2146 and @code{show} to inquire about the state of your program, or the state
2147 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2148 manual introduces each of them in the appropriate context. The listings
2149 under @code{info} and under @code{show} in the Command, Variable, and
2150 Function Index point to all the sub-commands. @xref{Command and Variable
2151 Index}.
2152
2153 @c @group
2154 @table @code
2155 @kindex info
2156 @kindex i @r{(@code{info})}
2157 @item info
2158 This command (abbreviated @code{i}) is for describing the state of your
2159 program. For example, you can show the arguments passed to a function
2160 with @code{info args}, list the registers currently in use with @code{info
2161 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2162 You can get a complete list of the @code{info} sub-commands with
2163 @w{@code{help info}}.
2164
2165 @kindex set
2166 @item set
2167 You can assign the result of an expression to an environment variable with
2168 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2169 @code{set prompt $}.
2170
2171 @kindex show
2172 @item show
2173 In contrast to @code{info}, @code{show} is for describing the state of
2174 @value{GDBN} itself.
2175 You can change most of the things you can @code{show}, by using the
2176 related command @code{set}; for example, you can control what number
2177 system is used for displays with @code{set radix}, or simply inquire
2178 which is currently in use with @code{show radix}.
2179
2180 @kindex info set
2181 To display all the settable parameters and their current
2182 values, you can use @code{show} with no arguments; you may also use
2183 @code{info set}. Both commands produce the same display.
2184 @c FIXME: "info set" violates the rule that "info" is for state of
2185 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2186 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2187 @end table
2188 @c @end group
2189
2190 Here are several miscellaneous @code{show} subcommands, all of which are
2191 exceptional in lacking corresponding @code{set} commands:
2192
2193 @table @code
2194 @kindex show version
2195 @cindex @value{GDBN} version number
2196 @item show version
2197 Show what version of @value{GDBN} is running. You should include this
2198 information in @value{GDBN} bug-reports. If multiple versions of
2199 @value{GDBN} are in use at your site, you may need to determine which
2200 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2201 commands are introduced, and old ones may wither away. Also, many
2202 system vendors ship variant versions of @value{GDBN}, and there are
2203 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2204 The version number is the same as the one announced when you start
2205 @value{GDBN}.
2206
2207 @kindex show copying
2208 @kindex info copying
2209 @cindex display @value{GDBN} copyright
2210 @item show copying
2211 @itemx info copying
2212 Display information about permission for copying @value{GDBN}.
2213
2214 @kindex show warranty
2215 @kindex info warranty
2216 @item show warranty
2217 @itemx info warranty
2218 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2219 if your version of @value{GDBN} comes with one.
2220
2221 @kindex show configuration
2222 @item show configuration
2223 Display detailed information about the way @value{GDBN} was configured
2224 when it was built. This displays the optional arguments passed to the
2225 @file{configure} script and also configuration parameters detected
2226 automatically by @command{configure}. When reporting a @value{GDBN}
2227 bug (@pxref{GDB Bugs}), it is important to include this information in
2228 your report.
2229
2230 @end table
2231
2232 @node Running
2233 @chapter Running Programs Under @value{GDBN}
2234
2235 When you run a program under @value{GDBN}, you must first generate
2236 debugging information when you compile it.
2237
2238 You may start @value{GDBN} with its arguments, if any, in an environment
2239 of your choice. If you are doing native debugging, you may redirect
2240 your program's input and output, debug an already running process, or
2241 kill a child process.
2242
2243 @menu
2244 * Compilation:: Compiling for debugging
2245 * Starting:: Starting your program
2246 * Arguments:: Your program's arguments
2247 * Environment:: Your program's environment
2248
2249 * Working Directory:: Your program's working directory
2250 * Input/Output:: Your program's input and output
2251 * Attach:: Debugging an already-running process
2252 * Kill Process:: Killing the child process
2253 * Inferiors Connections and Programs:: Debugging multiple inferiors
2254 connections and programs
2255 * Threads:: Debugging programs with multiple threads
2256 * Forks:: Debugging forks
2257 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2258 @end menu
2259
2260 @node Compilation
2261 @section Compiling for Debugging
2262
2263 In order to debug a program effectively, you need to generate
2264 debugging information when you compile it. This debugging information
2265 is stored in the object file; it describes the data type of each
2266 variable or function and the correspondence between source line numbers
2267 and addresses in the executable code.
2268
2269 To request debugging information, specify the @samp{-g} option when you run
2270 the compiler.
2271
2272 Programs that are to be shipped to your customers are compiled with
2273 optimizations, using the @samp{-O} compiler option. However, some
2274 compilers are unable to handle the @samp{-g} and @samp{-O} options
2275 together. Using those compilers, you cannot generate optimized
2276 executables containing debugging information.
2277
2278 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2279 without @samp{-O}, making it possible to debug optimized code. We
2280 recommend that you @emph{always} use @samp{-g} whenever you compile a
2281 program. You may think your program is correct, but there is no sense
2282 in pushing your luck. For more information, see @ref{Optimized Code}.
2283
2284 Older versions of the @sc{gnu} C compiler permitted a variant option
2285 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2286 format; if your @sc{gnu} C compiler has this option, do not use it.
2287
2288 @value{GDBN} knows about preprocessor macros and can show you their
2289 expansion (@pxref{Macros}). Most compilers do not include information
2290 about preprocessor macros in the debugging information if you specify
2291 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2292 the @sc{gnu} C compiler, provides macro information if you are using
2293 the DWARF debugging format, and specify the option @option{-g3}.
2294
2295 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2296 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2297 information on @value{NGCC} options affecting debug information.
2298
2299 You will have the best debugging experience if you use the latest
2300 version of the DWARF debugging format that your compiler supports.
2301 DWARF is currently the most expressive and best supported debugging
2302 format in @value{GDBN}.
2303
2304 @need 2000
2305 @node Starting
2306 @section Starting your Program
2307 @cindex starting
2308 @cindex running
2309
2310 @table @code
2311 @kindex run
2312 @kindex r @r{(@code{run})}
2313 @item run
2314 @itemx r
2315 Use the @code{run} command to start your program under @value{GDBN}.
2316 You must first specify the program name with an argument to
2317 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2318 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2319 command (@pxref{Files, ,Commands to Specify Files}).
2320
2321 @end table
2322
2323 If you are running your program in an execution environment that
2324 supports processes, @code{run} creates an inferior process and makes
2325 that process run your program. In some environments without processes,
2326 @code{run} jumps to the start of your program. Other targets,
2327 like @samp{remote}, are always running. If you get an error
2328 message like this one:
2329
2330 @smallexample
2331 The "remote" target does not support "run".
2332 Try "help target" or "continue".
2333 @end smallexample
2334
2335 @noindent
2336 then use @code{continue} to run your program. You may need @code{load}
2337 first (@pxref{load}).
2338
2339 The execution of a program is affected by certain information it
2340 receives from its superior. @value{GDBN} provides ways to specify this
2341 information, which you must do @emph{before} starting your program. (You
2342 can change it after starting your program, but such changes only affect
2343 your program the next time you start it.) This information may be
2344 divided into four categories:
2345
2346 @table @asis
2347 @item The @emph{arguments.}
2348 Specify the arguments to give your program as the arguments of the
2349 @code{run} command. If a shell is available on your target, the shell
2350 is used to pass the arguments, so that you may use normal conventions
2351 (such as wildcard expansion or variable substitution) in describing
2352 the arguments.
2353 In Unix systems, you can control which shell is used with the
2354 @code{SHELL} environment variable. If you do not define @code{SHELL},
2355 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2356 use of any shell with the @code{set startup-with-shell} command (see
2357 below for details).
2358
2359 @item The @emph{environment.}
2360 Your program normally inherits its environment from @value{GDBN}, but you can
2361 use the @value{GDBN} commands @code{set environment} and @code{unset
2362 environment} to change parts of the environment that affect
2363 your program. @xref{Environment, ,Your Program's Environment}.
2364
2365 @item The @emph{working directory.}
2366 You can set your program's working directory with the command
2367 @kbd{set cwd}. If you do not set any working directory with this
2368 command, your program will inherit @value{GDBN}'s working directory if
2369 native debugging, or the remote server's working directory if remote
2370 debugging. @xref{Working Directory, ,Your Program's Working
2371 Directory}.
2372
2373 @item The @emph{standard input and output.}
2374 Your program normally uses the same device for standard input and
2375 standard output as @value{GDBN} is using. You can redirect input and output
2376 in the @code{run} command line, or you can use the @code{tty} command to
2377 set a different device for your program.
2378 @xref{Input/Output, ,Your Program's Input and Output}.
2379
2380 @cindex pipes
2381 @emph{Warning:} While input and output redirection work, you cannot use
2382 pipes to pass the output of the program you are debugging to another
2383 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2384 wrong program.
2385 @end table
2386
2387 When you issue the @code{run} command, your program begins to execute
2388 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2389 of how to arrange for your program to stop. Once your program has
2390 stopped, you may call functions in your program, using the @code{print}
2391 or @code{call} commands. @xref{Data, ,Examining Data}.
2392
2393 If the modification time of your symbol file has changed since the last
2394 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2395 table, and reads it again. When it does this, @value{GDBN} tries to retain
2396 your current breakpoints.
2397
2398 @table @code
2399 @kindex start
2400 @item start
2401 @cindex run to main procedure
2402 The name of the main procedure can vary from language to language.
2403 With C or C@t{++}, the main procedure name is always @code{main}, but
2404 other languages such as Ada do not require a specific name for their
2405 main procedure. The debugger provides a convenient way to start the
2406 execution of the program and to stop at the beginning of the main
2407 procedure, depending on the language used.
2408
2409 The @samp{start} command does the equivalent of setting a temporary
2410 breakpoint at the beginning of the main procedure and then invoking
2411 the @samp{run} command.
2412
2413 @cindex elaboration phase
2414 Some programs contain an @dfn{elaboration} phase where some startup code is
2415 executed before the main procedure is called. This depends on the
2416 languages used to write your program. In C@t{++}, for instance,
2417 constructors for static and global objects are executed before
2418 @code{main} is called. It is therefore possible that the debugger stops
2419 before reaching the main procedure. However, the temporary breakpoint
2420 will remain to halt execution.
2421
2422 Specify the arguments to give to your program as arguments to the
2423 @samp{start} command. These arguments will be given verbatim to the
2424 underlying @samp{run} command. Note that the same arguments will be
2425 reused if no argument is provided during subsequent calls to
2426 @samp{start} or @samp{run}.
2427
2428 It is sometimes necessary to debug the program during elaboration. In
2429 these cases, using the @code{start} command would stop the execution
2430 of your program too late, as the program would have already completed
2431 the elaboration phase. Under these circumstances, either insert
2432 breakpoints in your elaboration code before running your program or
2433 use the @code{starti} command.
2434
2435 @kindex starti
2436 @item starti
2437 @cindex run to first instruction
2438 The @samp{starti} command does the equivalent of setting a temporary
2439 breakpoint at the first instruction of a program's execution and then
2440 invoking the @samp{run} command. For programs containing an
2441 elaboration phase, the @code{starti} command will stop execution at
2442 the start of the elaboration phase.
2443
2444 @anchor{set exec-wrapper}
2445 @kindex set exec-wrapper
2446 @item set exec-wrapper @var{wrapper}
2447 @itemx show exec-wrapper
2448 @itemx unset exec-wrapper
2449 When @samp{exec-wrapper} is set, the specified wrapper is used to
2450 launch programs for debugging. @value{GDBN} starts your program
2451 with a shell command of the form @kbd{exec @var{wrapper}
2452 @var{program}}. Quoting is added to @var{program} and its
2453 arguments, but not to @var{wrapper}, so you should add quotes if
2454 appropriate for your shell. The wrapper runs until it executes
2455 your program, and then @value{GDBN} takes control.
2456
2457 You can use any program that eventually calls @code{execve} with
2458 its arguments as a wrapper. Several standard Unix utilities do
2459 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2460 with @code{exec "$@@"} will also work.
2461
2462 For example, you can use @code{env} to pass an environment variable to
2463 the debugged program, without setting the variable in your shell's
2464 environment:
2465
2466 @smallexample
2467 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2468 (@value{GDBP}) run
2469 @end smallexample
2470
2471 This command is available when debugging locally on most targets, excluding
2472 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2473
2474 @kindex set startup-with-shell
2475 @anchor{set startup-with-shell}
2476 @item set startup-with-shell
2477 @itemx set startup-with-shell on
2478 @itemx set startup-with-shell off
2479 @itemx show startup-with-shell
2480 On Unix systems, by default, if a shell is available on your target,
2481 @value{GDBN}) uses it to start your program. Arguments of the
2482 @code{run} command are passed to the shell, which does variable
2483 substitution, expands wildcard characters and performs redirection of
2484 I/O. In some circumstances, it may be useful to disable such use of a
2485 shell, for example, when debugging the shell itself or diagnosing
2486 startup failures such as:
2487
2488 @smallexample
2489 (@value{GDBP}) run
2490 Starting program: ./a.out
2491 During startup program terminated with signal SIGSEGV, Segmentation fault.
2492 @end smallexample
2493
2494 @noindent
2495 which indicates the shell or the wrapper specified with
2496 @samp{exec-wrapper} crashed, not your program. Most often, this is
2497 caused by something odd in your shell's non-interactive mode
2498 initialization file---such as @file{.cshrc} for C-shell,
2499 $@file{.zshenv} for the Z shell, or the file specified in the
2500 @samp{BASH_ENV} environment variable for BASH.
2501
2502 @anchor{set auto-connect-native-target}
2503 @kindex set auto-connect-native-target
2504 @item set auto-connect-native-target
2505 @itemx set auto-connect-native-target on
2506 @itemx set auto-connect-native-target off
2507 @itemx show auto-connect-native-target
2508
2509 By default, if the current inferior is not connected to any target yet
2510 (e.g., with @code{target remote}), the @code{run} command starts your
2511 program as a native process under @value{GDBN}, on your local machine.
2512 If you're sure you don't want to debug programs on your local machine,
2513 you can tell @value{GDBN} to not connect to the native target
2514 automatically with the @code{set auto-connect-native-target off}
2515 command.
2516
2517 If @code{on}, which is the default, and if the current inferior is not
2518 connected to a target already, the @code{run} command automaticaly
2519 connects to the native target, if one is available.
2520
2521 If @code{off}, and if the current inferior is not connected to a
2522 target already, the @code{run} command fails with an error:
2523
2524 @smallexample
2525 (@value{GDBP}) run
2526 Don't know how to run. Try "help target".
2527 @end smallexample
2528
2529 If the current inferior is already connected to a target, @value{GDBN}
2530 always uses it with the @code{run} command.
2531
2532 In any case, you can explicitly connect to the native target with the
2533 @code{target native} command. For example,
2534
2535 @smallexample
2536 (@value{GDBP}) set auto-connect-native-target off
2537 (@value{GDBP}) run
2538 Don't know how to run. Try "help target".
2539 (@value{GDBP}) target native
2540 (@value{GDBP}) run
2541 Starting program: ./a.out
2542 [Inferior 1 (process 10421) exited normally]
2543 @end smallexample
2544
2545 In case you connected explicitly to the @code{native} target,
2546 @value{GDBN} remains connected even if all inferiors exit, ready for
2547 the next @code{run} command. Use the @code{disconnect} command to
2548 disconnect.
2549
2550 Examples of other commands that likewise respect the
2551 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2552 proc}, @code{info os}.
2553
2554 @kindex set disable-randomization
2555 @item set disable-randomization
2556 @itemx set disable-randomization on
2557 This option (enabled by default in @value{GDBN}) will turn off the native
2558 randomization of the virtual address space of the started program. This option
2559 is useful for multiple debugging sessions to make the execution better
2560 reproducible and memory addresses reusable across debugging sessions.
2561
2562 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2563 On @sc{gnu}/Linux you can get the same behavior using
2564
2565 @smallexample
2566 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2567 @end smallexample
2568
2569 @item set disable-randomization off
2570 Leave the behavior of the started executable unchanged. Some bugs rear their
2571 ugly heads only when the program is loaded at certain addresses. If your bug
2572 disappears when you run the program under @value{GDBN}, that might be because
2573 @value{GDBN} by default disables the address randomization on platforms, such
2574 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2575 disable-randomization off} to try to reproduce such elusive bugs.
2576
2577 On targets where it is available, virtual address space randomization
2578 protects the programs against certain kinds of security attacks. In these
2579 cases the attacker needs to know the exact location of a concrete executable
2580 code. Randomizing its location makes it impossible to inject jumps misusing
2581 a code at its expected addresses.
2582
2583 Prelinking shared libraries provides a startup performance advantage but it
2584 makes addresses in these libraries predictable for privileged processes by
2585 having just unprivileged access at the target system. Reading the shared
2586 library binary gives enough information for assembling the malicious code
2587 misusing it. Still even a prelinked shared library can get loaded at a new
2588 random address just requiring the regular relocation process during the
2589 startup. Shared libraries not already prelinked are always loaded at
2590 a randomly chosen address.
2591
2592 Position independent executables (PIE) contain position independent code
2593 similar to the shared libraries and therefore such executables get loaded at
2594 a randomly chosen address upon startup. PIE executables always load even
2595 already prelinked shared libraries at a random address. You can build such
2596 executable using @command{gcc -fPIE -pie}.
2597
2598 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2599 (as long as the randomization is enabled).
2600
2601 @item show disable-randomization
2602 Show the current setting of the explicit disable of the native randomization of
2603 the virtual address space of the started program.
2604
2605 @end table
2606
2607 @node Arguments
2608 @section Your Program's Arguments
2609
2610 @cindex arguments (to your program)
2611 The arguments to your program can be specified by the arguments of the
2612 @code{run} command.
2613 They are passed to a shell, which expands wildcard characters and
2614 performs redirection of I/O, and thence to your program. Your
2615 @code{SHELL} environment variable (if it exists) specifies what shell
2616 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2617 the default shell (@file{/bin/sh} on Unix).
2618
2619 On non-Unix systems, the program is usually invoked directly by
2620 @value{GDBN}, which emulates I/O redirection via the appropriate system
2621 calls, and the wildcard characters are expanded by the startup code of
2622 the program, not by the shell.
2623
2624 @code{run} with no arguments uses the same arguments used by the previous
2625 @code{run}, or those set by the @code{set args} command.
2626
2627 @table @code
2628 @kindex set args
2629 @item set args
2630 Specify the arguments to be used the next time your program is run. If
2631 @code{set args} has no arguments, @code{run} executes your program
2632 with no arguments. Once you have run your program with arguments,
2633 using @code{set args} before the next @code{run} is the only way to run
2634 it again without arguments.
2635
2636 @kindex show args
2637 @item show args
2638 Show the arguments to give your program when it is started.
2639 @end table
2640
2641 @node Environment
2642 @section Your Program's Environment
2643
2644 @cindex environment (of your program)
2645 The @dfn{environment} consists of a set of environment variables and
2646 their values. Environment variables conventionally record such things as
2647 your user name, your home directory, your terminal type, and your search
2648 path for programs to run. Usually you set up environment variables with
2649 the shell and they are inherited by all the other programs you run. When
2650 debugging, it can be useful to try running your program with a modified
2651 environment without having to start @value{GDBN} over again.
2652
2653 @table @code
2654 @kindex path
2655 @item path @var{directory}
2656 Add @var{directory} to the front of the @code{PATH} environment variable
2657 (the search path for executables) that will be passed to your program.
2658 The value of @code{PATH} used by @value{GDBN} does not change.
2659 You may specify several directory names, separated by whitespace or by a
2660 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2661 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2662 is moved to the front, so it is searched sooner.
2663
2664 You can use the string @samp{$cwd} to refer to whatever is the current
2665 working directory at the time @value{GDBN} searches the path. If you
2666 use @samp{.} instead, it refers to the directory where you executed the
2667 @code{path} command. @value{GDBN} replaces @samp{.} in the
2668 @var{directory} argument (with the current path) before adding
2669 @var{directory} to the search path.
2670 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2671 @c document that, since repeating it would be a no-op.
2672
2673 @kindex show paths
2674 @item show paths
2675 Display the list of search paths for executables (the @code{PATH}
2676 environment variable).
2677
2678 @kindex show environment
2679 @item show environment @r{[}@var{varname}@r{]}
2680 Print the value of environment variable @var{varname} to be given to
2681 your program when it starts. If you do not supply @var{varname},
2682 print the names and values of all environment variables to be given to
2683 your program. You can abbreviate @code{environment} as @code{env}.
2684
2685 @kindex set environment
2686 @anchor{set environment}
2687 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2688 Set environment variable @var{varname} to @var{value}. The value
2689 changes for your program (and the shell @value{GDBN} uses to launch
2690 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2691 values of environment variables are just strings, and any
2692 interpretation is supplied by your program itself. The @var{value}
2693 parameter is optional; if it is eliminated, the variable is set to a
2694 null value.
2695 @c "any string" here does not include leading, trailing
2696 @c blanks. Gnu asks: does anyone care?
2697
2698 For example, this command:
2699
2700 @smallexample
2701 set env USER = foo
2702 @end smallexample
2703
2704 @noindent
2705 tells the debugged program, when subsequently run, that its user is named
2706 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2707 are not actually required.)
2708
2709 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2710 which also inherits the environment set with @code{set environment}.
2711 If necessary, you can avoid that by using the @samp{env} program as a
2712 wrapper instead of using @code{set environment}. @xref{set
2713 exec-wrapper}, for an example doing just that.
2714
2715 Environment variables that are set by the user are also transmitted to
2716 @command{gdbserver} to be used when starting the remote inferior.
2717 @pxref{QEnvironmentHexEncoded}.
2718
2719 @kindex unset environment
2720 @anchor{unset environment}
2721 @item unset environment @var{varname}
2722 Remove variable @var{varname} from the environment to be passed to your
2723 program. This is different from @samp{set env @var{varname} =};
2724 @code{unset environment} removes the variable from the environment,
2725 rather than assigning it an empty value.
2726
2727 Environment variables that are unset by the user are also unset on
2728 @command{gdbserver} when starting the remote inferior.
2729 @pxref{QEnvironmentUnset}.
2730 @end table
2731
2732 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2733 the shell indicated by your @code{SHELL} environment variable if it
2734 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2735 names a shell that runs an initialization file when started
2736 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2737 for the Z shell, or the file specified in the @samp{BASH_ENV}
2738 environment variable for BASH---any variables you set in that file
2739 affect your program. You may wish to move setting of environment
2740 variables to files that are only run when you sign on, such as
2741 @file{.login} or @file{.profile}.
2742
2743 @node Working Directory
2744 @section Your Program's Working Directory
2745
2746 @cindex working directory (of your program)
2747 Each time you start your program with @code{run}, the inferior will be
2748 initialized with the current working directory specified by the
2749 @kbd{set cwd} command. If no directory has been specified by this
2750 command, then the inferior will inherit @value{GDBN}'s current working
2751 directory as its working directory if native debugging, or it will
2752 inherit the remote server's current working directory if remote
2753 debugging.
2754
2755 @table @code
2756 @kindex set cwd
2757 @cindex change inferior's working directory
2758 @anchor{set cwd command}
2759 @item set cwd @r{[}@var{directory}@r{]}
2760 Set the inferior's working directory to @var{directory}, which will be
2761 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2762 argument has been specified, the command clears the setting and resets
2763 it to an empty state. This setting has no effect on @value{GDBN}'s
2764 working directory, and it only takes effect the next time you start
2765 the inferior. The @file{~} in @var{directory} is a short for the
2766 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2767 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2768 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2769 fallback.
2770
2771 You can also change @value{GDBN}'s current working directory by using
2772 the @code{cd} command.
2773 @xref{cd command}.
2774
2775 @kindex show cwd
2776 @cindex show inferior's working directory
2777 @item show cwd
2778 Show the inferior's working directory. If no directory has been
2779 specified by @kbd{set cwd}, then the default inferior's working
2780 directory is the same as @value{GDBN}'s working directory.
2781
2782 @kindex cd
2783 @cindex change @value{GDBN}'s working directory
2784 @anchor{cd command}
2785 @item cd @r{[}@var{directory}@r{]}
2786 Set the @value{GDBN} working directory to @var{directory}. If not
2787 given, @var{directory} uses @file{'~'}.
2788
2789 The @value{GDBN} working directory serves as a default for the
2790 commands that specify files for @value{GDBN} to operate on.
2791 @xref{Files, ,Commands to Specify Files}.
2792 @xref{set cwd command}.
2793
2794 @kindex pwd
2795 @item pwd
2796 Print the @value{GDBN} working directory.
2797 @end table
2798
2799 It is generally impossible to find the current working directory of
2800 the process being debugged (since a program can change its directory
2801 during its run). If you work on a system where @value{GDBN} supports
2802 the @code{info proc} command (@pxref{Process Information}), you can
2803 use the @code{info proc} command to find out the
2804 current working directory of the debuggee.
2805
2806 @node Input/Output
2807 @section Your Program's Input and Output
2808
2809 @cindex redirection
2810 @cindex i/o
2811 @cindex terminal
2812 By default, the program you run under @value{GDBN} does input and output to
2813 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2814 to its own terminal modes to interact with you, but it records the terminal
2815 modes your program was using and switches back to them when you continue
2816 running your program.
2817
2818 @table @code
2819 @kindex info terminal
2820 @item info terminal
2821 Displays information recorded by @value{GDBN} about the terminal modes your
2822 program is using.
2823 @end table
2824
2825 You can redirect your program's input and/or output using shell
2826 redirection with the @code{run} command. For example,
2827
2828 @smallexample
2829 run > outfile
2830 @end smallexample
2831
2832 @noindent
2833 starts your program, diverting its output to the file @file{outfile}.
2834
2835 @kindex tty
2836 @cindex controlling terminal
2837 Another way to specify where your program should do input and output is
2838 with the @code{tty} command. This command accepts a file name as
2839 argument, and causes this file to be the default for future @code{run}
2840 commands. It also resets the controlling terminal for the child
2841 process, for future @code{run} commands. For example,
2842
2843 @smallexample
2844 tty /dev/ttyb
2845 @end smallexample
2846
2847 @noindent
2848 directs that processes started with subsequent @code{run} commands
2849 default to do input and output on the terminal @file{/dev/ttyb} and have
2850 that as their controlling terminal.
2851
2852 An explicit redirection in @code{run} overrides the @code{tty} command's
2853 effect on the input/output device, but not its effect on the controlling
2854 terminal.
2855
2856 When you use the @code{tty} command or redirect input in the @code{run}
2857 command, only the input @emph{for your program} is affected. The input
2858 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2859 for @code{set inferior-tty}.
2860
2861 @cindex inferior tty
2862 @cindex set inferior controlling terminal
2863 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2864 display the name of the terminal that will be used for future runs of your
2865 program.
2866
2867 @table @code
2868 @item set inferior-tty [ @var{tty} ]
2869 @kindex set inferior-tty
2870 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2871 restores the default behavior, which is to use the same terminal as
2872 @value{GDBN}.
2873
2874 @item show inferior-tty
2875 @kindex show inferior-tty
2876 Show the current tty for the program being debugged.
2877 @end table
2878
2879 @node Attach
2880 @section Debugging an Already-running Process
2881 @kindex attach
2882 @cindex attach
2883
2884 @table @code
2885 @item attach @var{process-id}
2886 This command attaches to a running process---one that was started
2887 outside @value{GDBN}. (@code{info files} shows your active
2888 targets.) The command takes as argument a process ID. The usual way to
2889 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2890 or with the @samp{jobs -l} shell command.
2891
2892 @code{attach} does not repeat if you press @key{RET} a second time after
2893 executing the command.
2894 @end table
2895
2896 To use @code{attach}, your program must be running in an environment
2897 which supports processes; for example, @code{attach} does not work for
2898 programs on bare-board targets that lack an operating system. You must
2899 also have permission to send the process a signal.
2900
2901 When you use @code{attach}, the debugger finds the program running in
2902 the process first by looking in the current working directory, then (if
2903 the program is not found) by using the source file search path
2904 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2905 the @code{file} command to load the program. @xref{Files, ,Commands to
2906 Specify Files}.
2907
2908 The first thing @value{GDBN} does after arranging to debug the specified
2909 process is to stop it. You can examine and modify an attached process
2910 with all the @value{GDBN} commands that are ordinarily available when
2911 you start processes with @code{run}. You can insert breakpoints; you
2912 can step and continue; you can modify storage. If you would rather the
2913 process continue running, you may use the @code{continue} command after
2914 attaching @value{GDBN} to the process.
2915
2916 @table @code
2917 @kindex detach
2918 @item detach
2919 When you have finished debugging the attached process, you can use the
2920 @code{detach} command to release it from @value{GDBN} control. Detaching
2921 the process continues its execution. After the @code{detach} command,
2922 that process and @value{GDBN} become completely independent once more, and you
2923 are ready to @code{attach} another process or start one with @code{run}.
2924 @code{detach} does not repeat if you press @key{RET} again after
2925 executing the command.
2926 @end table
2927
2928 If you exit @value{GDBN} while you have an attached process, you detach
2929 that process. If you use the @code{run} command, you kill that process.
2930 By default, @value{GDBN} asks for confirmation if you try to do either of these
2931 things; you can control whether or not you need to confirm by using the
2932 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2933 Messages}).
2934
2935 @node Kill Process
2936 @section Killing the Child Process
2937
2938 @table @code
2939 @kindex kill
2940 @item kill
2941 Kill the child process in which your program is running under @value{GDBN}.
2942 @end table
2943
2944 This command is useful if you wish to debug a core dump instead of a
2945 running process. @value{GDBN} ignores any core dump file while your program
2946 is running.
2947
2948 On some operating systems, a program cannot be executed outside @value{GDBN}
2949 while you have breakpoints set on it inside @value{GDBN}. You can use the
2950 @code{kill} command in this situation to permit running your program
2951 outside the debugger.
2952
2953 The @code{kill} command is also useful if you wish to recompile and
2954 relink your program, since on many systems it is impossible to modify an
2955 executable file while it is running in a process. In this case, when you
2956 next type @code{run}, @value{GDBN} notices that the file has changed, and
2957 reads the symbol table again (while trying to preserve your current
2958 breakpoint settings).
2959
2960 @node Inferiors Connections and Programs
2961 @section Debugging Multiple Inferiors Connections and Programs
2962
2963 @value{GDBN} lets you run and debug multiple programs in a single
2964 session. In addition, @value{GDBN} on some systems may let you run
2965 several programs simultaneously (otherwise you have to exit from one
2966 before starting another). On some systems @value{GDBN} may even let
2967 you debug several programs simultaneously on different remote systems.
2968 In the most general case, you can have multiple threads of execution
2969 in each of multiple processes, launched from multiple executables,
2970 running on different machines.
2971
2972 @cindex inferior
2973 @value{GDBN} represents the state of each program execution with an
2974 object called an @dfn{inferior}. An inferior typically corresponds to
2975 a process, but is more general and applies also to targets that do not
2976 have processes. Inferiors may be created before a process runs, and
2977 may be retained after a process exits. Inferiors have unique
2978 identifiers that are different from process ids. Usually each
2979 inferior will also have its own distinct address space, although some
2980 embedded targets may have several inferiors running in different parts
2981 of a single address space. Each inferior may in turn have multiple
2982 threads running in it.
2983
2984 To find out what inferiors exist at any moment, use @w{@code{info
2985 inferiors}}:
2986
2987 @table @code
2988 @kindex info inferiors [ @var{id}@dots{} ]
2989 @item info inferiors
2990 Print a list of all inferiors currently being managed by @value{GDBN}.
2991 By default all inferiors are printed, but the argument @var{id}@dots{}
2992 -- a space separated list of inferior numbers -- can be used to limit
2993 the display to just the requested inferiors.
2994
2995 @value{GDBN} displays for each inferior (in this order):
2996
2997 @enumerate
2998 @item
2999 the inferior number assigned by @value{GDBN}
3000
3001 @item
3002 the target system's inferior identifier
3003
3004 @item
3005 the target connection the inferior is bound to, including the unique
3006 connection number assigned by @value{GDBN}, and the protocol used by
3007 the connection.
3008
3009 @item
3010 the name of the executable the inferior is running.
3011
3012 @end enumerate
3013
3014 @noindent
3015 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3016 indicates the current inferior.
3017
3018 For example,
3019 @end table
3020 @c end table here to get a little more width for example
3021
3022 @smallexample
3023 (@value{GDBP}) info inferiors
3024 Num Description Connection Executable
3025 * 1 process 3401 1 (native) goodbye
3026 2 process 2307 2 (extended-remote host:10000) hello
3027 @end smallexample
3028
3029 To find out what open target connections exist at any moment, use
3030 @w{@code{info connections}}:
3031
3032 @table @code
3033 @kindex info connections [ @var{id}@dots{} ]
3034 @item info connections
3035 Print a list of all open target connections currently being managed by
3036 @value{GDBN}. By default all connections are printed, but the
3037 argument @var{id}@dots{} -- a space separated list of connections
3038 numbers -- can be used to limit the display to just the requested
3039 connections.
3040
3041 @value{GDBN} displays for each connection (in this order):
3042
3043 @enumerate
3044 @item
3045 the connection number assigned by @value{GDBN}.
3046
3047 @item
3048 the protocol used by the connection.
3049
3050 @item
3051 a textual description of the protocol used by the connection.
3052
3053 @end enumerate
3054
3055 @noindent
3056 An asterisk @samp{*} preceding the connection number indicates the
3057 connection of the current inferior.
3058
3059 For example,
3060 @end table
3061 @c end table here to get a little more width for example
3062
3063 @smallexample
3064 (@value{GDBP}) info connections
3065 Num What Description
3066 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3067 2 native Native process
3068 3 core Local core dump file
3069 @end smallexample
3070
3071 To switch focus between inferiors, use the @code{inferior} command:
3072
3073 @table @code
3074 @kindex inferior @var{infno}
3075 @item inferior @var{infno}
3076 Make inferior number @var{infno} the current inferior. The argument
3077 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3078 in the first field of the @samp{info inferiors} display.
3079 @end table
3080
3081 @vindex $_inferior@r{, convenience variable}
3082 The debugger convenience variable @samp{$_inferior} contains the
3083 number of the current inferior. You may find this useful in writing
3084 breakpoint conditional expressions, command scripts, and so forth.
3085 @xref{Convenience Vars,, Convenience Variables}, for general
3086 information on convenience variables.
3087
3088 You can get multiple executables into a debugging session via the
3089 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3090 systems @value{GDBN} can add inferiors to the debug session
3091 automatically by following calls to @code{fork} and @code{exec}. To
3092 remove inferiors from the debugging session use the
3093 @w{@code{remove-inferiors}} command.
3094
3095 @table @code
3096 @kindex add-inferior
3097 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3098 Adds @var{n} inferiors to be run using @var{executable} as the
3099 executable; @var{n} defaults to 1. If no executable is specified,
3100 the inferiors begins empty, with no program. You can still assign or
3101 change the program assigned to the inferior at any time by using the
3102 @code{file} command with the executable name as its argument.
3103
3104 By default, the new inferior begins connected to the same target
3105 connection as the current inferior. For example, if the current
3106 inferior was connected to @code{gdbserver} with @code{target remote},
3107 then the new inferior will be connected to the same @code{gdbserver}
3108 instance. The @samp{-no-connection} option starts the new inferior
3109 with no connection yet. You can then for example use the @code{target
3110 remote} command to connect to some other @code{gdbserver} instance,
3111 use @code{run} to spawn a local program, etc.
3112
3113 @kindex clone-inferior
3114 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3115 Adds @var{n} inferiors ready to execute the same program as inferior
3116 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3117 number of the current inferior. This is a convenient command when you
3118 want to run another instance of the inferior you are debugging.
3119
3120 @smallexample
3121 (@value{GDBP}) info inferiors
3122 Num Description Connection Executable
3123 * 1 process 29964 1 (native) helloworld
3124 (@value{GDBP}) clone-inferior
3125 Added inferior 2.
3126 1 inferiors added.
3127 (@value{GDBP}) info inferiors
3128 Num Description Connection Executable
3129 * 1 process 29964 1 (native) helloworld
3130 2 <null> 1 (native) helloworld
3131 @end smallexample
3132
3133 You can now simply switch focus to inferior 2 and run it.
3134
3135 @kindex remove-inferiors
3136 @item remove-inferiors @var{infno}@dots{}
3137 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3138 possible to remove an inferior that is running with this command. For
3139 those, use the @code{kill} or @code{detach} command first.
3140
3141 @end table
3142
3143 To quit debugging one of the running inferiors that is not the current
3144 inferior, you can either detach from it by using the @w{@code{detach
3145 inferior}} command (allowing it to run independently), or kill it
3146 using the @w{@code{kill inferiors}} command:
3147
3148 @table @code
3149 @kindex detach inferiors @var{infno}@dots{}
3150 @item detach inferior @var{infno}@dots{}
3151 Detach from the inferior or inferiors identified by @value{GDBN}
3152 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3153 still stays on the list of inferiors shown by @code{info inferiors},
3154 but its Description will show @samp{<null>}.
3155
3156 @kindex kill inferiors @var{infno}@dots{}
3157 @item kill inferiors @var{infno}@dots{}
3158 Kill the inferior or inferiors identified by @value{GDBN} inferior
3159 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3160 stays on the list of inferiors shown by @code{info inferiors}, but its
3161 Description will show @samp{<null>}.
3162 @end table
3163
3164 After the successful completion of a command such as @code{detach},
3165 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3166 a normal process exit, the inferior is still valid and listed with
3167 @code{info inferiors}, ready to be restarted.
3168
3169
3170 To be notified when inferiors are started or exit under @value{GDBN}'s
3171 control use @w{@code{set print inferior-events}}:
3172
3173 @table @code
3174 @kindex set print inferior-events
3175 @cindex print messages on inferior start and exit
3176 @item set print inferior-events
3177 @itemx set print inferior-events on
3178 @itemx set print inferior-events off
3179 The @code{set print inferior-events} command allows you to enable or
3180 disable printing of messages when @value{GDBN} notices that new
3181 inferiors have started or that inferiors have exited or have been
3182 detached. By default, these messages will not be printed.
3183
3184 @kindex show print inferior-events
3185 @item show print inferior-events
3186 Show whether messages will be printed when @value{GDBN} detects that
3187 inferiors have started, exited or have been detached.
3188 @end table
3189
3190 Many commands will work the same with multiple programs as with a
3191 single program: e.g., @code{print myglobal} will simply display the
3192 value of @code{myglobal} in the current inferior.
3193
3194
3195 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3196 get more info about the relationship of inferiors, programs, address
3197 spaces in a debug session. You can do that with the @w{@code{maint
3198 info program-spaces}} command.
3199
3200 @table @code
3201 @kindex maint info program-spaces
3202 @item maint info program-spaces
3203 Print a list of all program spaces currently being managed by
3204 @value{GDBN}.
3205
3206 @value{GDBN} displays for each program space (in this order):
3207
3208 @enumerate
3209 @item
3210 the program space number assigned by @value{GDBN}
3211
3212 @item
3213 the name of the executable loaded into the program space, with e.g.,
3214 the @code{file} command.
3215
3216 @end enumerate
3217
3218 @noindent
3219 An asterisk @samp{*} preceding the @value{GDBN} program space number
3220 indicates the current program space.
3221
3222 In addition, below each program space line, @value{GDBN} prints extra
3223 information that isn't suitable to display in tabular form. For
3224 example, the list of inferiors bound to the program space.
3225
3226 @smallexample
3227 (@value{GDBP}) maint info program-spaces
3228 Id Executable
3229 * 1 hello
3230 2 goodbye
3231 Bound inferiors: ID 1 (process 21561)
3232 @end smallexample
3233
3234 Here we can see that no inferior is running the program @code{hello},
3235 while @code{process 21561} is running the program @code{goodbye}. On
3236 some targets, it is possible that multiple inferiors are bound to the
3237 same program space. The most common example is that of debugging both
3238 the parent and child processes of a @code{vfork} call. For example,
3239
3240 @smallexample
3241 (@value{GDBP}) maint info program-spaces
3242 Id Executable
3243 * 1 vfork-test
3244 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3245 @end smallexample
3246
3247 Here, both inferior 2 and inferior 1 are running in the same program
3248 space as a result of inferior 1 having executed a @code{vfork} call.
3249 @end table
3250
3251 @node Threads
3252 @section Debugging Programs with Multiple Threads
3253
3254 @cindex threads of execution
3255 @cindex multiple threads
3256 @cindex switching threads
3257 In some operating systems, such as GNU/Linux and Solaris, a single program
3258 may have more than one @dfn{thread} of execution. The precise semantics
3259 of threads differ from one operating system to another, but in general
3260 the threads of a single program are akin to multiple processes---except
3261 that they share one address space (that is, they can all examine and
3262 modify the same variables). On the other hand, each thread has its own
3263 registers and execution stack, and perhaps private memory.
3264
3265 @value{GDBN} provides these facilities for debugging multi-thread
3266 programs:
3267
3268 @itemize @bullet
3269 @item automatic notification of new threads
3270 @item @samp{thread @var{thread-id}}, a command to switch among threads
3271 @item @samp{info threads}, a command to inquire about existing threads
3272 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3273 a command to apply a command to a list of threads
3274 @item thread-specific breakpoints
3275 @item @samp{set print thread-events}, which controls printing of
3276 messages on thread start and exit.
3277 @item @samp{set libthread-db-search-path @var{path}}, which lets
3278 the user specify which @code{libthread_db} to use if the default choice
3279 isn't compatible with the program.
3280 @end itemize
3281
3282 @cindex focus of debugging
3283 @cindex current thread
3284 The @value{GDBN} thread debugging facility allows you to observe all
3285 threads while your program runs---but whenever @value{GDBN} takes
3286 control, one thread in particular is always the focus of debugging.
3287 This thread is called the @dfn{current thread}. Debugging commands show
3288 program information from the perspective of the current thread.
3289
3290 @cindex @code{New} @var{systag} message
3291 @cindex thread identifier (system)
3292 @c FIXME-implementors!! It would be more helpful if the [New...] message
3293 @c included GDB's numeric thread handle, so you could just go to that
3294 @c thread without first checking `info threads'.
3295 Whenever @value{GDBN} detects a new thread in your program, it displays
3296 the target system's identification for the thread with a message in the
3297 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3298 whose form varies depending on the particular system. For example, on
3299 @sc{gnu}/Linux, you might see
3300
3301 @smallexample
3302 [New Thread 0x41e02940 (LWP 25582)]
3303 @end smallexample
3304
3305 @noindent
3306 when @value{GDBN} notices a new thread. In contrast, on other systems,
3307 the @var{systag} is simply something like @samp{process 368}, with no
3308 further qualifier.
3309
3310 @c FIXME!! (1) Does the [New...] message appear even for the very first
3311 @c thread of a program, or does it only appear for the
3312 @c second---i.e.@: when it becomes obvious we have a multithread
3313 @c program?
3314 @c (2) *Is* there necessarily a first thread always? Or do some
3315 @c multithread systems permit starting a program with multiple
3316 @c threads ab initio?
3317
3318 @anchor{thread numbers}
3319 @cindex thread number, per inferior
3320 @cindex thread identifier (GDB)
3321 For debugging purposes, @value{GDBN} associates its own thread number
3322 ---always a single integer---with each thread of an inferior. This
3323 number is unique between all threads of an inferior, but not unique
3324 between threads of different inferiors.
3325
3326 @cindex qualified thread ID
3327 You can refer to a given thread in an inferior using the qualified
3328 @var{inferior-num}.@var{thread-num} syntax, also known as
3329 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3330 number and @var{thread-num} being the thread number of the given
3331 inferior. For example, thread @code{2.3} refers to thread number 3 of
3332 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3333 then @value{GDBN} infers you're referring to a thread of the current
3334 inferior.
3335
3336 Until you create a second inferior, @value{GDBN} does not show the
3337 @var{inferior-num} part of thread IDs, even though you can always use
3338 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3339 of inferior 1, the initial inferior.
3340
3341 @anchor{thread ID lists}
3342 @cindex thread ID lists
3343 Some commands accept a space-separated @dfn{thread ID list} as
3344 argument. A list element can be:
3345
3346 @enumerate
3347 @item
3348 A thread ID as shown in the first field of the @samp{info threads}
3349 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3350 @samp{1}.
3351
3352 @item
3353 A range of thread numbers, again with or without an inferior
3354 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3355 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3356
3357 @item
3358 All threads of an inferior, specified with a star wildcard, with or
3359 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3360 @samp{1.*}) or @code{*}. The former refers to all threads of the
3361 given inferior, and the latter form without an inferior qualifier
3362 refers to all threads of the current inferior.
3363
3364 @end enumerate
3365
3366 For example, if the current inferior is 1, and inferior 7 has one
3367 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3368 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3369 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3370 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3371 7.1}.
3372
3373
3374 @anchor{global thread numbers}
3375 @cindex global thread number
3376 @cindex global thread identifier (GDB)
3377 In addition to a @emph{per-inferior} number, each thread is also
3378 assigned a unique @emph{global} number, also known as @dfn{global
3379 thread ID}, a single integer. Unlike the thread number component of
3380 the thread ID, no two threads have the same global ID, even when
3381 you're debugging multiple inferiors.
3382
3383 From @value{GDBN}'s perspective, a process always has at least one
3384 thread. In other words, @value{GDBN} assigns a thread number to the
3385 program's ``main thread'' even if the program is not multi-threaded.
3386
3387 @vindex $_thread@r{, convenience variable}
3388 @vindex $_gthread@r{, convenience variable}
3389 The debugger convenience variables @samp{$_thread} and
3390 @samp{$_gthread} contain, respectively, the per-inferior thread number
3391 and the global thread number of the current thread. You may find this
3392 useful in writing breakpoint conditional expressions, command scripts,
3393 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3394 general information on convenience variables.
3395
3396 If @value{GDBN} detects the program is multi-threaded, it augments the
3397 usual message about stopping at a breakpoint with the ID and name of
3398 the thread that hit the breakpoint.
3399
3400 @smallexample
3401 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3402 @end smallexample
3403
3404 Likewise when the program receives a signal:
3405
3406 @smallexample
3407 Thread 1 "main" received signal SIGINT, Interrupt.
3408 @end smallexample
3409
3410 @table @code
3411 @kindex info threads
3412 @item info threads @r{[}@var{thread-id-list}@r{]}
3413
3414 Display information about one or more threads. With no arguments
3415 displays information about all threads. You can specify the list of
3416 threads that you want to display using the thread ID list syntax
3417 (@pxref{thread ID lists}).
3418
3419 @value{GDBN} displays for each thread (in this order):
3420
3421 @enumerate
3422 @item
3423 the per-inferior thread number assigned by @value{GDBN}
3424
3425 @item
3426 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3427 option was specified
3428
3429 @item
3430 the target system's thread identifier (@var{systag})
3431
3432 @item
3433 the thread's name, if one is known. A thread can either be named by
3434 the user (see @code{thread name}, below), or, in some cases, by the
3435 program itself.
3436
3437 @item
3438 the current stack frame summary for that thread
3439 @end enumerate
3440
3441 @noindent
3442 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3443 indicates the current thread.
3444
3445 For example,
3446 @end table
3447 @c end table here to get a little more width for example
3448
3449 @smallexample
3450 (@value{GDBP}) info threads
3451 Id Target Id Frame
3452 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3453 2 process 35 thread 23 0x34e5 in sigpause ()
3454 3 process 35 thread 27 0x34e5 in sigpause ()
3455 at threadtest.c:68
3456 @end smallexample
3457
3458 If you're debugging multiple inferiors, @value{GDBN} displays thread
3459 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3460 Otherwise, only @var{thread-num} is shown.
3461
3462 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3463 indicating each thread's global thread ID:
3464
3465 @smallexample
3466 (@value{GDBP}) info threads
3467 Id GId Target Id Frame
3468 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3469 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3470 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3471 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3472 @end smallexample
3473
3474 On Solaris, you can display more information about user threads with a
3475 Solaris-specific command:
3476
3477 @table @code
3478 @item maint info sol-threads
3479 @kindex maint info sol-threads
3480 @cindex thread info (Solaris)
3481 Display info on Solaris user threads.
3482 @end table
3483
3484 @table @code
3485 @kindex thread @var{thread-id}
3486 @item thread @var{thread-id}
3487 Make thread ID @var{thread-id} the current thread. The command
3488 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3489 the first field of the @samp{info threads} display, with or without an
3490 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3491
3492 @value{GDBN} responds by displaying the system identifier of the
3493 thread you selected, and its current stack frame summary:
3494
3495 @smallexample
3496 (@value{GDBP}) thread 2
3497 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3498 #0 some_function (ignore=0x0) at example.c:8
3499 8 printf ("hello\n");
3500 @end smallexample
3501
3502 @noindent
3503 As with the @samp{[New @dots{}]} message, the form of the text after
3504 @samp{Switching to} depends on your system's conventions for identifying
3505 threads.
3506
3507 @anchor{thread apply all}
3508 @kindex thread apply
3509 @cindex apply command to several threads
3510 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3511 The @code{thread apply} command allows you to apply the named
3512 @var{command} to one or more threads. Specify the threads that you
3513 want affected using the thread ID list syntax (@pxref{thread ID
3514 lists}), or specify @code{all} to apply to all threads. To apply a
3515 command to all threads in descending order, type @kbd{thread apply all
3516 @var{command}}. To apply a command to all threads in ascending order,
3517 type @kbd{thread apply all -ascending @var{command}}.
3518
3519 The @var{flag} arguments control what output to produce and how to handle
3520 errors raised when applying @var{command} to a thread. @var{flag}
3521 must start with a @code{-} directly followed by one letter in
3522 @code{qcs}. If several flags are provided, they must be given
3523 individually, such as @code{-c -q}.
3524
3525 By default, @value{GDBN} displays some thread information before the
3526 output produced by @var{command}, and an error raised during the
3527 execution of a @var{command} will abort @code{thread apply}. The
3528 following flags can be used to fine-tune this behavior:
3529
3530 @table @code
3531 @item -c
3532 The flag @code{-c}, which stands for @samp{continue}, causes any
3533 errors in @var{command} to be displayed, and the execution of
3534 @code{thread apply} then continues.
3535 @item -s
3536 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3537 or empty output produced by a @var{command} to be silently ignored.
3538 That is, the execution continues, but the thread information and errors
3539 are not printed.
3540 @item -q
3541 The flag @code{-q} (@samp{quiet}) disables printing the thread
3542 information.
3543 @end table
3544
3545 Flags @code{-c} and @code{-s} cannot be used together.
3546
3547 @kindex taas
3548 @cindex apply command to all threads (ignoring errors and empty output)
3549 @item taas [@var{option}]@dots{} @var{command}
3550 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3551 Applies @var{command} on all threads, ignoring errors and empty output.
3552
3553 The @code{taas} command accepts the same options as the @code{thread
3554 apply all} command. @xref{thread apply all}.
3555
3556 @kindex tfaas
3557 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3558 @item tfaas [@var{option}]@dots{} @var{command}
3559 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3560 Applies @var{command} on all frames of all threads, ignoring errors
3561 and empty output. Note that the flag @code{-s} is specified twice:
3562 The first @code{-s} ensures that @code{thread apply} only shows the thread
3563 information of the threads for which @code{frame apply} produces
3564 some output. The second @code{-s} is needed to ensure that @code{frame
3565 apply} shows the frame information of a frame only if the
3566 @var{command} successfully produced some output.
3567
3568 It can for example be used to print a local variable or a function
3569 argument without knowing the thread or frame where this variable or argument
3570 is, using:
3571 @smallexample
3572 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3573 @end smallexample
3574
3575 The @code{tfaas} command accepts the same options as the @code{frame
3576 apply} command. @xref{frame apply}.
3577
3578 @kindex thread name
3579 @cindex name a thread
3580 @item thread name [@var{name}]
3581 This command assigns a name to the current thread. If no argument is
3582 given, any existing user-specified name is removed. The thread name
3583 appears in the @samp{info threads} display.
3584
3585 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3586 determine the name of the thread as given by the OS. On these
3587 systems, a name specified with @samp{thread name} will override the
3588 system-give name, and removing the user-specified name will cause
3589 @value{GDBN} to once again display the system-specified name.
3590
3591 @kindex thread find
3592 @cindex search for a thread
3593 @item thread find [@var{regexp}]
3594 Search for and display thread ids whose name or @var{systag}
3595 matches the supplied regular expression.
3596
3597 As well as being the complement to the @samp{thread name} command,
3598 this command also allows you to identify a thread by its target
3599 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3600 is the LWP id.
3601
3602 @smallexample
3603 (@value{GDBN}) thread find 26688
3604 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3605 (@value{GDBN}) info thread 4
3606 Id Target Id Frame
3607 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3608 @end smallexample
3609
3610 @kindex set print thread-events
3611 @cindex print messages on thread start and exit
3612 @item set print thread-events
3613 @itemx set print thread-events on
3614 @itemx set print thread-events off
3615 The @code{set print thread-events} command allows you to enable or
3616 disable printing of messages when @value{GDBN} notices that new threads have
3617 started or that threads have exited. By default, these messages will
3618 be printed if detection of these events is supported by the target.
3619 Note that these messages cannot be disabled on all targets.
3620
3621 @kindex show print thread-events
3622 @item show print thread-events
3623 Show whether messages will be printed when @value{GDBN} detects that threads
3624 have started and exited.
3625 @end table
3626
3627 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3628 more information about how @value{GDBN} behaves when you stop and start
3629 programs with multiple threads.
3630
3631 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3632 watchpoints in programs with multiple threads.
3633
3634 @anchor{set libthread-db-search-path}
3635 @table @code
3636 @kindex set libthread-db-search-path
3637 @cindex search path for @code{libthread_db}
3638 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3639 If this variable is set, @var{path} is a colon-separated list of
3640 directories @value{GDBN} will use to search for @code{libthread_db}.
3641 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3642 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3643 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3644 macro.
3645
3646 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3647 @code{libthread_db} library to obtain information about threads in the
3648 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3649 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3650 specific thread debugging library loading is enabled
3651 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3652
3653 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3654 refers to the default system directories that are
3655 normally searched for loading shared libraries. The @samp{$sdir} entry
3656 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3657 (@pxref{libthread_db.so.1 file}).
3658
3659 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3660 refers to the directory from which @code{libpthread}
3661 was loaded in the inferior process.
3662
3663 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3664 @value{GDBN} attempts to initialize it with the current inferior process.
3665 If this initialization fails (which could happen because of a version
3666 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3667 will unload @code{libthread_db}, and continue with the next directory.
3668 If none of @code{libthread_db} libraries initialize successfully,
3669 @value{GDBN} will issue a warning and thread debugging will be disabled.
3670
3671 Setting @code{libthread-db-search-path} is currently implemented
3672 only on some platforms.
3673
3674 @kindex show libthread-db-search-path
3675 @item show libthread-db-search-path
3676 Display current libthread_db search path.
3677
3678 @kindex set debug libthread-db
3679 @kindex show debug libthread-db
3680 @cindex debugging @code{libthread_db}
3681 @item set debug libthread-db
3682 @itemx show debug libthread-db
3683 Turns on or off display of @code{libthread_db}-related events.
3684 Use @code{1} to enable, @code{0} to disable.
3685 @end table
3686
3687 @node Forks
3688 @section Debugging Forks
3689
3690 @cindex fork, debugging programs which call
3691 @cindex multiple processes
3692 @cindex processes, multiple
3693 On most systems, @value{GDBN} has no special support for debugging
3694 programs which create additional processes using the @code{fork}
3695 function. When a program forks, @value{GDBN} will continue to debug the
3696 parent process and the child process will run unimpeded. If you have
3697 set a breakpoint in any code which the child then executes, the child
3698 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3699 will cause it to terminate.
3700
3701 However, if you want to debug the child process there is a workaround
3702 which isn't too painful. Put a call to @code{sleep} in the code which
3703 the child process executes after the fork. It may be useful to sleep
3704 only if a certain environment variable is set, or a certain file exists,
3705 so that the delay need not occur when you don't want to run @value{GDBN}
3706 on the child. While the child is sleeping, use the @code{ps} program to
3707 get its process ID. Then tell @value{GDBN} (a new invocation of
3708 @value{GDBN} if you are also debugging the parent process) to attach to
3709 the child process (@pxref{Attach}). From that point on you can debug
3710 the child process just like any other process which you attached to.
3711
3712 On some systems, @value{GDBN} provides support for debugging programs
3713 that create additional processes using the @code{fork} or @code{vfork}
3714 functions. On @sc{gnu}/Linux platforms, this feature is supported
3715 with kernel version 2.5.46 and later.
3716
3717 The fork debugging commands are supported in native mode and when
3718 connected to @code{gdbserver} in either @code{target remote} mode or
3719 @code{target extended-remote} mode.
3720
3721 By default, when a program forks, @value{GDBN} will continue to debug
3722 the parent process and the child process will run unimpeded.
3723
3724 If you want to follow the child process instead of the parent process,
3725 use the command @w{@code{set follow-fork-mode}}.
3726
3727 @table @code
3728 @kindex set follow-fork-mode
3729 @item set follow-fork-mode @var{mode}
3730 Set the debugger response to a program call of @code{fork} or
3731 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3732 process. The @var{mode} argument can be:
3733
3734 @table @code
3735 @item parent
3736 The original process is debugged after a fork. The child process runs
3737 unimpeded. This is the default.
3738
3739 @item child
3740 The new process is debugged after a fork. The parent process runs
3741 unimpeded.
3742
3743 @end table
3744
3745 @kindex show follow-fork-mode
3746 @item show follow-fork-mode
3747 Display the current debugger response to a @code{fork} or @code{vfork} call.
3748 @end table
3749
3750 @cindex debugging multiple processes
3751 On Linux, if you want to debug both the parent and child processes, use the
3752 command @w{@code{set detach-on-fork}}.
3753
3754 @table @code
3755 @kindex set detach-on-fork
3756 @item set detach-on-fork @var{mode}
3757 Tells gdb whether to detach one of the processes after a fork, or
3758 retain debugger control over them both.
3759
3760 @table @code
3761 @item on
3762 The child process (or parent process, depending on the value of
3763 @code{follow-fork-mode}) will be detached and allowed to run
3764 independently. This is the default.
3765
3766 @item off
3767 Both processes will be held under the control of @value{GDBN}.
3768 One process (child or parent, depending on the value of
3769 @code{follow-fork-mode}) is debugged as usual, while the other
3770 is held suspended.
3771
3772 @end table
3773
3774 @kindex show detach-on-fork
3775 @item show detach-on-fork
3776 Show whether detach-on-fork mode is on/off.
3777 @end table
3778
3779 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3780 will retain control of all forked processes (including nested forks).
3781 You can list the forked processes under the control of @value{GDBN} by
3782 using the @w{@code{info inferiors}} command, and switch from one fork
3783 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3784 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3785
3786 To quit debugging one of the forked processes, you can either detach
3787 from it by using the @w{@code{detach inferiors}} command (allowing it
3788 to run independently), or kill it using the @w{@code{kill inferiors}}
3789 command. @xref{Inferiors Connections and Programs, ,Debugging
3790 Multiple Inferiors Connections and Programs}.
3791
3792 If you ask to debug a child process and a @code{vfork} is followed by an
3793 @code{exec}, @value{GDBN} executes the new target up to the first
3794 breakpoint in the new target. If you have a breakpoint set on
3795 @code{main} in your original program, the breakpoint will also be set on
3796 the child process's @code{main}.
3797
3798 On some systems, when a child process is spawned by @code{vfork}, you
3799 cannot debug the child or parent until an @code{exec} call completes.
3800
3801 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3802 call executes, the new target restarts. To restart the parent
3803 process, use the @code{file} command with the parent executable name
3804 as its argument. By default, after an @code{exec} call executes,
3805 @value{GDBN} discards the symbols of the previous executable image.
3806 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3807 command.
3808
3809 @table @code
3810 @kindex set follow-exec-mode
3811 @item set follow-exec-mode @var{mode}
3812
3813 Set debugger response to a program call of @code{exec}. An
3814 @code{exec} call replaces the program image of a process.
3815
3816 @code{follow-exec-mode} can be:
3817
3818 @table @code
3819 @item new
3820 @value{GDBN} creates a new inferior and rebinds the process to this
3821 new inferior. The program the process was running before the
3822 @code{exec} call can be restarted afterwards by restarting the
3823 original inferior.
3824
3825 For example:
3826
3827 @smallexample
3828 (@value{GDBP}) info inferiors
3829 (gdb) info inferior
3830 Id Description Executable
3831 * 1 <null> prog1
3832 (@value{GDBP}) run
3833 process 12020 is executing new program: prog2
3834 Program exited normally.
3835 (@value{GDBP}) info inferiors
3836 Id Description Executable
3837 1 <null> prog1
3838 * 2 <null> prog2
3839 @end smallexample
3840
3841 @item same
3842 @value{GDBN} keeps the process bound to the same inferior. The new
3843 executable image replaces the previous executable loaded in the
3844 inferior. Restarting the inferior after the @code{exec} call, with
3845 e.g., the @code{run} command, restarts the executable the process was
3846 running after the @code{exec} call. This is the default mode.
3847
3848 For example:
3849
3850 @smallexample
3851 (@value{GDBP}) info inferiors
3852 Id Description Executable
3853 * 1 <null> prog1
3854 (@value{GDBP}) run
3855 process 12020 is executing new program: prog2
3856 Program exited normally.
3857 (@value{GDBP}) info inferiors
3858 Id Description Executable
3859 * 1 <null> prog2
3860 @end smallexample
3861
3862 @end table
3863 @end table
3864
3865 @code{follow-exec-mode} is supported in native mode and
3866 @code{target extended-remote} mode.
3867
3868 You can use the @code{catch} command to make @value{GDBN} stop whenever
3869 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3870 Catchpoints, ,Setting Catchpoints}.
3871
3872 @node Checkpoint/Restart
3873 @section Setting a @emph{Bookmark} to Return to Later
3874
3875 @cindex checkpoint
3876 @cindex restart
3877 @cindex bookmark
3878 @cindex snapshot of a process
3879 @cindex rewind program state
3880
3881 On certain operating systems@footnote{Currently, only
3882 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3883 program's state, called a @dfn{checkpoint}, and come back to it
3884 later.
3885
3886 Returning to a checkpoint effectively undoes everything that has
3887 happened in the program since the @code{checkpoint} was saved. This
3888 includes changes in memory, registers, and even (within some limits)
3889 system state. Effectively, it is like going back in time to the
3890 moment when the checkpoint was saved.
3891
3892 Thus, if you're stepping thru a program and you think you're
3893 getting close to the point where things go wrong, you can save
3894 a checkpoint. Then, if you accidentally go too far and miss
3895 the critical statement, instead of having to restart your program
3896 from the beginning, you can just go back to the checkpoint and
3897 start again from there.
3898
3899 This can be especially useful if it takes a lot of time or
3900 steps to reach the point where you think the bug occurs.
3901
3902 To use the @code{checkpoint}/@code{restart} method of debugging:
3903
3904 @table @code
3905 @kindex checkpoint
3906 @item checkpoint
3907 Save a snapshot of the debugged program's current execution state.
3908 The @code{checkpoint} command takes no arguments, but each checkpoint
3909 is assigned a small integer id, similar to a breakpoint id.
3910
3911 @kindex info checkpoints
3912 @item info checkpoints
3913 List the checkpoints that have been saved in the current debugging
3914 session. For each checkpoint, the following information will be
3915 listed:
3916
3917 @table @code
3918 @item Checkpoint ID
3919 @item Process ID
3920 @item Code Address
3921 @item Source line, or label
3922 @end table
3923
3924 @kindex restart @var{checkpoint-id}
3925 @item restart @var{checkpoint-id}
3926 Restore the program state that was saved as checkpoint number
3927 @var{checkpoint-id}. All program variables, registers, stack frames
3928 etc.@: will be returned to the values that they had when the checkpoint
3929 was saved. In essence, gdb will ``wind back the clock'' to the point
3930 in time when the checkpoint was saved.
3931
3932 Note that breakpoints, @value{GDBN} variables, command history etc.
3933 are not affected by restoring a checkpoint. In general, a checkpoint
3934 only restores things that reside in the program being debugged, not in
3935 the debugger.
3936
3937 @kindex delete checkpoint @var{checkpoint-id}
3938 @item delete checkpoint @var{checkpoint-id}
3939 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3940
3941 @end table
3942
3943 Returning to a previously saved checkpoint will restore the user state
3944 of the program being debugged, plus a significant subset of the system
3945 (OS) state, including file pointers. It won't ``un-write'' data from
3946 a file, but it will rewind the file pointer to the previous location,
3947 so that the previously written data can be overwritten. For files
3948 opened in read mode, the pointer will also be restored so that the
3949 previously read data can be read again.
3950
3951 Of course, characters that have been sent to a printer (or other
3952 external device) cannot be ``snatched back'', and characters received
3953 from eg.@: a serial device can be removed from internal program buffers,
3954 but they cannot be ``pushed back'' into the serial pipeline, ready to
3955 be received again. Similarly, the actual contents of files that have
3956 been changed cannot be restored (at this time).
3957
3958 However, within those constraints, you actually can ``rewind'' your
3959 program to a previously saved point in time, and begin debugging it
3960 again --- and you can change the course of events so as to debug a
3961 different execution path this time.
3962
3963 @cindex checkpoints and process id
3964 Finally, there is one bit of internal program state that will be
3965 different when you return to a checkpoint --- the program's process
3966 id. Each checkpoint will have a unique process id (or @var{pid}),
3967 and each will be different from the program's original @var{pid}.
3968 If your program has saved a local copy of its process id, this could
3969 potentially pose a problem.
3970
3971 @subsection A Non-obvious Benefit of Using Checkpoints
3972
3973 On some systems such as @sc{gnu}/Linux, address space randomization
3974 is performed on new processes for security reasons. This makes it
3975 difficult or impossible to set a breakpoint, or watchpoint, on an
3976 absolute address if you have to restart the program, since the
3977 absolute location of a symbol will change from one execution to the
3978 next.
3979
3980 A checkpoint, however, is an @emph{identical} copy of a process.
3981 Therefore if you create a checkpoint at (eg.@:) the start of main,
3982 and simply return to that checkpoint instead of restarting the
3983 process, you can avoid the effects of address randomization and
3984 your symbols will all stay in the same place.
3985
3986 @node Stopping
3987 @chapter Stopping and Continuing
3988
3989 The principal purposes of using a debugger are so that you can stop your
3990 program before it terminates; or so that, if your program runs into
3991 trouble, you can investigate and find out why.
3992
3993 Inside @value{GDBN}, your program may stop for any of several reasons,
3994 such as a signal, a breakpoint, or reaching a new line after a
3995 @value{GDBN} command such as @code{step}. You may then examine and
3996 change variables, set new breakpoints or remove old ones, and then
3997 continue execution. Usually, the messages shown by @value{GDBN} provide
3998 ample explanation of the status of your program---but you can also
3999 explicitly request this information at any time.
4000
4001 @table @code
4002 @kindex info program
4003 @item info program
4004 Display information about the status of your program: whether it is
4005 running or not, what process it is, and why it stopped.
4006 @end table
4007
4008 @menu
4009 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4010 * Continuing and Stepping:: Resuming execution
4011 * Skipping Over Functions and Files::
4012 Skipping over functions and files
4013 * Signals:: Signals
4014 * Thread Stops:: Stopping and starting multi-thread programs
4015 @end menu
4016
4017 @node Breakpoints
4018 @section Breakpoints, Watchpoints, and Catchpoints
4019
4020 @cindex breakpoints
4021 A @dfn{breakpoint} makes your program stop whenever a certain point in
4022 the program is reached. For each breakpoint, you can add conditions to
4023 control in finer detail whether your program stops. You can set
4024 breakpoints with the @code{break} command and its variants (@pxref{Set
4025 Breaks, ,Setting Breakpoints}), to specify the place where your program
4026 should stop by line number, function name or exact address in the
4027 program.
4028
4029 On some systems, you can set breakpoints in shared libraries before
4030 the executable is run.
4031
4032 @cindex watchpoints
4033 @cindex data breakpoints
4034 @cindex memory tracing
4035 @cindex breakpoint on memory address
4036 @cindex breakpoint on variable modification
4037 A @dfn{watchpoint} is a special breakpoint that stops your program
4038 when the value of an expression changes. The expression may be a value
4039 of a variable, or it could involve values of one or more variables
4040 combined by operators, such as @samp{a + b}. This is sometimes called
4041 @dfn{data breakpoints}. You must use a different command to set
4042 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4043 from that, you can manage a watchpoint like any other breakpoint: you
4044 enable, disable, and delete both breakpoints and watchpoints using the
4045 same commands.
4046
4047 You can arrange to have values from your program displayed automatically
4048 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4049 Automatic Display}.
4050
4051 @cindex catchpoints
4052 @cindex breakpoint on events
4053 A @dfn{catchpoint} is another special breakpoint that stops your program
4054 when a certain kind of event occurs, such as the throwing of a C@t{++}
4055 exception or the loading of a library. As with watchpoints, you use a
4056 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4057 Catchpoints}), but aside from that, you can manage a catchpoint like any
4058 other breakpoint. (To stop when your program receives a signal, use the
4059 @code{handle} command; see @ref{Signals, ,Signals}.)
4060
4061 @cindex breakpoint numbers
4062 @cindex numbers for breakpoints
4063 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4064 catchpoint when you create it; these numbers are successive integers
4065 starting with one. In many of the commands for controlling various
4066 features of breakpoints you use the breakpoint number to say which
4067 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4068 @dfn{disabled}; if disabled, it has no effect on your program until you
4069 enable it again.
4070
4071 @cindex breakpoint ranges
4072 @cindex breakpoint lists
4073 @cindex ranges of breakpoints
4074 @cindex lists of breakpoints
4075 Some @value{GDBN} commands accept a space-separated list of breakpoints
4076 on which to operate. A list element can be either a single breakpoint number,
4077 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4078 When a breakpoint list is given to a command, all breakpoints in that list
4079 are operated on.
4080
4081 @menu
4082 * Set Breaks:: Setting breakpoints
4083 * Set Watchpoints:: Setting watchpoints
4084 * Set Catchpoints:: Setting catchpoints
4085 * Delete Breaks:: Deleting breakpoints
4086 * Disabling:: Disabling breakpoints
4087 * Conditions:: Break conditions
4088 * Break Commands:: Breakpoint command lists
4089 * Dynamic Printf:: Dynamic printf
4090 * Save Breakpoints:: How to save breakpoints in a file
4091 * Static Probe Points:: Listing static probe points
4092 * Error in Breakpoints:: ``Cannot insert breakpoints''
4093 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4094 @end menu
4095
4096 @node Set Breaks
4097 @subsection Setting Breakpoints
4098
4099 @c FIXME LMB what does GDB do if no code on line of breakpt?
4100 @c consider in particular declaration with/without initialization.
4101 @c
4102 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4103
4104 @kindex break
4105 @kindex b @r{(@code{break})}
4106 @vindex $bpnum@r{, convenience variable}
4107 @cindex latest breakpoint
4108 Breakpoints are set with the @code{break} command (abbreviated
4109 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4110 number of the breakpoint you've set most recently; see @ref{Convenience
4111 Vars,, Convenience Variables}, for a discussion of what you can do with
4112 convenience variables.
4113
4114 @table @code
4115 @item break @var{location}
4116 Set a breakpoint at the given @var{location}, which can specify a
4117 function name, a line number, or an address of an instruction.
4118 (@xref{Specify Location}, for a list of all the possible ways to
4119 specify a @var{location}.) The breakpoint will stop your program just
4120 before it executes any of the code in the specified @var{location}.
4121
4122 When using source languages that permit overloading of symbols, such as
4123 C@t{++}, a function name may refer to more than one possible place to break.
4124 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4125 that situation.
4126
4127 It is also possible to insert a breakpoint that will stop the program
4128 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4129 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4130
4131 @item break
4132 When called without any arguments, @code{break} sets a breakpoint at
4133 the next instruction to be executed in the selected stack frame
4134 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4135 innermost, this makes your program stop as soon as control
4136 returns to that frame. This is similar to the effect of a
4137 @code{finish} command in the frame inside the selected frame---except
4138 that @code{finish} does not leave an active breakpoint. If you use
4139 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4140 the next time it reaches the current location; this may be useful
4141 inside loops.
4142
4143 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4144 least one instruction has been executed. If it did not do this, you
4145 would be unable to proceed past a breakpoint without first disabling the
4146 breakpoint. This rule applies whether or not the breakpoint already
4147 existed when your program stopped.
4148
4149 @item break @dots{} if @var{cond}
4150 Set a breakpoint with condition @var{cond}; evaluate the expression
4151 @var{cond} each time the breakpoint is reached, and stop only if the
4152 value is nonzero---that is, if @var{cond} evaluates as true.
4153 @samp{@dots{}} stands for one of the possible arguments described
4154 above (or no argument) specifying where to break. @xref{Conditions,
4155 ,Break Conditions}, for more information on breakpoint conditions.
4156
4157 @kindex tbreak
4158 @item tbreak @var{args}
4159 Set a breakpoint enabled only for one stop. The @var{args} are the
4160 same as for the @code{break} command, and the breakpoint is set in the same
4161 way, but the breakpoint is automatically deleted after the first time your
4162 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4163
4164 @kindex hbreak
4165 @cindex hardware breakpoints
4166 @item hbreak @var{args}
4167 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4168 @code{break} command and the breakpoint is set in the same way, but the
4169 breakpoint requires hardware support and some target hardware may not
4170 have this support. The main purpose of this is EPROM/ROM code
4171 debugging, so you can set a breakpoint at an instruction without
4172 changing the instruction. This can be used with the new trap-generation
4173 provided by SPARClite DSU and most x86-based targets. These targets
4174 will generate traps when a program accesses some data or instruction
4175 address that is assigned to the debug registers. However the hardware
4176 breakpoint registers can take a limited number of breakpoints. For
4177 example, on the DSU, only two data breakpoints can be set at a time, and
4178 @value{GDBN} will reject this command if more than two are used. Delete
4179 or disable unused hardware breakpoints before setting new ones
4180 (@pxref{Disabling, ,Disabling Breakpoints}).
4181 @xref{Conditions, ,Break Conditions}.
4182 For remote targets, you can restrict the number of hardware
4183 breakpoints @value{GDBN} will use, see @ref{set remote
4184 hardware-breakpoint-limit}.
4185
4186 @kindex thbreak
4187 @item thbreak @var{args}
4188 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4189 are the same as for the @code{hbreak} command and the breakpoint is set in
4190 the same way. However, like the @code{tbreak} command,
4191 the breakpoint is automatically deleted after the
4192 first time your program stops there. Also, like the @code{hbreak}
4193 command, the breakpoint requires hardware support and some target hardware
4194 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4195 See also @ref{Conditions, ,Break Conditions}.
4196
4197 @kindex rbreak
4198 @cindex regular expression
4199 @cindex breakpoints at functions matching a regexp
4200 @cindex set breakpoints in many functions
4201 @item rbreak @var{regex}
4202 Set breakpoints on all functions matching the regular expression
4203 @var{regex}. This command sets an unconditional breakpoint on all
4204 matches, printing a list of all breakpoints it set. Once these
4205 breakpoints are set, they are treated just like the breakpoints set with
4206 the @code{break} command. You can delete them, disable them, or make
4207 them conditional the same way as any other breakpoint.
4208
4209 In programs using different languages, @value{GDBN} chooses the syntax
4210 to print the list of all breakpoints it sets according to the
4211 @samp{set language} value: using @samp{set language auto}
4212 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4213 language of the breakpoint's function, other values mean to use
4214 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4215
4216 The syntax of the regular expression is the standard one used with tools
4217 like @file{grep}. Note that this is different from the syntax used by
4218 shells, so for instance @code{foo*} matches all functions that include
4219 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4220 @code{.*} leading and trailing the regular expression you supply, so to
4221 match only functions that begin with @code{foo}, use @code{^foo}.
4222
4223 @cindex non-member C@t{++} functions, set breakpoint in
4224 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4225 breakpoints on overloaded functions that are not members of any special
4226 classes.
4227
4228 @cindex set breakpoints on all functions
4229 The @code{rbreak} command can be used to set breakpoints in
4230 @strong{all} the functions in a program, like this:
4231
4232 @smallexample
4233 (@value{GDBP}) rbreak .
4234 @end smallexample
4235
4236 @item rbreak @var{file}:@var{regex}
4237 If @code{rbreak} is called with a filename qualification, it limits
4238 the search for functions matching the given regular expression to the
4239 specified @var{file}. This can be used, for example, to set breakpoints on
4240 every function in a given file:
4241
4242 @smallexample
4243 (@value{GDBP}) rbreak file.c:.
4244 @end smallexample
4245
4246 The colon separating the filename qualifier from the regex may
4247 optionally be surrounded by spaces.
4248
4249 @kindex info breakpoints
4250 @cindex @code{$_} and @code{info breakpoints}
4251 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4252 @itemx info break @r{[}@var{list}@dots{}@r{]}
4253 Print a table of all breakpoints, watchpoints, and catchpoints set and
4254 not deleted. Optional argument @var{n} means print information only
4255 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4256 For each breakpoint, following columns are printed:
4257
4258 @table @emph
4259 @item Breakpoint Numbers
4260 @item Type
4261 Breakpoint, watchpoint, or catchpoint.
4262 @item Disposition
4263 Whether the breakpoint is marked to be disabled or deleted when hit.
4264 @item Enabled or Disabled
4265 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4266 that are not enabled.
4267 @item Address
4268 Where the breakpoint is in your program, as a memory address. For a
4269 pending breakpoint whose address is not yet known, this field will
4270 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4271 library that has the symbol or line referred by breakpoint is loaded.
4272 See below for details. A breakpoint with several locations will
4273 have @samp{<MULTIPLE>} in this field---see below for details.
4274 @item What
4275 Where the breakpoint is in the source for your program, as a file and
4276 line number. For a pending breakpoint, the original string passed to
4277 the breakpoint command will be listed as it cannot be resolved until
4278 the appropriate shared library is loaded in the future.
4279 @end table
4280
4281 @noindent
4282 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4283 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4284 @value{GDBN} on the host's side. If it is ``target'', then the condition
4285 is evaluated by the target. The @code{info break} command shows
4286 the condition on the line following the affected breakpoint, together with
4287 its condition evaluation mode in between parentheses.
4288
4289 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4290 allowed to have a condition specified for it. The condition is not parsed for
4291 validity until a shared library is loaded that allows the pending
4292 breakpoint to resolve to a valid location.
4293
4294 @noindent
4295 @code{info break} with a breakpoint
4296 number @var{n} as argument lists only that breakpoint. The
4297 convenience variable @code{$_} and the default examining-address for
4298 the @code{x} command are set to the address of the last breakpoint
4299 listed (@pxref{Memory, ,Examining Memory}).
4300
4301 @noindent
4302 @code{info break} displays a count of the number of times the breakpoint
4303 has been hit. This is especially useful in conjunction with the
4304 @code{ignore} command. You can ignore a large number of breakpoint
4305 hits, look at the breakpoint info to see how many times the breakpoint
4306 was hit, and then run again, ignoring one less than that number. This
4307 will get you quickly to the last hit of that breakpoint.
4308
4309 @noindent
4310 For a breakpoints with an enable count (xref) greater than 1,
4311 @code{info break} also displays that count.
4312
4313 @end table
4314
4315 @value{GDBN} allows you to set any number of breakpoints at the same place in
4316 your program. There is nothing silly or meaningless about this. When
4317 the breakpoints are conditional, this is even useful
4318 (@pxref{Conditions, ,Break Conditions}).
4319
4320 @cindex multiple locations, breakpoints
4321 @cindex breakpoints, multiple locations
4322 It is possible that a breakpoint corresponds to several locations
4323 in your program. Examples of this situation are:
4324
4325 @itemize @bullet
4326 @item
4327 Multiple functions in the program may have the same name.
4328
4329 @item
4330 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4331 instances of the function body, used in different cases.
4332
4333 @item
4334 For a C@t{++} template function, a given line in the function can
4335 correspond to any number of instantiations.
4336
4337 @item
4338 For an inlined function, a given source line can correspond to
4339 several places where that function is inlined.
4340 @end itemize
4341
4342 In all those cases, @value{GDBN} will insert a breakpoint at all
4343 the relevant locations.
4344
4345 A breakpoint with multiple locations is displayed in the breakpoint
4346 table using several rows---one header row, followed by one row for
4347 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4348 address column. The rows for individual locations contain the actual
4349 addresses for locations, and show the functions to which those
4350 locations belong. The number column for a location is of the form
4351 @var{breakpoint-number}.@var{location-number}.
4352
4353 For example:
4354
4355 @smallexample
4356 Num Type Disp Enb Address What
4357 1 breakpoint keep y <MULTIPLE>
4358 stop only if i==1
4359 breakpoint already hit 1 time
4360 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4361 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4362 @end smallexample
4363
4364 You cannot delete the individual locations from a breakpoint. However,
4365 each location can be individually enabled or disabled by passing
4366 @var{breakpoint-number}.@var{location-number} as argument to the
4367 @code{enable} and @code{disable} commands. It's also possible to
4368 @code{enable} and @code{disable} a range of @var{location-number}
4369 locations using a @var{breakpoint-number} and two @var{location-number}s,
4370 in increasing order, separated by a hyphen, like
4371 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4372 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4373 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4374 all of the locations that belong to that breakpoint.
4375
4376 @cindex pending breakpoints
4377 It's quite common to have a breakpoint inside a shared library.
4378 Shared libraries can be loaded and unloaded explicitly,
4379 and possibly repeatedly, as the program is executed. To support
4380 this use case, @value{GDBN} updates breakpoint locations whenever
4381 any shared library is loaded or unloaded. Typically, you would
4382 set a breakpoint in a shared library at the beginning of your
4383 debugging session, when the library is not loaded, and when the
4384 symbols from the library are not available. When you try to set
4385 breakpoint, @value{GDBN} will ask you if you want to set
4386 a so called @dfn{pending breakpoint}---breakpoint whose address
4387 is not yet resolved.
4388
4389 After the program is run, whenever a new shared library is loaded,
4390 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4391 shared library contains the symbol or line referred to by some
4392 pending breakpoint, that breakpoint is resolved and becomes an
4393 ordinary breakpoint. When a library is unloaded, all breakpoints
4394 that refer to its symbols or source lines become pending again.
4395
4396 This logic works for breakpoints with multiple locations, too. For
4397 example, if you have a breakpoint in a C@t{++} template function, and
4398 a newly loaded shared library has an instantiation of that template,
4399 a new location is added to the list of locations for the breakpoint.
4400
4401 Except for having unresolved address, pending breakpoints do not
4402 differ from regular breakpoints. You can set conditions or commands,
4403 enable and disable them and perform other breakpoint operations.
4404
4405 @value{GDBN} provides some additional commands for controlling what
4406 happens when the @samp{break} command cannot resolve breakpoint
4407 address specification to an address:
4408
4409 @kindex set breakpoint pending
4410 @kindex show breakpoint pending
4411 @table @code
4412 @item set breakpoint pending auto
4413 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4414 location, it queries you whether a pending breakpoint should be created.
4415
4416 @item set breakpoint pending on
4417 This indicates that an unrecognized breakpoint location should automatically
4418 result in a pending breakpoint being created.
4419
4420 @item set breakpoint pending off
4421 This indicates that pending breakpoints are not to be created. Any
4422 unrecognized breakpoint location results in an error. This setting does
4423 not affect any pending breakpoints previously created.
4424
4425 @item show breakpoint pending
4426 Show the current behavior setting for creating pending breakpoints.
4427 @end table
4428
4429 The settings above only affect the @code{break} command and its
4430 variants. Once breakpoint is set, it will be automatically updated
4431 as shared libraries are loaded and unloaded.
4432
4433 @cindex automatic hardware breakpoints
4434 For some targets, @value{GDBN} can automatically decide if hardware or
4435 software breakpoints should be used, depending on whether the
4436 breakpoint address is read-only or read-write. This applies to
4437 breakpoints set with the @code{break} command as well as to internal
4438 breakpoints set by commands like @code{next} and @code{finish}. For
4439 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4440 breakpoints.
4441
4442 You can control this automatic behaviour with the following commands:
4443
4444 @kindex set breakpoint auto-hw
4445 @kindex show breakpoint auto-hw
4446 @table @code
4447 @item set breakpoint auto-hw on
4448 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4449 will try to use the target memory map to decide if software or hardware
4450 breakpoint must be used.
4451
4452 @item set breakpoint auto-hw off
4453 This indicates @value{GDBN} should not automatically select breakpoint
4454 type. If the target provides a memory map, @value{GDBN} will warn when
4455 trying to set software breakpoint at a read-only address.
4456 @end table
4457
4458 @value{GDBN} normally implements breakpoints by replacing the program code
4459 at the breakpoint address with a special instruction, which, when
4460 executed, given control to the debugger. By default, the program
4461 code is so modified only when the program is resumed. As soon as
4462 the program stops, @value{GDBN} restores the original instructions. This
4463 behaviour guards against leaving breakpoints inserted in the
4464 target should gdb abrubptly disconnect. However, with slow remote
4465 targets, inserting and removing breakpoint can reduce the performance.
4466 This behavior can be controlled with the following commands::
4467
4468 @kindex set breakpoint always-inserted
4469 @kindex show breakpoint always-inserted
4470 @table @code
4471 @item set breakpoint always-inserted off
4472 All breakpoints, including newly added by the user, are inserted in
4473 the target only when the target is resumed. All breakpoints are
4474 removed from the target when it stops. This is the default mode.
4475
4476 @item set breakpoint always-inserted on
4477 Causes all breakpoints to be inserted in the target at all times. If
4478 the user adds a new breakpoint, or changes an existing breakpoint, the
4479 breakpoints in the target are updated immediately. A breakpoint is
4480 removed from the target only when breakpoint itself is deleted.
4481 @end table
4482
4483 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4484 when a breakpoint breaks. If the condition is true, then the process being
4485 debugged stops, otherwise the process is resumed.
4486
4487 If the target supports evaluating conditions on its end, @value{GDBN} may
4488 download the breakpoint, together with its conditions, to it.
4489
4490 This feature can be controlled via the following commands:
4491
4492 @kindex set breakpoint condition-evaluation
4493 @kindex show breakpoint condition-evaluation
4494 @table @code
4495 @item set breakpoint condition-evaluation host
4496 This option commands @value{GDBN} to evaluate the breakpoint
4497 conditions on the host's side. Unconditional breakpoints are sent to
4498 the target which in turn receives the triggers and reports them back to GDB
4499 for condition evaluation. This is the standard evaluation mode.
4500
4501 @item set breakpoint condition-evaluation target
4502 This option commands @value{GDBN} to download breakpoint conditions
4503 to the target at the moment of their insertion. The target
4504 is responsible for evaluating the conditional expression and reporting
4505 breakpoint stop events back to @value{GDBN} whenever the condition
4506 is true. Due to limitations of target-side evaluation, some conditions
4507 cannot be evaluated there, e.g., conditions that depend on local data
4508 that is only known to the host. Examples include
4509 conditional expressions involving convenience variables, complex types
4510 that cannot be handled by the agent expression parser and expressions
4511 that are too long to be sent over to the target, specially when the
4512 target is a remote system. In these cases, the conditions will be
4513 evaluated by @value{GDBN}.
4514
4515 @item set breakpoint condition-evaluation auto
4516 This is the default mode. If the target supports evaluating breakpoint
4517 conditions on its end, @value{GDBN} will download breakpoint conditions to
4518 the target (limitations mentioned previously apply). If the target does
4519 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4520 to evaluating all these conditions on the host's side.
4521 @end table
4522
4523
4524 @cindex negative breakpoint numbers
4525 @cindex internal @value{GDBN} breakpoints
4526 @value{GDBN} itself sometimes sets breakpoints in your program for
4527 special purposes, such as proper handling of @code{longjmp} (in C
4528 programs). These internal breakpoints are assigned negative numbers,
4529 starting with @code{-1}; @samp{info breakpoints} does not display them.
4530 You can see these breakpoints with the @value{GDBN} maintenance command
4531 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4532
4533
4534 @node Set Watchpoints
4535 @subsection Setting Watchpoints
4536
4537 @cindex setting watchpoints
4538 You can use a watchpoint to stop execution whenever the value of an
4539 expression changes, without having to predict a particular place where
4540 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4541 The expression may be as simple as the value of a single variable, or
4542 as complex as many variables combined by operators. Examples include:
4543
4544 @itemize @bullet
4545 @item
4546 A reference to the value of a single variable.
4547
4548 @item
4549 An address cast to an appropriate data type. For example,
4550 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4551 address (assuming an @code{int} occupies 4 bytes).
4552
4553 @item
4554 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4555 expression can use any operators valid in the program's native
4556 language (@pxref{Languages}).
4557 @end itemize
4558
4559 You can set a watchpoint on an expression even if the expression can
4560 not be evaluated yet. For instance, you can set a watchpoint on
4561 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4562 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4563 the expression produces a valid value. If the expression becomes
4564 valid in some other way than changing a variable (e.g.@: if the memory
4565 pointed to by @samp{*global_ptr} becomes readable as the result of a
4566 @code{malloc} call), @value{GDBN} may not stop until the next time
4567 the expression changes.
4568
4569 @cindex software watchpoints
4570 @cindex hardware watchpoints
4571 Depending on your system, watchpoints may be implemented in software or
4572 hardware. @value{GDBN} does software watchpointing by single-stepping your
4573 program and testing the variable's value each time, which is hundreds of
4574 times slower than normal execution. (But this may still be worth it, to
4575 catch errors where you have no clue what part of your program is the
4576 culprit.)
4577
4578 On some systems, such as most PowerPC or x86-based targets,
4579 @value{GDBN} includes support for hardware watchpoints, which do not
4580 slow down the running of your program.
4581
4582 @table @code
4583 @kindex watch
4584 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4585 Set a watchpoint for an expression. @value{GDBN} will break when the
4586 expression @var{expr} is written into by the program and its value
4587 changes. The simplest (and the most popular) use of this command is
4588 to watch the value of a single variable:
4589
4590 @smallexample
4591 (@value{GDBP}) watch foo
4592 @end smallexample
4593
4594 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4595 argument, @value{GDBN} breaks only when the thread identified by
4596 @var{thread-id} changes the value of @var{expr}. If any other threads
4597 change the value of @var{expr}, @value{GDBN} will not break. Note
4598 that watchpoints restricted to a single thread in this way only work
4599 with Hardware Watchpoints.
4600
4601 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4602 (see below). The @code{-location} argument tells @value{GDBN} to
4603 instead watch the memory referred to by @var{expr}. In this case,
4604 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4605 and watch the memory at that address. The type of the result is used
4606 to determine the size of the watched memory. If the expression's
4607 result does not have an address, then @value{GDBN} will print an
4608 error.
4609
4610 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4611 of masked watchpoints, if the current architecture supports this
4612 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4613 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4614 to an address to watch. The mask specifies that some bits of an address
4615 (the bits which are reset in the mask) should be ignored when matching
4616 the address accessed by the inferior against the watchpoint address.
4617 Thus, a masked watchpoint watches many addresses simultaneously---those
4618 addresses whose unmasked bits are identical to the unmasked bits in the
4619 watchpoint address. The @code{mask} argument implies @code{-location}.
4620 Examples:
4621
4622 @smallexample
4623 (@value{GDBP}) watch foo mask 0xffff00ff
4624 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4625 @end smallexample
4626
4627 @kindex rwatch
4628 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4629 Set a watchpoint that will break when the value of @var{expr} is read
4630 by the program.
4631
4632 @kindex awatch
4633 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4634 Set a watchpoint that will break when @var{expr} is either read from
4635 or written into by the program.
4636
4637 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4638 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4639 This command prints a list of watchpoints, using the same format as
4640 @code{info break} (@pxref{Set Breaks}).
4641 @end table
4642
4643 If you watch for a change in a numerically entered address you need to
4644 dereference it, as the address itself is just a constant number which will
4645 never change. @value{GDBN} refuses to create a watchpoint that watches
4646 a never-changing value:
4647
4648 @smallexample
4649 (@value{GDBP}) watch 0x600850
4650 Cannot watch constant value 0x600850.
4651 (@value{GDBP}) watch *(int *) 0x600850
4652 Watchpoint 1: *(int *) 6293584
4653 @end smallexample
4654
4655 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4656 watchpoints execute very quickly, and the debugger reports a change in
4657 value at the exact instruction where the change occurs. If @value{GDBN}
4658 cannot set a hardware watchpoint, it sets a software watchpoint, which
4659 executes more slowly and reports the change in value at the next
4660 @emph{statement}, not the instruction, after the change occurs.
4661
4662 @cindex use only software watchpoints
4663 You can force @value{GDBN} to use only software watchpoints with the
4664 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4665 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4666 the underlying system supports them. (Note that hardware-assisted
4667 watchpoints that were set @emph{before} setting
4668 @code{can-use-hw-watchpoints} to zero will still use the hardware
4669 mechanism of watching expression values.)
4670
4671 @table @code
4672 @item set can-use-hw-watchpoints
4673 @kindex set can-use-hw-watchpoints
4674 Set whether or not to use hardware watchpoints.
4675
4676 @item show can-use-hw-watchpoints
4677 @kindex show can-use-hw-watchpoints
4678 Show the current mode of using hardware watchpoints.
4679 @end table
4680
4681 For remote targets, you can restrict the number of hardware
4682 watchpoints @value{GDBN} will use, see @ref{set remote
4683 hardware-breakpoint-limit}.
4684
4685 When you issue the @code{watch} command, @value{GDBN} reports
4686
4687 @smallexample
4688 Hardware watchpoint @var{num}: @var{expr}
4689 @end smallexample
4690
4691 @noindent
4692 if it was able to set a hardware watchpoint.
4693
4694 Currently, the @code{awatch} and @code{rwatch} commands can only set
4695 hardware watchpoints, because accesses to data that don't change the
4696 value of the watched expression cannot be detected without examining
4697 every instruction as it is being executed, and @value{GDBN} does not do
4698 that currently. If @value{GDBN} finds that it is unable to set a
4699 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4700 will print a message like this:
4701
4702 @smallexample
4703 Expression cannot be implemented with read/access watchpoint.
4704 @end smallexample
4705
4706 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4707 data type of the watched expression is wider than what a hardware
4708 watchpoint on the target machine can handle. For example, some systems
4709 can only watch regions that are up to 4 bytes wide; on such systems you
4710 cannot set hardware watchpoints for an expression that yields a
4711 double-precision floating-point number (which is typically 8 bytes
4712 wide). As a work-around, it might be possible to break the large region
4713 into a series of smaller ones and watch them with separate watchpoints.
4714
4715 If you set too many hardware watchpoints, @value{GDBN} might be unable
4716 to insert all of them when you resume the execution of your program.
4717 Since the precise number of active watchpoints is unknown until such
4718 time as the program is about to be resumed, @value{GDBN} might not be
4719 able to warn you about this when you set the watchpoints, and the
4720 warning will be printed only when the program is resumed:
4721
4722 @smallexample
4723 Hardware watchpoint @var{num}: Could not insert watchpoint
4724 @end smallexample
4725
4726 @noindent
4727 If this happens, delete or disable some of the watchpoints.
4728
4729 Watching complex expressions that reference many variables can also
4730 exhaust the resources available for hardware-assisted watchpoints.
4731 That's because @value{GDBN} needs to watch every variable in the
4732 expression with separately allocated resources.
4733
4734 If you call a function interactively using @code{print} or @code{call},
4735 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4736 kind of breakpoint or the call completes.
4737
4738 @value{GDBN} automatically deletes watchpoints that watch local
4739 (automatic) variables, or expressions that involve such variables, when
4740 they go out of scope, that is, when the execution leaves the block in
4741 which these variables were defined. In particular, when the program
4742 being debugged terminates, @emph{all} local variables go out of scope,
4743 and so only watchpoints that watch global variables remain set. If you
4744 rerun the program, you will need to set all such watchpoints again. One
4745 way of doing that would be to set a code breakpoint at the entry to the
4746 @code{main} function and when it breaks, set all the watchpoints.
4747
4748 @cindex watchpoints and threads
4749 @cindex threads and watchpoints
4750 In multi-threaded programs, watchpoints will detect changes to the
4751 watched expression from every thread.
4752
4753 @quotation
4754 @emph{Warning:} In multi-threaded programs, software watchpoints
4755 have only limited usefulness. If @value{GDBN} creates a software
4756 watchpoint, it can only watch the value of an expression @emph{in a
4757 single thread}. If you are confident that the expression can only
4758 change due to the current thread's activity (and if you are also
4759 confident that no other thread can become current), then you can use
4760 software watchpoints as usual. However, @value{GDBN} may not notice
4761 when a non-current thread's activity changes the expression. (Hardware
4762 watchpoints, in contrast, watch an expression in all threads.)
4763 @end quotation
4764
4765 @xref{set remote hardware-watchpoint-limit}.
4766
4767 @node Set Catchpoints
4768 @subsection Setting Catchpoints
4769 @cindex catchpoints, setting
4770 @cindex exception handlers
4771 @cindex event handling
4772
4773 You can use @dfn{catchpoints} to cause the debugger to stop for certain
4774 kinds of program events, such as C@t{++} exceptions or the loading of a
4775 shared library. Use the @code{catch} command to set a catchpoint.
4776
4777 @table @code
4778 @kindex catch
4779 @item catch @var{event}
4780 Stop when @var{event} occurs. The @var{event} can be any of the following:
4781
4782 @table @code
4783 @item throw @r{[}@var{regexp}@r{]}
4784 @itemx rethrow @r{[}@var{regexp}@r{]}
4785 @itemx catch @r{[}@var{regexp}@r{]}
4786 @kindex catch throw
4787 @kindex catch rethrow
4788 @kindex catch catch
4789 @cindex stop on C@t{++} exceptions
4790 The throwing, re-throwing, or catching of a C@t{++} exception.
4791
4792 If @var{regexp} is given, then only exceptions whose type matches the
4793 regular expression will be caught.
4794
4795 @vindex $_exception@r{, convenience variable}
4796 The convenience variable @code{$_exception} is available at an
4797 exception-related catchpoint, on some systems. This holds the
4798 exception being thrown.
4799
4800 There are currently some limitations to C@t{++} exception handling in
4801 @value{GDBN}:
4802
4803 @itemize @bullet
4804 @item
4805 The support for these commands is system-dependent. Currently, only
4806 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4807 supported.
4808
4809 @item
4810 The regular expression feature and the @code{$_exception} convenience
4811 variable rely on the presence of some SDT probes in @code{libstdc++}.
4812 If these probes are not present, then these features cannot be used.
4813 These probes were first available in the GCC 4.8 release, but whether
4814 or not they are available in your GCC also depends on how it was
4815 built.
4816
4817 @item
4818 The @code{$_exception} convenience variable is only valid at the
4819 instruction at which an exception-related catchpoint is set.
4820
4821 @item
4822 When an exception-related catchpoint is hit, @value{GDBN} stops at a
4823 location in the system library which implements runtime exception
4824 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4825 (@pxref{Selection}) to get to your code.
4826
4827 @item
4828 If you call a function interactively, @value{GDBN} normally returns
4829 control to you when the function has finished executing. If the call
4830 raises an exception, however, the call may bypass the mechanism that
4831 returns control to you and cause your program either to abort or to
4832 simply continue running until it hits a breakpoint, catches a signal
4833 that @value{GDBN} is listening for, or exits. This is the case even if
4834 you set a catchpoint for the exception; catchpoints on exceptions are
4835 disabled within interactive calls. @xref{Calling}, for information on
4836 controlling this with @code{set unwind-on-terminating-exception}.
4837
4838 @item
4839 You cannot raise an exception interactively.
4840
4841 @item
4842 You cannot install an exception handler interactively.
4843 @end itemize
4844
4845 @item exception @r{[}@var{name}@r{]}
4846 @kindex catch exception
4847 @cindex Ada exception catching
4848 @cindex catch Ada exceptions
4849 An Ada exception being raised. If an exception name is specified
4850 at the end of the command (eg @code{catch exception Program_Error}),
4851 the debugger will stop only when this specific exception is raised.
4852 Otherwise, the debugger stops execution when any Ada exception is raised.
4853
4854 When inserting an exception catchpoint on a user-defined exception whose
4855 name is identical to one of the exceptions defined by the language, the
4856 fully qualified name must be used as the exception name. Otherwise,
4857 @value{GDBN} will assume that it should stop on the pre-defined exception
4858 rather than the user-defined one. For instance, assuming an exception
4859 called @code{Constraint_Error} is defined in package @code{Pck}, then
4860 the command to use to catch such exceptions is @kbd{catch exception
4861 Pck.Constraint_Error}.
4862
4863 @vindex $_ada_exception@r{, convenience variable}
4864 The convenience variable @code{$_ada_exception} holds the address of
4865 the exception being thrown. This can be useful when setting a
4866 condition for such a catchpoint.
4867
4868 @item exception unhandled
4869 @kindex catch exception unhandled
4870 An exception that was raised but is not handled by the program. The
4871 convenience variable @code{$_ada_exception} is set as for @code{catch
4872 exception}.
4873
4874 @item handlers @r{[}@var{name}@r{]}
4875 @kindex catch handlers
4876 @cindex Ada exception handlers catching
4877 @cindex catch Ada exceptions when handled
4878 An Ada exception being handled. If an exception name is
4879 specified at the end of the command
4880 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4881 only when this specific exception is handled.
4882 Otherwise, the debugger stops execution when any Ada exception is handled.
4883
4884 When inserting a handlers catchpoint on a user-defined
4885 exception whose name is identical to one of the exceptions
4886 defined by the language, the fully qualified name must be used
4887 as the exception name. Otherwise, @value{GDBN} will assume that it
4888 should stop on the pre-defined exception rather than the
4889 user-defined one. For instance, assuming an exception called
4890 @code{Constraint_Error} is defined in package @code{Pck}, then the
4891 command to use to catch such exceptions handling is
4892 @kbd{catch handlers Pck.Constraint_Error}.
4893
4894 The convenience variable @code{$_ada_exception} is set as for
4895 @code{catch exception}.
4896
4897 @item assert
4898 @kindex catch assert
4899 A failed Ada assertion. Note that the convenience variable
4900 @code{$_ada_exception} is @emph{not} set by this catchpoint.
4901
4902 @item exec
4903 @kindex catch exec
4904 @cindex break on fork/exec
4905 A call to @code{exec}.
4906
4907 @anchor{catch syscall}
4908 @item syscall
4909 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
4910 @kindex catch syscall
4911 @cindex break on a system call.
4912 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4913 syscall is a mechanism for application programs to request a service
4914 from the operating system (OS) or one of the OS system services.
4915 @value{GDBN} can catch some or all of the syscalls issued by the
4916 debuggee, and show the related information for each syscall. If no
4917 argument is specified, calls to and returns from all system calls
4918 will be caught.
4919
4920 @var{name} can be any system call name that is valid for the
4921 underlying OS. Just what syscalls are valid depends on the OS. On
4922 GNU and Unix systems, you can find the full list of valid syscall
4923 names on @file{/usr/include/asm/unistd.h}.
4924
4925 @c For MS-Windows, the syscall names and the corresponding numbers
4926 @c can be found, e.g., on this URL:
4927 @c http://www.metasploit.com/users/opcode/syscalls.html
4928 @c but we don't support Windows syscalls yet.
4929
4930 Normally, @value{GDBN} knows in advance which syscalls are valid for
4931 each OS, so you can use the @value{GDBN} command-line completion
4932 facilities (@pxref{Completion,, command completion}) to list the
4933 available choices.
4934
4935 You may also specify the system call numerically. A syscall's
4936 number is the value passed to the OS's syscall dispatcher to
4937 identify the requested service. When you specify the syscall by its
4938 name, @value{GDBN} uses its database of syscalls to convert the name
4939 into the corresponding numeric code, but using the number directly
4940 may be useful if @value{GDBN}'s database does not have the complete
4941 list of syscalls on your system (e.g., because @value{GDBN} lags
4942 behind the OS upgrades).
4943
4944 You may specify a group of related syscalls to be caught at once using
4945 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
4946 instance, on some platforms @value{GDBN} allows you to catch all
4947 network related syscalls, by passing the argument @code{group:network}
4948 to @code{catch syscall}. Note that not all syscall groups are
4949 available in every system. You can use the command completion
4950 facilities (@pxref{Completion,, command completion}) to list the
4951 syscall groups available on your environment.
4952
4953 The example below illustrates how this command works if you don't provide
4954 arguments to it:
4955
4956 @smallexample
4957 (@value{GDBP}) catch syscall
4958 Catchpoint 1 (syscall)
4959 (@value{GDBP}) r
4960 Starting program: /tmp/catch-syscall
4961
4962 Catchpoint 1 (call to syscall 'close'), \
4963 0xffffe424 in __kernel_vsyscall ()
4964 (@value{GDBP}) c
4965 Continuing.
4966
4967 Catchpoint 1 (returned from syscall 'close'), \
4968 0xffffe424 in __kernel_vsyscall ()
4969 (@value{GDBP})
4970 @end smallexample
4971
4972 Here is an example of catching a system call by name:
4973
4974 @smallexample
4975 (@value{GDBP}) catch syscall chroot
4976 Catchpoint 1 (syscall 'chroot' [61])
4977 (@value{GDBP}) r
4978 Starting program: /tmp/catch-syscall
4979
4980 Catchpoint 1 (call to syscall 'chroot'), \
4981 0xffffe424 in __kernel_vsyscall ()
4982 (@value{GDBP}) c
4983 Continuing.
4984
4985 Catchpoint 1 (returned from syscall 'chroot'), \
4986 0xffffe424 in __kernel_vsyscall ()
4987 (@value{GDBP})
4988 @end smallexample
4989
4990 An example of specifying a system call numerically. In the case
4991 below, the syscall number has a corresponding entry in the XML
4992 file, so @value{GDBN} finds its name and prints it:
4993
4994 @smallexample
4995 (@value{GDBP}) catch syscall 252
4996 Catchpoint 1 (syscall(s) 'exit_group')
4997 (@value{GDBP}) r
4998 Starting program: /tmp/catch-syscall
4999
5000 Catchpoint 1 (call to syscall 'exit_group'), \
5001 0xffffe424 in __kernel_vsyscall ()
5002 (@value{GDBP}) c
5003 Continuing.
5004
5005 Program exited normally.
5006 (@value{GDBP})
5007 @end smallexample
5008
5009 Here is an example of catching a syscall group:
5010
5011 @smallexample
5012 (@value{GDBP}) catch syscall group:process
5013 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5014 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5015 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5016 (@value{GDBP}) r
5017 Starting program: /tmp/catch-syscall
5018
5019 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5020 from /lib64/ld-linux-x86-64.so.2
5021
5022 (@value{GDBP}) c
5023 Continuing.
5024 @end smallexample
5025
5026 However, there can be situations when there is no corresponding name
5027 in XML file for that syscall number. In this case, @value{GDBN} prints
5028 a warning message saying that it was not able to find the syscall name,
5029 but the catchpoint will be set anyway. See the example below:
5030
5031 @smallexample
5032 (@value{GDBP}) catch syscall 764
5033 warning: The number '764' does not represent a known syscall.
5034 Catchpoint 2 (syscall 764)
5035 (@value{GDBP})
5036 @end smallexample
5037
5038 If you configure @value{GDBN} using the @samp{--without-expat} option,
5039 it will not be able to display syscall names. Also, if your
5040 architecture does not have an XML file describing its system calls,
5041 you will not be able to see the syscall names. It is important to
5042 notice that these two features are used for accessing the syscall
5043 name database. In either case, you will see a warning like this:
5044
5045 @smallexample
5046 (@value{GDBP}) catch syscall
5047 warning: Could not open "syscalls/i386-linux.xml"
5048 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5049 GDB will not be able to display syscall names.
5050 Catchpoint 1 (syscall)
5051 (@value{GDBP})
5052 @end smallexample
5053
5054 Of course, the file name will change depending on your architecture and system.
5055
5056 Still using the example above, you can also try to catch a syscall by its
5057 number. In this case, you would see something like:
5058
5059 @smallexample
5060 (@value{GDBP}) catch syscall 252
5061 Catchpoint 1 (syscall(s) 252)
5062 @end smallexample
5063
5064 Again, in this case @value{GDBN} would not be able to display syscall's names.
5065
5066 @item fork
5067 @kindex catch fork
5068 A call to @code{fork}.
5069
5070 @item vfork
5071 @kindex catch vfork
5072 A call to @code{vfork}.
5073
5074 @item load @r{[}@var{regexp}@r{]}
5075 @itemx unload @r{[}@var{regexp}@r{]}
5076 @kindex catch load
5077 @kindex catch unload
5078 The loading or unloading of a shared library. If @var{regexp} is
5079 given, then the catchpoint will stop only if the regular expression
5080 matches one of the affected libraries.
5081
5082 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5083 @kindex catch signal
5084 The delivery of a signal.
5085
5086 With no arguments, this catchpoint will catch any signal that is not
5087 used internally by @value{GDBN}, specifically, all signals except
5088 @samp{SIGTRAP} and @samp{SIGINT}.
5089
5090 With the argument @samp{all}, all signals, including those used by
5091 @value{GDBN}, will be caught. This argument cannot be used with other
5092 signal names.
5093
5094 Otherwise, the arguments are a list of signal names as given to
5095 @code{handle} (@pxref{Signals}). Only signals specified in this list
5096 will be caught.
5097
5098 One reason that @code{catch signal} can be more useful than
5099 @code{handle} is that you can attach commands and conditions to the
5100 catchpoint.
5101
5102 When a signal is caught by a catchpoint, the signal's @code{stop} and
5103 @code{print} settings, as specified by @code{handle}, are ignored.
5104 However, whether the signal is still delivered to the inferior depends
5105 on the @code{pass} setting; this can be changed in the catchpoint's
5106 commands.
5107
5108 @end table
5109
5110 @item tcatch @var{event}
5111 @kindex tcatch
5112 Set a catchpoint that is enabled only for one stop. The catchpoint is
5113 automatically deleted after the first time the event is caught.
5114
5115 @end table
5116
5117 Use the @code{info break} command to list the current catchpoints.
5118
5119
5120 @node Delete Breaks
5121 @subsection Deleting Breakpoints
5122
5123 @cindex clearing breakpoints, watchpoints, catchpoints
5124 @cindex deleting breakpoints, watchpoints, catchpoints
5125 It is often necessary to eliminate a breakpoint, watchpoint, or
5126 catchpoint once it has done its job and you no longer want your program
5127 to stop there. This is called @dfn{deleting} the breakpoint. A
5128 breakpoint that has been deleted no longer exists; it is forgotten.
5129
5130 With the @code{clear} command you can delete breakpoints according to
5131 where they are in your program. With the @code{delete} command you can
5132 delete individual breakpoints, watchpoints, or catchpoints by specifying
5133 their breakpoint numbers.
5134
5135 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5136 automatically ignores breakpoints on the first instruction to be executed
5137 when you continue execution without changing the execution address.
5138
5139 @table @code
5140 @kindex clear
5141 @item clear
5142 Delete any breakpoints at the next instruction to be executed in the
5143 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5144 the innermost frame is selected, this is a good way to delete a
5145 breakpoint where your program just stopped.
5146
5147 @item clear @var{location}
5148 Delete any breakpoints set at the specified @var{location}.
5149 @xref{Specify Location}, for the various forms of @var{location}; the
5150 most useful ones are listed below:
5151
5152 @table @code
5153 @item clear @var{function}
5154 @itemx clear @var{filename}:@var{function}
5155 Delete any breakpoints set at entry to the named @var{function}.
5156
5157 @item clear @var{linenum}
5158 @itemx clear @var{filename}:@var{linenum}
5159 Delete any breakpoints set at or within the code of the specified
5160 @var{linenum} of the specified @var{filename}.
5161 @end table
5162
5163 @cindex delete breakpoints
5164 @kindex delete
5165 @kindex d @r{(@code{delete})}
5166 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5167 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5168 list specified as argument. If no argument is specified, delete all
5169 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5170 confirm off}). You can abbreviate this command as @code{d}.
5171 @end table
5172
5173 @node Disabling
5174 @subsection Disabling Breakpoints
5175
5176 @cindex enable/disable a breakpoint
5177 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5178 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5179 it had been deleted, but remembers the information on the breakpoint so
5180 that you can @dfn{enable} it again later.
5181
5182 You disable and enable breakpoints, watchpoints, and catchpoints with
5183 the @code{enable} and @code{disable} commands, optionally specifying
5184 one or more breakpoint numbers as arguments. Use @code{info break} to
5185 print a list of all breakpoints, watchpoints, and catchpoints if you
5186 do not know which numbers to use.
5187
5188 Disabling and enabling a breakpoint that has multiple locations
5189 affects all of its locations.
5190
5191 A breakpoint, watchpoint, or catchpoint can have any of several
5192 different states of enablement:
5193
5194 @itemize @bullet
5195 @item
5196 Enabled. The breakpoint stops your program. A breakpoint set
5197 with the @code{break} command starts out in this state.
5198 @item
5199 Disabled. The breakpoint has no effect on your program.
5200 @item
5201 Enabled once. The breakpoint stops your program, but then becomes
5202 disabled.
5203 @item
5204 Enabled for a count. The breakpoint stops your program for the next
5205 N times, then becomes disabled.
5206 @item
5207 Enabled for deletion. The breakpoint stops your program, but
5208 immediately after it does so it is deleted permanently. A breakpoint
5209 set with the @code{tbreak} command starts out in this state.
5210 @end itemize
5211
5212 You can use the following commands to enable or disable breakpoints,
5213 watchpoints, and catchpoints:
5214
5215 @table @code
5216 @kindex disable
5217 @kindex dis @r{(@code{disable})}
5218 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5219 Disable the specified breakpoints---or all breakpoints, if none are
5220 listed. A disabled breakpoint has no effect but is not forgotten. All
5221 options such as ignore-counts, conditions and commands are remembered in
5222 case the breakpoint is enabled again later. You may abbreviate
5223 @code{disable} as @code{dis}.
5224
5225 @kindex enable
5226 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5227 Enable the specified breakpoints (or all defined breakpoints). They
5228 become effective once again in stopping your program.
5229
5230 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5231 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5232 of these breakpoints immediately after stopping your program.
5233
5234 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5235 Enable the specified breakpoints temporarily. @value{GDBN} records
5236 @var{count} with each of the specified breakpoints, and decrements a
5237 breakpoint's count when it is hit. When any count reaches 0,
5238 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5239 count (@pxref{Conditions, ,Break Conditions}), that will be
5240 decremented to 0 before @var{count} is affected.
5241
5242 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5243 Enable the specified breakpoints to work once, then die. @value{GDBN}
5244 deletes any of these breakpoints as soon as your program stops there.
5245 Breakpoints set by the @code{tbreak} command start out in this state.
5246 @end table
5247
5248 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5249 @c confusing: tbreak is also initially enabled.
5250 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5251 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5252 subsequently, they become disabled or enabled only when you use one of
5253 the commands above. (The command @code{until} can set and delete a
5254 breakpoint of its own, but it does not change the state of your other
5255 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5256 Stepping}.)
5257
5258 @node Conditions
5259 @subsection Break Conditions
5260 @cindex conditional breakpoints
5261 @cindex breakpoint conditions
5262
5263 @c FIXME what is scope of break condition expr? Context where wanted?
5264 @c in particular for a watchpoint?
5265 The simplest sort of breakpoint breaks every time your program reaches a
5266 specified place. You can also specify a @dfn{condition} for a
5267 breakpoint. A condition is just a Boolean expression in your
5268 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5269 a condition evaluates the expression each time your program reaches it,
5270 and your program stops only if the condition is @emph{true}.
5271
5272 This is the converse of using assertions for program validation; in that
5273 situation, you want to stop when the assertion is violated---that is,
5274 when the condition is false. In C, if you want to test an assertion expressed
5275 by the condition @var{assert}, you should set the condition
5276 @samp{! @var{assert}} on the appropriate breakpoint.
5277
5278 Conditions are also accepted for watchpoints; you may not need them,
5279 since a watchpoint is inspecting the value of an expression anyhow---but
5280 it might be simpler, say, to just set a watchpoint on a variable name,
5281 and specify a condition that tests whether the new value is an interesting
5282 one.
5283
5284 Break conditions can have side effects, and may even call functions in
5285 your program. This can be useful, for example, to activate functions
5286 that log program progress, or to use your own print functions to
5287 format special data structures. The effects are completely predictable
5288 unless there is another enabled breakpoint at the same address. (In
5289 that case, @value{GDBN} might see the other breakpoint first and stop your
5290 program without checking the condition of this one.) Note that
5291 breakpoint commands are usually more convenient and flexible than break
5292 conditions for the
5293 purpose of performing side effects when a breakpoint is reached
5294 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5295
5296 Breakpoint conditions can also be evaluated on the target's side if
5297 the target supports it. Instead of evaluating the conditions locally,
5298 @value{GDBN} encodes the expression into an agent expression
5299 (@pxref{Agent Expressions}) suitable for execution on the target,
5300 independently of @value{GDBN}. Global variables become raw memory
5301 locations, locals become stack accesses, and so forth.
5302
5303 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5304 when its condition evaluates to true. This mechanism may provide faster
5305 response times depending on the performance characteristics of the target
5306 since it does not need to keep @value{GDBN} informed about
5307 every breakpoint trigger, even those with false conditions.
5308
5309 Break conditions can be specified when a breakpoint is set, by using
5310 @samp{if} in the arguments to the @code{break} command. @xref{Set
5311 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5312 with the @code{condition} command.
5313
5314 You can also use the @code{if} keyword with the @code{watch} command.
5315 The @code{catch} command does not recognize the @code{if} keyword;
5316 @code{condition} is the only way to impose a further condition on a
5317 catchpoint.
5318
5319 @table @code
5320 @kindex condition
5321 @item condition @var{bnum} @var{expression}
5322 Specify @var{expression} as the break condition for breakpoint,
5323 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5324 breakpoint @var{bnum} stops your program only if the value of
5325 @var{expression} is true (nonzero, in C). When you use
5326 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5327 syntactic correctness, and to determine whether symbols in it have
5328 referents in the context of your breakpoint. If @var{expression} uses
5329 symbols not referenced in the context of the breakpoint, @value{GDBN}
5330 prints an error message:
5331
5332 @smallexample
5333 No symbol "foo" in current context.
5334 @end smallexample
5335
5336 @noindent
5337 @value{GDBN} does
5338 not actually evaluate @var{expression} at the time the @code{condition}
5339 command (or a command that sets a breakpoint with a condition, like
5340 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5341
5342 @item condition @var{bnum}
5343 Remove the condition from breakpoint number @var{bnum}. It becomes
5344 an ordinary unconditional breakpoint.
5345 @end table
5346
5347 @cindex ignore count (of breakpoint)
5348 A special case of a breakpoint condition is to stop only when the
5349 breakpoint has been reached a certain number of times. This is so
5350 useful that there is a special way to do it, using the @dfn{ignore
5351 count} of the breakpoint. Every breakpoint has an ignore count, which
5352 is an integer. Most of the time, the ignore count is zero, and
5353 therefore has no effect. But if your program reaches a breakpoint whose
5354 ignore count is positive, then instead of stopping, it just decrements
5355 the ignore count by one and continues. As a result, if the ignore count
5356 value is @var{n}, the breakpoint does not stop the next @var{n} times
5357 your program reaches it.
5358
5359 @table @code
5360 @kindex ignore
5361 @item ignore @var{bnum} @var{count}
5362 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5363 The next @var{count} times the breakpoint is reached, your program's
5364 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5365 takes no action.
5366
5367 To make the breakpoint stop the next time it is reached, specify
5368 a count of zero.
5369
5370 When you use @code{continue} to resume execution of your program from a
5371 breakpoint, you can specify an ignore count directly as an argument to
5372 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5373 Stepping,,Continuing and Stepping}.
5374
5375 If a breakpoint has a positive ignore count and a condition, the
5376 condition is not checked. Once the ignore count reaches zero,
5377 @value{GDBN} resumes checking the condition.
5378
5379 You could achieve the effect of the ignore count with a condition such
5380 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5381 is decremented each time. @xref{Convenience Vars, ,Convenience
5382 Variables}.
5383 @end table
5384
5385 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5386
5387
5388 @node Break Commands
5389 @subsection Breakpoint Command Lists
5390
5391 @cindex breakpoint commands
5392 You can give any breakpoint (or watchpoint or catchpoint) a series of
5393 commands to execute when your program stops due to that breakpoint. For
5394 example, you might want to print the values of certain expressions, or
5395 enable other breakpoints.
5396
5397 @table @code
5398 @kindex commands
5399 @kindex end@r{ (breakpoint commands)}
5400 @item commands @r{[}@var{list}@dots{}@r{]}
5401 @itemx @dots{} @var{command-list} @dots{}
5402 @itemx end
5403 Specify a list of commands for the given breakpoints. The commands
5404 themselves appear on the following lines. Type a line containing just
5405 @code{end} to terminate the commands.
5406
5407 To remove all commands from a breakpoint, type @code{commands} and
5408 follow it immediately with @code{end}; that is, give no commands.
5409
5410 With no argument, @code{commands} refers to the last breakpoint,
5411 watchpoint, or catchpoint set (not to the breakpoint most recently
5412 encountered). If the most recent breakpoints were set with a single
5413 command, then the @code{commands} will apply to all the breakpoints
5414 set by that command. This applies to breakpoints set by
5415 @code{rbreak}, and also applies when a single @code{break} command
5416 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5417 Expressions}).
5418 @end table
5419
5420 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5421 disabled within a @var{command-list}.
5422
5423 You can use breakpoint commands to start your program up again. Simply
5424 use the @code{continue} command, or @code{step}, or any other command
5425 that resumes execution.
5426
5427 Any other commands in the command list, after a command that resumes
5428 execution, are ignored. This is because any time you resume execution
5429 (even with a simple @code{next} or @code{step}), you may encounter
5430 another breakpoint---which could have its own command list, leading to
5431 ambiguities about which list to execute.
5432
5433 @kindex silent
5434 If the first command you specify in a command list is @code{silent}, the
5435 usual message about stopping at a breakpoint is not printed. This may
5436 be desirable for breakpoints that are to print a specific message and
5437 then continue. If none of the remaining commands print anything, you
5438 see no sign that the breakpoint was reached. @code{silent} is
5439 meaningful only at the beginning of a breakpoint command list.
5440
5441 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5442 print precisely controlled output, and are often useful in silent
5443 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5444
5445 For example, here is how you could use breakpoint commands to print the
5446 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5447
5448 @smallexample
5449 break foo if x>0
5450 commands
5451 silent
5452 printf "x is %d\n",x
5453 cont
5454 end
5455 @end smallexample
5456
5457 One application for breakpoint commands is to compensate for one bug so
5458 you can test for another. Put a breakpoint just after the erroneous line
5459 of code, give it a condition to detect the case in which something
5460 erroneous has been done, and give it commands to assign correct values
5461 to any variables that need them. End with the @code{continue} command
5462 so that your program does not stop, and start with the @code{silent}
5463 command so that no output is produced. Here is an example:
5464
5465 @smallexample
5466 break 403
5467 commands
5468 silent
5469 set x = y + 4
5470 cont
5471 end
5472 @end smallexample
5473
5474 @node Dynamic Printf
5475 @subsection Dynamic Printf
5476
5477 @cindex dynamic printf
5478 @cindex dprintf
5479 The dynamic printf command @code{dprintf} combines a breakpoint with
5480 formatted printing of your program's data to give you the effect of
5481 inserting @code{printf} calls into your program on-the-fly, without
5482 having to recompile it.
5483
5484 In its most basic form, the output goes to the GDB console. However,
5485 you can set the variable @code{dprintf-style} for alternate handling.
5486 For instance, you can ask to format the output by calling your
5487 program's @code{printf} function. This has the advantage that the
5488 characters go to the program's output device, so they can recorded in
5489 redirects to files and so forth.
5490
5491 If you are doing remote debugging with a stub or agent, you can also
5492 ask to have the printf handled by the remote agent. In addition to
5493 ensuring that the output goes to the remote program's device along
5494 with any other output the program might produce, you can also ask that
5495 the dprintf remain active even after disconnecting from the remote
5496 target. Using the stub/agent is also more efficient, as it can do
5497 everything without needing to communicate with @value{GDBN}.
5498
5499 @table @code
5500 @kindex dprintf
5501 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5502 Whenever execution reaches @var{location}, print the values of one or
5503 more @var{expressions} under the control of the string @var{template}.
5504 To print several values, separate them with commas.
5505
5506 @item set dprintf-style @var{style}
5507 Set the dprintf output to be handled in one of several different
5508 styles enumerated below. A change of style affects all existing
5509 dynamic printfs immediately. (If you need individual control over the
5510 print commands, simply define normal breakpoints with
5511 explicitly-supplied command lists.)
5512
5513 @table @code
5514 @item gdb
5515 @kindex dprintf-style gdb
5516 Handle the output using the @value{GDBN} @code{printf} command.
5517
5518 @item call
5519 @kindex dprintf-style call
5520 Handle the output by calling a function in your program (normally
5521 @code{printf}).
5522
5523 @item agent
5524 @kindex dprintf-style agent
5525 Have the remote debugging agent (such as @code{gdbserver}) handle
5526 the output itself. This style is only available for agents that
5527 support running commands on the target.
5528 @end table
5529
5530 @item set dprintf-function @var{function}
5531 Set the function to call if the dprintf style is @code{call}. By
5532 default its value is @code{printf}. You may set it to any expression.
5533 that @value{GDBN} can evaluate to a function, as per the @code{call}
5534 command.
5535
5536 @item set dprintf-channel @var{channel}
5537 Set a ``channel'' for dprintf. If set to a non-empty value,
5538 @value{GDBN} will evaluate it as an expression and pass the result as
5539 a first argument to the @code{dprintf-function}, in the manner of
5540 @code{fprintf} and similar functions. Otherwise, the dprintf format
5541 string will be the first argument, in the manner of @code{printf}.
5542
5543 As an example, if you wanted @code{dprintf} output to go to a logfile
5544 that is a standard I/O stream assigned to the variable @code{mylog},
5545 you could do the following:
5546
5547 @example
5548 (gdb) set dprintf-style call
5549 (gdb) set dprintf-function fprintf
5550 (gdb) set dprintf-channel mylog
5551 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5552 Dprintf 1 at 0x123456: file main.c, line 25.
5553 (gdb) info break
5554 1 dprintf keep y 0x00123456 in main at main.c:25
5555 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5556 continue
5557 (gdb)
5558 @end example
5559
5560 Note that the @code{info break} displays the dynamic printf commands
5561 as normal breakpoint commands; you can thus easily see the effect of
5562 the variable settings.
5563
5564 @item set disconnected-dprintf on
5565 @itemx set disconnected-dprintf off
5566 @kindex set disconnected-dprintf
5567 Choose whether @code{dprintf} commands should continue to run if
5568 @value{GDBN} has disconnected from the target. This only applies
5569 if the @code{dprintf-style} is @code{agent}.
5570
5571 @item show disconnected-dprintf off
5572 @kindex show disconnected-dprintf
5573 Show the current choice for disconnected @code{dprintf}.
5574
5575 @end table
5576
5577 @value{GDBN} does not check the validity of function and channel,
5578 relying on you to supply values that are meaningful for the contexts
5579 in which they are being used. For instance, the function and channel
5580 may be the values of local variables, but if that is the case, then
5581 all enabled dynamic prints must be at locations within the scope of
5582 those locals. If evaluation fails, @value{GDBN} will report an error.
5583
5584 @node Save Breakpoints
5585 @subsection How to save breakpoints to a file
5586
5587 To save breakpoint definitions to a file use the @w{@code{save
5588 breakpoints}} command.
5589
5590 @table @code
5591 @kindex save breakpoints
5592 @cindex save breakpoints to a file for future sessions
5593 @item save breakpoints [@var{filename}]
5594 This command saves all current breakpoint definitions together with
5595 their commands and ignore counts, into a file @file{@var{filename}}
5596 suitable for use in a later debugging session. This includes all
5597 types of breakpoints (breakpoints, watchpoints, catchpoints,
5598 tracepoints). To read the saved breakpoint definitions, use the
5599 @code{source} command (@pxref{Command Files}). Note that watchpoints
5600 with expressions involving local variables may fail to be recreated
5601 because it may not be possible to access the context where the
5602 watchpoint is valid anymore. Because the saved breakpoint definitions
5603 are simply a sequence of @value{GDBN} commands that recreate the
5604 breakpoints, you can edit the file in your favorite editing program,
5605 and remove the breakpoint definitions you're not interested in, or
5606 that can no longer be recreated.
5607 @end table
5608
5609 @node Static Probe Points
5610 @subsection Static Probe Points
5611
5612 @cindex static probe point, SystemTap
5613 @cindex static probe point, DTrace
5614 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5615 for Statically Defined Tracing, and the probes are designed to have a tiny
5616 runtime code and data footprint, and no dynamic relocations.
5617
5618 Currently, the following types of probes are supported on
5619 ELF-compatible systems:
5620
5621 @itemize @bullet
5622
5623 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5624 @acronym{SDT} probes@footnote{See
5625 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5626 for more information on how to add @code{SystemTap} @acronym{SDT}
5627 probes in your applications.}. @code{SystemTap} probes are usable
5628 from assembly, C and C@t{++} languages@footnote{See
5629 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5630 for a good reference on how the @acronym{SDT} probes are implemented.}.
5631
5632 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5633 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5634 C@t{++} languages.
5635 @end itemize
5636
5637 @cindex semaphores on static probe points
5638 Some @code{SystemTap} probes have an associated semaphore variable;
5639 for instance, this happens automatically if you defined your probe
5640 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5641 @value{GDBN} will automatically enable it when you specify a
5642 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5643 breakpoint at a probe's location by some other method (e.g.,
5644 @code{break file:line}), then @value{GDBN} will not automatically set
5645 the semaphore. @code{DTrace} probes do not support semaphores.
5646
5647 You can examine the available static static probes using @code{info
5648 probes}, with optional arguments:
5649
5650 @table @code
5651 @kindex info probes
5652 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5653 If given, @var{type} is either @code{stap} for listing
5654 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5655 probes. If omitted all probes are listed regardless of their types.
5656
5657 If given, @var{provider} is a regular expression used to match against provider
5658 names when selecting which probes to list. If omitted, probes by all
5659 probes from all providers are listed.
5660
5661 If given, @var{name} is a regular expression to match against probe names
5662 when selecting which probes to list. If omitted, probe names are not
5663 considered when deciding whether to display them.
5664
5665 If given, @var{objfile} is a regular expression used to select which
5666 object files (executable or shared libraries) to examine. If not
5667 given, all object files are considered.
5668
5669 @item info probes all
5670 List the available static probes, from all types.
5671 @end table
5672
5673 @cindex enabling and disabling probes
5674 Some probe points can be enabled and/or disabled. The effect of
5675 enabling or disabling a probe depends on the type of probe being
5676 handled. Some @code{DTrace} probes can be enabled or
5677 disabled, but @code{SystemTap} probes cannot be disabled.
5678
5679 You can enable (or disable) one or more probes using the following
5680 commands, with optional arguments:
5681
5682 @table @code
5683 @kindex enable probes
5684 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5685 If given, @var{provider} is a regular expression used to match against
5686 provider names when selecting which probes to enable. If omitted,
5687 all probes from all providers are enabled.
5688
5689 If given, @var{name} is a regular expression to match against probe
5690 names when selecting which probes to enable. If omitted, probe names
5691 are not considered when deciding whether to enable them.
5692
5693 If given, @var{objfile} is a regular expression used to select which
5694 object files (executable or shared libraries) to examine. If not
5695 given, all object files are considered.
5696
5697 @kindex disable probes
5698 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5699 See the @code{enable probes} command above for a description of the
5700 optional arguments accepted by this command.
5701 @end table
5702
5703 @vindex $_probe_arg@r{, convenience variable}
5704 A probe may specify up to twelve arguments. These are available at the
5705 point at which the probe is defined---that is, when the current PC is
5706 at the probe's location. The arguments are available using the
5707 convenience variables (@pxref{Convenience Vars})
5708 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5709 probes each probe argument is an integer of the appropriate size;
5710 types are not preserved. In @code{DTrace} probes types are preserved
5711 provided that they are recognized as such by @value{GDBN}; otherwise
5712 the value of the probe argument will be a long integer. The
5713 convenience variable @code{$_probe_argc} holds the number of arguments
5714 at the current probe point.
5715
5716 These variables are always available, but attempts to access them at
5717 any location other than a probe point will cause @value{GDBN} to give
5718 an error message.
5719
5720
5721 @c @ifclear BARETARGET
5722 @node Error in Breakpoints
5723 @subsection ``Cannot insert breakpoints''
5724
5725 If you request too many active hardware-assisted breakpoints and
5726 watchpoints, you will see this error message:
5727
5728 @c FIXME: the precise wording of this message may change; the relevant
5729 @c source change is not committed yet (Sep 3, 1999).
5730 @smallexample
5731 Stopped; cannot insert breakpoints.
5732 You may have requested too many hardware breakpoints and watchpoints.
5733 @end smallexample
5734
5735 @noindent
5736 This message is printed when you attempt to resume the program, since
5737 only then @value{GDBN} knows exactly how many hardware breakpoints and
5738 watchpoints it needs to insert.
5739
5740 When this message is printed, you need to disable or remove some of the
5741 hardware-assisted breakpoints and watchpoints, and then continue.
5742
5743 @node Breakpoint-related Warnings
5744 @subsection ``Breakpoint address adjusted...''
5745 @cindex breakpoint address adjusted
5746
5747 Some processor architectures place constraints on the addresses at
5748 which breakpoints may be placed. For architectures thus constrained,
5749 @value{GDBN} will attempt to adjust the breakpoint's address to comply
5750 with the constraints dictated by the architecture.
5751
5752 One example of such an architecture is the Fujitsu FR-V. The FR-V is
5753 a VLIW architecture in which a number of RISC-like instructions may be
5754 bundled together for parallel execution. The FR-V architecture
5755 constrains the location of a breakpoint instruction within such a
5756 bundle to the instruction with the lowest address. @value{GDBN}
5757 honors this constraint by adjusting a breakpoint's address to the
5758 first in the bundle.
5759
5760 It is not uncommon for optimized code to have bundles which contain
5761 instructions from different source statements, thus it may happen that
5762 a breakpoint's address will be adjusted from one source statement to
5763 another. Since this adjustment may significantly alter @value{GDBN}'s
5764 breakpoint related behavior from what the user expects, a warning is
5765 printed when the breakpoint is first set and also when the breakpoint
5766 is hit.
5767
5768 A warning like the one below is printed when setting a breakpoint
5769 that's been subject to address adjustment:
5770
5771 @smallexample
5772 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5773 @end smallexample
5774
5775 Such warnings are printed both for user settable and @value{GDBN}'s
5776 internal breakpoints. If you see one of these warnings, you should
5777 verify that a breakpoint set at the adjusted address will have the
5778 desired affect. If not, the breakpoint in question may be removed and
5779 other breakpoints may be set which will have the desired behavior.
5780 E.g., it may be sufficient to place the breakpoint at a later
5781 instruction. A conditional breakpoint may also be useful in some
5782 cases to prevent the breakpoint from triggering too often.
5783
5784 @value{GDBN} will also issue a warning when stopping at one of these
5785 adjusted breakpoints:
5786
5787 @smallexample
5788 warning: Breakpoint 1 address previously adjusted from 0x00010414
5789 to 0x00010410.
5790 @end smallexample
5791
5792 When this warning is encountered, it may be too late to take remedial
5793 action except in cases where the breakpoint is hit earlier or more
5794 frequently than expected.
5795
5796 @node Continuing and Stepping
5797 @section Continuing and Stepping
5798
5799 @cindex stepping
5800 @cindex continuing
5801 @cindex resuming execution
5802 @dfn{Continuing} means resuming program execution until your program
5803 completes normally. In contrast, @dfn{stepping} means executing just
5804 one more ``step'' of your program, where ``step'' may mean either one
5805 line of source code, or one machine instruction (depending on what
5806 particular command you use). Either when continuing or when stepping,
5807 your program may stop even sooner, due to a breakpoint or a signal. (If
5808 it stops due to a signal, you may want to use @code{handle}, or use
5809 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5810 or you may step into the signal's handler (@pxref{stepping and signal
5811 handlers}).)
5812
5813 @table @code
5814 @kindex continue
5815 @kindex c @r{(@code{continue})}
5816 @kindex fg @r{(resume foreground execution)}
5817 @item continue @r{[}@var{ignore-count}@r{]}
5818 @itemx c @r{[}@var{ignore-count}@r{]}
5819 @itemx fg @r{[}@var{ignore-count}@r{]}
5820 Resume program execution, at the address where your program last stopped;
5821 any breakpoints set at that address are bypassed. The optional argument
5822 @var{ignore-count} allows you to specify a further number of times to
5823 ignore a breakpoint at this location; its effect is like that of
5824 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
5825
5826 The argument @var{ignore-count} is meaningful only when your program
5827 stopped due to a breakpoint. At other times, the argument to
5828 @code{continue} is ignored.
5829
5830 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5831 debugged program is deemed to be the foreground program) are provided
5832 purely for convenience, and have exactly the same behavior as
5833 @code{continue}.
5834 @end table
5835
5836 To resume execution at a different place, you can use @code{return}
5837 (@pxref{Returning, ,Returning from a Function}) to go back to the
5838 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
5839 Different Address}) to go to an arbitrary location in your program.
5840
5841 A typical technique for using stepping is to set a breakpoint
5842 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
5843 beginning of the function or the section of your program where a problem
5844 is believed to lie, run your program until it stops at that breakpoint,
5845 and then step through the suspect area, examining the variables that are
5846 interesting, until you see the problem happen.
5847
5848 @table @code
5849 @kindex step
5850 @kindex s @r{(@code{step})}
5851 @item step
5852 Continue running your program until control reaches a different source
5853 line, then stop it and return control to @value{GDBN}. This command is
5854 abbreviated @code{s}.
5855
5856 @quotation
5857 @c "without debugging information" is imprecise; actually "without line
5858 @c numbers in the debugging information". (gcc -g1 has debugging info but
5859 @c not line numbers). But it seems complex to try to make that
5860 @c distinction here.
5861 @emph{Warning:} If you use the @code{step} command while control is
5862 within a function that was compiled without debugging information,
5863 execution proceeds until control reaches a function that does have
5864 debugging information. Likewise, it will not step into a function which
5865 is compiled without debugging information. To step through functions
5866 without debugging information, use the @code{stepi} command, described
5867 below.
5868 @end quotation
5869
5870 The @code{step} command only stops at the first instruction of a source
5871 line. This prevents the multiple stops that could otherwise occur in
5872 @code{switch} statements, @code{for} loops, etc. @code{step} continues
5873 to stop if a function that has debugging information is called within
5874 the line. In other words, @code{step} @emph{steps inside} any functions
5875 called within the line.
5876
5877 Also, the @code{step} command only enters a function if there is line
5878 number information for the function. Otherwise it acts like the
5879 @code{next} command. This avoids problems when using @code{cc -gl}
5880 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5881 was any debugging information about the routine.
5882
5883 @item step @var{count}
5884 Continue running as in @code{step}, but do so @var{count} times. If a
5885 breakpoint is reached, or a signal not related to stepping occurs before
5886 @var{count} steps, stepping stops right away.
5887
5888 @kindex next
5889 @kindex n @r{(@code{next})}
5890 @item next @r{[}@var{count}@r{]}
5891 Continue to the next source line in the current (innermost) stack frame.
5892 This is similar to @code{step}, but function calls that appear within
5893 the line of code are executed without stopping. Execution stops when
5894 control reaches a different line of code at the original stack level
5895 that was executing when you gave the @code{next} command. This command
5896 is abbreviated @code{n}.
5897
5898 An argument @var{count} is a repeat count, as for @code{step}.
5899
5900
5901 @c FIX ME!! Do we delete this, or is there a way it fits in with
5902 @c the following paragraph? --- Vctoria
5903 @c
5904 @c @code{next} within a function that lacks debugging information acts like
5905 @c @code{step}, but any function calls appearing within the code of the
5906 @c function are executed without stopping.
5907
5908 The @code{next} command only stops at the first instruction of a
5909 source line. This prevents multiple stops that could otherwise occur in
5910 @code{switch} statements, @code{for} loops, etc.
5911
5912 @kindex set step-mode
5913 @item set step-mode
5914 @cindex functions without line info, and stepping
5915 @cindex stepping into functions with no line info
5916 @itemx set step-mode on
5917 The @code{set step-mode on} command causes the @code{step} command to
5918 stop at the first instruction of a function which contains no debug line
5919 information rather than stepping over it.
5920
5921 This is useful in cases where you may be interested in inspecting the
5922 machine instructions of a function which has no symbolic info and do not
5923 want @value{GDBN} to automatically skip over this function.
5924
5925 @item set step-mode off
5926 Causes the @code{step} command to step over any functions which contains no
5927 debug information. This is the default.
5928
5929 @item show step-mode
5930 Show whether @value{GDBN} will stop in or step over functions without
5931 source line debug information.
5932
5933 @kindex finish
5934 @kindex fin @r{(@code{finish})}
5935 @item finish
5936 Continue running until just after function in the selected stack frame
5937 returns. Print the returned value (if any). This command can be
5938 abbreviated as @code{fin}.
5939
5940 Contrast this with the @code{return} command (@pxref{Returning,
5941 ,Returning from a Function}).
5942
5943 @kindex set print finish
5944 @kindex show print finish
5945 @item set print finish @r{[}on|off@r{]}
5946 @itemx show print finish
5947 By default the @code{finish} command will show the value that is
5948 returned by the function. This can be disabled using @code{set print
5949 finish off}. When disabled, the value is still entered into the value
5950 history (@pxref{Value History}), but not displayed.
5951
5952 @kindex until
5953 @kindex u @r{(@code{until})}
5954 @cindex run until specified location
5955 @item until
5956 @itemx u
5957 Continue running until a source line past the current line, in the
5958 current stack frame, is reached. This command is used to avoid single
5959 stepping through a loop more than once. It is like the @code{next}
5960 command, except that when @code{until} encounters a jump, it
5961 automatically continues execution until the program counter is greater
5962 than the address of the jump.
5963
5964 This means that when you reach the end of a loop after single stepping
5965 though it, @code{until} makes your program continue execution until it
5966 exits the loop. In contrast, a @code{next} command at the end of a loop
5967 simply steps back to the beginning of the loop, which forces you to step
5968 through the next iteration.
5969
5970 @code{until} always stops your program if it attempts to exit the current
5971 stack frame.
5972
5973 @code{until} may produce somewhat counterintuitive results if the order
5974 of machine code does not match the order of the source lines. For
5975 example, in the following excerpt from a debugging session, the @code{f}
5976 (@code{frame}) command shows that execution is stopped at line
5977 @code{206}; yet when we use @code{until}, we get to line @code{195}:
5978
5979 @smallexample
5980 (@value{GDBP}) f
5981 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5982 206 expand_input();
5983 (@value{GDBP}) until
5984 195 for ( ; argc > 0; NEXTARG) @{
5985 @end smallexample
5986
5987 This happened because, for execution efficiency, the compiler had
5988 generated code for the loop closure test at the end, rather than the
5989 start, of the loop---even though the test in a C @code{for}-loop is
5990 written before the body of the loop. The @code{until} command appeared
5991 to step back to the beginning of the loop when it advanced to this
5992 expression; however, it has not really gone to an earlier
5993 statement---not in terms of the actual machine code.
5994
5995 @code{until} with no argument works by means of single
5996 instruction stepping, and hence is slower than @code{until} with an
5997 argument.
5998
5999 @item until @var{location}
6000 @itemx u @var{location}
6001 Continue running your program until either the specified @var{location} is
6002 reached, or the current stack frame returns. The location is any of
6003 the forms described in @ref{Specify Location}.
6004 This form of the command uses temporary breakpoints, and
6005 hence is quicker than @code{until} without an argument. The specified
6006 location is actually reached only if it is in the current frame. This
6007 implies that @code{until} can be used to skip over recursive function
6008 invocations. For instance in the code below, if the current location is
6009 line @code{96}, issuing @code{until 99} will execute the program up to
6010 line @code{99} in the same invocation of factorial, i.e., after the inner
6011 invocations have returned.
6012
6013 @smallexample
6014 94 int factorial (int value)
6015 95 @{
6016 96 if (value > 1) @{
6017 97 value *= factorial (value - 1);
6018 98 @}
6019 99 return (value);
6020 100 @}
6021 @end smallexample
6022
6023
6024 @kindex advance @var{location}
6025 @item advance @var{location}
6026 Continue running the program up to the given @var{location}. An argument is
6027 required, which should be of one of the forms described in
6028 @ref{Specify Location}.
6029 Execution will also stop upon exit from the current stack
6030 frame. This command is similar to @code{until}, but @code{advance} will
6031 not skip over recursive function calls, and the target location doesn't
6032 have to be in the same frame as the current one.
6033
6034
6035 @kindex stepi
6036 @kindex si @r{(@code{stepi})}
6037 @item stepi
6038 @itemx stepi @var{arg}
6039 @itemx si
6040 Execute one machine instruction, then stop and return to the debugger.
6041
6042 It is often useful to do @samp{display/i $pc} when stepping by machine
6043 instructions. This makes @value{GDBN} automatically display the next
6044 instruction to be executed, each time your program stops. @xref{Auto
6045 Display,, Automatic Display}.
6046
6047 An argument is a repeat count, as in @code{step}.
6048
6049 @need 750
6050 @kindex nexti
6051 @kindex ni @r{(@code{nexti})}
6052 @item nexti
6053 @itemx nexti @var{arg}
6054 @itemx ni
6055 Execute one machine instruction, but if it is a function call,
6056 proceed until the function returns.
6057
6058 An argument is a repeat count, as in @code{next}.
6059
6060 @end table
6061
6062 @anchor{range stepping}
6063 @cindex range stepping
6064 @cindex target-assisted range stepping
6065 By default, and if available, @value{GDBN} makes use of
6066 target-assisted @dfn{range stepping}. In other words, whenever you
6067 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6068 tells the target to step the corresponding range of instruction
6069 addresses instead of issuing multiple single-steps. This speeds up
6070 line stepping, particularly for remote targets. Ideally, there should
6071 be no reason you would want to turn range stepping off. However, it's
6072 possible that a bug in the debug info, a bug in the remote stub (for
6073 remote targets), or even a bug in @value{GDBN} could make line
6074 stepping behave incorrectly when target-assisted range stepping is
6075 enabled. You can use the following command to turn off range stepping
6076 if necessary:
6077
6078 @table @code
6079 @kindex set range-stepping
6080 @kindex show range-stepping
6081 @item set range-stepping
6082 @itemx show range-stepping
6083 Control whether range stepping is enabled.
6084
6085 If @code{on}, and the target supports it, @value{GDBN} tells the
6086 target to step a range of addresses itself, instead of issuing
6087 multiple single-steps. If @code{off}, @value{GDBN} always issues
6088 single-steps, even if range stepping is supported by the target. The
6089 default is @code{on}.
6090
6091 @end table
6092
6093 @node Skipping Over Functions and Files
6094 @section Skipping Over Functions and Files
6095 @cindex skipping over functions and files
6096
6097 The program you are debugging may contain some functions which are
6098 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6099 skip a function, all functions in a file or a particular function in
6100 a particular file when stepping.
6101
6102 For example, consider the following C function:
6103
6104 @smallexample
6105 101 int func()
6106 102 @{
6107 103 foo(boring());
6108 104 bar(boring());
6109 105 @}
6110 @end smallexample
6111
6112 @noindent
6113 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6114 are not interested in stepping through @code{boring}. If you run @code{step}
6115 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6116 step over both @code{foo} and @code{boring}!
6117
6118 One solution is to @code{step} into @code{boring} and use the @code{finish}
6119 command to immediately exit it. But this can become tedious if @code{boring}
6120 is called from many places.
6121
6122 A more flexible solution is to execute @kbd{skip boring}. This instructs
6123 @value{GDBN} never to step into @code{boring}. Now when you execute
6124 @code{step} at line 103, you'll step over @code{boring} and directly into
6125 @code{foo}.
6126
6127 Functions may be skipped by providing either a function name, linespec
6128 (@pxref{Specify Location}), regular expression that matches the function's
6129 name, file name or a @code{glob}-style pattern that matches the file name.
6130
6131 On Posix systems the form of the regular expression is
6132 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6133 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6134 expression is whatever is provided by the @code{regcomp} function of
6135 the underlying system.
6136 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6137 description of @code{glob}-style patterns.
6138
6139 @table @code
6140 @kindex skip
6141 @item skip @r{[}@var{options}@r{]}
6142 The basic form of the @code{skip} command takes zero or more options
6143 that specify what to skip.
6144 The @var{options} argument is any useful combination of the following:
6145
6146 @table @code
6147 @item -file @var{file}
6148 @itemx -fi @var{file}
6149 Functions in @var{file} will be skipped over when stepping.
6150
6151 @item -gfile @var{file-glob-pattern}
6152 @itemx -gfi @var{file-glob-pattern}
6153 @cindex skipping over files via glob-style patterns
6154 Functions in files matching @var{file-glob-pattern} will be skipped
6155 over when stepping.
6156
6157 @smallexample
6158 (gdb) skip -gfi utils/*.c
6159 @end smallexample
6160
6161 @item -function @var{linespec}
6162 @itemx -fu @var{linespec}
6163 Functions named by @var{linespec} or the function containing the line
6164 named by @var{linespec} will be skipped over when stepping.
6165 @xref{Specify Location}.
6166
6167 @item -rfunction @var{regexp}
6168 @itemx -rfu @var{regexp}
6169 @cindex skipping over functions via regular expressions
6170 Functions whose name matches @var{regexp} will be skipped over when stepping.
6171
6172 This form is useful for complex function names.
6173 For example, there is generally no need to step into C@t{++} @code{std::string}
6174 constructors or destructors. Plus with C@t{++} templates it can be hard to
6175 write out the full name of the function, and often it doesn't matter what
6176 the template arguments are. Specifying the function to be skipped as a
6177 regular expression makes this easier.
6178
6179 @smallexample
6180 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6181 @end smallexample
6182
6183 If you want to skip every templated C@t{++} constructor and destructor
6184 in the @code{std} namespace you can do:
6185
6186 @smallexample
6187 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6188 @end smallexample
6189 @end table
6190
6191 If no options are specified, the function you're currently debugging
6192 will be skipped.
6193
6194 @kindex skip function
6195 @item skip function @r{[}@var{linespec}@r{]}
6196 After running this command, the function named by @var{linespec} or the
6197 function containing the line named by @var{linespec} will be skipped over when
6198 stepping. @xref{Specify Location}.
6199
6200 If you do not specify @var{linespec}, the function you're currently debugging
6201 will be skipped.
6202
6203 (If you have a function called @code{file} that you want to skip, use
6204 @kbd{skip function file}.)
6205
6206 @kindex skip file
6207 @item skip file @r{[}@var{filename}@r{]}
6208 After running this command, any function whose source lives in @var{filename}
6209 will be skipped over when stepping.
6210
6211 @smallexample
6212 (gdb) skip file boring.c
6213 File boring.c will be skipped when stepping.
6214 @end smallexample
6215
6216 If you do not specify @var{filename}, functions whose source lives in the file
6217 you're currently debugging will be skipped.
6218 @end table
6219
6220 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6221 These are the commands for managing your list of skips:
6222
6223 @table @code
6224 @kindex info skip
6225 @item info skip @r{[}@var{range}@r{]}
6226 Print details about the specified skip(s). If @var{range} is not specified,
6227 print a table with details about all functions and files marked for skipping.
6228 @code{info skip} prints the following information about each skip:
6229
6230 @table @emph
6231 @item Identifier
6232 A number identifying this skip.
6233 @item Enabled or Disabled
6234 Enabled skips are marked with @samp{y}.
6235 Disabled skips are marked with @samp{n}.
6236 @item Glob
6237 If the file name is a @samp{glob} pattern this is @samp{y}.
6238 Otherwise it is @samp{n}.
6239 @item File
6240 The name or @samp{glob} pattern of the file to be skipped.
6241 If no file is specified this is @samp{<none>}.
6242 @item RE
6243 If the function name is a @samp{regular expression} this is @samp{y}.
6244 Otherwise it is @samp{n}.
6245 @item Function
6246 The name or regular expression of the function to skip.
6247 If no function is specified this is @samp{<none>}.
6248 @end table
6249
6250 @kindex skip delete
6251 @item skip delete @r{[}@var{range}@r{]}
6252 Delete the specified skip(s). If @var{range} is not specified, delete all
6253 skips.
6254
6255 @kindex skip enable
6256 @item skip enable @r{[}@var{range}@r{]}
6257 Enable the specified skip(s). If @var{range} is not specified, enable all
6258 skips.
6259
6260 @kindex skip disable
6261 @item skip disable @r{[}@var{range}@r{]}
6262 Disable the specified skip(s). If @var{range} is not specified, disable all
6263 skips.
6264
6265 @kindex set debug skip
6266 @item set debug skip @r{[}on|off@r{]}
6267 Set whether to print the debug output about skipping files and functions.
6268
6269 @kindex show debug skip
6270 @item show debug skip
6271 Show whether the debug output about skipping files and functions is printed.
6272
6273 @end table
6274
6275 @node Signals
6276 @section Signals
6277 @cindex signals
6278
6279 A signal is an asynchronous event that can happen in a program. The
6280 operating system defines the possible kinds of signals, and gives each
6281 kind a name and a number. For example, in Unix @code{SIGINT} is the
6282 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6283 @code{SIGSEGV} is the signal a program gets from referencing a place in
6284 memory far away from all the areas in use; @code{SIGALRM} occurs when
6285 the alarm clock timer goes off (which happens only if your program has
6286 requested an alarm).
6287
6288 @cindex fatal signals
6289 Some signals, including @code{SIGALRM}, are a normal part of the
6290 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6291 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6292 program has not specified in advance some other way to handle the signal.
6293 @code{SIGINT} does not indicate an error in your program, but it is normally
6294 fatal so it can carry out the purpose of the interrupt: to kill the program.
6295
6296 @value{GDBN} has the ability to detect any occurrence of a signal in your
6297 program. You can tell @value{GDBN} in advance what to do for each kind of
6298 signal.
6299
6300 @cindex handling signals
6301 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6302 @code{SIGALRM} be silently passed to your program
6303 (so as not to interfere with their role in the program's functioning)
6304 but to stop your program immediately whenever an error signal happens.
6305 You can change these settings with the @code{handle} command.
6306
6307 @table @code
6308 @kindex info signals
6309 @kindex info handle
6310 @item info signals
6311 @itemx info handle
6312 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6313 handle each one. You can use this to see the signal numbers of all
6314 the defined types of signals.
6315
6316 @item info signals @var{sig}
6317 Similar, but print information only about the specified signal number.
6318
6319 @code{info handle} is an alias for @code{info signals}.
6320
6321 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6322 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6323 for details about this command.
6324
6325 @kindex handle
6326 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6327 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6328 can be the number of a signal or its name (with or without the
6329 @samp{SIG} at the beginning); a list of signal numbers of the form
6330 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6331 known signals. Optional arguments @var{keywords}, described below,
6332 say what change to make.
6333 @end table
6334
6335 @c @group
6336 The keywords allowed by the @code{handle} command can be abbreviated.
6337 Their full names are:
6338
6339 @table @code
6340 @item nostop
6341 @value{GDBN} should not stop your program when this signal happens. It may
6342 still print a message telling you that the signal has come in.
6343
6344 @item stop
6345 @value{GDBN} should stop your program when this signal happens. This implies
6346 the @code{print} keyword as well.
6347
6348 @item print
6349 @value{GDBN} should print a message when this signal happens.
6350
6351 @item noprint
6352 @value{GDBN} should not mention the occurrence of the signal at all. This
6353 implies the @code{nostop} keyword as well.
6354
6355 @item pass
6356 @itemx noignore
6357 @value{GDBN} should allow your program to see this signal; your program
6358 can handle the signal, or else it may terminate if the signal is fatal
6359 and not handled. @code{pass} and @code{noignore} are synonyms.
6360
6361 @item nopass
6362 @itemx ignore
6363 @value{GDBN} should not allow your program to see this signal.
6364 @code{nopass} and @code{ignore} are synonyms.
6365 @end table
6366 @c @end group
6367
6368 When a signal stops your program, the signal is not visible to the
6369 program until you
6370 continue. Your program sees the signal then, if @code{pass} is in
6371 effect for the signal in question @emph{at that time}. In other words,
6372 after @value{GDBN} reports a signal, you can use the @code{handle}
6373 command with @code{pass} or @code{nopass} to control whether your
6374 program sees that signal when you continue.
6375
6376 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6377 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6378 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6379 erroneous signals.
6380
6381 You can also use the @code{signal} command to prevent your program from
6382 seeing a signal, or cause it to see a signal it normally would not see,
6383 or to give it any signal at any time. For example, if your program stopped
6384 due to some sort of memory reference error, you might store correct
6385 values into the erroneous variables and continue, hoping to see more
6386 execution; but your program would probably terminate immediately as
6387 a result of the fatal signal once it saw the signal. To prevent this,
6388 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6389 Program a Signal}.
6390
6391 @cindex stepping and signal handlers
6392 @anchor{stepping and signal handlers}
6393
6394 @value{GDBN} optimizes for stepping the mainline code. If a signal
6395 that has @code{handle nostop} and @code{handle pass} set arrives while
6396 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6397 in progress, @value{GDBN} lets the signal handler run and then resumes
6398 stepping the mainline code once the signal handler returns. In other
6399 words, @value{GDBN} steps over the signal handler. This prevents
6400 signals that you've specified as not interesting (with @code{handle
6401 nostop}) from changing the focus of debugging unexpectedly. Note that
6402 the signal handler itself may still hit a breakpoint, stop for another
6403 signal that has @code{handle stop} in effect, or for any other event
6404 that normally results in stopping the stepping command sooner. Also
6405 note that @value{GDBN} still informs you that the program received a
6406 signal if @code{handle print} is set.
6407
6408 @anchor{stepping into signal handlers}
6409
6410 If you set @code{handle pass} for a signal, and your program sets up a
6411 handler for it, then issuing a stepping command, such as @code{step}
6412 or @code{stepi}, when your program is stopped due to the signal will
6413 step @emph{into} the signal handler (if the target supports that).
6414
6415 Likewise, if you use the @code{queue-signal} command to queue a signal
6416 to be delivered to the current thread when execution of the thread
6417 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6418 stepping command will step into the signal handler.
6419
6420 Here's an example, using @code{stepi} to step to the first instruction
6421 of @code{SIGUSR1}'s handler:
6422
6423 @smallexample
6424 (@value{GDBP}) handle SIGUSR1
6425 Signal Stop Print Pass to program Description
6426 SIGUSR1 Yes Yes Yes User defined signal 1
6427 (@value{GDBP}) c
6428 Continuing.
6429
6430 Program received signal SIGUSR1, User defined signal 1.
6431 main () sigusr1.c:28
6432 28 p = 0;
6433 (@value{GDBP}) si
6434 sigusr1_handler () at sigusr1.c:9
6435 9 @{
6436 @end smallexample
6437
6438 The same, but using @code{queue-signal} instead of waiting for the
6439 program to receive the signal first:
6440
6441 @smallexample
6442 (@value{GDBP}) n
6443 28 p = 0;
6444 (@value{GDBP}) queue-signal SIGUSR1
6445 (@value{GDBP}) si
6446 sigusr1_handler () at sigusr1.c:9
6447 9 @{
6448 (@value{GDBP})
6449 @end smallexample
6450
6451 @cindex extra signal information
6452 @anchor{extra signal information}
6453
6454 On some targets, @value{GDBN} can inspect extra signal information
6455 associated with the intercepted signal, before it is actually
6456 delivered to the program being debugged. This information is exported
6457 by the convenience variable @code{$_siginfo}, and consists of data
6458 that is passed by the kernel to the signal handler at the time of the
6459 receipt of a signal. The data type of the information itself is
6460 target dependent. You can see the data type using the @code{ptype
6461 $_siginfo} command. On Unix systems, it typically corresponds to the
6462 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6463 system header.
6464
6465 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6466 referenced address that raised a segmentation fault.
6467
6468 @smallexample
6469 @group
6470 (@value{GDBP}) continue
6471 Program received signal SIGSEGV, Segmentation fault.
6472 0x0000000000400766 in main ()
6473 69 *(int *)p = 0;
6474 (@value{GDBP}) ptype $_siginfo
6475 type = struct @{
6476 int si_signo;
6477 int si_errno;
6478 int si_code;
6479 union @{
6480 int _pad[28];
6481 struct @{...@} _kill;
6482 struct @{...@} _timer;
6483 struct @{...@} _rt;
6484 struct @{...@} _sigchld;
6485 struct @{...@} _sigfault;
6486 struct @{...@} _sigpoll;
6487 @} _sifields;
6488 @}
6489 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6490 type = struct @{
6491 void *si_addr;
6492 @}
6493 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6494 $1 = (void *) 0x7ffff7ff7000
6495 @end group
6496 @end smallexample
6497
6498 Depending on target support, @code{$_siginfo} may also be writable.
6499
6500 @cindex Intel MPX boundary violations
6501 @cindex boundary violations, Intel MPX
6502 On some targets, a @code{SIGSEGV} can be caused by a boundary
6503 violation, i.e., accessing an address outside of the allowed range.
6504 In those cases @value{GDBN} may displays additional information,
6505 depending on how @value{GDBN} has been told to handle the signal.
6506 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6507 kind: "Upper" or "Lower", the memory address accessed and the
6508 bounds, while with @code{handle nostop SIGSEGV} no additional
6509 information is displayed.
6510
6511 The usual output of a segfault is:
6512 @smallexample
6513 Program received signal SIGSEGV, Segmentation fault
6514 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6515 68 value = *(p + len);
6516 @end smallexample
6517
6518 While a bound violation is presented as:
6519 @smallexample
6520 Program received signal SIGSEGV, Segmentation fault
6521 Upper bound violation while accessing address 0x7fffffffc3b3
6522 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6523 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6524 68 value = *(p + len);
6525 @end smallexample
6526
6527 @node Thread Stops
6528 @section Stopping and Starting Multi-thread Programs
6529
6530 @cindex stopped threads
6531 @cindex threads, stopped
6532
6533 @cindex continuing threads
6534 @cindex threads, continuing
6535
6536 @value{GDBN} supports debugging programs with multiple threads
6537 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6538 are two modes of controlling execution of your program within the
6539 debugger. In the default mode, referred to as @dfn{all-stop mode},
6540 when any thread in your program stops (for example, at a breakpoint
6541 or while being stepped), all other threads in the program are also stopped by
6542 @value{GDBN}. On some targets, @value{GDBN} also supports
6543 @dfn{non-stop mode}, in which other threads can continue to run freely while
6544 you examine the stopped thread in the debugger.
6545
6546 @menu
6547 * All-Stop Mode:: All threads stop when GDB takes control
6548 * Non-Stop Mode:: Other threads continue to execute
6549 * Background Execution:: Running your program asynchronously
6550 * Thread-Specific Breakpoints:: Controlling breakpoints
6551 * Interrupted System Calls:: GDB may interfere with system calls
6552 * Observer Mode:: GDB does not alter program behavior
6553 @end menu
6554
6555 @node All-Stop Mode
6556 @subsection All-Stop Mode
6557
6558 @cindex all-stop mode
6559
6560 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6561 @emph{all} threads of execution stop, not just the current thread. This
6562 allows you to examine the overall state of the program, including
6563 switching between threads, without worrying that things may change
6564 underfoot.
6565
6566 Conversely, whenever you restart the program, @emph{all} threads start
6567 executing. @emph{This is true even when single-stepping} with commands
6568 like @code{step} or @code{next}.
6569
6570 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6571 Since thread scheduling is up to your debugging target's operating
6572 system (not controlled by @value{GDBN}), other threads may
6573 execute more than one statement while the current thread completes a
6574 single step. Moreover, in general other threads stop in the middle of a
6575 statement, rather than at a clean statement boundary, when the program
6576 stops.
6577
6578 You might even find your program stopped in another thread after
6579 continuing or even single-stepping. This happens whenever some other
6580 thread runs into a breakpoint, a signal, or an exception before the
6581 first thread completes whatever you requested.
6582
6583 @cindex automatic thread selection
6584 @cindex switching threads automatically
6585 @cindex threads, automatic switching
6586 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6587 signal, it automatically selects the thread where that breakpoint or
6588 signal happened. @value{GDBN} alerts you to the context switch with a
6589 message such as @samp{[Switching to Thread @var{n}]} to identify the
6590 thread.
6591
6592 On some OSes, you can modify @value{GDBN}'s default behavior by
6593 locking the OS scheduler to allow only a single thread to run.
6594
6595 @table @code
6596 @item set scheduler-locking @var{mode}
6597 @cindex scheduler locking mode
6598 @cindex lock scheduler
6599 Set the scheduler locking mode. It applies to normal execution,
6600 record mode, and replay mode. If it is @code{off}, then there is no
6601 locking and any thread may run at any time. If @code{on}, then only
6602 the current thread may run when the inferior is resumed. The
6603 @code{step} mode optimizes for single-stepping; it prevents other
6604 threads from preempting the current thread while you are stepping, so
6605 that the focus of debugging does not change unexpectedly. Other
6606 threads never get a chance to run when you step, and they are
6607 completely free to run when you use commands like @samp{continue},
6608 @samp{until}, or @samp{finish}. However, unless another thread hits a
6609 breakpoint during its timeslice, @value{GDBN} does not change the
6610 current thread away from the thread that you are debugging. The
6611 @code{replay} mode behaves like @code{off} in record mode and like
6612 @code{on} in replay mode.
6613
6614 @item show scheduler-locking
6615 Display the current scheduler locking mode.
6616 @end table
6617
6618 @cindex resume threads of multiple processes simultaneously
6619 By default, when you issue one of the execution commands such as
6620 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6621 threads of the current inferior to run. For example, if @value{GDBN}
6622 is attached to two inferiors, each with two threads, the
6623 @code{continue} command resumes only the two threads of the current
6624 inferior. This is useful, for example, when you debug a program that
6625 forks and you want to hold the parent stopped (so that, for instance,
6626 it doesn't run to exit), while you debug the child. In other
6627 situations, you may not be interested in inspecting the current state
6628 of any of the processes @value{GDBN} is attached to, and you may want
6629 to resume them all until some breakpoint is hit. In the latter case,
6630 you can instruct @value{GDBN} to allow all threads of all the
6631 inferiors to run with the @w{@code{set schedule-multiple}} command.
6632
6633 @table @code
6634 @kindex set schedule-multiple
6635 @item set schedule-multiple
6636 Set the mode for allowing threads of multiple processes to be resumed
6637 when an execution command is issued. When @code{on}, all threads of
6638 all processes are allowed to run. When @code{off}, only the threads
6639 of the current process are resumed. The default is @code{off}. The
6640 @code{scheduler-locking} mode takes precedence when set to @code{on},
6641 or while you are stepping and set to @code{step}.
6642
6643 @item show schedule-multiple
6644 Display the current mode for resuming the execution of threads of
6645 multiple processes.
6646 @end table
6647
6648 @node Non-Stop Mode
6649 @subsection Non-Stop Mode
6650
6651 @cindex non-stop mode
6652
6653 @c This section is really only a place-holder, and needs to be expanded
6654 @c with more details.
6655
6656 For some multi-threaded targets, @value{GDBN} supports an optional
6657 mode of operation in which you can examine stopped program threads in
6658 the debugger while other threads continue to execute freely. This
6659 minimizes intrusion when debugging live systems, such as programs
6660 where some threads have real-time constraints or must continue to
6661 respond to external events. This is referred to as @dfn{non-stop} mode.
6662
6663 In non-stop mode, when a thread stops to report a debugging event,
6664 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6665 threads as well, in contrast to the all-stop mode behavior. Additionally,
6666 execution commands such as @code{continue} and @code{step} apply by default
6667 only to the current thread in non-stop mode, rather than all threads as
6668 in all-stop mode. This allows you to control threads explicitly in
6669 ways that are not possible in all-stop mode --- for example, stepping
6670 one thread while allowing others to run freely, stepping
6671 one thread while holding all others stopped, or stepping several threads
6672 independently and simultaneously.
6673
6674 To enter non-stop mode, use this sequence of commands before you run
6675 or attach to your program:
6676
6677 @smallexample
6678 # If using the CLI, pagination breaks non-stop.
6679 set pagination off
6680
6681 # Finally, turn it on!
6682 set non-stop on
6683 @end smallexample
6684
6685 You can use these commands to manipulate the non-stop mode setting:
6686
6687 @table @code
6688 @kindex set non-stop
6689 @item set non-stop on
6690 Enable selection of non-stop mode.
6691 @item set non-stop off
6692 Disable selection of non-stop mode.
6693 @kindex show non-stop
6694 @item show non-stop
6695 Show the current non-stop enablement setting.
6696 @end table
6697
6698 Note these commands only reflect whether non-stop mode is enabled,
6699 not whether the currently-executing program is being run in non-stop mode.
6700 In particular, the @code{set non-stop} preference is only consulted when
6701 @value{GDBN} starts or connects to the target program, and it is generally
6702 not possible to switch modes once debugging has started. Furthermore,
6703 since not all targets support non-stop mode, even when you have enabled
6704 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6705 default.
6706
6707 In non-stop mode, all execution commands apply only to the current thread
6708 by default. That is, @code{continue} only continues one thread.
6709 To continue all threads, issue @code{continue -a} or @code{c -a}.
6710
6711 You can use @value{GDBN}'s background execution commands
6712 (@pxref{Background Execution}) to run some threads in the background
6713 while you continue to examine or step others from @value{GDBN}.
6714 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6715 always executed asynchronously in non-stop mode.
6716
6717 Suspending execution is done with the @code{interrupt} command when
6718 running in the background, or @kbd{Ctrl-c} during foreground execution.
6719 In all-stop mode, this stops the whole process;
6720 but in non-stop mode the interrupt applies only to the current thread.
6721 To stop the whole program, use @code{interrupt -a}.
6722
6723 Other execution commands do not currently support the @code{-a} option.
6724
6725 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6726 that thread current, as it does in all-stop mode. This is because the
6727 thread stop notifications are asynchronous with respect to @value{GDBN}'s
6728 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6729 changed to a different thread just as you entered a command to operate on the
6730 previously current thread.
6731
6732 @node Background Execution
6733 @subsection Background Execution
6734
6735 @cindex foreground execution
6736 @cindex background execution
6737 @cindex asynchronous execution
6738 @cindex execution, foreground, background and asynchronous
6739
6740 @value{GDBN}'s execution commands have two variants: the normal
6741 foreground (synchronous) behavior, and a background
6742 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
6743 the program to report that some thread has stopped before prompting for
6744 another command. In background execution, @value{GDBN} immediately gives
6745 a command prompt so that you can issue other commands while your program runs.
6746
6747 If the target doesn't support async mode, @value{GDBN} issues an error
6748 message if you attempt to use the background execution commands.
6749
6750 @cindex @code{&}, background execution of commands
6751 To specify background execution, add a @code{&} to the command. For example,
6752 the background form of the @code{continue} command is @code{continue&}, or
6753 just @code{c&}. The execution commands that accept background execution
6754 are:
6755
6756 @table @code
6757 @kindex run&
6758 @item run
6759 @xref{Starting, , Starting your Program}.
6760
6761 @item attach
6762 @kindex attach&
6763 @xref{Attach, , Debugging an Already-running Process}.
6764
6765 @item step
6766 @kindex step&
6767 @xref{Continuing and Stepping, step}.
6768
6769 @item stepi
6770 @kindex stepi&
6771 @xref{Continuing and Stepping, stepi}.
6772
6773 @item next
6774 @kindex next&
6775 @xref{Continuing and Stepping, next}.
6776
6777 @item nexti
6778 @kindex nexti&
6779 @xref{Continuing and Stepping, nexti}.
6780
6781 @item continue
6782 @kindex continue&
6783 @xref{Continuing and Stepping, continue}.
6784
6785 @item finish
6786 @kindex finish&
6787 @xref{Continuing and Stepping, finish}.
6788
6789 @item until
6790 @kindex until&
6791 @xref{Continuing and Stepping, until}.
6792
6793 @end table
6794
6795 Background execution is especially useful in conjunction with non-stop
6796 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6797 However, you can also use these commands in the normal all-stop mode with
6798 the restriction that you cannot issue another execution command until the
6799 previous one finishes. Examples of commands that are valid in all-stop
6800 mode while the program is running include @code{help} and @code{info break}.
6801
6802 You can interrupt your program while it is running in the background by
6803 using the @code{interrupt} command.
6804
6805 @table @code
6806 @kindex interrupt
6807 @item interrupt
6808 @itemx interrupt -a
6809
6810 Suspend execution of the running program. In all-stop mode,
6811 @code{interrupt} stops the whole process, but in non-stop mode, it stops
6812 only the current thread. To stop the whole program in non-stop mode,
6813 use @code{interrupt -a}.
6814 @end table
6815
6816 @node Thread-Specific Breakpoints
6817 @subsection Thread-Specific Breakpoints
6818
6819 When your program has multiple threads (@pxref{Threads,, Debugging
6820 Programs with Multiple Threads}), you can choose whether to set
6821 breakpoints on all threads, or on a particular thread.
6822
6823 @table @code
6824 @cindex breakpoints and threads
6825 @cindex thread breakpoints
6826 @kindex break @dots{} thread @var{thread-id}
6827 @item break @var{location} thread @var{thread-id}
6828 @itemx break @var{location} thread @var{thread-id} if @dots{}
6829 @var{location} specifies source lines; there are several ways of
6830 writing them (@pxref{Specify Location}), but the effect is always to
6831 specify some source line.
6832
6833 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
6834 to specify that you only want @value{GDBN} to stop the program when a
6835 particular thread reaches this breakpoint. The @var{thread-id} specifier
6836 is one of the thread identifiers assigned by @value{GDBN}, shown
6837 in the first column of the @samp{info threads} display.
6838
6839 If you do not specify @samp{thread @var{thread-id}} when you set a
6840 breakpoint, the breakpoint applies to @emph{all} threads of your
6841 program.
6842
6843 You can use the @code{thread} qualifier on conditional breakpoints as
6844 well; in this case, place @samp{thread @var{thread-id}} before or
6845 after the breakpoint condition, like this:
6846
6847 @smallexample
6848 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
6849 @end smallexample
6850
6851 @end table
6852
6853 Thread-specific breakpoints are automatically deleted when
6854 @value{GDBN} detects the corresponding thread is no longer in the
6855 thread list. For example:
6856
6857 @smallexample
6858 (@value{GDBP}) c
6859 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6860 @end smallexample
6861
6862 There are several ways for a thread to disappear, such as a regular
6863 thread exit, but also when you detach from the process with the
6864 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
6865 Process}), or if @value{GDBN} loses the remote connection
6866 (@pxref{Remote Debugging}), etc. Note that with some targets,
6867 @value{GDBN} is only able to detect a thread has exited when the user
6868 explictly asks for the thread list with the @code{info threads}
6869 command.
6870
6871 @node Interrupted System Calls
6872 @subsection Interrupted System Calls
6873
6874 @cindex thread breakpoints and system calls
6875 @cindex system calls and thread breakpoints
6876 @cindex premature return from system calls
6877 There is an unfortunate side effect when using @value{GDBN} to debug
6878 multi-threaded programs. If one thread stops for a
6879 breakpoint, or for some other reason, and another thread is blocked in a
6880 system call, then the system call may return prematurely. This is a
6881 consequence of the interaction between multiple threads and the signals
6882 that @value{GDBN} uses to implement breakpoints and other events that
6883 stop execution.
6884
6885 To handle this problem, your program should check the return value of
6886 each system call and react appropriately. This is good programming
6887 style anyways.
6888
6889 For example, do not write code like this:
6890
6891 @smallexample
6892 sleep (10);
6893 @end smallexample
6894
6895 The call to @code{sleep} will return early if a different thread stops
6896 at a breakpoint or for some other reason.
6897
6898 Instead, write this:
6899
6900 @smallexample
6901 int unslept = 10;
6902 while (unslept > 0)
6903 unslept = sleep (unslept);
6904 @end smallexample
6905
6906 A system call is allowed to return early, so the system is still
6907 conforming to its specification. But @value{GDBN} does cause your
6908 multi-threaded program to behave differently than it would without
6909 @value{GDBN}.
6910
6911 Also, @value{GDBN} uses internal breakpoints in the thread library to
6912 monitor certain events such as thread creation and thread destruction.
6913 When such an event happens, a system call in another thread may return
6914 prematurely, even though your program does not appear to stop.
6915
6916 @node Observer Mode
6917 @subsection Observer Mode
6918
6919 If you want to build on non-stop mode and observe program behavior
6920 without any chance of disruption by @value{GDBN}, you can set
6921 variables to disable all of the debugger's attempts to modify state,
6922 whether by writing memory, inserting breakpoints, etc. These operate
6923 at a low level, intercepting operations from all commands.
6924
6925 When all of these are set to @code{off}, then @value{GDBN} is said to
6926 be @dfn{observer mode}. As a convenience, the variable
6927 @code{observer} can be set to disable these, plus enable non-stop
6928 mode.
6929
6930 Note that @value{GDBN} will not prevent you from making nonsensical
6931 combinations of these settings. For instance, if you have enabled
6932 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
6933 then breakpoints that work by writing trap instructions into the code
6934 stream will still not be able to be placed.
6935
6936 @table @code
6937
6938 @kindex observer
6939 @item set observer on
6940 @itemx set observer off
6941 When set to @code{on}, this disables all the permission variables
6942 below (except for @code{insert-fast-tracepoints}), plus enables
6943 non-stop debugging. Setting this to @code{off} switches back to
6944 normal debugging, though remaining in non-stop mode.
6945
6946 @item show observer
6947 Show whether observer mode is on or off.
6948
6949 @kindex may-write-registers
6950 @item set may-write-registers on
6951 @itemx set may-write-registers off
6952 This controls whether @value{GDBN} will attempt to alter the values of
6953 registers, such as with assignment expressions in @code{print}, or the
6954 @code{jump} command. It defaults to @code{on}.
6955
6956 @item show may-write-registers
6957 Show the current permission to write registers.
6958
6959 @kindex may-write-memory
6960 @item set may-write-memory on
6961 @itemx set may-write-memory off
6962 This controls whether @value{GDBN} will attempt to alter the contents
6963 of memory, such as with assignment expressions in @code{print}. It
6964 defaults to @code{on}.
6965
6966 @item show may-write-memory
6967 Show the current permission to write memory.
6968
6969 @kindex may-insert-breakpoints
6970 @item set may-insert-breakpoints on
6971 @itemx set may-insert-breakpoints off
6972 This controls whether @value{GDBN} will attempt to insert breakpoints.
6973 This affects all breakpoints, including internal breakpoints defined
6974 by @value{GDBN}. It defaults to @code{on}.
6975
6976 @item show may-insert-breakpoints
6977 Show the current permission to insert breakpoints.
6978
6979 @kindex may-insert-tracepoints
6980 @item set may-insert-tracepoints on
6981 @itemx set may-insert-tracepoints off
6982 This controls whether @value{GDBN} will attempt to insert (regular)
6983 tracepoints at the beginning of a tracing experiment. It affects only
6984 non-fast tracepoints, fast tracepoints being under the control of
6985 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6986
6987 @item show may-insert-tracepoints
6988 Show the current permission to insert tracepoints.
6989
6990 @kindex may-insert-fast-tracepoints
6991 @item set may-insert-fast-tracepoints on
6992 @itemx set may-insert-fast-tracepoints off
6993 This controls whether @value{GDBN} will attempt to insert fast
6994 tracepoints at the beginning of a tracing experiment. It affects only
6995 fast tracepoints, regular (non-fast) tracepoints being under the
6996 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6997
6998 @item show may-insert-fast-tracepoints
6999 Show the current permission to insert fast tracepoints.
7000
7001 @kindex may-interrupt
7002 @item set may-interrupt on
7003 @itemx set may-interrupt off
7004 This controls whether @value{GDBN} will attempt to interrupt or stop
7005 program execution. When this variable is @code{off}, the
7006 @code{interrupt} command will have no effect, nor will
7007 @kbd{Ctrl-c}. It defaults to @code{on}.
7008
7009 @item show may-interrupt
7010 Show the current permission to interrupt or stop the program.
7011
7012 @end table
7013
7014 @node Reverse Execution
7015 @chapter Running programs backward
7016 @cindex reverse execution
7017 @cindex running programs backward
7018
7019 When you are debugging a program, it is not unusual to realize that
7020 you have gone too far, and some event of interest has already happened.
7021 If the target environment supports it, @value{GDBN} can allow you to
7022 ``rewind'' the program by running it backward.
7023
7024 A target environment that supports reverse execution should be able
7025 to ``undo'' the changes in machine state that have taken place as the
7026 program was executing normally. Variables, registers etc.@: should
7027 revert to their previous values. Obviously this requires a great
7028 deal of sophistication on the part of the target environment; not
7029 all target environments can support reverse execution.
7030
7031 When a program is executed in reverse, the instructions that
7032 have most recently been executed are ``un-executed'', in reverse
7033 order. The program counter runs backward, following the previous
7034 thread of execution in reverse. As each instruction is ``un-executed'',
7035 the values of memory and/or registers that were changed by that
7036 instruction are reverted to their previous states. After executing
7037 a piece of source code in reverse, all side effects of that code
7038 should be ``undone'', and all variables should be returned to their
7039 prior values@footnote{
7040 Note that some side effects are easier to undo than others. For instance,
7041 memory and registers are relatively easy, but device I/O is hard. Some
7042 targets may be able undo things like device I/O, and some may not.
7043
7044 The contract between @value{GDBN} and the reverse executing target
7045 requires only that the target do something reasonable when
7046 @value{GDBN} tells it to execute backwards, and then report the
7047 results back to @value{GDBN}. Whatever the target reports back to
7048 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7049 assumes that the memory and registers that the target reports are in a
7050 consistent state, but @value{GDBN} accepts whatever it is given.
7051 }.
7052
7053 On some platforms, @value{GDBN} has built-in support for reverse
7054 execution, activated with the @code{record} or @code{record btrace}
7055 commands. @xref{Process Record and Replay}. Some remote targets,
7056 typically full system emulators, support reverse execution directly
7057 without requiring any special command.
7058
7059 If you are debugging in a target environment that supports
7060 reverse execution, @value{GDBN} provides the following commands.
7061
7062 @table @code
7063 @kindex reverse-continue
7064 @kindex rc @r{(@code{reverse-continue})}
7065 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7066 @itemx rc @r{[}@var{ignore-count}@r{]}
7067 Beginning at the point where your program last stopped, start executing
7068 in reverse. Reverse execution will stop for breakpoints and synchronous
7069 exceptions (signals), just like normal execution. Behavior of
7070 asynchronous signals depends on the target environment.
7071
7072 @kindex reverse-step
7073 @kindex rs @r{(@code{step})}
7074 @item reverse-step @r{[}@var{count}@r{]}
7075 Run the program backward until control reaches the start of a
7076 different source line; then stop it, and return control to @value{GDBN}.
7077
7078 Like the @code{step} command, @code{reverse-step} will only stop
7079 at the beginning of a source line. It ``un-executes'' the previously
7080 executed source line. If the previous source line included calls to
7081 debuggable functions, @code{reverse-step} will step (backward) into
7082 the called function, stopping at the beginning of the @emph{last}
7083 statement in the called function (typically a return statement).
7084
7085 Also, as with the @code{step} command, if non-debuggable functions are
7086 called, @code{reverse-step} will run thru them backward without stopping.
7087
7088 @kindex reverse-stepi
7089 @kindex rsi @r{(@code{reverse-stepi})}
7090 @item reverse-stepi @r{[}@var{count}@r{]}
7091 Reverse-execute one machine instruction. Note that the instruction
7092 to be reverse-executed is @emph{not} the one pointed to by the program
7093 counter, but the instruction executed prior to that one. For instance,
7094 if the last instruction was a jump, @code{reverse-stepi} will take you
7095 back from the destination of the jump to the jump instruction itself.
7096
7097 @kindex reverse-next
7098 @kindex rn @r{(@code{reverse-next})}
7099 @item reverse-next @r{[}@var{count}@r{]}
7100 Run backward to the beginning of the previous line executed in
7101 the current (innermost) stack frame. If the line contains function
7102 calls, they will be ``un-executed'' without stopping. Starting from
7103 the first line of a function, @code{reverse-next} will take you back
7104 to the caller of that function, @emph{before} the function was called,
7105 just as the normal @code{next} command would take you from the last
7106 line of a function back to its return to its caller
7107 @footnote{Unless the code is too heavily optimized.}.
7108
7109 @kindex reverse-nexti
7110 @kindex rni @r{(@code{reverse-nexti})}
7111 @item reverse-nexti @r{[}@var{count}@r{]}
7112 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7113 in reverse, except that called functions are ``un-executed'' atomically.
7114 That is, if the previously executed instruction was a return from
7115 another function, @code{reverse-nexti} will continue to execute
7116 in reverse until the call to that function (from the current stack
7117 frame) is reached.
7118
7119 @kindex reverse-finish
7120 @item reverse-finish
7121 Just as the @code{finish} command takes you to the point where the
7122 current function returns, @code{reverse-finish} takes you to the point
7123 where it was called. Instead of ending up at the end of the current
7124 function invocation, you end up at the beginning.
7125
7126 @kindex set exec-direction
7127 @item set exec-direction
7128 Set the direction of target execution.
7129 @item set exec-direction reverse
7130 @cindex execute forward or backward in time
7131 @value{GDBN} will perform all execution commands in reverse, until the
7132 exec-direction mode is changed to ``forward''. Affected commands include
7133 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7134 command cannot be used in reverse mode.
7135 @item set exec-direction forward
7136 @value{GDBN} will perform all execution commands in the normal fashion.
7137 This is the default.
7138 @end table
7139
7140
7141 @node Process Record and Replay
7142 @chapter Recording Inferior's Execution and Replaying It
7143 @cindex process record and replay
7144 @cindex recording inferior's execution and replaying it
7145
7146 On some platforms, @value{GDBN} provides a special @dfn{process record
7147 and replay} target that can record a log of the process execution, and
7148 replay it later with both forward and reverse execution commands.
7149
7150 @cindex replay mode
7151 When this target is in use, if the execution log includes the record
7152 for the next instruction, @value{GDBN} will debug in @dfn{replay
7153 mode}. In the replay mode, the inferior does not really execute code
7154 instructions. Instead, all the events that normally happen during
7155 code execution are taken from the execution log. While code is not
7156 really executed in replay mode, the values of registers (including the
7157 program counter register) and the memory of the inferior are still
7158 changed as they normally would. Their contents are taken from the
7159 execution log.
7160
7161 @cindex record mode
7162 If the record for the next instruction is not in the execution log,
7163 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7164 inferior executes normally, and @value{GDBN} records the execution log
7165 for future replay.
7166
7167 The process record and replay target supports reverse execution
7168 (@pxref{Reverse Execution}), even if the platform on which the
7169 inferior runs does not. However, the reverse execution is limited in
7170 this case by the range of the instructions recorded in the execution
7171 log. In other words, reverse execution on platforms that don't
7172 support it directly can only be done in the replay mode.
7173
7174 When debugging in the reverse direction, @value{GDBN} will work in
7175 replay mode as long as the execution log includes the record for the
7176 previous instruction; otherwise, it will work in record mode, if the
7177 platform supports reverse execution, or stop if not.
7178
7179 Currently, process record and replay is supported on ARM, Aarch64,
7180 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7181 GNU/Linux. Process record and replay can be used both when native
7182 debugging, and when remote debugging via @code{gdbserver}.
7183
7184 For architecture environments that support process record and replay,
7185 @value{GDBN} provides the following commands:
7186
7187 @table @code
7188 @kindex target record
7189 @kindex target record-full
7190 @kindex target record-btrace
7191 @kindex record
7192 @kindex record full
7193 @kindex record btrace
7194 @kindex record btrace bts
7195 @kindex record btrace pt
7196 @kindex record bts
7197 @kindex record pt
7198 @kindex rec
7199 @kindex rec full
7200 @kindex rec btrace
7201 @kindex rec btrace bts
7202 @kindex rec btrace pt
7203 @kindex rec bts
7204 @kindex rec pt
7205 @item record @var{method}
7206 This command starts the process record and replay target. The
7207 recording method can be specified as parameter. Without a parameter
7208 the command uses the @code{full} recording method. The following
7209 recording methods are available:
7210
7211 @table @code
7212 @item full
7213 Full record/replay recording using @value{GDBN}'s software record and
7214 replay implementation. This method allows replaying and reverse
7215 execution.
7216
7217 @item btrace @var{format}
7218 Hardware-supported instruction recording, supported on Intel
7219 processors. This method does not record data. Further, the data is
7220 collected in a ring buffer so old data will be overwritten when the
7221 buffer is full. It allows limited reverse execution. Variables and
7222 registers are not available during reverse execution. In remote
7223 debugging, recording continues on disconnect. Recorded data can be
7224 inspected after reconnecting. The recording may be stopped using
7225 @code{record stop}.
7226
7227 The recording format can be specified as parameter. Without a parameter
7228 the command chooses the recording format. The following recording
7229 formats are available:
7230
7231 @table @code
7232 @item bts
7233 @cindex branch trace store
7234 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7235 this format, the processor stores a from/to record for each executed
7236 branch in the btrace ring buffer.
7237
7238 @item pt
7239 @cindex Intel Processor Trace
7240 Use the @dfn{Intel Processor Trace} recording format. In this
7241 format, the processor stores the execution trace in a compressed form
7242 that is afterwards decoded by @value{GDBN}.
7243
7244 The trace can be recorded with very low overhead. The compressed
7245 trace format also allows small trace buffers to already contain a big
7246 number of instructions compared to @acronym{BTS}.
7247
7248 Decoding the recorded execution trace, on the other hand, is more
7249 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7250 increased number of instructions to process. You should increase the
7251 buffer-size with care.
7252 @end table
7253
7254 Not all recording formats may be available on all processors.
7255 @end table
7256
7257 The process record and replay target can only debug a process that is
7258 already running. Therefore, you need first to start the process with
7259 the @kbd{run} or @kbd{start} commands, and then start the recording
7260 with the @kbd{record @var{method}} command.
7261
7262 @cindex displaced stepping, and process record and replay
7263 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7264 will be automatically disabled when process record and replay target
7265 is started. That's because the process record and replay target
7266 doesn't support displaced stepping.
7267
7268 @cindex non-stop mode, and process record and replay
7269 @cindex asynchronous execution, and process record and replay
7270 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7271 the asynchronous execution mode (@pxref{Background Execution}), not
7272 all recording methods are available. The @code{full} recording method
7273 does not support these two modes.
7274
7275 @kindex record stop
7276 @kindex rec s
7277 @item record stop
7278 Stop the process record and replay target. When process record and
7279 replay target stops, the entire execution log will be deleted and the
7280 inferior will either be terminated, or will remain in its final state.
7281
7282 When you stop the process record and replay target in record mode (at
7283 the end of the execution log), the inferior will be stopped at the
7284 next instruction that would have been recorded. In other words, if
7285 you record for a while and then stop recording, the inferior process
7286 will be left in the same state as if the recording never happened.
7287
7288 On the other hand, if the process record and replay target is stopped
7289 while in replay mode (that is, not at the end of the execution log,
7290 but at some earlier point), the inferior process will become ``live''
7291 at that earlier state, and it will then be possible to continue the
7292 usual ``live'' debugging of the process from that state.
7293
7294 When the inferior process exits, or @value{GDBN} detaches from it,
7295 process record and replay target will automatically stop itself.
7296
7297 @kindex record goto
7298 @item record goto
7299 Go to a specific location in the execution log. There are several
7300 ways to specify the location to go to:
7301
7302 @table @code
7303 @item record goto begin
7304 @itemx record goto start
7305 Go to the beginning of the execution log.
7306
7307 @item record goto end
7308 Go to the end of the execution log.
7309
7310 @item record goto @var{n}
7311 Go to instruction number @var{n} in the execution log.
7312 @end table
7313
7314 @kindex record save
7315 @item record save @var{filename}
7316 Save the execution log to a file @file{@var{filename}}.
7317 Default filename is @file{gdb_record.@var{process_id}}, where
7318 @var{process_id} is the process ID of the inferior.
7319
7320 This command may not be available for all recording methods.
7321
7322 @kindex record restore
7323 @item record restore @var{filename}
7324 Restore the execution log from a file @file{@var{filename}}.
7325 File must have been created with @code{record save}.
7326
7327 @kindex set record full
7328 @item set record full insn-number-max @var{limit}
7329 @itemx set record full insn-number-max unlimited
7330 Set the limit of instructions to be recorded for the @code{full}
7331 recording method. Default value is 200000.
7332
7333 If @var{limit} is a positive number, then @value{GDBN} will start
7334 deleting instructions from the log once the number of the record
7335 instructions becomes greater than @var{limit}. For every new recorded
7336 instruction, @value{GDBN} will delete the earliest recorded
7337 instruction to keep the number of recorded instructions at the limit.
7338 (Since deleting recorded instructions loses information, @value{GDBN}
7339 lets you control what happens when the limit is reached, by means of
7340 the @code{stop-at-limit} option, described below.)
7341
7342 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7343 delete recorded instructions from the execution log. The number of
7344 recorded instructions is limited only by the available memory.
7345
7346 @kindex show record full
7347 @item show record full insn-number-max
7348 Show the limit of instructions to be recorded with the @code{full}
7349 recording method.
7350
7351 @item set record full stop-at-limit
7352 Control the behavior of the @code{full} recording method when the
7353 number of recorded instructions reaches the limit. If ON (the
7354 default), @value{GDBN} will stop when the limit is reached for the
7355 first time and ask you whether you want to stop the inferior or
7356 continue running it and recording the execution log. If you decide
7357 to continue recording, each new recorded instruction will cause the
7358 oldest one to be deleted.
7359
7360 If this option is OFF, @value{GDBN} will automatically delete the
7361 oldest record to make room for each new one, without asking.
7362
7363 @item show record full stop-at-limit
7364 Show the current setting of @code{stop-at-limit}.
7365
7366 @item set record full memory-query
7367 Control the behavior when @value{GDBN} is unable to record memory
7368 changes caused by an instruction for the @code{full} recording method.
7369 If ON, @value{GDBN} will query whether to stop the inferior in that
7370 case.
7371
7372 If this option is OFF (the default), @value{GDBN} will automatically
7373 ignore the effect of such instructions on memory. Later, when
7374 @value{GDBN} replays this execution log, it will mark the log of this
7375 instruction as not accessible, and it will not affect the replay
7376 results.
7377
7378 @item show record full memory-query
7379 Show the current setting of @code{memory-query}.
7380
7381 @kindex set record btrace
7382 The @code{btrace} record target does not trace data. As a
7383 convenience, when replaying, @value{GDBN} reads read-only memory off
7384 the live program directly, assuming that the addresses of the
7385 read-only areas don't change. This for example makes it possible to
7386 disassemble code while replaying, but not to print variables.
7387 In some cases, being able to inspect variables might be useful.
7388 You can use the following command for that:
7389
7390 @item set record btrace replay-memory-access
7391 Control the behavior of the @code{btrace} recording method when
7392 accessing memory during replay. If @code{read-only} (the default),
7393 @value{GDBN} will only allow accesses to read-only memory.
7394 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7395 and to read-write memory. Beware that the accessed memory corresponds
7396 to the live target and not necessarily to the current replay
7397 position.
7398
7399 @item set record btrace cpu @var{identifier}
7400 Set the processor to be used for enabling workarounds for processor
7401 errata when decoding the trace.
7402
7403 Processor errata are defects in processor operation, caused by its
7404 design or manufacture. They can cause a trace not to match the
7405 specification. This, in turn, may cause trace decode to fail.
7406 @value{GDBN} can detect erroneous trace packets and correct them, thus
7407 avoiding the decoding failures. These corrections are known as
7408 @dfn{errata workarounds}, and are enabled based on the processor on
7409 which the trace was recorded.
7410
7411 By default, @value{GDBN} attempts to detect the processor
7412 automatically, and apply the necessary workarounds for it. However,
7413 you may need to specify the processor if @value{GDBN} does not yet
7414 support it. This command allows you to do that, and also allows to
7415 disable the workarounds.
7416
7417 The argument @var{identifier} identifies the @sc{cpu} and is of the
7418 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7419 there are two special identifiers, @code{none} and @code{auto}
7420 (default).
7421
7422 The following vendor identifiers and corresponding processor
7423 identifiers are currently supported:
7424
7425 @multitable @columnfractions .1 .9
7426
7427 @item @code{intel}
7428 @tab @var{family}/@var{model}[/@var{stepping}]
7429
7430 @end multitable
7431
7432 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7433 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7434
7435 If @var{identifier} is @code{auto}, enable errata workarounds for the
7436 processor on which the trace was recorded. If @var{identifier} is
7437 @code{none}, errata workarounds are disabled.
7438
7439 For example, when using an old @value{GDBN} on a new system, decode
7440 may fail because @value{GDBN} does not support the new processor. It
7441 often suffices to specify an older processor that @value{GDBN}
7442 supports.
7443
7444 @smallexample
7445 (gdb) info record
7446 Active record target: record-btrace
7447 Recording format: Intel Processor Trace.
7448 Buffer size: 16kB.
7449 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7450 (gdb) set record btrace cpu intel:6/158
7451 (gdb) info record
7452 Active record target: record-btrace
7453 Recording format: Intel Processor Trace.
7454 Buffer size: 16kB.
7455 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7456 @end smallexample
7457
7458 @kindex show record btrace
7459 @item show record btrace replay-memory-access
7460 Show the current setting of @code{replay-memory-access}.
7461
7462 @item show record btrace cpu
7463 Show the processor to be used for enabling trace decode errata
7464 workarounds.
7465
7466 @kindex set record btrace bts
7467 @item set record btrace bts buffer-size @var{size}
7468 @itemx set record btrace bts buffer-size unlimited
7469 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7470 format. Default is 64KB.
7471
7472 If @var{size} is a positive number, then @value{GDBN} will try to
7473 allocate a buffer of at least @var{size} bytes for each new thread
7474 that uses the btrace recording method and the @acronym{BTS} format.
7475 The actually obtained buffer size may differ from the requested
7476 @var{size}. Use the @code{info record} command to see the actual
7477 buffer size for each thread that uses the btrace recording method and
7478 the @acronym{BTS} format.
7479
7480 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7481 allocate a buffer of 4MB.
7482
7483 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7484 also need longer to process the branch trace data before it can be used.
7485
7486 @item show record btrace bts buffer-size @var{size}
7487 Show the current setting of the requested ring buffer size for branch
7488 tracing in @acronym{BTS} format.
7489
7490 @kindex set record btrace pt
7491 @item set record btrace pt buffer-size @var{size}
7492 @itemx set record btrace pt buffer-size unlimited
7493 Set the requested ring buffer size for branch tracing in Intel
7494 Processor Trace format. Default is 16KB.
7495
7496 If @var{size} is a positive number, then @value{GDBN} will try to
7497 allocate a buffer of at least @var{size} bytes for each new thread
7498 that uses the btrace recording method and the Intel Processor Trace
7499 format. The actually obtained buffer size may differ from the
7500 requested @var{size}. Use the @code{info record} command to see the
7501 actual buffer size for each thread.
7502
7503 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7504 allocate a buffer of 4MB.
7505
7506 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7507 also need longer to process the branch trace data before it can be used.
7508
7509 @item show record btrace pt buffer-size @var{size}
7510 Show the current setting of the requested ring buffer size for branch
7511 tracing in Intel Processor Trace format.
7512
7513 @kindex info record
7514 @item info record
7515 Show various statistics about the recording depending on the recording
7516 method:
7517
7518 @table @code
7519 @item full
7520 For the @code{full} recording method, it shows the state of process
7521 record and its in-memory execution log buffer, including:
7522
7523 @itemize @bullet
7524 @item
7525 Whether in record mode or replay mode.
7526 @item
7527 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7528 @item
7529 Highest recorded instruction number.
7530 @item
7531 Current instruction about to be replayed (if in replay mode).
7532 @item
7533 Number of instructions contained in the execution log.
7534 @item
7535 Maximum number of instructions that may be contained in the execution log.
7536 @end itemize
7537
7538 @item btrace
7539 For the @code{btrace} recording method, it shows:
7540
7541 @itemize @bullet
7542 @item
7543 Recording format.
7544 @item
7545 Number of instructions that have been recorded.
7546 @item
7547 Number of blocks of sequential control-flow formed by the recorded
7548 instructions.
7549 @item
7550 Whether in record mode or replay mode.
7551 @end itemize
7552
7553 For the @code{bts} recording format, it also shows:
7554 @itemize @bullet
7555 @item
7556 Size of the perf ring buffer.
7557 @end itemize
7558
7559 For the @code{pt} recording format, it also shows:
7560 @itemize @bullet
7561 @item
7562 Size of the perf ring buffer.
7563 @end itemize
7564 @end table
7565
7566 @kindex record delete
7567 @kindex rec del
7568 @item record delete
7569 When record target runs in replay mode (``in the past''), delete the
7570 subsequent execution log and begin to record a new execution log starting
7571 from the current address. This means you will abandon the previously
7572 recorded ``future'' and begin recording a new ``future''.
7573
7574 @kindex record instruction-history
7575 @kindex rec instruction-history
7576 @item record instruction-history
7577 Disassembles instructions from the recorded execution log. By
7578 default, ten instructions are disassembled. This can be changed using
7579 the @code{set record instruction-history-size} command. Instructions
7580 are printed in execution order.
7581
7582 It can also print mixed source+disassembly if you specify the the
7583 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7584 as well as in symbolic form by specifying the @code{/r} modifier.
7585
7586 The current position marker is printed for the instruction at the
7587 current program counter value. This instruction can appear multiple
7588 times in the trace and the current position marker will be printed
7589 every time. To omit the current position marker, specify the
7590 @code{/p} modifier.
7591
7592 To better align the printed instructions when the trace contains
7593 instructions from more than one function, the function name may be
7594 omitted by specifying the @code{/f} modifier.
7595
7596 Speculatively executed instructions are prefixed with @samp{?}. This
7597 feature is not available for all recording formats.
7598
7599 There are several ways to specify what part of the execution log to
7600 disassemble:
7601
7602 @table @code
7603 @item record instruction-history @var{insn}
7604 Disassembles ten instructions starting from instruction number
7605 @var{insn}.
7606
7607 @item record instruction-history @var{insn}, +/-@var{n}
7608 Disassembles @var{n} instructions around instruction number
7609 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7610 @var{n} instructions after instruction number @var{insn}. If
7611 @var{n} is preceded with @code{-}, disassembles @var{n}
7612 instructions before instruction number @var{insn}.
7613
7614 @item record instruction-history
7615 Disassembles ten more instructions after the last disassembly.
7616
7617 @item record instruction-history -
7618 Disassembles ten more instructions before the last disassembly.
7619
7620 @item record instruction-history @var{begin}, @var{end}
7621 Disassembles instructions beginning with instruction number
7622 @var{begin} until instruction number @var{end}. The instruction
7623 number @var{end} is included.
7624 @end table
7625
7626 This command may not be available for all recording methods.
7627
7628 @kindex set record
7629 @item set record instruction-history-size @var{size}
7630 @itemx set record instruction-history-size unlimited
7631 Define how many instructions to disassemble in the @code{record
7632 instruction-history} command. The default value is 10.
7633 A @var{size} of @code{unlimited} means unlimited instructions.
7634
7635 @kindex show record
7636 @item show record instruction-history-size
7637 Show how many instructions to disassemble in the @code{record
7638 instruction-history} command.
7639
7640 @kindex record function-call-history
7641 @kindex rec function-call-history
7642 @item record function-call-history
7643 Prints the execution history at function granularity. It prints one
7644 line for each sequence of instructions that belong to the same
7645 function giving the name of that function, the source lines
7646 for this instruction sequence (if the @code{/l} modifier is
7647 specified), and the instructions numbers that form the sequence (if
7648 the @code{/i} modifier is specified). The function names are indented
7649 to reflect the call stack depth if the @code{/c} modifier is
7650 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7651 given together.
7652
7653 @smallexample
7654 (@value{GDBP}) @b{list 1, 10}
7655 1 void foo (void)
7656 2 @{
7657 3 @}
7658 4
7659 5 void bar (void)
7660 6 @{
7661 7 ...
7662 8 foo ();
7663 9 ...
7664 10 @}
7665 (@value{GDBP}) @b{record function-call-history /ilc}
7666 1 bar inst 1,4 at foo.c:6,8
7667 2 foo inst 5,10 at foo.c:2,3
7668 3 bar inst 11,13 at foo.c:9,10
7669 @end smallexample
7670
7671 By default, ten lines are printed. This can be changed using the
7672 @code{set record function-call-history-size} command. Functions are
7673 printed in execution order. There are several ways to specify what
7674 to print:
7675
7676 @table @code
7677 @item record function-call-history @var{func}
7678 Prints ten functions starting from function number @var{func}.
7679
7680 @item record function-call-history @var{func}, +/-@var{n}
7681 Prints @var{n} functions around function number @var{func}. If
7682 @var{n} is preceded with @code{+}, prints @var{n} functions after
7683 function number @var{func}. If @var{n} is preceded with @code{-},
7684 prints @var{n} functions before function number @var{func}.
7685
7686 @item record function-call-history
7687 Prints ten more functions after the last ten-line print.
7688
7689 @item record function-call-history -
7690 Prints ten more functions before the last ten-line print.
7691
7692 @item record function-call-history @var{begin}, @var{end}
7693 Prints functions beginning with function number @var{begin} until
7694 function number @var{end}. The function number @var{end} is included.
7695 @end table
7696
7697 This command may not be available for all recording methods.
7698
7699 @item set record function-call-history-size @var{size}
7700 @itemx set record function-call-history-size unlimited
7701 Define how many lines to print in the
7702 @code{record function-call-history} command. The default value is 10.
7703 A size of @code{unlimited} means unlimited lines.
7704
7705 @item show record function-call-history-size
7706 Show how many lines to print in the
7707 @code{record function-call-history} command.
7708 @end table
7709
7710
7711 @node Stack
7712 @chapter Examining the Stack
7713
7714 When your program has stopped, the first thing you need to know is where it
7715 stopped and how it got there.
7716
7717 @cindex call stack
7718 Each time your program performs a function call, information about the call
7719 is generated.
7720 That information includes the location of the call in your program,
7721 the arguments of the call,
7722 and the local variables of the function being called.
7723 The information is saved in a block of data called a @dfn{stack frame}.
7724 The stack frames are allocated in a region of memory called the @dfn{call
7725 stack}.
7726
7727 When your program stops, the @value{GDBN} commands for examining the
7728 stack allow you to see all of this information.
7729
7730 @cindex selected frame
7731 One of the stack frames is @dfn{selected} by @value{GDBN} and many
7732 @value{GDBN} commands refer implicitly to the selected frame. In
7733 particular, whenever you ask @value{GDBN} for the value of a variable in
7734 your program, the value is found in the selected frame. There are
7735 special @value{GDBN} commands to select whichever frame you are
7736 interested in. @xref{Selection, ,Selecting a Frame}.
7737
7738 When your program stops, @value{GDBN} automatically selects the
7739 currently executing frame and describes it briefly, similar to the
7740 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
7741
7742 @menu
7743 * Frames:: Stack frames
7744 * Backtrace:: Backtraces
7745 * Selection:: Selecting a frame
7746 * Frame Info:: Information on a frame
7747 * Frame Apply:: Applying a command to several frames
7748 * Frame Filter Management:: Managing frame filters
7749
7750 @end menu
7751
7752 @node Frames
7753 @section Stack Frames
7754
7755 @cindex frame, definition
7756 @cindex stack frame
7757 The call stack is divided up into contiguous pieces called @dfn{stack
7758 frames}, or @dfn{frames} for short; each frame is the data associated
7759 with one call to one function. The frame contains the arguments given
7760 to the function, the function's local variables, and the address at
7761 which the function is executing.
7762
7763 @cindex initial frame
7764 @cindex outermost frame
7765 @cindex innermost frame
7766 When your program is started, the stack has only one frame, that of the
7767 function @code{main}. This is called the @dfn{initial} frame or the
7768 @dfn{outermost} frame. Each time a function is called, a new frame is
7769 made. Each time a function returns, the frame for that function invocation
7770 is eliminated. If a function is recursive, there can be many frames for
7771 the same function. The frame for the function in which execution is
7772 actually occurring is called the @dfn{innermost} frame. This is the most
7773 recently created of all the stack frames that still exist.
7774
7775 @cindex frame pointer
7776 Inside your program, stack frames are identified by their addresses. A
7777 stack frame consists of many bytes, each of which has its own address; each
7778 kind of computer has a convention for choosing one byte whose
7779 address serves as the address of the frame. Usually this address is kept
7780 in a register called the @dfn{frame pointer register}
7781 (@pxref{Registers, $fp}) while execution is going on in that frame.
7782
7783 @cindex frame level
7784 @cindex frame number
7785 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
7786 number that is zero for the innermost frame, one for the frame that
7787 called it, and so on upward. These level numbers give you a way of
7788 designating stack frames in @value{GDBN} commands. The terms
7789 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
7790 describe this number.
7791
7792 @c The -fomit-frame-pointer below perennially causes hbox overflow
7793 @c underflow problems.
7794 @cindex frameless execution
7795 Some compilers provide a way to compile functions so that they operate
7796 without stack frames. (For example, the @value{NGCC} option
7797 @smallexample
7798 @samp{-fomit-frame-pointer}
7799 @end smallexample
7800 generates functions without a frame.)
7801 This is occasionally done with heavily used library functions to save
7802 the frame setup time. @value{GDBN} has limited facilities for dealing
7803 with these function invocations. If the innermost function invocation
7804 has no stack frame, @value{GDBN} nevertheless regards it as though
7805 it had a separate frame, which is numbered zero as usual, allowing
7806 correct tracing of the function call chain. However, @value{GDBN} has
7807 no provision for frameless functions elsewhere in the stack.
7808
7809 @node Backtrace
7810 @section Backtraces
7811
7812 @cindex traceback
7813 @cindex call stack traces
7814 A backtrace is a summary of how your program got where it is. It shows one
7815 line per frame, for many frames, starting with the currently executing
7816 frame (frame zero), followed by its caller (frame one), and on up the
7817 stack.
7818
7819 @anchor{backtrace-command}
7820 @kindex backtrace
7821 @kindex bt @r{(@code{backtrace})}
7822 To print a backtrace of the entire stack, use the @code{backtrace}
7823 command, or its alias @code{bt}. This command will print one line per
7824 frame for frames in the stack. By default, all stack frames are
7825 printed. You can stop the backtrace at any time by typing the system
7826 interrupt character, normally @kbd{Ctrl-c}.
7827
7828 @table @code
7829 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7830 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7831 Print the backtrace of the entire stack.
7832
7833 The optional @var{count} can be one of the following:
7834
7835 @table @code
7836 @item @var{n}
7837 @itemx @var{n}
7838 Print only the innermost @var{n} frames, where @var{n} is a positive
7839 number.
7840
7841 @item -@var{n}
7842 @itemx -@var{n}
7843 Print only the outermost @var{n} frames, where @var{n} is a positive
7844 number.
7845 @end table
7846
7847 Options:
7848
7849 @table @code
7850 @item -full
7851 Print the values of the local variables also. This can be combined
7852 with the optional @var{count} to limit the number of frames shown.
7853
7854 @item -no-filters
7855 Do not run Python frame filters on this backtrace. @xref{Frame
7856 Filter API}, for more information. Additionally use @ref{disable
7857 frame-filter all} to turn off all frame filters. This is only
7858 relevant when @value{GDBN} has been configured with @code{Python}
7859 support.
7860
7861 @item -hide
7862 A Python frame filter might decide to ``elide'' some frames. Normally
7863 such elided frames are still printed, but they are indented relative
7864 to the filtered frames that cause them to be elided. The @code{-hide}
7865 option causes elided frames to not be printed at all.
7866 @end table
7867
7868 The @code{backtrace} command also supports a number of options that
7869 allow overriding relevant global print settings as set by @code{set
7870 backtrace} and @code{set print} subcommands:
7871
7872 @table @code
7873 @item -past-main [@code{on}|@code{off}]
7874 Set whether backtraces should continue past @code{main}. Related setting:
7875 @ref{set backtrace past-main}.
7876
7877 @item -past-entry [@code{on}|@code{off}]
7878 Set whether backtraces should continue past the entry point of a program.
7879 Related setting: @ref{set backtrace past-entry}.
7880
7881 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
7882 Set printing of function arguments at function entry.
7883 Related setting: @ref{set print entry-values}.
7884
7885 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
7886 Set printing of non-scalar frame arguments.
7887 Related setting: @ref{set print frame-arguments}.
7888
7889 @item -raw-frame-arguments [@code{on}|@code{off}]
7890 Set whether to print frame arguments in raw form.
7891 Related setting: @ref{set print raw-frame-arguments}.
7892
7893 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
7894 Set printing of frame information.
7895 Related setting: @ref{set print frame-info}.
7896 @end table
7897
7898 The optional @var{qualifier} is maintained for backward compatibility.
7899 It can be one of the following:
7900
7901 @table @code
7902 @item full
7903 Equivalent to the @code{-full} option.
7904
7905 @item no-filters
7906 Equivalent to the @code{-no-filters} option.
7907
7908 @item hide
7909 Equivalent to the @code{-hide} option.
7910 @end table
7911
7912 @end table
7913
7914 @kindex where
7915 @kindex info stack
7916 The names @code{where} and @code{info stack} (abbreviated @code{info s})
7917 are additional aliases for @code{backtrace}.
7918
7919 @cindex multiple threads, backtrace
7920 In a multi-threaded program, @value{GDBN} by default shows the
7921 backtrace only for the current thread. To display the backtrace for
7922 several or all of the threads, use the command @code{thread apply}
7923 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7924 apply all backtrace}, @value{GDBN} will display the backtrace for all
7925 the threads; this is handy when you debug a core dump of a
7926 multi-threaded program.
7927
7928 Each line in the backtrace shows the frame number and the function name.
7929 The program counter value is also shown---unless you use @code{set
7930 print address off}. The backtrace also shows the source file name and
7931 line number, as well as the arguments to the function. The program
7932 counter value is omitted if it is at the beginning of the code for that
7933 line number.
7934
7935 Here is an example of a backtrace. It was made with the command
7936 @samp{bt 3}, so it shows the innermost three frames.
7937
7938 @smallexample
7939 @group
7940 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7941 at builtin.c:993
7942 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
7943 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7944 at macro.c:71
7945 (More stack frames follow...)
7946 @end group
7947 @end smallexample
7948
7949 @noindent
7950 The display for frame zero does not begin with a program counter
7951 value, indicating that your program has stopped at the beginning of the
7952 code for line @code{993} of @code{builtin.c}.
7953
7954 @noindent
7955 The value of parameter @code{data} in frame 1 has been replaced by
7956 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7957 only if it is a scalar (integer, pointer, enumeration, etc). See command
7958 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
7959 on how to configure the way function parameter values are printed.
7960 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
7961 what frame information is printed.
7962
7963 @cindex optimized out, in backtrace
7964 @cindex function call arguments, optimized out
7965 If your program was compiled with optimizations, some compilers will
7966 optimize away arguments passed to functions if those arguments are
7967 never used after the call. Such optimizations generate code that
7968 passes arguments through registers, but doesn't store those arguments
7969 in the stack frame. @value{GDBN} has no way of displaying such
7970 arguments in stack frames other than the innermost one. Here's what
7971 such a backtrace might look like:
7972
7973 @smallexample
7974 @group
7975 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7976 at builtin.c:993
7977 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
7978 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
7979 at macro.c:71
7980 (More stack frames follow...)
7981 @end group
7982 @end smallexample
7983
7984 @noindent
7985 The values of arguments that were not saved in their stack frames are
7986 shown as @samp{<optimized out>}.
7987
7988 If you need to display the values of such optimized-out arguments,
7989 either deduce that from other variables whose values depend on the one
7990 you are interested in, or recompile without optimizations.
7991
7992 @cindex backtrace beyond @code{main} function
7993 @cindex program entry point
7994 @cindex startup code, and backtrace
7995 Most programs have a standard user entry point---a place where system
7996 libraries and startup code transition into user code. For C this is
7997 @code{main}@footnote{
7998 Note that embedded programs (the so-called ``free-standing''
7999 environment) are not required to have a @code{main} function as the
8000 entry point. They could even have multiple entry points.}.
8001 When @value{GDBN} finds the entry function in a backtrace
8002 it will terminate the backtrace, to avoid tracing into highly
8003 system-specific (and generally uninteresting) code.
8004
8005 If you need to examine the startup code, or limit the number of levels
8006 in a backtrace, you can change this behavior:
8007
8008 @table @code
8009 @item set backtrace past-main
8010 @itemx set backtrace past-main on
8011 @anchor{set backtrace past-main}
8012 @kindex set backtrace
8013 Backtraces will continue past the user entry point.
8014
8015 @item set backtrace past-main off
8016 Backtraces will stop when they encounter the user entry point. This is the
8017 default.
8018
8019 @item show backtrace past-main
8020 @kindex show backtrace
8021 Display the current user entry point backtrace policy.
8022
8023 @item set backtrace past-entry
8024 @itemx set backtrace past-entry on
8025 @anchor{set backtrace past-entry}
8026 Backtraces will continue past the internal entry point of an application.
8027 This entry point is encoded by the linker when the application is built,
8028 and is likely before the user entry point @code{main} (or equivalent) is called.
8029
8030 @item set backtrace past-entry off
8031 Backtraces will stop when they encounter the internal entry point of an
8032 application. This is the default.
8033
8034 @item show backtrace past-entry
8035 Display the current internal entry point backtrace policy.
8036
8037 @item set backtrace limit @var{n}
8038 @itemx set backtrace limit 0
8039 @itemx set backtrace limit unlimited
8040 @anchor{set backtrace limit}
8041 @cindex backtrace limit
8042 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8043 or zero means unlimited levels.
8044
8045 @item show backtrace limit
8046 Display the current limit on backtrace levels.
8047 @end table
8048
8049 You can control how file names are displayed.
8050
8051 @table @code
8052 @item set filename-display
8053 @itemx set filename-display relative
8054 @cindex filename-display
8055 Display file names relative to the compilation directory. This is the default.
8056
8057 @item set filename-display basename
8058 Display only basename of a filename.
8059
8060 @item set filename-display absolute
8061 Display an absolute filename.
8062
8063 @item show filename-display
8064 Show the current way to display filenames.
8065 @end table
8066
8067 @node Selection
8068 @section Selecting a Frame
8069
8070 Most commands for examining the stack and other data in your program work on
8071 whichever stack frame is selected at the moment. Here are the commands for
8072 selecting a stack frame; all of them finish by printing a brief description
8073 of the stack frame just selected.
8074
8075 @table @code
8076 @kindex frame@r{, selecting}
8077 @kindex f @r{(@code{frame})}
8078 @item frame @r{[} @var{frame-selection-spec} @r{]}
8079 @item f @r{[} @var{frame-selection-spec} @r{]}
8080 The @command{frame} command allows different stack frames to be
8081 selected. The @var{frame-selection-spec} can be any of the following:
8082
8083 @table @code
8084 @kindex frame level
8085 @item @var{num}
8086 @item level @var{num}
8087 Select frame level @var{num}. Recall that frame zero is the innermost
8088 (currently executing) frame, frame one is the frame that called the
8089 innermost one, and so on. The highest level frame is usually the one
8090 for @code{main}.
8091
8092 As this is the most common method of navigating the frame stack, the
8093 string @command{level} can be omitted. For example, the following two
8094 commands are equivalent:
8095
8096 @smallexample
8097 (@value{GDBP}) frame 3
8098 (@value{GDBP}) frame level 3
8099 @end smallexample
8100
8101 @kindex frame address
8102 @item address @var{stack-address}
8103 Select the frame with stack address @var{stack-address}. The
8104 @var{stack-address} for a frame can be seen in the output of
8105 @command{info frame}, for example:
8106
8107 @smallexample
8108 (gdb) info frame
8109 Stack level 1, frame at 0x7fffffffda30:
8110 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8111 tail call frame, caller of frame at 0x7fffffffda30
8112 source language c++.
8113 Arglist at unknown address.
8114 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8115 @end smallexample
8116
8117 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8118 indicated by the line:
8119
8120 @smallexample
8121 Stack level 1, frame at 0x7fffffffda30:
8122 @end smallexample
8123
8124 @kindex frame function
8125 @item function @var{function-name}
8126 Select the stack frame for function @var{function-name}. If there are
8127 multiple stack frames for function @var{function-name} then the inner
8128 most stack frame is selected.
8129
8130 @kindex frame view
8131 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8132 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8133 viewed has stack address @var{stack-addr}, and optionally, a program
8134 counter address of @var{pc-addr}.
8135
8136 This is useful mainly if the chaining of stack frames has been
8137 damaged by a bug, making it impossible for @value{GDBN} to assign
8138 numbers properly to all frames. In addition, this can be useful
8139 when your program has multiple stacks and switches between them.
8140
8141 When viewing a frame outside the current backtrace using
8142 @command{frame view} then you can always return to the original
8143 stack using one of the previous stack frame selection instructions,
8144 for example @command{frame level 0}.
8145
8146 @end table
8147
8148 @kindex up
8149 @item up @var{n}
8150 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8151 numbers @var{n}, this advances toward the outermost frame, to higher
8152 frame numbers, to frames that have existed longer.
8153
8154 @kindex down
8155 @kindex do @r{(@code{down})}
8156 @item down @var{n}
8157 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8158 positive numbers @var{n}, this advances toward the innermost frame, to
8159 lower frame numbers, to frames that were created more recently.
8160 You may abbreviate @code{down} as @code{do}.
8161 @end table
8162
8163 All of these commands end by printing two lines of output describing the
8164 frame. The first line shows the frame number, the function name, the
8165 arguments, and the source file and line number of execution in that
8166 frame. The second line shows the text of that source line.
8167
8168 @need 1000
8169 For example:
8170
8171 @smallexample
8172 @group
8173 (@value{GDBP}) up
8174 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8175 at env.c:10
8176 10 read_input_file (argv[i]);
8177 @end group
8178 @end smallexample
8179
8180 After such a printout, the @code{list} command with no arguments
8181 prints ten lines centered on the point of execution in the frame.
8182 You can also edit the program at the point of execution with your favorite
8183 editing program by typing @code{edit}.
8184 @xref{List, ,Printing Source Lines},
8185 for details.
8186
8187 @table @code
8188 @kindex select-frame
8189 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8190 The @code{select-frame} command is a variant of @code{frame} that does
8191 not display the new frame after selecting it. This command is
8192 intended primarily for use in @value{GDBN} command scripts, where the
8193 output might be unnecessary and distracting. The
8194 @var{frame-selection-spec} is as for the @command{frame} command
8195 described in @ref{Selection, ,Selecting a Frame}.
8196
8197 @kindex down-silently
8198 @kindex up-silently
8199 @item up-silently @var{n}
8200 @itemx down-silently @var{n}
8201 These two commands are variants of @code{up} and @code{down},
8202 respectively; they differ in that they do their work silently, without
8203 causing display of the new frame. They are intended primarily for use
8204 in @value{GDBN} command scripts, where the output might be unnecessary and
8205 distracting.
8206 @end table
8207
8208 @node Frame Info
8209 @section Information About a Frame
8210
8211 There are several other commands to print information about the selected
8212 stack frame.
8213
8214 @table @code
8215 @item frame
8216 @itemx f
8217 When used without any argument, this command does not change which
8218 frame is selected, but prints a brief description of the currently
8219 selected stack frame. It can be abbreviated @code{f}. With an
8220 argument, this command is used to select a stack frame.
8221 @xref{Selection, ,Selecting a Frame}.
8222
8223 @kindex info frame
8224 @kindex info f @r{(@code{info frame})}
8225 @item info frame
8226 @itemx info f
8227 This command prints a verbose description of the selected stack frame,
8228 including:
8229
8230 @itemize @bullet
8231 @item
8232 the address of the frame
8233 @item
8234 the address of the next frame down (called by this frame)
8235 @item
8236 the address of the next frame up (caller of this frame)
8237 @item
8238 the language in which the source code corresponding to this frame is written
8239 @item
8240 the address of the frame's arguments
8241 @item
8242 the address of the frame's local variables
8243 @item
8244 the program counter saved in it (the address of execution in the caller frame)
8245 @item
8246 which registers were saved in the frame
8247 @end itemize
8248
8249 @noindent The verbose description is useful when
8250 something has gone wrong that has made the stack format fail to fit
8251 the usual conventions.
8252
8253 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8254 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8255 Print a verbose description of the frame selected by
8256 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8257 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8258 a Frame}). The selected frame remains unchanged by this command.
8259
8260 @kindex info args
8261 @item info args [-q]
8262 Print the arguments of the selected frame, each on a separate line.
8263
8264 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8265 printing header information and messages explaining why no argument
8266 have been printed.
8267
8268 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8269 Like @kbd{info args}, but only print the arguments selected
8270 with the provided regexp(s).
8271
8272 If @var{regexp} is provided, print only the arguments whose names
8273 match the regular expression @var{regexp}.
8274
8275 If @var{type_regexp} is provided, print only the arguments whose
8276 types, as printed by the @code{whatis} command, match
8277 the regular expression @var{type_regexp}.
8278 If @var{type_regexp} contains space(s), it should be enclosed in
8279 quote characters. If needed, use backslash to escape the meaning
8280 of special characters or quotes.
8281
8282 If both @var{regexp} and @var{type_regexp} are provided, an argument
8283 is printed only if its name matches @var{regexp} and its type matches
8284 @var{type_regexp}.
8285
8286 @item info locals [-q]
8287 @kindex info locals
8288 Print the local variables of the selected frame, each on a separate
8289 line. These are all variables (declared either static or automatic)
8290 accessible at the point of execution of the selected frame.
8291
8292 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8293 printing header information and messages explaining why no local variables
8294 have been printed.
8295
8296 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8297 Like @kbd{info locals}, but only print the local variables selected
8298 with the provided regexp(s).
8299
8300 If @var{regexp} is provided, print only the local variables whose names
8301 match the regular expression @var{regexp}.
8302
8303 If @var{type_regexp} is provided, print only the local variables whose
8304 types, as printed by the @code{whatis} command, match
8305 the regular expression @var{type_regexp}.
8306 If @var{type_regexp} contains space(s), it should be enclosed in
8307 quote characters. If needed, use backslash to escape the meaning
8308 of special characters or quotes.
8309
8310 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8311 is printed only if its name matches @var{regexp} and its type matches
8312 @var{type_regexp}.
8313
8314 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8315 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8316 For example, your program might use Resource Acquisition Is
8317 Initialization types (RAII) such as @code{lock_something_t}: each
8318 local variable of type @code{lock_something_t} automatically places a
8319 lock that is destroyed when the variable goes out of scope. You can
8320 then list all acquired locks in your program by doing
8321 @smallexample
8322 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8323 @end smallexample
8324 @noindent
8325 or the equivalent shorter form
8326 @smallexample
8327 tfaas i lo -q -t lock_something_t
8328 @end smallexample
8329
8330 @end table
8331
8332 @node Frame Apply
8333 @section Applying a Command to Several Frames.
8334 @anchor{frame apply}
8335 @kindex frame apply
8336 @cindex apply command to several frames
8337 @table @code
8338 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8339 The @code{frame apply} command allows you to apply the named
8340 @var{command} to one or more frames.
8341
8342 @table @code
8343 @item @code{all}
8344 Specify @code{all} to apply @var{command} to all frames.
8345
8346 @item @var{count}
8347 Use @var{count} to apply @var{command} to the innermost @var{count}
8348 frames, where @var{count} is a positive number.
8349
8350 @item @var{-count}
8351 Use @var{-count} to apply @var{command} to the outermost @var{count}
8352 frames, where @var{count} is a positive number.
8353
8354 @item @code{level}
8355 Use @code{level} to apply @var{command} to the set of frames identified
8356 by the @var{level} list. @var{level} is a frame level or a range of frame
8357 levels as @var{level1}-@var{level2}. The frame level is the number shown
8358 in the first field of the @samp{backtrace} command output.
8359 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8360 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8361
8362 @end table
8363
8364 Note that the frames on which @code{frame apply} applies a command are
8365 also influenced by the @code{set backtrace} settings such as @code{set
8366 backtrace past-main} and @code{set backtrace limit N}.
8367 @xref{Backtrace,,Backtraces}.
8368
8369 The @code{frame apply} command also supports a number of options that
8370 allow overriding relevant @code{set backtrace} settings:
8371
8372 @table @code
8373 @item -past-main [@code{on}|@code{off}]
8374 Whether backtraces should continue past @code{main}.
8375 Related setting: @ref{set backtrace past-main}.
8376
8377 @item -past-entry [@code{on}|@code{off}]
8378 Whether backtraces should continue past the entry point of a program.
8379 Related setting: @ref{set backtrace past-entry}.
8380 @end table
8381
8382 By default, @value{GDBN} displays some frame information before the
8383 output produced by @var{command}, and an error raised during the
8384 execution of a @var{command} will abort @code{frame apply}. The
8385 following options can be used to fine-tune these behaviors:
8386
8387 @table @code
8388 @item -c
8389 The flag @code{-c}, which stands for @samp{continue}, causes any
8390 errors in @var{command} to be displayed, and the execution of
8391 @code{frame apply} then continues.
8392 @item -s
8393 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8394 or empty output produced by a @var{command} to be silently ignored.
8395 That is, the execution continues, but the frame information and errors
8396 are not printed.
8397 @item -q
8398 The flag @code{-q} (@samp{quiet}) disables printing the frame
8399 information.
8400 @end table
8401
8402 The following example shows how the flags @code{-c} and @code{-s} are
8403 working when applying the command @code{p j} to all frames, where
8404 variable @code{j} can only be successfully printed in the outermost
8405 @code{#1 main} frame.
8406
8407 @smallexample
8408 @group
8409 (gdb) frame apply all p j
8410 #0 some_function (i=5) at fun.c:4
8411 No symbol "j" in current context.
8412 (gdb) frame apply all -c p j
8413 #0 some_function (i=5) at fun.c:4
8414 No symbol "j" in current context.
8415 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8416 $1 = 5
8417 (gdb) frame apply all -s p j
8418 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8419 $2 = 5
8420 (gdb)
8421 @end group
8422 @end smallexample
8423
8424 By default, @samp{frame apply}, prints the frame location
8425 information before the command output:
8426
8427 @smallexample
8428 @group
8429 (gdb) frame apply all p $sp
8430 #0 some_function (i=5) at fun.c:4
8431 $4 = (void *) 0xffffd1e0
8432 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8433 $5 = (void *) 0xffffd1f0
8434 (gdb)
8435 @end group
8436 @end smallexample
8437
8438 If the flag @code{-q} is given, no frame information is printed:
8439 @smallexample
8440 @group
8441 (gdb) frame apply all -q p $sp
8442 $12 = (void *) 0xffffd1e0
8443 $13 = (void *) 0xffffd1f0
8444 (gdb)
8445 @end group
8446 @end smallexample
8447
8448 @end table
8449
8450 @table @code
8451
8452 @kindex faas
8453 @cindex apply a command to all frames (ignoring errors and empty output)
8454 @item faas @var{command}
8455 Shortcut for @code{frame apply all -s @var{command}}.
8456 Applies @var{command} on all frames, ignoring errors and empty output.
8457
8458 It can for example be used to print a local variable or a function
8459 argument without knowing the frame where this variable or argument
8460 is, using:
8461 @smallexample
8462 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8463 @end smallexample
8464
8465 The @code{faas} command accepts the same options as the @code{frame
8466 apply} command. @xref{frame apply}.
8467
8468 Note that the command @code{tfaas @var{command}} applies @var{command}
8469 on all frames of all threads. See @xref{Threads,,Threads}.
8470 @end table
8471
8472
8473 @node Frame Filter Management
8474 @section Management of Frame Filters.
8475 @cindex managing frame filters
8476
8477 Frame filters are Python based utilities to manage and decorate the
8478 output of frames. @xref{Frame Filter API}, for further information.
8479
8480 Managing frame filters is performed by several commands available
8481 within @value{GDBN}, detailed here.
8482
8483 @table @code
8484 @kindex info frame-filter
8485 @item info frame-filter
8486 Print a list of installed frame filters from all dictionaries, showing
8487 their name, priority and enabled status.
8488
8489 @kindex disable frame-filter
8490 @anchor{disable frame-filter all}
8491 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8492 Disable a frame filter in the dictionary matching
8493 @var{filter-dictionary} and @var{filter-name}. The
8494 @var{filter-dictionary} may be @code{all}, @code{global},
8495 @code{progspace}, or the name of the object file where the frame filter
8496 dictionary resides. When @code{all} is specified, all frame filters
8497 across all dictionaries are disabled. The @var{filter-name} is the name
8498 of the frame filter and is used when @code{all} is not the option for
8499 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8500 may be enabled again later.
8501
8502 @kindex enable frame-filter
8503 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8504 Enable a frame filter in the dictionary matching
8505 @var{filter-dictionary} and @var{filter-name}. The
8506 @var{filter-dictionary} may be @code{all}, @code{global},
8507 @code{progspace} or the name of the object file where the frame filter
8508 dictionary resides. When @code{all} is specified, all frame filters across
8509 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8510 filter and is used when @code{all} is not the option for
8511 @var{filter-dictionary}.
8512
8513 Example:
8514
8515 @smallexample
8516 (gdb) info frame-filter
8517
8518 global frame-filters:
8519 Priority Enabled Name
8520 1000 No PrimaryFunctionFilter
8521 100 Yes Reverse
8522
8523 progspace /build/test frame-filters:
8524 Priority Enabled Name
8525 100 Yes ProgspaceFilter
8526
8527 objfile /build/test frame-filters:
8528 Priority Enabled Name
8529 999 Yes BuildProgramFilter
8530
8531 (gdb) disable frame-filter /build/test BuildProgramFilter
8532 (gdb) info frame-filter
8533
8534 global frame-filters:
8535 Priority Enabled Name
8536 1000 No PrimaryFunctionFilter
8537 100 Yes Reverse
8538
8539 progspace /build/test frame-filters:
8540 Priority Enabled Name
8541 100 Yes ProgspaceFilter
8542
8543 objfile /build/test frame-filters:
8544 Priority Enabled Name
8545 999 No BuildProgramFilter
8546
8547 (gdb) enable frame-filter global PrimaryFunctionFilter
8548 (gdb) info frame-filter
8549
8550 global frame-filters:
8551 Priority Enabled Name
8552 1000 Yes PrimaryFunctionFilter
8553 100 Yes Reverse
8554
8555 progspace /build/test frame-filters:
8556 Priority Enabled Name
8557 100 Yes ProgspaceFilter
8558
8559 objfile /build/test frame-filters:
8560 Priority Enabled Name
8561 999 No BuildProgramFilter
8562 @end smallexample
8563
8564 @kindex set frame-filter priority
8565 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8566 Set the @var{priority} of a frame filter in the dictionary matching
8567 @var{filter-dictionary}, and the frame filter name matching
8568 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8569 @code{progspace} or the name of the object file where the frame filter
8570 dictionary resides. The @var{priority} is an integer.
8571
8572 @kindex show frame-filter priority
8573 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8574 Show the @var{priority} of a frame filter in the dictionary matching
8575 @var{filter-dictionary}, and the frame filter name matching
8576 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8577 @code{progspace} or the name of the object file where the frame filter
8578 dictionary resides.
8579
8580 Example:
8581
8582 @smallexample
8583 (gdb) info frame-filter
8584
8585 global frame-filters:
8586 Priority Enabled Name
8587 1000 Yes PrimaryFunctionFilter
8588 100 Yes Reverse
8589
8590 progspace /build/test frame-filters:
8591 Priority Enabled Name
8592 100 Yes ProgspaceFilter
8593
8594 objfile /build/test frame-filters:
8595 Priority Enabled Name
8596 999 No BuildProgramFilter
8597
8598 (gdb) set frame-filter priority global Reverse 50
8599 (gdb) info frame-filter
8600
8601 global frame-filters:
8602 Priority Enabled Name
8603 1000 Yes PrimaryFunctionFilter
8604 50 Yes Reverse
8605
8606 progspace /build/test frame-filters:
8607 Priority Enabled Name
8608 100 Yes ProgspaceFilter
8609
8610 objfile /build/test frame-filters:
8611 Priority Enabled Name
8612 999 No BuildProgramFilter
8613 @end smallexample
8614 @end table
8615
8616 @node Source
8617 @chapter Examining Source Files
8618
8619 @value{GDBN} can print parts of your program's source, since the debugging
8620 information recorded in the program tells @value{GDBN} what source files were
8621 used to build it. When your program stops, @value{GDBN} spontaneously prints
8622 the line where it stopped. Likewise, when you select a stack frame
8623 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8624 execution in that frame has stopped. You can print other portions of
8625 source files by explicit command.
8626
8627 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8628 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8629 @value{GDBN} under @sc{gnu} Emacs}.
8630
8631 @menu
8632 * List:: Printing source lines
8633 * Specify Location:: How to specify code locations
8634 * Edit:: Editing source files
8635 * Search:: Searching source files
8636 * Source Path:: Specifying source directories
8637 * Machine Code:: Source and machine code
8638 @end menu
8639
8640 @node List
8641 @section Printing Source Lines
8642
8643 @kindex list
8644 @kindex l @r{(@code{list})}
8645 To print lines from a source file, use the @code{list} command
8646 (abbreviated @code{l}). By default, ten lines are printed.
8647 There are several ways to specify what part of the file you want to
8648 print; see @ref{Specify Location}, for the full list.
8649
8650 Here are the forms of the @code{list} command most commonly used:
8651
8652 @table @code
8653 @item list @var{linenum}
8654 Print lines centered around line number @var{linenum} in the
8655 current source file.
8656
8657 @item list @var{function}
8658 Print lines centered around the beginning of function
8659 @var{function}.
8660
8661 @item list
8662 Print more lines. If the last lines printed were printed with a
8663 @code{list} command, this prints lines following the last lines
8664 printed; however, if the last line printed was a solitary line printed
8665 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8666 Stack}), this prints lines centered around that line.
8667
8668 @item list -
8669 Print lines just before the lines last printed.
8670 @end table
8671
8672 @cindex @code{list}, how many lines to display
8673 By default, @value{GDBN} prints ten source lines with any of these forms of
8674 the @code{list} command. You can change this using @code{set listsize}:
8675
8676 @table @code
8677 @kindex set listsize
8678 @item set listsize @var{count}
8679 @itemx set listsize unlimited
8680 Make the @code{list} command display @var{count} source lines (unless
8681 the @code{list} argument explicitly specifies some other number).
8682 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8683
8684 @kindex show listsize
8685 @item show listsize
8686 Display the number of lines that @code{list} prints.
8687 @end table
8688
8689 Repeating a @code{list} command with @key{RET} discards the argument,
8690 so it is equivalent to typing just @code{list}. This is more useful
8691 than listing the same lines again. An exception is made for an
8692 argument of @samp{-}; that argument is preserved in repetition so that
8693 each repetition moves up in the source file.
8694
8695 In general, the @code{list} command expects you to supply zero, one or two
8696 @dfn{locations}. Locations specify source lines; there are several ways
8697 of writing them (@pxref{Specify Location}), but the effect is always
8698 to specify some source line.
8699
8700 Here is a complete description of the possible arguments for @code{list}:
8701
8702 @table @code
8703 @item list @var{location}
8704 Print lines centered around the line specified by @var{location}.
8705
8706 @item list @var{first},@var{last}
8707 Print lines from @var{first} to @var{last}. Both arguments are
8708 locations. When a @code{list} command has two locations, and the
8709 source file of the second location is omitted, this refers to
8710 the same source file as the first location.
8711
8712 @item list ,@var{last}
8713 Print lines ending with @var{last}.
8714
8715 @item list @var{first},
8716 Print lines starting with @var{first}.
8717
8718 @item list +
8719 Print lines just after the lines last printed.
8720
8721 @item list -
8722 Print lines just before the lines last printed.
8723
8724 @item list
8725 As described in the preceding table.
8726 @end table
8727
8728 @node Specify Location
8729 @section Specifying a Location
8730 @cindex specifying location
8731 @cindex location
8732 @cindex source location
8733
8734 @menu
8735 * Linespec Locations:: Linespec locations
8736 * Explicit Locations:: Explicit locations
8737 * Address Locations:: Address locations
8738 @end menu
8739
8740 Several @value{GDBN} commands accept arguments that specify a location
8741 of your program's code. Since @value{GDBN} is a source-level
8742 debugger, a location usually specifies some line in the source code.
8743 Locations may be specified using three different formats:
8744 linespec locations, explicit locations, or address locations.
8745
8746 @node Linespec Locations
8747 @subsection Linespec Locations
8748 @cindex linespec locations
8749
8750 A @dfn{linespec} is a colon-separated list of source location parameters such
8751 as file name, function name, etc. Here are all the different ways of
8752 specifying a linespec:
8753
8754 @table @code
8755 @item @var{linenum}
8756 Specifies the line number @var{linenum} of the current source file.
8757
8758 @item -@var{offset}
8759 @itemx +@var{offset}
8760 Specifies the line @var{offset} lines before or after the @dfn{current
8761 line}. For the @code{list} command, the current line is the last one
8762 printed; for the breakpoint commands, this is the line at which
8763 execution stopped in the currently selected @dfn{stack frame}
8764 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
8765 used as the second of the two linespecs in a @code{list} command,
8766 this specifies the line @var{offset} lines up or down from the first
8767 linespec.
8768
8769 @item @var{filename}:@var{linenum}
8770 Specifies the line @var{linenum} in the source file @var{filename}.
8771 If @var{filename} is a relative file name, then it will match any
8772 source file name with the same trailing components. For example, if
8773 @var{filename} is @samp{gcc/expr.c}, then it will match source file
8774 name of @file{/build/trunk/gcc/expr.c}, but not
8775 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
8776
8777 @item @var{function}
8778 Specifies the line that begins the body of the function @var{function}.
8779 For example, in C, this is the line with the open brace.
8780
8781 By default, in C@t{++} and Ada, @var{function} is interpreted as
8782 specifying all functions named @var{function} in all scopes. For
8783 C@t{++}, this means in all namespaces and classes. For Ada, this
8784 means in all packages.
8785
8786 For example, assuming a program with C@t{++} symbols named
8787 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8788 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8789
8790 Commands that accept a linespec let you override this with the
8791 @code{-qualified} option. For example, @w{@kbd{break -qualified
8792 func}} sets a breakpoint on a free-function named @code{func} ignoring
8793 any C@t{++} class methods and namespace functions called @code{func}.
8794
8795 @xref{Explicit Locations}.
8796
8797 @item @var{function}:@var{label}
8798 Specifies the line where @var{label} appears in @var{function}.
8799
8800 @item @var{filename}:@var{function}
8801 Specifies the line that begins the body of the function @var{function}
8802 in the file @var{filename}. You only need the file name with a
8803 function name to avoid ambiguity when there are identically named
8804 functions in different source files.
8805
8806 @item @var{label}
8807 Specifies the line at which the label named @var{label} appears
8808 in the function corresponding to the currently selected stack frame.
8809 If there is no current selected stack frame (for instance, if the inferior
8810 is not running), then @value{GDBN} will not search for a label.
8811
8812 @cindex breakpoint at static probe point
8813 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8814 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8815 applications to embed static probes. @xref{Static Probe Points}, for more
8816 information on finding and using static probes. This form of linespec
8817 specifies the location of such a static probe.
8818
8819 If @var{objfile} is given, only probes coming from that shared library
8820 or executable matching @var{objfile} as a regular expression are considered.
8821 If @var{provider} is given, then only probes from that provider are considered.
8822 If several probes match the spec, @value{GDBN} will insert a breakpoint at
8823 each one of those probes.
8824 @end table
8825
8826 @node Explicit Locations
8827 @subsection Explicit Locations
8828 @cindex explicit locations
8829
8830 @dfn{Explicit locations} allow the user to directly specify the source
8831 location's parameters using option-value pairs.
8832
8833 Explicit locations are useful when several functions, labels, or
8834 file names have the same name (base name for files) in the program's
8835 sources. In these cases, explicit locations point to the source
8836 line you meant more accurately and unambiguously. Also, using
8837 explicit locations might be faster in large programs.
8838
8839 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8840 defined in the file named @file{foo} or the label @code{bar} in a function
8841 named @code{foo}. @value{GDBN} must search either the file system or
8842 the symbol table to know.
8843
8844 The list of valid explicit location options is summarized in the
8845 following table:
8846
8847 @table @code
8848 @item -source @var{filename}
8849 The value specifies the source file name. To differentiate between
8850 files with the same base name, prepend as many directories as is necessary
8851 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8852 @value{GDBN} will use the first file it finds with the given base
8853 name. This option requires the use of either @code{-function} or @code{-line}.
8854
8855 @item -function @var{function}
8856 The value specifies the name of a function. Operations
8857 on function locations unmodified by other options (such as @code{-label}
8858 or @code{-line}) refer to the line that begins the body of the function.
8859 In C, for example, this is the line with the open brace.
8860
8861 By default, in C@t{++} and Ada, @var{function} is interpreted as
8862 specifying all functions named @var{function} in all scopes. For
8863 C@t{++}, this means in all namespaces and classes. For Ada, this
8864 means in all packages.
8865
8866 For example, assuming a program with C@t{++} symbols named
8867 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8868 -function func}} and @w{@kbd{break -function B::func}} set a
8869 breakpoint on both symbols.
8870
8871 You can use the @kbd{-qualified} flag to override this (see below).
8872
8873 @item -qualified
8874
8875 This flag makes @value{GDBN} interpret a function name specified with
8876 @kbd{-function} as a complete fully-qualified name.
8877
8878 For example, assuming a C@t{++} program with symbols named
8879 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8880 -function B::func}} command sets a breakpoint on @code{B::func}, only.
8881
8882 (Note: the @kbd{-qualified} option can precede a linespec as well
8883 (@pxref{Linespec Locations}), so the particular example above could be
8884 simplified as @w{@kbd{break -qualified B::func}}.)
8885
8886 @item -label @var{label}
8887 The value specifies the name of a label. When the function
8888 name is not specified, the label is searched in the function of the currently
8889 selected stack frame.
8890
8891 @item -line @var{number}
8892 The value specifies a line offset for the location. The offset may either
8893 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
8894 the command. When specified without any other options, the line offset is
8895 relative to the current line.
8896 @end table
8897
8898 Explicit location options may be abbreviated by omitting any non-unique
8899 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
8900
8901 @node Address Locations
8902 @subsection Address Locations
8903 @cindex address locations
8904
8905 @dfn{Address locations} indicate a specific program address. They have
8906 the generalized form *@var{address}.
8907
8908 For line-oriented commands, such as @code{list} and @code{edit}, this
8909 specifies a source line that contains @var{address}. For @code{break} and
8910 other breakpoint-oriented commands, this can be used to set breakpoints in
8911 parts of your program which do not have debugging information or
8912 source files.
8913
8914 Here @var{address} may be any expression valid in the current working
8915 language (@pxref{Languages, working language}) that specifies a code
8916 address. In addition, as a convenience, @value{GDBN} extends the
8917 semantics of expressions used in locations to cover several situations
8918 that frequently occur during debugging. Here are the various forms
8919 of @var{address}:
8920
8921 @table @code
8922 @item @var{expression}
8923 Any expression valid in the current working language.
8924
8925 @item @var{funcaddr}
8926 An address of a function or procedure derived from its name. In C,
8927 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
8928 simply the function's name @var{function} (and actually a special case
8929 of a valid expression). In Pascal and Modula-2, this is
8930 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
8931 (although the Pascal form also works).
8932
8933 This form specifies the address of the function's first instruction,
8934 before the stack frame and arguments have been set up.
8935
8936 @item '@var{filename}':@var{funcaddr}
8937 Like @var{funcaddr} above, but also specifies the name of the source
8938 file explicitly. This is useful if the name of the function does not
8939 specify the function unambiguously, e.g., if there are several
8940 functions with identical names in different source files.
8941 @end table
8942
8943 @node Edit
8944 @section Editing Source Files
8945 @cindex editing source files
8946
8947 @kindex edit
8948 @kindex e @r{(@code{edit})}
8949 To edit the lines in a source file, use the @code{edit} command.
8950 The editing program of your choice
8951 is invoked with the current line set to
8952 the active line in the program.
8953 Alternatively, there are several ways to specify what part of the file you
8954 want to print if you want to see other parts of the program:
8955
8956 @table @code
8957 @item edit @var{location}
8958 Edit the source file specified by @code{location}. Editing starts at
8959 that @var{location}, e.g., at the specified source line of the
8960 specified file. @xref{Specify Location}, for all the possible forms
8961 of the @var{location} argument; here are the forms of the @code{edit}
8962 command most commonly used:
8963
8964 @table @code
8965 @item edit @var{number}
8966 Edit the current source file with @var{number} as the active line number.
8967
8968 @item edit @var{function}
8969 Edit the file containing @var{function} at the beginning of its definition.
8970 @end table
8971
8972 @end table
8973
8974 @subsection Choosing your Editor
8975 You can customize @value{GDBN} to use any editor you want
8976 @footnote{
8977 The only restriction is that your editor (say @code{ex}), recognizes the
8978 following command-line syntax:
8979 @smallexample
8980 ex +@var{number} file
8981 @end smallexample
8982 The optional numeric value +@var{number} specifies the number of the line in
8983 the file where to start editing.}.
8984 By default, it is @file{@value{EDITOR}}, but you can change this
8985 by setting the environment variable @code{EDITOR} before using
8986 @value{GDBN}. For example, to configure @value{GDBN} to use the
8987 @code{vi} editor, you could use these commands with the @code{sh} shell:
8988 @smallexample
8989 EDITOR=/usr/bin/vi
8990 export EDITOR
8991 gdb @dots{}
8992 @end smallexample
8993 or in the @code{csh} shell,
8994 @smallexample
8995 setenv EDITOR /usr/bin/vi
8996 gdb @dots{}
8997 @end smallexample
8998
8999 @node Search
9000 @section Searching Source Files
9001 @cindex searching source files
9002
9003 There are two commands for searching through the current source file for a
9004 regular expression.
9005
9006 @table @code
9007 @kindex search
9008 @kindex forward-search
9009 @kindex fo @r{(@code{forward-search})}
9010 @item forward-search @var{regexp}
9011 @itemx search @var{regexp}
9012 The command @samp{forward-search @var{regexp}} checks each line,
9013 starting with the one following the last line listed, for a match for
9014 @var{regexp}. It lists the line that is found. You can use the
9015 synonym @samp{search @var{regexp}} or abbreviate the command name as
9016 @code{fo}.
9017
9018 @kindex reverse-search
9019 @item reverse-search @var{regexp}
9020 The command @samp{reverse-search @var{regexp}} checks each line, starting
9021 with the one before the last line listed and going backward, for a match
9022 for @var{regexp}. It lists the line that is found. You can abbreviate
9023 this command as @code{rev}.
9024 @end table
9025
9026 @node Source Path
9027 @section Specifying Source Directories
9028
9029 @cindex source path
9030 @cindex directories for source files
9031 Executable programs sometimes do not record the directories of the source
9032 files from which they were compiled, just the names. Even when they do,
9033 the directories could be moved between the compilation and your debugging
9034 session. @value{GDBN} has a list of directories to search for source files;
9035 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9036 it tries all the directories in the list, in the order they are present
9037 in the list, until it finds a file with the desired name.
9038
9039 For example, suppose an executable references the file
9040 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9041 directory, and the @dfn{source path} is @file{/mnt/cross}.
9042 @value{GDBN} would look for the source file in the following
9043 locations:
9044
9045 @enumerate
9046
9047 @item @file{/usr/src/foo-1.0/lib/foo.c}
9048 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9049 @item @file{/mnt/cross/foo.c}
9050
9051 @end enumerate
9052
9053 If the source file is not present at any of the above locations then
9054 an error is printed. @value{GDBN} does not look up the parts of the
9055 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9056 Likewise, the subdirectories of the source path are not searched: if
9057 the source path is @file{/mnt/cross}, and the binary refers to
9058 @file{foo.c}, @value{GDBN} would not find it under
9059 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9060
9061 Plain file names, relative file names with leading directories, file
9062 names containing dots, etc.@: are all treated as described above,
9063 except that non-absolute file names are not looked up literally. If
9064 the @dfn{source path} is @file{/mnt/cross}, the source file is
9065 recorded as @file{../lib/foo.c}, and no compilation directory is
9066 recorded, then @value{GDBN} will search in the following locations:
9067
9068 @enumerate
9069
9070 @item @file{/mnt/cross/../lib/foo.c}
9071 @item @file{/mnt/cross/foo.c}
9072
9073 @end enumerate
9074
9075 @kindex cdir
9076 @kindex cwd
9077 @vindex $cdir@r{, convenience variable}
9078 @vindex $cwd@r{, convenience variable}
9079 @cindex compilation directory
9080 @cindex current directory
9081 @cindex working directory
9082 @cindex directory, current
9083 @cindex directory, compilation
9084 The @dfn{source path} will always include two special entries
9085 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9086 (if one is recorded) and the current working directory respectively.
9087
9088 @samp{$cdir} causes @value{GDBN} to search within the compilation
9089 directory, if one is recorded in the debug information. If no
9090 compilation directory is recorded in the debug information then
9091 @samp{$cdir} is ignored.
9092
9093 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9094 current working directory as it changes during your @value{GDBN}
9095 session, while the latter is immediately expanded to the current
9096 directory at the time you add an entry to the source path.
9097
9098 If a compilation directory is recorded in the debug information, and
9099 @value{GDBN} has not found the source file after the first search
9100 using @dfn{source path}, then @value{GDBN} will combine the
9101 compilation directory and the filename, and then search for the source
9102 file again using the @dfn{source path}.
9103
9104 For example, if the executable records the source file as
9105 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9106 recorded as @file{/project/build}, and the @dfn{source path} is
9107 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9108 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9109 search for the source file in the following locations:
9110
9111 @enumerate
9112
9113 @item @file{/usr/src/foo-1.0/lib/foo.c}
9114 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9115 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9116 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9117 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9118 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9119 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9120 @item @file{/mnt/cross/foo.c}
9121 @item @file{/project/build/foo.c}
9122 @item @file{/home/user/foo.c}
9123
9124 @end enumerate
9125
9126 If the file name in the previous example had been recorded in the
9127 executable as a relative path rather than an absolute path, then the
9128 first look up would not have occurred, but all of the remaining steps
9129 would be similar.
9130
9131 When searching for source files on MS-DOS and MS-Windows, where
9132 absolute paths start with a drive letter (e.g.
9133 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9134 from the file name before appending it to a search directory from
9135 @dfn{source path}; for instance if the executable references the
9136 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9137 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9138 locations for the source file:
9139
9140 @enumerate
9141
9142 @item @file{C:/project/foo.c}
9143 @item @file{D:/mnt/cross/project/foo.c}
9144 @item @file{D:/mnt/cross/foo.c}
9145
9146 @end enumerate
9147
9148 Note that the executable search path is @emph{not} used to locate the
9149 source files.
9150
9151 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9152 any information it has cached about where source files are found and where
9153 each line is in the file.
9154
9155 @kindex directory
9156 @kindex dir
9157 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9158 and @samp{$cwd}, in that order.
9159 To add other directories, use the @code{directory} command.
9160
9161 The search path is used to find both program source files and @value{GDBN}
9162 script files (read using the @samp{-command} option and @samp{source} command).
9163
9164 In addition to the source path, @value{GDBN} provides a set of commands
9165 that manage a list of source path substitution rules. A @dfn{substitution
9166 rule} specifies how to rewrite source directories stored in the program's
9167 debug information in case the sources were moved to a different
9168 directory between compilation and debugging. A rule is made of
9169 two strings, the first specifying what needs to be rewritten in
9170 the path, and the second specifying how it should be rewritten.
9171 In @ref{set substitute-path}, we name these two parts @var{from} and
9172 @var{to} respectively. @value{GDBN} does a simple string replacement
9173 of @var{from} with @var{to} at the start of the directory part of the
9174 source file name, and uses that result instead of the original file
9175 name to look up the sources.
9176
9177 Using the previous example, suppose the @file{foo-1.0} tree has been
9178 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9179 @value{GDBN} to replace @file{/usr/src} in all source path names with
9180 @file{/mnt/cross}. The first lookup will then be
9181 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9182 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9183 substitution rule, use the @code{set substitute-path} command
9184 (@pxref{set substitute-path}).
9185
9186 To avoid unexpected substitution results, a rule is applied only if the
9187 @var{from} part of the directory name ends at a directory separator.
9188 For instance, a rule substituting @file{/usr/source} into
9189 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9190 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9191 is applied only at the beginning of the directory name, this rule will
9192 not be applied to @file{/root/usr/source/baz.c} either.
9193
9194 In many cases, you can achieve the same result using the @code{directory}
9195 command. However, @code{set substitute-path} can be more efficient in
9196 the case where the sources are organized in a complex tree with multiple
9197 subdirectories. With the @code{directory} command, you need to add each
9198 subdirectory of your project. If you moved the entire tree while
9199 preserving its internal organization, then @code{set substitute-path}
9200 allows you to direct the debugger to all the sources with one single
9201 command.
9202
9203 @code{set substitute-path} is also more than just a shortcut command.
9204 The source path is only used if the file at the original location no
9205 longer exists. On the other hand, @code{set substitute-path} modifies
9206 the debugger behavior to look at the rewritten location instead. So, if
9207 for any reason a source file that is not relevant to your executable is
9208 located at the original location, a substitution rule is the only
9209 method available to point @value{GDBN} at the new location.
9210
9211 @cindex @samp{--with-relocated-sources}
9212 @cindex default source path substitution
9213 You can configure a default source path substitution rule by
9214 configuring @value{GDBN} with the
9215 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9216 should be the name of a directory under @value{GDBN}'s configured
9217 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9218 directory names in debug information under @var{dir} will be adjusted
9219 automatically if the installed @value{GDBN} is moved to a new
9220 location. This is useful if @value{GDBN}, libraries or executables
9221 with debug information and corresponding source code are being moved
9222 together.
9223
9224 @table @code
9225 @item directory @var{dirname} @dots{}
9226 @item dir @var{dirname} @dots{}
9227 Add directory @var{dirname} to the front of the source path. Several
9228 directory names may be given to this command, separated by @samp{:}
9229 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9230 part of absolute file names) or
9231 whitespace. You may specify a directory that is already in the source
9232 path; this moves it forward, so @value{GDBN} searches it sooner.
9233
9234 The special strings @samp{$cdir} (to refer to the compilation
9235 directory, if one is recorded), and @samp{$cwd} (to refer to the
9236 current working directory) can also be included in the list of
9237 directories @var{dirname}. Though these will already be in the source
9238 path they will be moved forward in the list so @value{GDBN} searches
9239 them sooner.
9240
9241 @item directory
9242 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9243
9244 @c RET-repeat for @code{directory} is explicitly disabled, but since
9245 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9246
9247 @item set directories @var{path-list}
9248 @kindex set directories
9249 Set the source path to @var{path-list}.
9250 @samp{$cdir:$cwd} are added if missing.
9251
9252 @item show directories
9253 @kindex show directories
9254 Print the source path: show which directories it contains.
9255
9256 @anchor{set substitute-path}
9257 @item set substitute-path @var{from} @var{to}
9258 @kindex set substitute-path
9259 Define a source path substitution rule, and add it at the end of the
9260 current list of existing substitution rules. If a rule with the same
9261 @var{from} was already defined, then the old rule is also deleted.
9262
9263 For example, if the file @file{/foo/bar/baz.c} was moved to
9264 @file{/mnt/cross/baz.c}, then the command
9265
9266 @smallexample
9267 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9268 @end smallexample
9269
9270 @noindent
9271 will tell @value{GDBN} to replace @samp{/foo/bar} with
9272 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9273 @file{baz.c} even though it was moved.
9274
9275 In the case when more than one substitution rule have been defined,
9276 the rules are evaluated one by one in the order where they have been
9277 defined. The first one matching, if any, is selected to perform
9278 the substitution.
9279
9280 For instance, if we had entered the following commands:
9281
9282 @smallexample
9283 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9284 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9285 @end smallexample
9286
9287 @noindent
9288 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9289 @file{/mnt/include/defs.h} by using the first rule. However, it would
9290 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9291 @file{/mnt/src/lib/foo.c}.
9292
9293
9294 @item unset substitute-path [path]
9295 @kindex unset substitute-path
9296 If a path is specified, search the current list of substitution rules
9297 for a rule that would rewrite that path. Delete that rule if found.
9298 A warning is emitted by the debugger if no rule could be found.
9299
9300 If no path is specified, then all substitution rules are deleted.
9301
9302 @item show substitute-path [path]
9303 @kindex show substitute-path
9304 If a path is specified, then print the source path substitution rule
9305 which would rewrite that path, if any.
9306
9307 If no path is specified, then print all existing source path substitution
9308 rules.
9309
9310 @end table
9311
9312 If your source path is cluttered with directories that are no longer of
9313 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9314 versions of source. You can correct the situation as follows:
9315
9316 @enumerate
9317 @item
9318 Use @code{directory} with no argument to reset the source path to its default value.
9319
9320 @item
9321 Use @code{directory} with suitable arguments to reinstall the
9322 directories you want in the source path. You can add all the
9323 directories in one command.
9324 @end enumerate
9325
9326 @node Machine Code
9327 @section Source and Machine Code
9328 @cindex source line and its code address
9329
9330 You can use the command @code{info line} to map source lines to program
9331 addresses (and vice versa), and the command @code{disassemble} to display
9332 a range of addresses as machine instructions. You can use the command
9333 @code{set disassemble-next-line} to set whether to disassemble next
9334 source line when execution stops. When run under @sc{gnu} Emacs
9335 mode, the @code{info line} command causes the arrow to point to the
9336 line specified. Also, @code{info line} prints addresses in symbolic form as
9337 well as hex.
9338
9339 @table @code
9340 @kindex info line
9341 @item info line
9342 @itemx info line @var{location}
9343 Print the starting and ending addresses of the compiled code for
9344 source line @var{location}. You can specify source lines in any of
9345 the ways documented in @ref{Specify Location}. With no @var{location}
9346 information about the current source line is printed.
9347 @end table
9348
9349 For example, we can use @code{info line} to discover the location of
9350 the object code for the first line of function
9351 @code{m4_changequote}:
9352
9353 @smallexample
9354 (@value{GDBP}) info line m4_changequote
9355 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9356 ends at 0x6350 <m4_changequote+4>.
9357 @end smallexample
9358
9359 @noindent
9360 @cindex code address and its source line
9361 We can also inquire (using @code{*@var{addr}} as the form for
9362 @var{location}) what source line covers a particular address:
9363 @smallexample
9364 (@value{GDBP}) info line *0x63ff
9365 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9366 ends at 0x6404 <m4_changequote+184>.
9367 @end smallexample
9368
9369 @cindex @code{$_} and @code{info line}
9370 @cindex @code{x} command, default address
9371 @kindex x@r{(examine), and} info line
9372 After @code{info line}, the default address for the @code{x} command
9373 is changed to the starting address of the line, so that @samp{x/i} is
9374 sufficient to begin examining the machine code (@pxref{Memory,
9375 ,Examining Memory}). Also, this address is saved as the value of the
9376 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9377 Variables}).
9378
9379 @cindex info line, repeated calls
9380 After @code{info line}, using @code{info line} again without
9381 specifying a location will display information about the next source
9382 line.
9383
9384 @table @code
9385 @kindex disassemble
9386 @cindex assembly instructions
9387 @cindex instructions, assembly
9388 @cindex machine instructions
9389 @cindex listing machine instructions
9390 @item disassemble
9391 @itemx disassemble /m
9392 @itemx disassemble /s
9393 @itemx disassemble /r
9394 This specialized command dumps a range of memory as machine
9395 instructions. It can also print mixed source+disassembly by specifying
9396 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9397 as well as in symbolic form by specifying the @code{/r} modifier.
9398 The default memory range is the function surrounding the
9399 program counter of the selected frame. A single argument to this
9400 command is a program counter value; @value{GDBN} dumps the function
9401 surrounding this value. When two arguments are given, they should
9402 be separated by a comma, possibly surrounded by whitespace. The
9403 arguments specify a range of addresses to dump, in one of two forms:
9404
9405 @table @code
9406 @item @var{start},@var{end}
9407 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9408 @item @var{start},+@var{length}
9409 the addresses from @var{start} (inclusive) to
9410 @code{@var{start}+@var{length}} (exclusive).
9411 @end table
9412
9413 @noindent
9414 When 2 arguments are specified, the name of the function is also
9415 printed (since there could be several functions in the given range).
9416
9417 The argument(s) can be any expression yielding a numeric value, such as
9418 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9419
9420 If the range of memory being disassembled contains current program counter,
9421 the instruction at that location is shown with a @code{=>} marker.
9422 @end table
9423
9424 The following example shows the disassembly of a range of addresses of
9425 HP PA-RISC 2.0 code:
9426
9427 @smallexample
9428 (@value{GDBP}) disas 0x32c4, 0x32e4
9429 Dump of assembler code from 0x32c4 to 0x32e4:
9430 0x32c4 <main+204>: addil 0,dp
9431 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9432 0x32cc <main+212>: ldil 0x3000,r31
9433 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9434 0x32d4 <main+220>: ldo 0(r31),rp
9435 0x32d8 <main+224>: addil -0x800,dp
9436 0x32dc <main+228>: ldo 0x588(r1),r26
9437 0x32e0 <main+232>: ldil 0x3000,r31
9438 End of assembler dump.
9439 @end smallexample
9440
9441 Here is an example showing mixed source+assembly for Intel x86
9442 with @code{/m} or @code{/s}, when the program is stopped just after
9443 function prologue in a non-optimized function with no inline code.
9444
9445 @smallexample
9446 (@value{GDBP}) disas /m main
9447 Dump of assembler code for function main:
9448 5 @{
9449 0x08048330 <+0>: push %ebp
9450 0x08048331 <+1>: mov %esp,%ebp
9451 0x08048333 <+3>: sub $0x8,%esp
9452 0x08048336 <+6>: and $0xfffffff0,%esp
9453 0x08048339 <+9>: sub $0x10,%esp
9454
9455 6 printf ("Hello.\n");
9456 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9457 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9458
9459 7 return 0;
9460 8 @}
9461 0x08048348 <+24>: mov $0x0,%eax
9462 0x0804834d <+29>: leave
9463 0x0804834e <+30>: ret
9464
9465 End of assembler dump.
9466 @end smallexample
9467
9468 The @code{/m} option is deprecated as its output is not useful when
9469 there is either inlined code or re-ordered code.
9470 The @code{/s} option is the preferred choice.
9471 Here is an example for AMD x86-64 showing the difference between
9472 @code{/m} output and @code{/s} output.
9473 This example has one inline function defined in a header file,
9474 and the code is compiled with @samp{-O2} optimization.
9475 Note how the @code{/m} output is missing the disassembly of
9476 several instructions that are present in the @code{/s} output.
9477
9478 @file{foo.h}:
9479
9480 @smallexample
9481 int
9482 foo (int a)
9483 @{
9484 if (a < 0)
9485 return a * 2;
9486 if (a == 0)
9487 return 1;
9488 return a + 10;
9489 @}
9490 @end smallexample
9491
9492 @file{foo.c}:
9493
9494 @smallexample
9495 #include "foo.h"
9496 volatile int x, y;
9497 int
9498 main ()
9499 @{
9500 x = foo (y);
9501 return 0;
9502 @}
9503 @end smallexample
9504
9505 @smallexample
9506 (@value{GDBP}) disas /m main
9507 Dump of assembler code for function main:
9508 5 @{
9509
9510 6 x = foo (y);
9511 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9512 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9513
9514 7 return 0;
9515 8 @}
9516 0x000000000040041d <+29>: xor %eax,%eax
9517 0x000000000040041f <+31>: retq
9518 0x0000000000400420 <+32>: add %eax,%eax
9519 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9520
9521 End of assembler dump.
9522 (@value{GDBP}) disas /s main
9523 Dump of assembler code for function main:
9524 foo.c:
9525 5 @{
9526 6 x = foo (y);
9527 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9528
9529 foo.h:
9530 4 if (a < 0)
9531 0x0000000000400406 <+6>: test %eax,%eax
9532 0x0000000000400408 <+8>: js 0x400420 <main+32>
9533
9534 6 if (a == 0)
9535 7 return 1;
9536 8 return a + 10;
9537 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9538 0x000000000040040d <+13>: test %eax,%eax
9539 0x000000000040040f <+15>: mov $0x1,%eax
9540 0x0000000000400414 <+20>: cmovne %edx,%eax
9541
9542 foo.c:
9543 6 x = foo (y);
9544 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9545
9546 7 return 0;
9547 8 @}
9548 0x000000000040041d <+29>: xor %eax,%eax
9549 0x000000000040041f <+31>: retq
9550
9551 foo.h:
9552 5 return a * 2;
9553 0x0000000000400420 <+32>: add %eax,%eax
9554 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9555 End of assembler dump.
9556 @end smallexample
9557
9558 Here is another example showing raw instructions in hex for AMD x86-64,
9559
9560 @smallexample
9561 (gdb) disas /r 0x400281,+10
9562 Dump of assembler code from 0x400281 to 0x40028b:
9563 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9564 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9565 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9566 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9567 End of assembler dump.
9568 @end smallexample
9569
9570 Addresses cannot be specified as a location (@pxref{Specify Location}).
9571 So, for example, if you want to disassemble function @code{bar}
9572 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9573 and not @samp{disassemble foo.c:bar}.
9574
9575 Some architectures have more than one commonly-used set of instruction
9576 mnemonics or other syntax.
9577
9578 For programs that were dynamically linked and use shared libraries,
9579 instructions that call functions or branch to locations in the shared
9580 libraries might show a seemingly bogus location---it's actually a
9581 location of the relocation table. On some architectures, @value{GDBN}
9582 might be able to resolve these to actual function names.
9583
9584 @table @code
9585 @kindex set disassembler-options
9586 @cindex disassembler options
9587 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9588 This command controls the passing of target specific information to
9589 the disassembler. For a list of valid options, please refer to the
9590 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9591 manual and/or the output of @kbd{objdump --help}
9592 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9593 The default value is the empty string.
9594
9595 If it is necessary to specify more than one disassembler option, then
9596 multiple options can be placed together into a comma separated list.
9597 Currently this command is only supported on targets ARM, MIPS, PowerPC
9598 and S/390.
9599
9600 @kindex show disassembler-options
9601 @item show disassembler-options
9602 Show the current setting of the disassembler options.
9603 @end table
9604
9605 @table @code
9606 @kindex set disassembly-flavor
9607 @cindex Intel disassembly flavor
9608 @cindex AT&T disassembly flavor
9609 @item set disassembly-flavor @var{instruction-set}
9610 Select the instruction set to use when disassembling the
9611 program via the @code{disassemble} or @code{x/i} commands.
9612
9613 Currently this command is only defined for the Intel x86 family. You
9614 can set @var{instruction-set} to either @code{intel} or @code{att}.
9615 The default is @code{att}, the AT&T flavor used by default by Unix
9616 assemblers for x86-based targets.
9617
9618 @kindex show disassembly-flavor
9619 @item show disassembly-flavor
9620 Show the current setting of the disassembly flavor.
9621 @end table
9622
9623 @table @code
9624 @kindex set disassemble-next-line
9625 @kindex show disassemble-next-line
9626 @item set disassemble-next-line
9627 @itemx show disassemble-next-line
9628 Control whether or not @value{GDBN} will disassemble the next source
9629 line or instruction when execution stops. If ON, @value{GDBN} will
9630 display disassembly of the next source line when execution of the
9631 program being debugged stops. This is @emph{in addition} to
9632 displaying the source line itself, which @value{GDBN} always does if
9633 possible. If the next source line cannot be displayed for some reason
9634 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9635 info in the debug info), @value{GDBN} will display disassembly of the
9636 next @emph{instruction} instead of showing the next source line. If
9637 AUTO, @value{GDBN} will display disassembly of next instruction only
9638 if the source line cannot be displayed. This setting causes
9639 @value{GDBN} to display some feedback when you step through a function
9640 with no line info or whose source file is unavailable. The default is
9641 OFF, which means never display the disassembly of the next line or
9642 instruction.
9643 @end table
9644
9645
9646 @node Data
9647 @chapter Examining Data
9648
9649 @cindex printing data
9650 @cindex examining data
9651 @kindex print
9652 @kindex inspect
9653 The usual way to examine data in your program is with the @code{print}
9654 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9655 evaluates and prints the value of an expression of the language your
9656 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9657 Different Languages}). It may also print the expression using a
9658 Python-based pretty-printer (@pxref{Pretty Printing}).
9659
9660 @table @code
9661 @item print [[@var{options}] --] @var{expr}
9662 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9663 @var{expr} is an expression (in the source language). By default the
9664 value of @var{expr} is printed in a format appropriate to its data type;
9665 you can choose a different format by specifying @samp{/@var{f}}, where
9666 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9667 Formats}.
9668
9669 @anchor{print options}
9670 The @code{print} command supports a number of options that allow
9671 overriding relevant global print settings as set by @code{set print}
9672 subcommands:
9673
9674 @table @code
9675 @item -address [@code{on}|@code{off}]
9676 Set printing of addresses.
9677 Related setting: @ref{set print address}.
9678
9679 @item -array [@code{on}|@code{off}]
9680 Pretty formatting of arrays.
9681 Related setting: @ref{set print array}.
9682
9683 @item -array-indexes [@code{on}|@code{off}]
9684 Set printing of array indexes.
9685 Related setting: @ref{set print array-indexes}.
9686
9687 @item -elements @var{number-of-elements}|@code{unlimited}
9688 Set limit on string chars or array elements to print. The value
9689 @code{unlimited} causes there to be no limit. Related setting:
9690 @ref{set print elements}.
9691
9692 @item -max-depth @var{depth}|@code{unlimited}
9693 Set the threshold after which nested structures are replaced with
9694 ellipsis. Related setting: @ref{set print max-depth}.
9695
9696 @item -null-stop [@code{on}|@code{off}]
9697 Set printing of char arrays to stop at first null char. Related
9698 setting: @ref{set print null-stop}.
9699
9700 @item -object [@code{on}|@code{off}]
9701 Set printing C@t{++} virtual function tables. Related setting:
9702 @ref{set print object}.
9703
9704 @item -pretty [@code{on}|@code{off}]
9705 Set pretty formatting of structures. Related setting: @ref{set print
9706 pretty}.
9707
9708 @item -raw-values [@code{on}|@code{off}]
9709 Set whether to print values in raw form, bypassing any
9710 pretty-printers for that value. Related setting: @ref{set print
9711 raw-values}.
9712
9713 @item -repeats @var{number-of-repeats}|@code{unlimited}
9714 Set threshold for repeated print elements. @code{unlimited} causes
9715 all elements to be individually printed. Related setting: @ref{set
9716 print repeats}.
9717
9718 @item -static-members [@code{on}|@code{off}]
9719 Set printing C@t{++} static members. Related setting: @ref{set print
9720 static-members}.
9721
9722 @item -symbol [@code{on}|@code{off}]
9723 Set printing of symbol names when printing pointers. Related setting:
9724 @ref{set print symbol}.
9725
9726 @item -union [@code{on}|@code{off}]
9727 Set printing of unions interior to structures. Related setting:
9728 @ref{set print union}.
9729
9730 @item -vtbl [@code{on}|@code{off}]
9731 Set printing of C++ virtual function tables. Related setting:
9732 @ref{set print vtbl}.
9733 @end table
9734
9735 Because the @code{print} command accepts arbitrary expressions which
9736 may look like options (including abbreviations), if you specify any
9737 command option, then you must use a double dash (@code{--}) to mark
9738 the end of option processing.
9739
9740 For example, this prints the value of the @code{-p} expression:
9741
9742 @smallexample
9743 (@value{GDBP}) print -p
9744 @end smallexample
9745
9746 While this repeats the last value in the value history (see below)
9747 with the @code{-pretty} option in effect:
9748
9749 @smallexample
9750 (@value{GDBP}) print -p --
9751 @end smallexample
9752
9753 Here is an example including both on option and an expression:
9754
9755 @smallexample
9756 @group
9757 (@value{GDBP}) print -pretty -- *myptr
9758 $1 = @{
9759 next = 0x0,
9760 flags = @{
9761 sweet = 1,
9762 sour = 1
9763 @},
9764 meat = 0x54 "Pork"
9765 @}
9766 @end group
9767 @end smallexample
9768
9769 @item print [@var{options}]
9770 @itemx print [@var{options}] /@var{f}
9771 @cindex reprint the last value
9772 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
9773 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
9774 conveniently inspect the same value in an alternative format.
9775 @end table
9776
9777 A more low-level way of examining data is with the @code{x} command.
9778 It examines data in memory at a specified address and prints it in a
9779 specified format. @xref{Memory, ,Examining Memory}.
9780
9781 If you are interested in information about types, or about how the
9782 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9783 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
9784 Table}.
9785
9786 @cindex exploring hierarchical data structures
9787 @kindex explore
9788 Another way of examining values of expressions and type information is
9789 through the Python extension command @code{explore} (available only if
9790 the @value{GDBN} build is configured with @code{--with-python}). It
9791 offers an interactive way to start at the highest level (or, the most
9792 abstract level) of the data type of an expression (or, the data type
9793 itself) and explore all the way down to leaf scalar values/fields
9794 embedded in the higher level data types.
9795
9796 @table @code
9797 @item explore @var{arg}
9798 @var{arg} is either an expression (in the source language), or a type
9799 visible in the current context of the program being debugged.
9800 @end table
9801
9802 The working of the @code{explore} command can be illustrated with an
9803 example. If a data type @code{struct ComplexStruct} is defined in your
9804 C program as
9805
9806 @smallexample
9807 struct SimpleStruct
9808 @{
9809 int i;
9810 double d;
9811 @};
9812
9813 struct ComplexStruct
9814 @{
9815 struct SimpleStruct *ss_p;
9816 int arr[10];
9817 @};
9818 @end smallexample
9819
9820 @noindent
9821 followed by variable declarations as
9822
9823 @smallexample
9824 struct SimpleStruct ss = @{ 10, 1.11 @};
9825 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9826 @end smallexample
9827
9828 @noindent
9829 then, the value of the variable @code{cs} can be explored using the
9830 @code{explore} command as follows.
9831
9832 @smallexample
9833 (gdb) explore cs
9834 The value of `cs' is a struct/class of type `struct ComplexStruct' with
9835 the following fields:
9836
9837 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9838 arr = <Enter 1 to explore this field of type `int [10]'>
9839
9840 Enter the field number of choice:
9841 @end smallexample
9842
9843 @noindent
9844 Since the fields of @code{cs} are not scalar values, you are being
9845 prompted to chose the field you want to explore. Let's say you choose
9846 the field @code{ss_p} by entering @code{0}. Then, since this field is a
9847 pointer, you will be asked if it is pointing to a single value. From
9848 the declaration of @code{cs} above, it is indeed pointing to a single
9849 value, hence you enter @code{y}. If you enter @code{n}, then you will
9850 be asked if it were pointing to an array of values, in which case this
9851 field will be explored as if it were an array.
9852
9853 @smallexample
9854 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9855 Continue exploring it as a pointer to a single value [y/n]: y
9856 The value of `*(cs.ss_p)' is a struct/class of type `struct
9857 SimpleStruct' with the following fields:
9858
9859 i = 10 .. (Value of type `int')
9860 d = 1.1100000000000001 .. (Value of type `double')
9861
9862 Press enter to return to parent value:
9863 @end smallexample
9864
9865 @noindent
9866 If the field @code{arr} of @code{cs} was chosen for exploration by
9867 entering @code{1} earlier, then since it is as array, you will be
9868 prompted to enter the index of the element in the array that you want
9869 to explore.
9870
9871 @smallexample
9872 `cs.arr' is an array of `int'.
9873 Enter the index of the element you want to explore in `cs.arr': 5
9874
9875 `(cs.arr)[5]' is a scalar value of type `int'.
9876
9877 (cs.arr)[5] = 4
9878
9879 Press enter to return to parent value:
9880 @end smallexample
9881
9882 In general, at any stage of exploration, you can go deeper towards the
9883 leaf values by responding to the prompts appropriately, or hit the
9884 return key to return to the enclosing data structure (the @i{higher}
9885 level data structure).
9886
9887 Similar to exploring values, you can use the @code{explore} command to
9888 explore types. Instead of specifying a value (which is typically a
9889 variable name or an expression valid in the current context of the
9890 program being debugged), you specify a type name. If you consider the
9891 same example as above, your can explore the type
9892 @code{struct ComplexStruct} by passing the argument
9893 @code{struct ComplexStruct} to the @code{explore} command.
9894
9895 @smallexample
9896 (gdb) explore struct ComplexStruct
9897 @end smallexample
9898
9899 @noindent
9900 By responding to the prompts appropriately in the subsequent interactive
9901 session, you can explore the type @code{struct ComplexStruct} in a
9902 manner similar to how the value @code{cs} was explored in the above
9903 example.
9904
9905 The @code{explore} command also has two sub-commands,
9906 @code{explore value} and @code{explore type}. The former sub-command is
9907 a way to explicitly specify that value exploration of the argument is
9908 being invoked, while the latter is a way to explicitly specify that type
9909 exploration of the argument is being invoked.
9910
9911 @table @code
9912 @item explore value @var{expr}
9913 @cindex explore value
9914 This sub-command of @code{explore} explores the value of the
9915 expression @var{expr} (if @var{expr} is an expression valid in the
9916 current context of the program being debugged). The behavior of this
9917 command is identical to that of the behavior of the @code{explore}
9918 command being passed the argument @var{expr}.
9919
9920 @item explore type @var{arg}
9921 @cindex explore type
9922 This sub-command of @code{explore} explores the type of @var{arg} (if
9923 @var{arg} is a type visible in the current context of program being
9924 debugged), or the type of the value/expression @var{arg} (if @var{arg}
9925 is an expression valid in the current context of the program being
9926 debugged). If @var{arg} is a type, then the behavior of this command is
9927 identical to that of the @code{explore} command being passed the
9928 argument @var{arg}. If @var{arg} is an expression, then the behavior of
9929 this command will be identical to that of the @code{explore} command
9930 being passed the type of @var{arg} as the argument.
9931 @end table
9932
9933 @menu
9934 * Expressions:: Expressions
9935 * Ambiguous Expressions:: Ambiguous Expressions
9936 * Variables:: Program variables
9937 * Arrays:: Artificial arrays
9938 * Output Formats:: Output formats
9939 * Memory:: Examining memory
9940 * Auto Display:: Automatic display
9941 * Print Settings:: Print settings
9942 * Pretty Printing:: Python pretty printing
9943 * Value History:: Value history
9944 * Convenience Vars:: Convenience variables
9945 * Convenience Funs:: Convenience functions
9946 * Registers:: Registers
9947 * Floating Point Hardware:: Floating point hardware
9948 * Vector Unit:: Vector Unit
9949 * OS Information:: Auxiliary data provided by operating system
9950 * Memory Region Attributes:: Memory region attributes
9951 * Dump/Restore Files:: Copy between memory and a file
9952 * Core File Generation:: Cause a program dump its core
9953 * Character Sets:: Debugging programs that use a different
9954 character set than GDB does
9955 * Caching Target Data:: Data caching for targets
9956 * Searching Memory:: Searching memory for a sequence of bytes
9957 * Value Sizes:: Managing memory allocated for values
9958 @end menu
9959
9960 @node Expressions
9961 @section Expressions
9962
9963 @cindex expressions
9964 @code{print} and many other @value{GDBN} commands accept an expression and
9965 compute its value. Any kind of constant, variable or operator defined
9966 by the programming language you are using is valid in an expression in
9967 @value{GDBN}. This includes conditional expressions, function calls,
9968 casts, and string constants. It also includes preprocessor macros, if
9969 you compiled your program to include this information; see
9970 @ref{Compilation}.
9971
9972 @cindex arrays in expressions
9973 @value{GDBN} supports array constants in expressions input by
9974 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
9975 you can use the command @code{print @{1, 2, 3@}} to create an array
9976 of three integers. If you pass an array to a function or assign it
9977 to a program variable, @value{GDBN} copies the array to memory that
9978 is @code{malloc}ed in the target program.
9979
9980 Because C is so widespread, most of the expressions shown in examples in
9981 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
9982 Languages}, for information on how to use expressions in other
9983 languages.
9984
9985 In this section, we discuss operators that you can use in @value{GDBN}
9986 expressions regardless of your programming language.
9987
9988 @cindex casts, in expressions
9989 Casts are supported in all languages, not just in C, because it is so
9990 useful to cast a number into a pointer in order to examine a structure
9991 at that address in memory.
9992 @c FIXME: casts supported---Mod2 true?
9993
9994 @value{GDBN} supports these operators, in addition to those common
9995 to programming languages:
9996
9997 @table @code
9998 @item @@
9999 @samp{@@} is a binary operator for treating parts of memory as arrays.
10000 @xref{Arrays, ,Artificial Arrays}, for more information.
10001
10002 @item ::
10003 @samp{::} allows you to specify a variable in terms of the file or
10004 function where it is defined. @xref{Variables, ,Program Variables}.
10005
10006 @cindex @{@var{type}@}
10007 @cindex type casting memory
10008 @cindex memory, viewing as typed object
10009 @cindex casts, to view memory
10010 @item @{@var{type}@} @var{addr}
10011 Refers to an object of type @var{type} stored at address @var{addr} in
10012 memory. The address @var{addr} may be any expression whose value is
10013 an integer or pointer (but parentheses are required around binary
10014 operators, just as in a cast). This construct is allowed regardless
10015 of what kind of data is normally supposed to reside at @var{addr}.
10016 @end table
10017
10018 @node Ambiguous Expressions
10019 @section Ambiguous Expressions
10020 @cindex ambiguous expressions
10021
10022 Expressions can sometimes contain some ambiguous elements. For instance,
10023 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10024 a single function name to be defined several times, for application in
10025 different contexts. This is called @dfn{overloading}. Another example
10026 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10027 templates and is typically instantiated several times, resulting in
10028 the same function name being defined in different contexts.
10029
10030 In some cases and depending on the language, it is possible to adjust
10031 the expression to remove the ambiguity. For instance in C@t{++}, you
10032 can specify the signature of the function you want to break on, as in
10033 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10034 qualified name of your function often makes the expression unambiguous
10035 as well.
10036
10037 When an ambiguity that needs to be resolved is detected, the debugger
10038 has the capability to display a menu of numbered choices for each
10039 possibility, and then waits for the selection with the prompt @samp{>}.
10040 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10041 aborts the current command. If the command in which the expression was
10042 used allows more than one choice to be selected, the next option in the
10043 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10044 choices.
10045
10046 For example, the following session excerpt shows an attempt to set a
10047 breakpoint at the overloaded symbol @code{String::after}.
10048 We choose three particular definitions of that function name:
10049
10050 @c FIXME! This is likely to change to show arg type lists, at least
10051 @smallexample
10052 @group
10053 (@value{GDBP}) b String::after
10054 [0] cancel
10055 [1] all
10056 [2] file:String.cc; line number:867
10057 [3] file:String.cc; line number:860
10058 [4] file:String.cc; line number:875
10059 [5] file:String.cc; line number:853
10060 [6] file:String.cc; line number:846
10061 [7] file:String.cc; line number:735
10062 > 2 4 6
10063 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10064 Breakpoint 2 at 0xb344: file String.cc, line 875.
10065 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10066 Multiple breakpoints were set.
10067 Use the "delete" command to delete unwanted
10068 breakpoints.
10069 (@value{GDBP})
10070 @end group
10071 @end smallexample
10072
10073 @table @code
10074 @kindex set multiple-symbols
10075 @item set multiple-symbols @var{mode}
10076 @cindex multiple-symbols menu
10077
10078 This option allows you to adjust the debugger behavior when an expression
10079 is ambiguous.
10080
10081 By default, @var{mode} is set to @code{all}. If the command with which
10082 the expression is used allows more than one choice, then @value{GDBN}
10083 automatically selects all possible choices. For instance, inserting
10084 a breakpoint on a function using an ambiguous name results in a breakpoint
10085 inserted on each possible match. However, if a unique choice must be made,
10086 then @value{GDBN} uses the menu to help you disambiguate the expression.
10087 For instance, printing the address of an overloaded function will result
10088 in the use of the menu.
10089
10090 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10091 when an ambiguity is detected.
10092
10093 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10094 an error due to the ambiguity and the command is aborted.
10095
10096 @kindex show multiple-symbols
10097 @item show multiple-symbols
10098 Show the current value of the @code{multiple-symbols} setting.
10099 @end table
10100
10101 @node Variables
10102 @section Program Variables
10103
10104 The most common kind of expression to use is the name of a variable
10105 in your program.
10106
10107 Variables in expressions are understood in the selected stack frame
10108 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10109
10110 @itemize @bullet
10111 @item
10112 global (or file-static)
10113 @end itemize
10114
10115 @noindent or
10116
10117 @itemize @bullet
10118 @item
10119 visible according to the scope rules of the
10120 programming language from the point of execution in that frame
10121 @end itemize
10122
10123 @noindent This means that in the function
10124
10125 @smallexample
10126 foo (a)
10127 int a;
10128 @{
10129 bar (a);
10130 @{
10131 int b = test ();
10132 bar (b);
10133 @}
10134 @}
10135 @end smallexample
10136
10137 @noindent
10138 you can examine and use the variable @code{a} whenever your program is
10139 executing within the function @code{foo}, but you can only use or
10140 examine the variable @code{b} while your program is executing inside
10141 the block where @code{b} is declared.
10142
10143 @cindex variable name conflict
10144 There is an exception: you can refer to a variable or function whose
10145 scope is a single source file even if the current execution point is not
10146 in this file. But it is possible to have more than one such variable or
10147 function with the same name (in different source files). If that
10148 happens, referring to that name has unpredictable effects. If you wish,
10149 you can specify a static variable in a particular function or file by
10150 using the colon-colon (@code{::}) notation:
10151
10152 @cindex colon-colon, context for variables/functions
10153 @ifnotinfo
10154 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10155 @cindex @code{::}, context for variables/functions
10156 @end ifnotinfo
10157 @smallexample
10158 @var{file}::@var{variable}
10159 @var{function}::@var{variable}
10160 @end smallexample
10161
10162 @noindent
10163 Here @var{file} or @var{function} is the name of the context for the
10164 static @var{variable}. In the case of file names, you can use quotes to
10165 make sure @value{GDBN} parses the file name as a single word---for example,
10166 to print a global value of @code{x} defined in @file{f2.c}:
10167
10168 @smallexample
10169 (@value{GDBP}) p 'f2.c'::x
10170 @end smallexample
10171
10172 The @code{::} notation is normally used for referring to
10173 static variables, since you typically disambiguate uses of local variables
10174 in functions by selecting the appropriate frame and using the
10175 simple name of the variable. However, you may also use this notation
10176 to refer to local variables in frames enclosing the selected frame:
10177
10178 @smallexample
10179 void
10180 foo (int a)
10181 @{
10182 if (a < 10)
10183 bar (a);
10184 else
10185 process (a); /* Stop here */
10186 @}
10187
10188 int
10189 bar (int a)
10190 @{
10191 foo (a + 5);
10192 @}
10193 @end smallexample
10194
10195 @noindent
10196 For example, if there is a breakpoint at the commented line,
10197 here is what you might see
10198 when the program stops after executing the call @code{bar(0)}:
10199
10200 @smallexample
10201 (@value{GDBP}) p a
10202 $1 = 10
10203 (@value{GDBP}) p bar::a
10204 $2 = 5
10205 (@value{GDBP}) up 2
10206 #2 0x080483d0 in foo (a=5) at foobar.c:12
10207 (@value{GDBP}) p a
10208 $3 = 5
10209 (@value{GDBP}) p bar::a
10210 $4 = 0
10211 @end smallexample
10212
10213 @cindex C@t{++} scope resolution
10214 These uses of @samp{::} are very rarely in conflict with the very
10215 similar use of the same notation in C@t{++}. When they are in
10216 conflict, the C@t{++} meaning takes precedence; however, this can be
10217 overridden by quoting the file or function name with single quotes.
10218
10219 For example, suppose the program is stopped in a method of a class
10220 that has a field named @code{includefile}, and there is also an
10221 include file named @file{includefile} that defines a variable,
10222 @code{some_global}.
10223
10224 @smallexample
10225 (@value{GDBP}) p includefile
10226 $1 = 23
10227 (@value{GDBP}) p includefile::some_global
10228 A syntax error in expression, near `'.
10229 (@value{GDBP}) p 'includefile'::some_global
10230 $2 = 27
10231 @end smallexample
10232
10233 @cindex wrong values
10234 @cindex variable values, wrong
10235 @cindex function entry/exit, wrong values of variables
10236 @cindex optimized code, wrong values of variables
10237 @quotation
10238 @emph{Warning:} Occasionally, a local variable may appear to have the
10239 wrong value at certain points in a function---just after entry to a new
10240 scope, and just before exit.
10241 @end quotation
10242 You may see this problem when you are stepping by machine instructions.
10243 This is because, on most machines, it takes more than one instruction to
10244 set up a stack frame (including local variable definitions); if you are
10245 stepping by machine instructions, variables may appear to have the wrong
10246 values until the stack frame is completely built. On exit, it usually
10247 also takes more than one machine instruction to destroy a stack frame;
10248 after you begin stepping through that group of instructions, local
10249 variable definitions may be gone.
10250
10251 This may also happen when the compiler does significant optimizations.
10252 To be sure of always seeing accurate values, turn off all optimization
10253 when compiling.
10254
10255 @cindex ``No symbol "foo" in current context''
10256 Another possible effect of compiler optimizations is to optimize
10257 unused variables out of existence, or assign variables to registers (as
10258 opposed to memory addresses). Depending on the support for such cases
10259 offered by the debug info format used by the compiler, @value{GDBN}
10260 might not be able to display values for such local variables. If that
10261 happens, @value{GDBN} will print a message like this:
10262
10263 @smallexample
10264 No symbol "foo" in current context.
10265 @end smallexample
10266
10267 To solve such problems, either recompile without optimizations, or use a
10268 different debug info format, if the compiler supports several such
10269 formats. @xref{Compilation}, for more information on choosing compiler
10270 options. @xref{C, ,C and C@t{++}}, for more information about debug
10271 info formats that are best suited to C@t{++} programs.
10272
10273 If you ask to print an object whose contents are unknown to
10274 @value{GDBN}, e.g., because its data type is not completely specified
10275 by the debug information, @value{GDBN} will say @samp{<incomplete
10276 type>}. @xref{Symbols, incomplete type}, for more about this.
10277
10278 @cindex no debug info variables
10279 If you try to examine or use the value of a (global) variable for
10280 which @value{GDBN} has no type information, e.g., because the program
10281 includes no debug information, @value{GDBN} displays an error message.
10282 @xref{Symbols, unknown type}, for more about unknown types. If you
10283 cast the variable to its declared type, @value{GDBN} gets the
10284 variable's value using the cast-to type as the variable's type. For
10285 example, in a C program:
10286
10287 @smallexample
10288 (@value{GDBP}) p var
10289 'var' has unknown type; cast it to its declared type
10290 (@value{GDBP}) p (float) var
10291 $1 = 3.14
10292 @end smallexample
10293
10294 If you append @kbd{@@entry} string to a function parameter name you get its
10295 value at the time the function got called. If the value is not available an
10296 error message is printed. Entry values are available only with some compilers.
10297 Entry values are normally also printed at the function parameter list according
10298 to @ref{set print entry-values}.
10299
10300 @smallexample
10301 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10302 29 i++;
10303 (gdb) next
10304 30 e (i);
10305 (gdb) print i
10306 $1 = 31
10307 (gdb) print i@@entry
10308 $2 = 30
10309 @end smallexample
10310
10311 Strings are identified as arrays of @code{char} values without specified
10312 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10313 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10314 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10315 defines literal string type @code{"char"} as @code{char} without a sign.
10316 For program code
10317
10318 @smallexample
10319 char var0[] = "A";
10320 signed char var1[] = "A";
10321 @end smallexample
10322
10323 You get during debugging
10324 @smallexample
10325 (gdb) print var0
10326 $1 = "A"
10327 (gdb) print var1
10328 $2 = @{65 'A', 0 '\0'@}
10329 @end smallexample
10330
10331 @node Arrays
10332 @section Artificial Arrays
10333
10334 @cindex artificial array
10335 @cindex arrays
10336 @kindex @@@r{, referencing memory as an array}
10337 It is often useful to print out several successive objects of the
10338 same type in memory; a section of an array, or an array of
10339 dynamically determined size for which only a pointer exists in the
10340 program.
10341
10342 You can do this by referring to a contiguous span of memory as an
10343 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10344 operand of @samp{@@} should be the first element of the desired array
10345 and be an individual object. The right operand should be the desired length
10346 of the array. The result is an array value whose elements are all of
10347 the type of the left argument. The first element is actually the left
10348 argument; the second element comes from bytes of memory immediately
10349 following those that hold the first element, and so on. Here is an
10350 example. If a program says
10351
10352 @smallexample
10353 int *array = (int *) malloc (len * sizeof (int));
10354 @end smallexample
10355
10356 @noindent
10357 you can print the contents of @code{array} with
10358
10359 @smallexample
10360 p *array@@len
10361 @end smallexample
10362
10363 The left operand of @samp{@@} must reside in memory. Array values made
10364 with @samp{@@} in this way behave just like other arrays in terms of
10365 subscripting, and are coerced to pointers when used in expressions.
10366 Artificial arrays most often appear in expressions via the value history
10367 (@pxref{Value History, ,Value History}), after printing one out.
10368
10369 Another way to create an artificial array is to use a cast.
10370 This re-interprets a value as if it were an array.
10371 The value need not be in memory:
10372 @smallexample
10373 (@value{GDBP}) p/x (short[2])0x12345678
10374 $1 = @{0x1234, 0x5678@}
10375 @end smallexample
10376
10377 As a convenience, if you leave the array length out (as in
10378 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10379 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10380 @smallexample
10381 (@value{GDBP}) p/x (short[])0x12345678
10382 $2 = @{0x1234, 0x5678@}
10383 @end smallexample
10384
10385 Sometimes the artificial array mechanism is not quite enough; in
10386 moderately complex data structures, the elements of interest may not
10387 actually be adjacent---for example, if you are interested in the values
10388 of pointers in an array. One useful work-around in this situation is
10389 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10390 Variables}) as a counter in an expression that prints the first
10391 interesting value, and then repeat that expression via @key{RET}. For
10392 instance, suppose you have an array @code{dtab} of pointers to
10393 structures, and you are interested in the values of a field @code{fv}
10394 in each structure. Here is an example of what you might type:
10395
10396 @smallexample
10397 set $i = 0
10398 p dtab[$i++]->fv
10399 @key{RET}
10400 @key{RET}
10401 @dots{}
10402 @end smallexample
10403
10404 @node Output Formats
10405 @section Output Formats
10406
10407 @cindex formatted output
10408 @cindex output formats
10409 By default, @value{GDBN} prints a value according to its data type. Sometimes
10410 this is not what you want. For example, you might want to print a number
10411 in hex, or a pointer in decimal. Or you might want to view data in memory
10412 at a certain address as a character string or as an instruction. To do
10413 these things, specify an @dfn{output format} when you print a value.
10414
10415 The simplest use of output formats is to say how to print a value
10416 already computed. This is done by starting the arguments of the
10417 @code{print} command with a slash and a format letter. The format
10418 letters supported are:
10419
10420 @table @code
10421 @item x
10422 Regard the bits of the value as an integer, and print the integer in
10423 hexadecimal.
10424
10425 @item d
10426 Print as integer in signed decimal.
10427
10428 @item u
10429 Print as integer in unsigned decimal.
10430
10431 @item o
10432 Print as integer in octal.
10433
10434 @item t
10435 Print as integer in binary. The letter @samp{t} stands for ``two''.
10436 @footnote{@samp{b} cannot be used because these format letters are also
10437 used with the @code{x} command, where @samp{b} stands for ``byte'';
10438 see @ref{Memory,,Examining Memory}.}
10439
10440 @item a
10441 @cindex unknown address, locating
10442 @cindex locate address
10443 Print as an address, both absolute in hexadecimal and as an offset from
10444 the nearest preceding symbol. You can use this format used to discover
10445 where (in what function) an unknown address is located:
10446
10447 @smallexample
10448 (@value{GDBP}) p/a 0x54320
10449 $3 = 0x54320 <_initialize_vx+396>
10450 @end smallexample
10451
10452 @noindent
10453 The command @code{info symbol 0x54320} yields similar results.
10454 @xref{Symbols, info symbol}.
10455
10456 @item c
10457 Regard as an integer and print it as a character constant. This
10458 prints both the numerical value and its character representation. The
10459 character representation is replaced with the octal escape @samp{\nnn}
10460 for characters outside the 7-bit @sc{ascii} range.
10461
10462 Without this format, @value{GDBN} displays @code{char},
10463 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10464 constants. Single-byte members of vectors are displayed as integer
10465 data.
10466
10467 @item f
10468 Regard the bits of the value as a floating point number and print
10469 using typical floating point syntax.
10470
10471 @item s
10472 @cindex printing strings
10473 @cindex printing byte arrays
10474 Regard as a string, if possible. With this format, pointers to single-byte
10475 data are displayed as null-terminated strings and arrays of single-byte data
10476 are displayed as fixed-length strings. Other values are displayed in their
10477 natural types.
10478
10479 Without this format, @value{GDBN} displays pointers to and arrays of
10480 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10481 strings. Single-byte members of a vector are displayed as an integer
10482 array.
10483
10484 @item z
10485 Like @samp{x} formatting, the value is treated as an integer and
10486 printed as hexadecimal, but leading zeros are printed to pad the value
10487 to the size of the integer type.
10488
10489 @item r
10490 @cindex raw printing
10491 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10492 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10493 Printing}). This typically results in a higher-level display of the
10494 value's contents. The @samp{r} format bypasses any Python
10495 pretty-printer which might exist.
10496 @end table
10497
10498 For example, to print the program counter in hex (@pxref{Registers}), type
10499
10500 @smallexample
10501 p/x $pc
10502 @end smallexample
10503
10504 @noindent
10505 Note that no space is required before the slash; this is because command
10506 names in @value{GDBN} cannot contain a slash.
10507
10508 To reprint the last value in the value history with a different format,
10509 you can use the @code{print} command with just a format and no
10510 expression. For example, @samp{p/x} reprints the last value in hex.
10511
10512 @node Memory
10513 @section Examining Memory
10514
10515 You can use the command @code{x} (for ``examine'') to examine memory in
10516 any of several formats, independently of your program's data types.
10517
10518 @cindex examining memory
10519 @table @code
10520 @kindex x @r{(examine memory)}
10521 @item x/@var{nfu} @var{addr}
10522 @itemx x @var{addr}
10523 @itemx x
10524 Use the @code{x} command to examine memory.
10525 @end table
10526
10527 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10528 much memory to display and how to format it; @var{addr} is an
10529 expression giving the address where you want to start displaying memory.
10530 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10531 Several commands set convenient defaults for @var{addr}.
10532
10533 @table @r
10534 @item @var{n}, the repeat count
10535 The repeat count is a decimal integer; the default is 1. It specifies
10536 how much memory (counting by units @var{u}) to display. If a negative
10537 number is specified, memory is examined backward from @var{addr}.
10538 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10539 @c 4.1.2.
10540
10541 @item @var{f}, the display format
10542 The display format is one of the formats used by @code{print}
10543 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10544 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10545 The default is @samp{x} (hexadecimal) initially. The default changes
10546 each time you use either @code{x} or @code{print}.
10547
10548 @item @var{u}, the unit size
10549 The unit size is any of
10550
10551 @table @code
10552 @item b
10553 Bytes.
10554 @item h
10555 Halfwords (two bytes).
10556 @item w
10557 Words (four bytes). This is the initial default.
10558 @item g
10559 Giant words (eight bytes).
10560 @end table
10561
10562 Each time you specify a unit size with @code{x}, that size becomes the
10563 default unit the next time you use @code{x}. For the @samp{i} format,
10564 the unit size is ignored and is normally not written. For the @samp{s} format,
10565 the unit size defaults to @samp{b}, unless it is explicitly given.
10566 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10567 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10568 Note that the results depend on the programming language of the
10569 current compilation unit. If the language is C, the @samp{s}
10570 modifier will use the UTF-16 encoding while @samp{w} will use
10571 UTF-32. The encoding is set by the programming language and cannot
10572 be altered.
10573
10574 @item @var{addr}, starting display address
10575 @var{addr} is the address where you want @value{GDBN} to begin displaying
10576 memory. The expression need not have a pointer value (though it may);
10577 it is always interpreted as an integer address of a byte of memory.
10578 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10579 @var{addr} is usually just after the last address examined---but several
10580 other commands also set the default address: @code{info breakpoints} (to
10581 the address of the last breakpoint listed), @code{info line} (to the
10582 starting address of a line), and @code{print} (if you use it to display
10583 a value from memory).
10584 @end table
10585
10586 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10587 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10588 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10589 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10590 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10591
10592 You can also specify a negative repeat count to examine memory backward
10593 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10594 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10595
10596 Since the letters indicating unit sizes are all distinct from the
10597 letters specifying output formats, you do not have to remember whether
10598 unit size or format comes first; either order works. The output
10599 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10600 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10601
10602 Even though the unit size @var{u} is ignored for the formats @samp{s}
10603 and @samp{i}, you might still want to use a count @var{n}; for example,
10604 @samp{3i} specifies that you want to see three machine instructions,
10605 including any operands. For convenience, especially when used with
10606 the @code{display} command, the @samp{i} format also prints branch delay
10607 slot instructions, if any, beyond the count specified, which immediately
10608 follow the last instruction that is within the count. The command
10609 @code{disassemble} gives an alternative way of inspecting machine
10610 instructions; see @ref{Machine Code,,Source and Machine Code}.
10611
10612 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10613 the command displays null-terminated strings or instructions before the given
10614 address as many as the absolute value of the given number. For the @samp{i}
10615 format, we use line number information in the debug info to accurately locate
10616 instruction boundaries while disassembling backward. If line info is not
10617 available, the command stops examining memory with an error message.
10618
10619 All the defaults for the arguments to @code{x} are designed to make it
10620 easy to continue scanning memory with minimal specifications each time
10621 you use @code{x}. For example, after you have inspected three machine
10622 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10623 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10624 the repeat count @var{n} is used again; the other arguments default as
10625 for successive uses of @code{x}.
10626
10627 When examining machine instructions, the instruction at current program
10628 counter is shown with a @code{=>} marker. For example:
10629
10630 @smallexample
10631 (@value{GDBP}) x/5i $pc-6
10632 0x804837f <main+11>: mov %esp,%ebp
10633 0x8048381 <main+13>: push %ecx
10634 0x8048382 <main+14>: sub $0x4,%esp
10635 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10636 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10637 @end smallexample
10638
10639 @cindex @code{$_}, @code{$__}, and value history
10640 The addresses and contents printed by the @code{x} command are not saved
10641 in the value history because there is often too much of them and they
10642 would get in the way. Instead, @value{GDBN} makes these values available for
10643 subsequent use in expressions as values of the convenience variables
10644 @code{$_} and @code{$__}. After an @code{x} command, the last address
10645 examined is available for use in expressions in the convenience variable
10646 @code{$_}. The contents of that address, as examined, are available in
10647 the convenience variable @code{$__}.
10648
10649 If the @code{x} command has a repeat count, the address and contents saved
10650 are from the last memory unit printed; this is not the same as the last
10651 address printed if several units were printed on the last line of output.
10652
10653 @anchor{addressable memory unit}
10654 @cindex addressable memory unit
10655 Most targets have an addressable memory unit size of 8 bits. This means
10656 that to each memory address are associated 8 bits of data. Some
10657 targets, however, have other addressable memory unit sizes.
10658 Within @value{GDBN} and this document, the term
10659 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10660 when explicitly referring to a chunk of data of that size. The word
10661 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10662 the addressable memory unit size of the target. For most systems,
10663 addressable memory unit is a synonym of byte.
10664
10665 @cindex remote memory comparison
10666 @cindex target memory comparison
10667 @cindex verify remote memory image
10668 @cindex verify target memory image
10669 When you are debugging a program running on a remote target machine
10670 (@pxref{Remote Debugging}), you may wish to verify the program's image
10671 in the remote machine's memory against the executable file you
10672 downloaded to the target. Or, on any target, you may want to check
10673 whether the program has corrupted its own read-only sections. The
10674 @code{compare-sections} command is provided for such situations.
10675
10676 @table @code
10677 @kindex compare-sections
10678 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10679 Compare the data of a loadable section @var{section-name} in the
10680 executable file of the program being debugged with the same section in
10681 the target machine's memory, and report any mismatches. With no
10682 arguments, compares all loadable sections. With an argument of
10683 @code{-r}, compares all loadable read-only sections.
10684
10685 Note: for remote targets, this command can be accelerated if the
10686 target supports computing the CRC checksum of a block of memory
10687 (@pxref{qCRC packet}).
10688 @end table
10689
10690 @node Auto Display
10691 @section Automatic Display
10692 @cindex automatic display
10693 @cindex display of expressions
10694
10695 If you find that you want to print the value of an expression frequently
10696 (to see how it changes), you might want to add it to the @dfn{automatic
10697 display list} so that @value{GDBN} prints its value each time your program stops.
10698 Each expression added to the list is given a number to identify it;
10699 to remove an expression from the list, you specify that number.
10700 The automatic display looks like this:
10701
10702 @smallexample
10703 2: foo = 38
10704 3: bar[5] = (struct hack *) 0x3804
10705 @end smallexample
10706
10707 @noindent
10708 This display shows item numbers, expressions and their current values. As with
10709 displays you request manually using @code{x} or @code{print}, you can
10710 specify the output format you prefer; in fact, @code{display} decides
10711 whether to use @code{print} or @code{x} depending your format
10712 specification---it uses @code{x} if you specify either the @samp{i}
10713 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
10714
10715 @table @code
10716 @kindex display
10717 @item display @var{expr}
10718 Add the expression @var{expr} to the list of expressions to display
10719 each time your program stops. @xref{Expressions, ,Expressions}.
10720
10721 @code{display} does not repeat if you press @key{RET} again after using it.
10722
10723 @item display/@var{fmt} @var{expr}
10724 For @var{fmt} specifying only a display format and not a size or
10725 count, add the expression @var{expr} to the auto-display list but
10726 arrange to display it each time in the specified format @var{fmt}.
10727 @xref{Output Formats,,Output Formats}.
10728
10729 @item display/@var{fmt} @var{addr}
10730 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10731 number of units, add the expression @var{addr} as a memory address to
10732 be examined each time your program stops. Examining means in effect
10733 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
10734 @end table
10735
10736 For example, @samp{display/i $pc} can be helpful, to see the machine
10737 instruction about to be executed each time execution stops (@samp{$pc}
10738 is a common name for the program counter; @pxref{Registers, ,Registers}).
10739
10740 @table @code
10741 @kindex delete display
10742 @kindex undisplay
10743 @item undisplay @var{dnums}@dots{}
10744 @itemx delete display @var{dnums}@dots{}
10745 Remove items from the list of expressions to display. Specify the
10746 numbers of the displays that you want affected with the command
10747 argument @var{dnums}. It can be a single display number, one of the
10748 numbers shown in the first field of the @samp{info display} display;
10749 or it could be a range of display numbers, as in @code{2-4}.
10750
10751 @code{undisplay} does not repeat if you press @key{RET} after using it.
10752 (Otherwise you would just get the error @samp{No display number @dots{}}.)
10753
10754 @kindex disable display
10755 @item disable display @var{dnums}@dots{}
10756 Disable the display of item numbers @var{dnums}. A disabled display
10757 item is not printed automatically, but is not forgotten. It may be
10758 enabled again later. Specify the numbers of the displays that you
10759 want affected with the command argument @var{dnums}. It can be a
10760 single display number, one of the numbers shown in the first field of
10761 the @samp{info display} display; or it could be a range of display
10762 numbers, as in @code{2-4}.
10763
10764 @kindex enable display
10765 @item enable display @var{dnums}@dots{}
10766 Enable display of item numbers @var{dnums}. It becomes effective once
10767 again in auto display of its expression, until you specify otherwise.
10768 Specify the numbers of the displays that you want affected with the
10769 command argument @var{dnums}. It can be a single display number, one
10770 of the numbers shown in the first field of the @samp{info display}
10771 display; or it could be a range of display numbers, as in @code{2-4}.
10772
10773 @item display
10774 Display the current values of the expressions on the list, just as is
10775 done when your program stops.
10776
10777 @kindex info display
10778 @item info display
10779 Print the list of expressions previously set up to display
10780 automatically, each one with its item number, but without showing the
10781 values. This includes disabled expressions, which are marked as such.
10782 It also includes expressions which would not be displayed right now
10783 because they refer to automatic variables not currently available.
10784 @end table
10785
10786 @cindex display disabled out of scope
10787 If a display expression refers to local variables, then it does not make
10788 sense outside the lexical context for which it was set up. Such an
10789 expression is disabled when execution enters a context where one of its
10790 variables is not defined. For example, if you give the command
10791 @code{display last_char} while inside a function with an argument
10792 @code{last_char}, @value{GDBN} displays this argument while your program
10793 continues to stop inside that function. When it stops elsewhere---where
10794 there is no variable @code{last_char}---the display is disabled
10795 automatically. The next time your program stops where @code{last_char}
10796 is meaningful, you can enable the display expression once again.
10797
10798 @node Print Settings
10799 @section Print Settings
10800
10801 @cindex format options
10802 @cindex print settings
10803 @value{GDBN} provides the following ways to control how arrays, structures,
10804 and symbols are printed.
10805
10806 @noindent
10807 These settings are useful for debugging programs in any language:
10808
10809 @table @code
10810 @kindex set print
10811 @anchor{set print address}
10812 @item set print address
10813 @itemx set print address on
10814 @cindex print/don't print memory addresses
10815 @value{GDBN} prints memory addresses showing the location of stack
10816 traces, structure values, pointer values, breakpoints, and so forth,
10817 even when it also displays the contents of those addresses. The default
10818 is @code{on}. For example, this is what a stack frame display looks like with
10819 @code{set print address on}:
10820
10821 @smallexample
10822 @group
10823 (@value{GDBP}) f
10824 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10825 at input.c:530
10826 530 if (lquote != def_lquote)
10827 @end group
10828 @end smallexample
10829
10830 @item set print address off
10831 Do not print addresses when displaying their contents. For example,
10832 this is the same stack frame displayed with @code{set print address off}:
10833
10834 @smallexample
10835 @group
10836 (@value{GDBP}) set print addr off
10837 (@value{GDBP}) f
10838 #0 set_quotes (lq="<<", rq=">>") at input.c:530
10839 530 if (lquote != def_lquote)
10840 @end group
10841 @end smallexample
10842
10843 You can use @samp{set print address off} to eliminate all machine
10844 dependent displays from the @value{GDBN} interface. For example, with
10845 @code{print address off}, you should get the same text for backtraces on
10846 all machines---whether or not they involve pointer arguments.
10847
10848 @kindex show print
10849 @item show print address
10850 Show whether or not addresses are to be printed.
10851 @end table
10852
10853 When @value{GDBN} prints a symbolic address, it normally prints the
10854 closest earlier symbol plus an offset. If that symbol does not uniquely
10855 identify the address (for example, it is a name whose scope is a single
10856 source file), you may need to clarify. One way to do this is with
10857 @code{info line}, for example @samp{info line *0x4537}. Alternately,
10858 you can set @value{GDBN} to print the source file and line number when
10859 it prints a symbolic address:
10860
10861 @table @code
10862 @item set print symbol-filename on
10863 @cindex source file and line of a symbol
10864 @cindex symbol, source file and line
10865 Tell @value{GDBN} to print the source file name and line number of a
10866 symbol in the symbolic form of an address.
10867
10868 @item set print symbol-filename off
10869 Do not print source file name and line number of a symbol. This is the
10870 default.
10871
10872 @item show print symbol-filename
10873 Show whether or not @value{GDBN} will print the source file name and
10874 line number of a symbol in the symbolic form of an address.
10875 @end table
10876
10877 Another situation where it is helpful to show symbol filenames and line
10878 numbers is when disassembling code; @value{GDBN} shows you the line
10879 number and source file that corresponds to each instruction.
10880
10881 Also, you may wish to see the symbolic form only if the address being
10882 printed is reasonably close to the closest earlier symbol:
10883
10884 @table @code
10885 @item set print max-symbolic-offset @var{max-offset}
10886 @itemx set print max-symbolic-offset unlimited
10887 @cindex maximum value for offset of closest symbol
10888 Tell @value{GDBN} to only display the symbolic form of an address if the
10889 offset between the closest earlier symbol and the address is less than
10890 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
10891 to always print the symbolic form of an address if any symbol precedes
10892 it. Zero is equivalent to @code{unlimited}.
10893
10894 @item show print max-symbolic-offset
10895 Ask how large the maximum offset is that @value{GDBN} prints in a
10896 symbolic address.
10897 @end table
10898
10899 @cindex wild pointer, interpreting
10900 @cindex pointer, finding referent
10901 If you have a pointer and you are not sure where it points, try
10902 @samp{set print symbol-filename on}. Then you can determine the name
10903 and source file location of the variable where it points, using
10904 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
10905 For example, here @value{GDBN} shows that a variable @code{ptt} points
10906 at another variable @code{t}, defined in @file{hi2.c}:
10907
10908 @smallexample
10909 (@value{GDBP}) set print symbol-filename on
10910 (@value{GDBP}) p/a ptt
10911 $4 = 0xe008 <t in hi2.c>
10912 @end smallexample
10913
10914 @quotation
10915 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
10916 does not show the symbol name and filename of the referent, even with
10917 the appropriate @code{set print} options turned on.
10918 @end quotation
10919
10920 You can also enable @samp{/a}-like formatting all the time using
10921 @samp{set print symbol on}:
10922
10923 @anchor{set print symbol}
10924 @table @code
10925 @item set print symbol on
10926 Tell @value{GDBN} to print the symbol corresponding to an address, if
10927 one exists.
10928
10929 @item set print symbol off
10930 Tell @value{GDBN} not to print the symbol corresponding to an
10931 address. In this mode, @value{GDBN} will still print the symbol
10932 corresponding to pointers to functions. This is the default.
10933
10934 @item show print symbol
10935 Show whether @value{GDBN} will display the symbol corresponding to an
10936 address.
10937 @end table
10938
10939 Other settings control how different kinds of objects are printed:
10940
10941 @table @code
10942 @anchor{set print array}
10943 @item set print array
10944 @itemx set print array on
10945 @cindex pretty print arrays
10946 Pretty print arrays. This format is more convenient to read,
10947 but uses more space. The default is off.
10948
10949 @item set print array off
10950 Return to compressed format for arrays.
10951
10952 @item show print array
10953 Show whether compressed or pretty format is selected for displaying
10954 arrays.
10955
10956 @cindex print array indexes
10957 @anchor{set print array-indexes}
10958 @item set print array-indexes
10959 @itemx set print array-indexes on
10960 Print the index of each element when displaying arrays. May be more
10961 convenient to locate a given element in the array or quickly find the
10962 index of a given element in that printed array. The default is off.
10963
10964 @item set print array-indexes off
10965 Stop printing element indexes when displaying arrays.
10966
10967 @item show print array-indexes
10968 Show whether the index of each element is printed when displaying
10969 arrays.
10970
10971 @anchor{set print elements}
10972 @item set print elements @var{number-of-elements}
10973 @itemx set print elements unlimited
10974 @cindex number of array elements to print
10975 @cindex limit on number of printed array elements
10976 Set a limit on how many elements of an array @value{GDBN} will print.
10977 If @value{GDBN} is printing a large array, it stops printing after it has
10978 printed the number of elements set by the @code{set print elements} command.
10979 This limit also applies to the display of strings.
10980 When @value{GDBN} starts, this limit is set to 200.
10981 Setting @var{number-of-elements} to @code{unlimited} or zero means
10982 that the number of elements to print is unlimited.
10983
10984 @item show print elements
10985 Display the number of elements of a large array that @value{GDBN} will print.
10986 If the number is 0, then the printing is unlimited.
10987
10988 @anchor{set print frame-arguments}
10989 @item set print frame-arguments @var{value}
10990 @kindex set print frame-arguments
10991 @cindex printing frame argument values
10992 @cindex print all frame argument values
10993 @cindex print frame argument values for scalars only
10994 @cindex do not print frame arguments
10995 This command allows to control how the values of arguments are printed
10996 when the debugger prints a frame (@pxref{Frames}). The possible
10997 values are:
10998
10999 @table @code
11000 @item all
11001 The values of all arguments are printed.
11002
11003 @item scalars
11004 Print the value of an argument only if it is a scalar. The value of more
11005 complex arguments such as arrays, structures, unions, etc, is replaced
11006 by @code{@dots{}}. This is the default. Here is an example where
11007 only scalar arguments are shown:
11008
11009 @smallexample
11010 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11011 at frame-args.c:23
11012 @end smallexample
11013
11014 @item none
11015 None of the argument values are printed. Instead, the value of each argument
11016 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11017
11018 @smallexample
11019 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11020 at frame-args.c:23
11021 @end smallexample
11022
11023 @item presence
11024 Only the presence of arguments is indicated by @code{@dots{}}.
11025 The @code{@dots{}} are not printed for function without any arguments.
11026 None of the argument names and values are printed.
11027 In this case, the example above now becomes:
11028
11029 @smallexample
11030 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11031 @end smallexample
11032
11033 @end table
11034
11035 By default, only scalar arguments are printed. This command can be used
11036 to configure the debugger to print the value of all arguments, regardless
11037 of their type. However, it is often advantageous to not print the value
11038 of more complex parameters. For instance, it reduces the amount of
11039 information printed in each frame, making the backtrace more readable.
11040 Also, it improves performance when displaying Ada frames, because
11041 the computation of large arguments can sometimes be CPU-intensive,
11042 especially in large applications. Setting @code{print frame-arguments}
11043 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11044 this computation, thus speeding up the display of each Ada frame.
11045
11046 @item show print frame-arguments
11047 Show how the value of arguments should be displayed when printing a frame.
11048
11049 @anchor{set print raw-frame-arguments}
11050 @item set print raw-frame-arguments on
11051 Print frame arguments in raw, non pretty-printed, form.
11052
11053 @item set print raw-frame-arguments off
11054 Print frame arguments in pretty-printed form, if there is a pretty-printer
11055 for the value (@pxref{Pretty Printing}),
11056 otherwise print the value in raw form.
11057 This is the default.
11058
11059 @item show print raw-frame-arguments
11060 Show whether to print frame arguments in raw form.
11061
11062 @anchor{set print entry-values}
11063 @item set print entry-values @var{value}
11064 @kindex set print entry-values
11065 Set printing of frame argument values at function entry. In some cases
11066 @value{GDBN} can determine the value of function argument which was passed by
11067 the function caller, even if the value was modified inside the called function
11068 and therefore is different. With optimized code, the current value could be
11069 unavailable, but the entry value may still be known.
11070
11071 The default value is @code{default} (see below for its description). Older
11072 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11073 this feature will behave in the @code{default} setting the same way as with the
11074 @code{no} setting.
11075
11076 This functionality is currently supported only by DWARF 2 debugging format and
11077 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11078 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11079 this information.
11080
11081 The @var{value} parameter can be one of the following:
11082
11083 @table @code
11084 @item no
11085 Print only actual parameter values, never print values from function entry
11086 point.
11087 @smallexample
11088 #0 equal (val=5)
11089 #0 different (val=6)
11090 #0 lost (val=<optimized out>)
11091 #0 born (val=10)
11092 #0 invalid (val=<optimized out>)
11093 @end smallexample
11094
11095 @item only
11096 Print only parameter values from function entry point. The actual parameter
11097 values are never printed.
11098 @smallexample
11099 #0 equal (val@@entry=5)
11100 #0 different (val@@entry=5)
11101 #0 lost (val@@entry=5)
11102 #0 born (val@@entry=<optimized out>)
11103 #0 invalid (val@@entry=<optimized out>)
11104 @end smallexample
11105
11106 @item preferred
11107 Print only parameter values from function entry point. If value from function
11108 entry point is not known while the actual value is known, print the actual
11109 value for such parameter.
11110 @smallexample
11111 #0 equal (val@@entry=5)
11112 #0 different (val@@entry=5)
11113 #0 lost (val@@entry=5)
11114 #0 born (val=10)
11115 #0 invalid (val@@entry=<optimized out>)
11116 @end smallexample
11117
11118 @item if-needed
11119 Print actual parameter values. If actual parameter value is not known while
11120 value from function entry point is known, print the entry point value for such
11121 parameter.
11122 @smallexample
11123 #0 equal (val=5)
11124 #0 different (val=6)
11125 #0 lost (val@@entry=5)
11126 #0 born (val=10)
11127 #0 invalid (val=<optimized out>)
11128 @end smallexample
11129
11130 @item both
11131 Always print both the actual parameter value and its value from function entry
11132 point, even if values of one or both are not available due to compiler
11133 optimizations.
11134 @smallexample
11135 #0 equal (val=5, val@@entry=5)
11136 #0 different (val=6, val@@entry=5)
11137 #0 lost (val=<optimized out>, val@@entry=5)
11138 #0 born (val=10, val@@entry=<optimized out>)
11139 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11140 @end smallexample
11141
11142 @item compact
11143 Print the actual parameter value if it is known and also its value from
11144 function entry point if it is known. If neither is known, print for the actual
11145 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11146 values are known and identical, print the shortened
11147 @code{param=param@@entry=VALUE} notation.
11148 @smallexample
11149 #0 equal (val=val@@entry=5)
11150 #0 different (val=6, val@@entry=5)
11151 #0 lost (val@@entry=5)
11152 #0 born (val=10)
11153 #0 invalid (val=<optimized out>)
11154 @end smallexample
11155
11156 @item default
11157 Always print the actual parameter value. Print also its value from function
11158 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11159 if both values are known and identical, print the shortened
11160 @code{param=param@@entry=VALUE} notation.
11161 @smallexample
11162 #0 equal (val=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)
11166 #0 invalid (val=<optimized out>)
11167 @end smallexample
11168 @end table
11169
11170 For analysis messages on possible failures of frame argument values at function
11171 entry resolution see @ref{set debug entry-values}.
11172
11173 @item show print entry-values
11174 Show the method being used for printing of frame argument values at function
11175 entry.
11176
11177 @anchor{set print frame-info}
11178 @item set print frame-info @var{value}
11179 @kindex set print frame-info
11180 @cindex printing frame information
11181 @cindex frame information, printing
11182 This command allows to control the information printed when
11183 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11184 for a general explanation about frames and frame information.
11185 Note that some other settings (such as @code{set print frame-arguments}
11186 and @code{set print address}) are also influencing if and how some frame
11187 information is displayed. In particular, the frame program counter is never
11188 printed if @code{set print address} is off.
11189
11190 The possible values for @code{set print frame-info} are:
11191 @table @code
11192 @item short-location
11193 Print the frame level, the program counter (if not at the
11194 beginning of the location source line), the function, the function
11195 arguments.
11196 @item location
11197 Same as @code{short-location} but also print the source file and source line
11198 number.
11199 @item location-and-address
11200 Same as @code{location} but print the program counter even if located at the
11201 beginning of the location source line.
11202 @item source-line
11203 Print the program counter (if not at the beginning of the location
11204 source line), the line number and the source line.
11205 @item source-and-location
11206 Print what @code{location} and @code{source-line} are printing.
11207 @item auto
11208 The information printed for a frame is decided automatically
11209 by the @value{GDBN} command that prints a frame.
11210 For example, @code{frame} prints the information printed by
11211 @code{source-and-location} while @code{stepi} will switch between
11212 @code{source-line} and @code{source-and-location} depending on the program
11213 counter.
11214 The default value is @code{auto}.
11215 @end table
11216
11217 @anchor{set print repeats}
11218 @item set print repeats @var{number-of-repeats}
11219 @itemx set print repeats unlimited
11220 @cindex repeated array elements
11221 Set the threshold for suppressing display of repeated array
11222 elements. When the number of consecutive identical elements of an
11223 array exceeds the threshold, @value{GDBN} prints the string
11224 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11225 identical repetitions, instead of displaying the identical elements
11226 themselves. Setting the threshold to @code{unlimited} or zero will
11227 cause all elements to be individually printed. The default threshold
11228 is 10.
11229
11230 @item show print repeats
11231 Display the current threshold for printing repeated identical
11232 elements.
11233
11234 @anchor{set print max-depth}
11235 @item set print max-depth @var{depth}
11236 @item set print max-depth unlimited
11237 @cindex printing nested structures
11238 Set the threshold after which nested structures are replaced with
11239 ellipsis, this can make visualising deeply nested structures easier.
11240
11241 For example, given this C code
11242
11243 @smallexample
11244 typedef struct s1 @{ int a; @} s1;
11245 typedef struct s2 @{ s1 b; @} s2;
11246 typedef struct s3 @{ s2 c; @} s3;
11247 typedef struct s4 @{ s3 d; @} s4;
11248
11249 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11250 @end smallexample
11251
11252 The following table shows how different values of @var{depth} will
11253 effect how @code{var} is printed by @value{GDBN}:
11254
11255 @multitable @columnfractions .3 .7
11256 @headitem @var{depth} setting @tab Result of @samp{p var}
11257 @item unlimited
11258 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11259 @item @code{0}
11260 @tab @code{$1 = @{...@}}
11261 @item @code{1}
11262 @tab @code{$1 = @{d = @{...@}@}}
11263 @item @code{2}
11264 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11265 @item @code{3}
11266 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11267 @item @code{4}
11268 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11269 @end multitable
11270
11271 To see the contents of structures that have been hidden the user can
11272 either increase the print max-depth, or they can print the elements of
11273 the structure that are visible, for example
11274
11275 @smallexample
11276 (gdb) set print max-depth 2
11277 (gdb) p var
11278 $1 = @{d = @{c = @{...@}@}@}
11279 (gdb) p var.d
11280 $2 = @{c = @{b = @{...@}@}@}
11281 (gdb) p var.d.c
11282 $3 = @{b = @{a = 3@}@}
11283 @end smallexample
11284
11285 The pattern used to replace nested structures varies based on
11286 language, for most languages @code{@{...@}} is used, but Fortran uses
11287 @code{(...)}.
11288
11289 @item show print max-depth
11290 Display the current threshold after which nested structures are
11291 replaces with ellipsis.
11292
11293 @anchor{set print null-stop}
11294 @item set print null-stop
11295 @cindex @sc{null} elements in arrays
11296 Cause @value{GDBN} to stop printing the characters of an array when the first
11297 @sc{null} is encountered. This is useful when large arrays actually
11298 contain only short strings.
11299 The default is off.
11300
11301 @item show print null-stop
11302 Show whether @value{GDBN} stops printing an array on the first
11303 @sc{null} character.
11304
11305 @anchor{set print pretty}
11306 @item set print pretty on
11307 @cindex print structures in indented form
11308 @cindex indentation in structure display
11309 Cause @value{GDBN} to print structures in an indented format with one member
11310 per line, like this:
11311
11312 @smallexample
11313 @group
11314 $1 = @{
11315 next = 0x0,
11316 flags = @{
11317 sweet = 1,
11318 sour = 1
11319 @},
11320 meat = 0x54 "Pork"
11321 @}
11322 @end group
11323 @end smallexample
11324
11325 @item set print pretty off
11326 Cause @value{GDBN} to print structures in a compact format, like this:
11327
11328 @smallexample
11329 @group
11330 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11331 meat = 0x54 "Pork"@}
11332 @end group
11333 @end smallexample
11334
11335 @noindent
11336 This is the default format.
11337
11338 @item show print pretty
11339 Show which format @value{GDBN} is using to print structures.
11340
11341 @anchor{set print raw-values}
11342 @item set print raw-values on
11343 Print values in raw form, without applying the pretty
11344 printers for the value.
11345
11346 @item set print raw-values off
11347 Print values in pretty-printed form, if there is a pretty-printer
11348 for the value (@pxref{Pretty Printing}),
11349 otherwise print the value in raw form.
11350
11351 The default setting is ``off''.
11352
11353 @item show print raw-values
11354 Show whether to print values in raw form.
11355
11356 @item set print sevenbit-strings on
11357 @cindex eight-bit characters in strings
11358 @cindex octal escapes in strings
11359 Print using only seven-bit characters; if this option is set,
11360 @value{GDBN} displays any eight-bit characters (in strings or
11361 character values) using the notation @code{\}@var{nnn}. This setting is
11362 best if you are working in English (@sc{ascii}) and you use the
11363 high-order bit of characters as a marker or ``meta'' bit.
11364
11365 @item set print sevenbit-strings off
11366 Print full eight-bit characters. This allows the use of more
11367 international character sets, and is the default.
11368
11369 @item show print sevenbit-strings
11370 Show whether or not @value{GDBN} is printing only seven-bit characters.
11371
11372 @anchor{set print union}
11373 @item set print union on
11374 @cindex unions in structures, printing
11375 Tell @value{GDBN} to print unions which are contained in structures
11376 and other unions. This is the default setting.
11377
11378 @item set print union off
11379 Tell @value{GDBN} not to print unions which are contained in
11380 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11381 instead.
11382
11383 @item show print union
11384 Ask @value{GDBN} whether or not it will print unions which are contained in
11385 structures and other unions.
11386
11387 For example, given the declarations
11388
11389 @smallexample
11390 typedef enum @{Tree, Bug@} Species;
11391 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11392 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11393 Bug_forms;
11394
11395 struct thing @{
11396 Species it;
11397 union @{
11398 Tree_forms tree;
11399 Bug_forms bug;
11400 @} form;
11401 @};
11402
11403 struct thing foo = @{Tree, @{Acorn@}@};
11404 @end smallexample
11405
11406 @noindent
11407 with @code{set print union on} in effect @samp{p foo} would print
11408
11409 @smallexample
11410 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11411 @end smallexample
11412
11413 @noindent
11414 and with @code{set print union off} in effect it would print
11415
11416 @smallexample
11417 $1 = @{it = Tree, form = @{...@}@}
11418 @end smallexample
11419
11420 @noindent
11421 @code{set print union} affects programs written in C-like languages
11422 and in Pascal.
11423 @end table
11424
11425 @need 1000
11426 @noindent
11427 These settings are of interest when debugging C@t{++} programs:
11428
11429 @table @code
11430 @cindex demangling C@t{++} names
11431 @item set print demangle
11432 @itemx set print demangle on
11433 Print C@t{++} names in their source form rather than in the encoded
11434 (``mangled'') form passed to the assembler and linker for type-safe
11435 linkage. The default is on.
11436
11437 @item show print demangle
11438 Show whether C@t{++} names are printed in mangled or demangled form.
11439
11440 @item set print asm-demangle
11441 @itemx set print asm-demangle on
11442 Print C@t{++} names in their source form rather than their mangled form, even
11443 in assembler code printouts such as instruction disassemblies.
11444 The default is off.
11445
11446 @item show print asm-demangle
11447 Show whether C@t{++} names in assembly listings are printed in mangled
11448 or demangled form.
11449
11450 @cindex C@t{++} symbol decoding style
11451 @cindex symbol decoding style, C@t{++}
11452 @kindex set demangle-style
11453 @item set demangle-style @var{style}
11454 Choose among several encoding schemes used by different compilers to represent
11455 C@t{++} names. If you omit @var{style}, you will see a list of possible
11456 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11457 decoding style by inspecting your program.
11458
11459 @item show demangle-style
11460 Display the encoding style currently in use for decoding C@t{++} symbols.
11461
11462 @anchor{set print object}
11463 @item set print object
11464 @itemx set print object on
11465 @cindex derived type of an object, printing
11466 @cindex display derived types
11467 When displaying a pointer to an object, identify the @emph{actual}
11468 (derived) type of the object rather than the @emph{declared} type, using
11469 the virtual function table. Note that the virtual function table is
11470 required---this feature can only work for objects that have run-time
11471 type identification; a single virtual method in the object's declared
11472 type is sufficient. Note that this setting is also taken into account when
11473 working with variable objects via MI (@pxref{GDB/MI}).
11474
11475 @item set print object off
11476 Display only the declared type of objects, without reference to the
11477 virtual function table. This is the default setting.
11478
11479 @item show print object
11480 Show whether actual, or declared, object types are displayed.
11481
11482 @anchor{set print static-members}
11483 @item set print static-members
11484 @itemx set print static-members on
11485 @cindex static members of C@t{++} objects
11486 Print static members when displaying a C@t{++} object. The default is on.
11487
11488 @item set print static-members off
11489 Do not print static members when displaying a C@t{++} object.
11490
11491 @item show print static-members
11492 Show whether C@t{++} static members are printed or not.
11493
11494 @item set print pascal_static-members
11495 @itemx set print pascal_static-members on
11496 @cindex static members of Pascal objects
11497 @cindex Pascal objects, static members display
11498 Print static members when displaying a Pascal object. The default is on.
11499
11500 @item set print pascal_static-members off
11501 Do not print static members when displaying a Pascal object.
11502
11503 @item show print pascal_static-members
11504 Show whether Pascal static members are printed or not.
11505
11506 @c These don't work with HP ANSI C++ yet.
11507 @anchor{set print vtbl}
11508 @item set print vtbl
11509 @itemx set print vtbl on
11510 @cindex pretty print C@t{++} virtual function tables
11511 @cindex virtual functions (C@t{++}) display
11512 @cindex VTBL display
11513 Pretty print C@t{++} virtual function tables. The default is off.
11514 (The @code{vtbl} commands do not work on programs compiled with the HP
11515 ANSI C@t{++} compiler (@code{aCC}).)
11516
11517 @item set print vtbl off
11518 Do not pretty print C@t{++} virtual function tables.
11519
11520 @item show print vtbl
11521 Show whether C@t{++} virtual function tables are pretty printed, or not.
11522 @end table
11523
11524 @node Pretty Printing
11525 @section Pretty Printing
11526
11527 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11528 Python code. It greatly simplifies the display of complex objects. This
11529 mechanism works for both MI and the CLI.
11530
11531 @menu
11532 * Pretty-Printer Introduction:: Introduction to pretty-printers
11533 * Pretty-Printer Example:: An example pretty-printer
11534 * Pretty-Printer Commands:: Pretty-printer commands
11535 @end menu
11536
11537 @node Pretty-Printer Introduction
11538 @subsection Pretty-Printer Introduction
11539
11540 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11541 registered for the value. If there is then @value{GDBN} invokes the
11542 pretty-printer to print the value. Otherwise the value is printed normally.
11543
11544 Pretty-printers are normally named. This makes them easy to manage.
11545 The @samp{info pretty-printer} command will list all the installed
11546 pretty-printers with their names.
11547 If a pretty-printer can handle multiple data types, then its
11548 @dfn{subprinters} are the printers for the individual data types.
11549 Each such subprinter has its own name.
11550 The format of the name is @var{printer-name};@var{subprinter-name}.
11551
11552 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11553 Typically they are automatically loaded and registered when the corresponding
11554 debug information is loaded, thus making them available without having to
11555 do anything special.
11556
11557 There are three places where a pretty-printer can be registered.
11558
11559 @itemize @bullet
11560 @item
11561 Pretty-printers registered globally are available when debugging
11562 all inferiors.
11563
11564 @item
11565 Pretty-printers registered with a program space are available only
11566 when debugging that program.
11567 @xref{Progspaces In Python}, for more details on program spaces in Python.
11568
11569 @item
11570 Pretty-printers registered with an objfile are loaded and unloaded
11571 with the corresponding objfile (e.g., shared library).
11572 @xref{Objfiles In Python}, for more details on objfiles in Python.
11573 @end itemize
11574
11575 @xref{Selecting Pretty-Printers}, for further information on how
11576 pretty-printers are selected,
11577
11578 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11579 for new types.
11580
11581 @node Pretty-Printer Example
11582 @subsection Pretty-Printer Example
11583
11584 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11585
11586 @smallexample
11587 (@value{GDBP}) print s
11588 $1 = @{
11589 static npos = 4294967295,
11590 _M_dataplus = @{
11591 <std::allocator<char>> = @{
11592 <__gnu_cxx::new_allocator<char>> = @{
11593 <No data fields>@}, <No data fields>
11594 @},
11595 members of std::basic_string<char, std::char_traits<char>,
11596 std::allocator<char> >::_Alloc_hider:
11597 _M_p = 0x804a014 "abcd"
11598 @}
11599 @}
11600 @end smallexample
11601
11602 With a pretty-printer for @code{std::string} only the contents are printed:
11603
11604 @smallexample
11605 (@value{GDBP}) print s
11606 $2 = "abcd"
11607 @end smallexample
11608
11609 @node Pretty-Printer Commands
11610 @subsection Pretty-Printer Commands
11611 @cindex pretty-printer commands
11612
11613 @table @code
11614 @kindex info pretty-printer
11615 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11616 Print the list of installed pretty-printers.
11617 This includes disabled pretty-printers, which are marked as such.
11618
11619 @var{object-regexp} is a regular expression matching the objects
11620 whose pretty-printers to list.
11621 Objects can be @code{global}, the program space's file
11622 (@pxref{Progspaces In Python}),
11623 and the object files within that program space (@pxref{Objfiles In Python}).
11624 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11625 looks up a printer from these three objects.
11626
11627 @var{name-regexp} is a regular expression matching the name of the printers
11628 to list.
11629
11630 @kindex disable pretty-printer
11631 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11632 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11633 A disabled pretty-printer is not forgotten, it may be enabled again later.
11634
11635 @kindex enable pretty-printer
11636 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11637 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11638 @end table
11639
11640 Example:
11641
11642 Suppose we have three pretty-printers installed: one from library1.so
11643 named @code{foo} that prints objects of type @code{foo}, and
11644 another from library2.so named @code{bar} that prints two types of objects,
11645 @code{bar1} and @code{bar2}.
11646
11647 @smallexample
11648 (gdb) info pretty-printer
11649 library1.so:
11650 foo
11651 library2.so:
11652 bar
11653 bar1
11654 bar2
11655 (gdb) info pretty-printer library2
11656 library2.so:
11657 bar
11658 bar1
11659 bar2
11660 (gdb) disable pretty-printer library1
11661 1 printer disabled
11662 2 of 3 printers enabled
11663 (gdb) info pretty-printer
11664 library1.so:
11665 foo [disabled]
11666 library2.so:
11667 bar
11668 bar1
11669 bar2
11670 (gdb) disable pretty-printer library2 bar;bar1
11671 1 printer disabled
11672 1 of 3 printers enabled
11673 (gdb) info pretty-printer library2
11674 library1.so:
11675 foo [disabled]
11676 library2.so:
11677 bar
11678 bar1 [disabled]
11679 bar2
11680 (gdb) disable pretty-printer library2 bar
11681 1 printer disabled
11682 0 of 3 printers enabled
11683 (gdb) info pretty-printer library2
11684 library1.so:
11685 foo [disabled]
11686 library2.so:
11687 bar [disabled]
11688 bar1 [disabled]
11689 bar2
11690 @end smallexample
11691
11692 Note that for @code{bar} the entire printer can be disabled,
11693 as can each individual subprinter.
11694
11695 Printing values and frame arguments is done by default using
11696 the enabled pretty printers.
11697
11698 The print option @code{-raw-values} and @value{GDBN} setting
11699 @code{set print raw-values} (@pxref{set print raw-values}) can be
11700 used to print values without applying the enabled pretty printers.
11701
11702 Similarly, the backtrace option @code{-raw-frame-arguments} and
11703 @value{GDBN} setting @code{set print raw-frame-arguments}
11704 (@pxref{set print raw-frame-arguments}) can be used to ignore the
11705 enabled pretty printers when printing frame argument values.
11706
11707 @node Value History
11708 @section Value History
11709
11710 @cindex value history
11711 @cindex history of values printed by @value{GDBN}
11712 Values printed by the @code{print} command are saved in the @value{GDBN}
11713 @dfn{value history}. This allows you to refer to them in other expressions.
11714 Values are kept until the symbol table is re-read or discarded
11715 (for example with the @code{file} or @code{symbol-file} commands).
11716 When the symbol table changes, the value history is discarded,
11717 since the values may contain pointers back to the types defined in the
11718 symbol table.
11719
11720 @cindex @code{$}
11721 @cindex @code{$$}
11722 @cindex history number
11723 The values printed are given @dfn{history numbers} by which you can
11724 refer to them. These are successive integers starting with one.
11725 @code{print} shows you the history number assigned to a value by
11726 printing @samp{$@var{num} = } before the value; here @var{num} is the
11727 history number.
11728
11729 To refer to any previous value, use @samp{$} followed by the value's
11730 history number. The way @code{print} labels its output is designed to
11731 remind you of this. Just @code{$} refers to the most recent value in
11732 the history, and @code{$$} refers to the value before that.
11733 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11734 is the value just prior to @code{$$}, @code{$$1} is equivalent to
11735 @code{$$}, and @code{$$0} is equivalent to @code{$}.
11736
11737 For example, suppose you have just printed a pointer to a structure and
11738 want to see the contents of the structure. It suffices to type
11739
11740 @smallexample
11741 p *$
11742 @end smallexample
11743
11744 If you have a chain of structures where the component @code{next} points
11745 to the next one, you can print the contents of the next one with this:
11746
11747 @smallexample
11748 p *$.next
11749 @end smallexample
11750
11751 @noindent
11752 You can print successive links in the chain by repeating this
11753 command---which you can do by just typing @key{RET}.
11754
11755 Note that the history records values, not expressions. If the value of
11756 @code{x} is 4 and you type these commands:
11757
11758 @smallexample
11759 print x
11760 set x=5
11761 @end smallexample
11762
11763 @noindent
11764 then the value recorded in the value history by the @code{print} command
11765 remains 4 even though the value of @code{x} has changed.
11766
11767 @table @code
11768 @kindex show values
11769 @item show values
11770 Print the last ten values in the value history, with their item numbers.
11771 This is like @samp{p@ $$9} repeated ten times, except that @code{show
11772 values} does not change the history.
11773
11774 @item show values @var{n}
11775 Print ten history values centered on history item number @var{n}.
11776
11777 @item show values +
11778 Print ten history values just after the values last printed. If no more
11779 values are available, @code{show values +} produces no display.
11780 @end table
11781
11782 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11783 same effect as @samp{show values +}.
11784
11785 @node Convenience Vars
11786 @section Convenience Variables
11787
11788 @cindex convenience variables
11789 @cindex user-defined variables
11790 @value{GDBN} provides @dfn{convenience variables} that you can use within
11791 @value{GDBN} to hold on to a value and refer to it later. These variables
11792 exist entirely within @value{GDBN}; they are not part of your program, and
11793 setting a convenience variable has no direct effect on further execution
11794 of your program. That is why you can use them freely.
11795
11796 Convenience variables are prefixed with @samp{$}. Any name preceded by
11797 @samp{$} can be used for a convenience variable, unless it is one of
11798 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
11799 (Value history references, in contrast, are @emph{numbers} preceded
11800 by @samp{$}. @xref{Value History, ,Value History}.)
11801
11802 You can save a value in a convenience variable with an assignment
11803 expression, just as you would set a variable in your program.
11804 For example:
11805
11806 @smallexample
11807 set $foo = *object_ptr
11808 @end smallexample
11809
11810 @noindent
11811 would save in @code{$foo} the value contained in the object pointed to by
11812 @code{object_ptr}.
11813
11814 Using a convenience variable for the first time creates it, but its
11815 value is @code{void} until you assign a new value. You can alter the
11816 value with another assignment at any time.
11817
11818 Convenience variables have no fixed types. You can assign a convenience
11819 variable any type of value, including structures and arrays, even if
11820 that variable already has a value of a different type. The convenience
11821 variable, when used as an expression, has the type of its current value.
11822
11823 @table @code
11824 @kindex show convenience
11825 @cindex show all user variables and functions
11826 @item show convenience
11827 Print a list of convenience variables used so far, and their values,
11828 as well as a list of the convenience functions.
11829 Abbreviated @code{show conv}.
11830
11831 @kindex init-if-undefined
11832 @cindex convenience variables, initializing
11833 @item init-if-undefined $@var{variable} = @var{expression}
11834 Set a convenience variable if it has not already been set. This is useful
11835 for user-defined commands that keep some state. It is similar, in concept,
11836 to using local static variables with initializers in C (except that
11837 convenience variables are global). It can also be used to allow users to
11838 override default values used in a command script.
11839
11840 If the variable is already defined then the expression is not evaluated so
11841 any side-effects do not occur.
11842 @end table
11843
11844 One of the ways to use a convenience variable is as a counter to be
11845 incremented or a pointer to be advanced. For example, to print
11846 a field from successive elements of an array of structures:
11847
11848 @smallexample
11849 set $i = 0
11850 print bar[$i++]->contents
11851 @end smallexample
11852
11853 @noindent
11854 Repeat that command by typing @key{RET}.
11855
11856 Some convenience variables are created automatically by @value{GDBN} and given
11857 values likely to be useful.
11858
11859 @table @code
11860 @vindex $_@r{, convenience variable}
11861 @item $_
11862 The variable @code{$_} is automatically set by the @code{x} command to
11863 the last address examined (@pxref{Memory, ,Examining Memory}). Other
11864 commands which provide a default address for @code{x} to examine also
11865 set @code{$_} to that address; these commands include @code{info line}
11866 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11867 except when set by the @code{x} command, in which case it is a pointer
11868 to the type of @code{$__}.
11869
11870 @vindex $__@r{, convenience variable}
11871 @item $__
11872 The variable @code{$__} is automatically set by the @code{x} command
11873 to the value found in the last address examined. Its type is chosen
11874 to match the format in which the data was printed.
11875
11876 @item $_exitcode
11877 @vindex $_exitcode@r{, convenience variable}
11878 When the program being debugged terminates normally, @value{GDBN}
11879 automatically sets this variable to the exit code of the program, and
11880 resets @code{$_exitsignal} to @code{void}.
11881
11882 @item $_exitsignal
11883 @vindex $_exitsignal@r{, convenience variable}
11884 When the program being debugged dies due to an uncaught signal,
11885 @value{GDBN} automatically sets this variable to that signal's number,
11886 and resets @code{$_exitcode} to @code{void}.
11887
11888 To distinguish between whether the program being debugged has exited
11889 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
11890 @code{$_exitsignal} is not @code{void}), the convenience function
11891 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
11892 Functions}). For example, considering the following source code:
11893
11894 @smallexample
11895 #include <signal.h>
11896
11897 int
11898 main (int argc, char *argv[])
11899 @{
11900 raise (SIGALRM);
11901 return 0;
11902 @}
11903 @end smallexample
11904
11905 A valid way of telling whether the program being debugged has exited
11906 or signalled would be:
11907
11908 @smallexample
11909 (@value{GDBP}) define has_exited_or_signalled
11910 Type commands for definition of ``has_exited_or_signalled''.
11911 End with a line saying just ``end''.
11912 >if $_isvoid ($_exitsignal)
11913 >echo The program has exited\n
11914 >else
11915 >echo The program has signalled\n
11916 >end
11917 >end
11918 (@value{GDBP}) run
11919 Starting program:
11920
11921 Program terminated with signal SIGALRM, Alarm clock.
11922 The program no longer exists.
11923 (@value{GDBP}) has_exited_or_signalled
11924 The program has signalled
11925 @end smallexample
11926
11927 As can be seen, @value{GDBN} correctly informs that the program being
11928 debugged has signalled, since it calls @code{raise} and raises a
11929 @code{SIGALRM} signal. If the program being debugged had not called
11930 @code{raise}, then @value{GDBN} would report a normal exit:
11931
11932 @smallexample
11933 (@value{GDBP}) has_exited_or_signalled
11934 The program has exited
11935 @end smallexample
11936
11937 @item $_exception
11938 The variable @code{$_exception} is set to the exception object being
11939 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
11940
11941 @item $_ada_exception
11942 The variable @code{$_ada_exception} is set to the address of the
11943 exception being caught or thrown at an Ada exception-related
11944 catchpoint. @xref{Set Catchpoints}.
11945
11946 @item $_probe_argc
11947 @itemx $_probe_arg0@dots{}$_probe_arg11
11948 Arguments to a static probe. @xref{Static Probe Points}.
11949
11950 @item $_sdata
11951 @vindex $_sdata@r{, inspect, convenience variable}
11952 The variable @code{$_sdata} contains extra collected static tracepoint
11953 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
11954 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
11955 if extra static tracepoint data has not been collected.
11956
11957 @item $_siginfo
11958 @vindex $_siginfo@r{, convenience variable}
11959 The variable @code{$_siginfo} contains extra signal information
11960 (@pxref{extra signal information}). Note that @code{$_siginfo}
11961 could be empty, if the application has not yet received any signals.
11962 For example, it will be empty before you execute the @code{run} command.
11963
11964 @item $_tlb
11965 @vindex $_tlb@r{, convenience variable}
11966 The variable @code{$_tlb} is automatically set when debugging
11967 applications running on MS-Windows in native mode or connected to
11968 gdbserver that supports the @code{qGetTIBAddr} request.
11969 @xref{General Query Packets}.
11970 This variable contains the address of the thread information block.
11971
11972 @item $_inferior
11973 The number of the current inferior. @xref{Inferiors Connections and
11974 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
11975
11976 @item $_thread
11977 The thread number of the current thread. @xref{thread numbers}.
11978
11979 @item $_gthread
11980 The global number of the current thread. @xref{global thread numbers}.
11981
11982 @item $_gdb_major
11983 @itemx $_gdb_minor
11984 @vindex $_gdb_major@r{, convenience variable}
11985 @vindex $_gdb_minor@r{, convenience variable}
11986 The major and minor version numbers of the running @value{GDBN}.
11987 Development snapshots and pretest versions have their minor version
11988 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
11989 the value 12 for @code{$_gdb_minor}. These variables allow you to
11990 write scripts that work with different versions of @value{GDBN}
11991 without errors caused by features unavailable in some of those
11992 versions.
11993
11994 @item $_shell_exitcode
11995 @itemx $_shell_exitsignal
11996 @vindex $_shell_exitcode@r{, convenience variable}
11997 @vindex $_shell_exitsignal@r{, convenience variable}
11998 @cindex shell command, exit code
11999 @cindex shell command, exit signal
12000 @cindex exit status of shell commands
12001 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12002 shell commands. When a launched command terminates, @value{GDBN}
12003 automatically maintains the variables @code{$_shell_exitcode}
12004 and @code{$_shell_exitsignal} according to the exit status of the last
12005 launched command. These variables are set and used similarly to
12006 the variables @code{$_exitcode} and @code{$_exitsignal}.
12007
12008 @end table
12009
12010 @node Convenience Funs
12011 @section Convenience Functions
12012
12013 @cindex convenience functions
12014 @value{GDBN} also supplies some @dfn{convenience functions}. These
12015 have a syntax similar to convenience variables. A convenience
12016 function can be used in an expression just like an ordinary function;
12017 however, a convenience function is implemented internally to
12018 @value{GDBN}.
12019
12020 These functions do not require @value{GDBN} to be configured with
12021 @code{Python} support, which means that they are always available.
12022
12023 @table @code
12024
12025 @item $_isvoid (@var{expr})
12026 @findex $_isvoid@r{, convenience function}
12027 Return one if the expression @var{expr} is @code{void}. Otherwise it
12028 returns zero.
12029
12030 A @code{void} expression is an expression where the type of the result
12031 is @code{void}. For example, you can examine a convenience variable
12032 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12033 it is @code{void}:
12034
12035 @smallexample
12036 (@value{GDBP}) print $_exitcode
12037 $1 = void
12038 (@value{GDBP}) print $_isvoid ($_exitcode)
12039 $2 = 1
12040 (@value{GDBP}) run
12041 Starting program: ./a.out
12042 [Inferior 1 (process 29572) exited normally]
12043 (@value{GDBP}) print $_exitcode
12044 $3 = 0
12045 (@value{GDBP}) print $_isvoid ($_exitcode)
12046 $4 = 0
12047 @end smallexample
12048
12049 In the example above, we used @code{$_isvoid} to check whether
12050 @code{$_exitcode} is @code{void} before and after the execution of the
12051 program being debugged. Before the execution there is no exit code to
12052 be examined, therefore @code{$_exitcode} is @code{void}. After the
12053 execution the program being debugged returned zero, therefore
12054 @code{$_exitcode} is zero, which means that it is not @code{void}
12055 anymore.
12056
12057 The @code{void} expression can also be a call of a function from the
12058 program being debugged. For example, given the following function:
12059
12060 @smallexample
12061 void
12062 foo (void)
12063 @{
12064 @}
12065 @end smallexample
12066
12067 The result of calling it inside @value{GDBN} is @code{void}:
12068
12069 @smallexample
12070 (@value{GDBP}) print foo ()
12071 $1 = void
12072 (@value{GDBP}) print $_isvoid (foo ())
12073 $2 = 1
12074 (@value{GDBP}) set $v = foo ()
12075 (@value{GDBP}) print $v
12076 $3 = void
12077 (@value{GDBP}) print $_isvoid ($v)
12078 $4 = 1
12079 @end smallexample
12080
12081 @item $_gdb_setting_str (@var{setting})
12082 @findex $_gdb_setting_str@r{, convenience function}
12083 Return the value of the @value{GDBN} @var{setting} as a string.
12084 @var{setting} is any setting that can be used in a @code{set} or
12085 @code{show} command (@pxref{Controlling GDB}).
12086
12087 @smallexample
12088 (@value{GDBP}) show print frame-arguments
12089 Printing of non-scalar frame arguments is "scalars".
12090 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12091 $1 = "scalars"
12092 (@value{GDBP}) p $_gdb_setting_str("height")
12093 $2 = "30"
12094 (@value{GDBP})
12095 @end smallexample
12096
12097 @item $_gdb_setting (@var{setting})
12098 @findex $_gdb_setting@r{, convenience function}
12099 Return the value of the @value{GDBN} @var{setting}.
12100 The type of the returned value depends on the setting.
12101
12102 The value type for boolean and auto boolean settings is @code{int}.
12103 The boolean values @code{off} and @code{on} are converted to
12104 the integer values @code{0} and @code{1}. The value @code{auto} is
12105 converted to the value @code{-1}.
12106
12107 The value type for integer settings is either @code{unsigned int}
12108 or @code{int}, depending on the setting.
12109
12110 Some integer settings accept an @code{unlimited} value.
12111 Depending on the setting, the @code{set} command also accepts
12112 the value @code{0} or the value @code{@minus{}1} as a synonym for
12113 @code{unlimited}.
12114 For example, @code{set height unlimited} is equivalent to
12115 @code{set height 0}.
12116
12117 Some other settings that accept the @code{unlimited} value
12118 use the value @code{0} to literally mean zero.
12119 For example, @code{set history size 0} indicates to not
12120 record any @value{GDBN} commands in the command history.
12121 For such settings, @code{@minus{}1} is the synonym
12122 for @code{unlimited}.
12123
12124 See the documentation of the corresponding @code{set} command for
12125 the numerical value equivalent to @code{unlimited}.
12126
12127 The @code{$_gdb_setting} function converts the unlimited value
12128 to a @code{0} or a @code{@minus{}1} value according to what the
12129 @code{set} command uses.
12130
12131 @smallexample
12132 @group
12133 (@value{GDBP}) p $_gdb_setting_str("height")
12134 $1 = "30"
12135 (@value{GDBP}) p $_gdb_setting("height")
12136 $2 = 30
12137 (@value{GDBP}) set height unlimited
12138 (@value{GDBP}) p $_gdb_setting_str("height")
12139 $3 = "unlimited"
12140 (@value{GDBP}) p $_gdb_setting("height")
12141 $4 = 0
12142 @end group
12143 @group
12144 (@value{GDBP}) p $_gdb_setting_str("history size")
12145 $5 = "unlimited"
12146 (@value{GDBP}) p $_gdb_setting("history size")
12147 $6 = -1
12148 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12149 $7 = "auto"
12150 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12151 $8 = -1
12152 (@value{GDBP})
12153 @end group
12154 @end smallexample
12155
12156 Other setting types (enum, filename, optional filename, string, string noescape)
12157 are returned as string values.
12158
12159
12160 @item $_gdb_maint_setting_str (@var{setting})
12161 @findex $_gdb_maint_setting_str@r{, convenience function}
12162 Like the @code{$_gdb_setting_str} function, but works with
12163 @code{maintenance set} variables.
12164
12165 @item $_gdb_maint_setting (@var{setting})
12166 @findex $_gdb_maint_setting@r{, convenience function}
12167 Like the @code{$_gdb_setting} function, but works with
12168 @code{maintenance set} variables.
12169
12170 @end table
12171
12172 The following functions require @value{GDBN} to be configured with
12173 @code{Python} support.
12174
12175 @table @code
12176
12177 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12178 @findex $_memeq@r{, convenience function}
12179 Returns one if the @var{length} bytes at the addresses given by
12180 @var{buf1} and @var{buf2} are equal.
12181 Otherwise it returns zero.
12182
12183 @item $_regex(@var{str}, @var{regex})
12184 @findex $_regex@r{, convenience function}
12185 Returns one if the string @var{str} matches the regular expression
12186 @var{regex}. Otherwise it returns zero.
12187 The syntax of the regular expression is that specified by @code{Python}'s
12188 regular expression support.
12189
12190 @item $_streq(@var{str1}, @var{str2})
12191 @findex $_streq@r{, convenience function}
12192 Returns one if the strings @var{str1} and @var{str2} are equal.
12193 Otherwise it returns zero.
12194
12195 @item $_strlen(@var{str})
12196 @findex $_strlen@r{, convenience function}
12197 Returns the length of string @var{str}.
12198
12199 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12200 @findex $_caller_is@r{, convenience function}
12201 Returns one if the calling function's name is equal to @var{name}.
12202 Otherwise it returns zero.
12203
12204 If the optional argument @var{number_of_frames} is provided,
12205 it is the number of frames up in the stack to look.
12206 The default is 1.
12207
12208 Example:
12209
12210 @smallexample
12211 (gdb) backtrace
12212 #0 bottom_func ()
12213 at testsuite/gdb.python/py-caller-is.c:21
12214 #1 0x00000000004005a0 in middle_func ()
12215 at testsuite/gdb.python/py-caller-is.c:27
12216 #2 0x00000000004005ab in top_func ()
12217 at testsuite/gdb.python/py-caller-is.c:33
12218 #3 0x00000000004005b6 in main ()
12219 at testsuite/gdb.python/py-caller-is.c:39
12220 (gdb) print $_caller_is ("middle_func")
12221 $1 = 1
12222 (gdb) print $_caller_is ("top_func", 2)
12223 $1 = 1
12224 @end smallexample
12225
12226 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12227 @findex $_caller_matches@r{, convenience function}
12228 Returns one if the calling function's name matches the regular expression
12229 @var{regexp}. 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 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12236 @findex $_any_caller_is@r{, convenience function}
12237 Returns one if any calling function's name is equal to @var{name}.
12238 Otherwise it returns zero.
12239
12240 If the optional argument @var{number_of_frames} is provided,
12241 it is the number of frames up in the stack to look.
12242 The default is 1.
12243
12244 This function differs from @code{$_caller_is} in that this function
12245 checks all stack frames from the immediate caller to the frame specified
12246 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12247 frame specified by @var{number_of_frames}.
12248
12249 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12250 @findex $_any_caller_matches@r{, convenience function}
12251 Returns one if any calling function's name matches the regular expression
12252 @var{regexp}. Otherwise it returns zero.
12253
12254 If the optional argument @var{number_of_frames} is provided,
12255 it is the number of frames up in the stack to look.
12256 The default is 1.
12257
12258 This function differs from @code{$_caller_matches} in that this function
12259 checks all stack frames from the immediate caller to the frame specified
12260 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12261 frame specified by @var{number_of_frames}.
12262
12263 @item $_as_string(@var{value})
12264 @findex $_as_string@r{, convenience function}
12265 Return the string representation of @var{value}.
12266
12267 This function is useful to obtain the textual label (enumerator) of an
12268 enumeration value. For example, assuming the variable @var{node} is of
12269 an enumerated type:
12270
12271 @smallexample
12272 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12273 Visiting node of type NODE_INTEGER
12274 @end smallexample
12275
12276 @item $_cimag(@var{value})
12277 @itemx $_creal(@var{value})
12278 @findex $_cimag@r{, convenience function}
12279 @findex $_creal@r{, convenience function}
12280 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12281 the complex number @var{value}.
12282
12283 The type of the imaginary or real part depends on the type of the
12284 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12285 will return an imaginary part of type @code{float}.
12286
12287 @end table
12288
12289 @value{GDBN} provides the ability to list and get help on
12290 convenience functions.
12291
12292 @table @code
12293 @item help function
12294 @kindex help function
12295 @cindex show all convenience functions
12296 Print a list of all convenience functions.
12297 @end table
12298
12299 @node Registers
12300 @section Registers
12301
12302 @cindex registers
12303 You can refer to machine register contents, in expressions, as variables
12304 with names starting with @samp{$}. The names of registers are different
12305 for each machine; use @code{info registers} to see the names used on
12306 your machine.
12307
12308 @table @code
12309 @kindex info registers
12310 @item info registers
12311 Print the names and values of all registers except floating-point
12312 and vector registers (in the selected stack frame).
12313
12314 @kindex info all-registers
12315 @cindex floating point registers
12316 @item info all-registers
12317 Print the names and values of all registers, including floating-point
12318 and vector registers (in the selected stack frame).
12319
12320 @item info registers @var{reggroup} @dots{}
12321 Print the name and value of the registers in each of the specified
12322 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12323 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12324
12325 @item info registers @var{regname} @dots{}
12326 Print the @dfn{relativized} value of each specified register @var{regname}.
12327 As discussed in detail below, register values are normally relative to
12328 the selected stack frame. The @var{regname} may be any register name valid on
12329 the machine you are using, with or without the initial @samp{$}.
12330 @end table
12331
12332 @anchor{standard registers}
12333 @cindex stack pointer register
12334 @cindex program counter register
12335 @cindex process status register
12336 @cindex frame pointer register
12337 @cindex standard registers
12338 @value{GDBN} has four ``standard'' register names that are available (in
12339 expressions) on most machines---whenever they do not conflict with an
12340 architecture's canonical mnemonics for registers. The register names
12341 @code{$pc} and @code{$sp} are used for the program counter register and
12342 the stack pointer. @code{$fp} is used for a register that contains a
12343 pointer to the current stack frame, and @code{$ps} is used for a
12344 register that contains the processor status. For example,
12345 you could print the program counter in hex with
12346
12347 @smallexample
12348 p/x $pc
12349 @end smallexample
12350
12351 @noindent
12352 or print the instruction to be executed next with
12353
12354 @smallexample
12355 x/i $pc
12356 @end smallexample
12357
12358 @noindent
12359 or add four to the stack pointer@footnote{This is a way of removing
12360 one word from the stack, on machines where stacks grow downward in
12361 memory (most machines, nowadays). This assumes that the innermost
12362 stack frame is selected; setting @code{$sp} is not allowed when other
12363 stack frames are selected. To pop entire frames off the stack,
12364 regardless of machine architecture, use @code{return};
12365 see @ref{Returning, ,Returning from a Function}.} with
12366
12367 @smallexample
12368 set $sp += 4
12369 @end smallexample
12370
12371 Whenever possible, these four standard register names are available on
12372 your machine even though the machine has different canonical mnemonics,
12373 so long as there is no conflict. The @code{info registers} command
12374 shows the canonical names. For example, on the SPARC, @code{info
12375 registers} displays the processor status register as @code{$psr} but you
12376 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12377 is an alias for the @sc{eflags} register.
12378
12379 @value{GDBN} always considers the contents of an ordinary register as an
12380 integer when the register is examined in this way. Some machines have
12381 special registers which can hold nothing but floating point; these
12382 registers are considered to have floating point values. There is no way
12383 to refer to the contents of an ordinary register as floating point value
12384 (although you can @emph{print} it as a floating point value with
12385 @samp{print/f $@var{regname}}).
12386
12387 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12388 means that the data format in which the register contents are saved by
12389 the operating system is not the same one that your program normally
12390 sees. For example, the registers of the 68881 floating point
12391 coprocessor are always saved in ``extended'' (raw) format, but all C
12392 programs expect to work with ``double'' (virtual) format. In such
12393 cases, @value{GDBN} normally works with the virtual format only (the format
12394 that makes sense for your program), but the @code{info registers} command
12395 prints the data in both formats.
12396
12397 @cindex SSE registers (x86)
12398 @cindex MMX registers (x86)
12399 Some machines have special registers whose contents can be interpreted
12400 in several different ways. For example, modern x86-based machines
12401 have SSE and MMX registers that can hold several values packed
12402 together in several different formats. @value{GDBN} refers to such
12403 registers in @code{struct} notation:
12404
12405 @smallexample
12406 (@value{GDBP}) print $xmm1
12407 $1 = @{
12408 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12409 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12410 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12411 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12412 v4_int32 = @{0, 20657912, 11, 13@},
12413 v2_int64 = @{88725056443645952, 55834574859@},
12414 uint128 = 0x0000000d0000000b013b36f800000000
12415 @}
12416 @end smallexample
12417
12418 @noindent
12419 To set values of such registers, you need to tell @value{GDBN} which
12420 view of the register you wish to change, as if you were assigning
12421 value to a @code{struct} member:
12422
12423 @smallexample
12424 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12425 @end smallexample
12426
12427 Normally, register values are relative to the selected stack frame
12428 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12429 value that the register would contain if all stack frames farther in
12430 were exited and their saved registers restored. In order to see the
12431 true contents of hardware registers, you must select the innermost
12432 frame (with @samp{frame 0}).
12433
12434 @cindex caller-saved registers
12435 @cindex call-clobbered registers
12436 @cindex volatile registers
12437 @cindex <not saved> values
12438 Usually ABIs reserve some registers as not needed to be saved by the
12439 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12440 registers). It may therefore not be possible for @value{GDBN} to know
12441 the value a register had before the call (in other words, in the outer
12442 frame), if the register value has since been changed by the callee.
12443 @value{GDBN} tries to deduce where the inner frame saved
12444 (``callee-saved'') registers, from the debug info, unwind info, or the
12445 machine code generated by your compiler. If some register is not
12446 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12447 its own knowledge of the ABI, or because the debug/unwind info
12448 explicitly says the register's value is undefined), @value{GDBN}
12449 displays @w{@samp{<not saved>}} as the register's value. With targets
12450 that @value{GDBN} has no knowledge of the register saving convention,
12451 if a register was not saved by the callee, then its value and location
12452 in the outer frame are assumed to be the same of the inner frame.
12453 This is usually harmless, because if the register is call-clobbered,
12454 the caller either does not care what is in the register after the
12455 call, or has code to restore the value that it does care about. Note,
12456 however, that if you change such a register in the outer frame, you
12457 may also be affecting the inner frame. Also, the more ``outer'' the
12458 frame is you're looking at, the more likely a call-clobbered
12459 register's value is to be wrong, in the sense that it doesn't actually
12460 represent the value the register had just before the call.
12461
12462 @node Floating Point Hardware
12463 @section Floating Point Hardware
12464 @cindex floating point
12465
12466 Depending on the configuration, @value{GDBN} may be able to give
12467 you more information about the status of the floating point hardware.
12468
12469 @table @code
12470 @kindex info float
12471 @item info float
12472 Display hardware-dependent information about the floating
12473 point unit. The exact contents and layout vary depending on the
12474 floating point chip. Currently, @samp{info float} is supported on
12475 the ARM and x86 machines.
12476 @end table
12477
12478 @node Vector Unit
12479 @section Vector Unit
12480 @cindex vector unit
12481
12482 Depending on the configuration, @value{GDBN} may be able to give you
12483 more information about the status of the vector unit.
12484
12485 @table @code
12486 @kindex info vector
12487 @item info vector
12488 Display information about the vector unit. The exact contents and
12489 layout vary depending on the hardware.
12490 @end table
12491
12492 @node OS Information
12493 @section Operating System Auxiliary Information
12494 @cindex OS information
12495
12496 @value{GDBN} provides interfaces to useful OS facilities that can help
12497 you debug your program.
12498
12499 @cindex auxiliary vector
12500 @cindex vector, auxiliary
12501 Some operating systems supply an @dfn{auxiliary vector} to programs at
12502 startup. This is akin to the arguments and environment that you
12503 specify for a program, but contains a system-dependent variety of
12504 binary values that tell system libraries important details about the
12505 hardware, operating system, and process. Each value's purpose is
12506 identified by an integer tag; the meanings are well-known but system-specific.
12507 Depending on the configuration and operating system facilities,
12508 @value{GDBN} may be able to show you this information. For remote
12509 targets, this functionality may further depend on the remote stub's
12510 support of the @samp{qXfer:auxv:read} packet, see
12511 @ref{qXfer auxiliary vector read}.
12512
12513 @table @code
12514 @kindex info auxv
12515 @item info auxv
12516 Display the auxiliary vector of the inferior, which can be either a
12517 live process or a core dump file. @value{GDBN} prints each tag value
12518 numerically, and also shows names and text descriptions for recognized
12519 tags. Some values in the vector are numbers, some bit masks, and some
12520 pointers to strings or other data. @value{GDBN} displays each value in the
12521 most appropriate form for a recognized tag, and in hexadecimal for
12522 an unrecognized tag.
12523 @end table
12524
12525 On some targets, @value{GDBN} can access operating system-specific
12526 information and show it to you. The types of information available
12527 will differ depending on the type of operating system running on the
12528 target. The mechanism used to fetch the data is described in
12529 @ref{Operating System Information}. For remote targets, this
12530 functionality depends on the remote stub's support of the
12531 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12532
12533 @table @code
12534 @kindex info os
12535 @item info os @var{infotype}
12536
12537 Display OS information of the requested type.
12538
12539 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12540
12541 @anchor{linux info os infotypes}
12542 @table @code
12543 @kindex info os cpus
12544 @item cpus
12545 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12546 the available fields from /proc/cpuinfo. For each supported architecture
12547 different fields are available. Two common entries are processor which gives
12548 CPU number and bogomips; a system constant that is calculated during
12549 kernel initialization.
12550
12551 @kindex info os files
12552 @item files
12553 Display the list of open file descriptors on the target. For each
12554 file descriptor, @value{GDBN} prints the identifier of the process
12555 owning the descriptor, the command of the owning process, the value
12556 of the descriptor, and the target of the descriptor.
12557
12558 @kindex info os modules
12559 @item modules
12560 Display the list of all loaded kernel modules on the target. For each
12561 module, @value{GDBN} prints the module name, the size of the module in
12562 bytes, the number of times the module is used, the dependencies of the
12563 module, the status of the module, and the address of the loaded module
12564 in memory.
12565
12566 @kindex info os msg
12567 @item msg
12568 Display the list of all System V message queues on the target. For each
12569 message queue, @value{GDBN} prints the message queue key, the message
12570 queue identifier, the access permissions, the current number of bytes
12571 on the queue, the current number of messages on the queue, the processes
12572 that last sent and received a message on the queue, the user and group
12573 of the owner and creator of the message queue, the times at which a
12574 message was last sent and received on the queue, and the time at which
12575 the message queue was last changed.
12576
12577 @kindex info os processes
12578 @item processes
12579 Display the list of processes on the target. For each process,
12580 @value{GDBN} prints the process identifier, the name of the user, the
12581 command corresponding to the process, and the list of processor cores
12582 that the process is currently running on. (To understand what these
12583 properties mean, for this and the following info types, please consult
12584 the general @sc{gnu}/Linux documentation.)
12585
12586 @kindex info os procgroups
12587 @item procgroups
12588 Display the list of process groups on the target. For each process,
12589 @value{GDBN} prints the identifier of the process group that it belongs
12590 to, the command corresponding to the process group leader, the process
12591 identifier, and the command line of the process. The list is sorted
12592 first by the process group identifier, then by the process identifier,
12593 so that processes belonging to the same process group are grouped together
12594 and the process group leader is listed first.
12595
12596 @kindex info os semaphores
12597 @item semaphores
12598 Display the list of all System V semaphore sets on the target. For each
12599 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12600 set identifier, the access permissions, the number of semaphores in the
12601 set, the user and group of the owner and creator of the semaphore set,
12602 and the times at which the semaphore set was operated upon and changed.
12603
12604 @kindex info os shm
12605 @item shm
12606 Display the list of all System V shared-memory regions on the target.
12607 For each shared-memory region, @value{GDBN} prints the region key,
12608 the shared-memory identifier, the access permissions, the size of the
12609 region, the process that created the region, the process that last
12610 attached to or detached from the region, the current number of live
12611 attaches to the region, and the times at which the region was last
12612 attached to, detach from, and changed.
12613
12614 @kindex info os sockets
12615 @item sockets
12616 Display the list of Internet-domain sockets on the target. For each
12617 socket, @value{GDBN} prints the address and port of the local and
12618 remote endpoints, the current state of the connection, the creator of
12619 the socket, the IP address family of the socket, and the type of the
12620 connection.
12621
12622 @kindex info os threads
12623 @item threads
12624 Display the list of threads running on the target. For each thread,
12625 @value{GDBN} prints the identifier of the process that the thread
12626 belongs to, the command of the process, the thread identifier, and the
12627 processor core that it is currently running on. The main thread of a
12628 process is not listed.
12629 @end table
12630
12631 @item info os
12632 If @var{infotype} is omitted, then list the possible values for
12633 @var{infotype} and the kind of OS information available for each
12634 @var{infotype}. If the target does not return a list of possible
12635 types, this command will report an error.
12636 @end table
12637
12638 @node Memory Region Attributes
12639 @section Memory Region Attributes
12640 @cindex memory region attributes
12641
12642 @dfn{Memory region attributes} allow you to describe special handling
12643 required by regions of your target's memory. @value{GDBN} uses
12644 attributes to determine whether to allow certain types of memory
12645 accesses; whether to use specific width accesses; and whether to cache
12646 target memory. By default the description of memory regions is
12647 fetched from the target (if the current target supports this), but the
12648 user can override the fetched regions.
12649
12650 Defined memory regions can be individually enabled and disabled. When a
12651 memory region is disabled, @value{GDBN} uses the default attributes when
12652 accessing memory in that region. Similarly, if no memory regions have
12653 been defined, @value{GDBN} uses the default attributes when accessing
12654 all memory.
12655
12656 When a memory region is defined, it is given a number to identify it;
12657 to enable, disable, or remove a memory region, you specify that number.
12658
12659 @table @code
12660 @kindex mem
12661 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
12662 Define a memory region bounded by @var{lower} and @var{upper} with
12663 attributes @var{attributes}@dots{}, and add it to the list of regions
12664 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
12665 case: it is treated as the target's maximum memory address.
12666 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
12667
12668 @item mem auto
12669 Discard any user changes to the memory regions and use target-supplied
12670 regions, if available, or no regions if the target does not support.
12671
12672 @kindex delete mem
12673 @item delete mem @var{nums}@dots{}
12674 Remove memory regions @var{nums}@dots{} from the list of regions
12675 monitored by @value{GDBN}.
12676
12677 @kindex disable mem
12678 @item disable mem @var{nums}@dots{}
12679 Disable monitoring of memory regions @var{nums}@dots{}.
12680 A disabled memory region is not forgotten.
12681 It may be enabled again later.
12682
12683 @kindex enable mem
12684 @item enable mem @var{nums}@dots{}
12685 Enable monitoring of memory regions @var{nums}@dots{}.
12686
12687 @kindex info mem
12688 @item info mem
12689 Print a table of all defined memory regions, with the following columns
12690 for each region:
12691
12692 @table @emph
12693 @item Memory Region Number
12694 @item Enabled or Disabled.
12695 Enabled memory regions are marked with @samp{y}.
12696 Disabled memory regions are marked with @samp{n}.
12697
12698 @item Lo Address
12699 The address defining the inclusive lower bound of the memory region.
12700
12701 @item Hi Address
12702 The address defining the exclusive upper bound of the memory region.
12703
12704 @item Attributes
12705 The list of attributes set for this memory region.
12706 @end table
12707 @end table
12708
12709
12710 @subsection Attributes
12711
12712 @subsubsection Memory Access Mode
12713 The access mode attributes set whether @value{GDBN} may make read or
12714 write accesses to a memory region.
12715
12716 While these attributes prevent @value{GDBN} from performing invalid
12717 memory accesses, they do nothing to prevent the target system, I/O DMA,
12718 etc.@: from accessing memory.
12719
12720 @table @code
12721 @item ro
12722 Memory is read only.
12723 @item wo
12724 Memory is write only.
12725 @item rw
12726 Memory is read/write. This is the default.
12727 @end table
12728
12729 @subsubsection Memory Access Size
12730 The access size attribute tells @value{GDBN} to use specific sized
12731 accesses in the memory region. Often memory mapped device registers
12732 require specific sized accesses. If no access size attribute is
12733 specified, @value{GDBN} may use accesses of any size.
12734
12735 @table @code
12736 @item 8
12737 Use 8 bit memory accesses.
12738 @item 16
12739 Use 16 bit memory accesses.
12740 @item 32
12741 Use 32 bit memory accesses.
12742 @item 64
12743 Use 64 bit memory accesses.
12744 @end table
12745
12746 @c @subsubsection Hardware/Software Breakpoints
12747 @c The hardware/software breakpoint attributes set whether @value{GDBN}
12748 @c will use hardware or software breakpoints for the internal breakpoints
12749 @c used by the step, next, finish, until, etc. commands.
12750 @c
12751 @c @table @code
12752 @c @item hwbreak
12753 @c Always use hardware breakpoints
12754 @c @item swbreak (default)
12755 @c @end table
12756
12757 @subsubsection Data Cache
12758 The data cache attributes set whether @value{GDBN} will cache target
12759 memory. While this generally improves performance by reducing debug
12760 protocol overhead, it can lead to incorrect results because @value{GDBN}
12761 does not know about volatile variables or memory mapped device
12762 registers.
12763
12764 @table @code
12765 @item cache
12766 Enable @value{GDBN} to cache target memory.
12767 @item nocache
12768 Disable @value{GDBN} from caching target memory. This is the default.
12769 @end table
12770
12771 @subsection Memory Access Checking
12772 @value{GDBN} can be instructed to refuse accesses to memory that is
12773 not explicitly described. This can be useful if accessing such
12774 regions has undesired effects for a specific target, or to provide
12775 better error checking. The following commands control this behaviour.
12776
12777 @table @code
12778 @kindex set mem inaccessible-by-default
12779 @item set mem inaccessible-by-default [on|off]
12780 If @code{on} is specified, make @value{GDBN} treat memory not
12781 explicitly described by the memory ranges as non-existent and refuse accesses
12782 to such memory. The checks are only performed if there's at least one
12783 memory range defined. If @code{off} is specified, make @value{GDBN}
12784 treat the memory not explicitly described by the memory ranges as RAM.
12785 The default value is @code{on}.
12786 @kindex show mem inaccessible-by-default
12787 @item show mem inaccessible-by-default
12788 Show the current handling of accesses to unknown memory.
12789 @end table
12790
12791
12792 @c @subsubsection Memory Write Verification
12793 @c The memory write verification attributes set whether @value{GDBN}
12794 @c will re-reads data after each write to verify the write was successful.
12795 @c
12796 @c @table @code
12797 @c @item verify
12798 @c @item noverify (default)
12799 @c @end table
12800
12801 @node Dump/Restore Files
12802 @section Copy Between Memory and a File
12803 @cindex dump/restore files
12804 @cindex append data to a file
12805 @cindex dump data to a file
12806 @cindex restore data from a file
12807
12808 You can use the commands @code{dump}, @code{append}, and
12809 @code{restore} to copy data between target memory and a file. The
12810 @code{dump} and @code{append} commands write data to a file, and the
12811 @code{restore} command reads data from a file back into the inferior's
12812 memory. Files may be in binary, Motorola S-record, Intel hex,
12813 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12814 append to binary files, and cannot read from Verilog Hex files.
12815
12816 @table @code
12817
12818 @kindex dump
12819 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12820 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12821 Dump the contents of memory from @var{start_addr} to @var{end_addr},
12822 or the value of @var{expr}, to @var{filename} in the given format.
12823
12824 The @var{format} parameter may be any one of:
12825 @table @code
12826 @item binary
12827 Raw binary form.
12828 @item ihex
12829 Intel hex format.
12830 @item srec
12831 Motorola S-record format.
12832 @item tekhex
12833 Tektronix Hex format.
12834 @item verilog
12835 Verilog Hex format.
12836 @end table
12837
12838 @value{GDBN} uses the same definitions of these formats as the
12839 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12840 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
12841 form.
12842
12843 @kindex append
12844 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12845 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12846 Append the contents of memory from @var{start_addr} to @var{end_addr},
12847 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
12848 (@value{GDBN} can only append data to files in raw binary form.)
12849
12850 @kindex restore
12851 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12852 Restore the contents of file @var{filename} into memory. The
12853 @code{restore} command can automatically recognize any known @sc{bfd}
12854 file format, except for raw binary. To restore a raw binary file you
12855 must specify the optional keyword @code{binary} after the filename.
12856
12857 If @var{bias} is non-zero, its value will be added to the addresses
12858 contained in the file. Binary files always start at address zero, so
12859 they will be restored at address @var{bias}. Other bfd files have
12860 a built-in location; they will be restored at offset @var{bias}
12861 from that location.
12862
12863 If @var{start} and/or @var{end} are non-zero, then only data between
12864 file offset @var{start} and file offset @var{end} will be restored.
12865 These offsets are relative to the addresses in the file, before
12866 the @var{bias} argument is applied.
12867
12868 @end table
12869
12870 @node Core File Generation
12871 @section How to Produce a Core File from Your Program
12872 @cindex dump core from inferior
12873
12874 A @dfn{core file} or @dfn{core dump} is a file that records the memory
12875 image of a running process and its process status (register values
12876 etc.). Its primary use is post-mortem debugging of a program that
12877 crashed while it ran outside a debugger. A program that crashes
12878 automatically produces a core file, unless this feature is disabled by
12879 the user. @xref{Files}, for information on invoking @value{GDBN} in
12880 the post-mortem debugging mode.
12881
12882 Occasionally, you may wish to produce a core file of the program you
12883 are debugging in order to preserve a snapshot of its state.
12884 @value{GDBN} has a special command for that.
12885
12886 @table @code
12887 @kindex gcore
12888 @kindex generate-core-file
12889 @item generate-core-file [@var{file}]
12890 @itemx gcore [@var{file}]
12891 Produce a core dump of the inferior process. The optional argument
12892 @var{file} specifies the file name where to put the core dump. If not
12893 specified, the file name defaults to @file{core.@var{pid}}, where
12894 @var{pid} is the inferior process ID.
12895
12896 Note that this command is implemented only for some systems (as of
12897 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
12898
12899 On @sc{gnu}/Linux, this command can take into account the value of the
12900 file @file{/proc/@var{pid}/coredump_filter} when generating the core
12901 dump (@pxref{set use-coredump-filter}), and by default honors the
12902 @code{VM_DONTDUMP} flag for mappings where it is present in the file
12903 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
12904
12905 @kindex set use-coredump-filter
12906 @anchor{set use-coredump-filter}
12907 @item set use-coredump-filter on
12908 @itemx set use-coredump-filter off
12909 Enable or disable the use of the file
12910 @file{/proc/@var{pid}/coredump_filter} when generating core dump
12911 files. This file is used by the Linux kernel to decide what types of
12912 memory mappings will be dumped or ignored when generating a core dump
12913 file. @var{pid} is the process ID of a currently running process.
12914
12915 To make use of this feature, you have to write in the
12916 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
12917 which is a bit mask representing the memory mapping types. If a bit
12918 is set in the bit mask, then the memory mappings of the corresponding
12919 types will be dumped; otherwise, they will be ignored. This
12920 configuration is inherited by child processes. For more information
12921 about the bits that can be set in the
12922 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
12923 manpage of @code{core(5)}.
12924
12925 By default, this option is @code{on}. If this option is turned
12926 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
12927 and instead uses the same default value as the Linux kernel in order
12928 to decide which pages will be dumped in the core dump file. This
12929 value is currently @code{0x33}, which means that bits @code{0}
12930 (anonymous private mappings), @code{1} (anonymous shared mappings),
12931 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
12932 This will cause these memory mappings to be dumped automatically.
12933
12934 @kindex set dump-excluded-mappings
12935 @anchor{set dump-excluded-mappings}
12936 @item set dump-excluded-mappings on
12937 @itemx set dump-excluded-mappings off
12938 If @code{on} is specified, @value{GDBN} will dump memory mappings
12939 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
12940 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
12941
12942 The default value is @code{off}.
12943 @end table
12944
12945 @node Character Sets
12946 @section Character Sets
12947 @cindex character sets
12948 @cindex charset
12949 @cindex translating between character sets
12950 @cindex host character set
12951 @cindex target character set
12952
12953 If the program you are debugging uses a different character set to
12954 represent characters and strings than the one @value{GDBN} uses itself,
12955 @value{GDBN} can automatically translate between the character sets for
12956 you. The character set @value{GDBN} uses we call the @dfn{host
12957 character set}; the one the inferior program uses we call the
12958 @dfn{target character set}.
12959
12960 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
12961 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
12962 remote protocol (@pxref{Remote Debugging}) to debug a program
12963 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
12964 then the host character set is Latin-1, and the target character set is
12965 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
12966 target-charset EBCDIC-US}, then @value{GDBN} translates between
12967 @sc{ebcdic} and Latin 1 as you print character or string values, or use
12968 character and string literals in expressions.
12969
12970 @value{GDBN} has no way to automatically recognize which character set
12971 the inferior program uses; you must tell it, using the @code{set
12972 target-charset} command, described below.
12973
12974 Here are the commands for controlling @value{GDBN}'s character set
12975 support:
12976
12977 @table @code
12978 @item set target-charset @var{charset}
12979 @kindex set target-charset
12980 Set the current target character set to @var{charset}. To display the
12981 list of supported target character sets, type
12982 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
12983
12984 @item set host-charset @var{charset}
12985 @kindex set host-charset
12986 Set the current host character set to @var{charset}.
12987
12988 By default, @value{GDBN} uses a host character set appropriate to the
12989 system it is running on; you can override that default using the
12990 @code{set host-charset} command. On some systems, @value{GDBN} cannot
12991 automatically determine the appropriate host character set. In this
12992 case, @value{GDBN} uses @samp{UTF-8}.
12993
12994 @value{GDBN} can only use certain character sets as its host character
12995 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
12996 @value{GDBN} will list the host character sets it supports.
12997
12998 @item set charset @var{charset}
12999 @kindex set charset
13000 Set the current host and target character sets to @var{charset}. As
13001 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13002 @value{GDBN} will list the names of the character sets that can be used
13003 for both host and target.
13004
13005 @item show charset
13006 @kindex show charset
13007 Show the names of the current host and target character sets.
13008
13009 @item show host-charset
13010 @kindex show host-charset
13011 Show the name of the current host character set.
13012
13013 @item show target-charset
13014 @kindex show target-charset
13015 Show the name of the current target character set.
13016
13017 @item set target-wide-charset @var{charset}
13018 @kindex set target-wide-charset
13019 Set the current target's wide character set to @var{charset}. This is
13020 the character set used by the target's @code{wchar_t} type. To
13021 display the list of supported wide character sets, type
13022 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13023
13024 @item show target-wide-charset
13025 @kindex show target-wide-charset
13026 Show the name of the current target's wide character set.
13027 @end table
13028
13029 Here is an example of @value{GDBN}'s character set support in action.
13030 Assume that the following source code has been placed in the file
13031 @file{charset-test.c}:
13032
13033 @smallexample
13034 #include <stdio.h>
13035
13036 char ascii_hello[]
13037 = @{72, 101, 108, 108, 111, 44, 32, 119,
13038 111, 114, 108, 100, 33, 10, 0@};
13039 char ibm1047_hello[]
13040 = @{200, 133, 147, 147, 150, 107, 64, 166,
13041 150, 153, 147, 132, 90, 37, 0@};
13042
13043 main ()
13044 @{
13045 printf ("Hello, world!\n");
13046 @}
13047 @end smallexample
13048
13049 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13050 containing the string @samp{Hello, world!} followed by a newline,
13051 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13052
13053 We compile the program, and invoke the debugger on it:
13054
13055 @smallexample
13056 $ gcc -g charset-test.c -o charset-test
13057 $ gdb -nw charset-test
13058 GNU gdb 2001-12-19-cvs
13059 Copyright 2001 Free Software Foundation, Inc.
13060 @dots{}
13061 (@value{GDBP})
13062 @end smallexample
13063
13064 We can use the @code{show charset} command to see what character sets
13065 @value{GDBN} is currently using to interpret and display characters and
13066 strings:
13067
13068 @smallexample
13069 (@value{GDBP}) show charset
13070 The current host and target character set is `ISO-8859-1'.
13071 (@value{GDBP})
13072 @end smallexample
13073
13074 For the sake of printing this manual, let's use @sc{ascii} as our
13075 initial character set:
13076 @smallexample
13077 (@value{GDBP}) set charset ASCII
13078 (@value{GDBP}) show charset
13079 The current host and target character set is `ASCII'.
13080 (@value{GDBP})
13081 @end smallexample
13082
13083 Let's assume that @sc{ascii} is indeed the correct character set for our
13084 host system --- in other words, let's assume that if @value{GDBN} prints
13085 characters using the @sc{ascii} character set, our terminal will display
13086 them properly. Since our current target character set is also
13087 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13088
13089 @smallexample
13090 (@value{GDBP}) print ascii_hello
13091 $1 = 0x401698 "Hello, world!\n"
13092 (@value{GDBP}) print ascii_hello[0]
13093 $2 = 72 'H'
13094 (@value{GDBP})
13095 @end smallexample
13096
13097 @value{GDBN} uses the target character set for character and string
13098 literals you use in expressions:
13099
13100 @smallexample
13101 (@value{GDBP}) print '+'
13102 $3 = 43 '+'
13103 (@value{GDBP})
13104 @end smallexample
13105
13106 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13107 character.
13108
13109 @value{GDBN} relies on the user to tell it which character set the
13110 target program uses. If we print @code{ibm1047_hello} while our target
13111 character set is still @sc{ascii}, we get jibberish:
13112
13113 @smallexample
13114 (@value{GDBP}) print ibm1047_hello
13115 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13116 (@value{GDBP}) print ibm1047_hello[0]
13117 $5 = 200 '\310'
13118 (@value{GDBP})
13119 @end smallexample
13120
13121 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13122 @value{GDBN} tells us the character sets it supports:
13123
13124 @smallexample
13125 (@value{GDBP}) set target-charset
13126 ASCII EBCDIC-US IBM1047 ISO-8859-1
13127 (@value{GDBP}) set target-charset
13128 @end smallexample
13129
13130 We can select @sc{ibm1047} as our target character set, and examine the
13131 program's strings again. Now the @sc{ascii} string is wrong, but
13132 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13133 target character set, @sc{ibm1047}, to the host character set,
13134 @sc{ascii}, and they display correctly:
13135
13136 @smallexample
13137 (@value{GDBP}) set target-charset IBM1047
13138 (@value{GDBP}) show charset
13139 The current host character set is `ASCII'.
13140 The current target character set is `IBM1047'.
13141 (@value{GDBP}) print ascii_hello
13142 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13143 (@value{GDBP}) print ascii_hello[0]
13144 $7 = 72 '\110'
13145 (@value{GDBP}) print ibm1047_hello
13146 $8 = 0x4016a8 "Hello, world!\n"
13147 (@value{GDBP}) print ibm1047_hello[0]
13148 $9 = 200 'H'
13149 (@value{GDBP})
13150 @end smallexample
13151
13152 As above, @value{GDBN} uses the target character set for character and
13153 string literals you use in expressions:
13154
13155 @smallexample
13156 (@value{GDBP}) print '+'
13157 $10 = 78 '+'
13158 (@value{GDBP})
13159 @end smallexample
13160
13161 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13162 character.
13163
13164 @node Caching Target Data
13165 @section Caching Data of Targets
13166 @cindex caching data of targets
13167
13168 @value{GDBN} caches data exchanged between the debugger and a target.
13169 Each cache is associated with the address space of the inferior.
13170 @xref{Inferiors Connections and Programs}, about inferior and address space.
13171 Such caching generally improves performance in remote debugging
13172 (@pxref{Remote Debugging}), because it reduces the overhead of the
13173 remote protocol by bundling memory reads and writes into large chunks.
13174 Unfortunately, simply caching everything would lead to incorrect results,
13175 since @value{GDBN} does not necessarily know anything about volatile
13176 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13177 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13178 is executing.
13179 Therefore, by default, @value{GDBN} only caches data
13180 known to be on the stack@footnote{In non-stop mode, it is moderately
13181 rare for a running thread to modify the stack of a stopped thread
13182 in a way that would interfere with a backtrace, and caching of
13183 stack reads provides a significant speed up of remote backtraces.} or
13184 in the code segment.
13185 Other regions of memory can be explicitly marked as
13186 cacheable; @pxref{Memory Region Attributes}.
13187
13188 @table @code
13189 @kindex set remotecache
13190 @item set remotecache on
13191 @itemx set remotecache off
13192 This option no longer does anything; it exists for compatibility
13193 with old scripts.
13194
13195 @kindex show remotecache
13196 @item show remotecache
13197 Show the current state of the obsolete remotecache flag.
13198
13199 @kindex set stack-cache
13200 @item set stack-cache on
13201 @itemx set stack-cache off
13202 Enable or disable caching of stack accesses. When @code{on}, use
13203 caching. By default, this option is @code{on}.
13204
13205 @kindex show stack-cache
13206 @item show stack-cache
13207 Show the current state of data caching for memory accesses.
13208
13209 @kindex set code-cache
13210 @item set code-cache on
13211 @itemx set code-cache off
13212 Enable or disable caching of code segment accesses. When @code{on},
13213 use caching. By default, this option is @code{on}. This improves
13214 performance of disassembly in remote debugging.
13215
13216 @kindex show code-cache
13217 @item show code-cache
13218 Show the current state of target memory cache for code segment
13219 accesses.
13220
13221 @kindex info dcache
13222 @item info dcache @r{[}line@r{]}
13223 Print the information about the performance of data cache of the
13224 current inferior's address space. The information displayed
13225 includes the dcache width and depth, and for each cache line, its
13226 number, address, and how many times it was referenced. This
13227 command is useful for debugging the data cache operation.
13228
13229 If a line number is specified, the contents of that line will be
13230 printed in hex.
13231
13232 @item set dcache size @var{size}
13233 @cindex dcache size
13234 @kindex set dcache size
13235 Set maximum number of entries in dcache (dcache depth above).
13236
13237 @item set dcache line-size @var{line-size}
13238 @cindex dcache line-size
13239 @kindex set dcache line-size
13240 Set number of bytes each dcache entry caches (dcache width above).
13241 Must be a power of 2.
13242
13243 @item show dcache size
13244 @kindex show dcache size
13245 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13246
13247 @item show dcache line-size
13248 @kindex show dcache line-size
13249 Show default size of dcache lines.
13250
13251 @end table
13252
13253 @node Searching Memory
13254 @section Search Memory
13255 @cindex searching memory
13256
13257 Memory can be searched for a particular sequence of bytes with the
13258 @code{find} command.
13259
13260 @table @code
13261 @kindex find
13262 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13263 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13264 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13265 etc. The search begins at address @var{start_addr} and continues for either
13266 @var{len} bytes or through to @var{end_addr} inclusive.
13267 @end table
13268
13269 @var{s} and @var{n} are optional parameters.
13270 They may be specified in either order, apart or together.
13271
13272 @table @r
13273 @item @var{s}, search query size
13274 The size of each search query value.
13275
13276 @table @code
13277 @item b
13278 bytes
13279 @item h
13280 halfwords (two bytes)
13281 @item w
13282 words (four bytes)
13283 @item g
13284 giant words (eight bytes)
13285 @end table
13286
13287 All values are interpreted in the current language.
13288 This means, for example, that if the current source language is C/C@t{++}
13289 then searching for the string ``hello'' includes the trailing '\0'.
13290 The null terminator can be removed from searching by using casts,
13291 e.g.: @samp{@{char[5]@}"hello"}.
13292
13293 If the value size is not specified, it is taken from the
13294 value's type in the current language.
13295 This is useful when one wants to specify the search
13296 pattern as a mixture of types.
13297 Note that this means, for example, that in the case of C-like languages
13298 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13299 which is typically four bytes.
13300
13301 @item @var{n}, maximum number of finds
13302 The maximum number of matches to print. The default is to print all finds.
13303 @end table
13304
13305 You can use strings as search values. Quote them with double-quotes
13306 (@code{"}).
13307 The string value is copied into the search pattern byte by byte,
13308 regardless of the endianness of the target and the size specification.
13309
13310 The address of each match found is printed as well as a count of the
13311 number of matches found.
13312
13313 The address of the last value found is stored in convenience variable
13314 @samp{$_}.
13315 A count of the number of matches is stored in @samp{$numfound}.
13316
13317 For example, if stopped at the @code{printf} in this function:
13318
13319 @smallexample
13320 void
13321 hello ()
13322 @{
13323 static char hello[] = "hello-hello";
13324 static struct @{ char c; short s; int i; @}
13325 __attribute__ ((packed)) mixed
13326 = @{ 'c', 0x1234, 0x87654321 @};
13327 printf ("%s\n", hello);
13328 @}
13329 @end smallexample
13330
13331 @noindent
13332 you get during debugging:
13333
13334 @smallexample
13335 (gdb) find &hello[0], +sizeof(hello), "hello"
13336 0x804956d <hello.1620+6>
13337 1 pattern found
13338 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13339 0x8049567 <hello.1620>
13340 0x804956d <hello.1620+6>
13341 2 patterns found.
13342 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13343 0x8049567 <hello.1620>
13344 0x804956d <hello.1620+6>
13345 2 patterns found.
13346 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13347 0x8049567 <hello.1620>
13348 1 pattern found
13349 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13350 0x8049560 <mixed.1625>
13351 1 pattern found
13352 (gdb) print $numfound
13353 $1 = 1
13354 (gdb) print $_
13355 $2 = (void *) 0x8049560
13356 @end smallexample
13357
13358 @node Value Sizes
13359 @section Value Sizes
13360
13361 Whenever @value{GDBN} prints a value memory will be allocated within
13362 @value{GDBN} to hold the contents of the value. It is possible in
13363 some languages with dynamic typing systems, that an invalid program
13364 may indicate a value that is incorrectly large, this in turn may cause
13365 @value{GDBN} to try and allocate an overly large amount of memory.
13366
13367 @table @code
13368 @kindex set max-value-size
13369 @item set max-value-size @var{bytes}
13370 @itemx set max-value-size unlimited
13371 Set the maximum size of memory that @value{GDBN} will allocate for the
13372 contents of a value to @var{bytes}, trying to display a value that
13373 requires more memory than that will result in an error.
13374
13375 Setting this variable does not effect values that have already been
13376 allocated within @value{GDBN}, only future allocations.
13377
13378 There's a minimum size that @code{max-value-size} can be set to in
13379 order that @value{GDBN} can still operate correctly, this minimum is
13380 currently 16 bytes.
13381
13382 The limit applies to the results of some subexpressions as well as to
13383 complete expressions. For example, an expression denoting a simple
13384 integer component, such as @code{x.y.z}, may fail if the size of
13385 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13386 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13387 @var{A} is an array variable with non-constant size, will generally
13388 succeed regardless of the bounds on @var{A}, as long as the component
13389 size is less than @var{bytes}.
13390
13391 The default value of @code{max-value-size} is currently 64k.
13392
13393 @kindex show max-value-size
13394 @item show max-value-size
13395 Show the maximum size of memory, in bytes, that @value{GDBN} will
13396 allocate for the contents of a value.
13397 @end table
13398
13399 @node Optimized Code
13400 @chapter Debugging Optimized Code
13401 @cindex optimized code, debugging
13402 @cindex debugging optimized code
13403
13404 Almost all compilers support optimization. With optimization
13405 disabled, the compiler generates assembly code that corresponds
13406 directly to your source code, in a simplistic way. As the compiler
13407 applies more powerful optimizations, the generated assembly code
13408 diverges from your original source code. With help from debugging
13409 information generated by the compiler, @value{GDBN} can map from
13410 the running program back to constructs from your original source.
13411
13412 @value{GDBN} is more accurate with optimization disabled. If you
13413 can recompile without optimization, it is easier to follow the
13414 progress of your program during debugging. But, there are many cases
13415 where you may need to debug an optimized version.
13416
13417 When you debug a program compiled with @samp{-g -O}, remember that the
13418 optimizer has rearranged your code; the debugger shows you what is
13419 really there. Do not be too surprised when the execution path does not
13420 exactly match your source file! An extreme example: if you define a
13421 variable, but never use it, @value{GDBN} never sees that
13422 variable---because the compiler optimizes it out of existence.
13423
13424 Some things do not work as well with @samp{-g -O} as with just
13425 @samp{-g}, particularly on machines with instruction scheduling. If in
13426 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13427 please report it to us as a bug (including a test case!).
13428 @xref{Variables}, for more information about debugging optimized code.
13429
13430 @menu
13431 * Inline Functions:: How @value{GDBN} presents inlining
13432 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13433 @end menu
13434
13435 @node Inline Functions
13436 @section Inline Functions
13437 @cindex inline functions, debugging
13438
13439 @dfn{Inlining} is an optimization that inserts a copy of the function
13440 body directly at each call site, instead of jumping to a shared
13441 routine. @value{GDBN} displays inlined functions just like
13442 non-inlined functions. They appear in backtraces. You can view their
13443 arguments and local variables, step into them with @code{step}, skip
13444 them with @code{next}, and escape from them with @code{finish}.
13445 You can check whether a function was inlined by using the
13446 @code{info frame} command.
13447
13448 For @value{GDBN} to support inlined functions, the compiler must
13449 record information about inlining in the debug information ---
13450 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13451 other compilers do also. @value{GDBN} only supports inlined functions
13452 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13453 do not emit two required attributes (@samp{DW_AT_call_file} and
13454 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13455 function calls with earlier versions of @value{NGCC}. It instead
13456 displays the arguments and local variables of inlined functions as
13457 local variables in the caller.
13458
13459 The body of an inlined function is directly included at its call site;
13460 unlike a non-inlined function, there are no instructions devoted to
13461 the call. @value{GDBN} still pretends that the call site and the
13462 start of the inlined function are different instructions. Stepping to
13463 the call site shows the call site, and then stepping again shows
13464 the first line of the inlined function, even though no additional
13465 instructions are executed.
13466
13467 This makes source-level debugging much clearer; you can see both the
13468 context of the call and then the effect of the call. Only stepping by
13469 a single instruction using @code{stepi} or @code{nexti} does not do
13470 this; single instruction steps always show the inlined body.
13471
13472 There are some ways that @value{GDBN} does not pretend that inlined
13473 function calls are the same as normal calls:
13474
13475 @itemize @bullet
13476 @item
13477 Setting breakpoints at the call site of an inlined function may not
13478 work, because the call site does not contain any code. @value{GDBN}
13479 may incorrectly move the breakpoint to the next line of the enclosing
13480 function, after the call. This limitation will be removed in a future
13481 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13482 or inside the inlined function instead.
13483
13484 @item
13485 @value{GDBN} cannot locate the return value of inlined calls after
13486 using the @code{finish} command. This is a limitation of compiler-generated
13487 debugging information; after @code{finish}, you can step to the next line
13488 and print a variable where your program stored the return value.
13489
13490 @end itemize
13491
13492 @node Tail Call Frames
13493 @section Tail Call Frames
13494 @cindex tail call frames, debugging
13495
13496 Function @code{B} can call function @code{C} in its very last statement. In
13497 unoptimized compilation the call of @code{C} is immediately followed by return
13498 instruction at the end of @code{B} code. Optimizing compiler may replace the
13499 call and return in function @code{B} into one jump to function @code{C}
13500 instead. Such use of a jump instruction is called @dfn{tail call}.
13501
13502 During execution of function @code{C}, there will be no indication in the
13503 function call stack frames that it was tail-called from @code{B}. If function
13504 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13505 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13506 some cases @value{GDBN} can determine that @code{C} was tail-called from
13507 @code{B}, and it will then create fictitious call frame for that, with the
13508 return address set up as if @code{B} called @code{C} normally.
13509
13510 This functionality is currently supported only by DWARF 2 debugging format and
13511 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13512 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13513 this information.
13514
13515 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13516 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13517
13518 @smallexample
13519 (gdb) x/i $pc - 2
13520 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13521 (gdb) info frame
13522 Stack level 1, frame at 0x7fffffffda30:
13523 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13524 tail call frame, caller of frame at 0x7fffffffda30
13525 source language c++.
13526 Arglist at unknown address.
13527 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13528 @end smallexample
13529
13530 The detection of all the possible code path executions can find them ambiguous.
13531 There is no execution history stored (possible @ref{Reverse Execution} is never
13532 used for this purpose) and the last known caller could have reached the known
13533 callee by multiple different jump sequences. In such case @value{GDBN} still
13534 tries to show at least all the unambiguous top tail callers and all the
13535 unambiguous bottom tail calees, if any.
13536
13537 @table @code
13538 @anchor{set debug entry-values}
13539 @item set debug entry-values
13540 @kindex set debug entry-values
13541 When set to on, enables printing of analysis messages for both frame argument
13542 values at function entry and tail calls. It will show all the possible valid
13543 tail calls code paths it has considered. It will also print the intersection
13544 of them with the final unambiguous (possibly partial or even empty) code path
13545 result.
13546
13547 @item show debug entry-values
13548 @kindex show debug entry-values
13549 Show the current state of analysis messages printing for both frame argument
13550 values at function entry and tail calls.
13551 @end table
13552
13553 The analysis messages for tail calls can for example show why the virtual tail
13554 call frame for function @code{c} has not been recognized (due to the indirect
13555 reference by variable @code{x}):
13556
13557 @smallexample
13558 static void __attribute__((noinline, noclone)) c (void);
13559 void (*x) (void) = c;
13560 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13561 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13562 int main (void) @{ x (); return 0; @}
13563
13564 Breakpoint 1, DW_OP_entry_value resolving cannot find
13565 DW_TAG_call_site 0x40039a in main
13566 a () at t.c:3
13567 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13568 (gdb) bt
13569 #0 a () at t.c:3
13570 #1 0x000000000040039a in main () at t.c:5
13571 @end smallexample
13572
13573 Another possibility is an ambiguous virtual tail call frames resolution:
13574
13575 @smallexample
13576 int i;
13577 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13578 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13579 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13580 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13581 static void __attribute__((noinline, noclone)) b (void)
13582 @{ if (i) c (); else e (); @}
13583 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13584 int main (void) @{ a (); return 0; @}
13585
13586 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13587 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13588 tailcall: reduced: 0x4004d2(a) |
13589 (gdb) bt
13590 #0 f () at t.c:2
13591 #1 0x00000000004004d2 in a () at t.c:8
13592 #2 0x0000000000400395 in main () at t.c:9
13593 @end smallexample
13594
13595 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13596 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13597
13598 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13599 @ifset HAVE_MAKEINFO_CLICK
13600 @set ARROW @click{}
13601 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13602 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13603 @end ifset
13604 @ifclear HAVE_MAKEINFO_CLICK
13605 @set ARROW ->
13606 @set CALLSEQ1B @value{CALLSEQ1A}
13607 @set CALLSEQ2B @value{CALLSEQ2A}
13608 @end ifclear
13609
13610 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13611 The code can have possible execution paths @value{CALLSEQ1B} or
13612 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13613
13614 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13615 has found. It then finds another possible calling sequence - that one is
13616 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13617 printed as the @code{reduced:} calling sequence. That one could have many
13618 further @code{compare:} and @code{reduced:} statements as long as there remain
13619 any non-ambiguous sequence entries.
13620
13621 For the frame of function @code{b} in both cases there are different possible
13622 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
13623 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
13624 therefore this one is displayed to the user while the ambiguous frames are
13625 omitted.
13626
13627 There can be also reasons why printing of frame argument values at function
13628 entry may fail:
13629
13630 @smallexample
13631 int v;
13632 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13633 static void __attribute__((noinline, noclone)) a (int i);
13634 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13635 static void __attribute__((noinline, noclone)) a (int i)
13636 @{ if (i) b (i - 1); else c (0); @}
13637 int main (void) @{ a (5); return 0; @}
13638
13639 (gdb) bt
13640 #0 c (i=i@@entry=0) at t.c:2
13641 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
13642 function "a" at 0x400420 can call itself via tail calls
13643 i=<optimized out>) at t.c:6
13644 #2 0x000000000040036e in main () at t.c:7
13645 @end smallexample
13646
13647 @value{GDBN} cannot find out from the inferior state if and how many times did
13648 function @code{a} call itself (via function @code{b}) as these calls would be
13649 tail calls. Such tail calls would modify the @code{i} variable, therefore
13650 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13651 prints @code{<optimized out>} instead.
13652
13653 @node Macros
13654 @chapter C Preprocessor Macros
13655
13656 Some languages, such as C and C@t{++}, provide a way to define and invoke
13657 ``preprocessor macros'' which expand into strings of tokens.
13658 @value{GDBN} can evaluate expressions containing macro invocations, show
13659 the result of macro expansion, and show a macro's definition, including
13660 where it was defined.
13661
13662 You may need to compile your program specially to provide @value{GDBN}
13663 with information about preprocessor macros. Most compilers do not
13664 include macros in their debugging information, even when you compile
13665 with the @option{-g} flag. @xref{Compilation}.
13666
13667 A program may define a macro at one point, remove that definition later,
13668 and then provide a different definition after that. Thus, at different
13669 points in the program, a macro may have different definitions, or have
13670 no definition at all. If there is a current stack frame, @value{GDBN}
13671 uses the macros in scope at that frame's source code line. Otherwise,
13672 @value{GDBN} uses the macros in scope at the current listing location;
13673 see @ref{List}.
13674
13675 Whenever @value{GDBN} evaluates an expression, it always expands any
13676 macro invocations present in the expression. @value{GDBN} also provides
13677 the following commands for working with macros explicitly.
13678
13679 @table @code
13680
13681 @kindex macro expand
13682 @cindex macro expansion, showing the results of preprocessor
13683 @cindex preprocessor macro expansion, showing the results of
13684 @cindex expanding preprocessor macros
13685 @item macro expand @var{expression}
13686 @itemx macro exp @var{expression}
13687 Show the results of expanding all preprocessor macro invocations in
13688 @var{expression}. Since @value{GDBN} simply expands macros, but does
13689 not parse the result, @var{expression} need not be a valid expression;
13690 it can be any string of tokens.
13691
13692 @kindex macro exp1
13693 @item macro expand-once @var{expression}
13694 @itemx macro exp1 @var{expression}
13695 @cindex expand macro once
13696 @i{(This command is not yet implemented.)} Show the results of
13697 expanding those preprocessor macro invocations that appear explicitly in
13698 @var{expression}. Macro invocations appearing in that expansion are
13699 left unchanged. This command allows you to see the effect of a
13700 particular macro more clearly, without being confused by further
13701 expansions. Since @value{GDBN} simply expands macros, but does not
13702 parse the result, @var{expression} need not be a valid expression; it
13703 can be any string of tokens.
13704
13705 @kindex info macro
13706 @cindex macro definition, showing
13707 @cindex definition of a macro, showing
13708 @cindex macros, from debug info
13709 @item info macro [-a|-all] [--] @var{macro}
13710 Show the current definition or all definitions of the named @var{macro},
13711 and describe the source location or compiler command-line where that
13712 definition was established. The optional double dash is to signify the end of
13713 argument processing and the beginning of @var{macro} for non C-like macros where
13714 the macro may begin with a hyphen.
13715
13716 @kindex info macros
13717 @item info macros @var{location}
13718 Show all macro definitions that are in effect at the location specified
13719 by @var{location}, and describe the source location or compiler
13720 command-line where those definitions were established.
13721
13722 @kindex macro define
13723 @cindex user-defined macros
13724 @cindex defining macros interactively
13725 @cindex macros, user-defined
13726 @item macro define @var{macro} @var{replacement-list}
13727 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
13728 Introduce a definition for a preprocessor macro named @var{macro},
13729 invocations of which are replaced by the tokens given in
13730 @var{replacement-list}. The first form of this command defines an
13731 ``object-like'' macro, which takes no arguments; the second form
13732 defines a ``function-like'' macro, which takes the arguments given in
13733 @var{arglist}.
13734
13735 A definition introduced by this command is in scope in every
13736 expression evaluated in @value{GDBN}, until it is removed with the
13737 @code{macro undef} command, described below. The definition overrides
13738 all definitions for @var{macro} present in the program being debugged,
13739 as well as any previous user-supplied definition.
13740
13741 @kindex macro undef
13742 @item macro undef @var{macro}
13743 Remove any user-supplied definition for the macro named @var{macro}.
13744 This command only affects definitions provided with the @code{macro
13745 define} command, described above; it cannot remove definitions present
13746 in the program being debugged.
13747
13748 @kindex macro list
13749 @item macro list
13750 List all the macros defined using the @code{macro define} command.
13751 @end table
13752
13753 @cindex macros, example of debugging with
13754 Here is a transcript showing the above commands in action. First, we
13755 show our source files:
13756
13757 @smallexample
13758 $ cat sample.c
13759 #include <stdio.h>
13760 #include "sample.h"
13761
13762 #define M 42
13763 #define ADD(x) (M + x)
13764
13765 main ()
13766 @{
13767 #define N 28
13768 printf ("Hello, world!\n");
13769 #undef N
13770 printf ("We're so creative.\n");
13771 #define N 1729
13772 printf ("Goodbye, world!\n");
13773 @}
13774 $ cat sample.h
13775 #define Q <
13776 $
13777 @end smallexample
13778
13779 Now, we compile the program using the @sc{gnu} C compiler,
13780 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13781 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13782 and @option{-gdwarf-4}; we recommend always choosing the most recent
13783 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13784 includes information about preprocessor macros in the debugging
13785 information.
13786
13787 @smallexample
13788 $ gcc -gdwarf-2 -g3 sample.c -o sample
13789 $
13790 @end smallexample
13791
13792 Now, we start @value{GDBN} on our sample program:
13793
13794 @smallexample
13795 $ gdb -nw sample
13796 GNU gdb 2002-05-06-cvs
13797 Copyright 2002 Free Software Foundation, Inc.
13798 GDB is free software, @dots{}
13799 (@value{GDBP})
13800 @end smallexample
13801
13802 We can expand macros and examine their definitions, even when the
13803 program is not running. @value{GDBN} uses the current listing position
13804 to decide which macro definitions are in scope:
13805
13806 @smallexample
13807 (@value{GDBP}) list main
13808 3
13809 4 #define M 42
13810 5 #define ADD(x) (M + x)
13811 6
13812 7 main ()
13813 8 @{
13814 9 #define N 28
13815 10 printf ("Hello, world!\n");
13816 11 #undef N
13817 12 printf ("We're so creative.\n");
13818 (@value{GDBP}) info macro ADD
13819 Defined at /home/jimb/gdb/macros/play/sample.c:5
13820 #define ADD(x) (M + x)
13821 (@value{GDBP}) info macro Q
13822 Defined at /home/jimb/gdb/macros/play/sample.h:1
13823 included at /home/jimb/gdb/macros/play/sample.c:2
13824 #define Q <
13825 (@value{GDBP}) macro expand ADD(1)
13826 expands to: (42 + 1)
13827 (@value{GDBP}) macro expand-once ADD(1)
13828 expands to: once (M + 1)
13829 (@value{GDBP})
13830 @end smallexample
13831
13832 In the example above, note that @code{macro expand-once} expands only
13833 the macro invocation explicit in the original text --- the invocation of
13834 @code{ADD} --- but does not expand the invocation of the macro @code{M},
13835 which was introduced by @code{ADD}.
13836
13837 Once the program is running, @value{GDBN} uses the macro definitions in
13838 force at the source line of the current stack frame:
13839
13840 @smallexample
13841 (@value{GDBP}) break main
13842 Breakpoint 1 at 0x8048370: file sample.c, line 10.
13843 (@value{GDBP}) run
13844 Starting program: /home/jimb/gdb/macros/play/sample
13845
13846 Breakpoint 1, main () at sample.c:10
13847 10 printf ("Hello, world!\n");
13848 (@value{GDBP})
13849 @end smallexample
13850
13851 At line 10, the definition of the macro @code{N} at line 9 is in force:
13852
13853 @smallexample
13854 (@value{GDBP}) info macro N
13855 Defined at /home/jimb/gdb/macros/play/sample.c:9
13856 #define N 28
13857 (@value{GDBP}) macro expand N Q M
13858 expands to: 28 < 42
13859 (@value{GDBP}) print N Q M
13860 $1 = 1
13861 (@value{GDBP})
13862 @end smallexample
13863
13864 As we step over directives that remove @code{N}'s definition, and then
13865 give it a new definition, @value{GDBN} finds the definition (or lack
13866 thereof) in force at each point:
13867
13868 @smallexample
13869 (@value{GDBP}) next
13870 Hello, world!
13871 12 printf ("We're so creative.\n");
13872 (@value{GDBP}) info macro N
13873 The symbol `N' has no definition as a C/C++ preprocessor macro
13874 at /home/jimb/gdb/macros/play/sample.c:12
13875 (@value{GDBP}) next
13876 We're so creative.
13877 14 printf ("Goodbye, world!\n");
13878 (@value{GDBP}) info macro N
13879 Defined at /home/jimb/gdb/macros/play/sample.c:13
13880 #define N 1729
13881 (@value{GDBP}) macro expand N Q M
13882 expands to: 1729 < 42
13883 (@value{GDBP}) print N Q M
13884 $2 = 0
13885 (@value{GDBP})
13886 @end smallexample
13887
13888 In addition to source files, macros can be defined on the compilation command
13889 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
13890 such a way, @value{GDBN} displays the location of their definition as line zero
13891 of the source file submitted to the compiler.
13892
13893 @smallexample
13894 (@value{GDBP}) info macro __STDC__
13895 Defined at /home/jimb/gdb/macros/play/sample.c:0
13896 -D__STDC__=1
13897 (@value{GDBP})
13898 @end smallexample
13899
13900
13901 @node Tracepoints
13902 @chapter Tracepoints
13903 @c This chapter is based on the documentation written by Michael
13904 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
13905
13906 @cindex tracepoints
13907 In some applications, it is not feasible for the debugger to interrupt
13908 the program's execution long enough for the developer to learn
13909 anything helpful about its behavior. If the program's correctness
13910 depends on its real-time behavior, delays introduced by a debugger
13911 might cause the program to change its behavior drastically, or perhaps
13912 fail, even when the code itself is correct. It is useful to be able
13913 to observe the program's behavior without interrupting it.
13914
13915 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
13916 specify locations in the program, called @dfn{tracepoints}, and
13917 arbitrary expressions to evaluate when those tracepoints are reached.
13918 Later, using the @code{tfind} command, you can examine the values
13919 those expressions had when the program hit the tracepoints. The
13920 expressions may also denote objects in memory---structures or arrays,
13921 for example---whose values @value{GDBN} should record; while visiting
13922 a particular tracepoint, you may inspect those objects as if they were
13923 in memory at that moment. However, because @value{GDBN} records these
13924 values without interacting with you, it can do so quickly and
13925 unobtrusively, hopefully not disturbing the program's behavior.
13926
13927 The tracepoint facility is currently available only for remote
13928 targets. @xref{Targets}. In addition, your remote target must know
13929 how to collect trace data. This functionality is implemented in the
13930 remote stub; however, none of the stubs distributed with @value{GDBN}
13931 support tracepoints as of this writing. The format of the remote
13932 packets used to implement tracepoints are described in @ref{Tracepoint
13933 Packets}.
13934
13935 It is also possible to get trace data from a file, in a manner reminiscent
13936 of corefiles; you specify the filename, and use @code{tfind} to search
13937 through the file. @xref{Trace Files}, for more details.
13938
13939 This chapter describes the tracepoint commands and features.
13940
13941 @menu
13942 * Set Tracepoints::
13943 * Analyze Collected Data::
13944 * Tracepoint Variables::
13945 * Trace Files::
13946 @end menu
13947
13948 @node Set Tracepoints
13949 @section Commands to Set Tracepoints
13950
13951 Before running such a @dfn{trace experiment}, an arbitrary number of
13952 tracepoints can be set. A tracepoint is actually a special type of
13953 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
13954 standard breakpoint commands. For instance, as with breakpoints,
13955 tracepoint numbers are successive integers starting from one, and many
13956 of the commands associated with tracepoints take the tracepoint number
13957 as their argument, to identify which tracepoint to work on.
13958
13959 For each tracepoint, you can specify, in advance, some arbitrary set
13960 of data that you want the target to collect in the trace buffer when
13961 it hits that tracepoint. The collected data can include registers,
13962 local variables, or global data. Later, you can use @value{GDBN}
13963 commands to examine the values these data had at the time the
13964 tracepoint was hit.
13965
13966 Tracepoints do not support every breakpoint feature. Ignore counts on
13967 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
13968 commands when they are hit. Tracepoints may not be thread-specific
13969 either.
13970
13971 @cindex fast tracepoints
13972 Some targets may support @dfn{fast tracepoints}, which are inserted in
13973 a different way (such as with a jump instead of a trap), that is
13974 faster but possibly restricted in where they may be installed.
13975
13976 @cindex static tracepoints
13977 @cindex markers, static tracepoints
13978 @cindex probing markers, static tracepoints
13979 Regular and fast tracepoints are dynamic tracing facilities, meaning
13980 that they can be used to insert tracepoints at (almost) any location
13981 in the target. Some targets may also support controlling @dfn{static
13982 tracepoints} from @value{GDBN}. With static tracing, a set of
13983 instrumentation points, also known as @dfn{markers}, are embedded in
13984 the target program, and can be activated or deactivated by name or
13985 address. These are usually placed at locations which facilitate
13986 investigating what the target is actually doing. @value{GDBN}'s
13987 support for static tracing includes being able to list instrumentation
13988 points, and attach them with @value{GDBN} defined high level
13989 tracepoints that expose the whole range of convenience of
13990 @value{GDBN}'s tracepoints support. Namely, support for collecting
13991 registers values and values of global or local (to the instrumentation
13992 point) variables; tracepoint conditions and trace state variables.
13993 The act of installing a @value{GDBN} static tracepoint on an
13994 instrumentation point, or marker, is referred to as @dfn{probing} a
13995 static tracepoint marker.
13996
13997 @code{gdbserver} supports tracepoints on some target systems.
13998 @xref{Server,,Tracepoints support in @code{gdbserver}}.
13999
14000 This section describes commands to set tracepoints and associated
14001 conditions and actions.
14002
14003 @menu
14004 * Create and Delete Tracepoints::
14005 * Enable and Disable Tracepoints::
14006 * Tracepoint Passcounts::
14007 * Tracepoint Conditions::
14008 * Trace State Variables::
14009 * Tracepoint Actions::
14010 * Listing Tracepoints::
14011 * Listing Static Tracepoint Markers::
14012 * Starting and Stopping Trace Experiments::
14013 * Tracepoint Restrictions::
14014 @end menu
14015
14016 @node Create and Delete Tracepoints
14017 @subsection Create and Delete Tracepoints
14018
14019 @table @code
14020 @cindex set tracepoint
14021 @kindex trace
14022 @item trace @var{location}
14023 The @code{trace} command is very similar to the @code{break} command.
14024 Its argument @var{location} can be any valid location.
14025 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14026 which is a point in the target program where the debugger will briefly stop,
14027 collect some data, and then allow the program to continue. Setting a tracepoint
14028 or changing its actions takes effect immediately if the remote stub
14029 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14030 in tracing}).
14031 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14032 these changes don't take effect until the next @code{tstart}
14033 command, and once a trace experiment is running, further changes will
14034 not have any effect until the next trace experiment starts. In addition,
14035 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14036 address is not yet resolved. (This is similar to pending breakpoints.)
14037 Pending tracepoints are not downloaded to the target and not installed
14038 until they are resolved. The resolution of pending tracepoints requires
14039 @value{GDBN} support---when debugging with the remote target, and
14040 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14041 tracing}), pending tracepoints can not be resolved (and downloaded to
14042 the remote stub) while @value{GDBN} is disconnected.
14043
14044 Here are some examples of using the @code{trace} command:
14045
14046 @smallexample
14047 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14048
14049 (@value{GDBP}) @b{trace +2} // 2 lines forward
14050
14051 (@value{GDBP}) @b{trace my_function} // first source line of function
14052
14053 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14054
14055 (@value{GDBP}) @b{trace *0x2117c4} // an address
14056 @end smallexample
14057
14058 @noindent
14059 You can abbreviate @code{trace} as @code{tr}.
14060
14061 @item trace @var{location} if @var{cond}
14062 Set a tracepoint with condition @var{cond}; evaluate the expression
14063 @var{cond} each time the tracepoint is reached, and collect data only
14064 if the value is nonzero---that is, if @var{cond} evaluates as true.
14065 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14066 information on tracepoint conditions.
14067
14068 @item ftrace @var{location} [ if @var{cond} ]
14069 @cindex set fast tracepoint
14070 @cindex fast tracepoints, setting
14071 @kindex ftrace
14072 The @code{ftrace} command sets a fast tracepoint. For targets that
14073 support them, fast tracepoints will use a more efficient but possibly
14074 less general technique to trigger data collection, such as a jump
14075 instruction instead of a trap, or some sort of hardware support. It
14076 may not be possible to create a fast tracepoint at the desired
14077 location, in which case the command will exit with an explanatory
14078 message.
14079
14080 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14081 @code{trace}.
14082
14083 On 32-bit x86-architecture systems, fast tracepoints normally need to
14084 be placed at an instruction that is 5 bytes or longer, but can be
14085 placed at 4-byte instructions if the low 64K of memory of the target
14086 program is available to install trampolines. Some Unix-type systems,
14087 such as @sc{gnu}/Linux, exclude low addresses from the program's
14088 address space; but for instance with the Linux kernel it is possible
14089 to let @value{GDBN} use this area by doing a @command{sysctl} command
14090 to set the @code{mmap_min_addr} kernel parameter, as in
14091
14092 @example
14093 sudo sysctl -w vm.mmap_min_addr=32768
14094 @end example
14095
14096 @noindent
14097 which sets the low address to 32K, which leaves plenty of room for
14098 trampolines. The minimum address should be set to a page boundary.
14099
14100 @item strace @var{location} [ if @var{cond} ]
14101 @cindex set static tracepoint
14102 @cindex static tracepoints, setting
14103 @cindex probe static tracepoint marker
14104 @kindex strace
14105 The @code{strace} command sets a static tracepoint. For targets that
14106 support it, setting a static tracepoint probes a static
14107 instrumentation point, or marker, found at @var{location}. It may not
14108 be possible to set a static tracepoint at the desired location, in
14109 which case the command will exit with an explanatory message.
14110
14111 @value{GDBN} handles arguments to @code{strace} exactly as for
14112 @code{trace}, with the addition that the user can also specify
14113 @code{-m @var{marker}} as @var{location}. This probes the marker
14114 identified by the @var{marker} string identifier. This identifier
14115 depends on the static tracepoint backend library your program is
14116 using. You can find all the marker identifiers in the @samp{ID} field
14117 of the @code{info static-tracepoint-markers} command output.
14118 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14119 Markers}. For example, in the following small program using the UST
14120 tracing engine:
14121
14122 @smallexample
14123 main ()
14124 @{
14125 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14126 @}
14127 @end smallexample
14128
14129 @noindent
14130 the marker id is composed of joining the first two arguments to the
14131 @code{trace_mark} call with a slash, which translates to:
14132
14133 @smallexample
14134 (@value{GDBP}) info static-tracepoint-markers
14135 Cnt Enb ID Address What
14136 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14137 Data: "str %s"
14138 [etc...]
14139 @end smallexample
14140
14141 @noindent
14142 so you may probe the marker above with:
14143
14144 @smallexample
14145 (@value{GDBP}) strace -m ust/bar33
14146 @end smallexample
14147
14148 Static tracepoints accept an extra collect action --- @code{collect
14149 $_sdata}. This collects arbitrary user data passed in the probe point
14150 call to the tracing library. In the UST example above, you'll see
14151 that the third argument to @code{trace_mark} is a printf-like format
14152 string. The user data is then the result of running that formatting
14153 string against the following arguments. Note that @code{info
14154 static-tracepoint-markers} command output lists that format string in
14155 the @samp{Data:} field.
14156
14157 You can inspect this data when analyzing the trace buffer, by printing
14158 the $_sdata variable like any other variable available to
14159 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14160
14161 @vindex $tpnum
14162 @cindex last tracepoint number
14163 @cindex recent tracepoint number
14164 @cindex tracepoint number
14165 The convenience variable @code{$tpnum} records the tracepoint number
14166 of the most recently set tracepoint.
14167
14168 @kindex delete tracepoint
14169 @cindex tracepoint deletion
14170 @item delete tracepoint @r{[}@var{num}@r{]}
14171 Permanently delete one or more tracepoints. With no argument, the
14172 default is to delete all tracepoints. Note that the regular
14173 @code{delete} command can remove tracepoints also.
14174
14175 Examples:
14176
14177 @smallexample
14178 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14179
14180 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14181 @end smallexample
14182
14183 @noindent
14184 You can abbreviate this command as @code{del tr}.
14185 @end table
14186
14187 @node Enable and Disable Tracepoints
14188 @subsection Enable and Disable Tracepoints
14189
14190 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14191
14192 @table @code
14193 @kindex disable tracepoint
14194 @item disable tracepoint @r{[}@var{num}@r{]}
14195 Disable tracepoint @var{num}, or all tracepoints if no argument
14196 @var{num} is given. A disabled tracepoint will have no effect during
14197 a trace experiment, but it is not forgotten. You can re-enable
14198 a disabled tracepoint using the @code{enable tracepoint} command.
14199 If the command is issued during a trace experiment and the debug target
14200 has support for disabling tracepoints during a trace experiment, then the
14201 change will be effective immediately. Otherwise, it will be applied to the
14202 next trace experiment.
14203
14204 @kindex enable tracepoint
14205 @item enable tracepoint @r{[}@var{num}@r{]}
14206 Enable tracepoint @var{num}, or all tracepoints. If this command is
14207 issued during a trace experiment and the debug target supports enabling
14208 tracepoints during a trace experiment, then the enabled tracepoints will
14209 become effective immediately. Otherwise, they will become effective the
14210 next time a trace experiment is run.
14211 @end table
14212
14213 @node Tracepoint Passcounts
14214 @subsection Tracepoint Passcounts
14215
14216 @table @code
14217 @kindex passcount
14218 @cindex tracepoint pass count
14219 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14220 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14221 automatically stop a trace experiment. If a tracepoint's passcount is
14222 @var{n}, then the trace experiment will be automatically stopped on
14223 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14224 @var{num} is not specified, the @code{passcount} command sets the
14225 passcount of the most recently defined tracepoint. If no passcount is
14226 given, the trace experiment will run until stopped explicitly by the
14227 user.
14228
14229 Examples:
14230
14231 @smallexample
14232 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14233 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14234
14235 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14236 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14237 (@value{GDBP}) @b{trace foo}
14238 (@value{GDBP}) @b{pass 3}
14239 (@value{GDBP}) @b{trace bar}
14240 (@value{GDBP}) @b{pass 2}
14241 (@value{GDBP}) @b{trace baz}
14242 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14243 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14244 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14245 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14246 @end smallexample
14247 @end table
14248
14249 @node Tracepoint Conditions
14250 @subsection Tracepoint Conditions
14251 @cindex conditional tracepoints
14252 @cindex tracepoint conditions
14253
14254 The simplest sort of tracepoint collects data every time your program
14255 reaches a specified place. You can also specify a @dfn{condition} for
14256 a tracepoint. A condition is just a Boolean expression in your
14257 programming language (@pxref{Expressions, ,Expressions}). A
14258 tracepoint with a condition evaluates the expression each time your
14259 program reaches it, and data collection happens only if the condition
14260 is true.
14261
14262 Tracepoint conditions can be specified when a tracepoint is set, by
14263 using @samp{if} in the arguments to the @code{trace} command.
14264 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14265 also be set or changed at any time with the @code{condition} command,
14266 just as with breakpoints.
14267
14268 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14269 the conditional expression itself. Instead, @value{GDBN} encodes the
14270 expression into an agent expression (@pxref{Agent Expressions})
14271 suitable for execution on the target, independently of @value{GDBN}.
14272 Global variables become raw memory locations, locals become stack
14273 accesses, and so forth.
14274
14275 For instance, suppose you have a function that is usually called
14276 frequently, but should not be called after an error has occurred. You
14277 could use the following tracepoint command to collect data about calls
14278 of that function that happen while the error code is propagating
14279 through the program; an unconditional tracepoint could end up
14280 collecting thousands of useless trace frames that you would have to
14281 search through.
14282
14283 @smallexample
14284 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14285 @end smallexample
14286
14287 @node Trace State Variables
14288 @subsection Trace State Variables
14289 @cindex trace state variables
14290
14291 A @dfn{trace state variable} is a special type of variable that is
14292 created and managed by target-side code. The syntax is the same as
14293 that for GDB's convenience variables (a string prefixed with ``$''),
14294 but they are stored on the target. They must be created explicitly,
14295 using a @code{tvariable} command. They are always 64-bit signed
14296 integers.
14297
14298 Trace state variables are remembered by @value{GDBN}, and downloaded
14299 to the target along with tracepoint information when the trace
14300 experiment starts. There are no intrinsic limits on the number of
14301 trace state variables, beyond memory limitations of the target.
14302
14303 @cindex convenience variables, and trace state variables
14304 Although trace state variables are managed by the target, you can use
14305 them in print commands and expressions as if they were convenience
14306 variables; @value{GDBN} will get the current value from the target
14307 while the trace experiment is running. Trace state variables share
14308 the same namespace as other ``$'' variables, which means that you
14309 cannot have trace state variables with names like @code{$23} or
14310 @code{$pc}, nor can you have a trace state variable and a convenience
14311 variable with the same name.
14312
14313 @table @code
14314
14315 @item tvariable $@var{name} [ = @var{expression} ]
14316 @kindex tvariable
14317 The @code{tvariable} command creates a new trace state variable named
14318 @code{$@var{name}}, and optionally gives it an initial value of
14319 @var{expression}. The @var{expression} is evaluated when this command is
14320 entered; the result will be converted to an integer if possible,
14321 otherwise @value{GDBN} will report an error. A subsequent
14322 @code{tvariable} command specifying the same name does not create a
14323 variable, but instead assigns the supplied initial value to the
14324 existing variable of that name, overwriting any previous initial
14325 value. The default initial value is 0.
14326
14327 @item info tvariables
14328 @kindex info tvariables
14329 List all the trace state variables along with their initial values.
14330 Their current values may also be displayed, if the trace experiment is
14331 currently running.
14332
14333 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14334 @kindex delete tvariable
14335 Delete the given trace state variables, or all of them if no arguments
14336 are specified.
14337
14338 @end table
14339
14340 @node Tracepoint Actions
14341 @subsection Tracepoint Action Lists
14342
14343 @table @code
14344 @kindex actions
14345 @cindex tracepoint actions
14346 @item actions @r{[}@var{num}@r{]}
14347 This command will prompt for a list of actions to be taken when the
14348 tracepoint is hit. If the tracepoint number @var{num} is not
14349 specified, this command sets the actions for the one that was most
14350 recently defined (so that you can define a tracepoint and then say
14351 @code{actions} without bothering about its number). You specify the
14352 actions themselves on the following lines, one action at a time, and
14353 terminate the actions list with a line containing just @code{end}. So
14354 far, the only defined actions are @code{collect}, @code{teval}, and
14355 @code{while-stepping}.
14356
14357 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14358 Commands, ,Breakpoint Command Lists}), except that only the defined
14359 actions are allowed; any other @value{GDBN} command is rejected.
14360
14361 @cindex remove actions from a tracepoint
14362 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14363 and follow it immediately with @samp{end}.
14364
14365 @smallexample
14366 (@value{GDBP}) @b{collect @var{data}} // collect some data
14367
14368 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14369
14370 (@value{GDBP}) @b{end} // signals the end of actions.
14371 @end smallexample
14372
14373 In the following example, the action list begins with @code{collect}
14374 commands indicating the things to be collected when the tracepoint is
14375 hit. Then, in order to single-step and collect additional data
14376 following the tracepoint, a @code{while-stepping} command is used,
14377 followed by the list of things to be collected after each step in a
14378 sequence of single steps. The @code{while-stepping} command is
14379 terminated by its own separate @code{end} command. Lastly, the action
14380 list is terminated by an @code{end} command.
14381
14382 @smallexample
14383 (@value{GDBP}) @b{trace foo}
14384 (@value{GDBP}) @b{actions}
14385 Enter actions for tracepoint 1, one per line:
14386 > collect bar,baz
14387 > collect $regs
14388 > while-stepping 12
14389 > collect $pc, arr[i]
14390 > end
14391 end
14392 @end smallexample
14393
14394 @kindex collect @r{(tracepoints)}
14395 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14396 Collect values of the given expressions when the tracepoint is hit.
14397 This command accepts a comma-separated list of any valid expressions.
14398 In addition to global, static, or local variables, the following
14399 special arguments are supported:
14400
14401 @table @code
14402 @item $regs
14403 Collect all registers.
14404
14405 @item $args
14406 Collect all function arguments.
14407
14408 @item $locals
14409 Collect all local variables.
14410
14411 @item $_ret
14412 Collect the return address. This is helpful if you want to see more
14413 of a backtrace.
14414
14415 @emph{Note:} The return address location can not always be reliably
14416 determined up front, and the wrong address / registers may end up
14417 collected instead. On some architectures the reliability is higher
14418 for tracepoints at function entry, while on others it's the opposite.
14419 When this happens, backtracing will stop because the return address is
14420 found unavailable (unless another collect rule happened to match it).
14421
14422 @item $_probe_argc
14423 Collects the number of arguments from the static probe at which the
14424 tracepoint is located.
14425 @xref{Static Probe Points}.
14426
14427 @item $_probe_arg@var{n}
14428 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14429 from the static probe at which the tracepoint is located.
14430 @xref{Static Probe Points}.
14431
14432 @item $_sdata
14433 @vindex $_sdata@r{, collect}
14434 Collect static tracepoint marker specific data. Only available for
14435 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14436 Lists}. On the UST static tracepoints library backend, an
14437 instrumentation point resembles a @code{printf} function call. The
14438 tracing library is able to collect user specified data formatted to a
14439 character string using the format provided by the programmer that
14440 instrumented the program. Other backends have similar mechanisms.
14441 Here's an example of a UST marker call:
14442
14443 @smallexample
14444 const char master_name[] = "$your_name";
14445 trace_mark(channel1, marker1, "hello %s", master_name)
14446 @end smallexample
14447
14448 In this case, collecting @code{$_sdata} collects the string
14449 @samp{hello $yourname}. When analyzing the trace buffer, you can
14450 inspect @samp{$_sdata} like any other variable available to
14451 @value{GDBN}.
14452 @end table
14453
14454 You can give several consecutive @code{collect} commands, each one
14455 with a single argument, or one @code{collect} command with several
14456 arguments separated by commas; the effect is the same.
14457
14458 The optional @var{mods} changes the usual handling of the arguments.
14459 @code{s} requests that pointers to chars be handled as strings, in
14460 particular collecting the contents of the memory being pointed at, up
14461 to the first zero. The upper bound is by default the value of the
14462 @code{print elements} variable; if @code{s} is followed by a decimal
14463 number, that is the upper bound instead. So for instance
14464 @samp{collect/s25 mystr} collects as many as 25 characters at
14465 @samp{mystr}.
14466
14467 The command @code{info scope} (@pxref{Symbols, info scope}) is
14468 particularly useful for figuring out what data to collect.
14469
14470 @kindex teval @r{(tracepoints)}
14471 @item teval @var{expr1}, @var{expr2}, @dots{}
14472 Evaluate the given expressions when the tracepoint is hit. This
14473 command accepts a comma-separated list of expressions. The results
14474 are discarded, so this is mainly useful for assigning values to trace
14475 state variables (@pxref{Trace State Variables}) without adding those
14476 values to the trace buffer, as would be the case if the @code{collect}
14477 action were used.
14478
14479 @kindex while-stepping @r{(tracepoints)}
14480 @item while-stepping @var{n}
14481 Perform @var{n} single-step instruction traces after the tracepoint,
14482 collecting new data after each step. The @code{while-stepping}
14483 command is followed by the list of what to collect while stepping
14484 (followed by its own @code{end} command):
14485
14486 @smallexample
14487 > while-stepping 12
14488 > collect $regs, myglobal
14489 > end
14490 >
14491 @end smallexample
14492
14493 @noindent
14494 Note that @code{$pc} is not automatically collected by
14495 @code{while-stepping}; you need to explicitly collect that register if
14496 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14497 @code{stepping}.
14498
14499 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14500 @kindex set default-collect
14501 @cindex default collection action
14502 This variable is a list of expressions to collect at each tracepoint
14503 hit. It is effectively an additional @code{collect} action prepended
14504 to every tracepoint action list. The expressions are parsed
14505 individually for each tracepoint, so for instance a variable named
14506 @code{xyz} may be interpreted as a global for one tracepoint, and a
14507 local for another, as appropriate to the tracepoint's location.
14508
14509 @item show default-collect
14510 @kindex show default-collect
14511 Show the list of expressions that are collected by default at each
14512 tracepoint hit.
14513
14514 @end table
14515
14516 @node Listing Tracepoints
14517 @subsection Listing Tracepoints
14518
14519 @table @code
14520 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14521 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14522 @cindex information about tracepoints
14523 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14524 Display information about the tracepoint @var{num}. If you don't
14525 specify a tracepoint number, displays information about all the
14526 tracepoints defined so far. The format is similar to that used for
14527 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14528 command, simply restricting itself to tracepoints.
14529
14530 A tracepoint's listing may include additional information specific to
14531 tracing:
14532
14533 @itemize @bullet
14534 @item
14535 its passcount as given by the @code{passcount @var{n}} command
14536
14537 @item
14538 the state about installed on target of each location
14539 @end itemize
14540
14541 @smallexample
14542 (@value{GDBP}) @b{info trace}
14543 Num Type Disp Enb Address What
14544 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14545 while-stepping 20
14546 collect globfoo, $regs
14547 end
14548 collect globfoo2
14549 end
14550 pass count 1200
14551 2 tracepoint keep y <MULTIPLE>
14552 collect $eip
14553 2.1 y 0x0804859c in func4 at change-loc.h:35
14554 installed on target
14555 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14556 installed on target
14557 2.3 y <PENDING> set_tracepoint
14558 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14559 not installed on target
14560 (@value{GDBP})
14561 @end smallexample
14562
14563 @noindent
14564 This command can be abbreviated @code{info tp}.
14565 @end table
14566
14567 @node Listing Static Tracepoint Markers
14568 @subsection Listing Static Tracepoint Markers
14569
14570 @table @code
14571 @kindex info static-tracepoint-markers
14572 @cindex information about static tracepoint markers
14573 @item info static-tracepoint-markers
14574 Display information about all static tracepoint markers defined in the
14575 program.
14576
14577 For each marker, the following columns are printed:
14578
14579 @table @emph
14580 @item Count
14581 An incrementing counter, output to help readability. This is not a
14582 stable identifier.
14583 @item ID
14584 The marker ID, as reported by the target.
14585 @item Enabled or Disabled
14586 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14587 that are not enabled.
14588 @item Address
14589 Where the marker is in your program, as a memory address.
14590 @item What
14591 Where the marker is in the source for your program, as a file and line
14592 number. If the debug information included in the program does not
14593 allow @value{GDBN} to locate the source of the marker, this column
14594 will be left blank.
14595 @end table
14596
14597 @noindent
14598 In addition, the following information may be printed for each marker:
14599
14600 @table @emph
14601 @item Data
14602 User data passed to the tracing library by the marker call. In the
14603 UST backend, this is the format string passed as argument to the
14604 marker call.
14605 @item Static tracepoints probing the marker
14606 The list of static tracepoints attached to the marker.
14607 @end table
14608
14609 @smallexample
14610 (@value{GDBP}) info static-tracepoint-markers
14611 Cnt ID Enb Address What
14612 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14613 Data: number1 %d number2 %d
14614 Probed by static tracepoints: #2
14615 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14616 Data: str %s
14617 (@value{GDBP})
14618 @end smallexample
14619 @end table
14620
14621 @node Starting and Stopping Trace Experiments
14622 @subsection Starting and Stopping Trace Experiments
14623
14624 @table @code
14625 @kindex tstart [ @var{notes} ]
14626 @cindex start a new trace experiment
14627 @cindex collected data discarded
14628 @item tstart
14629 This command starts the trace experiment, and begins collecting data.
14630 It has the side effect of discarding all the data collected in the
14631 trace buffer during the previous trace experiment. If any arguments
14632 are supplied, they are taken as a note and stored with the trace
14633 experiment's state. The notes may be arbitrary text, and are
14634 especially useful with disconnected tracing in a multi-user context;
14635 the notes can explain what the trace is doing, supply user contact
14636 information, and so forth.
14637
14638 @kindex tstop [ @var{notes} ]
14639 @cindex stop a running trace experiment
14640 @item tstop
14641 This command stops the trace experiment. If any arguments are
14642 supplied, they are recorded with the experiment as a note. This is
14643 useful if you are stopping a trace started by someone else, for
14644 instance if the trace is interfering with the system's behavior and
14645 needs to be stopped quickly.
14646
14647 @strong{Note}: a trace experiment and data collection may stop
14648 automatically if any tracepoint's passcount is reached
14649 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14650
14651 @kindex tstatus
14652 @cindex status of trace data collection
14653 @cindex trace experiment, status of
14654 @item tstatus
14655 This command displays the status of the current trace data
14656 collection.
14657 @end table
14658
14659 Here is an example of the commands we described so far:
14660
14661 @smallexample
14662 (@value{GDBP}) @b{trace gdb_c_test}
14663 (@value{GDBP}) @b{actions}
14664 Enter actions for tracepoint #1, one per line.
14665 > collect $regs,$locals,$args
14666 > while-stepping 11
14667 > collect $regs
14668 > end
14669 > end
14670 (@value{GDBP}) @b{tstart}
14671 [time passes @dots{}]
14672 (@value{GDBP}) @b{tstop}
14673 @end smallexample
14674
14675 @anchor{disconnected tracing}
14676 @cindex disconnected tracing
14677 You can choose to continue running the trace experiment even if
14678 @value{GDBN} disconnects from the target, voluntarily or
14679 involuntarily. For commands such as @code{detach}, the debugger will
14680 ask what you want to do with the trace. But for unexpected
14681 terminations (@value{GDBN} crash, network outage), it would be
14682 unfortunate to lose hard-won trace data, so the variable
14683 @code{disconnected-tracing} lets you decide whether the trace should
14684 continue running without @value{GDBN}.
14685
14686 @table @code
14687 @item set disconnected-tracing on
14688 @itemx set disconnected-tracing off
14689 @kindex set disconnected-tracing
14690 Choose whether a tracing run should continue to run if @value{GDBN}
14691 has disconnected from the target. Note that @code{detach} or
14692 @code{quit} will ask you directly what to do about a running trace no
14693 matter what this variable's setting, so the variable is mainly useful
14694 for handling unexpected situations, such as loss of the network.
14695
14696 @item show disconnected-tracing
14697 @kindex show disconnected-tracing
14698 Show the current choice for disconnected tracing.
14699
14700 @end table
14701
14702 When you reconnect to the target, the trace experiment may or may not
14703 still be running; it might have filled the trace buffer in the
14704 meantime, or stopped for one of the other reasons. If it is running,
14705 it will continue after reconnection.
14706
14707 Upon reconnection, the target will upload information about the
14708 tracepoints in effect. @value{GDBN} will then compare that
14709 information to the set of tracepoints currently defined, and attempt
14710 to match them up, allowing for the possibility that the numbers may
14711 have changed due to creation and deletion in the meantime. If one of
14712 the target's tracepoints does not match any in @value{GDBN}, the
14713 debugger will create a new tracepoint, so that you have a number with
14714 which to specify that tracepoint. This matching-up process is
14715 necessarily heuristic, and it may result in useless tracepoints being
14716 created; you may simply delete them if they are of no use.
14717
14718 @cindex circular trace buffer
14719 If your target agent supports a @dfn{circular trace buffer}, then you
14720 can run a trace experiment indefinitely without filling the trace
14721 buffer; when space runs out, the agent deletes already-collected trace
14722 frames, oldest first, until there is enough room to continue
14723 collecting. This is especially useful if your tracepoints are being
14724 hit too often, and your trace gets terminated prematurely because the
14725 buffer is full. To ask for a circular trace buffer, simply set
14726 @samp{circular-trace-buffer} to on. You can set this at any time,
14727 including during tracing; if the agent can do it, it will change
14728 buffer handling on the fly, otherwise it will not take effect until
14729 the next run.
14730
14731 @table @code
14732 @item set circular-trace-buffer on
14733 @itemx set circular-trace-buffer off
14734 @kindex set circular-trace-buffer
14735 Choose whether a tracing run should use a linear or circular buffer
14736 for trace data. A linear buffer will not lose any trace data, but may
14737 fill up prematurely, while a circular buffer will discard old trace
14738 data, but it will have always room for the latest tracepoint hits.
14739
14740 @item show circular-trace-buffer
14741 @kindex show circular-trace-buffer
14742 Show the current choice for the trace buffer. Note that this may not
14743 match the agent's current buffer handling, nor is it guaranteed to
14744 match the setting that might have been in effect during a past run,
14745 for instance if you are looking at frames from a trace file.
14746
14747 @end table
14748
14749 @table @code
14750 @item set trace-buffer-size @var{n}
14751 @itemx set trace-buffer-size unlimited
14752 @kindex set trace-buffer-size
14753 Request that the target use a trace buffer of @var{n} bytes. Not all
14754 targets will honor the request; they may have a compiled-in size for
14755 the trace buffer, or some other limitation. Set to a value of
14756 @code{unlimited} or @code{-1} to let the target use whatever size it
14757 likes. This is also the default.
14758
14759 @item show trace-buffer-size
14760 @kindex show trace-buffer-size
14761 Show the current requested size for the trace buffer. Note that this
14762 will only match the actual size if the target supports size-setting,
14763 and was able to handle the requested size. For instance, if the
14764 target can only change buffer size between runs, this variable will
14765 not reflect the change until the next run starts. Use @code{tstatus}
14766 to get a report of the actual buffer size.
14767 @end table
14768
14769 @table @code
14770 @item set trace-user @var{text}
14771 @kindex set trace-user
14772
14773 @item show trace-user
14774 @kindex show trace-user
14775
14776 @item set trace-notes @var{text}
14777 @kindex set trace-notes
14778 Set the trace run's notes.
14779
14780 @item show trace-notes
14781 @kindex show trace-notes
14782 Show the trace run's notes.
14783
14784 @item set trace-stop-notes @var{text}
14785 @kindex set trace-stop-notes
14786 Set the trace run's stop notes. The handling of the note is as for
14787 @code{tstop} arguments; the set command is convenient way to fix a
14788 stop note that is mistaken or incomplete.
14789
14790 @item show trace-stop-notes
14791 @kindex show trace-stop-notes
14792 Show the trace run's stop notes.
14793
14794 @end table
14795
14796 @node Tracepoint Restrictions
14797 @subsection Tracepoint Restrictions
14798
14799 @cindex tracepoint restrictions
14800 There are a number of restrictions on the use of tracepoints. As
14801 described above, tracepoint data gathering occurs on the target
14802 without interaction from @value{GDBN}. Thus the full capabilities of
14803 the debugger are not available during data gathering, and then at data
14804 examination time, you will be limited by only having what was
14805 collected. The following items describe some common problems, but it
14806 is not exhaustive, and you may run into additional difficulties not
14807 mentioned here.
14808
14809 @itemize @bullet
14810
14811 @item
14812 Tracepoint expressions are intended to gather objects (lvalues). Thus
14813 the full flexibility of GDB's expression evaluator is not available.
14814 You cannot call functions, cast objects to aggregate types, access
14815 convenience variables or modify values (except by assignment to trace
14816 state variables). Some language features may implicitly call
14817 functions (for instance Objective-C fields with accessors), and therefore
14818 cannot be collected either.
14819
14820 @item
14821 Collection of local variables, either individually or in bulk with
14822 @code{$locals} or @code{$args}, during @code{while-stepping} may
14823 behave erratically. The stepping action may enter a new scope (for
14824 instance by stepping into a function), or the location of the variable
14825 may change (for instance it is loaded into a register). The
14826 tracepoint data recorded uses the location information for the
14827 variables that is correct for the tracepoint location. When the
14828 tracepoint is created, it is not possible, in general, to determine
14829 where the steps of a @code{while-stepping} sequence will advance the
14830 program---particularly if a conditional branch is stepped.
14831
14832 @item
14833 Collection of an incompletely-initialized or partially-destroyed object
14834 may result in something that @value{GDBN} cannot display, or displays
14835 in a misleading way.
14836
14837 @item
14838 When @value{GDBN} displays a pointer to character it automatically
14839 dereferences the pointer to also display characters of the string
14840 being pointed to. However, collecting the pointer during tracing does
14841 not automatically collect the string. You need to explicitly
14842 dereference the pointer and provide size information if you want to
14843 collect not only the pointer, but the memory pointed to. For example,
14844 @code{*ptr@@50} can be used to collect the 50 element array pointed to
14845 by @code{ptr}.
14846
14847 @item
14848 It is not possible to collect a complete stack backtrace at a
14849 tracepoint. Instead, you may collect the registers and a few hundred
14850 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
14851 (adjust to use the name of the actual stack pointer register on your
14852 target architecture, and the amount of stack you wish to capture).
14853 Then the @code{backtrace} command will show a partial backtrace when
14854 using a trace frame. The number of stack frames that can be examined
14855 depends on the sizes of the frames in the collected stack. Note that
14856 if you ask for a block so large that it goes past the bottom of the
14857 stack, the target agent may report an error trying to read from an
14858 invalid address.
14859
14860 @item
14861 If you do not collect registers at a tracepoint, @value{GDBN} can
14862 infer that the value of @code{$pc} must be the same as the address of
14863 the tracepoint and use that when you are looking at a trace frame
14864 for that tracepoint. However, this cannot work if the tracepoint has
14865 multiple locations (for instance if it was set in a function that was
14866 inlined), or if it has a @code{while-stepping} loop. In those cases
14867 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
14868 it to zero.
14869
14870 @end itemize
14871
14872 @node Analyze Collected Data
14873 @section Using the Collected Data
14874
14875 After the tracepoint experiment ends, you use @value{GDBN} commands
14876 for examining the trace data. The basic idea is that each tracepoint
14877 collects a trace @dfn{snapshot} every time it is hit and another
14878 snapshot every time it single-steps. All these snapshots are
14879 consecutively numbered from zero and go into a buffer, and you can
14880 examine them later. The way you examine them is to @dfn{focus} on a
14881 specific trace snapshot. When the remote stub is focused on a trace
14882 snapshot, it will respond to all @value{GDBN} requests for memory and
14883 registers by reading from the buffer which belongs to that snapshot,
14884 rather than from @emph{real} memory or registers of the program being
14885 debugged. This means that @strong{all} @value{GDBN} commands
14886 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
14887 behave as if we were currently debugging the program state as it was
14888 when the tracepoint occurred. Any requests for data that are not in
14889 the buffer will fail.
14890
14891 @menu
14892 * tfind:: How to select a trace snapshot
14893 * tdump:: How to display all data for a snapshot
14894 * save tracepoints:: How to save tracepoints for a future run
14895 @end menu
14896
14897 @node tfind
14898 @subsection @code{tfind @var{n}}
14899
14900 @kindex tfind
14901 @cindex select trace snapshot
14902 @cindex find trace snapshot
14903 The basic command for selecting a trace snapshot from the buffer is
14904 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
14905 counting from zero. If no argument @var{n} is given, the next
14906 snapshot is selected.
14907
14908 Here are the various forms of using the @code{tfind} command.
14909
14910 @table @code
14911 @item tfind start
14912 Find the first snapshot in the buffer. This is a synonym for
14913 @code{tfind 0} (since 0 is the number of the first snapshot).
14914
14915 @item tfind none
14916 Stop debugging trace snapshots, resume @emph{live} debugging.
14917
14918 @item tfind end
14919 Same as @samp{tfind none}.
14920
14921 @item tfind
14922 No argument means find the next trace snapshot or find the first
14923 one if no trace snapshot is selected.
14924
14925 @item tfind -
14926 Find the previous trace snapshot before the current one. This permits
14927 retracing earlier steps.
14928
14929 @item tfind tracepoint @var{num}
14930 Find the next snapshot associated with tracepoint @var{num}. Search
14931 proceeds forward from the last examined trace snapshot. If no
14932 argument @var{num} is given, it means find the next snapshot collected
14933 for the same tracepoint as the current snapshot.
14934
14935 @item tfind pc @var{addr}
14936 Find the next snapshot associated with the value @var{addr} of the
14937 program counter. Search proceeds forward from the last examined trace
14938 snapshot. If no argument @var{addr} is given, it means find the next
14939 snapshot with the same value of PC as the current snapshot.
14940
14941 @item tfind outside @var{addr1}, @var{addr2}
14942 Find the next snapshot whose PC is outside the given range of
14943 addresses (exclusive).
14944
14945 @item tfind range @var{addr1}, @var{addr2}
14946 Find the next snapshot whose PC is between @var{addr1} and
14947 @var{addr2} (inclusive).
14948
14949 @item tfind line @r{[}@var{file}:@r{]}@var{n}
14950 Find the next snapshot associated with the source line @var{n}. If
14951 the optional argument @var{file} is given, refer to line @var{n} in
14952 that source file. Search proceeds forward from the last examined
14953 trace snapshot. If no argument @var{n} is given, it means find the
14954 next line other than the one currently being examined; thus saying
14955 @code{tfind line} repeatedly can appear to have the same effect as
14956 stepping from line to line in a @emph{live} debugging session.
14957 @end table
14958
14959 The default arguments for the @code{tfind} commands are specifically
14960 designed to make it easy to scan through the trace buffer. For
14961 instance, @code{tfind} with no argument selects the next trace
14962 snapshot, and @code{tfind -} with no argument selects the previous
14963 trace snapshot. So, by giving one @code{tfind} command, and then
14964 simply hitting @key{RET} repeatedly you can examine all the trace
14965 snapshots in order. Or, by saying @code{tfind -} and then hitting
14966 @key{RET} repeatedly you can examine the snapshots in reverse order.
14967 The @code{tfind line} command with no argument selects the snapshot
14968 for the next source line executed. The @code{tfind pc} command with
14969 no argument selects the next snapshot with the same program counter
14970 (PC) as the current frame. The @code{tfind tracepoint} command with
14971 no argument selects the next trace snapshot collected by the same
14972 tracepoint as the current one.
14973
14974 In addition to letting you scan through the trace buffer manually,
14975 these commands make it easy to construct @value{GDBN} scripts that
14976 scan through the trace buffer and print out whatever collected data
14977 you are interested in. Thus, if we want to examine the PC, FP, and SP
14978 registers from each trace frame in the buffer, we can say this:
14979
14980 @smallexample
14981 (@value{GDBP}) @b{tfind start}
14982 (@value{GDBP}) @b{while ($trace_frame != -1)}
14983 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
14984 $trace_frame, $pc, $sp, $fp
14985 > tfind
14986 > end
14987
14988 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
14989 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
14990 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
14991 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
14992 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
14993 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
14994 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
14995 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
14996 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
14997 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
14998 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
14999 @end smallexample
15000
15001 Or, if we want to examine the variable @code{X} at each source line in
15002 the buffer:
15003
15004 @smallexample
15005 (@value{GDBP}) @b{tfind start}
15006 (@value{GDBP}) @b{while ($trace_frame != -1)}
15007 > printf "Frame %d, X == %d\n", $trace_frame, X
15008 > tfind line
15009 > end
15010
15011 Frame 0, X = 1
15012 Frame 7, X = 2
15013 Frame 13, X = 255
15014 @end smallexample
15015
15016 @node tdump
15017 @subsection @code{tdump}
15018 @kindex tdump
15019 @cindex dump all data collected at tracepoint
15020 @cindex tracepoint data, display
15021
15022 This command takes no arguments. It prints all the data collected at
15023 the current trace snapshot.
15024
15025 @smallexample
15026 (@value{GDBP}) @b{trace 444}
15027 (@value{GDBP}) @b{actions}
15028 Enter actions for tracepoint #2, one per line:
15029 > collect $regs, $locals, $args, gdb_long_test
15030 > end
15031
15032 (@value{GDBP}) @b{tstart}
15033
15034 (@value{GDBP}) @b{tfind line 444}
15035 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15036 at gdb_test.c:444
15037 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15038
15039 (@value{GDBP}) @b{tdump}
15040 Data collected at tracepoint 2, trace frame 1:
15041 d0 0xc4aa0085 -995491707
15042 d1 0x18 24
15043 d2 0x80 128
15044 d3 0x33 51
15045 d4 0x71aea3d 119204413
15046 d5 0x22 34
15047 d6 0xe0 224
15048 d7 0x380035 3670069
15049 a0 0x19e24a 1696330
15050 a1 0x3000668 50333288
15051 a2 0x100 256
15052 a3 0x322000 3284992
15053 a4 0x3000698 50333336
15054 a5 0x1ad3cc 1758156
15055 fp 0x30bf3c 0x30bf3c
15056 sp 0x30bf34 0x30bf34
15057 ps 0x0 0
15058 pc 0x20b2c8 0x20b2c8
15059 fpcontrol 0x0 0
15060 fpstatus 0x0 0
15061 fpiaddr 0x0 0
15062 p = 0x20e5b4 "gdb-test"
15063 p1 = (void *) 0x11
15064 p2 = (void *) 0x22
15065 p3 = (void *) 0x33
15066 p4 = (void *) 0x44
15067 p5 = (void *) 0x55
15068 p6 = (void *) 0x66
15069 gdb_long_test = 17 '\021'
15070
15071 (@value{GDBP})
15072 @end smallexample
15073
15074 @code{tdump} works by scanning the tracepoint's current collection
15075 actions and printing the value of each expression listed. So
15076 @code{tdump} can fail, if after a run, you change the tracepoint's
15077 actions to mention variables that were not collected during the run.
15078
15079 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15080 uses the collected value of @code{$pc} to distinguish between trace
15081 frames that were collected at the tracepoint hit, and frames that were
15082 collected while stepping. This allows it to correctly choose whether
15083 to display the basic list of collections, or the collections from the
15084 body of the while-stepping loop. However, if @code{$pc} was not collected,
15085 then @code{tdump} will always attempt to dump using the basic collection
15086 list, and may fail if a while-stepping frame does not include all the
15087 same data that is collected at the tracepoint hit.
15088 @c This is getting pretty arcane, example would be good.
15089
15090 @node save tracepoints
15091 @subsection @code{save tracepoints @var{filename}}
15092 @kindex save tracepoints
15093 @kindex save-tracepoints
15094 @cindex save tracepoints for future sessions
15095
15096 This command saves all current tracepoint definitions together with
15097 their actions and passcounts, into a file @file{@var{filename}}
15098 suitable for use in a later debugging session. To read the saved
15099 tracepoint definitions, use the @code{source} command (@pxref{Command
15100 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15101 alias for @w{@code{save tracepoints}}
15102
15103 @node Tracepoint Variables
15104 @section Convenience Variables for Tracepoints
15105 @cindex tracepoint variables
15106 @cindex convenience variables for tracepoints
15107
15108 @table @code
15109 @vindex $trace_frame
15110 @item (int) $trace_frame
15111 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15112 snapshot is selected.
15113
15114 @vindex $tracepoint
15115 @item (int) $tracepoint
15116 The tracepoint for the current trace snapshot.
15117
15118 @vindex $trace_line
15119 @item (int) $trace_line
15120 The line number for the current trace snapshot.
15121
15122 @vindex $trace_file
15123 @item (char []) $trace_file
15124 The source file for the current trace snapshot.
15125
15126 @vindex $trace_func
15127 @item (char []) $trace_func
15128 The name of the function containing @code{$tracepoint}.
15129 @end table
15130
15131 Note: @code{$trace_file} is not suitable for use in @code{printf},
15132 use @code{output} instead.
15133
15134 Here's a simple example of using these convenience variables for
15135 stepping through all the trace snapshots and printing some of their
15136 data. Note that these are not the same as trace state variables,
15137 which are managed by the target.
15138
15139 @smallexample
15140 (@value{GDBP}) @b{tfind start}
15141
15142 (@value{GDBP}) @b{while $trace_frame != -1}
15143 > output $trace_file
15144 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15145 > tfind
15146 > end
15147 @end smallexample
15148
15149 @node Trace Files
15150 @section Using Trace Files
15151 @cindex trace files
15152
15153 In some situations, the target running a trace experiment may no
15154 longer be available; perhaps it crashed, or the hardware was needed
15155 for a different activity. To handle these cases, you can arrange to
15156 dump the trace data into a file, and later use that file as a source
15157 of trace data, via the @code{target tfile} command.
15158
15159 @table @code
15160
15161 @kindex tsave
15162 @item tsave [ -r ] @var{filename}
15163 @itemx tsave [-ctf] @var{dirname}
15164 Save the trace data to @var{filename}. By default, this command
15165 assumes that @var{filename} refers to the host filesystem, so if
15166 necessary @value{GDBN} will copy raw trace data up from the target and
15167 then save it. If the target supports it, you can also supply the
15168 optional argument @code{-r} (``remote'') to direct the target to save
15169 the data directly into @var{filename} in its own filesystem, which may be
15170 more efficient if the trace buffer is very large. (Note, however, that
15171 @code{target tfile} can only read from files accessible to the host.)
15172 By default, this command will save trace frame in tfile format.
15173 You can supply the optional argument @code{-ctf} to save data in CTF
15174 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15175 that can be shared by multiple debugging and tracing tools. Please go to
15176 @indicateurl{http://www.efficios.com/ctf} to get more information.
15177
15178 @kindex target tfile
15179 @kindex tfile
15180 @kindex target ctf
15181 @kindex ctf
15182 @item target tfile @var{filename}
15183 @itemx target ctf @var{dirname}
15184 Use the file named @var{filename} or directory named @var{dirname} as
15185 a source of trace data. Commands that examine data work as they do with
15186 a live target, but it is not possible to run any new trace experiments.
15187 @code{tstatus} will report the state of the trace run at the moment
15188 the data was saved, as well as the current trace frame you are examining.
15189 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15190 the host.
15191
15192 @smallexample
15193 (@value{GDBP}) target ctf ctf.ctf
15194 (@value{GDBP}) tfind
15195 Found trace frame 0, tracepoint 2
15196 39 ++a; /* set tracepoint 1 here */
15197 (@value{GDBP}) tdump
15198 Data collected at tracepoint 2, trace frame 0:
15199 i = 0
15200 a = 0
15201 b = 1 '\001'
15202 c = @{"123", "456", "789", "123", "456", "789"@}
15203 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15204 (@value{GDBP}) p b
15205 $1 = 1
15206 @end smallexample
15207
15208 @end table
15209
15210 @node Overlays
15211 @chapter Debugging Programs That Use Overlays
15212 @cindex overlays
15213
15214 If your program is too large to fit completely in your target system's
15215 memory, you can sometimes use @dfn{overlays} to work around this
15216 problem. @value{GDBN} provides some support for debugging programs that
15217 use overlays.
15218
15219 @menu
15220 * How Overlays Work:: A general explanation of overlays.
15221 * Overlay Commands:: Managing overlays in @value{GDBN}.
15222 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15223 mapped by asking the inferior.
15224 * Overlay Sample Program:: A sample program using overlays.
15225 @end menu
15226
15227 @node How Overlays Work
15228 @section How Overlays Work
15229 @cindex mapped overlays
15230 @cindex unmapped overlays
15231 @cindex load address, overlay's
15232 @cindex mapped address
15233 @cindex overlay area
15234
15235 Suppose you have a computer whose instruction address space is only 64
15236 kilobytes long, but which has much more memory which can be accessed by
15237 other means: special instructions, segment registers, or memory
15238 management hardware, for example. Suppose further that you want to
15239 adapt a program which is larger than 64 kilobytes to run on this system.
15240
15241 One solution is to identify modules of your program which are relatively
15242 independent, and need not call each other directly; call these modules
15243 @dfn{overlays}. Separate the overlays from the main program, and place
15244 their machine code in the larger memory. Place your main program in
15245 instruction memory, but leave at least enough space there to hold the
15246 largest overlay as well.
15247
15248 Now, to call a function located in an overlay, you must first copy that
15249 overlay's machine code from the large memory into the space set aside
15250 for it in the instruction memory, and then jump to its entry point
15251 there.
15252
15253 @c NB: In the below the mapped area's size is greater or equal to the
15254 @c size of all overlays. This is intentional to remind the developer
15255 @c that overlays don't necessarily need to be the same size.
15256
15257 @smallexample
15258 @group
15259 Data Instruction Larger
15260 Address Space Address Space Address Space
15261 +-----------+ +-----------+ +-----------+
15262 | | | | | |
15263 +-----------+ +-----------+ +-----------+<-- overlay 1
15264 | program | | main | .----| overlay 1 | load address
15265 | variables | | program | | +-----------+
15266 | and heap | | | | | |
15267 +-----------+ | | | +-----------+<-- overlay 2
15268 | | +-----------+ | | | load address
15269 +-----------+ | | | .-| overlay 2 |
15270 | | | | | |
15271 mapped --->+-----------+ | | +-----------+
15272 address | | | | | |
15273 | overlay | <-' | | |
15274 | area | <---' +-----------+<-- overlay 3
15275 | | <---. | | load address
15276 +-----------+ `--| overlay 3 |
15277 | | | |
15278 +-----------+ | |
15279 +-----------+
15280 | |
15281 +-----------+
15282
15283 @anchor{A code overlay}A code overlay
15284 @end group
15285 @end smallexample
15286
15287 The diagram (@pxref{A code overlay}) shows a system with separate data
15288 and instruction address spaces. To map an overlay, the program copies
15289 its code from the larger address space to the instruction address space.
15290 Since the overlays shown here all use the same mapped address, only one
15291 may be mapped at a time. For a system with a single address space for
15292 data and instructions, the diagram would be similar, except that the
15293 program variables and heap would share an address space with the main
15294 program and the overlay area.
15295
15296 An overlay loaded into instruction memory and ready for use is called a
15297 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15298 instruction memory. An overlay not present (or only partially present)
15299 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15300 is its address in the larger memory. The mapped address is also called
15301 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15302 called the @dfn{load memory address}, or @dfn{LMA}.
15303
15304 Unfortunately, overlays are not a completely transparent way to adapt a
15305 program to limited instruction memory. They introduce a new set of
15306 global constraints you must keep in mind as you design your program:
15307
15308 @itemize @bullet
15309
15310 @item
15311 Before calling or returning to a function in an overlay, your program
15312 must make sure that overlay is actually mapped. Otherwise, the call or
15313 return will transfer control to the right address, but in the wrong
15314 overlay, and your program will probably crash.
15315
15316 @item
15317 If the process of mapping an overlay is expensive on your system, you
15318 will need to choose your overlays carefully to minimize their effect on
15319 your program's performance.
15320
15321 @item
15322 The executable file you load onto your system must contain each
15323 overlay's instructions, appearing at the overlay's load address, not its
15324 mapped address. However, each overlay's instructions must be relocated
15325 and its symbols defined as if the overlay were at its mapped address.
15326 You can use GNU linker scripts to specify different load and relocation
15327 addresses for pieces of your program; see @ref{Overlay Description,,,
15328 ld.info, Using ld: the GNU linker}.
15329
15330 @item
15331 The procedure for loading executable files onto your system must be able
15332 to load their contents into the larger address space as well as the
15333 instruction and data spaces.
15334
15335 @end itemize
15336
15337 The overlay system described above is rather simple, and could be
15338 improved in many ways:
15339
15340 @itemize @bullet
15341
15342 @item
15343 If your system has suitable bank switch registers or memory management
15344 hardware, you could use those facilities to make an overlay's load area
15345 contents simply appear at their mapped address in instruction space.
15346 This would probably be faster than copying the overlay to its mapped
15347 area in the usual way.
15348
15349 @item
15350 If your overlays are small enough, you could set aside more than one
15351 overlay area, and have more than one overlay mapped at a time.
15352
15353 @item
15354 You can use overlays to manage data, as well as instructions. In
15355 general, data overlays are even less transparent to your design than
15356 code overlays: whereas code overlays only require care when you call or
15357 return to functions, data overlays require care every time you access
15358 the data. Also, if you change the contents of a data overlay, you
15359 must copy its contents back out to its load address before you can copy a
15360 different data overlay into the same mapped area.
15361
15362 @end itemize
15363
15364
15365 @node Overlay Commands
15366 @section Overlay Commands
15367
15368 To use @value{GDBN}'s overlay support, each overlay in your program must
15369 correspond to a separate section of the executable file. The section's
15370 virtual memory address and load memory address must be the overlay's
15371 mapped and load addresses. Identifying overlays with sections allows
15372 @value{GDBN} to determine the appropriate address of a function or
15373 variable, depending on whether the overlay is mapped or not.
15374
15375 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15376 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15377
15378 @table @code
15379 @item overlay off
15380 @kindex overlay
15381 Disable @value{GDBN}'s overlay support. When overlay support is
15382 disabled, @value{GDBN} assumes that all functions and variables are
15383 always present at their mapped addresses. By default, @value{GDBN}'s
15384 overlay support is disabled.
15385
15386 @item overlay manual
15387 @cindex manual overlay debugging
15388 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15389 relies on you to tell it which overlays are mapped, and which are not,
15390 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15391 commands described below.
15392
15393 @item overlay map-overlay @var{overlay}
15394 @itemx overlay map @var{overlay}
15395 @cindex map an overlay
15396 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15397 be the name of the object file section containing the overlay. When an
15398 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15399 functions and variables at their mapped addresses. @value{GDBN} assumes
15400 that any other overlays whose mapped ranges overlap that of
15401 @var{overlay} are now unmapped.
15402
15403 @item overlay unmap-overlay @var{overlay}
15404 @itemx overlay unmap @var{overlay}
15405 @cindex unmap an overlay
15406 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15407 must be the name of the object file section containing the overlay.
15408 When an overlay is unmapped, @value{GDBN} assumes it can find the
15409 overlay's functions and variables at their load addresses.
15410
15411 @item overlay auto
15412 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15413 consults a data structure the overlay manager maintains in the inferior
15414 to see which overlays are mapped. For details, see @ref{Automatic
15415 Overlay Debugging}.
15416
15417 @item overlay load-target
15418 @itemx overlay load
15419 @cindex reloading the overlay table
15420 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15421 re-reads the table @value{GDBN} automatically each time the inferior
15422 stops, so this command should only be necessary if you have changed the
15423 overlay mapping yourself using @value{GDBN}. This command is only
15424 useful when using automatic overlay debugging.
15425
15426 @item overlay list-overlays
15427 @itemx overlay list
15428 @cindex listing mapped overlays
15429 Display a list of the overlays currently mapped, along with their mapped
15430 addresses, load addresses, and sizes.
15431
15432 @end table
15433
15434 Normally, when @value{GDBN} prints a code address, it includes the name
15435 of the function the address falls in:
15436
15437 @smallexample
15438 (@value{GDBP}) print main
15439 $3 = @{int ()@} 0x11a0 <main>
15440 @end smallexample
15441 @noindent
15442 When overlay debugging is enabled, @value{GDBN} recognizes code in
15443 unmapped overlays, and prints the names of unmapped functions with
15444 asterisks around them. For example, if @code{foo} is a function in an
15445 unmapped overlay, @value{GDBN} prints it this way:
15446
15447 @smallexample
15448 (@value{GDBP}) overlay list
15449 No sections are mapped.
15450 (@value{GDBP}) print foo
15451 $5 = @{int (int)@} 0x100000 <*foo*>
15452 @end smallexample
15453 @noindent
15454 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15455 name normally:
15456
15457 @smallexample
15458 (@value{GDBP}) overlay list
15459 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15460 mapped at 0x1016 - 0x104a
15461 (@value{GDBP}) print foo
15462 $6 = @{int (int)@} 0x1016 <foo>
15463 @end smallexample
15464
15465 When overlay debugging is enabled, @value{GDBN} can find the correct
15466 address for functions and variables in an overlay, whether or not the
15467 overlay is mapped. This allows most @value{GDBN} commands, like
15468 @code{break} and @code{disassemble}, to work normally, even on unmapped
15469 code. However, @value{GDBN}'s breakpoint support has some limitations:
15470
15471 @itemize @bullet
15472 @item
15473 @cindex breakpoints in overlays
15474 @cindex overlays, setting breakpoints in
15475 You can set breakpoints in functions in unmapped overlays, as long as
15476 @value{GDBN} can write to the overlay at its load address.
15477 @item
15478 @value{GDBN} can not set hardware or simulator-based breakpoints in
15479 unmapped overlays. However, if you set a breakpoint at the end of your
15480 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15481 you are using manual overlay management), @value{GDBN} will re-set its
15482 breakpoints properly.
15483 @end itemize
15484
15485
15486 @node Automatic Overlay Debugging
15487 @section Automatic Overlay Debugging
15488 @cindex automatic overlay debugging
15489
15490 @value{GDBN} can automatically track which overlays are mapped and which
15491 are not, given some simple co-operation from the overlay manager in the
15492 inferior. If you enable automatic overlay debugging with the
15493 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15494 looks in the inferior's memory for certain variables describing the
15495 current state of the overlays.
15496
15497 Here are the variables your overlay manager must define to support
15498 @value{GDBN}'s automatic overlay debugging:
15499
15500 @table @asis
15501
15502 @item @code{_ovly_table}:
15503 This variable must be an array of the following structures:
15504
15505 @smallexample
15506 struct
15507 @{
15508 /* The overlay's mapped address. */
15509 unsigned long vma;
15510
15511 /* The size of the overlay, in bytes. */
15512 unsigned long size;
15513
15514 /* The overlay's load address. */
15515 unsigned long lma;
15516
15517 /* Non-zero if the overlay is currently mapped;
15518 zero otherwise. */
15519 unsigned long mapped;
15520 @}
15521 @end smallexample
15522
15523 @item @code{_novlys}:
15524 This variable must be a four-byte signed integer, holding the total
15525 number of elements in @code{_ovly_table}.
15526
15527 @end table
15528
15529 To decide whether a particular overlay is mapped or not, @value{GDBN}
15530 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15531 @code{lma} members equal the VMA and LMA of the overlay's section in the
15532 executable file. When @value{GDBN} finds a matching entry, it consults
15533 the entry's @code{mapped} member to determine whether the overlay is
15534 currently mapped.
15535
15536 In addition, your overlay manager may define a function called
15537 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15538 will silently set a breakpoint there. If the overlay manager then
15539 calls this function whenever it has changed the overlay table, this
15540 will enable @value{GDBN} to accurately keep track of which overlays
15541 are in program memory, and update any breakpoints that may be set
15542 in overlays. This will allow breakpoints to work even if the
15543 overlays are kept in ROM or other non-writable memory while they
15544 are not being executed.
15545
15546 @node Overlay Sample Program
15547 @section Overlay Sample Program
15548 @cindex overlay example program
15549
15550 When linking a program which uses overlays, you must place the overlays
15551 at their load addresses, while relocating them to run at their mapped
15552 addresses. To do this, you must write a linker script (@pxref{Overlay
15553 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15554 since linker scripts are specific to a particular host system, target
15555 architecture, and target memory layout, this manual cannot provide
15556 portable sample code demonstrating @value{GDBN}'s overlay support.
15557
15558 However, the @value{GDBN} source distribution does contain an overlaid
15559 program, with linker scripts for a few systems, as part of its test
15560 suite. The program consists of the following files from
15561 @file{gdb/testsuite/gdb.base}:
15562
15563 @table @file
15564 @item overlays.c
15565 The main program file.
15566 @item ovlymgr.c
15567 A simple overlay manager, used by @file{overlays.c}.
15568 @item foo.c
15569 @itemx bar.c
15570 @itemx baz.c
15571 @itemx grbx.c
15572 Overlay modules, loaded and used by @file{overlays.c}.
15573 @item d10v.ld
15574 @itemx m32r.ld
15575 Linker scripts for linking the test program on the @code{d10v-elf}
15576 and @code{m32r-elf} targets.
15577 @end table
15578
15579 You can build the test program using the @code{d10v-elf} GCC
15580 cross-compiler like this:
15581
15582 @smallexample
15583 $ d10v-elf-gcc -g -c overlays.c
15584 $ d10v-elf-gcc -g -c ovlymgr.c
15585 $ d10v-elf-gcc -g -c foo.c
15586 $ d10v-elf-gcc -g -c bar.c
15587 $ d10v-elf-gcc -g -c baz.c
15588 $ d10v-elf-gcc -g -c grbx.c
15589 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15590 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15591 @end smallexample
15592
15593 The build process is identical for any other architecture, except that
15594 you must substitute the appropriate compiler and linker script for the
15595 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15596
15597
15598 @node Languages
15599 @chapter Using @value{GDBN} with Different Languages
15600 @cindex languages
15601
15602 Although programming languages generally have common aspects, they are
15603 rarely expressed in the same manner. For instance, in ANSI C,
15604 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15605 Modula-2, it is accomplished by @code{p^}. Values can also be
15606 represented (and displayed) differently. Hex numbers in C appear as
15607 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15608
15609 @cindex working language
15610 Language-specific information is built into @value{GDBN} for some languages,
15611 allowing you to express operations like the above in your program's
15612 native language, and allowing @value{GDBN} to output values in a manner
15613 consistent with the syntax of your program's native language. The
15614 language you use to build expressions is called the @dfn{working
15615 language}.
15616
15617 @menu
15618 * Setting:: Switching between source languages
15619 * Show:: Displaying the language
15620 * Checks:: Type and range checks
15621 * Supported Languages:: Supported languages
15622 * Unsupported Languages:: Unsupported languages
15623 @end menu
15624
15625 @node Setting
15626 @section Switching Between Source Languages
15627
15628 There are two ways to control the working language---either have @value{GDBN}
15629 set it automatically, or select it manually yourself. You can use the
15630 @code{set language} command for either purpose. On startup, @value{GDBN}
15631 defaults to setting the language automatically. The working language is
15632 used to determine how expressions you type are interpreted, how values
15633 are printed, etc.
15634
15635 In addition to the working language, every source file that
15636 @value{GDBN} knows about has its own working language. For some object
15637 file formats, the compiler might indicate which language a particular
15638 source file is in. However, most of the time @value{GDBN} infers the
15639 language from the name of the file. The language of a source file
15640 controls whether C@t{++} names are demangled---this way @code{backtrace} can
15641 show each frame appropriately for its own language. There is no way to
15642 set the language of a source file from within @value{GDBN}, but you can
15643 set the language associated with a filename extension. @xref{Show, ,
15644 Displaying the Language}.
15645
15646 This is most commonly a problem when you use a program, such
15647 as @code{cfront} or @code{f2c}, that generates C but is written in
15648 another language. In that case, make the
15649 program use @code{#line} directives in its C output; that way
15650 @value{GDBN} will know the correct language of the source code of the original
15651 program, and will display that source code, not the generated C code.
15652
15653 @menu
15654 * Filenames:: Filename extensions and languages.
15655 * Manually:: Setting the working language manually
15656 * Automatically:: Having @value{GDBN} infer the source language
15657 @end menu
15658
15659 @node Filenames
15660 @subsection List of Filename Extensions and Languages
15661
15662 If a source file name ends in one of the following extensions, then
15663 @value{GDBN} infers that its language is the one indicated.
15664
15665 @table @file
15666 @item .ada
15667 @itemx .ads
15668 @itemx .adb
15669 @itemx .a
15670 Ada source file.
15671
15672 @item .c
15673 C source file
15674
15675 @item .C
15676 @itemx .cc
15677 @itemx .cp
15678 @itemx .cpp
15679 @itemx .cxx
15680 @itemx .c++
15681 C@t{++} source file
15682
15683 @item .d
15684 D source file
15685
15686 @item .m
15687 Objective-C source file
15688
15689 @item .f
15690 @itemx .F
15691 Fortran source file
15692
15693 @item .mod
15694 Modula-2 source file
15695
15696 @item .s
15697 @itemx .S
15698 Assembler source file. This actually behaves almost like C, but
15699 @value{GDBN} does not skip over function prologues when stepping.
15700 @end table
15701
15702 In addition, you may set the language associated with a filename
15703 extension. @xref{Show, , Displaying the Language}.
15704
15705 @node Manually
15706 @subsection Setting the Working Language
15707
15708 If you allow @value{GDBN} to set the language automatically,
15709 expressions are interpreted the same way in your debugging session and
15710 your program.
15711
15712 @kindex set language
15713 If you wish, you may set the language manually. To do this, issue the
15714 command @samp{set language @var{lang}}, where @var{lang} is the name of
15715 a language, such as
15716 @code{c} or @code{modula-2}.
15717 For a list of the supported languages, type @samp{set language}.
15718
15719 Setting the language manually prevents @value{GDBN} from updating the working
15720 language automatically. This can lead to confusion if you try
15721 to debug a program when the working language is not the same as the
15722 source language, when an expression is acceptable to both
15723 languages---but means different things. For instance, if the current
15724 source file were written in C, and @value{GDBN} was parsing Modula-2, a
15725 command such as:
15726
15727 @smallexample
15728 print a = b + c
15729 @end smallexample
15730
15731 @noindent
15732 might not have the effect you intended. In C, this means to add
15733 @code{b} and @code{c} and place the result in @code{a}. The result
15734 printed would be the value of @code{a}. In Modula-2, this means to compare
15735 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
15736
15737 @node Automatically
15738 @subsection Having @value{GDBN} Infer the Source Language
15739
15740 To have @value{GDBN} set the working language automatically, use
15741 @samp{set language local} or @samp{set language auto}. @value{GDBN}
15742 then infers the working language. That is, when your program stops in a
15743 frame (usually by encountering a breakpoint), @value{GDBN} sets the
15744 working language to the language recorded for the function in that
15745 frame. If the language for a frame is unknown (that is, if the function
15746 or block corresponding to the frame was defined in a source file that
15747 does not have a recognized extension), the current working language is
15748 not changed, and @value{GDBN} issues a warning.
15749
15750 This may not seem necessary for most programs, which are written
15751 entirely in one source language. However, program modules and libraries
15752 written in one source language can be used by a main program written in
15753 a different source language. Using @samp{set language auto} in this
15754 case frees you from having to set the working language manually.
15755
15756 @node Show
15757 @section Displaying the Language
15758
15759 The following commands help you find out which language is the
15760 working language, and also what language source files were written in.
15761
15762 @table @code
15763 @item show language
15764 @anchor{show language}
15765 @kindex show language
15766 Display the current working language. This is the
15767 language you can use with commands such as @code{print} to
15768 build and compute expressions that may involve variables in your program.
15769
15770 @item info frame
15771 @kindex info frame@r{, show the source language}
15772 Display the source language for this frame. This language becomes the
15773 working language if you use an identifier from this frame.
15774 @xref{Frame Info, ,Information about a Frame}, to identify the other
15775 information listed here.
15776
15777 @item info source
15778 @kindex info source@r{, show the source language}
15779 Display the source language of this source file.
15780 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
15781 information listed here.
15782 @end table
15783
15784 In unusual circumstances, you may have source files with extensions
15785 not in the standard list. You can then set the extension associated
15786 with a language explicitly:
15787
15788 @table @code
15789 @item set extension-language @var{ext} @var{language}
15790 @kindex set extension-language
15791 Tell @value{GDBN} that source files with extension @var{ext} are to be
15792 assumed as written in the source language @var{language}.
15793
15794 @item info extensions
15795 @kindex info extensions
15796 List all the filename extensions and the associated languages.
15797 @end table
15798
15799 @node Checks
15800 @section Type and Range Checking
15801
15802 Some languages are designed to guard you against making seemingly common
15803 errors through a series of compile- and run-time checks. These include
15804 checking the type of arguments to functions and operators and making
15805 sure mathematical overflows are caught at run time. Checks such as
15806 these help to ensure a program's correctness once it has been compiled
15807 by eliminating type mismatches and providing active checks for range
15808 errors when your program is running.
15809
15810 By default @value{GDBN} checks for these errors according to the
15811 rules of the current source language. Although @value{GDBN} does not check
15812 the statements in your program, it can check expressions entered directly
15813 into @value{GDBN} for evaluation via the @code{print} command, for example.
15814
15815 @menu
15816 * Type Checking:: An overview of type checking
15817 * Range Checking:: An overview of range checking
15818 @end menu
15819
15820 @cindex type checking
15821 @cindex checks, type
15822 @node Type Checking
15823 @subsection An Overview of Type Checking
15824
15825 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
15826 arguments to operators and functions have to be of the correct type,
15827 otherwise an error occurs. These checks prevent type mismatch
15828 errors from ever causing any run-time problems. For example,
15829
15830 @smallexample
15831 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15832
15833 (@value{GDBP}) print obj.my_method (0)
15834 $1 = 2
15835 @exdent but
15836 (@value{GDBP}) print obj.my_method (0x1234)
15837 Cannot resolve method klass::my_method to any overloaded instance
15838 @end smallexample
15839
15840 The second example fails because in C@t{++} the integer constant
15841 @samp{0x1234} is not type-compatible with the pointer parameter type.
15842
15843 For the expressions you use in @value{GDBN} commands, you can tell
15844 @value{GDBN} to not enforce strict type checking or
15845 to treat any mismatches as errors and abandon the expression;
15846 When type checking is disabled, @value{GDBN} successfully evaluates
15847 expressions like the second example above.
15848
15849 Even if type checking is off, there may be other reasons
15850 related to type that prevent @value{GDBN} from evaluating an expression.
15851 For instance, @value{GDBN} does not know how to add an @code{int} and
15852 a @code{struct foo}. These particular type errors have nothing to do
15853 with the language in use and usually arise from expressions which make
15854 little sense to evaluate anyway.
15855
15856 @value{GDBN} provides some additional commands for controlling type checking:
15857
15858 @kindex set check type
15859 @kindex show check type
15860 @table @code
15861 @item set check type on
15862 @itemx set check type off
15863 Set strict type checking on or off. If any type mismatches occur in
15864 evaluating an expression while type checking is on, @value{GDBN} prints a
15865 message and aborts evaluation of the expression.
15866
15867 @item show check type
15868 Show the current setting of type checking and whether @value{GDBN}
15869 is enforcing strict type checking rules.
15870 @end table
15871
15872 @cindex range checking
15873 @cindex checks, range
15874 @node Range Checking
15875 @subsection An Overview of Range Checking
15876
15877 In some languages (such as Modula-2), it is an error to exceed the
15878 bounds of a type; this is enforced with run-time checks. Such range
15879 checking is meant to ensure program correctness by making sure
15880 computations do not overflow, or indices on an array element access do
15881 not exceed the bounds of the array.
15882
15883 For expressions you use in @value{GDBN} commands, you can tell
15884 @value{GDBN} to treat range errors in one of three ways: ignore them,
15885 always treat them as errors and abandon the expression, or issue
15886 warnings but evaluate the expression anyway.
15887
15888 A range error can result from numerical overflow, from exceeding an
15889 array index bound, or when you type a constant that is not a member
15890 of any type. Some languages, however, do not treat overflows as an
15891 error. In many implementations of C, mathematical overflow causes the
15892 result to ``wrap around'' to lower values---for example, if @var{m} is
15893 the largest integer value, and @var{s} is the smallest, then
15894
15895 @smallexample
15896 @var{m} + 1 @result{} @var{s}
15897 @end smallexample
15898
15899 This, too, is specific to individual languages, and in some cases
15900 specific to individual compilers or machines. @xref{Supported Languages, ,
15901 Supported Languages}, for further details on specific languages.
15902
15903 @value{GDBN} provides some additional commands for controlling the range checker:
15904
15905 @kindex set check range
15906 @kindex show check range
15907 @table @code
15908 @item set check range auto
15909 Set range checking on or off based on the current working language.
15910 @xref{Supported Languages, ,Supported Languages}, for the default settings for
15911 each language.
15912
15913 @item set check range on
15914 @itemx set check range off
15915 Set range checking on or off, overriding the default setting for the
15916 current working language. A warning is issued if the setting does not
15917 match the language default. If a range error occurs and range checking is on,
15918 then a message is printed and evaluation of the expression is aborted.
15919
15920 @item set check range warn
15921 Output messages when the @value{GDBN} range checker detects a range error,
15922 but attempt to evaluate the expression anyway. Evaluating the
15923 expression may still be impossible for other reasons, such as accessing
15924 memory that the process does not own (a typical example from many Unix
15925 systems).
15926
15927 @item show range
15928 Show the current setting of the range checker, and whether or not it is
15929 being set automatically by @value{GDBN}.
15930 @end table
15931
15932 @node Supported Languages
15933 @section Supported Languages
15934
15935 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
15936 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
15937 @c This is false ...
15938 Some @value{GDBN} features may be used in expressions regardless of the
15939 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
15940 and the @samp{@{type@}addr} construct (@pxref{Expressions,
15941 ,Expressions}) can be used with the constructs of any supported
15942 language.
15943
15944 The following sections detail to what degree each source language is
15945 supported by @value{GDBN}. These sections are not meant to be language
15946 tutorials or references, but serve only as a reference guide to what the
15947 @value{GDBN} expression parser accepts, and what input and output
15948 formats should look like for different languages. There are many good
15949 books written on each of these languages; please look to these for a
15950 language reference or tutorial.
15951
15952 @menu
15953 * C:: C and C@t{++}
15954 * D:: D
15955 * Go:: Go
15956 * Objective-C:: Objective-C
15957 * OpenCL C:: OpenCL C
15958 * Fortran:: Fortran
15959 * Pascal:: Pascal
15960 * Rust:: Rust
15961 * Modula-2:: Modula-2
15962 * Ada:: Ada
15963 @end menu
15964
15965 @node C
15966 @subsection C and C@t{++}
15967
15968 @cindex C and C@t{++}
15969 @cindex expressions in C or C@t{++}
15970
15971 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
15972 to both languages. Whenever this is the case, we discuss those languages
15973 together.
15974
15975 @cindex C@t{++}
15976 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
15977 @cindex @sc{gnu} C@t{++}
15978 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
15979 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
15980 effectively, you must compile your C@t{++} programs with a supported
15981 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
15982 compiler (@code{aCC}).
15983
15984 @menu
15985 * C Operators:: C and C@t{++} operators
15986 * C Constants:: C and C@t{++} constants
15987 * C Plus Plus Expressions:: C@t{++} expressions
15988 * C Defaults:: Default settings for C and C@t{++}
15989 * C Checks:: C and C@t{++} type and range checks
15990 * Debugging C:: @value{GDBN} and C
15991 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
15992 * Decimal Floating Point:: Numbers in Decimal Floating Point format
15993 @end menu
15994
15995 @node C Operators
15996 @subsubsection C and C@t{++} Operators
15997
15998 @cindex C and C@t{++} operators
15999
16000 Operators must be defined on values of specific types. For instance,
16001 @code{+} is defined on numbers, but not on structures. Operators are
16002 often defined on groups of types.
16003
16004 For the purposes of C and C@t{++}, the following definitions hold:
16005
16006 @itemize @bullet
16007
16008 @item
16009 @emph{Integral types} include @code{int} with any of its storage-class
16010 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16011
16012 @item
16013 @emph{Floating-point types} include @code{float}, @code{double}, and
16014 @code{long double} (if supported by the target platform).
16015
16016 @item
16017 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16018
16019 @item
16020 @emph{Scalar types} include all of the above.
16021
16022 @end itemize
16023
16024 @noindent
16025 The following operators are supported. They are listed here
16026 in order of increasing precedence:
16027
16028 @table @code
16029 @item ,
16030 The comma or sequencing operator. Expressions in a comma-separated list
16031 are evaluated from left to right, with the result of the entire
16032 expression being the last expression evaluated.
16033
16034 @item =
16035 Assignment. The value of an assignment expression is the value
16036 assigned. Defined on scalar types.
16037
16038 @item @var{op}=
16039 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16040 and translated to @w{@code{@var{a} = @var{a op b}}}.
16041 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16042 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16043 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16044
16045 @item ?:
16046 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16047 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16048 should be of an integral type.
16049
16050 @item ||
16051 Logical @sc{or}. Defined on integral types.
16052
16053 @item &&
16054 Logical @sc{and}. Defined on integral types.
16055
16056 @item |
16057 Bitwise @sc{or}. Defined on integral types.
16058
16059 @item ^
16060 Bitwise exclusive-@sc{or}. Defined on integral types.
16061
16062 @item &
16063 Bitwise @sc{and}. Defined on integral types.
16064
16065 @item ==@r{, }!=
16066 Equality and inequality. Defined on scalar types. The value of these
16067 expressions is 0 for false and non-zero for true.
16068
16069 @item <@r{, }>@r{, }<=@r{, }>=
16070 Less than, greater than, less than or equal, greater than or equal.
16071 Defined on scalar types. The value of these expressions is 0 for false
16072 and non-zero for true.
16073
16074 @item <<@r{, }>>
16075 left shift, and right shift. Defined on integral types.
16076
16077 @item @@
16078 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16079
16080 @item +@r{, }-
16081 Addition and subtraction. Defined on integral types, floating-point types and
16082 pointer types.
16083
16084 @item *@r{, }/@r{, }%
16085 Multiplication, division, and modulus. Multiplication and division are
16086 defined on integral and floating-point types. Modulus is defined on
16087 integral types.
16088
16089 @item ++@r{, }--
16090 Increment and decrement. When appearing before a variable, the
16091 operation is performed before the variable is used in an expression;
16092 when appearing after it, the variable's value is used before the
16093 operation takes place.
16094
16095 @item *
16096 Pointer dereferencing. Defined on pointer types. Same precedence as
16097 @code{++}.
16098
16099 @item &
16100 Address operator. Defined on variables. Same precedence as @code{++}.
16101
16102 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16103 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16104 to examine the address
16105 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16106 stored.
16107
16108 @item -
16109 Negative. Defined on integral and floating-point types. Same
16110 precedence as @code{++}.
16111
16112 @item !
16113 Logical negation. Defined on integral types. Same precedence as
16114 @code{++}.
16115
16116 @item ~
16117 Bitwise complement operator. Defined on integral types. Same precedence as
16118 @code{++}.
16119
16120
16121 @item .@r{, }->
16122 Structure member, and pointer-to-structure member. For convenience,
16123 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16124 pointer based on the stored type information.
16125 Defined on @code{struct} and @code{union} data.
16126
16127 @item .*@r{, }->*
16128 Dereferences of pointers to members.
16129
16130 @item []
16131 Array indexing. @code{@var{a}[@var{i}]} is defined as
16132 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16133
16134 @item ()
16135 Function parameter list. Same precedence as @code{->}.
16136
16137 @item ::
16138 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16139 and @code{class} types.
16140
16141 @item ::
16142 Doubled colons also represent the @value{GDBN} scope operator
16143 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16144 above.
16145 @end table
16146
16147 If an operator is redefined in the user code, @value{GDBN} usually
16148 attempts to invoke the redefined version instead of using the operator's
16149 predefined meaning.
16150
16151 @node C Constants
16152 @subsubsection C and C@t{++} Constants
16153
16154 @cindex C and C@t{++} constants
16155
16156 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16157 following ways:
16158
16159 @itemize @bullet
16160 @item
16161 Integer constants are a sequence of digits. Octal constants are
16162 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16163 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16164 @samp{l}, specifying that the constant should be treated as a
16165 @code{long} value.
16166
16167 @item
16168 Floating point constants are a sequence of digits, followed by a decimal
16169 point, followed by a sequence of digits, and optionally followed by an
16170 exponent. An exponent is of the form:
16171 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16172 sequence of digits. The @samp{+} is optional for positive exponents.
16173 A floating-point constant may also end with a letter @samp{f} or
16174 @samp{F}, specifying that the constant should be treated as being of
16175 the @code{float} (as opposed to the default @code{double}) type; or with
16176 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16177 constant.
16178
16179 @item
16180 Enumerated constants consist of enumerated identifiers, or their
16181 integral equivalents.
16182
16183 @item
16184 Character constants are a single character surrounded by single quotes
16185 (@code{'}), or a number---the ordinal value of the corresponding character
16186 (usually its @sc{ascii} value). Within quotes, the single character may
16187 be represented by a letter or by @dfn{escape sequences}, which are of
16188 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16189 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16190 @samp{@var{x}} is a predefined special character---for example,
16191 @samp{\n} for newline.
16192
16193 Wide character constants can be written by prefixing a character
16194 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16195 form of @samp{x}. The target wide character set is used when
16196 computing the value of this constant (@pxref{Character Sets}).
16197
16198 @item
16199 String constants are a sequence of character constants surrounded by
16200 double quotes (@code{"}). Any valid character constant (as described
16201 above) may appear. Double quotes within the string must be preceded by
16202 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16203 characters.
16204
16205 Wide string constants can be written by prefixing a string constant
16206 with @samp{L}, as in C. The target wide character set is used when
16207 computing the value of this constant (@pxref{Character Sets}).
16208
16209 @item
16210 Pointer constants are an integral value. You can also write pointers
16211 to constants using the C operator @samp{&}.
16212
16213 @item
16214 Array constants are comma-separated lists surrounded by braces @samp{@{}
16215 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16216 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16217 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16218 @end itemize
16219
16220 @node C Plus Plus Expressions
16221 @subsubsection C@t{++} Expressions
16222
16223 @cindex expressions in C@t{++}
16224 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16225
16226 @cindex debugging C@t{++} programs
16227 @cindex C@t{++} compilers
16228 @cindex debug formats and C@t{++}
16229 @cindex @value{NGCC} and C@t{++}
16230 @quotation
16231 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16232 the proper compiler and the proper debug format. Currently,
16233 @value{GDBN} works best when debugging C@t{++} code that is compiled
16234 with the most recent version of @value{NGCC} possible. The DWARF
16235 debugging format is preferred; @value{NGCC} defaults to this on most
16236 popular platforms. Other compilers and/or debug formats are likely to
16237 work badly or not at all when using @value{GDBN} to debug C@t{++}
16238 code. @xref{Compilation}.
16239 @end quotation
16240
16241 @enumerate
16242
16243 @cindex member functions
16244 @item
16245 Member function calls are allowed; you can use expressions like
16246
16247 @smallexample
16248 count = aml->GetOriginal(x, y)
16249 @end smallexample
16250
16251 @vindex this@r{, inside C@t{++} member functions}
16252 @cindex namespace in C@t{++}
16253 @item
16254 While a member function is active (in the selected stack frame), your
16255 expressions have the same namespace available as the member function;
16256 that is, @value{GDBN} allows implicit references to the class instance
16257 pointer @code{this} following the same rules as C@t{++}. @code{using}
16258 declarations in the current scope are also respected by @value{GDBN}.
16259
16260 @cindex call overloaded functions
16261 @cindex overloaded functions, calling
16262 @cindex type conversions in C@t{++}
16263 @item
16264 You can call overloaded functions; @value{GDBN} resolves the function
16265 call to the right definition, with some restrictions. @value{GDBN} does not
16266 perform overload resolution involving user-defined type conversions,
16267 calls to constructors, or instantiations of templates that do not exist
16268 in the program. It also cannot handle ellipsis argument lists or
16269 default arguments.
16270
16271 It does perform integral conversions and promotions, floating-point
16272 promotions, arithmetic conversions, pointer conversions, conversions of
16273 class objects to base classes, and standard conversions such as those of
16274 functions or arrays to pointers; it requires an exact match on the
16275 number of function arguments.
16276
16277 Overload resolution is always performed, unless you have specified
16278 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16279 ,@value{GDBN} Features for C@t{++}}.
16280
16281 You must specify @code{set overload-resolution off} in order to use an
16282 explicit function signature to call an overloaded function, as in
16283 @smallexample
16284 p 'foo(char,int)'('x', 13)
16285 @end smallexample
16286
16287 The @value{GDBN} command-completion facility can simplify this;
16288 see @ref{Completion, ,Command Completion}.
16289
16290 @cindex reference declarations
16291 @item
16292 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16293 references; you can use them in expressions just as you do in C@t{++}
16294 source---they are automatically dereferenced.
16295
16296 In the parameter list shown when @value{GDBN} displays a frame, the values of
16297 reference variables are not displayed (unlike other variables); this
16298 avoids clutter, since references are often used for large structures.
16299 The @emph{address} of a reference variable is always shown, unless
16300 you have specified @samp{set print address off}.
16301
16302 @item
16303 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16304 expressions can use it just as expressions in your program do. Since
16305 one scope may be defined in another, you can use @code{::} repeatedly if
16306 necessary, for example in an expression like
16307 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16308 resolving name scope by reference to source files, in both C and C@t{++}
16309 debugging (@pxref{Variables, ,Program Variables}).
16310
16311 @item
16312 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16313 specification.
16314 @end enumerate
16315
16316 @node C Defaults
16317 @subsubsection C and C@t{++} Defaults
16318
16319 @cindex C and C@t{++} defaults
16320
16321 If you allow @value{GDBN} to set range checking automatically, it
16322 defaults to @code{off} whenever the working language changes to
16323 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16324 selects the working language.
16325
16326 If you allow @value{GDBN} to set the language automatically, it
16327 recognizes source files whose names end with @file{.c}, @file{.C}, or
16328 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16329 these files, it sets the working language to C or C@t{++}.
16330 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16331 for further details.
16332
16333 @node C Checks
16334 @subsubsection C and C@t{++} Type and Range Checks
16335
16336 @cindex C and C@t{++} checks
16337
16338 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16339 checking is used. However, if you turn type checking off, @value{GDBN}
16340 will allow certain non-standard conversions, such as promoting integer
16341 constants to pointers.
16342
16343 Range checking, if turned on, is done on mathematical operations. Array
16344 indices are not checked, since they are often used to index a pointer
16345 that is not itself an array.
16346
16347 @node Debugging C
16348 @subsubsection @value{GDBN} and C
16349
16350 The @code{set print union} and @code{show print union} commands apply to
16351 the @code{union} type. When set to @samp{on}, any @code{union} that is
16352 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16353 appears as @samp{@{...@}}.
16354
16355 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16356 with pointers and a memory allocation function. @xref{Expressions,
16357 ,Expressions}.
16358
16359 @node Debugging C Plus Plus
16360 @subsubsection @value{GDBN} Features for C@t{++}
16361
16362 @cindex commands for C@t{++}
16363
16364 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16365 designed specifically for use with C@t{++}. Here is a summary:
16366
16367 @table @code
16368 @cindex break in overloaded functions
16369 @item @r{breakpoint menus}
16370 When you want a breakpoint in a function whose name is overloaded,
16371 @value{GDBN} has the capability to display a menu of possible breakpoint
16372 locations to help you specify which function definition you want.
16373 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16374
16375 @cindex overloading in C@t{++}
16376 @item rbreak @var{regex}
16377 Setting breakpoints using regular expressions is helpful for setting
16378 breakpoints on overloaded functions that are not members of any special
16379 classes.
16380 @xref{Set Breaks, ,Setting Breakpoints}.
16381
16382 @cindex C@t{++} exception handling
16383 @item catch throw
16384 @itemx catch rethrow
16385 @itemx catch catch
16386 Debug C@t{++} exception handling using these commands. @xref{Set
16387 Catchpoints, , Setting Catchpoints}.
16388
16389 @cindex inheritance
16390 @item ptype @var{typename}
16391 Print inheritance relationships as well as other information for type
16392 @var{typename}.
16393 @xref{Symbols, ,Examining the Symbol Table}.
16394
16395 @item info vtbl @var{expression}.
16396 The @code{info vtbl} command can be used to display the virtual
16397 method tables of the object computed by @var{expression}. This shows
16398 one entry per virtual table; there may be multiple virtual tables when
16399 multiple inheritance is in use.
16400
16401 @cindex C@t{++} demangling
16402 @item demangle @var{name}
16403 Demangle @var{name}.
16404 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16405
16406 @cindex C@t{++} symbol display
16407 @item set print demangle
16408 @itemx show print demangle
16409 @itemx set print asm-demangle
16410 @itemx show print asm-demangle
16411 Control whether C@t{++} symbols display in their source form, both when
16412 displaying code as C@t{++} source and when displaying disassemblies.
16413 @xref{Print Settings, ,Print Settings}.
16414
16415 @item set print object
16416 @itemx show print object
16417 Choose whether to print derived (actual) or declared types of objects.
16418 @xref{Print Settings, ,Print Settings}.
16419
16420 @item set print vtbl
16421 @itemx show print vtbl
16422 Control the format for printing virtual function tables.
16423 @xref{Print Settings, ,Print Settings}.
16424 (The @code{vtbl} commands do not work on programs compiled with the HP
16425 ANSI C@t{++} compiler (@code{aCC}).)
16426
16427 @kindex set overload-resolution
16428 @cindex overloaded functions, overload resolution
16429 @item set overload-resolution on
16430 Enable overload resolution for C@t{++} expression evaluation. The default
16431 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16432 and searches for a function whose signature matches the argument types,
16433 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16434 Expressions, ,C@t{++} Expressions}, for details).
16435 If it cannot find a match, it emits a message.
16436
16437 @item set overload-resolution off
16438 Disable overload resolution for C@t{++} expression evaluation. For
16439 overloaded functions that are not class member functions, @value{GDBN}
16440 chooses the first function of the specified name that it finds in the
16441 symbol table, whether or not its arguments are of the correct type. For
16442 overloaded functions that are class member functions, @value{GDBN}
16443 searches for a function whose signature @emph{exactly} matches the
16444 argument types.
16445
16446 @kindex show overload-resolution
16447 @item show overload-resolution
16448 Show the current setting of overload resolution.
16449
16450 @item @r{Overloaded symbol names}
16451 You can specify a particular definition of an overloaded symbol, using
16452 the same notation that is used to declare such symbols in C@t{++}: type
16453 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16454 also use the @value{GDBN} command-line word completion facilities to list the
16455 available choices, or to finish the type list for you.
16456 @xref{Completion,, Command Completion}, for details on how to do this.
16457
16458 @item @r{Breakpoints in functions with ABI tags}
16459
16460 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16461 correspond to changes in the ABI of a type, function, or variable that
16462 would not otherwise be reflected in a mangled name. See
16463 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16464 for more detail.
16465
16466 The ABI tags are visible in C@t{++} demangled names. For example, a
16467 function that returns a std::string:
16468
16469 @smallexample
16470 std::string function(int);
16471 @end smallexample
16472
16473 @noindent
16474 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16475 tag, and @value{GDBN} displays the symbol like this:
16476
16477 @smallexample
16478 function[abi:cxx11](int)
16479 @end smallexample
16480
16481 You can set a breakpoint on such functions simply as if they had no
16482 tag. For example:
16483
16484 @smallexample
16485 (gdb) b function(int)
16486 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16487 (gdb) info breakpoints
16488 Num Type Disp Enb Address What
16489 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16490 at main.cc:10
16491 @end smallexample
16492
16493 On the rare occasion you need to disambiguate between different ABI
16494 tags, you can do so by simply including the ABI tag in the function
16495 name, like:
16496
16497 @smallexample
16498 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16499 @end smallexample
16500 @end table
16501
16502 @node Decimal Floating Point
16503 @subsubsection Decimal Floating Point format
16504 @cindex decimal floating point format
16505
16506 @value{GDBN} can examine, set and perform computations with numbers in
16507 decimal floating point format, which in the C language correspond to the
16508 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16509 specified by the extension to support decimal floating-point arithmetic.
16510
16511 There are two encodings in use, depending on the architecture: BID (Binary
16512 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16513 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16514 configured target.
16515
16516 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16517 to manipulate decimal floating point numbers, it is not possible to convert
16518 (using a cast, for example) integers wider than 32-bit to decimal float.
16519
16520 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16521 point computations, error checking in decimal float operations ignores
16522 underflow, overflow and divide by zero exceptions.
16523
16524 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16525 to inspect @code{_Decimal128} values stored in floating point registers.
16526 See @ref{PowerPC,,PowerPC} for more details.
16527
16528 @node D
16529 @subsection D
16530
16531 @cindex D
16532 @value{GDBN} can be used to debug programs written in D and compiled with
16533 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16534 specific feature --- dynamic arrays.
16535
16536 @node Go
16537 @subsection Go
16538
16539 @cindex Go (programming language)
16540 @value{GDBN} can be used to debug programs written in Go and compiled with
16541 @file{gccgo} or @file{6g} compilers.
16542
16543 Here is a summary of the Go-specific features and restrictions:
16544
16545 @table @code
16546 @cindex current Go package
16547 @item The current Go package
16548 The name of the current package does not need to be specified when
16549 specifying global variables and functions.
16550
16551 For example, given the program:
16552
16553 @example
16554 package main
16555 var myglob = "Shall we?"
16556 func main () @{
16557 // ...
16558 @}
16559 @end example
16560
16561 When stopped inside @code{main} either of these work:
16562
16563 @example
16564 (gdb) p myglob
16565 (gdb) p main.myglob
16566 @end example
16567
16568 @cindex builtin Go types
16569 @item Builtin Go types
16570 The @code{string} type is recognized by @value{GDBN} and is printed
16571 as a string.
16572
16573 @cindex builtin Go functions
16574 @item Builtin Go functions
16575 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16576 function and handles it internally.
16577
16578 @cindex restrictions on Go expressions
16579 @item Restrictions on Go expressions
16580 All Go operators are supported except @code{&^}.
16581 The Go @code{_} ``blank identifier'' is not supported.
16582 Automatic dereferencing of pointers is not supported.
16583 @end table
16584
16585 @node Objective-C
16586 @subsection Objective-C
16587
16588 @cindex Objective-C
16589 This section provides information about some commands and command
16590 options that are useful for debugging Objective-C code. See also
16591 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16592 few more commands specific to Objective-C support.
16593
16594 @menu
16595 * Method Names in Commands::
16596 * The Print Command with Objective-C::
16597 @end menu
16598
16599 @node Method Names in Commands
16600 @subsubsection Method Names in Commands
16601
16602 The following commands have been extended to accept Objective-C method
16603 names as line specifications:
16604
16605 @kindex clear@r{, and Objective-C}
16606 @kindex break@r{, and Objective-C}
16607 @kindex info line@r{, and Objective-C}
16608 @kindex jump@r{, and Objective-C}
16609 @kindex list@r{, and Objective-C}
16610 @itemize
16611 @item @code{clear}
16612 @item @code{break}
16613 @item @code{info line}
16614 @item @code{jump}
16615 @item @code{list}
16616 @end itemize
16617
16618 A fully qualified Objective-C method name is specified as
16619
16620 @smallexample
16621 -[@var{Class} @var{methodName}]
16622 @end smallexample
16623
16624 where the minus sign is used to indicate an instance method and a
16625 plus sign (not shown) is used to indicate a class method. The class
16626 name @var{Class} and method name @var{methodName} are enclosed in
16627 brackets, similar to the way messages are specified in Objective-C
16628 source code. For example, to set a breakpoint at the @code{create}
16629 instance method of class @code{Fruit} in the program currently being
16630 debugged, enter:
16631
16632 @smallexample
16633 break -[Fruit create]
16634 @end smallexample
16635
16636 To list ten program lines around the @code{initialize} class method,
16637 enter:
16638
16639 @smallexample
16640 list +[NSText initialize]
16641 @end smallexample
16642
16643 In the current version of @value{GDBN}, the plus or minus sign is
16644 required. In future versions of @value{GDBN}, the plus or minus
16645 sign will be optional, but you can use it to narrow the search. It
16646 is also possible to specify just a method name:
16647
16648 @smallexample
16649 break create
16650 @end smallexample
16651
16652 You must specify the complete method name, including any colons. If
16653 your program's source files contain more than one @code{create} method,
16654 you'll be presented with a numbered list of classes that implement that
16655 method. Indicate your choice by number, or type @samp{0} to exit if
16656 none apply.
16657
16658 As another example, to clear a breakpoint established at the
16659 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16660
16661 @smallexample
16662 clear -[NSWindow makeKeyAndOrderFront:]
16663 @end smallexample
16664
16665 @node The Print Command with Objective-C
16666 @subsubsection The Print Command With Objective-C
16667 @cindex Objective-C, print objects
16668 @kindex print-object
16669 @kindex po @r{(@code{print-object})}
16670
16671 The print command has also been extended to accept methods. For example:
16672
16673 @smallexample
16674 print -[@var{object} hash]
16675 @end smallexample
16676
16677 @cindex print an Objective-C object description
16678 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16679 @noindent
16680 will tell @value{GDBN} to send the @code{hash} message to @var{object}
16681 and print the result. Also, an additional command has been added,
16682 @code{print-object} or @code{po} for short, which is meant to print
16683 the description of an object. However, this command may only work
16684 with certain Objective-C libraries that have a particular hook
16685 function, @code{_NSPrintForDebugger}, defined.
16686
16687 @node OpenCL C
16688 @subsection OpenCL C
16689
16690 @cindex OpenCL C
16691 This section provides information about @value{GDBN}s OpenCL C support.
16692
16693 @menu
16694 * OpenCL C Datatypes::
16695 * OpenCL C Expressions::
16696 * OpenCL C Operators::
16697 @end menu
16698
16699 @node OpenCL C Datatypes
16700 @subsubsection OpenCL C Datatypes
16701
16702 @cindex OpenCL C Datatypes
16703 @value{GDBN} supports the builtin scalar and vector datatypes specified
16704 by OpenCL 1.1. In addition the half- and double-precision floating point
16705 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16706 extensions are also known to @value{GDBN}.
16707
16708 @node OpenCL C Expressions
16709 @subsubsection OpenCL C Expressions
16710
16711 @cindex OpenCL C Expressions
16712 @value{GDBN} supports accesses to vector components including the access as
16713 lvalue where possible. Since OpenCL C is based on C99 most C expressions
16714 supported by @value{GDBN} can be used as well.
16715
16716 @node OpenCL C Operators
16717 @subsubsection OpenCL C Operators
16718
16719 @cindex OpenCL C Operators
16720 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16721 vector data types.
16722
16723 @node Fortran
16724 @subsection Fortran
16725 @cindex Fortran-specific support in @value{GDBN}
16726
16727 @value{GDBN} can be used to debug programs written in Fortran, but it
16728 currently supports only the features of Fortran 77 language.
16729
16730 @cindex trailing underscore, in Fortran symbols
16731 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16732 among them) append an underscore to the names of variables and
16733 functions. When you debug programs compiled by those compilers, you
16734 will need to refer to variables and functions with a trailing
16735 underscore.
16736
16737 @menu
16738 * Fortran Operators:: Fortran operators and expressions
16739 * Fortran Defaults:: Default settings for Fortran
16740 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
16741 @end menu
16742
16743 @node Fortran Operators
16744 @subsubsection Fortran Operators and Expressions
16745
16746 @cindex Fortran operators and expressions
16747
16748 Operators must be defined on values of specific types. For instance,
16749 @code{+} is defined on numbers, but not on characters or other non-
16750 arithmetic types. Operators are often defined on groups of types.
16751
16752 @table @code
16753 @item **
16754 The exponentiation operator. It raises the first operand to the power
16755 of the second one.
16756
16757 @item :
16758 The range operator. Normally used in the form of array(low:high) to
16759 represent a section of array.
16760
16761 @item %
16762 The access component operator. Normally used to access elements in derived
16763 types. Also suitable for unions. As unions aren't part of regular Fortran,
16764 this can only happen when accessing a register that uses a gdbarch-defined
16765 union type.
16766 @item ::
16767 The scope operator. Normally used to access variables in modules or
16768 to set breakpoints on subroutines nested in modules or in other
16769 subroutines (internal subroutines).
16770 @end table
16771
16772 @node Fortran Defaults
16773 @subsubsection Fortran Defaults
16774
16775 @cindex Fortran Defaults
16776
16777 Fortran symbols are usually case-insensitive, so @value{GDBN} by
16778 default uses case-insensitive matches for Fortran symbols. You can
16779 change that with the @samp{set case-insensitive} command, see
16780 @ref{Symbols}, for the details.
16781
16782 @node Special Fortran Commands
16783 @subsubsection Special Fortran Commands
16784
16785 @cindex Special Fortran commands
16786
16787 @value{GDBN} has some commands to support Fortran-specific features,
16788 such as displaying common blocks.
16789
16790 @table @code
16791 @cindex @code{COMMON} blocks, Fortran
16792 @kindex info common
16793 @item info common @r{[}@var{common-name}@r{]}
16794 This command prints the values contained in the Fortran @code{COMMON}
16795 block whose name is @var{common-name}. With no argument, the names of
16796 all @code{COMMON} blocks visible at the current program location are
16797 printed.
16798 @end table
16799
16800 @node Pascal
16801 @subsection Pascal
16802
16803 @cindex Pascal support in @value{GDBN}, limitations
16804 Debugging Pascal programs which use sets, subranges, file variables, or
16805 nested functions does not currently work. @value{GDBN} does not support
16806 entering expressions, printing values, or similar features using Pascal
16807 syntax.
16808
16809 The Pascal-specific command @code{set print pascal_static-members}
16810 controls whether static members of Pascal objects are displayed.
16811 @xref{Print Settings, pascal_static-members}.
16812
16813 @node Rust
16814 @subsection Rust
16815
16816 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16817 Programming Language}. Type- and value-printing, and expression
16818 parsing, are reasonably complete. However, there are a few
16819 peculiarities and holes to be aware of.
16820
16821 @itemize @bullet
16822 @item
16823 Linespecs (@pxref{Specify Location}) are never relative to the current
16824 crate. Instead, they act as if there were a global namespace of
16825 crates, somewhat similar to the way @code{extern crate} behaves.
16826
16827 That is, if @value{GDBN} is stopped at a breakpoint in a function in
16828 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16829 to set a breakpoint in a function named @samp{f} in a crate named
16830 @samp{B}.
16831
16832 As a consequence of this approach, linespecs also cannot refer to
16833 items using @samp{self::} or @samp{super::}.
16834
16835 @item
16836 Because @value{GDBN} implements Rust name-lookup semantics in
16837 expressions, it will sometimes prepend the current crate to a name.
16838 For example, if @value{GDBN} is stopped at a breakpoint in the crate
16839 @samp{K}, then @code{print ::x::y} will try to find the symbol
16840 @samp{K::x::y}.
16841
16842 However, since it is useful to be able to refer to other crates when
16843 debugging, @value{GDBN} provides the @code{extern} extension to
16844 circumvent this. To use the extension, just put @code{extern} before
16845 a path expression to refer to the otherwise unavailable ``global''
16846 scope.
16847
16848 In the above example, if you wanted to refer to the symbol @samp{y} in
16849 the crate @samp{x}, you would use @code{print extern x::y}.
16850
16851 @item
16852 The Rust expression evaluator does not support ``statement-like''
16853 expressions such as @code{if} or @code{match}, or lambda expressions.
16854
16855 @item
16856 Tuple expressions are not implemented.
16857
16858 @item
16859 The Rust expression evaluator does not currently implement the
16860 @code{Drop} trait. Objects that may be created by the evaluator will
16861 never be destroyed.
16862
16863 @item
16864 @value{GDBN} does not implement type inference for generics. In order
16865 to call generic functions or otherwise refer to generic items, you
16866 will have to specify the type parameters manually.
16867
16868 @item
16869 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16870 cases this does not cause any problems. However, in an expression
16871 context, completing a generic function name will give syntactically
16872 invalid results. This happens because Rust requires the @samp{::}
16873 operator between the function name and its generic arguments. For
16874 example, @value{GDBN} might provide a completion like
16875 @code{crate::f<u32>}, where the parser would require
16876 @code{crate::f::<u32>}.
16877
16878 @item
16879 As of this writing, the Rust compiler (version 1.8) has a few holes in
16880 the debugging information it generates. These holes prevent certain
16881 features from being implemented by @value{GDBN}:
16882 @itemize @bullet
16883
16884 @item
16885 Method calls cannot be made via traits.
16886
16887 @item
16888 Operator overloading is not implemented.
16889
16890 @item
16891 When debugging in a monomorphized function, you cannot use the generic
16892 type names.
16893
16894 @item
16895 The type @code{Self} is not available.
16896
16897 @item
16898 @code{use} statements are not available, so some names may not be
16899 available in the crate.
16900 @end itemize
16901 @end itemize
16902
16903 @node Modula-2
16904 @subsection Modula-2
16905
16906 @cindex Modula-2, @value{GDBN} support
16907
16908 The extensions made to @value{GDBN} to support Modula-2 only support
16909 output from the @sc{gnu} Modula-2 compiler (which is currently being
16910 developed). Other Modula-2 compilers are not currently supported, and
16911 attempting to debug executables produced by them is most likely
16912 to give an error as @value{GDBN} reads in the executable's symbol
16913 table.
16914
16915 @cindex expressions in Modula-2
16916 @menu
16917 * M2 Operators:: Built-in operators
16918 * Built-In Func/Proc:: Built-in functions and procedures
16919 * M2 Constants:: Modula-2 constants
16920 * M2 Types:: Modula-2 types
16921 * M2 Defaults:: Default settings for Modula-2
16922 * Deviations:: Deviations from standard Modula-2
16923 * M2 Checks:: Modula-2 type and range checks
16924 * M2 Scope:: The scope operators @code{::} and @code{.}
16925 * GDB/M2:: @value{GDBN} and Modula-2
16926 @end menu
16927
16928 @node M2 Operators
16929 @subsubsection Operators
16930 @cindex Modula-2 operators
16931
16932 Operators must be defined on values of specific types. For instance,
16933 @code{+} is defined on numbers, but not on structures. Operators are
16934 often defined on groups of types. For the purposes of Modula-2, the
16935 following definitions hold:
16936
16937 @itemize @bullet
16938
16939 @item
16940 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
16941 their subranges.
16942
16943 @item
16944 @emph{Character types} consist of @code{CHAR} and its subranges.
16945
16946 @item
16947 @emph{Floating-point types} consist of @code{REAL}.
16948
16949 @item
16950 @emph{Pointer types} consist of anything declared as @code{POINTER TO
16951 @var{type}}.
16952
16953 @item
16954 @emph{Scalar types} consist of all of the above.
16955
16956 @item
16957 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
16958
16959 @item
16960 @emph{Boolean types} consist of @code{BOOLEAN}.
16961 @end itemize
16962
16963 @noindent
16964 The following operators are supported, and appear in order of
16965 increasing precedence:
16966
16967 @table @code
16968 @item ,
16969 Function argument or array index separator.
16970
16971 @item :=
16972 Assignment. The value of @var{var} @code{:=} @var{value} is
16973 @var{value}.
16974
16975 @item <@r{, }>
16976 Less than, greater than on integral, floating-point, or enumerated
16977 types.
16978
16979 @item <=@r{, }>=
16980 Less than or equal to, greater than or equal to
16981 on integral, floating-point and enumerated types, or set inclusion on
16982 set types. Same precedence as @code{<}.
16983
16984 @item =@r{, }<>@r{, }#
16985 Equality and two ways of expressing inequality, valid on scalar types.
16986 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
16987 available for inequality, since @code{#} conflicts with the script
16988 comment character.
16989
16990 @item IN
16991 Set membership. Defined on set types and the types of their members.
16992 Same precedence as @code{<}.
16993
16994 @item OR
16995 Boolean disjunction. Defined on boolean types.
16996
16997 @item AND@r{, }&
16998 Boolean conjunction. Defined on boolean types.
16999
17000 @item @@
17001 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17002
17003 @item +@r{, }-
17004 Addition and subtraction on integral and floating-point types, or union
17005 and difference on set types.
17006
17007 @item *
17008 Multiplication on integral and floating-point types, or set intersection
17009 on set types.
17010
17011 @item /
17012 Division on floating-point types, or symmetric set difference on set
17013 types. Same precedence as @code{*}.
17014
17015 @item DIV@r{, }MOD
17016 Integer division and remainder. Defined on integral types. Same
17017 precedence as @code{*}.
17018
17019 @item -
17020 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17021
17022 @item ^
17023 Pointer dereferencing. Defined on pointer types.
17024
17025 @item NOT
17026 Boolean negation. Defined on boolean types. Same precedence as
17027 @code{^}.
17028
17029 @item .
17030 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17031 precedence as @code{^}.
17032
17033 @item []
17034 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17035
17036 @item ()
17037 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17038 as @code{^}.
17039
17040 @item ::@r{, }.
17041 @value{GDBN} and Modula-2 scope operators.
17042 @end table
17043
17044 @quotation
17045 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17046 treats the use of the operator @code{IN}, or the use of operators
17047 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17048 @code{<=}, and @code{>=} on sets as an error.
17049 @end quotation
17050
17051
17052 @node Built-In Func/Proc
17053 @subsubsection Built-in Functions and Procedures
17054 @cindex Modula-2 built-ins
17055
17056 Modula-2 also makes available several built-in procedures and functions.
17057 In describing these, the following metavariables are used:
17058
17059 @table @var
17060
17061 @item a
17062 represents an @code{ARRAY} variable.
17063
17064 @item c
17065 represents a @code{CHAR} constant or variable.
17066
17067 @item i
17068 represents a variable or constant of integral type.
17069
17070 @item m
17071 represents an identifier that belongs to a set. Generally used in the
17072 same function with the metavariable @var{s}. The type of @var{s} should
17073 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17074
17075 @item n
17076 represents a variable or constant of integral or floating-point type.
17077
17078 @item r
17079 represents a variable or constant of floating-point type.
17080
17081 @item t
17082 represents a type.
17083
17084 @item v
17085 represents a variable.
17086
17087 @item x
17088 represents a variable or constant of one of many types. See the
17089 explanation of the function for details.
17090 @end table
17091
17092 All Modula-2 built-in procedures also return a result, described below.
17093
17094 @table @code
17095 @item ABS(@var{n})
17096 Returns the absolute value of @var{n}.
17097
17098 @item CAP(@var{c})
17099 If @var{c} is a lower case letter, it returns its upper case
17100 equivalent, otherwise it returns its argument.
17101
17102 @item CHR(@var{i})
17103 Returns the character whose ordinal value is @var{i}.
17104
17105 @item DEC(@var{v})
17106 Decrements the value in the variable @var{v} by one. Returns the new value.
17107
17108 @item DEC(@var{v},@var{i})
17109 Decrements the value in the variable @var{v} by @var{i}. Returns the
17110 new value.
17111
17112 @item EXCL(@var{m},@var{s})
17113 Removes the element @var{m} from the set @var{s}. Returns the new
17114 set.
17115
17116 @item FLOAT(@var{i})
17117 Returns the floating point equivalent of the integer @var{i}.
17118
17119 @item HIGH(@var{a})
17120 Returns the index of the last member of @var{a}.
17121
17122 @item INC(@var{v})
17123 Increments the value in the variable @var{v} by one. Returns the new value.
17124
17125 @item INC(@var{v},@var{i})
17126 Increments the value in the variable @var{v} by @var{i}. Returns the
17127 new value.
17128
17129 @item INCL(@var{m},@var{s})
17130 Adds the element @var{m} to the set @var{s} if it is not already
17131 there. Returns the new set.
17132
17133 @item MAX(@var{t})
17134 Returns the maximum value of the type @var{t}.
17135
17136 @item MIN(@var{t})
17137 Returns the minimum value of the type @var{t}.
17138
17139 @item ODD(@var{i})
17140 Returns boolean TRUE if @var{i} is an odd number.
17141
17142 @item ORD(@var{x})
17143 Returns the ordinal value of its argument. For example, the ordinal
17144 value of a character is its @sc{ascii} value (on machines supporting
17145 the @sc{ascii} character set). The argument @var{x} must be of an
17146 ordered type, which include integral, character and enumerated types.
17147
17148 @item SIZE(@var{x})
17149 Returns the size of its argument. The argument @var{x} can be a
17150 variable or a type.
17151
17152 @item TRUNC(@var{r})
17153 Returns the integral part of @var{r}.
17154
17155 @item TSIZE(@var{x})
17156 Returns the size of its argument. The argument @var{x} can be a
17157 variable or a type.
17158
17159 @item VAL(@var{t},@var{i})
17160 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17161 @end table
17162
17163 @quotation
17164 @emph{Warning:} Sets and their operations are not yet supported, so
17165 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17166 an error.
17167 @end quotation
17168
17169 @cindex Modula-2 constants
17170 @node M2 Constants
17171 @subsubsection Constants
17172
17173 @value{GDBN} allows you to express the constants of Modula-2 in the following
17174 ways:
17175
17176 @itemize @bullet
17177
17178 @item
17179 Integer constants are simply a sequence of digits. When used in an
17180 expression, a constant is interpreted to be type-compatible with the
17181 rest of the expression. Hexadecimal integers are specified by a
17182 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17183
17184 @item
17185 Floating point constants appear as a sequence of digits, followed by a
17186 decimal point and another sequence of digits. An optional exponent can
17187 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17188 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17189 digits of the floating point constant must be valid decimal (base 10)
17190 digits.
17191
17192 @item
17193 Character constants consist of a single character enclosed by a pair of
17194 like quotes, either single (@code{'}) or double (@code{"}). They may
17195 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17196 followed by a @samp{C}.
17197
17198 @item
17199 String constants consist of a sequence of characters enclosed by a
17200 pair of like quotes, either single (@code{'}) or double (@code{"}).
17201 Escape sequences in the style of C are also allowed. @xref{C
17202 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17203 sequences.
17204
17205 @item
17206 Enumerated constants consist of an enumerated identifier.
17207
17208 @item
17209 Boolean constants consist of the identifiers @code{TRUE} and
17210 @code{FALSE}.
17211
17212 @item
17213 Pointer constants consist of integral values only.
17214
17215 @item
17216 Set constants are not yet supported.
17217 @end itemize
17218
17219 @node M2 Types
17220 @subsubsection Modula-2 Types
17221 @cindex Modula-2 types
17222
17223 Currently @value{GDBN} can print the following data types in Modula-2
17224 syntax: array types, record types, set types, pointer types, procedure
17225 types, enumerated types, subrange types and base types. You can also
17226 print the contents of variables declared using these type.
17227 This section gives a number of simple source code examples together with
17228 sample @value{GDBN} sessions.
17229
17230 The first example contains the following section of code:
17231
17232 @smallexample
17233 VAR
17234 s: SET OF CHAR ;
17235 r: [20..40] ;
17236 @end smallexample
17237
17238 @noindent
17239 and you can request @value{GDBN} to interrogate the type and value of
17240 @code{r} and @code{s}.
17241
17242 @smallexample
17243 (@value{GDBP}) print s
17244 @{'A'..'C', 'Z'@}
17245 (@value{GDBP}) ptype s
17246 SET OF CHAR
17247 (@value{GDBP}) print r
17248 21
17249 (@value{GDBP}) ptype r
17250 [20..40]
17251 @end smallexample
17252
17253 @noindent
17254 Likewise if your source code declares @code{s} as:
17255
17256 @smallexample
17257 VAR
17258 s: SET ['A'..'Z'] ;
17259 @end smallexample
17260
17261 @noindent
17262 then you may query the type of @code{s} by:
17263
17264 @smallexample
17265 (@value{GDBP}) ptype s
17266 type = SET ['A'..'Z']
17267 @end smallexample
17268
17269 @noindent
17270 Note that at present you cannot interactively manipulate set
17271 expressions using the debugger.
17272
17273 The following example shows how you might declare an array in Modula-2
17274 and how you can interact with @value{GDBN} to print its type and contents:
17275
17276 @smallexample
17277 VAR
17278 s: ARRAY [-10..10] OF CHAR ;
17279 @end smallexample
17280
17281 @smallexample
17282 (@value{GDBP}) ptype s
17283 ARRAY [-10..10] OF CHAR
17284 @end smallexample
17285
17286 Note that the array handling is not yet complete and although the type
17287 is printed correctly, expression handling still assumes that all
17288 arrays have a lower bound of zero and not @code{-10} as in the example
17289 above.
17290
17291 Here are some more type related Modula-2 examples:
17292
17293 @smallexample
17294 TYPE
17295 colour = (blue, red, yellow, green) ;
17296 t = [blue..yellow] ;
17297 VAR
17298 s: t ;
17299 BEGIN
17300 s := blue ;
17301 @end smallexample
17302
17303 @noindent
17304 The @value{GDBN} interaction shows how you can query the data type
17305 and value of a variable.
17306
17307 @smallexample
17308 (@value{GDBP}) print s
17309 $1 = blue
17310 (@value{GDBP}) ptype t
17311 type = [blue..yellow]
17312 @end smallexample
17313
17314 @noindent
17315 In this example a Modula-2 array is declared and its contents
17316 displayed. Observe that the contents are written in the same way as
17317 their @code{C} counterparts.
17318
17319 @smallexample
17320 VAR
17321 s: ARRAY [1..5] OF CARDINAL ;
17322 BEGIN
17323 s[1] := 1 ;
17324 @end smallexample
17325
17326 @smallexample
17327 (@value{GDBP}) print s
17328 $1 = @{1, 0, 0, 0, 0@}
17329 (@value{GDBP}) ptype s
17330 type = ARRAY [1..5] OF CARDINAL
17331 @end smallexample
17332
17333 The Modula-2 language interface to @value{GDBN} also understands
17334 pointer types as shown in this example:
17335
17336 @smallexample
17337 VAR
17338 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17339 BEGIN
17340 NEW(s) ;
17341 s^[1] := 1 ;
17342 @end smallexample
17343
17344 @noindent
17345 and you can request that @value{GDBN} describes the type of @code{s}.
17346
17347 @smallexample
17348 (@value{GDBP}) ptype s
17349 type = POINTER TO ARRAY [1..5] OF CARDINAL
17350 @end smallexample
17351
17352 @value{GDBN} handles compound types as we can see in this example.
17353 Here we combine array types, record types, pointer types and subrange
17354 types:
17355
17356 @smallexample
17357 TYPE
17358 foo = RECORD
17359 f1: CARDINAL ;
17360 f2: CHAR ;
17361 f3: myarray ;
17362 END ;
17363
17364 myarray = ARRAY myrange OF CARDINAL ;
17365 myrange = [-2..2] ;
17366 VAR
17367 s: POINTER TO ARRAY myrange OF foo ;
17368 @end smallexample
17369
17370 @noindent
17371 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17372 below.
17373
17374 @smallexample
17375 (@value{GDBP}) ptype s
17376 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17377 f1 : CARDINAL;
17378 f2 : CHAR;
17379 f3 : ARRAY [-2..2] OF CARDINAL;
17380 END
17381 @end smallexample
17382
17383 @node M2 Defaults
17384 @subsubsection Modula-2 Defaults
17385 @cindex Modula-2 defaults
17386
17387 If type and range checking are set automatically by @value{GDBN}, they
17388 both default to @code{on} whenever the working language changes to
17389 Modula-2. This happens regardless of whether you or @value{GDBN}
17390 selected the working language.
17391
17392 If you allow @value{GDBN} to set the language automatically, then entering
17393 code compiled from a file whose name ends with @file{.mod} sets the
17394 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17395 Infer the Source Language}, for further details.
17396
17397 @node Deviations
17398 @subsubsection Deviations from Standard Modula-2
17399 @cindex Modula-2, deviations from
17400
17401 A few changes have been made to make Modula-2 programs easier to debug.
17402 This is done primarily via loosening its type strictness:
17403
17404 @itemize @bullet
17405 @item
17406 Unlike in standard Modula-2, pointer constants can be formed by
17407 integers. This allows you to modify pointer variables during
17408 debugging. (In standard Modula-2, the actual address contained in a
17409 pointer variable is hidden from you; it can only be modified
17410 through direct assignment to another pointer variable or expression that
17411 returned a pointer.)
17412
17413 @item
17414 C escape sequences can be used in strings and characters to represent
17415 non-printable characters. @value{GDBN} prints out strings with these
17416 escape sequences embedded. Single non-printable characters are
17417 printed using the @samp{CHR(@var{nnn})} format.
17418
17419 @item
17420 The assignment operator (@code{:=}) returns the value of its right-hand
17421 argument.
17422
17423 @item
17424 All built-in procedures both modify @emph{and} return their argument.
17425 @end itemize
17426
17427 @node M2 Checks
17428 @subsubsection Modula-2 Type and Range Checks
17429 @cindex Modula-2 checks
17430
17431 @quotation
17432 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17433 range checking.
17434 @end quotation
17435 @c FIXME remove warning when type/range checks added
17436
17437 @value{GDBN} considers two Modula-2 variables type equivalent if:
17438
17439 @itemize @bullet
17440 @item
17441 They are of types that have been declared equivalent via a @code{TYPE
17442 @var{t1} = @var{t2}} statement
17443
17444 @item
17445 They have been declared on the same line. (Note: This is true of the
17446 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17447 @end itemize
17448
17449 As long as type checking is enabled, any attempt to combine variables
17450 whose types are not equivalent is an error.
17451
17452 Range checking is done on all mathematical operations, assignment, array
17453 index bounds, and all built-in functions and procedures.
17454
17455 @node M2 Scope
17456 @subsubsection The Scope Operators @code{::} and @code{.}
17457 @cindex scope
17458 @cindex @code{.}, Modula-2 scope operator
17459 @cindex colon, doubled as scope operator
17460 @ifinfo
17461 @vindex colon-colon@r{, in Modula-2}
17462 @c Info cannot handle :: but TeX can.
17463 @end ifinfo
17464 @ifnotinfo
17465 @vindex ::@r{, in Modula-2}
17466 @end ifnotinfo
17467
17468 There are a few subtle differences between the Modula-2 scope operator
17469 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17470 similar syntax:
17471
17472 @smallexample
17473
17474 @var{module} . @var{id}
17475 @var{scope} :: @var{id}
17476 @end smallexample
17477
17478 @noindent
17479 where @var{scope} is the name of a module or a procedure,
17480 @var{module} the name of a module, and @var{id} is any declared
17481 identifier within your program, except another module.
17482
17483 Using the @code{::} operator makes @value{GDBN} search the scope
17484 specified by @var{scope} for the identifier @var{id}. If it is not
17485 found in the specified scope, then @value{GDBN} searches all scopes
17486 enclosing the one specified by @var{scope}.
17487
17488 Using the @code{.} operator makes @value{GDBN} search the current scope for
17489 the identifier specified by @var{id} that was imported from the
17490 definition module specified by @var{module}. With this operator, it is
17491 an error if the identifier @var{id} was not imported from definition
17492 module @var{module}, or if @var{id} is not an identifier in
17493 @var{module}.
17494
17495 @node GDB/M2
17496 @subsubsection @value{GDBN} and Modula-2
17497
17498 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17499 Five subcommands of @code{set print} and @code{show print} apply
17500 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17501 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17502 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17503 analogue in Modula-2.
17504
17505 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17506 with any language, is not useful with Modula-2. Its
17507 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17508 created in Modula-2 as they can in C or C@t{++}. However, because an
17509 address can be specified by an integral constant, the construct
17510 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17511
17512 @cindex @code{#} in Modula-2
17513 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17514 interpreted as the beginning of a comment. Use @code{<>} instead.
17515
17516 @node Ada
17517 @subsection Ada
17518 @cindex Ada
17519
17520 The extensions made to @value{GDBN} for Ada only support
17521 output from the @sc{gnu} Ada (GNAT) compiler.
17522 Other Ada compilers are not currently supported, and
17523 attempting to debug executables produced by them is most likely
17524 to be difficult.
17525
17526
17527 @cindex expressions in Ada
17528 @menu
17529 * Ada Mode Intro:: General remarks on the Ada syntax
17530 and semantics supported by Ada mode
17531 in @value{GDBN}.
17532 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17533 * Additions to Ada:: Extensions of the Ada expression syntax.
17534 * Overloading support for Ada:: Support for expressions involving overloaded
17535 subprograms.
17536 * Stopping Before Main Program:: Debugging the program during elaboration.
17537 * Ada Exceptions:: Ada Exceptions
17538 * Ada Tasks:: Listing and setting breakpoints in tasks.
17539 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17540 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17541 Profile
17542 * Ada Settings:: New settable GDB parameters for Ada.
17543 * Ada Glitches:: Known peculiarities of Ada mode.
17544 @end menu
17545
17546 @node Ada Mode Intro
17547 @subsubsection Introduction
17548 @cindex Ada mode, general
17549
17550 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17551 syntax, with some extensions.
17552 The philosophy behind the design of this subset is
17553
17554 @itemize @bullet
17555 @item
17556 That @value{GDBN} should provide basic literals and access to operations for
17557 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17558 leaving more sophisticated computations to subprograms written into the
17559 program (which therefore may be called from @value{GDBN}).
17560
17561 @item
17562 That type safety and strict adherence to Ada language restrictions
17563 are not particularly important to the @value{GDBN} user.
17564
17565 @item
17566 That brevity is important to the @value{GDBN} user.
17567 @end itemize
17568
17569 Thus, for brevity, the debugger acts as if all names declared in
17570 user-written packages are directly visible, even if they are not visible
17571 according to Ada rules, thus making it unnecessary to fully qualify most
17572 names with their packages, regardless of context. Where this causes
17573 ambiguity, @value{GDBN} asks the user's intent.
17574
17575 The debugger will start in Ada mode if it detects an Ada main program.
17576 As for other languages, it will enter Ada mode when stopped in a program that
17577 was translated from an Ada source file.
17578
17579 While in Ada mode, you may use `@t{--}' for comments. This is useful
17580 mostly for documenting command files. The standard @value{GDBN} comment
17581 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17582 middle (to allow based literals).
17583
17584 @node Omissions from Ada
17585 @subsubsection Omissions from Ada
17586 @cindex Ada, omissions from
17587
17588 Here are the notable omissions from the subset:
17589
17590 @itemize @bullet
17591 @item
17592 Only a subset of the attributes are supported:
17593
17594 @itemize @minus
17595 @item
17596 @t{'First}, @t{'Last}, and @t{'Length}
17597 on array objects (not on types and subtypes).
17598
17599 @item
17600 @t{'Min} and @t{'Max}.
17601
17602 @item
17603 @t{'Pos} and @t{'Val}.
17604
17605 @item
17606 @t{'Tag}.
17607
17608 @item
17609 @t{'Range} on array objects (not subtypes), but only as the right
17610 operand of the membership (@code{in}) operator.
17611
17612 @item
17613 @t{'Access}, @t{'Unchecked_Access}, and
17614 @t{'Unrestricted_Access} (a GNAT extension).
17615
17616 @item
17617 @t{'Address}.
17618 @end itemize
17619
17620 @item
17621 The names in
17622 @code{Characters.Latin_1} are not available and
17623 concatenation is not implemented. Thus, escape characters in strings are
17624 not currently available.
17625
17626 @item
17627 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17628 equality of representations. They will generally work correctly
17629 for strings and arrays whose elements have integer or enumeration types.
17630 They may not work correctly for arrays whose element
17631 types have user-defined equality, for arrays of real values
17632 (in particular, IEEE-conformant floating point, because of negative
17633 zeroes and NaNs), and for arrays whose elements contain unused bits with
17634 indeterminate values.
17635
17636 @item
17637 The other component-by-component array operations (@code{and}, @code{or},
17638 @code{xor}, @code{not}, and relational tests other than equality)
17639 are not implemented.
17640
17641 @item
17642 @cindex array aggregates (Ada)
17643 @cindex record aggregates (Ada)
17644 @cindex aggregates (Ada)
17645 There is limited support for array and record aggregates. They are
17646 permitted only on the right sides of assignments, as in these examples:
17647
17648 @smallexample
17649 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17650 (@value{GDBP}) set An_Array := (1, others => 0)
17651 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17652 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17653 (@value{GDBP}) set A_Record := (1, "Peter", True);
17654 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
17655 @end smallexample
17656
17657 Changing a
17658 discriminant's value by assigning an aggregate has an
17659 undefined effect if that discriminant is used within the record.
17660 However, you can first modify discriminants by directly assigning to
17661 them (which normally would not be allowed in Ada), and then performing an
17662 aggregate assignment. For example, given a variable @code{A_Rec}
17663 declared to have a type such as:
17664
17665 @smallexample
17666 type Rec (Len : Small_Integer := 0) is record
17667 Id : Integer;
17668 Vals : IntArray (1 .. Len);
17669 end record;
17670 @end smallexample
17671
17672 you can assign a value with a different size of @code{Vals} with two
17673 assignments:
17674
17675 @smallexample
17676 (@value{GDBP}) set A_Rec.Len := 4
17677 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
17678 @end smallexample
17679
17680 As this example also illustrates, @value{GDBN} is very loose about the usual
17681 rules concerning aggregates. You may leave out some of the
17682 components of an array or record aggregate (such as the @code{Len}
17683 component in the assignment to @code{A_Rec} above); they will retain their
17684 original values upon assignment. You may freely use dynamic values as
17685 indices in component associations. You may even use overlapping or
17686 redundant component associations, although which component values are
17687 assigned in such cases is not defined.
17688
17689 @item
17690 Calls to dispatching subprograms are not implemented.
17691
17692 @item
17693 The overloading algorithm is much more limited (i.e., less selective)
17694 than that of real Ada. It makes only limited use of the context in
17695 which a subexpression appears to resolve its meaning, and it is much
17696 looser in its rules for allowing type matches. As a result, some
17697 function calls will be ambiguous, and the user will be asked to choose
17698 the proper resolution.
17699
17700 @item
17701 The @code{new} operator is not implemented.
17702
17703 @item
17704 Entry calls are not implemented.
17705
17706 @item
17707 Aside from printing, arithmetic operations on the native VAX floating-point
17708 formats are not supported.
17709
17710 @item
17711 It is not possible to slice a packed array.
17712
17713 @item
17714 The names @code{True} and @code{False}, when not part of a qualified name,
17715 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17716 context.
17717 Should your program
17718 redefine these names in a package or procedure (at best a dubious practice),
17719 you will have to use fully qualified names to access their new definitions.
17720 @end itemize
17721
17722 @node Additions to Ada
17723 @subsubsection Additions to Ada
17724 @cindex Ada, deviations from
17725
17726 As it does for other languages, @value{GDBN} makes certain generic
17727 extensions to Ada (@pxref{Expressions}):
17728
17729 @itemize @bullet
17730 @item
17731 If the expression @var{E} is a variable residing in memory (typically
17732 a local variable or array element) and @var{N} is a positive integer,
17733 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17734 @var{N}-1 adjacent variables following it in memory as an array. In
17735 Ada, this operator is generally not necessary, since its prime use is
17736 in displaying parts of an array, and slicing will usually do this in
17737 Ada. However, there are occasional uses when debugging programs in
17738 which certain debugging information has been optimized away.
17739
17740 @item
17741 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
17742 appears in function or file @var{B}.'' When @var{B} is a file name,
17743 you must typically surround it in single quotes.
17744
17745 @item
17746 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17747 @var{type} that appears at address @var{addr}.''
17748
17749 @item
17750 A name starting with @samp{$} is a convenience variable
17751 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17752 @end itemize
17753
17754 In addition, @value{GDBN} provides a few other shortcuts and outright
17755 additions specific to Ada:
17756
17757 @itemize @bullet
17758 @item
17759 The assignment statement is allowed as an expression, returning
17760 its right-hand operand as its value. Thus, you may enter
17761
17762 @smallexample
17763 (@value{GDBP}) set x := y + 3
17764 (@value{GDBP}) print A(tmp := y + 1)
17765 @end smallexample
17766
17767 @item
17768 The semicolon is allowed as an ``operator,'' returning as its value
17769 the value of its right-hand operand.
17770 This allows, for example,
17771 complex conditional breaks:
17772
17773 @smallexample
17774 (@value{GDBP}) break f
17775 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
17776 @end smallexample
17777
17778 @item
17779 Rather than use catenation and symbolic character names to introduce special
17780 characters into strings, one may instead use a special bracket notation,
17781 which is also used to print strings. A sequence of characters of the form
17782 @samp{["@var{XX}"]} within a string or character literal denotes the
17783 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
17784 sequence of characters @samp{["""]} also denotes a single quotation mark
17785 in strings. For example,
17786 @smallexample
17787 "One line.["0a"]Next line.["0a"]"
17788 @end smallexample
17789 @noindent
17790 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17791 after each period.
17792
17793 @item
17794 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17795 @t{'Max} is optional (and is ignored in any case). For example, it is valid
17796 to write
17797
17798 @smallexample
17799 (@value{GDBP}) print 'max(x, y)
17800 @end smallexample
17801
17802 @item
17803 When printing arrays, @value{GDBN} uses positional notation when the
17804 array has a lower bound of 1, and uses a modified named notation otherwise.
17805 For example, a one-dimensional array of three integers with a lower bound
17806 of 3 might print as
17807
17808 @smallexample
17809 (3 => 10, 17, 1)
17810 @end smallexample
17811
17812 @noindent
17813 That is, in contrast to valid Ada, only the first component has a @code{=>}
17814 clause.
17815
17816 @item
17817 You may abbreviate attributes in expressions with any unique,
17818 multi-character subsequence of
17819 their names (an exact match gets preference).
17820 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17821 in place of @t{a'length}.
17822
17823 @item
17824 @cindex quoting Ada internal identifiers
17825 Since Ada is case-insensitive, the debugger normally maps identifiers you type
17826 to lower case. The GNAT compiler uses upper-case characters for
17827 some of its internal identifiers, which are normally of no interest to users.
17828 For the rare occasions when you actually have to look at them,
17829 enclose them in angle brackets to avoid the lower-case mapping.
17830 For example,
17831 @smallexample
17832 (@value{GDBP}) print <JMPBUF_SAVE>[0]
17833 @end smallexample
17834
17835 @item
17836 Printing an object of class-wide type or dereferencing an
17837 access-to-class-wide value will display all the components of the object's
17838 specific type (as indicated by its run-time tag). Likewise, component
17839 selection on such a value will operate on the specific type of the
17840 object.
17841
17842 @end itemize
17843
17844 @node Overloading support for Ada
17845 @subsubsection Overloading support for Ada
17846 @cindex overloading, Ada
17847
17848 The debugger supports limited overloading. Given a subprogram call in which
17849 the function symbol has multiple definitions, it will use the number of
17850 actual parameters and some information about their types to attempt to narrow
17851 the set of definitions. It also makes very limited use of context, preferring
17852 procedures to functions in the context of the @code{call} command, and
17853 functions to procedures elsewhere.
17854
17855 If, after narrowing, the set of matching definitions still contains more than
17856 one definition, @value{GDBN} will display a menu to query which one it should
17857 use, for instance:
17858
17859 @smallexample
17860 (@value{GDBP}) print f(1)
17861 Multiple matches for f
17862 [0] cancel
17863 [1] foo.f (integer) return boolean at foo.adb:23
17864 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
17865 >
17866 @end smallexample
17867
17868 In this case, just select one menu entry either to cancel expression evaluation
17869 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17870 instance (type the corresponding number and press @key{RET}).
17871
17872 Here are a couple of commands to customize @value{GDBN}'s behavior in this
17873 case:
17874
17875 @table @code
17876
17877 @kindex set ada print-signatures
17878 @item set ada print-signatures
17879 Control whether parameter types and return types are displayed in overloads
17880 selection menus. It is @code{on} by default.
17881 @xref{Overloading support for Ada}.
17882
17883 @kindex show ada print-signatures
17884 @item show ada print-signatures
17885 Show the current setting for displaying parameter types and return types in
17886 overloads selection menu.
17887 @xref{Overloading support for Ada}.
17888
17889 @end table
17890
17891 @node Stopping Before Main Program
17892 @subsubsection Stopping at the Very Beginning
17893
17894 @cindex breakpointing Ada elaboration code
17895 It is sometimes necessary to debug the program during elaboration, and
17896 before reaching the main procedure.
17897 As defined in the Ada Reference
17898 Manual, the elaboration code is invoked from a procedure called
17899 @code{adainit}. To run your program up to the beginning of
17900 elaboration, simply use the following two commands:
17901 @code{tbreak adainit} and @code{run}.
17902
17903 @node Ada Exceptions
17904 @subsubsection Ada Exceptions
17905
17906 A command is provided to list all Ada exceptions:
17907
17908 @table @code
17909 @kindex info exceptions
17910 @item info exceptions
17911 @itemx info exceptions @var{regexp}
17912 The @code{info exceptions} command allows you to list all Ada exceptions
17913 defined within the program being debugged, as well as their addresses.
17914 With a regular expression, @var{regexp}, as argument, only those exceptions
17915 whose names match @var{regexp} are listed.
17916 @end table
17917
17918 Below is a small example, showing how the command can be used, first
17919 without argument, and next with a regular expression passed as an
17920 argument.
17921
17922 @smallexample
17923 (@value{GDBP}) info exceptions
17924 All defined Ada exceptions:
17925 constraint_error: 0x613da0
17926 program_error: 0x613d20
17927 storage_error: 0x613ce0
17928 tasking_error: 0x613ca0
17929 const.aint_global_e: 0x613b00
17930 (@value{GDBP}) info exceptions const.aint
17931 All Ada exceptions matching regular expression "const.aint":
17932 constraint_error: 0x613da0
17933 const.aint_global_e: 0x613b00
17934 @end smallexample
17935
17936 It is also possible to ask @value{GDBN} to stop your program's execution
17937 when an exception is raised. For more details, see @ref{Set Catchpoints}.
17938
17939 @node Ada Tasks
17940 @subsubsection Extensions for Ada Tasks
17941 @cindex Ada, tasking
17942
17943 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
17944 @value{GDBN} provides the following task-related commands:
17945
17946 @table @code
17947 @kindex info tasks
17948 @item info tasks
17949 This command shows a list of current Ada tasks, as in the following example:
17950
17951
17952 @smallexample
17953 @iftex
17954 @leftskip=0.5cm
17955 @end iftex
17956 (@value{GDBP}) info tasks
17957 ID TID P-ID Pri State Name
17958 1 8088000 0 15 Child Activation Wait main_task
17959 2 80a4000 1 15 Accept Statement b
17960 3 809a800 1 15 Child Activation Wait a
17961 * 4 80ae800 3 15 Runnable c
17962
17963 @end smallexample
17964
17965 @noindent
17966 In this listing, the asterisk before the last task indicates it to be the
17967 task currently being inspected.
17968
17969 @table @asis
17970 @item ID
17971 Represents @value{GDBN}'s internal task number.
17972
17973 @item TID
17974 The Ada task ID.
17975
17976 @item P-ID
17977 The parent's task ID (@value{GDBN}'s internal task number).
17978
17979 @item Pri
17980 The base priority of the task.
17981
17982 @item State
17983 Current state of the task.
17984
17985 @table @code
17986 @item Unactivated
17987 The task has been created but has not been activated. It cannot be
17988 executing.
17989
17990 @item Runnable
17991 The task is not blocked for any reason known to Ada. (It may be waiting
17992 for a mutex, though.) It is conceptually "executing" in normal mode.
17993
17994 @item Terminated
17995 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
17996 that were waiting on terminate alternatives have been awakened and have
17997 terminated themselves.
17998
17999 @item Child Activation Wait
18000 The task is waiting for created tasks to complete activation.
18001
18002 @item Accept Statement
18003 The task is waiting on an accept or selective wait statement.
18004
18005 @item Waiting on entry call
18006 The task is waiting on an entry call.
18007
18008 @item Async Select Wait
18009 The task is waiting to start the abortable part of an asynchronous
18010 select statement.
18011
18012 @item Delay Sleep
18013 The task is waiting on a select statement with only a delay
18014 alternative open.
18015
18016 @item Child Termination Wait
18017 The task is sleeping having completed a master within itself, and is
18018 waiting for the tasks dependent on that master to become terminated or
18019 waiting on a terminate Phase.
18020
18021 @item Wait Child in Term Alt
18022 The task is sleeping waiting for tasks on terminate alternatives to
18023 finish terminating.
18024
18025 @item Accepting RV with @var{taskno}
18026 The task is accepting a rendez-vous with the task @var{taskno}.
18027 @end table
18028
18029 @item Name
18030 Name of the task in the program.
18031
18032 @end table
18033
18034 @kindex info task @var{taskno}
18035 @item info task @var{taskno}
18036 This command shows detailed informations on the specified task, as in
18037 the following example:
18038 @smallexample
18039 @iftex
18040 @leftskip=0.5cm
18041 @end iftex
18042 (@value{GDBP}) info tasks
18043 ID TID P-ID Pri State Name
18044 1 8077880 0 15 Child Activation Wait main_task
18045 * 2 807c468 1 15 Runnable task_1
18046 (@value{GDBP}) info task 2
18047 Ada Task: 0x807c468
18048 Name: "task_1"
18049 Thread: 0
18050 LWP: 0x1fac
18051 Parent: 1 ("main_task")
18052 Base Priority: 15
18053 State: Runnable
18054 @end smallexample
18055
18056 @item task
18057 @kindex task@r{ (Ada)}
18058 @cindex current Ada task ID
18059 This command prints the ID and name of the current task.
18060
18061 @smallexample
18062 @iftex
18063 @leftskip=0.5cm
18064 @end iftex
18065 (@value{GDBP}) info tasks
18066 ID TID P-ID Pri State Name
18067 1 8077870 0 15 Child Activation Wait main_task
18068 * 2 807c458 1 15 Runnable some_task
18069 (@value{GDBP}) task
18070 [Current task is 2 "some_task"]
18071 @end smallexample
18072
18073 @item task @var{taskno}
18074 @cindex Ada task switching
18075 This command is like the @code{thread @var{thread-id}}
18076 command (@pxref{Threads}). It switches the context of debugging
18077 from the current task to the given task.
18078
18079 @smallexample
18080 @iftex
18081 @leftskip=0.5cm
18082 @end iftex
18083 (@value{GDBP}) info tasks
18084 ID TID P-ID Pri State Name
18085 1 8077870 0 15 Child Activation Wait main_task
18086 * 2 807c458 1 15 Runnable some_task
18087 (@value{GDBP}) task 1
18088 [Switching to task 1 "main_task"]
18089 #0 0x8067726 in pthread_cond_wait ()
18090 (@value{GDBP}) bt
18091 #0 0x8067726 in pthread_cond_wait ()
18092 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18093 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18094 #3 0x806153e in system.tasking.stages.activate_tasks ()
18095 #4 0x804aacc in un () at un.adb:5
18096 @end smallexample
18097
18098 @item break @var{location} task @var{taskno}
18099 @itemx break @var{location} task @var{taskno} if @dots{}
18100 @cindex breakpoints and tasks, in Ada
18101 @cindex task breakpoints, in Ada
18102 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18103 These commands are like the @code{break @dots{} thread @dots{}}
18104 command (@pxref{Thread Stops}). The
18105 @var{location} argument specifies source lines, as described
18106 in @ref{Specify Location}.
18107
18108 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18109 to specify that you only want @value{GDBN} to stop the program when a
18110 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18111 numeric task identifiers assigned by @value{GDBN}, shown in the first
18112 column of the @samp{info tasks} display.
18113
18114 If you do not specify @samp{task @var{taskno}} when you set a
18115 breakpoint, the breakpoint applies to @emph{all} tasks of your
18116 program.
18117
18118 You can use the @code{task} qualifier on conditional breakpoints as
18119 well; in this case, place @samp{task @var{taskno}} before the
18120 breakpoint condition (before the @code{if}).
18121
18122 For example,
18123
18124 @smallexample
18125 @iftex
18126 @leftskip=0.5cm
18127 @end iftex
18128 (@value{GDBP}) info tasks
18129 ID TID P-ID Pri State Name
18130 1 140022020 0 15 Child Activation Wait main_task
18131 2 140045060 1 15 Accept/Select Wait t2
18132 3 140044840 1 15 Runnable t1
18133 * 4 140056040 1 15 Runnable t3
18134 (@value{GDBP}) b 15 task 2
18135 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18136 (@value{GDBP}) cont
18137 Continuing.
18138 task # 1 running
18139 task # 2 running
18140
18141 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18142 15 flush;
18143 (@value{GDBP}) info tasks
18144 ID TID P-ID Pri State Name
18145 1 140022020 0 15 Child Activation Wait main_task
18146 * 2 140045060 1 15 Runnable t2
18147 3 140044840 1 15 Runnable t1
18148 4 140056040 1 15 Delay Sleep t3
18149 @end smallexample
18150 @end table
18151
18152 @node Ada Tasks and Core Files
18153 @subsubsection Tasking Support when Debugging Core Files
18154 @cindex Ada tasking and core file debugging
18155
18156 When inspecting a core file, as opposed to debugging a live program,
18157 tasking support may be limited or even unavailable, depending on
18158 the platform being used.
18159 For instance, on x86-linux, the list of tasks is available, but task
18160 switching is not supported.
18161
18162 On certain platforms, the debugger needs to perform some
18163 memory writes in order to provide Ada tasking support. When inspecting
18164 a core file, this means that the core file must be opened with read-write
18165 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18166 Under these circumstances, you should make a backup copy of the core
18167 file before inspecting it with @value{GDBN}.
18168
18169 @node Ravenscar Profile
18170 @subsubsection Tasking Support when using the Ravenscar Profile
18171 @cindex Ravenscar Profile
18172
18173 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18174 specifically designed for systems with safety-critical real-time
18175 requirements.
18176
18177 @table @code
18178 @kindex set ravenscar task-switching on
18179 @cindex task switching with program using Ravenscar Profile
18180 @item set ravenscar task-switching on
18181 Allows task switching when debugging a program that uses the Ravenscar
18182 Profile. This is the default.
18183
18184 @kindex set ravenscar task-switching off
18185 @item set ravenscar task-switching off
18186 Turn off task switching when debugging a program that uses the Ravenscar
18187 Profile. This is mostly intended to disable the code that adds support
18188 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18189 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18190 To be effective, this command should be run before the program is started.
18191
18192 @kindex show ravenscar task-switching
18193 @item show ravenscar task-switching
18194 Show whether it is possible to switch from task to task in a program
18195 using the Ravenscar Profile.
18196
18197 @end table
18198
18199 @node Ada Settings
18200 @subsubsection Ada Settings
18201 @cindex Ada settings
18202
18203 @table @code
18204 @kindex set varsize-limit
18205 @item set varsize-limit @var{size}
18206 Prevent @value{GDBN} from attempting to evaluate objects whose size
18207 is above the given limit (@var{size}) when those sizes are computed
18208 from run-time quantities. This is typically the case when the object
18209 has a variable size, such as an array whose bounds are not known at
18210 compile time for example. Setting @var{size} to @code{unlimited}
18211 removes the size limitation. By default, the limit is about 65KB.
18212
18213 The purpose of having such a limit is to prevent @value{GDBN} from
18214 trying to grab enormous chunks of virtual memory when asked to evaluate
18215 a quantity whose bounds have been corrupted or have not yet been fully
18216 initialized. The limit applies to the results of some subexpressions
18217 as well as to complete expressions. For example, an expression denoting
18218 a simple integer component, such as @code{x.y.z}, may fail if the size of
18219 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18220 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18221 @code{A} is an array variable with non-constant size, will generally
18222 succeed regardless of the bounds on @code{A}, as long as the component
18223 size is less than @var{size}.
18224
18225 @kindex show varsize-limit
18226 @item show varsize-limit
18227 Show the limit on types whose size is determined by run-time quantities.
18228 @end table
18229
18230 @node Ada Glitches
18231 @subsubsection Known Peculiarities of Ada Mode
18232 @cindex Ada, problems
18233
18234 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18235 we know of several problems with and limitations of Ada mode in
18236 @value{GDBN},
18237 some of which will be fixed with planned future releases of the debugger
18238 and the GNU Ada compiler.
18239
18240 @itemize @bullet
18241 @item
18242 Static constants that the compiler chooses not to materialize as objects in
18243 storage are invisible to the debugger.
18244
18245 @item
18246 Named parameter associations in function argument lists are ignored (the
18247 argument lists are treated as positional).
18248
18249 @item
18250 Many useful library packages are currently invisible to the debugger.
18251
18252 @item
18253 Fixed-point arithmetic, conversions, input, and output is carried out using
18254 floating-point arithmetic, and may give results that only approximate those on
18255 the host machine.
18256
18257 @item
18258 The GNAT compiler never generates the prefix @code{Standard} for any of
18259 the standard symbols defined by the Ada language. @value{GDBN} knows about
18260 this: it will strip the prefix from names when you use it, and will never
18261 look for a name you have so qualified among local symbols, nor match against
18262 symbols in other packages or subprograms. If you have
18263 defined entities anywhere in your program other than parameters and
18264 local variables whose simple names match names in @code{Standard},
18265 GNAT's lack of qualification here can cause confusion. When this happens,
18266 you can usually resolve the confusion
18267 by qualifying the problematic names with package
18268 @code{Standard} explicitly.
18269 @end itemize
18270
18271 Older versions of the compiler sometimes generate erroneous debugging
18272 information, resulting in the debugger incorrectly printing the value
18273 of affected entities. In some cases, the debugger is able to work
18274 around an issue automatically. In other cases, the debugger is able
18275 to work around the issue, but the work-around has to be specifically
18276 enabled.
18277
18278 @kindex set ada trust-PAD-over-XVS
18279 @kindex show ada trust-PAD-over-XVS
18280 @table @code
18281
18282 @item set ada trust-PAD-over-XVS on
18283 Configure GDB to strictly follow the GNAT encoding when computing the
18284 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18285 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18286 a complete description of the encoding used by the GNAT compiler).
18287 This is the default.
18288
18289 @item set ada trust-PAD-over-XVS off
18290 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18291 sometimes prints the wrong value for certain entities, changing @code{ada
18292 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18293 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18294 @code{off}, but this incurs a slight performance penalty, so it is
18295 recommended to leave this setting to @code{on} unless necessary.
18296
18297 @end table
18298
18299 @cindex GNAT descriptive types
18300 @cindex GNAT encoding
18301 Internally, the debugger also relies on the compiler following a number
18302 of conventions known as the @samp{GNAT Encoding}, all documented in
18303 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18304 how the debugging information should be generated for certain types.
18305 In particular, this convention makes use of @dfn{descriptive types},
18306 which are artificial types generated purely to help the debugger.
18307
18308 These encodings were defined at a time when the debugging information
18309 format used was not powerful enough to describe some of the more complex
18310 types available in Ada. Since DWARF allows us to express nearly all
18311 Ada features, the long-term goal is to slowly replace these descriptive
18312 types by their pure DWARF equivalent. To facilitate that transition,
18313 a new maintenance option is available to force the debugger to ignore
18314 those descriptive types. It allows the user to quickly evaluate how
18315 well @value{GDBN} works without them.
18316
18317 @table @code
18318
18319 @kindex maint ada set ignore-descriptive-types
18320 @item maintenance ada set ignore-descriptive-types [on|off]
18321 Control whether the debugger should ignore descriptive types.
18322 The default is not to ignore descriptives types (@code{off}).
18323
18324 @kindex maint ada show ignore-descriptive-types
18325 @item maintenance ada show ignore-descriptive-types
18326 Show if descriptive types are ignored by @value{GDBN}.
18327
18328 @end table
18329
18330 @node Unsupported Languages
18331 @section Unsupported Languages
18332
18333 @cindex unsupported languages
18334 @cindex minimal language
18335 In addition to the other fully-supported programming languages,
18336 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18337 It does not represent a real programming language, but provides a set
18338 of capabilities close to what the C or assembly languages provide.
18339 This should allow most simple operations to be performed while debugging
18340 an application that uses a language currently not supported by @value{GDBN}.
18341
18342 If the language is set to @code{auto}, @value{GDBN} will automatically
18343 select this language if the current frame corresponds to an unsupported
18344 language.
18345
18346 @node Symbols
18347 @chapter Examining the Symbol Table
18348
18349 The commands described in this chapter allow you to inquire about the
18350 symbols (names of variables, functions and types) defined in your
18351 program. This information is inherent in the text of your program and
18352 does not change as your program executes. @value{GDBN} finds it in your
18353 program's symbol table, in the file indicated when you started @value{GDBN}
18354 (@pxref{File Options, ,Choosing Files}), or by one of the
18355 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18356
18357 @cindex symbol names
18358 @cindex names of symbols
18359 @cindex quoting names
18360 @anchor{quoting names}
18361 Occasionally, you may need to refer to symbols that contain unusual
18362 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18363 most frequent case is in referring to static variables in other
18364 source files (@pxref{Variables,,Program Variables}). File names
18365 are recorded in object files as debugging symbols, but @value{GDBN} would
18366 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18367 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18368 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18369
18370 @smallexample
18371 p 'foo.c'::x
18372 @end smallexample
18373
18374 @noindent
18375 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18376
18377 @table @code
18378 @cindex case-insensitive symbol names
18379 @cindex case sensitivity in symbol names
18380 @kindex set case-sensitive
18381 @item set case-sensitive on
18382 @itemx set case-sensitive off
18383 @itemx set case-sensitive auto
18384 Normally, when @value{GDBN} looks up symbols, it matches their names
18385 with case sensitivity determined by the current source language.
18386 Occasionally, you may wish to control that. The command @code{set
18387 case-sensitive} lets you do that by specifying @code{on} for
18388 case-sensitive matches or @code{off} for case-insensitive ones. If
18389 you specify @code{auto}, case sensitivity is reset to the default
18390 suitable for the source language. The default is case-sensitive
18391 matches for all languages except for Fortran, for which the default is
18392 case-insensitive matches.
18393
18394 @kindex show case-sensitive
18395 @item show case-sensitive
18396 This command shows the current setting of case sensitivity for symbols
18397 lookups.
18398
18399 @kindex set print type methods
18400 @item set print type methods
18401 @itemx set print type methods on
18402 @itemx set print type methods off
18403 Normally, when @value{GDBN} prints a class, it displays any methods
18404 declared in that class. You can control this behavior either by
18405 passing the appropriate flag to @code{ptype}, or using @command{set
18406 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18407 display the methods; this is the default. Specifying @code{off} will
18408 cause @value{GDBN} to omit the methods.
18409
18410 @kindex show print type methods
18411 @item show print type methods
18412 This command shows the current setting of method display when printing
18413 classes.
18414
18415 @kindex set print type nested-type-limit
18416 @item set print type nested-type-limit @var{limit}
18417 @itemx set print type nested-type-limit unlimited
18418 Set the limit of displayed nested types that the type printer will
18419 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18420 nested definitions. By default, the type printer will not show any nested
18421 types defined in classes.
18422
18423 @kindex show print type nested-type-limit
18424 @item show print type nested-type-limit
18425 This command shows the current display limit of nested types when
18426 printing classes.
18427
18428 @kindex set print type typedefs
18429 @item set print type typedefs
18430 @itemx set print type typedefs on
18431 @itemx set print type typedefs off
18432
18433 Normally, when @value{GDBN} prints a class, it displays any typedefs
18434 defined in that class. You can control this behavior either by
18435 passing the appropriate flag to @code{ptype}, or using @command{set
18436 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18437 display the typedef definitions; this is the default. Specifying
18438 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18439 Note that this controls whether the typedef definition itself is
18440 printed, not whether typedef names are substituted when printing other
18441 types.
18442
18443 @kindex show print type typedefs
18444 @item show print type typedefs
18445 This command shows the current setting of typedef display when
18446 printing classes.
18447
18448 @kindex info address
18449 @cindex address of a symbol
18450 @item info address @var{symbol}
18451 Describe where the data for @var{symbol} is stored. For a register
18452 variable, this says which register it is kept in. For a non-register
18453 local variable, this prints the stack-frame offset at which the variable
18454 is always stored.
18455
18456 Note the contrast with @samp{print &@var{symbol}}, which does not work
18457 at all for a register variable, and for a stack local variable prints
18458 the exact address of the current instantiation of the variable.
18459
18460 @kindex info symbol
18461 @cindex symbol from address
18462 @cindex closest symbol and offset for an address
18463 @item info symbol @var{addr}
18464 Print the name of a symbol which is stored at the address @var{addr}.
18465 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18466 nearest symbol and an offset from it:
18467
18468 @smallexample
18469 (@value{GDBP}) info symbol 0x54320
18470 _initialize_vx + 396 in section .text
18471 @end smallexample
18472
18473 @noindent
18474 This is the opposite of the @code{info address} command. You can use
18475 it to find out the name of a variable or a function given its address.
18476
18477 For dynamically linked executables, the name of executable or shared
18478 library containing the symbol is also printed:
18479
18480 @smallexample
18481 (@value{GDBP}) info symbol 0x400225
18482 _start + 5 in section .text of /tmp/a.out
18483 (@value{GDBP}) info symbol 0x2aaaac2811cf
18484 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18485 @end smallexample
18486
18487 @kindex demangle
18488 @cindex demangle
18489 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18490 Demangle @var{name}.
18491 If @var{language} is provided it is the name of the language to demangle
18492 @var{name} in. Otherwise @var{name} is demangled in the current language.
18493
18494 The @samp{--} option specifies the end of options,
18495 and is useful when @var{name} begins with a dash.
18496
18497 The parameter @code{demangle-style} specifies how to interpret the kind
18498 of mangling used. @xref{Print Settings}.
18499
18500 @kindex whatis
18501 @item whatis[/@var{flags}] [@var{arg}]
18502 Print the data type of @var{arg}, which can be either an expression
18503 or a name of a data type. With no argument, print the data type of
18504 @code{$}, the last value in the value history.
18505
18506 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18507 is not actually evaluated, and any side-effecting operations (such as
18508 assignments or function calls) inside it do not take place.
18509
18510 If @var{arg} is a variable or an expression, @code{whatis} prints its
18511 literal type as it is used in the source code. If the type was
18512 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18513 the data type underlying the @code{typedef}. If the type of the
18514 variable or the expression is a compound data type, such as
18515 @code{struct} or @code{class}, @code{whatis} never prints their
18516 fields or methods. It just prints the @code{struct}/@code{class}
18517 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18518 such a compound data type, use @code{ptype}.
18519
18520 If @var{arg} is a type name that was defined using @code{typedef},
18521 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18522 Unrolling means that @code{whatis} will show the underlying type used
18523 in the @code{typedef} declaration of @var{arg}. However, if that
18524 underlying type is also a @code{typedef}, @code{whatis} will not
18525 unroll it.
18526
18527 For C code, the type names may also have the form @samp{class
18528 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18529 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18530
18531 @var{flags} can be used to modify how the type is displayed.
18532 Available flags are:
18533
18534 @table @code
18535 @item r
18536 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18537 parameters and typedefs defined in a class when printing the class'
18538 members. The @code{/r} flag disables this.
18539
18540 @item m
18541 Do not print methods defined in the class.
18542
18543 @item M
18544 Print methods defined in the class. This is the default, but the flag
18545 exists in case you change the default with @command{set print type methods}.
18546
18547 @item t
18548 Do not print typedefs defined in the class. Note that this controls
18549 whether the typedef definition itself is printed, not whether typedef
18550 names are substituted when printing other types.
18551
18552 @item T
18553 Print typedefs defined in the class. This is the default, but the flag
18554 exists in case you change the default with @command{set print type typedefs}.
18555
18556 @item o
18557 Print the offsets and sizes of fields in a struct, similar to what the
18558 @command{pahole} tool does. This option implies the @code{/tm} flags.
18559
18560 For example, given the following declarations:
18561
18562 @smallexample
18563 struct tuv
18564 @{
18565 int a1;
18566 char *a2;
18567 int a3;
18568 @};
18569
18570 struct xyz
18571 @{
18572 int f1;
18573 char f2;
18574 void *f3;
18575 struct tuv f4;
18576 @};
18577
18578 union qwe
18579 @{
18580 struct tuv fff1;
18581 struct xyz fff2;
18582 @};
18583
18584 struct tyu
18585 @{
18586 int a1 : 1;
18587 int a2 : 3;
18588 int a3 : 23;
18589 char a4 : 2;
18590 int64_t a5;
18591 int a6 : 5;
18592 int64_t a7 : 3;
18593 @};
18594 @end smallexample
18595
18596 Issuing a @kbd{ptype /o struct tuv} command would print:
18597
18598 @smallexample
18599 (@value{GDBP}) ptype /o struct tuv
18600 /* offset | size */ type = struct tuv @{
18601 /* 0 | 4 */ int a1;
18602 /* XXX 4-byte hole */
18603 /* 8 | 8 */ char *a2;
18604 /* 16 | 4 */ int a3;
18605
18606 /* total size (bytes): 24 */
18607 @}
18608 @end smallexample
18609
18610 Notice the format of the first column of comments. There, you can
18611 find two parts separated by the @samp{|} character: the @emph{offset},
18612 which indicates where the field is located inside the struct, in
18613 bytes, and the @emph{size} of the field. Another interesting line is
18614 the marker of a @emph{hole} in the struct, indicating that it may be
18615 possible to pack the struct and make it use less space by reorganizing
18616 its fields.
18617
18618 It is also possible to print offsets inside an union:
18619
18620 @smallexample
18621 (@value{GDBP}) ptype /o union qwe
18622 /* offset | size */ type = union qwe @{
18623 /* 24 */ struct tuv @{
18624 /* 0 | 4 */ int a1;
18625 /* XXX 4-byte hole */
18626 /* 8 | 8 */ char *a2;
18627 /* 16 | 4 */ int a3;
18628
18629 /* total size (bytes): 24 */
18630 @} fff1;
18631 /* 40 */ struct xyz @{
18632 /* 0 | 4 */ int f1;
18633 /* 4 | 1 */ char f2;
18634 /* XXX 3-byte hole */
18635 /* 8 | 8 */ void *f3;
18636 /* 16 | 24 */ struct tuv @{
18637 /* 16 | 4 */ int a1;
18638 /* XXX 4-byte hole */
18639 /* 24 | 8 */ char *a2;
18640 /* 32 | 4 */ int a3;
18641
18642 /* total size (bytes): 24 */
18643 @} f4;
18644
18645 /* total size (bytes): 40 */
18646 @} fff2;
18647
18648 /* total size (bytes): 40 */
18649 @}
18650 @end smallexample
18651
18652 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18653 same space (because we are dealing with an union), the offset is not
18654 printed for them. However, you can still examine the offset of each
18655 of these structures' fields.
18656
18657 Another useful scenario is printing the offsets of a struct containing
18658 bitfields:
18659
18660 @smallexample
18661 (@value{GDBP}) ptype /o struct tyu
18662 /* offset | size */ type = struct tyu @{
18663 /* 0:31 | 4 */ int a1 : 1;
18664 /* 0:28 | 4 */ int a2 : 3;
18665 /* 0: 5 | 4 */ int a3 : 23;
18666 /* 3: 3 | 1 */ signed char a4 : 2;
18667 /* XXX 3-bit hole */
18668 /* XXX 4-byte hole */
18669 /* 8 | 8 */ int64_t a5;
18670 /* 16: 0 | 4 */ int a6 : 5;
18671 /* 16: 5 | 8 */ int64_t a7 : 3;
18672 "/* XXX 7-byte padding */
18673
18674 /* total size (bytes): 24 */
18675 @}
18676 @end smallexample
18677
18678 Note how the offset information is now extended to also include the
18679 first bit of the bitfield.
18680 @end table
18681
18682 @kindex ptype
18683 @item ptype[/@var{flags}] [@var{arg}]
18684 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
18685 detailed description of the type, instead of just the name of the type.
18686 @xref{Expressions, ,Expressions}.
18687
18688 Contrary to @code{whatis}, @code{ptype} always unrolls any
18689 @code{typedef}s in its argument declaration, whether the argument is
18690 a variable, expression, or a data type. This means that @code{ptype}
18691 of a variable or an expression will not print literally its type as
18692 present in the source code---use @code{whatis} for that. @code{typedef}s at
18693 the pointer or reference targets are also unrolled. Only @code{typedef}s of
18694 fields, methods and inner @code{class typedef}s of @code{struct}s,
18695 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18696
18697 For example, for this variable declaration:
18698
18699 @smallexample
18700 typedef double real_t;
18701 struct complex @{ real_t real; double imag; @};
18702 typedef struct complex complex_t;
18703 complex_t var;
18704 real_t *real_pointer_var;
18705 @end smallexample
18706
18707 @noindent
18708 the two commands give this output:
18709
18710 @smallexample
18711 @group
18712 (@value{GDBP}) whatis var
18713 type = complex_t
18714 (@value{GDBP}) ptype var
18715 type = struct complex @{
18716 real_t real;
18717 double imag;
18718 @}
18719 (@value{GDBP}) whatis complex_t
18720 type = struct complex
18721 (@value{GDBP}) whatis struct complex
18722 type = struct complex
18723 (@value{GDBP}) ptype struct complex
18724 type = struct complex @{
18725 real_t real;
18726 double imag;
18727 @}
18728 (@value{GDBP}) whatis real_pointer_var
18729 type = real_t *
18730 (@value{GDBP}) ptype real_pointer_var
18731 type = double *
18732 @end group
18733 @end smallexample
18734
18735 @noindent
18736 As with @code{whatis}, using @code{ptype} without an argument refers to
18737 the type of @code{$}, the last value in the value history.
18738
18739 @cindex incomplete type
18740 Sometimes, programs use opaque data types or incomplete specifications
18741 of complex data structure. If the debug information included in the
18742 program does not allow @value{GDBN} to display a full declaration of
18743 the data type, it will say @samp{<incomplete type>}. For example,
18744 given these declarations:
18745
18746 @smallexample
18747 struct foo;
18748 struct foo *fooptr;
18749 @end smallexample
18750
18751 @noindent
18752 but no definition for @code{struct foo} itself, @value{GDBN} will say:
18753
18754 @smallexample
18755 (@value{GDBP}) ptype foo
18756 $1 = <incomplete type>
18757 @end smallexample
18758
18759 @noindent
18760 ``Incomplete type'' is C terminology for data types that are not
18761 completely specified.
18762
18763 @cindex unknown type
18764 Othertimes, information about a variable's type is completely absent
18765 from the debug information included in the program. This most often
18766 happens when the program or library where the variable is defined
18767 includes no debug information at all. @value{GDBN} knows the variable
18768 exists from inspecting the linker/loader symbol table (e.g., the ELF
18769 dynamic symbol table), but such symbols do not contain type
18770 information. Inspecting the type of a (global) variable for which
18771 @value{GDBN} has no type information shows:
18772
18773 @smallexample
18774 (@value{GDBP}) ptype var
18775 type = <data variable, no debug info>
18776 @end smallexample
18777
18778 @xref{Variables, no debug info variables}, for how to print the values
18779 of such variables.
18780
18781 @kindex info types
18782 @item info types [-q] [@var{regexp}]
18783 Print a brief description of all types whose names match the regular
18784 expression @var{regexp} (or all types in your program, if you supply
18785 no argument). Each complete typename is matched as though it were a
18786 complete line; thus, @samp{i type value} gives information on all
18787 types in your program whose names include the string @code{value}, but
18788 @samp{i type ^value$} gives information only on types whose complete
18789 name is @code{value}.
18790
18791 In programs using different languages, @value{GDBN} chooses the syntax
18792 to print the type description according to the
18793 @samp{set language} value: using @samp{set language auto}
18794 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18795 language of the type, other values mean to use
18796 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18797
18798 This command differs from @code{ptype} in two ways: first, like
18799 @code{whatis}, it does not print a detailed description; second, it
18800 lists all source files and line numbers where a type is defined.
18801
18802 The output from @samp{into types} is proceeded with a header line
18803 describing what types are being listed. The optional flag @samp{-q},
18804 which stands for @samp{quiet}, disables printing this header
18805 information.
18806
18807 @kindex info type-printers
18808 @item info type-printers
18809 Versions of @value{GDBN} that ship with Python scripting enabled may
18810 have ``type printers'' available. When using @command{ptype} or
18811 @command{whatis}, these printers are consulted when the name of a type
18812 is needed. @xref{Type Printing API}, for more information on writing
18813 type printers.
18814
18815 @code{info type-printers} displays all the available type printers.
18816
18817 @kindex enable type-printer
18818 @kindex disable type-printer
18819 @item enable type-printer @var{name}@dots{}
18820 @item disable type-printer @var{name}@dots{}
18821 These commands can be used to enable or disable type printers.
18822
18823 @kindex info scope
18824 @cindex local variables
18825 @item info scope @var{location}
18826 List all the variables local to a particular scope. This command
18827 accepts a @var{location} argument---a function name, a source line, or
18828 an address preceded by a @samp{*}, and prints all the variables local
18829 to the scope defined by that location. (@xref{Specify Location}, for
18830 details about supported forms of @var{location}.) For example:
18831
18832 @smallexample
18833 (@value{GDBP}) @b{info scope command_line_handler}
18834 Scope for command_line_handler:
18835 Symbol rl is an argument at stack/frame offset 8, length 4.
18836 Symbol linebuffer is in static storage at address 0x150a18, length 4.
18837 Symbol linelength is in static storage at address 0x150a1c, length 4.
18838 Symbol p is a local variable in register $esi, length 4.
18839 Symbol p1 is a local variable in register $ebx, length 4.
18840 Symbol nline is a local variable in register $edx, length 4.
18841 Symbol repeat is a local variable at frame offset -8, length 4.
18842 @end smallexample
18843
18844 @noindent
18845 This command is especially useful for determining what data to collect
18846 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18847 collect}.
18848
18849 @kindex info source
18850 @item info source
18851 Show information about the current source file---that is, the source file for
18852 the function containing the current point of execution:
18853 @itemize @bullet
18854 @item
18855 the name of the source file, and the directory containing it,
18856 @item
18857 the directory it was compiled in,
18858 @item
18859 its length, in lines,
18860 @item
18861 which programming language it is written in,
18862 @item
18863 if the debug information provides it, the program that compiled the file
18864 (which may include, e.g., the compiler version and command line arguments),
18865 @item
18866 whether the executable includes debugging information for that file, and
18867 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18868 @item
18869 whether the debugging information includes information about
18870 preprocessor macros.
18871 @end itemize
18872
18873
18874 @kindex info sources
18875 @item info sources
18876 Print the names of all source files in your program for which there is
18877 debugging information, organized into two lists: files whose symbols
18878 have already been read, and files whose symbols will be read when needed.
18879
18880 @item info sources [-dirname | -basename] [--] [@var{regexp}]
18881 Like @samp{info sources}, but only print the names of the files
18882 matching the provided @var{regexp}.
18883 By default, the @var{regexp} is used to match anywhere in the filename.
18884 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
18885 If @code{-basename}, only files having a basename matching @var{regexp}
18886 are shown.
18887 The matching is case-sensitive, except on operating systems that
18888 have case-insensitive filesystem (e.g., MS-Windows).
18889
18890 @kindex info functions
18891 @item info functions [-q] [-n]
18892 Print the names and data types of all defined functions.
18893 Similarly to @samp{info types}, this command groups its output by source
18894 files and annotates each function definition with its source line
18895 number.
18896
18897 In programs using different languages, @value{GDBN} chooses the syntax
18898 to print the function name and type according to the
18899 @samp{set language} value: using @samp{set language auto}
18900 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18901 language of the function, other values mean to use
18902 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18903
18904 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
18905 results. A non-debugging symbol is a symbol that comes from the
18906 executable's symbol table, not from the debug information (for
18907 example, DWARF) associated with the executable.
18908
18909 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18910 printing header information and messages explaining why no functions
18911 have been printed.
18912
18913 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
18914 Like @samp{info functions}, but only print the names and data types
18915 of the functions selected with the provided regexp(s).
18916
18917 If @var{regexp} is provided, print only the functions whose names
18918 match the regular expression @var{regexp}.
18919 Thus, @samp{info fun step} finds all functions whose
18920 names include @code{step}; @samp{info fun ^step} finds those whose names
18921 start with @code{step}. If a function name contains characters that
18922 conflict with the regular expression language (e.g.@:
18923 @samp{operator*()}), they may be quoted with a backslash.
18924
18925 If @var{type_regexp} is provided, print only the functions whose
18926 types, as printed by the @code{whatis} command, match
18927 the regular expression @var{type_regexp}.
18928 If @var{type_regexp} contains space(s), it should be enclosed in
18929 quote characters. If needed, use backslash to escape the meaning
18930 of special characters or quotes.
18931 Thus, @samp{info fun -t '^int ('} finds the functions that return
18932 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
18933 have an argument type containing int; @samp{info fun -t '^int (' ^step}
18934 finds the functions whose names start with @code{step} and that return
18935 int.
18936
18937 If both @var{regexp} and @var{type_regexp} are provided, a function
18938 is printed only if its name matches @var{regexp} and its type matches
18939 @var{type_regexp}.
18940
18941
18942 @kindex info variables
18943 @item info variables [-q] [-n]
18944 Print the names and data types of all variables that are defined
18945 outside of functions (i.e.@: excluding local variables).
18946 The printed variables are grouped by source files and annotated with
18947 their respective source line numbers.
18948
18949 In programs using different languages, @value{GDBN} chooses the syntax
18950 to print the variable name and type according to the
18951 @samp{set language} value: using @samp{set language auto}
18952 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18953 language of the variable, other values mean to use
18954 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18955
18956 The @samp{-n} flag excludes non-debugging symbols from the results.
18957
18958 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18959 printing header information and messages explaining why no variables
18960 have been printed.
18961
18962 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
18963 Like @kbd{info variables}, but only print the variables selected
18964 with the provided regexp(s).
18965
18966 If @var{regexp} is provided, print only the variables whose names
18967 match the regular expression @var{regexp}.
18968
18969 If @var{type_regexp} is provided, print only the variables whose
18970 types, as printed by the @code{whatis} command, match
18971 the regular expression @var{type_regexp}.
18972 If @var{type_regexp} contains space(s), it should be enclosed in
18973 quote characters. If needed, use backslash to escape the meaning
18974 of special characters or quotes.
18975
18976 If both @var{regexp} and @var{type_regexp} are provided, an argument
18977 is printed only if its name matches @var{regexp} and its type matches
18978 @var{type_regexp}.
18979
18980 @kindex info modules
18981 @cindex modules
18982 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
18983 List all Fortran modules in the program, or all modules matching the
18984 optional regular expression @var{regexp}.
18985
18986 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18987 printing header information and messages explaining why no modules
18988 have been printed.
18989
18990 @kindex info module
18991 @cindex Fortran modules, information about
18992 @cindex functions and variables by Fortran module
18993 @cindex module functions and variables
18994 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
18995 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
18996 List all functions or variables within all Fortran modules. The set
18997 of functions or variables listed can be limited by providing some or
18998 all of the optional regular expressions. If @var{module-regexp} is
18999 provided, then only Fortran modules matching @var{module-regexp} will
19000 be searched. Only functions or variables whose type matches the
19001 optional regular expression @var{type-regexp} will be listed. And
19002 only functions or variables whose name matches the optional regular
19003 expression @var{regexp} will be listed.
19004
19005 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19006 printing header information and messages explaining why no functions
19007 or variables have been printed.
19008
19009 @kindex info classes
19010 @cindex Objective-C, classes and selectors
19011 @item info classes
19012 @itemx info classes @var{regexp}
19013 Display all Objective-C classes in your program, or
19014 (with the @var{regexp} argument) all those matching a particular regular
19015 expression.
19016
19017 @kindex info selectors
19018 @item info selectors
19019 @itemx info selectors @var{regexp}
19020 Display all Objective-C selectors in your program, or
19021 (with the @var{regexp} argument) all those matching a particular regular
19022 expression.
19023
19024 @ignore
19025 This was never implemented.
19026 @kindex info methods
19027 @item info methods
19028 @itemx info methods @var{regexp}
19029 The @code{info methods} command permits the user to examine all defined
19030 methods within C@t{++} program, or (with the @var{regexp} argument) a
19031 specific set of methods found in the various C@t{++} classes. Many
19032 C@t{++} classes provide a large number of methods. Thus, the output
19033 from the @code{ptype} command can be overwhelming and hard to use. The
19034 @code{info-methods} command filters the methods, printing only those
19035 which match the regular-expression @var{regexp}.
19036 @end ignore
19037
19038 @cindex opaque data types
19039 @kindex set opaque-type-resolution
19040 @item set opaque-type-resolution on
19041 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19042 declared as a pointer to a @code{struct}, @code{class}, or
19043 @code{union}---for example, @code{struct MyType *}---that is used in one
19044 source file although the full declaration of @code{struct MyType} is in
19045 another source file. The default is on.
19046
19047 A change in the setting of this subcommand will not take effect until
19048 the next time symbols for a file are loaded.
19049
19050 @item set opaque-type-resolution off
19051 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19052 is printed as follows:
19053 @smallexample
19054 @{<no data fields>@}
19055 @end smallexample
19056
19057 @kindex show opaque-type-resolution
19058 @item show opaque-type-resolution
19059 Show whether opaque types are resolved or not.
19060
19061 @kindex set print symbol-loading
19062 @cindex print messages when symbols are loaded
19063 @item set print symbol-loading
19064 @itemx set print symbol-loading full
19065 @itemx set print symbol-loading brief
19066 @itemx set print symbol-loading off
19067 The @code{set print symbol-loading} command allows you to control the
19068 printing of messages when @value{GDBN} loads symbol information.
19069 By default a message is printed for the executable and one for each
19070 shared library, and normally this is what you want. However, when
19071 debugging apps with large numbers of shared libraries these messages
19072 can be annoying.
19073 When set to @code{brief} a message is printed for each executable,
19074 and when @value{GDBN} loads a collection of shared libraries at once
19075 it will only print one message regardless of the number of shared
19076 libraries. When set to @code{off} no messages are printed.
19077
19078 @kindex show print symbol-loading
19079 @item show print symbol-loading
19080 Show whether messages will be printed when a @value{GDBN} command
19081 entered from the keyboard causes symbol information to be loaded.
19082
19083 @kindex maint print symbols
19084 @cindex symbol dump
19085 @kindex maint print psymbols
19086 @cindex partial symbol dump
19087 @kindex maint print msymbols
19088 @cindex minimal symbol dump
19089 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19090 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19091 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19092 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19093 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19094 Write a dump of debugging symbol data into the file @var{filename} or
19095 the terminal if @var{filename} is unspecified.
19096 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19097 that objfile.
19098 If @code{-pc @var{address}} is specified, only dump symbols for the file
19099 with code at that address. Note that @var{address} may be a symbol like
19100 @code{main}.
19101 If @code{-source @var{source}} is specified, only dump symbols for that
19102 source file.
19103
19104 These commands are used to debug the @value{GDBN} symbol-reading code.
19105 These commands do not modify internal @value{GDBN} state, therefore
19106 @samp{maint print symbols} will only print symbols for already expanded symbol
19107 tables.
19108 You can use the command @code{info sources} to find out which files these are.
19109 If you use @samp{maint print psymbols} instead, the dump shows information
19110 about symbols that @value{GDBN} only knows partially---that is, symbols
19111 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19112 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19113 ``ELF symbols''.
19114
19115 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19116 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19117
19118 @kindex maint info symtabs
19119 @kindex maint info psymtabs
19120 @cindex listing @value{GDBN}'s internal symbol tables
19121 @cindex symbol tables, listing @value{GDBN}'s internal
19122 @cindex full symbol tables, listing @value{GDBN}'s internal
19123 @cindex partial symbol tables, listing @value{GDBN}'s internal
19124 @item maint info symtabs @r{[} @var{regexp} @r{]}
19125 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19126
19127 List the @code{struct symtab} or @code{struct partial_symtab}
19128 structures whose names match @var{regexp}. If @var{regexp} is not
19129 given, list them all. The output includes expressions which you can
19130 copy into a @value{GDBN} debugging this one to examine a particular
19131 structure in more detail. For example:
19132
19133 @smallexample
19134 (@value{GDBP}) maint info psymtabs dwarf2read
19135 @{ objfile /home/gnu/build/gdb/gdb
19136 ((struct objfile *) 0x82e69d0)
19137 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19138 ((struct partial_symtab *) 0x8474b10)
19139 readin no
19140 fullname (null)
19141 text addresses 0x814d3c8 -- 0x8158074
19142 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19143 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19144 dependencies (none)
19145 @}
19146 @}
19147 (@value{GDBP}) maint info symtabs
19148 (@value{GDBP})
19149 @end smallexample
19150 @noindent
19151 We see that there is one partial symbol table whose filename contains
19152 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19153 and we see that @value{GDBN} has not read in any symtabs yet at all.
19154 If we set a breakpoint on a function, that will cause @value{GDBN} to
19155 read the symtab for the compilation unit containing that function:
19156
19157 @smallexample
19158 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19159 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19160 line 1574.
19161 (@value{GDBP}) maint info symtabs
19162 @{ objfile /home/gnu/build/gdb/gdb
19163 ((struct objfile *) 0x82e69d0)
19164 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19165 ((struct symtab *) 0x86c1f38)
19166 dirname (null)
19167 fullname (null)
19168 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19169 linetable ((struct linetable *) 0x8370fa0)
19170 debugformat DWARF 2
19171 @}
19172 @}
19173 (@value{GDBP})
19174 @end smallexample
19175
19176 @kindex maint info line-table
19177 @cindex listing @value{GDBN}'s internal line tables
19178 @cindex line tables, listing @value{GDBN}'s internal
19179 @item maint info line-table @r{[} @var{regexp} @r{]}
19180
19181 List the @code{struct linetable} from all @code{struct symtab}
19182 instances whose name matches @var{regexp}. If @var{regexp} is not
19183 given, list the @code{struct linetable} from all @code{struct symtab}.
19184
19185 @kindex maint set symbol-cache-size
19186 @cindex symbol cache size
19187 @item maint set symbol-cache-size @var{size}
19188 Set the size of the symbol cache to @var{size}.
19189 The default size is intended to be good enough for debugging
19190 most applications. This option exists to allow for experimenting
19191 with different sizes.
19192
19193 @kindex maint show symbol-cache-size
19194 @item maint show symbol-cache-size
19195 Show the size of the symbol cache.
19196
19197 @kindex maint print symbol-cache
19198 @cindex symbol cache, printing its contents
19199 @item maint print symbol-cache
19200 Print the contents of the symbol cache.
19201 This is useful when debugging symbol cache issues.
19202
19203 @kindex maint print symbol-cache-statistics
19204 @cindex symbol cache, printing usage statistics
19205 @item maint print symbol-cache-statistics
19206 Print symbol cache usage statistics.
19207 This helps determine how well the cache is being utilized.
19208
19209 @kindex maint flush-symbol-cache
19210 @cindex symbol cache, flushing
19211 @item maint flush-symbol-cache
19212 Flush the contents of the symbol cache, all entries are removed.
19213 This command is useful when debugging the symbol cache.
19214 It is also useful when collecting performance data.
19215
19216 @end table
19217
19218 @node Altering
19219 @chapter Altering Execution
19220
19221 Once you think you have found an error in your program, you might want to
19222 find out for certain whether correcting the apparent error would lead to
19223 correct results in the rest of the run. You can find the answer by
19224 experiment, using the @value{GDBN} features for altering execution of the
19225 program.
19226
19227 For example, you can store new values into variables or memory
19228 locations, give your program a signal, restart it at a different
19229 address, or even return prematurely from a function.
19230
19231 @menu
19232 * Assignment:: Assignment to variables
19233 * Jumping:: Continuing at a different address
19234 * Signaling:: Giving your program a signal
19235 * Returning:: Returning from a function
19236 * Calling:: Calling your program's functions
19237 * Patching:: Patching your program
19238 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19239 @end menu
19240
19241 @node Assignment
19242 @section Assignment to Variables
19243
19244 @cindex assignment
19245 @cindex setting variables
19246 To alter the value of a variable, evaluate an assignment expression.
19247 @xref{Expressions, ,Expressions}. For example,
19248
19249 @smallexample
19250 print x=4
19251 @end smallexample
19252
19253 @noindent
19254 stores the value 4 into the variable @code{x}, and then prints the
19255 value of the assignment expression (which is 4).
19256 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19257 information on operators in supported languages.
19258
19259 @kindex set variable
19260 @cindex variables, setting
19261 If you are not interested in seeing the value of the assignment, use the
19262 @code{set} command instead of the @code{print} command. @code{set} is
19263 really the same as @code{print} except that the expression's value is
19264 not printed and is not put in the value history (@pxref{Value History,
19265 ,Value History}). The expression is evaluated only for its effects.
19266
19267 If the beginning of the argument string of the @code{set} command
19268 appears identical to a @code{set} subcommand, use the @code{set
19269 variable} command instead of just @code{set}. This command is identical
19270 to @code{set} except for its lack of subcommands. For example, if your
19271 program has a variable @code{width}, you get an error if you try to set
19272 a new value with just @samp{set width=13}, because @value{GDBN} has the
19273 command @code{set width}:
19274
19275 @smallexample
19276 (@value{GDBP}) whatis width
19277 type = double
19278 (@value{GDBP}) p width
19279 $4 = 13
19280 (@value{GDBP}) set width=47
19281 Invalid syntax in expression.
19282 @end smallexample
19283
19284 @noindent
19285 The invalid expression, of course, is @samp{=47}. In
19286 order to actually set the program's variable @code{width}, use
19287
19288 @smallexample
19289 (@value{GDBP}) set var width=47
19290 @end smallexample
19291
19292 Because the @code{set} command has many subcommands that can conflict
19293 with the names of program variables, it is a good idea to use the
19294 @code{set variable} command instead of just @code{set}. For example, if
19295 your program has a variable @code{g}, you run into problems if you try
19296 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19297 the command @code{set gnutarget}, abbreviated @code{set g}:
19298
19299 @smallexample
19300 @group
19301 (@value{GDBP}) whatis g
19302 type = double
19303 (@value{GDBP}) p g
19304 $1 = 1
19305 (@value{GDBP}) set g=4
19306 (@value{GDBP}) p g
19307 $2 = 1
19308 (@value{GDBP}) r
19309 The program being debugged has been started already.
19310 Start it from the beginning? (y or n) y
19311 Starting program: /home/smith/cc_progs/a.out
19312 "/home/smith/cc_progs/a.out": can't open to read symbols:
19313 Invalid bfd target.
19314 (@value{GDBP}) show g
19315 The current BFD target is "=4".
19316 @end group
19317 @end smallexample
19318
19319 @noindent
19320 The program variable @code{g} did not change, and you silently set the
19321 @code{gnutarget} to an invalid value. In order to set the variable
19322 @code{g}, use
19323
19324 @smallexample
19325 (@value{GDBP}) set var g=4
19326 @end smallexample
19327
19328 @value{GDBN} allows more implicit conversions in assignments than C; you can
19329 freely store an integer value into a pointer variable or vice versa,
19330 and you can convert any structure to any other structure that is the
19331 same length or shorter.
19332 @comment FIXME: how do structs align/pad in these conversions?
19333 @comment /doc@cygnus.com 18dec1990
19334
19335 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19336 construct to generate a value of specified type at a specified address
19337 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19338 to memory location @code{0x83040} as an integer (which implies a certain size
19339 and representation in memory), and
19340
19341 @smallexample
19342 set @{int@}0x83040 = 4
19343 @end smallexample
19344
19345 @noindent
19346 stores the value 4 into that memory location.
19347
19348 @node Jumping
19349 @section Continuing at a Different Address
19350
19351 Ordinarily, when you continue your program, you do so at the place where
19352 it stopped, with the @code{continue} command. You can instead continue at
19353 an address of your own choosing, with the following commands:
19354
19355 @table @code
19356 @kindex jump
19357 @kindex j @r{(@code{jump})}
19358 @item jump @var{location}
19359 @itemx j @var{location}
19360 Resume execution at @var{location}. Execution stops again immediately
19361 if there is a breakpoint there. @xref{Specify Location}, for a description
19362 of the different forms of @var{location}. It is common
19363 practice to use the @code{tbreak} command in conjunction with
19364 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19365
19366 The @code{jump} command does not change the current stack frame, or
19367 the stack pointer, or the contents of any memory location or any
19368 register other than the program counter. If @var{location} is in
19369 a different function from the one currently executing, the results may
19370 be bizarre if the two functions expect different patterns of arguments or
19371 of local variables. For this reason, the @code{jump} command requests
19372 confirmation if the specified line is not in the function currently
19373 executing. However, even bizarre results are predictable if you are
19374 well acquainted with the machine-language code of your program.
19375 @end table
19376
19377 On many systems, you can get much the same effect as the @code{jump}
19378 command by storing a new value into the register @code{$pc}. The
19379 difference is that this does not start your program running; it only
19380 changes the address of where it @emph{will} run when you continue. For
19381 example,
19382
19383 @smallexample
19384 set $pc = 0x485
19385 @end smallexample
19386
19387 @noindent
19388 makes the next @code{continue} command or stepping command execute at
19389 address @code{0x485}, rather than at the address where your program stopped.
19390 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19391
19392 The most common occasion to use the @code{jump} command is to back
19393 up---perhaps with more breakpoints set---over a portion of a program
19394 that has already executed, in order to examine its execution in more
19395 detail.
19396
19397 @c @group
19398 @node Signaling
19399 @section Giving your Program a Signal
19400 @cindex deliver a signal to a program
19401
19402 @table @code
19403 @kindex signal
19404 @item signal @var{signal}
19405 Resume execution where your program is stopped, but immediately give it the
19406 signal @var{signal}. The @var{signal} can be the name or the number of a
19407 signal. For example, on many systems @code{signal 2} and @code{signal
19408 SIGINT} are both ways of sending an interrupt signal.
19409
19410 Alternatively, if @var{signal} is zero, continue execution without
19411 giving a signal. This is useful when your program stopped on account of
19412 a signal and would ordinarily see the signal when resumed with the
19413 @code{continue} command; @samp{signal 0} causes it to resume without a
19414 signal.
19415
19416 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19417 delivered to the currently selected thread, not the thread that last
19418 reported a stop. This includes the situation where a thread was
19419 stopped due to a signal. So if you want to continue execution
19420 suppressing the signal that stopped a thread, you should select that
19421 same thread before issuing the @samp{signal 0} command. If you issue
19422 the @samp{signal 0} command with another thread as the selected one,
19423 @value{GDBN} detects that and asks for confirmation.
19424
19425 Invoking the @code{signal} command is not the same as invoking the
19426 @code{kill} utility from the shell. Sending a signal with @code{kill}
19427 causes @value{GDBN} to decide what to do with the signal depending on
19428 the signal handling tables (@pxref{Signals}). The @code{signal} command
19429 passes the signal directly to your program.
19430
19431 @code{signal} does not repeat when you press @key{RET} a second time
19432 after executing the command.
19433
19434 @kindex queue-signal
19435 @item queue-signal @var{signal}
19436 Queue @var{signal} to be delivered immediately to the current thread
19437 when execution of the thread resumes. The @var{signal} can be the name or
19438 the number of a signal. For example, on many systems @code{signal 2} and
19439 @code{signal SIGINT} are both ways of sending an interrupt signal.
19440 The handling of the signal must be set to pass the signal to the program,
19441 otherwise @value{GDBN} will report an error.
19442 You can control the handling of signals from @value{GDBN} with the
19443 @code{handle} command (@pxref{Signals}).
19444
19445 Alternatively, if @var{signal} is zero, any currently queued signal
19446 for the current thread is discarded and when execution resumes no signal
19447 will be delivered. This is useful when your program stopped on account
19448 of a signal and would ordinarily see the signal when resumed with the
19449 @code{continue} command.
19450
19451 This command differs from the @code{signal} command in that the signal
19452 is just queued, execution is not resumed. And @code{queue-signal} cannot
19453 be used to pass a signal whose handling state has been set to @code{nopass}
19454 (@pxref{Signals}).
19455 @end table
19456 @c @end group
19457
19458 @xref{stepping into signal handlers}, for information on how stepping
19459 commands behave when the thread has a signal queued.
19460
19461 @node Returning
19462 @section Returning from a Function
19463
19464 @table @code
19465 @cindex returning from a function
19466 @kindex return
19467 @item return
19468 @itemx return @var{expression}
19469 You can cancel execution of a function call with the @code{return}
19470 command. If you give an
19471 @var{expression} argument, its value is used as the function's return
19472 value.
19473 @end table
19474
19475 When you use @code{return}, @value{GDBN} discards the selected stack frame
19476 (and all frames within it). You can think of this as making the
19477 discarded frame return prematurely. If you wish to specify a value to
19478 be returned, give that value as the argument to @code{return}.
19479
19480 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19481 Frame}), and any other frames inside of it, leaving its caller as the
19482 innermost remaining frame. That frame becomes selected. The
19483 specified value is stored in the registers used for returning values
19484 of functions.
19485
19486 The @code{return} command does not resume execution; it leaves the
19487 program stopped in the state that would exist if the function had just
19488 returned. In contrast, the @code{finish} command (@pxref{Continuing
19489 and Stepping, ,Continuing and Stepping}) resumes execution until the
19490 selected stack frame returns naturally.
19491
19492 @value{GDBN} needs to know how the @var{expression} argument should be set for
19493 the inferior. The concrete registers assignment depends on the OS ABI and the
19494 type being returned by the selected stack frame. For example it is common for
19495 OS ABI to return floating point values in FPU registers while integer values in
19496 CPU registers. Still some ABIs return even floating point values in CPU
19497 registers. Larger integer widths (such as @code{long long int}) also have
19498 specific placement rules. @value{GDBN} already knows the OS ABI from its
19499 current target so it needs to find out also the type being returned to make the
19500 assignment into the right register(s).
19501
19502 Normally, the selected stack frame has debug info. @value{GDBN} will always
19503 use the debug info instead of the implicit type of @var{expression} when the
19504 debug info is available. For example, if you type @kbd{return -1}, and the
19505 function in the current stack frame is declared to return a @code{long long
19506 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19507 into a @code{long long int}:
19508
19509 @smallexample
19510 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19511 29 return 31;
19512 (@value{GDBP}) return -1
19513 Make func return now? (y or n) y
19514 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19515 43 printf ("result=%lld\n", func ());
19516 (@value{GDBP})
19517 @end smallexample
19518
19519 However, if the selected stack frame does not have a debug info, e.g., if the
19520 function was compiled without debug info, @value{GDBN} has to find out the type
19521 to return from user. Specifying a different type by mistake may set the value
19522 in different inferior registers than the caller code expects. For example,
19523 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19524 of a @code{long long int} result for a debug info less function (on 32-bit
19525 architectures). Therefore the user is required to specify the return type by
19526 an appropriate cast explicitly:
19527
19528 @smallexample
19529 Breakpoint 2, 0x0040050b in func ()
19530 (@value{GDBP}) return -1
19531 Return value type not available for selected stack frame.
19532 Please use an explicit cast of the value to return.
19533 (@value{GDBP}) return (long long int) -1
19534 Make selected stack frame return now? (y or n) y
19535 #0 0x00400526 in main ()
19536 (@value{GDBP})
19537 @end smallexample
19538
19539 @node Calling
19540 @section Calling Program Functions
19541
19542 @table @code
19543 @cindex calling functions
19544 @cindex inferior functions, calling
19545 @item print @var{expr}
19546 Evaluate the expression @var{expr} and display the resulting value.
19547 The expression may include calls to functions in the program being
19548 debugged.
19549
19550 @kindex call
19551 @item call @var{expr}
19552 Evaluate the expression @var{expr} without displaying @code{void}
19553 returned values.
19554
19555 You can use this variant of the @code{print} command if you want to
19556 execute a function from your program that does not return anything
19557 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19558 with @code{void} returned values that @value{GDBN} will otherwise
19559 print. If the result is not void, it is printed and saved in the
19560 value history.
19561 @end table
19562
19563 It is possible for the function you call via the @code{print} or
19564 @code{call} command to generate a signal (e.g., if there's a bug in
19565 the function, or if you passed it incorrect arguments). What happens
19566 in that case is controlled by the @code{set unwindonsignal} command.
19567
19568 Similarly, with a C@t{++} program it is possible for the function you
19569 call via the @code{print} or @code{call} command to generate an
19570 exception that is not handled due to the constraints of the dummy
19571 frame. In this case, any exception that is raised in the frame, but has
19572 an out-of-frame exception handler will not be found. GDB builds a
19573 dummy-frame for the inferior function call, and the unwinder cannot
19574 seek for exception handlers outside of this dummy-frame. What happens
19575 in that case is controlled by the
19576 @code{set unwind-on-terminating-exception} command.
19577
19578 @table @code
19579 @item set unwindonsignal
19580 @kindex set unwindonsignal
19581 @cindex unwind stack in called functions
19582 @cindex call dummy stack unwinding
19583 Set unwinding of the stack if a signal is received while in a function
19584 that @value{GDBN} called in the program being debugged. If set to on,
19585 @value{GDBN} unwinds the stack it created for the call and restores
19586 the context to what it was before the call. If set to off (the
19587 default), @value{GDBN} stops in the frame where the signal was
19588 received.
19589
19590 @item show unwindonsignal
19591 @kindex show unwindonsignal
19592 Show the current setting of stack unwinding in the functions called by
19593 @value{GDBN}.
19594
19595 @item set unwind-on-terminating-exception
19596 @kindex set unwind-on-terminating-exception
19597 @cindex unwind stack in called functions with unhandled exceptions
19598 @cindex call dummy stack unwinding on unhandled exception.
19599 Set unwinding of the stack if a C@t{++} exception is raised, but left
19600 unhandled while in a function that @value{GDBN} called in the program being
19601 debugged. If set to on (the default), @value{GDBN} unwinds the stack
19602 it created for the call and restores the context to what it was before
19603 the call. If set to off, @value{GDBN} the exception is delivered to
19604 the default C@t{++} exception handler and the inferior terminated.
19605
19606 @item show unwind-on-terminating-exception
19607 @kindex show unwind-on-terminating-exception
19608 Show the current setting of stack unwinding in the functions called by
19609 @value{GDBN}.
19610
19611 @item set may-call-functions
19612 @kindex set may-call-functions
19613 @cindex disabling calling functions in the program
19614 @cindex calling functions in the program, disabling
19615 Set permission to call functions in the program.
19616 This controls whether @value{GDBN} will attempt to call functions in
19617 the program, such as with expressions in the @code{print} command. It
19618 defaults to @code{on}.
19619
19620 To call a function in the program, @value{GDBN} has to temporarily
19621 modify the state of the inferior. This has potentially undesired side
19622 effects. Also, having @value{GDBN} call nested functions is likely to
19623 be erroneous and may even crash the program being debugged. You can
19624 avoid such hazards by forbidding @value{GDBN} from calling functions
19625 in the program being debugged. If calling functions in the program
19626 is forbidden, GDB will throw an error when a command (such as printing
19627 an expression) starts a function call in the program.
19628
19629 @item show may-call-functions
19630 @kindex show may-call-functions
19631 Show permission to call functions in the program.
19632
19633 @end table
19634
19635 @subsection Calling functions with no debug info
19636
19637 @cindex no debug info functions
19638 Sometimes, a function you wish to call is missing debug information.
19639 In such case, @value{GDBN} does not know the type of the function,
19640 including the types of the function's parameters. To avoid calling
19641 the inferior function incorrectly, which could result in the called
19642 function functioning erroneously and even crash, @value{GDBN} refuses
19643 to call the function unless you tell it the type of the function.
19644
19645 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19646 to do that. The simplest is to cast the call to the function's
19647 declared return type. For example:
19648
19649 @smallexample
19650 (@value{GDBP}) p getenv ("PATH")
19651 'getenv' has unknown return type; cast the call to its declared return type
19652 (@value{GDBP}) p (char *) getenv ("PATH")
19653 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19654 @end smallexample
19655
19656 Casting the return type of a no-debug function is equivalent to
19657 casting the function to a pointer to a prototyped function that has a
19658 prototype that matches the types of the passed-in arguments, and
19659 calling that. I.e., the call above is equivalent to:
19660
19661 @smallexample
19662 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19663 @end smallexample
19664
19665 @noindent
19666 and given this prototyped C or C++ function with float parameters:
19667
19668 @smallexample
19669 float multiply (float v1, float v2) @{ return v1 * v2; @}
19670 @end smallexample
19671
19672 @noindent
19673 these calls are equivalent:
19674
19675 @smallexample
19676 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19677 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19678 @end smallexample
19679
19680 If the function you wish to call is declared as unprototyped (i.e.@:
19681 old K&R style), you must use the cast-to-function-pointer syntax, so
19682 that @value{GDBN} knows that it needs to apply default argument
19683 promotions (promote float arguments to double). @xref{ABI, float
19684 promotion}. For example, given this unprototyped C function with
19685 float parameters, and no debug info:
19686
19687 @smallexample
19688 float
19689 multiply_noproto (v1, v2)
19690 float v1, v2;
19691 @{
19692 return v1 * v2;
19693 @}
19694 @end smallexample
19695
19696 @noindent
19697 you call it like this:
19698
19699 @smallexample
19700 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19701 @end smallexample
19702
19703 @node Patching
19704 @section Patching Programs
19705
19706 @cindex patching binaries
19707 @cindex writing into executables
19708 @cindex writing into corefiles
19709
19710 By default, @value{GDBN} opens the file containing your program's
19711 executable code (or the corefile) read-only. This prevents accidental
19712 alterations to machine code; but it also prevents you from intentionally
19713 patching your program's binary.
19714
19715 If you'd like to be able to patch the binary, you can specify that
19716 explicitly with the @code{set write} command. For example, you might
19717 want to turn on internal debugging flags, or even to make emergency
19718 repairs.
19719
19720 @table @code
19721 @kindex set write
19722 @item set write on
19723 @itemx set write off
19724 If you specify @samp{set write on}, @value{GDBN} opens executable and
19725 core files for both reading and writing; if you specify @kbd{set write
19726 off} (the default), @value{GDBN} opens them read-only.
19727
19728 If you have already loaded a file, you must load it again (using the
19729 @code{exec-file} or @code{core-file} command) after changing @code{set
19730 write}, for your new setting to take effect.
19731
19732 @item show write
19733 @kindex show write
19734 Display whether executable files and core files are opened for writing
19735 as well as reading.
19736 @end table
19737
19738 @node Compiling and Injecting Code
19739 @section Compiling and injecting code in @value{GDBN}
19740 @cindex injecting code
19741 @cindex writing into executables
19742 @cindex compiling code
19743
19744 @value{GDBN} supports on-demand compilation and code injection into
19745 programs running under @value{GDBN}. GCC 5.0 or higher built with
19746 @file{libcc1.so} must be installed for this functionality to be enabled.
19747 This functionality is implemented with the following commands.
19748
19749 @table @code
19750 @kindex compile code
19751 @item compile code @var{source-code}
19752 @itemx compile code -raw @var{--} @var{source-code}
19753 Compile @var{source-code} with the compiler language found as the current
19754 language in @value{GDBN} (@pxref{Languages}). If compilation and
19755 injection is not supported with the current language specified in
19756 @value{GDBN}, or the compiler does not support this feature, an error
19757 message will be printed. If @var{source-code} compiles and links
19758 successfully, @value{GDBN} will load the object-code emitted,
19759 and execute it within the context of the currently selected inferior.
19760 It is important to note that the compiled code is executed immediately.
19761 After execution, the compiled code is removed from @value{GDBN} and any
19762 new types or variables you have defined will be deleted.
19763
19764 The command allows you to specify @var{source-code} in two ways.
19765 The simplest method is to provide a single line of code to the command.
19766 E.g.:
19767
19768 @smallexample
19769 compile code printf ("hello world\n");
19770 @end smallexample
19771
19772 If you specify options on the command line as well as source code, they
19773 may conflict. The @samp{--} delimiter can be used to separate options
19774 from actual source code. E.g.:
19775
19776 @smallexample
19777 compile code -r -- printf ("hello world\n");
19778 @end smallexample
19779
19780 Alternatively you can enter source code as multiple lines of text. To
19781 enter this mode, invoke the @samp{compile code} command without any text
19782 following the command. This will start the multiple-line editor and
19783 allow you to type as many lines of source code as required. When you
19784 have completed typing, enter @samp{end} on its own line to exit the
19785 editor.
19786
19787 @smallexample
19788 compile code
19789 >printf ("hello\n");
19790 >printf ("world\n");
19791 >end
19792 @end smallexample
19793
19794 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19795 provided @var{source-code} in a callable scope. In this case, you must
19796 specify the entry point of the code by defining a function named
19797 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19798 inferior. Using @samp{-raw} option may be needed for example when
19799 @var{source-code} requires @samp{#include} lines which may conflict with
19800 inferior symbols otherwise.
19801
19802 @kindex compile file
19803 @item compile file @var{filename}
19804 @itemx compile file -raw @var{filename}
19805 Like @code{compile code}, but take the source code from @var{filename}.
19806
19807 @smallexample
19808 compile file /home/user/example.c
19809 @end smallexample
19810 @end table
19811
19812 @table @code
19813 @item compile print [[@var{options}] --] @var{expr}
19814 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
19815 Compile and execute @var{expr} with the compiler language found as the
19816 current language in @value{GDBN} (@pxref{Languages}). By default the
19817 value of @var{expr} is printed in a format appropriate to its data type;
19818 you can choose a different format by specifying @samp{/@var{f}}, where
19819 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
19820 Formats}. The @code{compile print} command accepts the same options
19821 as the @code{print} command; see @ref{print options}.
19822
19823 @item compile print [[@var{options}] --]
19824 @itemx compile print [[@var{options}] --] /@var{f}
19825 @cindex reprint the last value
19826 Alternatively you can enter the expression (source code producing it) as
19827 multiple lines of text. To enter this mode, invoke the @samp{compile print}
19828 command without any text following the command. This will start the
19829 multiple-line editor.
19830 @end table
19831
19832 @noindent
19833 The process of compiling and injecting the code can be inspected using:
19834
19835 @table @code
19836 @anchor{set debug compile}
19837 @item set debug compile
19838 @cindex compile command debugging info
19839 Turns on or off display of @value{GDBN} process of compiling and
19840 injecting the code. The default is off.
19841
19842 @item show debug compile
19843 Displays the current state of displaying @value{GDBN} process of
19844 compiling and injecting the code.
19845
19846 @anchor{set debug compile-cplus-types}
19847 @item set debug compile-cplus-types
19848 @cindex compile C@t{++} type conversion
19849 Turns on or off the display of C@t{++} type conversion debugging information.
19850 The default is off.
19851
19852 @item show debug compile-cplus-types
19853 Displays the current state of displaying debugging information for
19854 C@t{++} type conversion.
19855 @end table
19856
19857 @subsection Compilation options for the @code{compile} command
19858
19859 @value{GDBN} needs to specify the right compilation options for the code
19860 to be injected, in part to make its ABI compatible with the inferior
19861 and in part to make the injected code compatible with @value{GDBN}'s
19862 injecting process.
19863
19864 @noindent
19865 The options used, in increasing precedence:
19866
19867 @table @asis
19868 @item target architecture and OS options (@code{gdbarch})
19869 These options depend on target processor type and target operating
19870 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19871 (@code{-m64}) compilation option.
19872
19873 @item compilation options recorded in the target
19874 @value{NGCC} (since version 4.7) stores the options used for compilation
19875 into @code{DW_AT_producer} part of DWARF debugging information according
19876 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19877 explicitly specify @code{-g} during inferior compilation otherwise
19878 @value{NGCC} produces no DWARF. This feature is only relevant for
19879 platforms where @code{-g} produces DWARF by default, otherwise one may
19880 try to enforce DWARF by using @code{-gdwarf-4}.
19881
19882 @item compilation options set by @code{set compile-args}
19883 @end table
19884
19885 @noindent
19886 You can override compilation options using the following command:
19887
19888 @table @code
19889 @item set compile-args
19890 @cindex compile command options override
19891 Set compilation options used for compiling and injecting code with the
19892 @code{compile} commands. These options override any conflicting ones
19893 from the target architecture and/or options stored during inferior
19894 compilation.
19895
19896 @item show compile-args
19897 Displays the current state of compilation options override.
19898 This does not show all the options actually used during compilation,
19899 use @ref{set debug compile} for that.
19900 @end table
19901
19902 @subsection Caveats when using the @code{compile} command
19903
19904 There are a few caveats to keep in mind when using the @code{compile}
19905 command. As the caveats are different per language, the table below
19906 highlights specific issues on a per language basis.
19907
19908 @table @asis
19909 @item C code examples and caveats
19910 When the language in @value{GDBN} is set to @samp{C}, the compiler will
19911 attempt to compile the source code with a @samp{C} compiler. The source
19912 code provided to the @code{compile} command will have much the same
19913 access to variables and types as it normally would if it were part of
19914 the program currently being debugged in @value{GDBN}.
19915
19916 Below is a sample program that forms the basis of the examples that
19917 follow. This program has been compiled and loaded into @value{GDBN},
19918 much like any other normal debugging session.
19919
19920 @smallexample
19921 void function1 (void)
19922 @{
19923 int i = 42;
19924 printf ("function 1\n");
19925 @}
19926
19927 void function2 (void)
19928 @{
19929 int j = 12;
19930 function1 ();
19931 @}
19932
19933 int main(void)
19934 @{
19935 int k = 6;
19936 int *p;
19937 function2 ();
19938 return 0;
19939 @}
19940 @end smallexample
19941
19942 For the purposes of the examples in this section, the program above has
19943 been compiled, loaded into @value{GDBN}, stopped at the function
19944 @code{main}, and @value{GDBN} is awaiting input from the user.
19945
19946 To access variables and types for any program in @value{GDBN}, the
19947 program must be compiled and packaged with debug information. The
19948 @code{compile} command is not an exception to this rule. Without debug
19949 information, you can still use the @code{compile} command, but you will
19950 be very limited in what variables and types you can access.
19951
19952 So with that in mind, the example above has been compiled with debug
19953 information enabled. The @code{compile} command will have access to
19954 all variables and types (except those that may have been optimized
19955 out). Currently, as @value{GDBN} has stopped the program in the
19956 @code{main} function, the @code{compile} command would have access to
19957 the variable @code{k}. You could invoke the @code{compile} command
19958 and type some source code to set the value of @code{k}. You can also
19959 read it, or do anything with that variable you would normally do in
19960 @code{C}. Be aware that changes to inferior variables in the
19961 @code{compile} command are persistent. In the following example:
19962
19963 @smallexample
19964 compile code k = 3;
19965 @end smallexample
19966
19967 @noindent
19968 the variable @code{k} is now 3. It will retain that value until
19969 something else in the example program changes it, or another
19970 @code{compile} command changes it.
19971
19972 Normal scope and access rules apply to source code compiled and
19973 injected by the @code{compile} command. In the example, the variables
19974 @code{j} and @code{k} are not accessible yet, because the program is
19975 currently stopped in the @code{main} function, where these variables
19976 are not in scope. Therefore, the following command
19977
19978 @smallexample
19979 compile code j = 3;
19980 @end smallexample
19981
19982 @noindent
19983 will result in a compilation error message.
19984
19985 Once the program is continued, execution will bring these variables in
19986 scope, and they will become accessible; then the code you specify via
19987 the @code{compile} command will be able to access them.
19988
19989 You can create variables and types with the @code{compile} command as
19990 part of your source code. Variables and types that are created as part
19991 of the @code{compile} command are not visible to the rest of the program for
19992 the duration of its run. This example is valid:
19993
19994 @smallexample
19995 compile code int ff = 5; printf ("ff is %d\n", ff);
19996 @end smallexample
19997
19998 However, if you were to type the following into @value{GDBN} after that
19999 command has completed:
20000
20001 @smallexample
20002 compile code printf ("ff is %d\n'', ff);
20003 @end smallexample
20004
20005 @noindent
20006 a compiler error would be raised as the variable @code{ff} no longer
20007 exists. Object code generated and injected by the @code{compile}
20008 command is removed when its execution ends. Caution is advised
20009 when assigning to program variables values of variables created by the
20010 code submitted to the @code{compile} command. This example is valid:
20011
20012 @smallexample
20013 compile code int ff = 5; k = ff;
20014 @end smallexample
20015
20016 The value of the variable @code{ff} is assigned to @code{k}. The variable
20017 @code{k} does not require the existence of @code{ff} to maintain the value
20018 it has been assigned. However, pointers require particular care in
20019 assignment. If the source code compiled with the @code{compile} command
20020 changed the address of a pointer in the example program, perhaps to a
20021 variable created in the @code{compile} command, that pointer would point
20022 to an invalid location when the command exits. The following example
20023 would likely cause issues with your debugged program:
20024
20025 @smallexample
20026 compile code int ff = 5; p = &ff;
20027 @end smallexample
20028
20029 In this example, @code{p} would point to @code{ff} when the
20030 @code{compile} command is executing the source code provided to it.
20031 However, as variables in the (example) program persist with their
20032 assigned values, the variable @code{p} would point to an invalid
20033 location when the command exists. A general rule should be followed
20034 in that you should either assign @code{NULL} to any assigned pointers,
20035 or restore a valid location to the pointer before the command exits.
20036
20037 Similar caution must be exercised with any structs, unions, and typedefs
20038 defined in @code{compile} command. Types defined in the @code{compile}
20039 command will no longer be available in the next @code{compile} command.
20040 Therefore, if you cast a variable to a type defined in the
20041 @code{compile} command, care must be taken to ensure that any future
20042 need to resolve the type can be achieved.
20043
20044 @smallexample
20045 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20046 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20047 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20048 Compilation failed.
20049 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20050 42
20051 @end smallexample
20052
20053 Variables that have been optimized away by the compiler are not
20054 accessible to the code submitted to the @code{compile} command.
20055 Access to those variables will generate a compiler error which @value{GDBN}
20056 will print to the console.
20057 @end table
20058
20059 @subsection Compiler search for the @code{compile} command
20060
20061 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20062 which may not be obvious for remote targets of different architecture
20063 than where @value{GDBN} is running. Environment variable @code{PATH} on
20064 @value{GDBN} host is searched for @value{NGCC} binary matching the
20065 target architecture and operating system. This search can be overriden
20066 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20067 taken from shell that executed @value{GDBN}, it is not the value set by
20068 @value{GDBN} command @code{set environment}). @xref{Environment}.
20069
20070
20071 Specifically @code{PATH} is searched for binaries matching regular expression
20072 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20073 debugged. @var{arch} is processor name --- multiarch is supported, so for
20074 example both @code{i386} and @code{x86_64} targets look for pattern
20075 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20076 for pattern @code{s390x?}. @var{os} is currently supported only for
20077 pattern @code{linux(-gnu)?}.
20078
20079 On Posix hosts the compiler driver @value{GDBN} needs to find also
20080 shared library @file{libcc1.so} from the compiler. It is searched in
20081 default shared library search path (overridable with usual environment
20082 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20083 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20084 according to the installation of the found compiler --- as possibly
20085 specified by the @code{set compile-gcc} command.
20086
20087 @table @code
20088 @item set compile-gcc
20089 @cindex compile command driver filename override
20090 Set compilation command used for compiling and injecting code with the
20091 @code{compile} commands. If this option is not set (it is set to
20092 an empty string), the search described above will occur --- that is the
20093 default.
20094
20095 @item show compile-gcc
20096 Displays the current compile command @value{NGCC} driver filename.
20097 If set, it is the main command @command{gcc}, found usually for example
20098 under name @file{x86_64-linux-gnu-gcc}.
20099 @end table
20100
20101 @node GDB Files
20102 @chapter @value{GDBN} Files
20103
20104 @value{GDBN} needs to know the file name of the program to be debugged,
20105 both in order to read its symbol table and in order to start your
20106 program. To debug a core dump of a previous run, you must also tell
20107 @value{GDBN} the name of the core dump file.
20108
20109 @menu
20110 * Files:: Commands to specify files
20111 * File Caching:: Information about @value{GDBN}'s file caching
20112 * Separate Debug Files:: Debugging information in separate files
20113 * MiniDebugInfo:: Debugging information in a special section
20114 * Index Files:: Index files speed up GDB
20115 * Symbol Errors:: Errors reading symbol files
20116 * Data Files:: GDB data files
20117 @end menu
20118
20119 @node Files
20120 @section Commands to Specify Files
20121
20122 @cindex symbol table
20123 @cindex core dump file
20124
20125 You may want to specify executable and core dump file names. The usual
20126 way to do this is at start-up time, using the arguments to
20127 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20128 Out of @value{GDBN}}).
20129
20130 Occasionally it is necessary to change to a different file during a
20131 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20132 specify a file you want to use. Or you are debugging a remote target
20133 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20134 Program}). In these situations the @value{GDBN} commands to specify
20135 new files are useful.
20136
20137 @table @code
20138 @cindex executable file
20139 @kindex file
20140 @item file @var{filename}
20141 Use @var{filename} as the program to be debugged. It is read for its
20142 symbols and for the contents of pure memory. It is also the program
20143 executed when you use the @code{run} command. If you do not specify a
20144 directory and the file is not found in the @value{GDBN} working directory,
20145 @value{GDBN} uses the environment variable @code{PATH} as a list of
20146 directories to search, just as the shell does when looking for a program
20147 to run. You can change the value of this variable, for both @value{GDBN}
20148 and your program, using the @code{path} command.
20149
20150 @cindex unlinked object files
20151 @cindex patching object files
20152 You can load unlinked object @file{.o} files into @value{GDBN} using
20153 the @code{file} command. You will not be able to ``run'' an object
20154 file, but you can disassemble functions and inspect variables. Also,
20155 if the underlying BFD functionality supports it, you could use
20156 @kbd{gdb -write} to patch object files using this technique. Note
20157 that @value{GDBN} can neither interpret nor modify relocations in this
20158 case, so branches and some initialized variables will appear to go to
20159 the wrong place. But this feature is still handy from time to time.
20160
20161 @item file
20162 @code{file} with no argument makes @value{GDBN} discard any information it
20163 has on both executable file and the symbol table.
20164
20165 @kindex exec-file
20166 @item exec-file @r{[} @var{filename} @r{]}
20167 Specify that the program to be run (but not the symbol table) is found
20168 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20169 if necessary to locate your program. Omitting @var{filename} means to
20170 discard information on the executable file.
20171
20172 @kindex symbol-file
20173 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20174 Read symbol table information from file @var{filename}. @code{PATH} is
20175 searched when necessary. Use the @code{file} command to get both symbol
20176 table and program to run from the same file.
20177
20178 If an optional @var{offset} is specified, it is added to the start
20179 address of each section in the symbol file. This is useful if the
20180 program is relocated at runtime, such as the Linux kernel with kASLR
20181 enabled.
20182
20183 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20184 program's symbol table.
20185
20186 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20187 some breakpoints and auto-display expressions. This is because they may
20188 contain pointers to the internal data recording symbols and data types,
20189 which are part of the old symbol table data being discarded inside
20190 @value{GDBN}.
20191
20192 @code{symbol-file} does not repeat if you press @key{RET} again after
20193 executing it once.
20194
20195 When @value{GDBN} is configured for a particular environment, it
20196 understands debugging information in whatever format is the standard
20197 generated for that environment; you may use either a @sc{gnu} compiler, or
20198 other compilers that adhere to the local conventions.
20199 Best results are usually obtained from @sc{gnu} compilers; for example,
20200 using @code{@value{NGCC}} you can generate debugging information for
20201 optimized code.
20202
20203 For most kinds of object files, with the exception of old SVR3 systems
20204 using COFF, the @code{symbol-file} command does not normally read the
20205 symbol table in full right away. Instead, it scans the symbol table
20206 quickly to find which source files and which symbols are present. The
20207 details are read later, one source file at a time, as they are needed.
20208
20209 The purpose of this two-stage reading strategy is to make @value{GDBN}
20210 start up faster. For the most part, it is invisible except for
20211 occasional pauses while the symbol table details for a particular source
20212 file are being read. (The @code{set verbose} command can turn these
20213 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20214 Warnings and Messages}.)
20215
20216 We have not implemented the two-stage strategy for COFF yet. When the
20217 symbol table is stored in COFF format, @code{symbol-file} reads the
20218 symbol table data in full right away. Note that ``stabs-in-COFF''
20219 still does the two-stage strategy, since the debug info is actually
20220 in stabs format.
20221
20222 @kindex readnow
20223 @cindex reading symbols immediately
20224 @cindex symbols, reading immediately
20225 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20226 @itemx file @r{[} -readnow @r{]} @var{filename}
20227 You can override the @value{GDBN} two-stage strategy for reading symbol
20228 tables by using the @samp{-readnow} option with any of the commands that
20229 load symbol table information, if you want to be sure @value{GDBN} has the
20230 entire symbol table available.
20231
20232 @cindex @code{-readnever}, option for symbol-file command
20233 @cindex never read symbols
20234 @cindex symbols, never read
20235 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20236 @itemx file @r{[} -readnever @r{]} @var{filename}
20237 You can instruct @value{GDBN} to never read the symbolic information
20238 contained in @var{filename} by using the @samp{-readnever} option.
20239 @xref{--readnever}.
20240
20241 @c FIXME: for now no mention of directories, since this seems to be in
20242 @c flux. 13mar1992 status is that in theory GDB would look either in
20243 @c current dir or in same dir as myprog; but issues like competing
20244 @c GDB's, or clutter in system dirs, mean that in practice right now
20245 @c only current dir is used. FFish says maybe a special GDB hierarchy
20246 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20247 @c files.
20248
20249 @kindex core-file
20250 @item core-file @r{[}@var{filename}@r{]}
20251 @itemx core
20252 Specify the whereabouts of a core dump file to be used as the ``contents
20253 of memory''. Traditionally, core files contain only some parts of the
20254 address space of the process that generated them; @value{GDBN} can access the
20255 executable file itself for other parts.
20256
20257 @code{core-file} with no argument specifies that no core file is
20258 to be used.
20259
20260 Note that the core file is ignored when your program is actually running
20261 under @value{GDBN}. So, if you have been running your program and you
20262 wish to debug a core file instead, you must kill the subprocess in which
20263 the program is running. To do this, use the @code{kill} command
20264 (@pxref{Kill Process, ,Killing the Child Process}).
20265
20266 @kindex add-symbol-file
20267 @cindex dynamic linking
20268 @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{]}
20269 The @code{add-symbol-file} command reads additional symbol table
20270 information from the file @var{filename}. You would use this command
20271 when @var{filename} has been dynamically loaded (by some other means)
20272 into the program that is running. The @var{textaddress} parameter gives
20273 the memory address at which the file's text section has been loaded.
20274 You can additionally specify the base address of other sections using
20275 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20276 If a section is omitted, @value{GDBN} will use its default addresses
20277 as found in @var{filename}. Any @var{address} or @var{textaddress}
20278 can be given as an expression.
20279
20280 If an optional @var{offset} is specified, it is added to the start
20281 address of each section, except those for which the address was
20282 specified explicitly.
20283
20284 The symbol table of the file @var{filename} is added to the symbol table
20285 originally read with the @code{symbol-file} command. You can use the
20286 @code{add-symbol-file} command any number of times; the new symbol data
20287 thus read is kept in addition to the old.
20288
20289 Changes can be reverted using the command @code{remove-symbol-file}.
20290
20291 @cindex relocatable object files, reading symbols from
20292 @cindex object files, relocatable, reading symbols from
20293 @cindex reading symbols from relocatable object files
20294 @cindex symbols, reading from relocatable object files
20295 @cindex @file{.o} files, reading symbols from
20296 Although @var{filename} is typically a shared library file, an
20297 executable file, or some other object file which has been fully
20298 relocated for loading into a process, you can also load symbolic
20299 information from relocatable @file{.o} files, as long as:
20300
20301 @itemize @bullet
20302 @item
20303 the file's symbolic information refers only to linker symbols defined in
20304 that file, not to symbols defined by other object files,
20305 @item
20306 every section the file's symbolic information refers to has actually
20307 been loaded into the inferior, as it appears in the file, and
20308 @item
20309 you can determine the address at which every section was loaded, and
20310 provide these to the @code{add-symbol-file} command.
20311 @end itemize
20312
20313 @noindent
20314 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20315 relocatable files into an already running program; such systems
20316 typically make the requirements above easy to meet. However, it's
20317 important to recognize that many native systems use complex link
20318 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20319 assembly, for example) that make the requirements difficult to meet. In
20320 general, one cannot assume that using @code{add-symbol-file} to read a
20321 relocatable object file's symbolic information will have the same effect
20322 as linking the relocatable object file into the program in the normal
20323 way.
20324
20325 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20326
20327 @kindex remove-symbol-file
20328 @item remove-symbol-file @var{filename}
20329 @item remove-symbol-file -a @var{address}
20330 Remove a symbol file added via the @code{add-symbol-file} command. The
20331 file to remove can be identified by its @var{filename} or by an @var{address}
20332 that lies within the boundaries of this symbol file in memory. Example:
20333
20334 @smallexample
20335 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20336 add symbol table from file "/home/user/gdb/mylib.so" at
20337 .text_addr = 0x7ffff7ff9480
20338 (y or n) y
20339 Reading symbols from /home/user/gdb/mylib.so...done.
20340 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20341 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20342 (gdb)
20343 @end smallexample
20344
20345
20346 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20347
20348 @kindex add-symbol-file-from-memory
20349 @cindex @code{syscall DSO}
20350 @cindex load symbols from memory
20351 @item add-symbol-file-from-memory @var{address}
20352 Load symbols from the given @var{address} in a dynamically loaded
20353 object file whose image is mapped directly into the inferior's memory.
20354 For example, the Linux kernel maps a @code{syscall DSO} into each
20355 process's address space; this DSO provides kernel-specific code for
20356 some system calls. The argument can be any expression whose
20357 evaluation yields the address of the file's shared object file header.
20358 For this command to work, you must have used @code{symbol-file} or
20359 @code{exec-file} commands in advance.
20360
20361 @kindex section
20362 @item section @var{section} @var{addr}
20363 The @code{section} command changes the base address of the named
20364 @var{section} of the exec file to @var{addr}. This can be used if the
20365 exec file does not contain section addresses, (such as in the
20366 @code{a.out} format), or when the addresses specified in the file
20367 itself are wrong. Each section must be changed separately. The
20368 @code{info files} command, described below, lists all the sections and
20369 their addresses.
20370
20371 @kindex info files
20372 @kindex info target
20373 @item info files
20374 @itemx info target
20375 @code{info files} and @code{info target} are synonymous; both print the
20376 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20377 including the names of the executable and core dump files currently in
20378 use by @value{GDBN}, and the files from which symbols were loaded. The
20379 command @code{help target} lists all possible targets rather than
20380 current ones.
20381
20382 @kindex maint info sections
20383 @item maint info sections
20384 Another command that can give you extra information about program sections
20385 is @code{maint info sections}. In addition to the section information
20386 displayed by @code{info files}, this command displays the flags and file
20387 offset of each section in the executable and core dump files. In addition,
20388 @code{maint info sections} provides the following command options (which
20389 may be arbitrarily combined):
20390
20391 @table @code
20392 @item ALLOBJ
20393 Display sections for all loaded object files, including shared libraries.
20394 @item @var{sections}
20395 Display info only for named @var{sections}.
20396 @item @var{section-flags}
20397 Display info only for sections for which @var{section-flags} are true.
20398 The section flags that @value{GDBN} currently knows about are:
20399 @table @code
20400 @item ALLOC
20401 Section will have space allocated in the process when loaded.
20402 Set for all sections except those containing debug information.
20403 @item LOAD
20404 Section will be loaded from the file into the child process memory.
20405 Set for pre-initialized code and data, clear for @code{.bss} sections.
20406 @item RELOC
20407 Section needs to be relocated before loading.
20408 @item READONLY
20409 Section cannot be modified by the child process.
20410 @item CODE
20411 Section contains executable code only.
20412 @item DATA
20413 Section contains data only (no executable code).
20414 @item ROM
20415 Section will reside in ROM.
20416 @item CONSTRUCTOR
20417 Section contains data for constructor/destructor lists.
20418 @item HAS_CONTENTS
20419 Section is not empty.
20420 @item NEVER_LOAD
20421 An instruction to the linker to not output the section.
20422 @item COFF_SHARED_LIBRARY
20423 A notification to the linker that the section contains
20424 COFF shared library information.
20425 @item IS_COMMON
20426 Section contains common symbols.
20427 @end table
20428 @end table
20429 @kindex set trust-readonly-sections
20430 @cindex read-only sections
20431 @item set trust-readonly-sections on
20432 Tell @value{GDBN} that readonly sections in your object file
20433 really are read-only (i.e.@: that their contents will not change).
20434 In that case, @value{GDBN} can fetch values from these sections
20435 out of the object file, rather than from the target program.
20436 For some targets (notably embedded ones), this can be a significant
20437 enhancement to debugging performance.
20438
20439 The default is off.
20440
20441 @item set trust-readonly-sections off
20442 Tell @value{GDBN} not to trust readonly sections. This means that
20443 the contents of the section might change while the program is running,
20444 and must therefore be fetched from the target when needed.
20445
20446 @item show trust-readonly-sections
20447 Show the current setting of trusting readonly sections.
20448 @end table
20449
20450 All file-specifying commands allow both absolute and relative file names
20451 as arguments. @value{GDBN} always converts the file name to an absolute file
20452 name and remembers it that way.
20453
20454 @cindex shared libraries
20455 @anchor{Shared Libraries}
20456 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20457 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20458 DSBT (TIC6X) shared libraries.
20459
20460 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20461 shared libraries. @xref{Expat}.
20462
20463 @value{GDBN} automatically loads symbol definitions from shared libraries
20464 when you use the @code{run} command, or when you examine a core file.
20465 (Before you issue the @code{run} command, @value{GDBN} does not understand
20466 references to a function in a shared library, however---unless you are
20467 debugging a core file).
20468
20469 @c FIXME: some @value{GDBN} release may permit some refs to undef
20470 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20471 @c FIXME...lib; check this from time to time when updating manual
20472
20473 There are times, however, when you may wish to not automatically load
20474 symbol definitions from shared libraries, such as when they are
20475 particularly large or there are many of them.
20476
20477 To control the automatic loading of shared library symbols, use the
20478 commands:
20479
20480 @table @code
20481 @kindex set auto-solib-add
20482 @item set auto-solib-add @var{mode}
20483 If @var{mode} is @code{on}, symbols from all shared object libraries
20484 will be loaded automatically when the inferior begins execution, you
20485 attach to an independently started inferior, or when the dynamic linker
20486 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20487 is @code{off}, symbols must be loaded manually, using the
20488 @code{sharedlibrary} command. The default value is @code{on}.
20489
20490 @cindex memory used for symbol tables
20491 If your program uses lots of shared libraries with debug info that
20492 takes large amounts of memory, you can decrease the @value{GDBN}
20493 memory footprint by preventing it from automatically loading the
20494 symbols from shared libraries. To that end, type @kbd{set
20495 auto-solib-add off} before running the inferior, then load each
20496 library whose debug symbols you do need with @kbd{sharedlibrary
20497 @var{regexp}}, where @var{regexp} is a regular expression that matches
20498 the libraries whose symbols you want to be loaded.
20499
20500 @kindex show auto-solib-add
20501 @item show auto-solib-add
20502 Display the current autoloading mode.
20503 @end table
20504
20505 @cindex load shared library
20506 To explicitly load shared library symbols, use the @code{sharedlibrary}
20507 command:
20508
20509 @table @code
20510 @kindex info sharedlibrary
20511 @kindex info share
20512 @item info share @var{regex}
20513 @itemx info sharedlibrary @var{regex}
20514 Print the names of the shared libraries which are currently loaded
20515 that match @var{regex}. If @var{regex} is omitted then print
20516 all shared libraries that are loaded.
20517
20518 @kindex info dll
20519 @item info dll @var{regex}
20520 This is an alias of @code{info sharedlibrary}.
20521
20522 @kindex sharedlibrary
20523 @kindex share
20524 @item sharedlibrary @var{regex}
20525 @itemx share @var{regex}
20526 Load shared object library symbols for files matching a
20527 Unix regular expression.
20528 As with files loaded automatically, it only loads shared libraries
20529 required by your program for a core file or after typing @code{run}. If
20530 @var{regex} is omitted all shared libraries required by your program are
20531 loaded.
20532
20533 @item nosharedlibrary
20534 @kindex nosharedlibrary
20535 @cindex unload symbols from shared libraries
20536 Unload all shared object library symbols. This discards all symbols
20537 that have been loaded from all shared libraries. Symbols from shared
20538 libraries that were loaded by explicit user requests are not
20539 discarded.
20540 @end table
20541
20542 Sometimes you may wish that @value{GDBN} stops and gives you control
20543 when any of shared library events happen. The best way to do this is
20544 to use @code{catch load} and @code{catch unload} (@pxref{Set
20545 Catchpoints}).
20546
20547 @value{GDBN} also supports the the @code{set stop-on-solib-events}
20548 command for this. This command exists for historical reasons. It is
20549 less useful than setting a catchpoint, because it does not allow for
20550 conditions or commands as a catchpoint does.
20551
20552 @table @code
20553 @item set stop-on-solib-events
20554 @kindex set stop-on-solib-events
20555 This command controls whether @value{GDBN} should give you control
20556 when the dynamic linker notifies it about some shared library event.
20557 The most common event of interest is loading or unloading of a new
20558 shared library.
20559
20560 @item show stop-on-solib-events
20561 @kindex show stop-on-solib-events
20562 Show whether @value{GDBN} stops and gives you control when shared
20563 library events happen.
20564 @end table
20565
20566 Shared libraries are also supported in many cross or remote debugging
20567 configurations. @value{GDBN} needs to have access to the target's libraries;
20568 this can be accomplished either by providing copies of the libraries
20569 on the host system, or by asking @value{GDBN} to automatically retrieve the
20570 libraries from the target. If copies of the target libraries are
20571 provided, they need to be the same as the target libraries, although the
20572 copies on the target can be stripped as long as the copies on the host are
20573 not.
20574
20575 @cindex where to look for shared libraries
20576 For remote debugging, you need to tell @value{GDBN} where the target
20577 libraries are, so that it can load the correct copies---otherwise, it
20578 may try to load the host's libraries. @value{GDBN} has two variables
20579 to specify the search directories for target libraries.
20580
20581 @table @code
20582 @cindex prefix for executable and shared library file names
20583 @cindex system root, alternate
20584 @kindex set solib-absolute-prefix
20585 @kindex set sysroot
20586 @item set sysroot @var{path}
20587 Use @var{path} as the system root for the program being debugged. Any
20588 absolute shared library paths will be prefixed with @var{path}; many
20589 runtime loaders store the absolute paths to the shared library in the
20590 target program's memory. When starting processes remotely, and when
20591 attaching to already-running processes (local or remote), their
20592 executable filenames will be prefixed with @var{path} if reported to
20593 @value{GDBN} as absolute by the operating system. If you use
20594 @code{set sysroot} to find executables and shared libraries, they need
20595 to be laid out in the same way that they are on the target, with
20596 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20597 @var{path}.
20598
20599 If @var{path} starts with the sequence @file{target:} and the target
20600 system is remote then @value{GDBN} will retrieve the target binaries
20601 from the remote system. This is only supported when using a remote
20602 target that supports the @code{remote get} command (@pxref{File
20603 Transfer,,Sending files to a remote system}). The part of @var{path}
20604 following the initial @file{target:} (if present) is used as system
20605 root prefix on the remote file system. If @var{path} starts with the
20606 sequence @file{remote:} this is converted to the sequence
20607 @file{target:} by @code{set sysroot}@footnote{Historically the
20608 functionality to retrieve binaries from the remote system was
20609 provided by prefixing @var{path} with @file{remote:}}. If you want
20610 to specify a local system root using a directory that happens to be
20611 named @file{target:} or @file{remote:}, you need to use some
20612 equivalent variant of the name like @file{./target:}.
20613
20614 For targets with an MS-DOS based filesystem, such as MS-Windows and
20615 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20616 absolute file name with @var{path}. But first, on Unix hosts,
20617 @value{GDBN} converts all backslash directory separators into forward
20618 slashes, because the backslash is not a directory separator on Unix:
20619
20620 @smallexample
20621 c:\foo\bar.dll @result{} c:/foo/bar.dll
20622 @end smallexample
20623
20624 Then, @value{GDBN} attempts prefixing the target file name with
20625 @var{path}, and looks for the resulting file name in the host file
20626 system:
20627
20628 @smallexample
20629 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20630 @end smallexample
20631
20632 If that does not find the binary, @value{GDBN} tries removing
20633 the @samp{:} character from the drive spec, both for convenience, and,
20634 for the case of the host file system not supporting file names with
20635 colons:
20636
20637 @smallexample
20638 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20639 @end smallexample
20640
20641 This makes it possible to have a system root that mirrors a target
20642 with more than one drive. E.g., you may want to setup your local
20643 copies of the target system shared libraries like so (note @samp{c} vs
20644 @samp{z}):
20645
20646 @smallexample
20647 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20648 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20649 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20650 @end smallexample
20651
20652 @noindent
20653 and point the system root at @file{/path/to/sysroot}, so that
20654 @value{GDBN} can find the correct copies of both
20655 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20656
20657 If that still does not find the binary, @value{GDBN} tries
20658 removing the whole drive spec from the target file name:
20659
20660 @smallexample
20661 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20662 @end smallexample
20663
20664 This last lookup makes it possible to not care about the drive name,
20665 if you don't want or need to.
20666
20667 The @code{set solib-absolute-prefix} command is an alias for @code{set
20668 sysroot}.
20669
20670 @cindex default system root
20671 @cindex @samp{--with-sysroot}
20672 You can set the default system root by using the configure-time
20673 @samp{--with-sysroot} option. If the system root is inside
20674 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20675 @samp{--exec-prefix}), then the default system root will be updated
20676 automatically if the installed @value{GDBN} is moved to a new
20677 location.
20678
20679 @kindex show sysroot
20680 @item show sysroot
20681 Display the current executable and shared library prefix.
20682
20683 @kindex set solib-search-path
20684 @item set solib-search-path @var{path}
20685 If this variable is set, @var{path} is a colon-separated list of
20686 directories to search for shared libraries. @samp{solib-search-path}
20687 is used after @samp{sysroot} fails to locate the library, or if the
20688 path to the library is relative instead of absolute. If you want to
20689 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
20690 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
20691 finding your host's libraries. @samp{sysroot} is preferred; setting
20692 it to a nonexistent directory may interfere with automatic loading
20693 of shared library symbols.
20694
20695 @kindex show solib-search-path
20696 @item show solib-search-path
20697 Display the current shared library search path.
20698
20699 @cindex DOS file-name semantics of file names.
20700 @kindex set target-file-system-kind (unix|dos-based|auto)
20701 @kindex show target-file-system-kind
20702 @item set target-file-system-kind @var{kind}
20703 Set assumed file system kind for target reported file names.
20704
20705 Shared library file names as reported by the target system may not
20706 make sense as is on the system @value{GDBN} is running on. For
20707 example, when remote debugging a target that has MS-DOS based file
20708 system semantics, from a Unix host, the target may be reporting to
20709 @value{GDBN} a list of loaded shared libraries with file names such as
20710 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20711 drive letters, so the @samp{c:\} prefix is not normally understood as
20712 indicating an absolute file name, and neither is the backslash
20713 normally considered a directory separator character. In that case,
20714 the native file system would interpret this whole absolute file name
20715 as a relative file name with no directory components. This would make
20716 it impossible to point @value{GDBN} at a copy of the remote target's
20717 shared libraries on the host using @code{set sysroot}, and impractical
20718 with @code{set solib-search-path}. Setting
20719 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20720 to interpret such file names similarly to how the target would, and to
20721 map them to file names valid on @value{GDBN}'s native file system
20722 semantics. The value of @var{kind} can be @code{"auto"}, in addition
20723 to one of the supported file system kinds. In that case, @value{GDBN}
20724 tries to determine the appropriate file system variant based on the
20725 current target's operating system (@pxref{ABI, ,Configuring the
20726 Current ABI}). The supported file system settings are:
20727
20728 @table @code
20729 @item unix
20730 Instruct @value{GDBN} to assume the target file system is of Unix
20731 kind. Only file names starting the forward slash (@samp{/}) character
20732 are considered absolute, and the directory separator character is also
20733 the forward slash.
20734
20735 @item dos-based
20736 Instruct @value{GDBN} to assume the target file system is DOS based.
20737 File names starting with either a forward slash, or a drive letter
20738 followed by a colon (e.g., @samp{c:}), are considered absolute, and
20739 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20740 considered directory separators.
20741
20742 @item auto
20743 Instruct @value{GDBN} to use the file system kind associated with the
20744 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20745 This is the default.
20746 @end table
20747 @end table
20748
20749 @cindex file name canonicalization
20750 @cindex base name differences
20751 When processing file names provided by the user, @value{GDBN}
20752 frequently needs to compare them to the file names recorded in the
20753 program's debug info. Normally, @value{GDBN} compares just the
20754 @dfn{base names} of the files as strings, which is reasonably fast
20755 even for very large programs. (The base name of a file is the last
20756 portion of its name, after stripping all the leading directories.)
20757 This shortcut in comparison is based upon the assumption that files
20758 cannot have more than one base name. This is usually true, but
20759 references to files that use symlinks or similar filesystem
20760 facilities violate that assumption. If your program records files
20761 using such facilities, or if you provide file names to @value{GDBN}
20762 using symlinks etc., you can set @code{basenames-may-differ} to
20763 @code{true} to instruct @value{GDBN} to completely canonicalize each
20764 pair of file names it needs to compare. This will make file-name
20765 comparisons accurate, but at a price of a significant slowdown.
20766
20767 @table @code
20768 @item set basenames-may-differ
20769 @kindex set basenames-may-differ
20770 Set whether a source file may have multiple base names.
20771
20772 @item show basenames-may-differ
20773 @kindex show basenames-may-differ
20774 Show whether a source file may have multiple base names.
20775 @end table
20776
20777 @node File Caching
20778 @section File Caching
20779 @cindex caching of opened files
20780 @cindex caching of bfd objects
20781
20782 To speed up file loading, and reduce memory usage, @value{GDBN} will
20783 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20784 BFD, bfd, The Binary File Descriptor Library}. The following commands
20785 allow visibility and control of the caching behavior.
20786
20787 @table @code
20788 @kindex maint info bfds
20789 @item maint info bfds
20790 This prints information about each @code{bfd} object that is known to
20791 @value{GDBN}.
20792
20793 @kindex maint set bfd-sharing
20794 @kindex maint show bfd-sharing
20795 @kindex bfd caching
20796 @item maint set bfd-sharing
20797 @item maint show bfd-sharing
20798 Control whether @code{bfd} objects can be shared. When sharing is
20799 enabled @value{GDBN} reuses already open @code{bfd} objects rather
20800 than reopening the same file. Turning sharing off does not cause
20801 already shared @code{bfd} objects to be unshared, but all future files
20802 that are opened will create a new @code{bfd} object. Similarly,
20803 re-enabling sharing does not cause multiple existing @code{bfd}
20804 objects to be collapsed into a single shared @code{bfd} object.
20805
20806 @kindex set debug bfd-cache @var{level}
20807 @kindex bfd caching
20808 @item set debug bfd-cache @var{level}
20809 Turns on debugging of the bfd cache, setting the level to @var{level}.
20810
20811 @kindex show debug bfd-cache
20812 @kindex bfd caching
20813 @item show debug bfd-cache
20814 Show the current debugging level of the bfd cache.
20815 @end table
20816
20817 @node Separate Debug Files
20818 @section Debugging Information in Separate Files
20819 @cindex separate debugging information files
20820 @cindex debugging information in separate files
20821 @cindex @file{.debug} subdirectories
20822 @cindex debugging information directory, global
20823 @cindex global debugging information directories
20824 @cindex build ID, and separate debugging files
20825 @cindex @file{.build-id} directory
20826
20827 @value{GDBN} allows you to put a program's debugging information in a
20828 file separate from the executable itself, in a way that allows
20829 @value{GDBN} to find and load the debugging information automatically.
20830 Since debugging information can be very large---sometimes larger
20831 than the executable code itself---some systems distribute debugging
20832 information for their executables in separate files, which users can
20833 install only when they need to debug a problem.
20834
20835 @value{GDBN} supports two ways of specifying the separate debug info
20836 file:
20837
20838 @itemize @bullet
20839 @item
20840 The executable contains a @dfn{debug link} that specifies the name of
20841 the separate debug info file. The separate debug file's name is
20842 usually @file{@var{executable}.debug}, where @var{executable} is the
20843 name of the corresponding executable file without leading directories
20844 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
20845 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20846 checksum for the debug file, which @value{GDBN} uses to validate that
20847 the executable and the debug file came from the same build.
20848
20849 @item
20850 The executable contains a @dfn{build ID}, a unique bit string that is
20851 also present in the corresponding debug info file. (This is supported
20852 only on some operating systems, when using the ELF or PE file formats
20853 for binary files and the @sc{gnu} Binutils.) For more details about
20854 this feature, see the description of the @option{--build-id}
20855 command-line option in @ref{Options, , Command Line Options, ld,
20856 The GNU Linker}. The debug info file's name is not specified
20857 explicitly by the build ID, but can be computed from the build ID, see
20858 below.
20859 @end itemize
20860
20861 Depending on the way the debug info file is specified, @value{GDBN}
20862 uses two different methods of looking for the debug file:
20863
20864 @itemize @bullet
20865 @item
20866 For the ``debug link'' method, @value{GDBN} looks up the named file in
20867 the directory of the executable file, then in a subdirectory of that
20868 directory named @file{.debug}, and finally under each one of the
20869 global debug directories, in a subdirectory whose name is identical to
20870 the leading directories of the executable's absolute file name. (On
20871 MS-Windows/MS-DOS, the drive letter of the executable's leading
20872 directories is converted to a one-letter subdirectory, i.e.@:
20873 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20874 filesystems disallow colons in file names.)
20875
20876 @item
20877 For the ``build ID'' method, @value{GDBN} looks in the
20878 @file{.build-id} subdirectory of each one of the global debug directories for
20879 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
20880 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
20881 are the rest of the bit string. (Real build ID strings are 32 or more
20882 hex characters, not 10.)
20883 @end itemize
20884
20885 So, for example, suppose you ask @value{GDBN} to debug
20886 @file{/usr/bin/ls}, which has a debug link that specifies the
20887 file @file{ls.debug}, and a build ID whose value in hex is
20888 @code{abcdef1234}. If the list of the global debug directories includes
20889 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
20890 debug information files, in the indicated order:
20891
20892 @itemize @minus
20893 @item
20894 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
20895 @item
20896 @file{/usr/bin/ls.debug}
20897 @item
20898 @file{/usr/bin/.debug/ls.debug}
20899 @item
20900 @file{/usr/lib/debug/usr/bin/ls.debug}.
20901 @end itemize
20902
20903 @anchor{debug-file-directory}
20904 Global debugging info directories default to what is set by @value{GDBN}
20905 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
20906 you can also set the global debugging info directories, and view the list
20907 @value{GDBN} is currently using.
20908
20909 @table @code
20910
20911 @kindex set debug-file-directory
20912 @item set debug-file-directory @var{directories}
20913 Set the directories which @value{GDBN} searches for separate debugging
20914 information files to @var{directory}. Multiple path components can be set
20915 concatenating them by a path separator.
20916
20917 @kindex show debug-file-directory
20918 @item show debug-file-directory
20919 Show the directories @value{GDBN} searches for separate debugging
20920 information files.
20921
20922 @end table
20923
20924 @cindex @code{.gnu_debuglink} sections
20925 @cindex debug link sections
20926 A debug link is a special section of the executable file named
20927 @code{.gnu_debuglink}. The section must contain:
20928
20929 @itemize
20930 @item
20931 A filename, with any leading directory components removed, followed by
20932 a zero byte,
20933 @item
20934 zero to three bytes of padding, as needed to reach the next four-byte
20935 boundary within the section, and
20936 @item
20937 a four-byte CRC checksum, stored in the same endianness used for the
20938 executable file itself. The checksum is computed on the debugging
20939 information file's full contents by the function given below, passing
20940 zero as the @var{crc} argument.
20941 @end itemize
20942
20943 Any executable file format can carry a debug link, as long as it can
20944 contain a section named @code{.gnu_debuglink} with the contents
20945 described above.
20946
20947 @cindex @code{.note.gnu.build-id} sections
20948 @cindex build ID sections
20949 The build ID is a special section in the executable file (and in other
20950 ELF binary files that @value{GDBN} may consider). This section is
20951 often named @code{.note.gnu.build-id}, but that name is not mandatory.
20952 It contains unique identification for the built files---the ID remains
20953 the same across multiple builds of the same build tree. The default
20954 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
20955 content for the build ID string. The same section with an identical
20956 value is present in the original built binary with symbols, in its
20957 stripped variant, and in the separate debugging information file.
20958
20959 The debugging information file itself should be an ordinary
20960 executable, containing a full set of linker symbols, sections, and
20961 debugging information. The sections of the debugging information file
20962 should have the same names, addresses, and sizes as the original file,
20963 but they need not contain any data---much like a @code{.bss} section
20964 in an ordinary executable.
20965
20966 The @sc{gnu} binary utilities (Binutils) package includes the
20967 @samp{objcopy} utility that can produce
20968 the separated executable / debugging information file pairs using the
20969 following commands:
20970
20971 @smallexample
20972 @kbd{objcopy --only-keep-debug foo foo.debug}
20973 @kbd{strip -g foo}
20974 @end smallexample
20975
20976 @noindent
20977 These commands remove the debugging
20978 information from the executable file @file{foo} and place it in the file
20979 @file{foo.debug}. You can use the first, second or both methods to link the
20980 two files:
20981
20982 @itemize @bullet
20983 @item
20984 The debug link method needs the following additional command to also leave
20985 behind a debug link in @file{foo}:
20986
20987 @smallexample
20988 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
20989 @end smallexample
20990
20991 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
20992 a version of the @code{strip} command such that the command @kbd{strip foo -f
20993 foo.debug} has the same functionality as the two @code{objcopy} commands and
20994 the @code{ln -s} command above, together.
20995
20996 @item
20997 Build ID gets embedded into the main executable using @code{ld --build-id} or
20998 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
20999 compatibility fixes for debug files separation are present in @sc{gnu} binary
21000 utilities (Binutils) package since version 2.18.
21001 @end itemize
21002
21003 @noindent
21004
21005 @cindex CRC algorithm definition
21006 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21007 IEEE 802.3 using the polynomial:
21008
21009 @c TexInfo requires naked braces for multi-digit exponents for Tex
21010 @c output, but this causes HTML output to barf. HTML has to be set using
21011 @c raw commands. So we end up having to specify this equation in 2
21012 @c different ways!
21013 @ifhtml
21014 @display
21015 @html
21016 <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>
21017 + <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
21018 @end html
21019 @end display
21020 @end ifhtml
21021 @ifnothtml
21022 @display
21023 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21024 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21025 @end display
21026 @end ifnothtml
21027
21028 The function is computed byte at a time, taking the least
21029 significant bit of each byte first. The initial pattern
21030 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21031 the final result is inverted to ensure trailing zeros also affect the
21032 CRC.
21033
21034 @emph{Note:} This is the same CRC polynomial as used in handling the
21035 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21036 However in the case of the Remote Serial Protocol, the CRC is computed
21037 @emph{most} significant bit first, and the result is not inverted, so
21038 trailing zeros have no effect on the CRC value.
21039
21040 To complete the description, we show below the code of the function
21041 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21042 initially supplied @code{crc} argument means that an initial call to
21043 this function passing in zero will start computing the CRC using
21044 @code{0xffffffff}.
21045
21046 @kindex gnu_debuglink_crc32
21047 @smallexample
21048 unsigned long
21049 gnu_debuglink_crc32 (unsigned long crc,
21050 unsigned char *buf, size_t len)
21051 @{
21052 static const unsigned long crc32_table[256] =
21053 @{
21054 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21055 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21056 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21057 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21058 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21059 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21060 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21061 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21062 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21063 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21064 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21065 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21066 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21067 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21068 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21069 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21070 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21071 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21072 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21073 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21074 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21075 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21076 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21077 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21078 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21079 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21080 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21081 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21082 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21083 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21084 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21085 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21086 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21087 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21088 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21089 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21090 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21091 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21092 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21093 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21094 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21095 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21096 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21097 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21098 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21099 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21100 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21101 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21102 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21103 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21104 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21105 0x2d02ef8d
21106 @};
21107 unsigned char *end;
21108
21109 crc = ~crc & 0xffffffff;
21110 for (end = buf + len; buf < end; ++buf)
21111 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21112 return ~crc & 0xffffffff;
21113 @}
21114 @end smallexample
21115
21116 @noindent
21117 This computation does not apply to the ``build ID'' method.
21118
21119 @node MiniDebugInfo
21120 @section Debugging information in a special section
21121 @cindex separate debug sections
21122 @cindex @samp{.gnu_debugdata} section
21123
21124 Some systems ship pre-built executables and libraries that have a
21125 special @samp{.gnu_debugdata} section. This feature is called
21126 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21127 is used to supply extra symbols for backtraces.
21128
21129 The intent of this section is to provide extra minimal debugging
21130 information for use in simple backtraces. It is not intended to be a
21131 replacement for full separate debugging information (@pxref{Separate
21132 Debug Files}). The example below shows the intended use; however,
21133 @value{GDBN} does not currently put restrictions on what sort of
21134 debugging information might be included in the section.
21135
21136 @value{GDBN} has support for this extension. If the section exists,
21137 then it is used provided that no other source of debugging information
21138 can be found, and that @value{GDBN} was configured with LZMA support.
21139
21140 This section can be easily created using @command{objcopy} and other
21141 standard utilities:
21142
21143 @smallexample
21144 # Extract the dynamic symbols from the main binary, there is no need
21145 # to also have these in the normal symbol table.
21146 nm -D @var{binary} --format=posix --defined-only \
21147 | awk '@{ print $1 @}' | sort > dynsyms
21148
21149 # Extract all the text (i.e. function) symbols from the debuginfo.
21150 # (Note that we actually also accept "D" symbols, for the benefit
21151 # of platforms like PowerPC64 that use function descriptors.)
21152 nm @var{binary} --format=posix --defined-only \
21153 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21154 | sort > funcsyms
21155
21156 # Keep all the function symbols not already in the dynamic symbol
21157 # table.
21158 comm -13 dynsyms funcsyms > keep_symbols
21159
21160 # Separate full debug info into debug binary.
21161 objcopy --only-keep-debug @var{binary} debug
21162
21163 # Copy the full debuginfo, keeping only a minimal set of symbols and
21164 # removing some unnecessary sections.
21165 objcopy -S --remove-section .gdb_index --remove-section .comment \
21166 --keep-symbols=keep_symbols debug mini_debuginfo
21167
21168 # Drop the full debug info from the original binary.
21169 strip --strip-all -R .comment @var{binary}
21170
21171 # Inject the compressed data into the .gnu_debugdata section of the
21172 # original binary.
21173 xz mini_debuginfo
21174 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21175 @end smallexample
21176
21177 @node Index Files
21178 @section Index Files Speed Up @value{GDBN}
21179 @cindex index files
21180 @cindex @samp{.gdb_index} section
21181
21182 When @value{GDBN} finds a symbol file, it scans the symbols in the
21183 file in order to construct an internal symbol table. This lets most
21184 @value{GDBN} operations work quickly---at the cost of a delay early
21185 on. For large programs, this delay can be quite lengthy, so
21186 @value{GDBN} provides a way to build an index, which speeds up
21187 startup.
21188
21189 For convenience, @value{GDBN} comes with a program,
21190 @command{gdb-add-index}, which can be used to add the index to a
21191 symbol file. It takes the symbol file as its only argument:
21192
21193 @smallexample
21194 $ gdb-add-index symfile
21195 @end smallexample
21196
21197 @xref{gdb-add-index}.
21198
21199 It is also possible to do the work manually. Here is what
21200 @command{gdb-add-index} does behind the curtains.
21201
21202 The index is stored as a section in the symbol file. @value{GDBN} can
21203 write the index to a file, then you can put it into the symbol file
21204 using @command{objcopy}.
21205
21206 To create an index file, use the @code{save gdb-index} command:
21207
21208 @table @code
21209 @item save gdb-index [-dwarf-5] @var{directory}
21210 @kindex save gdb-index
21211 Create index files for all symbol files currently known by
21212 @value{GDBN}. For each known @var{symbol-file}, this command by
21213 default creates it produces a single file
21214 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21215 the @option{-dwarf-5} option, it produces 2 files:
21216 @file{@var{symbol-file}.debug_names} and
21217 @file{@var{symbol-file}.debug_str}. The files are created in the
21218 given @var{directory}.
21219 @end table
21220
21221 Once you have created an index file you can merge it into your symbol
21222 file, here named @file{symfile}, using @command{objcopy}:
21223
21224 @smallexample
21225 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21226 --set-section-flags .gdb_index=readonly symfile symfile
21227 @end smallexample
21228
21229 Or for @code{-dwarf-5}:
21230
21231 @smallexample
21232 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21233 $ cat symfile.debug_str >>symfile.debug_str.new
21234 $ objcopy --add-section .debug_names=symfile.gdb-index \
21235 --set-section-flags .debug_names=readonly \
21236 --update-section .debug_str=symfile.debug_str.new symfile symfile
21237 @end smallexample
21238
21239 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21240 sections that have been deprecated. Usually they are deprecated because
21241 they are missing a new feature or have performance issues.
21242 To tell @value{GDBN} to use a deprecated index section anyway
21243 specify @code{set use-deprecated-index-sections on}.
21244 The default is @code{off}.
21245 This can speed up startup, but may result in some functionality being lost.
21246 @xref{Index Section Format}.
21247
21248 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21249 must be done before gdb reads the file. The following will not work:
21250
21251 @smallexample
21252 $ gdb -ex "set use-deprecated-index-sections on" <program>
21253 @end smallexample
21254
21255 Instead you must do, for example,
21256
21257 @smallexample
21258 $ gdb -iex "set use-deprecated-index-sections on" <program>
21259 @end smallexample
21260
21261 There are currently some limitation on indices. They only work when
21262 using DWARF debugging information, not stabs. And, only the
21263 @code{-dwarf-5} index works for programs using Ada.
21264
21265 @subsection Automatic symbol index cache
21266
21267 @cindex automatic symbol index cache
21268 It is possible for @value{GDBN} to automatically save a copy of this index in a
21269 cache on disk and retrieve it from there when loading the same binary in the
21270 future. This feature can be turned on with @kbd{set index-cache on}. The
21271 following commands can be used to tweak the behavior of the index cache.
21272
21273 @table @code
21274
21275 @kindex set index-cache
21276 @item set index-cache on
21277 @itemx set index-cache off
21278 Enable or disable the use of the symbol index cache.
21279
21280 @item set index-cache directory @var{directory}
21281 @kindex show index-cache
21282 @itemx show index-cache directory
21283 Set/show the directory where index files will be saved.
21284
21285 The default value for this directory depends on the host platform. On
21286 most systems, the index is cached in the @file{gdb} subdirectory of
21287 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21288 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21289 of your home directory. However, on some systems, the default may
21290 differ according to local convention.
21291
21292 There is no limit on the disk space used by index cache. It is perfectly safe
21293 to delete the content of that directory to free up disk space.
21294
21295 @item show index-cache stats
21296 Print the number of cache hits and misses since the launch of @value{GDBN}.
21297
21298 @end table
21299
21300 @node Symbol Errors
21301 @section Errors Reading Symbol Files
21302
21303 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21304 such as symbol types it does not recognize, or known bugs in compiler
21305 output. By default, @value{GDBN} does not notify you of such problems, since
21306 they are relatively common and primarily of interest to people
21307 debugging compilers. If you are interested in seeing information
21308 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21309 only one message about each such type of problem, no matter how many
21310 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21311 to see how many times the problems occur, with the @code{set
21312 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21313 Messages}).
21314
21315 The messages currently printed, and their meanings, include:
21316
21317 @table @code
21318 @item inner block not inside outer block in @var{symbol}
21319
21320 The symbol information shows where symbol scopes begin and end
21321 (such as at the start of a function or a block of statements). This
21322 error indicates that an inner scope block is not fully contained
21323 in its outer scope blocks.
21324
21325 @value{GDBN} circumvents the problem by treating the inner block as if it had
21326 the same scope as the outer block. In the error message, @var{symbol}
21327 may be shown as ``@code{(don't know)}'' if the outer block is not a
21328 function.
21329
21330 @item block at @var{address} out of order
21331
21332 The symbol information for symbol scope blocks should occur in
21333 order of increasing addresses. This error indicates that it does not
21334 do so.
21335
21336 @value{GDBN} does not circumvent this problem, and has trouble
21337 locating symbols in the source file whose symbols it is reading. (You
21338 can often determine what source file is affected by specifying
21339 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21340 Messages}.)
21341
21342 @item bad block start address patched
21343
21344 The symbol information for a symbol scope block has a start address
21345 smaller than the address of the preceding source line. This is known
21346 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21347
21348 @value{GDBN} circumvents the problem by treating the symbol scope block as
21349 starting on the previous source line.
21350
21351 @item bad string table offset in symbol @var{n}
21352
21353 @cindex foo
21354 Symbol number @var{n} contains a pointer into the string table which is
21355 larger than the size of the string table.
21356
21357 @value{GDBN} circumvents the problem by considering the symbol to have the
21358 name @code{foo}, which may cause other problems if many symbols end up
21359 with this name.
21360
21361 @item unknown symbol type @code{0x@var{nn}}
21362
21363 The symbol information contains new data types that @value{GDBN} does
21364 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21365 uncomprehended information, in hexadecimal.
21366
21367 @value{GDBN} circumvents the error by ignoring this symbol information.
21368 This usually allows you to debug your program, though certain symbols
21369 are not accessible. If you encounter such a problem and feel like
21370 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21371 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21372 and examine @code{*bufp} to see the symbol.
21373
21374 @item stub type has NULL name
21375
21376 @value{GDBN} could not find the full definition for a struct or class.
21377
21378 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21379 The symbol information for a C@t{++} member function is missing some
21380 information that recent versions of the compiler should have output for
21381 it.
21382
21383 @item info mismatch between compiler and debugger
21384
21385 @value{GDBN} could not parse a type specification output by the compiler.
21386
21387 @end table
21388
21389 @node Data Files
21390 @section GDB Data Files
21391
21392 @cindex prefix for data files
21393 @value{GDBN} will sometimes read an auxiliary data file. These files
21394 are kept in a directory known as the @dfn{data directory}.
21395
21396 You can set the data directory's name, and view the name @value{GDBN}
21397 is currently using.
21398
21399 @table @code
21400 @kindex set data-directory
21401 @item set data-directory @var{directory}
21402 Set the directory which @value{GDBN} searches for auxiliary data files
21403 to @var{directory}.
21404
21405 @kindex show data-directory
21406 @item show data-directory
21407 Show the directory @value{GDBN} searches for auxiliary data files.
21408 @end table
21409
21410 @cindex default data directory
21411 @cindex @samp{--with-gdb-datadir}
21412 You can set the default data directory by using the configure-time
21413 @samp{--with-gdb-datadir} option. If the data directory is inside
21414 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21415 @samp{--exec-prefix}), then the default data directory will be updated
21416 automatically if the installed @value{GDBN} is moved to a new
21417 location.
21418
21419 The data directory may also be specified with the
21420 @code{--data-directory} command line option.
21421 @xref{Mode Options}.
21422
21423 @node Targets
21424 @chapter Specifying a Debugging Target
21425
21426 @cindex debugging target
21427 A @dfn{target} is the execution environment occupied by your program.
21428
21429 Often, @value{GDBN} runs in the same host environment as your program;
21430 in that case, the debugging target is specified as a side effect when
21431 you use the @code{file} or @code{core} commands. When you need more
21432 flexibility---for example, running @value{GDBN} on a physically separate
21433 host, or controlling a standalone system over a serial port or a
21434 realtime system over a TCP/IP connection---you can use the @code{target}
21435 command to specify one of the target types configured for @value{GDBN}
21436 (@pxref{Target Commands, ,Commands for Managing Targets}).
21437
21438 @cindex target architecture
21439 It is possible to build @value{GDBN} for several different @dfn{target
21440 architectures}. When @value{GDBN} is built like that, you can choose
21441 one of the available architectures with the @kbd{set architecture}
21442 command.
21443
21444 @table @code
21445 @kindex set architecture
21446 @kindex show architecture
21447 @item set architecture @var{arch}
21448 This command sets the current target architecture to @var{arch}. The
21449 value of @var{arch} can be @code{"auto"}, in addition to one of the
21450 supported architectures.
21451
21452 @item show architecture
21453 Show the current target architecture.
21454
21455 @item set processor
21456 @itemx processor
21457 @kindex set processor
21458 @kindex show processor
21459 These are alias commands for, respectively, @code{set architecture}
21460 and @code{show architecture}.
21461 @end table
21462
21463 @menu
21464 * Active Targets:: Active targets
21465 * Target Commands:: Commands for managing targets
21466 * Byte Order:: Choosing target byte order
21467 @end menu
21468
21469 @node Active Targets
21470 @section Active Targets
21471
21472 @cindex stacking targets
21473 @cindex active targets
21474 @cindex multiple targets
21475
21476 There are multiple classes of targets such as: processes, executable files or
21477 recording sessions. Core files belong to the process class, making core file
21478 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21479 on multiple active targets, one in each class. This allows you to (for
21480 example) start a process and inspect its activity, while still having access to
21481 the executable file after the process finishes. Or if you start process
21482 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21483 presented a virtual layer of the recording target, while the process target
21484 remains stopped at the chronologically last point of the process execution.
21485
21486 Use the @code{core-file} and @code{exec-file} commands to select a new core
21487 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21488 specify as a target a process that is already running, use the @code{attach}
21489 command (@pxref{Attach, ,Debugging an Already-running Process}).
21490
21491 @node Target Commands
21492 @section Commands for Managing Targets
21493
21494 @table @code
21495 @item target @var{type} @var{parameters}
21496 Connects the @value{GDBN} host environment to a target machine or
21497 process. A target is typically a protocol for talking to debugging
21498 facilities. You use the argument @var{type} to specify the type or
21499 protocol of the target machine.
21500
21501 Further @var{parameters} are interpreted by the target protocol, but
21502 typically include things like device names or host names to connect
21503 with, process numbers, and baud rates.
21504
21505 The @code{target} command does not repeat if you press @key{RET} again
21506 after executing the command.
21507
21508 @kindex help target
21509 @item help target
21510 Displays the names of all targets available. To display targets
21511 currently selected, use either @code{info target} or @code{info files}
21512 (@pxref{Files, ,Commands to Specify Files}).
21513
21514 @item help target @var{name}
21515 Describe a particular target, including any parameters necessary to
21516 select it.
21517
21518 @kindex set gnutarget
21519 @item set gnutarget @var{args}
21520 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21521 knows whether it is reading an @dfn{executable},
21522 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21523 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21524 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21525
21526 @quotation
21527 @emph{Warning:} To specify a file format with @code{set gnutarget},
21528 you must know the actual BFD name.
21529 @end quotation
21530
21531 @noindent
21532 @xref{Files, , Commands to Specify Files}.
21533
21534 @kindex show gnutarget
21535 @item show gnutarget
21536 Use the @code{show gnutarget} command to display what file format
21537 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21538 @value{GDBN} will determine the file format for each file automatically,
21539 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21540 @end table
21541
21542 @cindex common targets
21543 Here are some common targets (available, or not, depending on the GDB
21544 configuration):
21545
21546 @table @code
21547 @kindex target
21548 @item target exec @var{program}
21549 @cindex executable file target
21550 An executable file. @samp{target exec @var{program}} is the same as
21551 @samp{exec-file @var{program}}.
21552
21553 @item target core @var{filename}
21554 @cindex core dump file target
21555 A core dump file. @samp{target core @var{filename}} is the same as
21556 @samp{core-file @var{filename}}.
21557
21558 @item target remote @var{medium}
21559 @cindex remote target
21560 A remote system connected to @value{GDBN} via a serial line or network
21561 connection. This command tells @value{GDBN} to use its own remote
21562 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21563
21564 For example, if you have a board connected to @file{/dev/ttya} on the
21565 machine running @value{GDBN}, you could say:
21566
21567 @smallexample
21568 target remote /dev/ttya
21569 @end smallexample
21570
21571 @code{target remote} supports the @code{load} command. This is only
21572 useful if you have some other way of getting the stub to the target
21573 system, and you can put it somewhere in memory where it won't get
21574 clobbered by the download.
21575
21576 @item target sim @r{[}@var{simargs}@r{]} @dots{}
21577 @cindex built-in simulator target
21578 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
21579 In general,
21580 @smallexample
21581 target sim
21582 load
21583 run
21584 @end smallexample
21585 @noindent
21586 works; however, you cannot assume that a specific memory map, device
21587 drivers, or even basic I/O is available, although some simulators do
21588 provide these. For info about any processor-specific simulator details,
21589 see the appropriate section in @ref{Embedded Processors, ,Embedded
21590 Processors}.
21591
21592 @item target native
21593 @cindex native target
21594 Setup for local/native process debugging. Useful to make the
21595 @code{run} command spawn native processes (likewise @code{attach},
21596 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21597 (@pxref{set auto-connect-native-target}).
21598
21599 @end table
21600
21601 Different targets are available on different configurations of @value{GDBN};
21602 your configuration may have more or fewer targets.
21603
21604 Many remote targets require you to download the executable's code once
21605 you've successfully established a connection. You may wish to control
21606 various aspects of this process.
21607
21608 @table @code
21609
21610 @item set hash
21611 @kindex set hash@r{, for remote monitors}
21612 @cindex hash mark while downloading
21613 This command controls whether a hash mark @samp{#} is displayed while
21614 downloading a file to the remote monitor. If on, a hash mark is
21615 displayed after each S-record is successfully downloaded to the
21616 monitor.
21617
21618 @item show hash
21619 @kindex show hash@r{, for remote monitors}
21620 Show the current status of displaying the hash mark.
21621
21622 @item set debug monitor
21623 @kindex set debug monitor
21624 @cindex display remote monitor communications
21625 Enable or disable display of communications messages between
21626 @value{GDBN} and the remote monitor.
21627
21628 @item show debug monitor
21629 @kindex show debug monitor
21630 Show the current status of displaying communications between
21631 @value{GDBN} and the remote monitor.
21632 @end table
21633
21634 @table @code
21635
21636 @kindex load @var{filename} @var{offset}
21637 @item load @var{filename} @var{offset}
21638 @anchor{load}
21639 Depending on what remote debugging facilities are configured into
21640 @value{GDBN}, the @code{load} command may be available. Where it exists, it
21641 is meant to make @var{filename} (an executable) available for debugging
21642 on the remote system---by downloading, or dynamic linking, for example.
21643 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21644 the @code{add-symbol-file} command.
21645
21646 If your @value{GDBN} does not have a @code{load} command, attempting to
21647 execute it gets the error message ``@code{You can't do that when your
21648 target is @dots{}}''
21649
21650 The file is loaded at whatever address is specified in the executable.
21651 For some object file formats, you can specify the load address when you
21652 link the program; for other formats, like a.out, the object file format
21653 specifies a fixed address.
21654 @c FIXME! This would be a good place for an xref to the GNU linker doc.
21655
21656 It is also possible to tell @value{GDBN} to load the executable file at a
21657 specific offset described by the optional argument @var{offset}. When
21658 @var{offset} is provided, @var{filename} must also be provided.
21659
21660 Depending on the remote side capabilities, @value{GDBN} may be able to
21661 load programs into flash memory.
21662
21663 @code{load} does not repeat if you press @key{RET} again after using it.
21664 @end table
21665
21666 @table @code
21667
21668 @kindex flash-erase
21669 @item flash-erase
21670 @anchor{flash-erase}
21671
21672 Erases all known flash memory regions on the target.
21673
21674 @end table
21675
21676 @node Byte Order
21677 @section Choosing Target Byte Order
21678
21679 @cindex choosing target byte order
21680 @cindex target byte order
21681
21682 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
21683 offer the ability to run either big-endian or little-endian byte
21684 orders. Usually the executable or symbol will include a bit to
21685 designate the endian-ness, and you will not need to worry about
21686 which to use. However, you may still find it useful to adjust
21687 @value{GDBN}'s idea of processor endian-ness manually.
21688
21689 @table @code
21690 @kindex set endian
21691 @item set endian big
21692 Instruct @value{GDBN} to assume the target is big-endian.
21693
21694 @item set endian little
21695 Instruct @value{GDBN} to assume the target is little-endian.
21696
21697 @item set endian auto
21698 Instruct @value{GDBN} to use the byte order associated with the
21699 executable.
21700
21701 @item show endian
21702 Display @value{GDBN}'s current idea of the target byte order.
21703
21704 @end table
21705
21706 If the @code{set endian auto} mode is in effect and no executable has
21707 been selected, then the endianness used is the last one chosen either
21708 by one of the @code{set endian big} and @code{set endian little}
21709 commands or by inferring from the last executable used. If no
21710 endianness has been previously chosen, then the default for this mode
21711 is inferred from the target @value{GDBN} has been built for, and is
21712 @code{little} if the name of the target CPU has an @code{el} suffix
21713 and @code{big} otherwise.
21714
21715 Note that these commands merely adjust interpretation of symbolic
21716 data on the host, and that they have absolutely no effect on the
21717 target system.
21718
21719
21720 @node Remote Debugging
21721 @chapter Debugging Remote Programs
21722 @cindex remote debugging
21723
21724 If you are trying to debug a program running on a machine that cannot run
21725 @value{GDBN} in the usual way, it is often useful to use remote debugging.
21726 For example, you might use remote debugging on an operating system kernel,
21727 or on a small system which does not have a general purpose operating system
21728 powerful enough to run a full-featured debugger.
21729
21730 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21731 to make this work with particular debugging targets. In addition,
21732 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
21733 but not specific to any particular target system) which you can use if you
21734 write the remote stubs---the code that runs on the remote system to
21735 communicate with @value{GDBN}.
21736
21737 Other remote targets may be available in your
21738 configuration of @value{GDBN}; use @code{help target} to list them.
21739
21740 @menu
21741 * Connecting:: Connecting to a remote target
21742 * File Transfer:: Sending files to a remote system
21743 * Server:: Using the gdbserver program
21744 * Remote Configuration:: Remote configuration
21745 * Remote Stub:: Implementing a remote stub
21746 @end menu
21747
21748 @node Connecting
21749 @section Connecting to a Remote Target
21750 @cindex remote debugging, connecting
21751 @cindex @code{gdbserver}, connecting
21752 @cindex remote debugging, types of connections
21753 @cindex @code{gdbserver}, types of connections
21754 @cindex @code{gdbserver}, @code{target remote} mode
21755 @cindex @code{gdbserver}, @code{target extended-remote} mode
21756
21757 This section describes how to connect to a remote target, including the
21758 types of connections and their differences, how to set up executable and
21759 symbol files on the host and target, and the commands used for
21760 connecting to and disconnecting from the remote target.
21761
21762 @subsection Types of Remote Connections
21763
21764 @value{GDBN} supports two types of remote connections, @code{target remote}
21765 mode and @code{target extended-remote} mode. Note that many remote targets
21766 support only @code{target remote} mode. There are several major
21767 differences between the two types of connections, enumerated here:
21768
21769 @table @asis
21770
21771 @cindex remote debugging, detach and program exit
21772 @item Result of detach or program exit
21773 @strong{With target remote mode:} When the debugged program exits or you
21774 detach from it, @value{GDBN} disconnects from the target. When using
21775 @code{gdbserver}, @code{gdbserver} will exit.
21776
21777 @strong{With target extended-remote mode:} When the debugged program exits or
21778 you detach from it, @value{GDBN} remains connected to the target, even
21779 though no program is running. You can rerun the program, attach to a
21780 running program, or use @code{monitor} commands specific to the target.
21781
21782 When using @code{gdbserver} in this case, it does not exit unless it was
21783 invoked using the @option{--once} option. If the @option{--once} option
21784 was not used, you can ask @code{gdbserver} to exit using the
21785 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21786
21787 @item Specifying the program to debug
21788 For both connection types you use the @code{file} command to specify the
21789 program on the host system. If you are using @code{gdbserver} there are
21790 some differences in how to specify the location of the program on the
21791 target.
21792
21793 @strong{With target remote mode:} You must either specify the program to debug
21794 on the @code{gdbserver} command line or use the @option{--attach} option
21795 (@pxref{Attaching to a program,,Attaching to a Running Program}).
21796
21797 @cindex @option{--multi}, @code{gdbserver} option
21798 @strong{With target extended-remote mode:} You may specify the program to debug
21799 on the @code{gdbserver} command line, or you can load the program or attach
21800 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21801
21802 @anchor{--multi Option in Types of Remote Connnections}
21803 You can start @code{gdbserver} without supplying an initial command to run
21804 or process ID to attach. To do this, use the @option{--multi} command line
21805 option. Then you can connect using @code{target extended-remote} and start
21806 the program you want to debug (see below for details on using the
21807 @code{run} command in this scenario). Note that the conditions under which
21808 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
21809 (@code{target remote} or @code{target extended-remote}). The
21810 @option{--multi} option to @code{gdbserver} has no influence on that.
21811
21812 @item The @code{run} command
21813 @strong{With target remote mode:} The @code{run} command is not
21814 supported. Once a connection has been established, you can use all
21815 the usual @value{GDBN} commands to examine and change data. The
21816 remote program is already running, so you can use commands like
21817 @kbd{step} and @kbd{continue}.
21818
21819 @strong{With target extended-remote mode:} The @code{run} command is
21820 supported. The @code{run} command uses the value set by
21821 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
21822 the program to run. Command line arguments are supported, except for
21823 wildcard expansion and I/O redirection (@pxref{Arguments}).
21824
21825 If you specify the program to debug on the command line, then the
21826 @code{run} command is not required to start execution, and you can
21827 resume using commands like @kbd{step} and @kbd{continue} as with
21828 @code{target remote} mode.
21829
21830 @anchor{Attaching in Types of Remote Connections}
21831 @item Attaching
21832 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21833 not supported. To attach to a running program using @code{gdbserver}, you
21834 must use the @option{--attach} option (@pxref{Running gdbserver}).
21835
21836 @strong{With target extended-remote mode:} To attach to a running program,
21837 you may use the @code{attach} command after the connection has been
21838 established. If you are using @code{gdbserver}, you may also invoke
21839 @code{gdbserver} using the @option{--attach} option
21840 (@pxref{Running gdbserver}).
21841
21842 @end table
21843
21844 @anchor{Host and target files}
21845 @subsection Host and Target Files
21846 @cindex remote debugging, symbol files
21847 @cindex symbol files, remote debugging
21848
21849 @value{GDBN}, running on the host, needs access to symbol and debugging
21850 information for your program running on the target. This requires
21851 access to an unstripped copy of your program, and possibly any associated
21852 symbol files. Note that this section applies equally to both @code{target
21853 remote} mode and @code{target extended-remote} mode.
21854
21855 Some remote targets (@pxref{qXfer executable filename read}, and
21856 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21857 the same connection used to communicate with @value{GDBN}. With such a
21858 target, if the remote program is unstripped, the only command you need is
21859 @code{target remote} (or @code{target extended-remote}).
21860
21861 If the remote program is stripped, or the target does not support remote
21862 program file access, start up @value{GDBN} using the name of the local
21863 unstripped copy of your program as the first argument, or use the
21864 @code{file} command. Use @code{set sysroot} to specify the location (on
21865 the host) of target libraries (unless your @value{GDBN} was compiled with
21866 the correct sysroot using @code{--with-sysroot}). Alternatively, you
21867 may use @code{set solib-search-path} to specify how @value{GDBN} locates
21868 target libraries.
21869
21870 The symbol file and target libraries must exactly match the executable
21871 and libraries on the target, with one exception: the files on the host
21872 system should not be stripped, even if the files on the target system
21873 are. Mismatched or missing files will lead to confusing results
21874 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21875 files may also prevent @code{gdbserver} from debugging multi-threaded
21876 programs.
21877
21878 @subsection Remote Connection Commands
21879 @cindex remote connection commands
21880 @value{GDBN} can communicate with the target over a serial line, a
21881 local Unix domain socket, or
21882 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
21883 each case, @value{GDBN} uses the same protocol for debugging your
21884 program; only the medium carrying the debugging packets varies. The
21885 @code{target remote} and @code{target extended-remote} commands
21886 establish a connection to the target. Both commands accept the same
21887 arguments, which indicate the medium to use:
21888
21889 @table @code
21890
21891 @item target remote @var{serial-device}
21892 @itemx target extended-remote @var{serial-device}
21893 @cindex serial line, @code{target remote}
21894 Use @var{serial-device} to communicate with the target. For example,
21895 to use a serial line connected to the device named @file{/dev/ttyb}:
21896
21897 @smallexample
21898 target remote /dev/ttyb
21899 @end smallexample
21900
21901 If you're using a serial line, you may want to give @value{GDBN} the
21902 @samp{--baud} option, or use the @code{set serial baud} command
21903 (@pxref{Remote Configuration, set serial baud}) before the
21904 @code{target} command.
21905
21906 @item target remote @var{local-socket}
21907 @itemx target extended-remote @var{local-socket}
21908 @cindex local socket, @code{target remote}
21909 @cindex Unix domain socket
21910 Use @var{local-socket} to communicate with the target. For example,
21911 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
21912
21913 @smallexample
21914 target remote /tmp/gdb-socket0
21915 @end smallexample
21916
21917 Note that this command has the same form as the command to connect
21918 to a serial line. @value{GDBN} will automatically determine which
21919 kind of file you have specified and will make the appropriate kind
21920 of connection.
21921 This feature is not available if the host system does not support
21922 Unix domain sockets.
21923
21924 @item target remote @code{@var{host}:@var{port}}
21925 @itemx target remote @code{@var{[host]}:@var{port}}
21926 @itemx target remote @code{tcp:@var{host}:@var{port}}
21927 @itemx target remote @code{tcp:@var{[host]}:@var{port}}
21928 @itemx target remote @code{tcp4:@var{host}:@var{port}}
21929 @itemx target remote @code{tcp6:@var{host}:@var{port}}
21930 @itemx target remote @code{tcp6:@var{[host]}:@var{port}}
21931 @itemx target extended-remote @code{@var{host}:@var{port}}
21932 @itemx target extended-remote @code{@var{[host]}:@var{port}}
21933 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
21934 @itemx target extended-remote @code{tcp:@var{[host]}:@var{port}}
21935 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
21936 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
21937 @itemx target extended-remote @code{tcp6:@var{[host]}:@var{port}}
21938 @cindex @acronym{TCP} port, @code{target remote}
21939 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
21940 The @var{host} may be either a host name, a numeric @acronym{IPv4}
21941 address, or a numeric @acronym{IPv6} address (with or without the
21942 square brackets to separate the address from the port); @var{port}
21943 must be a decimal number. The @var{host} could be the target machine
21944 itself, if it is directly connected to the net, or it might be a
21945 terminal server which in turn has a serial line to the target.
21946
21947 For example, to connect to port 2828 on a terminal server named
21948 @code{manyfarms}:
21949
21950 @smallexample
21951 target remote manyfarms:2828
21952 @end smallexample
21953
21954 To connect to port 2828 on a terminal server whose address is
21955 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
21956 square bracket syntax:
21957
21958 @smallexample
21959 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
21960 @end smallexample
21961
21962 @noindent
21963 or explicitly specify the @acronym{IPv6} protocol:
21964
21965 @smallexample
21966 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
21967 @end smallexample
21968
21969 This last example may be confusing to the reader, because there is no
21970 visible separation between the hostname and the port number.
21971 Therefore, we recommend the user to provide @acronym{IPv6} addresses
21972 using square brackets for clarity. However, it is important to
21973 mention that for @value{GDBN} there is no ambiguity: the number after
21974 the last colon is considered to be the port number.
21975
21976 If your remote target is actually running on the same machine as your
21977 debugger session (e.g.@: a simulator for your target running on the
21978 same host), you can omit the hostname. For example, to connect to
21979 port 1234 on your local machine:
21980
21981 @smallexample
21982 target remote :1234
21983 @end smallexample
21984 @noindent
21985
21986 Note that the colon is still required here.
21987
21988 @item target remote @code{udp:@var{host}:@var{port}}
21989 @itemx target remote @code{udp:@var{[host]}:@var{port}}
21990 @itemx target remote @code{udp4:@var{host}:@var{port}}
21991 @itemx target remote @code{udp6:@var{[host]}:@var{port}}
21992 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
21993 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
21994 @itemx target extended-remote @code{udp:@var{[host]}:@var{port}}
21995 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
21996 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
21997 @itemx target extended-remote @code{udp6:@var{[host]}:@var{port}}
21998 @cindex @acronym{UDP} port, @code{target remote}
21999 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22000 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22001
22002 @smallexample
22003 target remote udp:manyfarms:2828
22004 @end smallexample
22005
22006 When using a @acronym{UDP} connection for remote debugging, you should
22007 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22008 can silently drop packets on busy or unreliable networks, which will
22009 cause havoc with your debugging session.
22010
22011 @item target remote | @var{command}
22012 @itemx target extended-remote | @var{command}
22013 @cindex pipe, @code{target remote} to
22014 Run @var{command} in the background and communicate with it using a
22015 pipe. The @var{command} is a shell command, to be parsed and expanded
22016 by the system's command shell, @code{/bin/sh}; it should expect remote
22017 protocol packets on its standard input, and send replies on its
22018 standard output. You could use this to run a stand-alone simulator
22019 that speaks the remote debugging protocol, to make net connections
22020 using programs like @code{ssh}, or for other similar tricks.
22021
22022 If @var{command} closes its standard output (perhaps by exiting),
22023 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22024 program has already exited, this will have no effect.)
22025
22026 @end table
22027
22028 @cindex interrupting remote programs
22029 @cindex remote programs, interrupting
22030 Whenever @value{GDBN} is waiting for the remote program, if you type the
22031 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22032 program. This may or may not succeed, depending in part on the hardware
22033 and the serial drivers the remote system uses. If you type the
22034 interrupt character once again, @value{GDBN} displays this prompt:
22035
22036 @smallexample
22037 Interrupted while waiting for the program.
22038 Give up (and stop debugging it)? (y or n)
22039 @end smallexample
22040
22041 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22042 the remote debugging session. (If you decide you want to try again later,
22043 you can use @kbd{target remote} again to connect once more.) If you type
22044 @kbd{n}, @value{GDBN} goes back to waiting.
22045
22046 In @code{target extended-remote} mode, typing @kbd{n} will leave
22047 @value{GDBN} connected to the target.
22048
22049 @table @code
22050 @kindex detach (remote)
22051 @item detach
22052 When you have finished debugging the remote program, you can use the
22053 @code{detach} command to release it from @value{GDBN} control.
22054 Detaching from the target normally resumes its execution, but the results
22055 will depend on your particular remote stub. After the @code{detach}
22056 command in @code{target remote} mode, @value{GDBN} is free to connect to
22057 another target. In @code{target extended-remote} mode, @value{GDBN} is
22058 still connected to the target.
22059
22060 @kindex disconnect
22061 @item disconnect
22062 The @code{disconnect} command closes the connection to the target, and
22063 the target is generally not resumed. It will wait for @value{GDBN}
22064 (this instance or another one) to connect and continue debugging. After
22065 the @code{disconnect} command, @value{GDBN} is again free to connect to
22066 another target.
22067
22068 @cindex send command to remote monitor
22069 @cindex extend @value{GDBN} for remote targets
22070 @cindex add new commands for external monitor
22071 @kindex monitor
22072 @item monitor @var{cmd}
22073 This command allows you to send arbitrary commands directly to the
22074 remote monitor. Since @value{GDBN} doesn't care about the commands it
22075 sends like this, this command is the way to extend @value{GDBN}---you
22076 can add new commands that only the external monitor will understand
22077 and implement.
22078 @end table
22079
22080 @node File Transfer
22081 @section Sending files to a remote system
22082 @cindex remote target, file transfer
22083 @cindex file transfer
22084 @cindex sending files to remote systems
22085
22086 Some remote targets offer the ability to transfer files over the same
22087 connection used to communicate with @value{GDBN}. This is convenient
22088 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22089 running @code{gdbserver} over a network interface. For other targets,
22090 e.g.@: embedded devices with only a single serial port, this may be
22091 the only way to upload or download files.
22092
22093 Not all remote targets support these commands.
22094
22095 @table @code
22096 @kindex remote put
22097 @item remote put @var{hostfile} @var{targetfile}
22098 Copy file @var{hostfile} from the host system (the machine running
22099 @value{GDBN}) to @var{targetfile} on the target system.
22100
22101 @kindex remote get
22102 @item remote get @var{targetfile} @var{hostfile}
22103 Copy file @var{targetfile} from the target system to @var{hostfile}
22104 on the host system.
22105
22106 @kindex remote delete
22107 @item remote delete @var{targetfile}
22108 Delete @var{targetfile} from the target system.
22109
22110 @end table
22111
22112 @node Server
22113 @section Using the @code{gdbserver} Program
22114
22115 @kindex gdbserver
22116 @cindex remote connection without stubs
22117 @code{gdbserver} is a control program for Unix-like systems, which
22118 allows you to connect your program with a remote @value{GDBN} via
22119 @code{target remote} or @code{target extended-remote}---but without
22120 linking in the usual debugging stub.
22121
22122 @code{gdbserver} is not a complete replacement for the debugging stubs,
22123 because it requires essentially the same operating-system facilities
22124 that @value{GDBN} itself does. In fact, a system that can run
22125 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22126 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22127 because it is a much smaller program than @value{GDBN} itself. It is
22128 also easier to port than all of @value{GDBN}, so you may be able to get
22129 started more quickly on a new system by using @code{gdbserver}.
22130 Finally, if you develop code for real-time systems, you may find that
22131 the tradeoffs involved in real-time operation make it more convenient to
22132 do as much development work as possible on another system, for example
22133 by cross-compiling. You can use @code{gdbserver} to make a similar
22134 choice for debugging.
22135
22136 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22137 or a TCP connection, using the standard @value{GDBN} remote serial
22138 protocol.
22139
22140 @quotation
22141 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22142 Do not run @code{gdbserver} connected to any public network; a
22143 @value{GDBN} connection to @code{gdbserver} provides access to the
22144 target system with the same privileges as the user running
22145 @code{gdbserver}.
22146 @end quotation
22147
22148 @anchor{Running gdbserver}
22149 @subsection Running @code{gdbserver}
22150 @cindex arguments, to @code{gdbserver}
22151 @cindex @code{gdbserver}, command-line arguments
22152
22153 Run @code{gdbserver} on the target system. You need a copy of the
22154 program you want to debug, including any libraries it requires.
22155 @code{gdbserver} does not need your program's symbol table, so you can
22156 strip the program if necessary to save space. @value{GDBN} on the host
22157 system does all the symbol handling.
22158
22159 To use the server, you must tell it how to communicate with @value{GDBN};
22160 the name of your program; and the arguments for your program. The usual
22161 syntax is:
22162
22163 @smallexample
22164 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22165 @end smallexample
22166
22167 @var{comm} is either a device name (to use a serial line), or a TCP
22168 hostname and portnumber, or @code{-} or @code{stdio} to use
22169 stdin/stdout of @code{gdbserver}.
22170 For example, to debug Emacs with the argument
22171 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22172 @file{/dev/com1}:
22173
22174 @smallexample
22175 target> gdbserver /dev/com1 emacs foo.txt
22176 @end smallexample
22177
22178 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22179 with it.
22180
22181 To use a TCP connection instead of a serial line:
22182
22183 @smallexample
22184 target> gdbserver host:2345 emacs foo.txt
22185 @end smallexample
22186
22187 The only difference from the previous example is the first argument,
22188 specifying that you are communicating with the host @value{GDBN} via
22189 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22190 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22191 (Currently, the @samp{host} part is ignored.) You can choose any number
22192 you want for the port number as long as it does not conflict with any
22193 TCP ports already in use on the target system (for example, @code{23} is
22194 reserved for @code{telnet}).@footnote{If you choose a port number that
22195 conflicts with another service, @code{gdbserver} prints an error message
22196 and exits.} You must use the same port number with the host @value{GDBN}
22197 @code{target remote} command.
22198
22199 The @code{stdio} connection is useful when starting @code{gdbserver}
22200 with ssh:
22201
22202 @smallexample
22203 (gdb) target remote | ssh -T hostname gdbserver - hello
22204 @end smallexample
22205
22206 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22207 and we don't want escape-character handling. Ssh does this by default when
22208 a command is provided, the flag is provided to make it explicit.
22209 You could elide it if you want to.
22210
22211 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22212 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22213 display through a pipe connected to gdbserver.
22214 Both @code{stdout} and @code{stderr} use the same pipe.
22215
22216 @anchor{Attaching to a program}
22217 @subsubsection Attaching to a Running Program
22218 @cindex attach to a program, @code{gdbserver}
22219 @cindex @option{--attach}, @code{gdbserver} option
22220
22221 On some targets, @code{gdbserver} can also attach to running programs.
22222 This is accomplished via the @code{--attach} argument. The syntax is:
22223
22224 @smallexample
22225 target> gdbserver --attach @var{comm} @var{pid}
22226 @end smallexample
22227
22228 @var{pid} is the process ID of a currently running process. It isn't
22229 necessary to point @code{gdbserver} at a binary for the running process.
22230
22231 In @code{target extended-remote} mode, you can also attach using the
22232 @value{GDBN} attach command
22233 (@pxref{Attaching in Types of Remote Connections}).
22234
22235 @pindex pidof
22236 You can debug processes by name instead of process ID if your target has the
22237 @code{pidof} utility:
22238
22239 @smallexample
22240 target> gdbserver --attach @var{comm} `pidof @var{program}`
22241 @end smallexample
22242
22243 In case more than one copy of @var{program} is running, or @var{program}
22244 has multiple threads, most versions of @code{pidof} support the
22245 @code{-s} option to only return the first process ID.
22246
22247 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22248
22249 This section applies only when @code{gdbserver} is run to listen on a TCP
22250 port.
22251
22252 @code{gdbserver} normally terminates after all of its debugged processes have
22253 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22254 extended-remote}, @code{gdbserver} stays running even with no processes left.
22255 @value{GDBN} normally terminates the spawned debugged process on its exit,
22256 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22257 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22258 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22259 stays running even in the @kbd{target remote} mode.
22260
22261 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22262 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22263 completeness, at most one @value{GDBN} can be connected at a time.
22264
22265 @cindex @option{--once}, @code{gdbserver} option
22266 By default, @code{gdbserver} keeps the listening TCP port open, so that
22267 subsequent connections are possible. However, if you start @code{gdbserver}
22268 with the @option{--once} option, it will stop listening for any further
22269 connection attempts after connecting to the first @value{GDBN} session. This
22270 means no further connections to @code{gdbserver} will be possible after the
22271 first one. It also means @code{gdbserver} will terminate after the first
22272 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22273 connections and even in the @kbd{target extended-remote} mode. The
22274 @option{--once} option allows reusing the same port number for connecting to
22275 multiple instances of @code{gdbserver} running on the same host, since each
22276 instance closes its port after the first connection.
22277
22278 @anchor{Other Command-Line Arguments for gdbserver}
22279 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22280
22281 You can use the @option{--multi} option to start @code{gdbserver} without
22282 specifying a program to debug or a process to attach to. Then you can
22283 attach in @code{target extended-remote} mode and run or attach to a
22284 program. For more information,
22285 @pxref{--multi Option in Types of Remote Connnections}.
22286
22287 @cindex @option{--debug}, @code{gdbserver} option
22288 The @option{--debug} option tells @code{gdbserver} to display extra
22289 status information about the debugging process.
22290 @cindex @option{--remote-debug}, @code{gdbserver} option
22291 The @option{--remote-debug} option tells @code{gdbserver} to display
22292 remote protocol debug output.
22293 @cindex @option{--debug-file}, @code{gdbserver} option
22294 @cindex @code{gdbserver}, send all debug output to a single file
22295 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22296 write any debug output to the given @var{filename}. These options are intended
22297 for @code{gdbserver} development and for bug reports to the developers.
22298
22299 @cindex @option{--debug-format}, @code{gdbserver} option
22300 The @option{--debug-format=option1[,option2,...]} option tells
22301 @code{gdbserver} to include additional information in each output.
22302 Possible options are:
22303
22304 @table @code
22305 @item none
22306 Turn off all extra information in debugging output.
22307 @item all
22308 Turn on all extra information in debugging output.
22309 @item timestamps
22310 Include a timestamp in each line of debugging output.
22311 @end table
22312
22313 Options are processed in order. Thus, for example, if @option{none}
22314 appears last then no additional information is added to debugging output.
22315
22316 @cindex @option{--wrapper}, @code{gdbserver} option
22317 The @option{--wrapper} option specifies a wrapper to launch programs
22318 for debugging. The option should be followed by the name of the
22319 wrapper, then any command-line arguments to pass to the wrapper, then
22320 @kbd{--} indicating the end of the wrapper arguments.
22321
22322 @code{gdbserver} runs the specified wrapper program with a combined
22323 command line including the wrapper arguments, then the name of the
22324 program to debug, then any arguments to the program. The wrapper
22325 runs until it executes your program, and then @value{GDBN} gains control.
22326
22327 You can use any program that eventually calls @code{execve} with
22328 its arguments as a wrapper. Several standard Unix utilities do
22329 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22330 with @code{exec "$@@"} will also work.
22331
22332 For example, you can use @code{env} to pass an environment variable to
22333 the debugged program, without setting the variable in @code{gdbserver}'s
22334 environment:
22335
22336 @smallexample
22337 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22338 @end smallexample
22339
22340 @cindex @option{--selftest}
22341 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22342
22343 @smallexample
22344 $ gdbserver --selftest
22345 Ran 2 unit tests, 0 failed
22346 @end smallexample
22347
22348 These tests are disabled in release.
22349 @subsection Connecting to @code{gdbserver}
22350
22351 The basic procedure for connecting to the remote target is:
22352 @itemize
22353
22354 @item
22355 Run @value{GDBN} on the host system.
22356
22357 @item
22358 Make sure you have the necessary symbol files
22359 (@pxref{Host and target files}).
22360 Load symbols for your application using the @code{file} command before you
22361 connect. Use @code{set sysroot} to locate target libraries (unless your
22362 @value{GDBN} was compiled with the correct sysroot using
22363 @code{--with-sysroot}).
22364
22365 @item
22366 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22367 For TCP connections, you must start up @code{gdbserver} prior to using
22368 the @code{target} command. Otherwise you may get an error whose
22369 text depends on the host system, but which usually looks something like
22370 @samp{Connection refused}. Don't use the @code{load}
22371 command in @value{GDBN} when using @code{target remote} mode, since the
22372 program is already on the target.
22373
22374 @end itemize
22375
22376 @anchor{Monitor Commands for gdbserver}
22377 @subsection Monitor Commands for @code{gdbserver}
22378 @cindex monitor commands, for @code{gdbserver}
22379
22380 During a @value{GDBN} session using @code{gdbserver}, you can use the
22381 @code{monitor} command to send special requests to @code{gdbserver}.
22382 Here are the available commands.
22383
22384 @table @code
22385 @item monitor help
22386 List the available monitor commands.
22387
22388 @item monitor set debug 0
22389 @itemx monitor set debug 1
22390 Disable or enable general debugging messages.
22391
22392 @item monitor set remote-debug 0
22393 @itemx monitor set remote-debug 1
22394 Disable or enable specific debugging messages associated with the remote
22395 protocol (@pxref{Remote Protocol}).
22396
22397 @item monitor set debug-file filename
22398 @itemx monitor set debug-file
22399 Send any debug output to the given file, or to stderr.
22400
22401 @item monitor set debug-format option1@r{[},option2,...@r{]}
22402 Specify additional text to add to debugging messages.
22403 Possible options are:
22404
22405 @table @code
22406 @item none
22407 Turn off all extra information in debugging output.
22408 @item all
22409 Turn on all extra information in debugging output.
22410 @item timestamps
22411 Include a timestamp in each line of debugging output.
22412 @end table
22413
22414 Options are processed in order. Thus, for example, if @option{none}
22415 appears last then no additional information is added to debugging output.
22416
22417 @item monitor set libthread-db-search-path [PATH]
22418 @cindex gdbserver, search path for @code{libthread_db}
22419 When this command is issued, @var{path} is a colon-separated list of
22420 directories to search for @code{libthread_db} (@pxref{Threads,,set
22421 libthread-db-search-path}). If you omit @var{path},
22422 @samp{libthread-db-search-path} will be reset to its default value.
22423
22424 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22425 not supported in @code{gdbserver}.
22426
22427 @item monitor exit
22428 Tell gdbserver to exit immediately. This command should be followed by
22429 @code{disconnect} to close the debugging session. @code{gdbserver} will
22430 detach from any attached processes and kill any processes it created.
22431 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22432 of a multi-process mode debug session.
22433
22434 @end table
22435
22436 @subsection Tracepoints support in @code{gdbserver}
22437 @cindex tracepoints support in @code{gdbserver}
22438
22439 On some targets, @code{gdbserver} supports tracepoints, fast
22440 tracepoints and static tracepoints.
22441
22442 For fast or static tracepoints to work, a special library called the
22443 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22444 This library is built and distributed as an integral part of
22445 @code{gdbserver}. In addition, support for static tracepoints
22446 requires building the in-process agent library with static tracepoints
22447 support. At present, the UST (LTTng Userspace Tracer,
22448 @url{http://lttng.org/ust}) tracing engine is supported. This support
22449 is automatically available if UST development headers are found in the
22450 standard include path when @code{gdbserver} is built, or if
22451 @code{gdbserver} was explicitly configured using @option{--with-ust}
22452 to point at such headers. You can explicitly disable the support
22453 using @option{--with-ust=no}.
22454
22455 There are several ways to load the in-process agent in your program:
22456
22457 @table @code
22458 @item Specifying it as dependency at link time
22459
22460 You can link your program dynamically with the in-process agent
22461 library. On most systems, this is accomplished by adding
22462 @code{-linproctrace} to the link command.
22463
22464 @item Using the system's preloading mechanisms
22465
22466 You can force loading the in-process agent at startup time by using
22467 your system's support for preloading shared libraries. Many Unixes
22468 support the concept of preloading user defined libraries. In most
22469 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22470 in the environment. See also the description of @code{gdbserver}'s
22471 @option{--wrapper} command line option.
22472
22473 @item Using @value{GDBN} to force loading the agent at run time
22474
22475 On some systems, you can force the inferior to load a shared library,
22476 by calling a dynamic loader function in the inferior that takes care
22477 of dynamically looking up and loading a shared library. On most Unix
22478 systems, the function is @code{dlopen}. You'll use the @code{call}
22479 command for that. For example:
22480
22481 @smallexample
22482 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22483 @end smallexample
22484
22485 Note that on most Unix systems, for the @code{dlopen} function to be
22486 available, the program needs to be linked with @code{-ldl}.
22487 @end table
22488
22489 On systems that have a userspace dynamic loader, like most Unix
22490 systems, when you connect to @code{gdbserver} using @code{target
22491 remote}, you'll find that the program is stopped at the dynamic
22492 loader's entry point, and no shared library has been loaded in the
22493 program's address space yet, including the in-process agent. In that
22494 case, before being able to use any of the fast or static tracepoints
22495 features, you need to let the loader run and load the shared
22496 libraries. The simplest way to do that is to run the program to the
22497 main procedure. E.g., if debugging a C or C@t{++} program, start
22498 @code{gdbserver} like so:
22499
22500 @smallexample
22501 $ gdbserver :9999 myprogram
22502 @end smallexample
22503
22504 Start GDB and connect to @code{gdbserver} like so, and run to main:
22505
22506 @smallexample
22507 $ gdb myprogram
22508 (@value{GDBP}) target remote myhost:9999
22509 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22510 (@value{GDBP}) b main
22511 (@value{GDBP}) continue
22512 @end smallexample
22513
22514 The in-process tracing agent library should now be loaded into the
22515 process; you can confirm it with the @code{info sharedlibrary}
22516 command, which will list @file{libinproctrace.so} as loaded in the
22517 process. You are now ready to install fast tracepoints, list static
22518 tracepoint markers, probe static tracepoints markers, and start
22519 tracing.
22520
22521 @node Remote Configuration
22522 @section Remote Configuration
22523
22524 @kindex set remote
22525 @kindex show remote
22526 This section documents the configuration options available when
22527 debugging remote programs. For the options related to the File I/O
22528 extensions of the remote protocol, see @ref{system,
22529 system-call-allowed}.
22530
22531 @table @code
22532 @item set remoteaddresssize @var{bits}
22533 @cindex address size for remote targets
22534 @cindex bits in remote address
22535 Set the maximum size of address in a memory packet to the specified
22536 number of bits. @value{GDBN} will mask off the address bits above
22537 that number, when it passes addresses to the remote target. The
22538 default value is the number of bits in the target's address.
22539
22540 @item show remoteaddresssize
22541 Show the current value of remote address size in bits.
22542
22543 @item set serial baud @var{n}
22544 @cindex baud rate for remote targets
22545 Set the baud rate for the remote serial I/O to @var{n} baud. The
22546 value is used to set the speed of the serial port used for debugging
22547 remote targets.
22548
22549 @item show serial baud
22550 Show the current speed of the remote connection.
22551
22552 @item set serial parity @var{parity}
22553 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22554 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22555
22556 @item show serial parity
22557 Show the current parity of the serial port.
22558
22559 @item set remotebreak
22560 @cindex interrupt remote programs
22561 @cindex BREAK signal instead of Ctrl-C
22562 @anchor{set remotebreak}
22563 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
22564 when you type @kbd{Ctrl-c} to interrupt the program running
22565 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
22566 character instead. The default is off, since most remote systems
22567 expect to see @samp{Ctrl-C} as the interrupt signal.
22568
22569 @item show remotebreak
22570 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22571 interrupt the remote program.
22572
22573 @item set remoteflow on
22574 @itemx set remoteflow off
22575 @kindex set remoteflow
22576 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22577 on the serial port used to communicate to the remote target.
22578
22579 @item show remoteflow
22580 @kindex show remoteflow
22581 Show the current setting of hardware flow control.
22582
22583 @item set remotelogbase @var{base}
22584 Set the base (a.k.a.@: radix) of logging serial protocol
22585 communications to @var{base}. Supported values of @var{base} are:
22586 @code{ascii}, @code{octal}, and @code{hex}. The default is
22587 @code{ascii}.
22588
22589 @item show remotelogbase
22590 Show the current setting of the radix for logging remote serial
22591 protocol.
22592
22593 @item set remotelogfile @var{file}
22594 @cindex record serial communications on file
22595 Record remote serial communications on the named @var{file}. The
22596 default is not to record at all.
22597
22598 @item show remotelogfile
22599 Show the current setting of the file name on which to record the
22600 serial communications.
22601
22602 @item set remotetimeout @var{num}
22603 @cindex timeout for serial communications
22604 @cindex remote timeout
22605 Set the timeout limit to wait for the remote target to respond to
22606 @var{num} seconds. The default is 2 seconds.
22607
22608 @item show remotetimeout
22609 Show the current number of seconds to wait for the remote target
22610 responses.
22611
22612 @cindex limit hardware breakpoints and watchpoints
22613 @cindex remote target, limit break- and watchpoints
22614 @anchor{set remote hardware-watchpoint-limit}
22615 @anchor{set remote hardware-breakpoint-limit}
22616 @item set remote hardware-watchpoint-limit @var{limit}
22617 @itemx set remote hardware-breakpoint-limit @var{limit}
22618 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22619 or breakpoints. The @var{limit} can be set to 0 to disable hardware
22620 watchpoints or breakpoints, and @code{unlimited} for unlimited
22621 watchpoints or breakpoints.
22622
22623 @item show remote hardware-watchpoint-limit
22624 @itemx show remote hardware-breakpoint-limit
22625 Show the current limit for the number of hardware watchpoints or
22626 breakpoints that @value{GDBN} can use.
22627
22628 @cindex limit hardware watchpoints length
22629 @cindex remote target, limit watchpoints length
22630 @anchor{set remote hardware-watchpoint-length-limit}
22631 @item set remote hardware-watchpoint-length-limit @var{limit}
22632 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22633 length of a remote hardware watchpoint. A @var{limit} of 0 disables
22634 hardware watchpoints and @code{unlimited} allows watchpoints of any
22635 length.
22636
22637 @item show remote hardware-watchpoint-length-limit
22638 Show the current limit (in bytes) of the maximum length of
22639 a remote hardware watchpoint.
22640
22641 @item set remote exec-file @var{filename}
22642 @itemx show remote exec-file
22643 @anchor{set remote exec-file}
22644 @cindex executable file, for remote target
22645 Select the file used for @code{run} with @code{target
22646 extended-remote}. This should be set to a filename valid on the
22647 target system. If it is not set, the target will use a default
22648 filename (e.g.@: the last program run).
22649
22650 @item set remote interrupt-sequence
22651 @cindex interrupt remote programs
22652 @cindex select Ctrl-C, BREAK or BREAK-g
22653 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22654 @samp{BREAK-g} as the
22655 sequence to the remote target in order to interrupt the execution.
22656 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22657 is high level of serial line for some certain time.
22658 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22659 It is @code{BREAK} signal followed by character @code{g}.
22660
22661 @item show interrupt-sequence
22662 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22663 is sent by @value{GDBN} to interrupt the remote program.
22664 @code{BREAK-g} is BREAK signal followed by @code{g} and
22665 also known as Magic SysRq g.
22666
22667 @item set remote interrupt-on-connect
22668 @cindex send interrupt-sequence on start
22669 Specify whether interrupt-sequence is sent to remote target when
22670 @value{GDBN} connects to it. This is mostly needed when you debug
22671 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22672 which is known as Magic SysRq g in order to connect @value{GDBN}.
22673
22674 @item show interrupt-on-connect
22675 Show whether interrupt-sequence is sent
22676 to remote target when @value{GDBN} connects to it.
22677
22678 @kindex set tcp
22679 @kindex show tcp
22680 @item set tcp auto-retry on
22681 @cindex auto-retry, for remote TCP target
22682 Enable auto-retry for remote TCP connections. This is useful if the remote
22683 debugging agent is launched in parallel with @value{GDBN}; there is a race
22684 condition because the agent may not become ready to accept the connection
22685 before @value{GDBN} attempts to connect. When auto-retry is
22686 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22687 to establish the connection using the timeout specified by
22688 @code{set tcp connect-timeout}.
22689
22690 @item set tcp auto-retry off
22691 Do not auto-retry failed TCP connections.
22692
22693 @item show tcp auto-retry
22694 Show the current auto-retry setting.
22695
22696 @item set tcp connect-timeout @var{seconds}
22697 @itemx set tcp connect-timeout unlimited
22698 @cindex connection timeout, for remote TCP target
22699 @cindex timeout, for remote target connection
22700 Set the timeout for establishing a TCP connection to the remote target to
22701 @var{seconds}. The timeout affects both polling to retry failed connections
22702 (enabled by @code{set tcp auto-retry on}) and waiting for connections
22703 that are merely slow to complete, and represents an approximate cumulative
22704 value. If @var{seconds} is @code{unlimited}, there is no timeout and
22705 @value{GDBN} will keep attempting to establish a connection forever,
22706 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
22707
22708 @item show tcp connect-timeout
22709 Show the current connection timeout setting.
22710 @end table
22711
22712 @cindex remote packets, enabling and disabling
22713 The @value{GDBN} remote protocol autodetects the packets supported by
22714 your debugging stub. If you need to override the autodetection, you
22715 can use these commands to enable or disable individual packets. Each
22716 packet can be set to @samp{on} (the remote target supports this
22717 packet), @samp{off} (the remote target does not support this packet),
22718 or @samp{auto} (detect remote target support for this packet). They
22719 all default to @samp{auto}. For more information about each packet,
22720 see @ref{Remote Protocol}.
22721
22722 During normal use, you should not have to use any of these commands.
22723 If you do, that may be a bug in your remote debugging stub, or a bug
22724 in @value{GDBN}. You may want to report the problem to the
22725 @value{GDBN} developers.
22726
22727 For each packet @var{name}, the command to enable or disable the
22728 packet is @code{set remote @var{name}-packet}. The available settings
22729 are:
22730
22731 @multitable @columnfractions 0.28 0.32 0.25
22732 @item Command Name
22733 @tab Remote Packet
22734 @tab Related Features
22735
22736 @item @code{fetch-register}
22737 @tab @code{p}
22738 @tab @code{info registers}
22739
22740 @item @code{set-register}
22741 @tab @code{P}
22742 @tab @code{set}
22743
22744 @item @code{binary-download}
22745 @tab @code{X}
22746 @tab @code{load}, @code{set}
22747
22748 @item @code{read-aux-vector}
22749 @tab @code{qXfer:auxv:read}
22750 @tab @code{info auxv}
22751
22752 @item @code{symbol-lookup}
22753 @tab @code{qSymbol}
22754 @tab Detecting multiple threads
22755
22756 @item @code{attach}
22757 @tab @code{vAttach}
22758 @tab @code{attach}
22759
22760 @item @code{verbose-resume}
22761 @tab @code{vCont}
22762 @tab Stepping or resuming multiple threads
22763
22764 @item @code{run}
22765 @tab @code{vRun}
22766 @tab @code{run}
22767
22768 @item @code{software-breakpoint}
22769 @tab @code{Z0}
22770 @tab @code{break}
22771
22772 @item @code{hardware-breakpoint}
22773 @tab @code{Z1}
22774 @tab @code{hbreak}
22775
22776 @item @code{write-watchpoint}
22777 @tab @code{Z2}
22778 @tab @code{watch}
22779
22780 @item @code{read-watchpoint}
22781 @tab @code{Z3}
22782 @tab @code{rwatch}
22783
22784 @item @code{access-watchpoint}
22785 @tab @code{Z4}
22786 @tab @code{awatch}
22787
22788 @item @code{pid-to-exec-file}
22789 @tab @code{qXfer:exec-file:read}
22790 @tab @code{attach}, @code{run}
22791
22792 @item @code{target-features}
22793 @tab @code{qXfer:features:read}
22794 @tab @code{set architecture}
22795
22796 @item @code{library-info}
22797 @tab @code{qXfer:libraries:read}
22798 @tab @code{info sharedlibrary}
22799
22800 @item @code{memory-map}
22801 @tab @code{qXfer:memory-map:read}
22802 @tab @code{info mem}
22803
22804 @item @code{read-sdata-object}
22805 @tab @code{qXfer:sdata:read}
22806 @tab @code{print $_sdata}
22807
22808 @item @code{read-siginfo-object}
22809 @tab @code{qXfer:siginfo:read}
22810 @tab @code{print $_siginfo}
22811
22812 @item @code{write-siginfo-object}
22813 @tab @code{qXfer:siginfo:write}
22814 @tab @code{set $_siginfo}
22815
22816 @item @code{threads}
22817 @tab @code{qXfer:threads:read}
22818 @tab @code{info threads}
22819
22820 @item @code{get-thread-local-@*storage-address}
22821 @tab @code{qGetTLSAddr}
22822 @tab Displaying @code{__thread} variables
22823
22824 @item @code{get-thread-information-block-address}
22825 @tab @code{qGetTIBAddr}
22826 @tab Display MS-Windows Thread Information Block.
22827
22828 @item @code{search-memory}
22829 @tab @code{qSearch:memory}
22830 @tab @code{find}
22831
22832 @item @code{supported-packets}
22833 @tab @code{qSupported}
22834 @tab Remote communications parameters
22835
22836 @item @code{catch-syscalls}
22837 @tab @code{QCatchSyscalls}
22838 @tab @code{catch syscall}
22839
22840 @item @code{pass-signals}
22841 @tab @code{QPassSignals}
22842 @tab @code{handle @var{signal}}
22843
22844 @item @code{program-signals}
22845 @tab @code{QProgramSignals}
22846 @tab @code{handle @var{signal}}
22847
22848 @item @code{hostio-close-packet}
22849 @tab @code{vFile:close}
22850 @tab @code{remote get}, @code{remote put}
22851
22852 @item @code{hostio-open-packet}
22853 @tab @code{vFile:open}
22854 @tab @code{remote get}, @code{remote put}
22855
22856 @item @code{hostio-pread-packet}
22857 @tab @code{vFile:pread}
22858 @tab @code{remote get}, @code{remote put}
22859
22860 @item @code{hostio-pwrite-packet}
22861 @tab @code{vFile:pwrite}
22862 @tab @code{remote get}, @code{remote put}
22863
22864 @item @code{hostio-unlink-packet}
22865 @tab @code{vFile:unlink}
22866 @tab @code{remote delete}
22867
22868 @item @code{hostio-readlink-packet}
22869 @tab @code{vFile:readlink}
22870 @tab Host I/O
22871
22872 @item @code{hostio-fstat-packet}
22873 @tab @code{vFile:fstat}
22874 @tab Host I/O
22875
22876 @item @code{hostio-setfs-packet}
22877 @tab @code{vFile:setfs}
22878 @tab Host I/O
22879
22880 @item @code{noack-packet}
22881 @tab @code{QStartNoAckMode}
22882 @tab Packet acknowledgment
22883
22884 @item @code{osdata}
22885 @tab @code{qXfer:osdata:read}
22886 @tab @code{info os}
22887
22888 @item @code{query-attached}
22889 @tab @code{qAttached}
22890 @tab Querying remote process attach state.
22891
22892 @item @code{trace-buffer-size}
22893 @tab @code{QTBuffer:size}
22894 @tab @code{set trace-buffer-size}
22895
22896 @item @code{trace-status}
22897 @tab @code{qTStatus}
22898 @tab @code{tstatus}
22899
22900 @item @code{traceframe-info}
22901 @tab @code{qXfer:traceframe-info:read}
22902 @tab Traceframe info
22903
22904 @item @code{install-in-trace}
22905 @tab @code{InstallInTrace}
22906 @tab Install tracepoint in tracing
22907
22908 @item @code{disable-randomization}
22909 @tab @code{QDisableRandomization}
22910 @tab @code{set disable-randomization}
22911
22912 @item @code{startup-with-shell}
22913 @tab @code{QStartupWithShell}
22914 @tab @code{set startup-with-shell}
22915
22916 @item @code{environment-hex-encoded}
22917 @tab @code{QEnvironmentHexEncoded}
22918 @tab @code{set environment}
22919
22920 @item @code{environment-unset}
22921 @tab @code{QEnvironmentUnset}
22922 @tab @code{unset environment}
22923
22924 @item @code{environment-reset}
22925 @tab @code{QEnvironmentReset}
22926 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
22927
22928 @item @code{set-working-dir}
22929 @tab @code{QSetWorkingDir}
22930 @tab @code{set cwd}
22931
22932 @item @code{conditional-breakpoints-packet}
22933 @tab @code{Z0 and Z1}
22934 @tab @code{Support for target-side breakpoint condition evaluation}
22935
22936 @item @code{multiprocess-extensions}
22937 @tab @code{multiprocess extensions}
22938 @tab Debug multiple processes and remote process PID awareness
22939
22940 @item @code{swbreak-feature}
22941 @tab @code{swbreak stop reason}
22942 @tab @code{break}
22943
22944 @item @code{hwbreak-feature}
22945 @tab @code{hwbreak stop reason}
22946 @tab @code{hbreak}
22947
22948 @item @code{fork-event-feature}
22949 @tab @code{fork stop reason}
22950 @tab @code{fork}
22951
22952 @item @code{vfork-event-feature}
22953 @tab @code{vfork stop reason}
22954 @tab @code{vfork}
22955
22956 @item @code{exec-event-feature}
22957 @tab @code{exec stop reason}
22958 @tab @code{exec}
22959
22960 @item @code{thread-events}
22961 @tab @code{QThreadEvents}
22962 @tab Tracking thread lifetime.
22963
22964 @item @code{no-resumed-stop-reply}
22965 @tab @code{no resumed thread left stop reply}
22966 @tab Tracking thread lifetime.
22967
22968 @end multitable
22969
22970 @node Remote Stub
22971 @section Implementing a Remote Stub
22972
22973 @cindex debugging stub, example
22974 @cindex remote stub, example
22975 @cindex stub example, remote debugging
22976 The stub files provided with @value{GDBN} implement the target side of the
22977 communication protocol, and the @value{GDBN} side is implemented in the
22978 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
22979 these subroutines to communicate, and ignore the details. (If you're
22980 implementing your own stub file, you can still ignore the details: start
22981 with one of the existing stub files. @file{sparc-stub.c} is the best
22982 organized, and therefore the easiest to read.)
22983
22984 @cindex remote serial debugging, overview
22985 To debug a program running on another machine (the debugging
22986 @dfn{target} machine), you must first arrange for all the usual
22987 prerequisites for the program to run by itself. For example, for a C
22988 program, you need:
22989
22990 @enumerate
22991 @item
22992 A startup routine to set up the C runtime environment; these usually
22993 have a name like @file{crt0}. The startup routine may be supplied by
22994 your hardware supplier, or you may have to write your own.
22995
22996 @item
22997 A C subroutine library to support your program's
22998 subroutine calls, notably managing input and output.
22999
23000 @item
23001 A way of getting your program to the other machine---for example, a
23002 download program. These are often supplied by the hardware
23003 manufacturer, but you may have to write your own from hardware
23004 documentation.
23005 @end enumerate
23006
23007 The next step is to arrange for your program to use a serial port to
23008 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23009 machine). In general terms, the scheme looks like this:
23010
23011 @table @emph
23012 @item On the host,
23013 @value{GDBN} already understands how to use this protocol; when everything
23014 else is set up, you can simply use the @samp{target remote} command
23015 (@pxref{Targets,,Specifying a Debugging Target}).
23016
23017 @item On the target,
23018 you must link with your program a few special-purpose subroutines that
23019 implement the @value{GDBN} remote serial protocol. The file containing these
23020 subroutines is called a @dfn{debugging stub}.
23021
23022 On certain remote targets, you can use an auxiliary program
23023 @code{gdbserver} instead of linking a stub into your program.
23024 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23025 @end table
23026
23027 The debugging stub is specific to the architecture of the remote
23028 machine; for example, use @file{sparc-stub.c} to debug programs on
23029 @sc{sparc} boards.
23030
23031 @cindex remote serial stub list
23032 These working remote stubs are distributed with @value{GDBN}:
23033
23034 @table @code
23035
23036 @item i386-stub.c
23037 @cindex @file{i386-stub.c}
23038 @cindex Intel
23039 @cindex i386
23040 For Intel 386 and compatible architectures.
23041
23042 @item m68k-stub.c
23043 @cindex @file{m68k-stub.c}
23044 @cindex Motorola 680x0
23045 @cindex m680x0
23046 For Motorola 680x0 architectures.
23047
23048 @item sh-stub.c
23049 @cindex @file{sh-stub.c}
23050 @cindex Renesas
23051 @cindex SH
23052 For Renesas SH architectures.
23053
23054 @item sparc-stub.c
23055 @cindex @file{sparc-stub.c}
23056 @cindex Sparc
23057 For @sc{sparc} architectures.
23058
23059 @item sparcl-stub.c
23060 @cindex @file{sparcl-stub.c}
23061 @cindex Fujitsu
23062 @cindex SparcLite
23063 For Fujitsu @sc{sparclite} architectures.
23064
23065 @end table
23066
23067 The @file{README} file in the @value{GDBN} distribution may list other
23068 recently added stubs.
23069
23070 @menu
23071 * Stub Contents:: What the stub can do for you
23072 * Bootstrapping:: What you must do for the stub
23073 * Debug Session:: Putting it all together
23074 @end menu
23075
23076 @node Stub Contents
23077 @subsection What the Stub Can Do for You
23078
23079 @cindex remote serial stub
23080 The debugging stub for your architecture supplies these three
23081 subroutines:
23082
23083 @table @code
23084 @item set_debug_traps
23085 @findex set_debug_traps
23086 @cindex remote serial stub, initialization
23087 This routine arranges for @code{handle_exception} to run when your
23088 program stops. You must call this subroutine explicitly in your
23089 program's startup code.
23090
23091 @item handle_exception
23092 @findex handle_exception
23093 @cindex remote serial stub, main routine
23094 This is the central workhorse, but your program never calls it
23095 explicitly---the setup code arranges for @code{handle_exception} to
23096 run when a trap is triggered.
23097
23098 @code{handle_exception} takes control when your program stops during
23099 execution (for example, on a breakpoint), and mediates communications
23100 with @value{GDBN} on the host machine. This is where the communications
23101 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23102 representative on the target machine. It begins by sending summary
23103 information on the state of your program, then continues to execute,
23104 retrieving and transmitting any information @value{GDBN} needs, until you
23105 execute a @value{GDBN} command that makes your program resume; at that point,
23106 @code{handle_exception} returns control to your own code on the target
23107 machine.
23108
23109 @item breakpoint
23110 @cindex @code{breakpoint} subroutine, remote
23111 Use this auxiliary subroutine to make your program contain a
23112 breakpoint. Depending on the particular situation, this may be the only
23113 way for @value{GDBN} to get control. For instance, if your target
23114 machine has some sort of interrupt button, you won't need to call this;
23115 pressing the interrupt button transfers control to
23116 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23117 simply receiving characters on the serial port may also trigger a trap;
23118 again, in that situation, you don't need to call @code{breakpoint} from
23119 your own program---simply running @samp{target remote} from the host
23120 @value{GDBN} session gets control.
23121
23122 Call @code{breakpoint} if none of these is true, or if you simply want
23123 to make certain your program stops at a predetermined point for the
23124 start of your debugging session.
23125 @end table
23126
23127 @node Bootstrapping
23128 @subsection What You Must Do for the Stub
23129
23130 @cindex remote stub, support routines
23131 The debugging stubs that come with @value{GDBN} are set up for a particular
23132 chip architecture, but they have no information about the rest of your
23133 debugging target machine.
23134
23135 First of all you need to tell the stub how to communicate with the
23136 serial port.
23137
23138 @table @code
23139 @item int getDebugChar()
23140 @findex getDebugChar
23141 Write this subroutine to read a single character from the serial port.
23142 It may be identical to @code{getchar} for your target system; a
23143 different name is used to allow you to distinguish the two if you wish.
23144
23145 @item void putDebugChar(int)
23146 @findex putDebugChar
23147 Write this subroutine to write a single character to the serial port.
23148 It may be identical to @code{putchar} for your target system; a
23149 different name is used to allow you to distinguish the two if you wish.
23150 @end table
23151
23152 @cindex control C, and remote debugging
23153 @cindex interrupting remote targets
23154 If you want @value{GDBN} to be able to stop your program while it is
23155 running, you need to use an interrupt-driven serial driver, and arrange
23156 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23157 character). That is the character which @value{GDBN} uses to tell the
23158 remote system to stop.
23159
23160 Getting the debugging target to return the proper status to @value{GDBN}
23161 probably requires changes to the standard stub; one quick and dirty way
23162 is to just execute a breakpoint instruction (the ``dirty'' part is that
23163 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23164
23165 Other routines you need to supply are:
23166
23167 @table @code
23168 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23169 @findex exceptionHandler
23170 Write this function to install @var{exception_address} in the exception
23171 handling tables. You need to do this because the stub does not have any
23172 way of knowing what the exception handling tables on your target system
23173 are like (for example, the processor's table might be in @sc{rom},
23174 containing entries which point to a table in @sc{ram}).
23175 The @var{exception_number} specifies the exception which should be changed;
23176 its meaning is architecture-dependent (for example, different numbers
23177 might represent divide by zero, misaligned access, etc). When this
23178 exception occurs, control should be transferred directly to
23179 @var{exception_address}, and the processor state (stack, registers,
23180 and so on) should be just as it is when a processor exception occurs. So if
23181 you want to use a jump instruction to reach @var{exception_address}, it
23182 should be a simple jump, not a jump to subroutine.
23183
23184 For the 386, @var{exception_address} should be installed as an interrupt
23185 gate so that interrupts are masked while the handler runs. The gate
23186 should be at privilege level 0 (the most privileged level). The
23187 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23188 help from @code{exceptionHandler}.
23189
23190 @item void flush_i_cache()
23191 @findex flush_i_cache
23192 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23193 instruction cache, if any, on your target machine. If there is no
23194 instruction cache, this subroutine may be a no-op.
23195
23196 On target machines that have instruction caches, @value{GDBN} requires this
23197 function to make certain that the state of your program is stable.
23198 @end table
23199
23200 @noindent
23201 You must also make sure this library routine is available:
23202
23203 @table @code
23204 @item void *memset(void *, int, int)
23205 @findex memset
23206 This is the standard library function @code{memset} that sets an area of
23207 memory to a known value. If you have one of the free versions of
23208 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23209 either obtain it from your hardware manufacturer, or write your own.
23210 @end table
23211
23212 If you do not use the GNU C compiler, you may need other standard
23213 library subroutines as well; this varies from one stub to another,
23214 but in general the stubs are likely to use any of the common library
23215 subroutines which @code{@value{NGCC}} generates as inline code.
23216
23217
23218 @node Debug Session
23219 @subsection Putting it All Together
23220
23221 @cindex remote serial debugging summary
23222 In summary, when your program is ready to debug, you must follow these
23223 steps.
23224
23225 @enumerate
23226 @item
23227 Make sure you have defined the supporting low-level routines
23228 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23229 @display
23230 @code{getDebugChar}, @code{putDebugChar},
23231 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23232 @end display
23233
23234 @item
23235 Insert these lines in your program's startup code, before the main
23236 procedure is called:
23237
23238 @smallexample
23239 set_debug_traps();
23240 breakpoint();
23241 @end smallexample
23242
23243 On some machines, when a breakpoint trap is raised, the hardware
23244 automatically makes the PC point to the instruction after the
23245 breakpoint. If your machine doesn't do that, you may need to adjust
23246 @code{handle_exception} to arrange for it to return to the instruction
23247 after the breakpoint on this first invocation, so that your program
23248 doesn't keep hitting the initial breakpoint instead of making
23249 progress.
23250
23251 @item
23252 For the 680x0 stub only, you need to provide a variable called
23253 @code{exceptionHook}. Normally you just use:
23254
23255 @smallexample
23256 void (*exceptionHook)() = 0;
23257 @end smallexample
23258
23259 @noindent
23260 but if before calling @code{set_debug_traps}, you set it to point to a
23261 function in your program, that function is called when
23262 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23263 error). The function indicated by @code{exceptionHook} is called with
23264 one parameter: an @code{int} which is the exception number.
23265
23266 @item
23267 Compile and link together: your program, the @value{GDBN} debugging stub for
23268 your target architecture, and the supporting subroutines.
23269
23270 @item
23271 Make sure you have a serial connection between your target machine and
23272 the @value{GDBN} host, and identify the serial port on the host.
23273
23274 @item
23275 @c The "remote" target now provides a `load' command, so we should
23276 @c document that. FIXME.
23277 Download your program to your target machine (or get it there by
23278 whatever means the manufacturer provides), and start it.
23279
23280 @item
23281 Start @value{GDBN} on the host, and connect to the target
23282 (@pxref{Connecting,,Connecting to a Remote Target}).
23283
23284 @end enumerate
23285
23286 @node Configurations
23287 @chapter Configuration-Specific Information
23288
23289 While nearly all @value{GDBN} commands are available for all native and
23290 cross versions of the debugger, there are some exceptions. This chapter
23291 describes things that are only available in certain configurations.
23292
23293 There are three major categories of configurations: native
23294 configurations, where the host and target are the same, embedded
23295 operating system configurations, which are usually the same for several
23296 different processor architectures, and bare embedded processors, which
23297 are quite different from each other.
23298
23299 @menu
23300 * Native::
23301 * Embedded OS::
23302 * Embedded Processors::
23303 * Architectures::
23304 @end menu
23305
23306 @node Native
23307 @section Native
23308
23309 This section describes details specific to particular native
23310 configurations.
23311
23312 @menu
23313 * BSD libkvm Interface:: Debugging BSD kernel memory images
23314 * Process Information:: Process information
23315 * DJGPP Native:: Features specific to the DJGPP port
23316 * Cygwin Native:: Features specific to the Cygwin port
23317 * Hurd Native:: Features specific to @sc{gnu} Hurd
23318 * Darwin:: Features specific to Darwin
23319 * FreeBSD:: Features specific to FreeBSD
23320 @end menu
23321
23322 @node BSD libkvm Interface
23323 @subsection BSD libkvm Interface
23324
23325 @cindex libkvm
23326 @cindex kernel memory image
23327 @cindex kernel crash dump
23328
23329 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23330 interface that provides a uniform interface for accessing kernel virtual
23331 memory images, including live systems and crash dumps. @value{GDBN}
23332 uses this interface to allow you to debug live kernels and kernel crash
23333 dumps on many native BSD configurations. This is implemented as a
23334 special @code{kvm} debugging target. For debugging a live system, load
23335 the currently running kernel into @value{GDBN} and connect to the
23336 @code{kvm} target:
23337
23338 @smallexample
23339 (@value{GDBP}) @b{target kvm}
23340 @end smallexample
23341
23342 For debugging crash dumps, provide the file name of the crash dump as an
23343 argument:
23344
23345 @smallexample
23346 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23347 @end smallexample
23348
23349 Once connected to the @code{kvm} target, the following commands are
23350 available:
23351
23352 @table @code
23353 @kindex kvm
23354 @item kvm pcb
23355 Set current context from the @dfn{Process Control Block} (PCB) address.
23356
23357 @item kvm proc
23358 Set current context from proc address. This command isn't available on
23359 modern FreeBSD systems.
23360 @end table
23361
23362 @node Process Information
23363 @subsection Process Information
23364 @cindex /proc
23365 @cindex examine process image
23366 @cindex process info via @file{/proc}
23367
23368 Some operating systems provide interfaces to fetch additional
23369 information about running processes beyond memory and per-thread
23370 register state. If @value{GDBN} is configured for an operating system
23371 with a supported interface, the command @code{info proc} is available
23372 to report information about the process running your program, or about
23373 any process running on your system.
23374
23375 One supported interface is a facility called @samp{/proc} that can be
23376 used to examine the image of a running process using file-system
23377 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23378 systems.
23379
23380 On FreeBSD systems, system control nodes are used to query process
23381 information.
23382
23383 In addition, some systems may provide additional process information
23384 in core files. Note that a core file may include a subset of the
23385 information available from a live process. Process information is
23386 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23387 systems.
23388
23389 @table @code
23390 @kindex info proc
23391 @cindex process ID
23392 @item info proc
23393 @itemx info proc @var{process-id}
23394 Summarize available information about a process. If a
23395 process ID is specified by @var{process-id}, display information about
23396 that process; otherwise display information about the program being
23397 debugged. The summary includes the debugged process ID, the command
23398 line used to invoke it, its current working directory, and its
23399 executable file's absolute file name.
23400
23401 On some systems, @var{process-id} can be of the form
23402 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23403 within a process. If the optional @var{pid} part is missing, it means
23404 a thread from the process being debugged (the leading @samp{/} still
23405 needs to be present, or else @value{GDBN} will interpret the number as
23406 a process ID rather than a thread ID).
23407
23408 @item info proc cmdline
23409 @cindex info proc cmdline
23410 Show the original command line of the process. This command is
23411 supported on @sc{gnu}/Linux and FreeBSD.
23412
23413 @item info proc cwd
23414 @cindex info proc cwd
23415 Show the current working directory of the process. This command is
23416 supported on @sc{gnu}/Linux and FreeBSD.
23417
23418 @item info proc exe
23419 @cindex info proc exe
23420 Show the name of executable of the process. This command is supported
23421 on @sc{gnu}/Linux and FreeBSD.
23422
23423 @item info proc files
23424 @cindex info proc files
23425 Show the file descriptors open by the process. For each open file
23426 descriptor, @value{GDBN} shows its number, type (file, directory,
23427 character device, socket), file pointer offset, and the name of the
23428 resource open on the descriptor. The resource name can be a file name
23429 (for files, directories, and devices) or a protocol followed by socket
23430 address (for network connections). This command is supported on
23431 FreeBSD.
23432
23433 This example shows the open file descriptors for a process using a
23434 tty for standard input and output as well as two network sockets:
23435
23436 @smallexample
23437 (gdb) info proc files 22136
23438 process 22136
23439 Open files:
23440
23441 FD Type Offset Flags Name
23442 text file - r-------- /usr/bin/ssh
23443 ctty chr - rw------- /dev/pts/20
23444 cwd dir - r-------- /usr/home/john
23445 root dir - r-------- /
23446 0 chr 0x32933a4 rw------- /dev/pts/20
23447 1 chr 0x32933a4 rw------- /dev/pts/20
23448 2 chr 0x32933a4 rw------- /dev/pts/20
23449 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23450 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23451 @end smallexample
23452
23453 @item info proc mappings
23454 @cindex memory address space mappings
23455 Report the memory address space ranges accessible in a process. On
23456 Solaris and FreeBSD systems, each memory range includes information on
23457 whether the process has read, write, or execute access rights to each
23458 range. On @sc{gnu}/Linux and FreeBSD systems, each memory range
23459 includes the object file which is mapped to that range.
23460
23461 @item info proc stat
23462 @itemx info proc status
23463 @cindex process detailed status information
23464 Show additional process-related information, including the user ID and
23465 group ID; virtual memory usage; the signals that are pending, blocked,
23466 and ignored; its TTY; its consumption of system and user time; its
23467 stack size; its @samp{nice} value; etc. These commands are supported
23468 on @sc{gnu}/Linux and FreeBSD.
23469
23470 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23471 information (type @kbd{man 5 proc} from your shell prompt).
23472
23473 For FreeBSD systems, @code{info proc stat} is an alias for @code{info
23474 proc status}.
23475
23476 @item info proc all
23477 Show all the information about the process described under all of the
23478 above @code{info proc} subcommands.
23479
23480 @ignore
23481 @comment These sub-options of 'info proc' were not included when
23482 @comment procfs.c was re-written. Keep their descriptions around
23483 @comment against the day when someone finds the time to put them back in.
23484 @kindex info proc times
23485 @item info proc times
23486 Starting time, user CPU time, and system CPU time for your program and
23487 its children.
23488
23489 @kindex info proc id
23490 @item info proc id
23491 Report on the process IDs related to your program: its own process ID,
23492 the ID of its parent, the process group ID, and the session ID.
23493 @end ignore
23494
23495 @item set procfs-trace
23496 @kindex set procfs-trace
23497 @cindex @code{procfs} API calls
23498 This command enables and disables tracing of @code{procfs} API calls.
23499
23500 @item show procfs-trace
23501 @kindex show procfs-trace
23502 Show the current state of @code{procfs} API call tracing.
23503
23504 @item set procfs-file @var{file}
23505 @kindex set procfs-file
23506 Tell @value{GDBN} to write @code{procfs} API trace to the named
23507 @var{file}. @value{GDBN} appends the trace info to the previous
23508 contents of the file. The default is to display the trace on the
23509 standard output.
23510
23511 @item show procfs-file
23512 @kindex show procfs-file
23513 Show the file to which @code{procfs} API trace is written.
23514
23515 @item proc-trace-entry
23516 @itemx proc-trace-exit
23517 @itemx proc-untrace-entry
23518 @itemx proc-untrace-exit
23519 @kindex proc-trace-entry
23520 @kindex proc-trace-exit
23521 @kindex proc-untrace-entry
23522 @kindex proc-untrace-exit
23523 These commands enable and disable tracing of entries into and exits
23524 from the @code{syscall} interface.
23525
23526 @item info pidlist
23527 @kindex info pidlist
23528 @cindex process list, QNX Neutrino
23529 For QNX Neutrino only, this command displays the list of all the
23530 processes and all the threads within each process.
23531
23532 @item info meminfo
23533 @kindex info meminfo
23534 @cindex mapinfo list, QNX Neutrino
23535 For QNX Neutrino only, this command displays the list of all mapinfos.
23536 @end table
23537
23538 @node DJGPP Native
23539 @subsection Features for Debugging @sc{djgpp} Programs
23540 @cindex @sc{djgpp} debugging
23541 @cindex native @sc{djgpp} debugging
23542 @cindex MS-DOS-specific commands
23543
23544 @cindex DPMI
23545 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23546 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23547 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23548 top of real-mode DOS systems and their emulations.
23549
23550 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
23551 defines a few commands specific to the @sc{djgpp} port. This
23552 subsection describes those commands.
23553
23554 @table @code
23555 @kindex info dos
23556 @item info dos
23557 This is a prefix of @sc{djgpp}-specific commands which print
23558 information about the target system and important OS structures.
23559
23560 @kindex sysinfo
23561 @cindex MS-DOS system info
23562 @cindex free memory information (MS-DOS)
23563 @item info dos sysinfo
23564 This command displays assorted information about the underlying
23565 platform: the CPU type and features, the OS version and flavor, the
23566 DPMI version, and the available conventional and DPMI memory.
23567
23568 @cindex GDT
23569 @cindex LDT
23570 @cindex IDT
23571 @cindex segment descriptor tables
23572 @cindex descriptor tables display
23573 @item info dos gdt
23574 @itemx info dos ldt
23575 @itemx info dos idt
23576 These 3 commands display entries from, respectively, Global, Local,
23577 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23578 tables are data structures which store a descriptor for each segment
23579 that is currently in use. The segment's selector is an index into a
23580 descriptor table; the table entry for that index holds the
23581 descriptor's base address and limit, and its attributes and access
23582 rights.
23583
23584 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23585 segment (used for both data and the stack), and a DOS segment (which
23586 allows access to DOS/BIOS data structures and absolute addresses in
23587 conventional memory). However, the DPMI host will usually define
23588 additional segments in order to support the DPMI environment.
23589
23590 @cindex garbled pointers
23591 These commands allow to display entries from the descriptor tables.
23592 Without an argument, all entries from the specified table are
23593 displayed. An argument, which should be an integer expression, means
23594 display a single entry whose index is given by the argument. For
23595 example, here's a convenient way to display information about the
23596 debugged program's data segment:
23597
23598 @smallexample
23599 @exdent @code{(@value{GDBP}) info dos ldt $ds}
23600 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23601 @end smallexample
23602
23603 @noindent
23604 This comes in handy when you want to see whether a pointer is outside
23605 the data segment's limit (i.e.@: @dfn{garbled}).
23606
23607 @cindex page tables display (MS-DOS)
23608 @item info dos pde
23609 @itemx info dos pte
23610 These two commands display entries from, respectively, the Page
23611 Directory and the Page Tables. Page Directories and Page Tables are
23612 data structures which control how virtual memory addresses are mapped
23613 into physical addresses. A Page Table includes an entry for every
23614 page of memory that is mapped into the program's address space; there
23615 may be several Page Tables, each one holding up to 4096 entries. A
23616 Page Directory has up to 4096 entries, one each for every Page Table
23617 that is currently in use.
23618
23619 Without an argument, @kbd{info dos pde} displays the entire Page
23620 Directory, and @kbd{info dos pte} displays all the entries in all of
23621 the Page Tables. An argument, an integer expression, given to the
23622 @kbd{info dos pde} command means display only that entry from the Page
23623 Directory table. An argument given to the @kbd{info dos pte} command
23624 means display entries from a single Page Table, the one pointed to by
23625 the specified entry in the Page Directory.
23626
23627 @cindex direct memory access (DMA) on MS-DOS
23628 These commands are useful when your program uses @dfn{DMA} (Direct
23629 Memory Access), which needs physical addresses to program the DMA
23630 controller.
23631
23632 These commands are supported only with some DPMI servers.
23633
23634 @cindex physical address from linear address
23635 @item info dos address-pte @var{addr}
23636 This command displays the Page Table entry for a specified linear
23637 address. The argument @var{addr} is a linear address which should
23638 already have the appropriate segment's base address added to it,
23639 because this command accepts addresses which may belong to @emph{any}
23640 segment. For example, here's how to display the Page Table entry for
23641 the page where a variable @code{i} is stored:
23642
23643 @smallexample
23644 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23645 @exdent @code{Page Table entry for address 0x11a00d30:}
23646 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
23647 @end smallexample
23648
23649 @noindent
23650 This says that @code{i} is stored at offset @code{0xd30} from the page
23651 whose physical base address is @code{0x02698000}, and shows all the
23652 attributes of that page.
23653
23654 Note that you must cast the addresses of variables to a @code{char *},
23655 since otherwise the value of @code{__djgpp_base_address}, the base
23656 address of all variables and functions in a @sc{djgpp} program, will
23657 be added using the rules of C pointer arithmetics: if @code{i} is
23658 declared an @code{int}, @value{GDBN} will add 4 times the value of
23659 @code{__djgpp_base_address} to the address of @code{i}.
23660
23661 Here's another example, it displays the Page Table entry for the
23662 transfer buffer:
23663
23664 @smallexample
23665 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23666 @exdent @code{Page Table entry for address 0x29110:}
23667 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23668 @end smallexample
23669
23670 @noindent
23671 (The @code{+ 3} offset is because the transfer buffer's address is the
23672 3rd member of the @code{_go32_info_block} structure.) The output
23673 clearly shows that this DPMI server maps the addresses in conventional
23674 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23675 linear (@code{0x29110}) addresses are identical.
23676
23677 This command is supported only with some DPMI servers.
23678 @end table
23679
23680 @cindex DOS serial data link, remote debugging
23681 In addition to native debugging, the DJGPP port supports remote
23682 debugging via a serial data link. The following commands are specific
23683 to remote serial debugging in the DJGPP port of @value{GDBN}.
23684
23685 @table @code
23686 @kindex set com1base
23687 @kindex set com1irq
23688 @kindex set com2base
23689 @kindex set com2irq
23690 @kindex set com3base
23691 @kindex set com3irq
23692 @kindex set com4base
23693 @kindex set com4irq
23694 @item set com1base @var{addr}
23695 This command sets the base I/O port address of the @file{COM1} serial
23696 port.
23697
23698 @item set com1irq @var{irq}
23699 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23700 for the @file{COM1} serial port.
23701
23702 There are similar commands @samp{set com2base}, @samp{set com3irq},
23703 etc.@: for setting the port address and the @code{IRQ} lines for the
23704 other 3 COM ports.
23705
23706 @kindex show com1base
23707 @kindex show com1irq
23708 @kindex show com2base
23709 @kindex show com2irq
23710 @kindex show com3base
23711 @kindex show com3irq
23712 @kindex show com4base
23713 @kindex show com4irq
23714 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23715 display the current settings of the base address and the @code{IRQ}
23716 lines used by the COM ports.
23717
23718 @item info serial
23719 @kindex info serial
23720 @cindex DOS serial port status
23721 This command prints the status of the 4 DOS serial ports. For each
23722 port, it prints whether it's active or not, its I/O base address and
23723 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23724 counts of various errors encountered so far.
23725 @end table
23726
23727
23728 @node Cygwin Native
23729 @subsection Features for Debugging MS Windows PE Executables
23730 @cindex MS Windows debugging
23731 @cindex native Cygwin debugging
23732 @cindex Cygwin-specific commands
23733
23734 @value{GDBN} supports native debugging of MS Windows programs, including
23735 DLLs with and without symbolic debugging information.
23736
23737 @cindex Ctrl-BREAK, MS-Windows
23738 @cindex interrupt debuggee on MS-Windows
23739 MS-Windows programs that call @code{SetConsoleMode} to switch off the
23740 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23741 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23742 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23743 sequence, which can be used to interrupt the debuggee even if it
23744 ignores @kbd{C-c}.
23745
23746 There are various additional Cygwin-specific commands, described in
23747 this section. Working with DLLs that have no debugging symbols is
23748 described in @ref{Non-debug DLL Symbols}.
23749
23750 @table @code
23751 @kindex info w32
23752 @item info w32
23753 This is a prefix of MS Windows-specific commands which print
23754 information about the target system and important OS structures.
23755
23756 @item info w32 selector
23757 This command displays information returned by
23758 the Win32 API @code{GetThreadSelectorEntry} function.
23759 It takes an optional argument that is evaluated to
23760 a long value to give the information about this given selector.
23761 Without argument, this command displays information
23762 about the six segment registers.
23763
23764 @item info w32 thread-information-block
23765 This command displays thread specific information stored in the
23766 Thread Information Block (readable on the X86 CPU family using @code{$fs}
23767 selector for 32-bit programs and @code{$gs} for 64-bit programs).
23768
23769 @kindex signal-event
23770 @item signal-event @var{id}
23771 This command signals an event with user-provided @var{id}. Used to resume
23772 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23773
23774 To use it, create or edit the following keys in
23775 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23776 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23777 (for x86_64 versions):
23778
23779 @itemize @minus
23780 @item
23781 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
23782 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23783 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
23784
23785 The first @code{%ld} will be replaced by the process ID of the
23786 crashing process, the second @code{%ld} will be replaced by the ID of
23787 the event that blocks the crashing process, waiting for @value{GDBN}
23788 to attach.
23789
23790 @item
23791 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23792 make the system run debugger specified by the Debugger key
23793 automatically, @code{0} will cause a dialog box with ``OK'' and
23794 ``Cancel'' buttons to appear, which allows the user to either
23795 terminate the crashing process (OK) or debug it (Cancel).
23796 @end itemize
23797
23798 @kindex set cygwin-exceptions
23799 @cindex debugging the Cygwin DLL
23800 @cindex Cygwin DLL, debugging
23801 @item set cygwin-exceptions @var{mode}
23802 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23803 happen inside the Cygwin DLL. If @var{mode} is @code{off},
23804 @value{GDBN} will delay recognition of exceptions, and may ignore some
23805 exceptions which seem to be caused by internal Cygwin DLL
23806 ``bookkeeping''. This option is meant primarily for debugging the
23807 Cygwin DLL itself; the default value is @code{off} to avoid annoying
23808 @value{GDBN} users with false @code{SIGSEGV} signals.
23809
23810 @kindex show cygwin-exceptions
23811 @item show cygwin-exceptions
23812 Displays whether @value{GDBN} will break on exceptions that happen
23813 inside the Cygwin DLL itself.
23814
23815 @kindex set new-console
23816 @item set new-console @var{mode}
23817 If @var{mode} is @code{on} the debuggee will
23818 be started in a new console on next start.
23819 If @var{mode} is @code{off}, the debuggee will
23820 be started in the same console as the debugger.
23821
23822 @kindex show new-console
23823 @item show new-console
23824 Displays whether a new console is used
23825 when the debuggee is started.
23826
23827 @kindex set new-group
23828 @item set new-group @var{mode}
23829 This boolean value controls whether the debuggee should
23830 start a new group or stay in the same group as the debugger.
23831 This affects the way the Windows OS handles
23832 @samp{Ctrl-C}.
23833
23834 @kindex show new-group
23835 @item show new-group
23836 Displays current value of new-group boolean.
23837
23838 @kindex set debugevents
23839 @item set debugevents
23840 This boolean value adds debug output concerning kernel events related
23841 to the debuggee seen by the debugger. This includes events that
23842 signal thread and process creation and exit, DLL loading and
23843 unloading, console interrupts, and debugging messages produced by the
23844 Windows @code{OutputDebugString} API call.
23845
23846 @kindex set debugexec
23847 @item set debugexec
23848 This boolean value adds debug output concerning execute events
23849 (such as resume thread) seen by the debugger.
23850
23851 @kindex set debugexceptions
23852 @item set debugexceptions
23853 This boolean value adds debug output concerning exceptions in the
23854 debuggee seen by the debugger.
23855
23856 @kindex set debugmemory
23857 @item set debugmemory
23858 This boolean value adds debug output concerning debuggee memory reads
23859 and writes by the debugger.
23860
23861 @kindex set shell
23862 @item set shell
23863 This boolean values specifies whether the debuggee is called
23864 via a shell or directly (default value is on).
23865
23866 @kindex show shell
23867 @item show shell
23868 Displays if the debuggee will be started with a shell.
23869
23870 @end table
23871
23872 @menu
23873 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
23874 @end menu
23875
23876 @node Non-debug DLL Symbols
23877 @subsubsection Support for DLLs without Debugging Symbols
23878 @cindex DLLs with no debugging symbols
23879 @cindex Minimal symbols and DLLs
23880
23881 Very often on windows, some of the DLLs that your program relies on do
23882 not include symbolic debugging information (for example,
23883 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
23884 symbols in a DLL, it relies on the minimal amount of symbolic
23885 information contained in the DLL's export table. This section
23886 describes working with such symbols, known internally to @value{GDBN} as
23887 ``minimal symbols''.
23888
23889 Note that before the debugged program has started execution, no DLLs
23890 will have been loaded. The easiest way around this problem is simply to
23891 start the program --- either by setting a breakpoint or letting the
23892 program run once to completion.
23893
23894 @subsubsection DLL Name Prefixes
23895
23896 In keeping with the naming conventions used by the Microsoft debugging
23897 tools, DLL export symbols are made available with a prefix based on the
23898 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
23899 also entered into the symbol table, so @code{CreateFileA} is often
23900 sufficient. In some cases there will be name clashes within a program
23901 (particularly if the executable itself includes full debugging symbols)
23902 necessitating the use of the fully qualified name when referring to the
23903 contents of the DLL. Use single-quotes around the name to avoid the
23904 exclamation mark (``!'') being interpreted as a language operator.
23905
23906 Note that the internal name of the DLL may be all upper-case, even
23907 though the file name of the DLL is lower-case, or vice-versa. Since
23908 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
23909 some confusion. If in doubt, try the @code{info functions} and
23910 @code{info variables} commands or even @code{maint print msymbols}
23911 (@pxref{Symbols}). Here's an example:
23912
23913 @smallexample
23914 (@value{GDBP}) info function CreateFileA
23915 All functions matching regular expression "CreateFileA":
23916
23917 Non-debugging symbols:
23918 0x77e885f4 CreateFileA
23919 0x77e885f4 KERNEL32!CreateFileA
23920 @end smallexample
23921
23922 @smallexample
23923 (@value{GDBP}) info function !
23924 All functions matching regular expression "!":
23925
23926 Non-debugging symbols:
23927 0x6100114c cygwin1!__assert
23928 0x61004034 cygwin1!_dll_crt0@@0
23929 0x61004240 cygwin1!dll_crt0(per_process *)
23930 [etc...]
23931 @end smallexample
23932
23933 @subsubsection Working with Minimal Symbols
23934
23935 Symbols extracted from a DLL's export table do not contain very much
23936 type information. All that @value{GDBN} can do is guess whether a symbol
23937 refers to a function or variable depending on the linker section that
23938 contains the symbol. Also note that the actual contents of the memory
23939 contained in a DLL are not available unless the program is running. This
23940 means that you cannot examine the contents of a variable or disassemble
23941 a function within a DLL without a running program.
23942
23943 Variables are generally treated as pointers and dereferenced
23944 automatically. For this reason, it is often necessary to prefix a
23945 variable name with the address-of operator (``&'') and provide explicit
23946 type information in the command. Here's an example of the type of
23947 problem:
23948
23949 @smallexample
23950 (@value{GDBP}) print 'cygwin1!__argv'
23951 'cygwin1!__argv' has unknown type; cast it to its declared type
23952 @end smallexample
23953
23954 @smallexample
23955 (@value{GDBP}) x 'cygwin1!__argv'
23956 'cygwin1!__argv' has unknown type; cast it to its declared type
23957 @end smallexample
23958
23959 And two possible solutions:
23960
23961 @smallexample
23962 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
23963 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
23964 @end smallexample
23965
23966 @smallexample
23967 (@value{GDBP}) x/2x &'cygwin1!__argv'
23968 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
23969 (@value{GDBP}) x/x 0x10021608
23970 0x10021608: 0x0022fd98
23971 (@value{GDBP}) x/s 0x0022fd98
23972 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
23973 @end smallexample
23974
23975 Setting a break point within a DLL is possible even before the program
23976 starts execution. However, under these circumstances, @value{GDBN} can't
23977 examine the initial instructions of the function in order to skip the
23978 function's frame set-up code. You can work around this by using ``*&''
23979 to set the breakpoint at a raw memory address:
23980
23981 @smallexample
23982 (@value{GDBP}) break *&'python22!PyOS_Readline'
23983 Breakpoint 1 at 0x1e04eff0
23984 @end smallexample
23985
23986 The author of these extensions is not entirely convinced that setting a
23987 break point within a shared DLL like @file{kernel32.dll} is completely
23988 safe.
23989
23990 @node Hurd Native
23991 @subsection Commands Specific to @sc{gnu} Hurd Systems
23992 @cindex @sc{gnu} Hurd debugging
23993
23994 This subsection describes @value{GDBN} commands specific to the
23995 @sc{gnu} Hurd native debugging.
23996
23997 @table @code
23998 @item set signals
23999 @itemx set sigs
24000 @kindex set signals@r{, Hurd command}
24001 @kindex set sigs@r{, Hurd command}
24002 This command toggles the state of inferior signal interception by
24003 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24004 affected by this command. @code{sigs} is a shorthand alias for
24005 @code{signals}.
24006
24007 @item show signals
24008 @itemx show sigs
24009 @kindex show signals@r{, Hurd command}
24010 @kindex show sigs@r{, Hurd command}
24011 Show the current state of intercepting inferior's signals.
24012
24013 @item set signal-thread
24014 @itemx set sigthread
24015 @kindex set signal-thread
24016 @kindex set sigthread
24017 This command tells @value{GDBN} which thread is the @code{libc} signal
24018 thread. That thread is run when a signal is delivered to a running
24019 process. @code{set sigthread} is the shorthand alias of @code{set
24020 signal-thread}.
24021
24022 @item show signal-thread
24023 @itemx show sigthread
24024 @kindex show signal-thread
24025 @kindex show sigthread
24026 These two commands show which thread will run when the inferior is
24027 delivered a signal.
24028
24029 @item set stopped
24030 @kindex set stopped@r{, Hurd command}
24031 This commands tells @value{GDBN} that the inferior process is stopped,
24032 as with the @code{SIGSTOP} signal. The stopped process can be
24033 continued by delivering a signal to it.
24034
24035 @item show stopped
24036 @kindex show stopped@r{, Hurd command}
24037 This command shows whether @value{GDBN} thinks the debuggee is
24038 stopped.
24039
24040 @item set exceptions
24041 @kindex set exceptions@r{, Hurd command}
24042 Use this command to turn off trapping of exceptions in the inferior.
24043 When exception trapping is off, neither breakpoints nor
24044 single-stepping will work. To restore the default, set exception
24045 trapping on.
24046
24047 @item show exceptions
24048 @kindex show exceptions@r{, Hurd command}
24049 Show the current state of trapping exceptions in the inferior.
24050
24051 @item set task pause
24052 @kindex set task@r{, Hurd commands}
24053 @cindex task attributes (@sc{gnu} Hurd)
24054 @cindex pause current task (@sc{gnu} Hurd)
24055 This command toggles task suspension when @value{GDBN} has control.
24056 Setting it to on takes effect immediately, and the task is suspended
24057 whenever @value{GDBN} gets control. Setting it to off will take
24058 effect the next time the inferior is continued. If this option is set
24059 to off, you can use @code{set thread default pause on} or @code{set
24060 thread pause on} (see below) to pause individual threads.
24061
24062 @item show task pause
24063 @kindex show task@r{, Hurd commands}
24064 Show the current state of task suspension.
24065
24066 @item set task detach-suspend-count
24067 @cindex task suspend count
24068 @cindex detach from task, @sc{gnu} Hurd
24069 This command sets the suspend count the task will be left with when
24070 @value{GDBN} detaches from it.
24071
24072 @item show task detach-suspend-count
24073 Show the suspend count the task will be left with when detaching.
24074
24075 @item set task exception-port
24076 @itemx set task excp
24077 @cindex task exception port, @sc{gnu} Hurd
24078 This command sets the task exception port to which @value{GDBN} will
24079 forward exceptions. The argument should be the value of the @dfn{send
24080 rights} of the task. @code{set task excp} is a shorthand alias.
24081
24082 @item set noninvasive
24083 @cindex noninvasive task options
24084 This command switches @value{GDBN} to a mode that is the least
24085 invasive as far as interfering with the inferior is concerned. This
24086 is the same as using @code{set task pause}, @code{set exceptions}, and
24087 @code{set signals} to values opposite to the defaults.
24088
24089 @item info send-rights
24090 @itemx info receive-rights
24091 @itemx info port-rights
24092 @itemx info port-sets
24093 @itemx info dead-names
24094 @itemx info ports
24095 @itemx info psets
24096 @cindex send rights, @sc{gnu} Hurd
24097 @cindex receive rights, @sc{gnu} Hurd
24098 @cindex port rights, @sc{gnu} Hurd
24099 @cindex port sets, @sc{gnu} Hurd
24100 @cindex dead names, @sc{gnu} Hurd
24101 These commands display information about, respectively, send rights,
24102 receive rights, port rights, port sets, and dead names of a task.
24103 There are also shorthand aliases: @code{info ports} for @code{info
24104 port-rights} and @code{info psets} for @code{info port-sets}.
24105
24106 @item set thread pause
24107 @kindex set thread@r{, Hurd command}
24108 @cindex thread properties, @sc{gnu} Hurd
24109 @cindex pause current thread (@sc{gnu} Hurd)
24110 This command toggles current thread suspension when @value{GDBN} has
24111 control. Setting it to on takes effect immediately, and the current
24112 thread is suspended whenever @value{GDBN} gets control. Setting it to
24113 off will take effect the next time the inferior is continued.
24114 Normally, this command has no effect, since when @value{GDBN} has
24115 control, the whole task is suspended. However, if you used @code{set
24116 task pause off} (see above), this command comes in handy to suspend
24117 only the current thread.
24118
24119 @item show thread pause
24120 @kindex show thread@r{, Hurd command}
24121 This command shows the state of current thread suspension.
24122
24123 @item set thread run
24124 This command sets whether the current thread is allowed to run.
24125
24126 @item show thread run
24127 Show whether the current thread is allowed to run.
24128
24129 @item set thread detach-suspend-count
24130 @cindex thread suspend count, @sc{gnu} Hurd
24131 @cindex detach from thread, @sc{gnu} Hurd
24132 This command sets the suspend count @value{GDBN} will leave on a
24133 thread when detaching. This number is relative to the suspend count
24134 found by @value{GDBN} when it notices the thread; use @code{set thread
24135 takeover-suspend-count} to force it to an absolute value.
24136
24137 @item show thread detach-suspend-count
24138 Show the suspend count @value{GDBN} will leave on the thread when
24139 detaching.
24140
24141 @item set thread exception-port
24142 @itemx set thread excp
24143 Set the thread exception port to which to forward exceptions. This
24144 overrides the port set by @code{set task exception-port} (see above).
24145 @code{set thread excp} is the shorthand alias.
24146
24147 @item set thread takeover-suspend-count
24148 Normally, @value{GDBN}'s thread suspend counts are relative to the
24149 value @value{GDBN} finds when it notices each thread. This command
24150 changes the suspend counts to be absolute instead.
24151
24152 @item set thread default
24153 @itemx show thread default
24154 @cindex thread default settings, @sc{gnu} Hurd
24155 Each of the above @code{set thread} commands has a @code{set thread
24156 default} counterpart (e.g., @code{set thread default pause}, @code{set
24157 thread default exception-port}, etc.). The @code{thread default}
24158 variety of commands sets the default thread properties for all
24159 threads; you can then change the properties of individual threads with
24160 the non-default commands.
24161 @end table
24162
24163 @node Darwin
24164 @subsection Darwin
24165 @cindex Darwin
24166
24167 @value{GDBN} provides the following commands specific to the Darwin target:
24168
24169 @table @code
24170 @item set debug darwin @var{num}
24171 @kindex set debug darwin
24172 When set to a non zero value, enables debugging messages specific to
24173 the Darwin support. Higher values produce more verbose output.
24174
24175 @item show debug darwin
24176 @kindex show debug darwin
24177 Show the current state of Darwin messages.
24178
24179 @item set debug mach-o @var{num}
24180 @kindex set debug mach-o
24181 When set to a non zero value, enables debugging messages while
24182 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24183 file format used on Darwin for object and executable files.) Higher
24184 values produce more verbose output. This is a command to diagnose
24185 problems internal to @value{GDBN} and should not be needed in normal
24186 usage.
24187
24188 @item show debug mach-o
24189 @kindex show debug mach-o
24190 Show the current state of Mach-O file messages.
24191
24192 @item set mach-exceptions on
24193 @itemx set mach-exceptions off
24194 @kindex set mach-exceptions
24195 On Darwin, faults are first reported as a Mach exception and are then
24196 mapped to a Posix signal. Use this command to turn on trapping of
24197 Mach exceptions in the inferior. This might be sometimes useful to
24198 better understand the cause of a fault. The default is off.
24199
24200 @item show mach-exceptions
24201 @kindex show mach-exceptions
24202 Show the current state of exceptions trapping.
24203 @end table
24204
24205 @node FreeBSD
24206 @subsection FreeBSD
24207 @cindex FreeBSD
24208
24209 When the ABI of a system call is changed in the FreeBSD kernel, this
24210 is implemented by leaving a compatibility system call using the old
24211 ABI at the existing number and allocating a new system call number for
24212 the version using the new ABI. As a convenience, when a system call
24213 is caught by name (@pxref{catch syscall}), compatibility system calls
24214 are also caught.
24215
24216 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24217 system call and catching the @code{kevent} system call by name catches
24218 both variants:
24219
24220 @smallexample
24221 (@value{GDBP}) catch syscall kevent
24222 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24223 (@value{GDBP})
24224 @end smallexample
24225
24226
24227 @node Embedded OS
24228 @section Embedded Operating Systems
24229
24230 This section describes configurations involving the debugging of
24231 embedded operating systems that are available for several different
24232 architectures.
24233
24234 @value{GDBN} includes the ability to debug programs running on
24235 various real-time operating systems.
24236
24237 @node Embedded Processors
24238 @section Embedded Processors
24239
24240 This section goes into details specific to particular embedded
24241 configurations.
24242
24243 @cindex send command to simulator
24244 Whenever a specific embedded processor has a simulator, @value{GDBN}
24245 allows to send an arbitrary command to the simulator.
24246
24247 @table @code
24248 @item sim @var{command}
24249 @kindex sim@r{, a command}
24250 Send an arbitrary @var{command} string to the simulator. Consult the
24251 documentation for the specific simulator in use for information about
24252 acceptable commands.
24253 @end table
24254
24255
24256 @menu
24257 * ARC:: Synopsys ARC
24258 * ARM:: ARM
24259 * M68K:: Motorola M68K
24260 * MicroBlaze:: Xilinx MicroBlaze
24261 * MIPS Embedded:: MIPS Embedded
24262 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24263 * PowerPC Embedded:: PowerPC Embedded
24264 * AVR:: Atmel AVR
24265 * CRIS:: CRIS
24266 * Super-H:: Renesas Super-H
24267 @end menu
24268
24269 @node ARC
24270 @subsection Synopsys ARC
24271 @cindex Synopsys ARC
24272 @cindex ARC specific commands
24273 @cindex ARC600
24274 @cindex ARC700
24275 @cindex ARC EM
24276 @cindex ARC HS
24277
24278 @value{GDBN} provides the following ARC-specific commands:
24279
24280 @table @code
24281 @item set debug arc
24282 @kindex set debug arc
24283 Control the level of ARC specific debug messages. Use 0 for no messages (the
24284 default), 1 for debug messages, and 2 for even more debug messages.
24285
24286 @item show debug arc
24287 @kindex show debug arc
24288 Show the level of ARC specific debugging in operation.
24289
24290 @item maint print arc arc-instruction @var{address}
24291 @kindex maint print arc arc-instruction
24292 Print internal disassembler information about instruction at a given address.
24293
24294 @end table
24295
24296 @node ARM
24297 @subsection ARM
24298
24299 @value{GDBN} provides the following ARM-specific commands:
24300
24301 @table @code
24302 @item set arm disassembler
24303 @kindex set arm
24304 This commands selects from a list of disassembly styles. The
24305 @code{"std"} style is the standard style.
24306
24307 @item show arm disassembler
24308 @kindex show arm
24309 Show the current disassembly style.
24310
24311 @item set arm apcs32
24312 @cindex ARM 32-bit mode
24313 This command toggles ARM operation mode between 32-bit and 26-bit.
24314
24315 @item show arm apcs32
24316 Display the current usage of the ARM 32-bit mode.
24317
24318 @item set arm fpu @var{fputype}
24319 This command sets the ARM floating-point unit (FPU) type. The
24320 argument @var{fputype} can be one of these:
24321
24322 @table @code
24323 @item auto
24324 Determine the FPU type by querying the OS ABI.
24325 @item softfpa
24326 Software FPU, with mixed-endian doubles on little-endian ARM
24327 processors.
24328 @item fpa
24329 GCC-compiled FPA co-processor.
24330 @item softvfp
24331 Software FPU with pure-endian doubles.
24332 @item vfp
24333 VFP co-processor.
24334 @end table
24335
24336 @item show arm fpu
24337 Show the current type of the FPU.
24338
24339 @item set arm abi
24340 This command forces @value{GDBN} to use the specified ABI.
24341
24342 @item show arm abi
24343 Show the currently used ABI.
24344
24345 @item set arm fallback-mode (arm|thumb|auto)
24346 @value{GDBN} uses the symbol table, when available, to determine
24347 whether instructions are ARM or Thumb. This command controls
24348 @value{GDBN}'s default behavior when the symbol table is not
24349 available. The default is @samp{auto}, which causes @value{GDBN} to
24350 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24351 register).
24352
24353 @item show arm fallback-mode
24354 Show the current fallback instruction mode.
24355
24356 @item set arm force-mode (arm|thumb|auto)
24357 This command overrides use of the symbol table to determine whether
24358 instructions are ARM or Thumb. The default is @samp{auto}, which
24359 causes @value{GDBN} to use the symbol table and then the setting
24360 of @samp{set arm fallback-mode}.
24361
24362 @item show arm force-mode
24363 Show the current forced instruction mode.
24364
24365 @item set debug arm
24366 Toggle whether to display ARM-specific debugging messages from the ARM
24367 target support subsystem.
24368
24369 @item show debug arm
24370 Show whether ARM-specific debugging messages are enabled.
24371 @end table
24372
24373 @table @code
24374 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24375 The @value{GDBN} ARM simulator accepts the following optional arguments.
24376
24377 @table @code
24378 @item --swi-support=@var{type}
24379 Tell the simulator which SWI interfaces to support. The argument
24380 @var{type} may be a comma separated list of the following values.
24381 The default value is @code{all}.
24382
24383 @table @code
24384 @item none
24385 @item demon
24386 @item angel
24387 @item redboot
24388 @item all
24389 @end table
24390 @end table
24391 @end table
24392
24393 @node M68K
24394 @subsection M68k
24395
24396 The Motorola m68k configuration includes ColdFire support.
24397
24398 @node MicroBlaze
24399 @subsection MicroBlaze
24400 @cindex Xilinx MicroBlaze
24401 @cindex XMD, Xilinx Microprocessor Debugger
24402
24403 The MicroBlaze is a soft-core processor supported on various Xilinx
24404 FPGAs, such as Spartan or Virtex series. Boards with these processors
24405 usually have JTAG ports which connect to a host system running the Xilinx
24406 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24407 This host system is used to download the configuration bitstream to
24408 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24409 communicates with the target board using the JTAG interface and
24410 presents a @code{gdbserver} interface to the board. By default
24411 @code{xmd} uses port @code{1234}. (While it is possible to change
24412 this default port, it requires the use of undocumented @code{xmd}
24413 commands. Contact Xilinx support if you need to do this.)
24414
24415 Use these GDB commands to connect to the MicroBlaze target processor.
24416
24417 @table @code
24418 @item target remote :1234
24419 Use this command to connect to the target if you are running @value{GDBN}
24420 on the same system as @code{xmd}.
24421
24422 @item target remote @var{xmd-host}:1234
24423 Use this command to connect to the target if it is connected to @code{xmd}
24424 running on a different system named @var{xmd-host}.
24425
24426 @item load
24427 Use this command to download a program to the MicroBlaze target.
24428
24429 @item set debug microblaze @var{n}
24430 Enable MicroBlaze-specific debugging messages if non-zero.
24431
24432 @item show debug microblaze @var{n}
24433 Show MicroBlaze-specific debugging level.
24434 @end table
24435
24436 @node MIPS Embedded
24437 @subsection @acronym{MIPS} Embedded
24438
24439 @noindent
24440 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24441
24442 @table @code
24443 @item set mipsfpu double
24444 @itemx set mipsfpu single
24445 @itemx set mipsfpu none
24446 @itemx set mipsfpu auto
24447 @itemx show mipsfpu
24448 @kindex set mipsfpu
24449 @kindex show mipsfpu
24450 @cindex @acronym{MIPS} remote floating point
24451 @cindex floating point, @acronym{MIPS} remote
24452 If your target board does not support the @acronym{MIPS} floating point
24453 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24454 need this, you may wish to put the command in your @value{GDBN} init
24455 file). This tells @value{GDBN} how to find the return value of
24456 functions which return floating point values. It also allows
24457 @value{GDBN} to avoid saving the floating point registers when calling
24458 functions on the board. If you are using a floating point coprocessor
24459 with only single precision floating point support, as on the @sc{r4650}
24460 processor, use the command @samp{set mipsfpu single}. The default
24461 double precision floating point coprocessor may be selected using
24462 @samp{set mipsfpu double}.
24463
24464 In previous versions the only choices were double precision or no
24465 floating point, so @samp{set mipsfpu on} will select double precision
24466 and @samp{set mipsfpu off} will select no floating point.
24467
24468 As usual, you can inquire about the @code{mipsfpu} variable with
24469 @samp{show mipsfpu}.
24470 @end table
24471
24472 @node OpenRISC 1000
24473 @subsection OpenRISC 1000
24474 @cindex OpenRISC 1000
24475
24476 @noindent
24477 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24478 mainly provided as a soft-core which can run on Xilinx, Altera and other
24479 FPGA's.
24480
24481 @value{GDBN} for OpenRISC supports the below commands when connecting to
24482 a target:
24483
24484 @table @code
24485
24486 @kindex target sim
24487 @item target sim
24488
24489 Runs the builtin CPU simulator which can run very basic
24490 programs but does not support most hardware functions like MMU.
24491 For more complex use cases the user is advised to run an external
24492 target, and connect using @samp{target remote}.
24493
24494 Example: @code{target sim}
24495
24496 @item set debug or1k
24497 Toggle whether to display OpenRISC-specific debugging messages from the
24498 OpenRISC target support subsystem.
24499
24500 @item show debug or1k
24501 Show whether OpenRISC-specific debugging messages are enabled.
24502 @end table
24503
24504 @node PowerPC Embedded
24505 @subsection PowerPC Embedded
24506
24507 @cindex DVC register
24508 @value{GDBN} supports using the DVC (Data Value Compare) register to
24509 implement in hardware simple hardware watchpoint conditions of the form:
24510
24511 @smallexample
24512 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24513 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24514 @end smallexample
24515
24516 The DVC register will be automatically used when @value{GDBN} detects
24517 such pattern in a condition expression, and the created watchpoint uses one
24518 debug register (either the @code{exact-watchpoints} option is on and the
24519 variable is scalar, or the variable has a length of one byte). This feature
24520 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24521 or newer.
24522
24523 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24524 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24525 in which case watchpoints using only one debug register are created when
24526 watching variables of scalar types.
24527
24528 You can create an artificial array to watch an arbitrary memory
24529 region using one of the following commands (@pxref{Expressions}):
24530
24531 @smallexample
24532 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24533 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24534 @end smallexample
24535
24536 PowerPC embedded processors support masked watchpoints. See the discussion
24537 about the @code{mask} argument in @ref{Set Watchpoints}.
24538
24539 @cindex ranged breakpoint
24540 PowerPC embedded processors support hardware accelerated
24541 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24542 the inferior whenever it executes an instruction at any address within
24543 the range it specifies. To set a ranged breakpoint in @value{GDBN},
24544 use the @code{break-range} command.
24545
24546 @value{GDBN} provides the following PowerPC-specific commands:
24547
24548 @table @code
24549 @kindex break-range
24550 @item break-range @var{start-location}, @var{end-location}
24551 Set a breakpoint for an address range given by
24552 @var{start-location} and @var{end-location}, which can specify a function name,
24553 a line number, an offset of lines from the current line or from the start
24554 location, or an address of an instruction (see @ref{Specify Location},
24555 for a list of all the possible ways to specify a @var{location}.)
24556 The breakpoint will stop execution of the inferior whenever it
24557 executes an instruction at any address within the specified range,
24558 (including @var{start-location} and @var{end-location}.)
24559
24560 @kindex set powerpc
24561 @item set powerpc soft-float
24562 @itemx show powerpc soft-float
24563 Force @value{GDBN} to use (or not use) a software floating point calling
24564 convention. By default, @value{GDBN} selects the calling convention based
24565 on the selected architecture and the provided executable file.
24566
24567 @item set powerpc vector-abi
24568 @itemx show powerpc vector-abi
24569 Force @value{GDBN} to use the specified calling convention for vector
24570 arguments and return values. The valid options are @samp{auto};
24571 @samp{generic}, to avoid vector registers even if they are present;
24572 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24573 registers. By default, @value{GDBN} selects the calling convention
24574 based on the selected architecture and the provided executable file.
24575
24576 @item set powerpc exact-watchpoints
24577 @itemx show powerpc exact-watchpoints
24578 Allow @value{GDBN} to use only one debug register when watching a variable
24579 of scalar type, thus assuming that the variable is accessed through the
24580 address of its first byte.
24581
24582 @end table
24583
24584 @node AVR
24585 @subsection Atmel AVR
24586 @cindex AVR
24587
24588 When configured for debugging the Atmel AVR, @value{GDBN} supports the
24589 following AVR-specific commands:
24590
24591 @table @code
24592 @item info io_registers
24593 @kindex info io_registers@r{, AVR}
24594 @cindex I/O registers (Atmel AVR)
24595 This command displays information about the AVR I/O registers. For
24596 each register, @value{GDBN} prints its number and value.
24597 @end table
24598
24599 @node CRIS
24600 @subsection CRIS
24601 @cindex CRIS
24602
24603 When configured for debugging CRIS, @value{GDBN} provides the
24604 following CRIS-specific commands:
24605
24606 @table @code
24607 @item set cris-version @var{ver}
24608 @cindex CRIS version
24609 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24610 The CRIS version affects register names and sizes. This command is useful in
24611 case autodetection of the CRIS version fails.
24612
24613 @item show cris-version
24614 Show the current CRIS version.
24615
24616 @item set cris-dwarf2-cfi
24617 @cindex DWARF-2 CFI and CRIS
24618 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24619 Change to @samp{off} when using @code{gcc-cris} whose version is below
24620 @code{R59}.
24621
24622 @item show cris-dwarf2-cfi
24623 Show the current state of using DWARF-2 CFI.
24624
24625 @item set cris-mode @var{mode}
24626 @cindex CRIS mode
24627 Set the current CRIS mode to @var{mode}. It should only be changed when
24628 debugging in guru mode, in which case it should be set to
24629 @samp{guru} (the default is @samp{normal}).
24630
24631 @item show cris-mode
24632 Show the current CRIS mode.
24633 @end table
24634
24635 @node Super-H
24636 @subsection Renesas Super-H
24637 @cindex Super-H
24638
24639 For the Renesas Super-H processor, @value{GDBN} provides these
24640 commands:
24641
24642 @table @code
24643 @item set sh calling-convention @var{convention}
24644 @kindex set sh calling-convention
24645 Set the calling-convention used when calling functions from @value{GDBN}.
24646 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24647 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24648 convention. If the DWARF-2 information of the called function specifies
24649 that the function follows the Renesas calling convention, the function
24650 is called using the Renesas calling convention. If the calling convention
24651 is set to @samp{renesas}, the Renesas calling convention is always used,
24652 regardless of the DWARF-2 information. This can be used to override the
24653 default of @samp{gcc} if debug information is missing, or the compiler
24654 does not emit the DWARF-2 calling convention entry for a function.
24655
24656 @item show sh calling-convention
24657 @kindex show sh calling-convention
24658 Show the current calling convention setting.
24659
24660 @end table
24661
24662
24663 @node Architectures
24664 @section Architectures
24665
24666 This section describes characteristics of architectures that affect
24667 all uses of @value{GDBN} with the architecture, both native and cross.
24668
24669 @menu
24670 * AArch64::
24671 * i386::
24672 * Alpha::
24673 * MIPS::
24674 * HPPA:: HP PA architecture
24675 * PowerPC::
24676 * Nios II::
24677 * Sparc64::
24678 * S12Z::
24679 @end menu
24680
24681 @node AArch64
24682 @subsection AArch64
24683 @cindex AArch64 support
24684
24685 When @value{GDBN} is debugging the AArch64 architecture, it provides the
24686 following special commands:
24687
24688 @table @code
24689 @item set debug aarch64
24690 @kindex set debug aarch64
24691 This command determines whether AArch64 architecture-specific debugging
24692 messages are to be displayed.
24693
24694 @item show debug aarch64
24695 Show whether AArch64 debugging messages are displayed.
24696
24697 @end table
24698
24699 @subsubsection AArch64 SVE.
24700 @cindex AArch64 SVE.
24701
24702 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24703 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24704 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24705 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24706 @code{$vg} will be provided. This is the vector granule for the current thread
24707 and represents the number of 64-bit chunks in an SVE @code{z} register.
24708
24709 If the vector length changes, then the @code{$vg} register will be updated,
24710 but the lengths of the @code{z} and @code{p} registers will not change. This
24711 is a known limitation of @value{GDBN} and does not affect the execution of the
24712 target process.
24713
24714 @subsubsection AArch64 Pointer Authentication.
24715 @cindex AArch64 Pointer Authentication.
24716
24717 When @value{GDBN} is debugging the AArch64 architecture, and the program is
24718 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
24719 register @code{$lr} is pointing to an PAC function its value will be masked.
24720 When GDB prints a backtrace, any addresses that required unmasking will be
24721 postfixed with the marker [PAC]. When using the MI, this is printed as part
24722 of the @code{addr_flags} field.
24723
24724 @node i386
24725 @subsection x86 Architecture-specific Issues
24726
24727 @table @code
24728 @item set struct-convention @var{mode}
24729 @kindex set struct-convention
24730 @cindex struct return convention
24731 @cindex struct/union returned in registers
24732 Set the convention used by the inferior to return @code{struct}s and
24733 @code{union}s from functions to @var{mode}. Possible values of
24734 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24735 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24736 are returned on the stack, while @code{"reg"} means that a
24737 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24738 be returned in a register.
24739
24740 @item show struct-convention
24741 @kindex show struct-convention
24742 Show the current setting of the convention to return @code{struct}s
24743 from functions.
24744 @end table
24745
24746
24747 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24748 @cindex Intel Memory Protection Extensions (MPX).
24749
24750 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24751 @footnote{The register named with capital letters represent the architecture
24752 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24753 which are the lower bound and upper bound. Bounds are effective addresses or
24754 memory locations. The upper bounds are architecturally represented in 1's
24755 complement form. A bound having lower bound = 0, and upper bound = 0
24756 (1's complement of all bits set) will allow access to the entire address space.
24757
24758 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24759 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24760 display the upper bound performing the complement of one operation on the
24761 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24762 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24763 can also be noted that the upper bounds are inclusive.
24764
24765 As an example, assume that the register BND0 holds bounds for a pointer having
24766 access allowed for the range between 0x32 and 0x71. The values present on
24767 bnd0raw and bnd registers are presented as follows:
24768
24769 @smallexample
24770 bnd0raw = @{0x32, 0xffffffff8e@}
24771 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24772 @end smallexample
24773
24774 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24775 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24776 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24777 Python, the display includes the memory size, in bits, accessible to
24778 the pointer.
24779
24780 Bounds can also be stored in bounds tables, which are stored in
24781 application memory. These tables store bounds for pointers by specifying
24782 the bounds pointer's value along with its bounds. Evaluating and changing
24783 bounds located in bound tables is therefore interesting while investigating
24784 bugs on MPX context. @value{GDBN} provides commands for this purpose:
24785
24786 @table @code
24787 @item show mpx bound @var{pointer}
24788 @kindex show mpx bound
24789 Display bounds of the given @var{pointer}.
24790
24791 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24792 @kindex set mpx bound
24793 Set the bounds of a pointer in the bound table.
24794 This command takes three parameters: @var{pointer} is the pointers
24795 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24796 for lower and upper bounds respectively.
24797 @end table
24798
24799 When you call an inferior function on an Intel MPX enabled program,
24800 GDB sets the inferior's bound registers to the init (disabled) state
24801 before calling the function. As a consequence, bounds checks for the
24802 pointer arguments passed to the function will always pass.
24803
24804 This is necessary because when you call an inferior function, the
24805 program is usually in the middle of the execution of other function.
24806 Since at that point bound registers are in an arbitrary state, not
24807 clearing them would lead to random bound violations in the called
24808 function.
24809
24810 You can still examine the influence of the bound registers on the
24811 execution of the called function by stopping the execution of the
24812 called function at its prologue, setting bound registers, and
24813 continuing the execution. For example:
24814
24815 @smallexample
24816 $ break *upper
24817 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24818 $ print upper (a, b, c, d, 1)
24819 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24820 $ print $bnd0
24821 @{lbound = 0x0, ubound = ffffffff@} : size -1
24822 @end smallexample
24823
24824 At this last step the value of bnd0 can be changed for investigation of bound
24825 violations caused along the execution of the call. In order to know how to
24826 set the bound registers or bound table for the call consult the ABI.
24827
24828 @node Alpha
24829 @subsection Alpha
24830
24831 See the following section.
24832
24833 @node MIPS
24834 @subsection @acronym{MIPS}
24835
24836 @cindex stack on Alpha
24837 @cindex stack on @acronym{MIPS}
24838 @cindex Alpha stack
24839 @cindex @acronym{MIPS} stack
24840 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
24841 sometimes requires @value{GDBN} to search backward in the object code to
24842 find the beginning of a function.
24843
24844 @cindex response time, @acronym{MIPS} debugging
24845 To improve response time (especially for embedded applications, where
24846 @value{GDBN} may be restricted to a slow serial line for this search)
24847 you may want to limit the size of this search, using one of these
24848 commands:
24849
24850 @table @code
24851 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
24852 @item set heuristic-fence-post @var{limit}
24853 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24854 search for the beginning of a function. A value of @var{0} (the
24855 default) means there is no limit. However, except for @var{0}, the
24856 larger the limit the more bytes @code{heuristic-fence-post} must search
24857 and therefore the longer it takes to run. You should only need to use
24858 this command when debugging a stripped executable.
24859
24860 @item show heuristic-fence-post
24861 Display the current limit.
24862 @end table
24863
24864 @noindent
24865 These commands are available @emph{only} when @value{GDBN} is configured
24866 for debugging programs on Alpha or @acronym{MIPS} processors.
24867
24868 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
24869 programs:
24870
24871 @table @code
24872 @item set mips abi @var{arg}
24873 @kindex set mips abi
24874 @cindex set ABI for @acronym{MIPS}
24875 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
24876 values of @var{arg} are:
24877
24878 @table @samp
24879 @item auto
24880 The default ABI associated with the current binary (this is the
24881 default).
24882 @item o32
24883 @item o64
24884 @item n32
24885 @item n64
24886 @item eabi32
24887 @item eabi64
24888 @end table
24889
24890 @item show mips abi
24891 @kindex show mips abi
24892 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
24893
24894 @item set mips compression @var{arg}
24895 @kindex set mips compression
24896 @cindex code compression, @acronym{MIPS}
24897 Tell @value{GDBN} which @acronym{MIPS} compressed
24898 @acronym{ISA, Instruction Set Architecture} encoding is used by the
24899 inferior. @value{GDBN} uses this for code disassembly and other
24900 internal interpretation purposes. This setting is only referred to
24901 when no executable has been associated with the debugging session or
24902 the executable does not provide information about the encoding it uses.
24903 Otherwise this setting is automatically updated from information
24904 provided by the executable.
24905
24906 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
24907 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
24908 executables containing @acronym{MIPS16} code frequently are not
24909 identified as such.
24910
24911 This setting is ``sticky''; that is, it retains its value across
24912 debugging sessions until reset either explicitly with this command or
24913 implicitly from an executable.
24914
24915 The compiler and/or assembler typically add symbol table annotations to
24916 identify functions compiled for the @acronym{MIPS16} or
24917 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
24918 are present, @value{GDBN} uses them in preference to the global
24919 compressed @acronym{ISA} encoding setting.
24920
24921 @item show mips compression
24922 @kindex show mips compression
24923 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
24924 @value{GDBN} to debug the inferior.
24925
24926 @item set mipsfpu
24927 @itemx show mipsfpu
24928 @xref{MIPS Embedded, set mipsfpu}.
24929
24930 @item set mips mask-address @var{arg}
24931 @kindex set mips mask-address
24932 @cindex @acronym{MIPS} addresses, masking
24933 This command determines whether the most-significant 32 bits of 64-bit
24934 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
24935 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
24936 setting, which lets @value{GDBN} determine the correct value.
24937
24938 @item show mips mask-address
24939 @kindex show mips mask-address
24940 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
24941 not.
24942
24943 @item set remote-mips64-transfers-32bit-regs
24944 @kindex set remote-mips64-transfers-32bit-regs
24945 This command controls compatibility with 64-bit @acronym{MIPS} targets that
24946 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
24947 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
24948 and 64 bits for other registers, set this option to @samp{on}.
24949
24950 @item show remote-mips64-transfers-32bit-regs
24951 @kindex show remote-mips64-transfers-32bit-regs
24952 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
24953
24954 @item set debug mips
24955 @kindex set debug mips
24956 This command turns on and off debugging messages for the @acronym{MIPS}-specific
24957 target code in @value{GDBN}.
24958
24959 @item show debug mips
24960 @kindex show debug mips
24961 Show the current setting of @acronym{MIPS} debugging messages.
24962 @end table
24963
24964
24965 @node HPPA
24966 @subsection HPPA
24967 @cindex HPPA support
24968
24969 When @value{GDBN} is debugging the HP PA architecture, it provides the
24970 following special commands:
24971
24972 @table @code
24973 @item set debug hppa
24974 @kindex set debug hppa
24975 This command determines whether HPPA architecture-specific debugging
24976 messages are to be displayed.
24977
24978 @item show debug hppa
24979 Show whether HPPA debugging messages are displayed.
24980
24981 @item maint print unwind @var{address}
24982 @kindex maint print unwind@r{, HPPA}
24983 This command displays the contents of the unwind table entry at the
24984 given @var{address}.
24985
24986 @end table
24987
24988
24989 @node PowerPC
24990 @subsection PowerPC
24991 @cindex PowerPC architecture
24992
24993 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
24994 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
24995 numbers stored in the floating point registers. These values must be stored
24996 in two consecutive registers, always starting at an even register like
24997 @code{f0} or @code{f2}.
24998
24999 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25000 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25001 @code{f2} and @code{f3} for @code{$dl1} and so on.
25002
25003 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25004 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25005
25006 @node Nios II
25007 @subsection Nios II
25008 @cindex Nios II architecture
25009
25010 When @value{GDBN} is debugging the Nios II architecture,
25011 it provides the following special commands:
25012
25013 @table @code
25014
25015 @item set debug nios2
25016 @kindex set debug nios2
25017 This command turns on and off debugging messages for the Nios II
25018 target code in @value{GDBN}.
25019
25020 @item show debug nios2
25021 @kindex show debug nios2
25022 Show the current setting of Nios II debugging messages.
25023 @end table
25024
25025 @node Sparc64
25026 @subsection Sparc64
25027 @cindex Sparc64 support
25028 @cindex Application Data Integrity
25029 @subsubsection ADI Support
25030
25031 The M7 processor supports an Application Data Integrity (ADI) feature that
25032 detects invalid data accesses. When software allocates memory and enables
25033 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25034 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25035 the 4-bit version in every cacheline of that data. Hardware saves the latter
25036 in spare bits in the cache and memory hierarchy. On each load and store,
25037 the processor compares the upper 4 VA (virtual address) bits to the
25038 cacheline's version. If there is a mismatch, the processor generates a
25039 version mismatch trap which can be either precise or disrupting. The trap
25040 is an error condition which the kernel delivers to the process as a SIGSEGV
25041 signal.
25042
25043 Note that only 64-bit applications can use ADI and need to be built with
25044 ADI-enabled.
25045
25046 Values of the ADI version tags, which are in granularity of a
25047 cacheline (64 bytes), can be viewed or modified.
25048
25049
25050 @table @code
25051 @kindex adi examine
25052 @item adi (examine | x) [ / @var{n} ] @var{addr}
25053
25054 The @code{adi examine} command displays the value of one ADI version tag per
25055 cacheline.
25056
25057 @var{n} is a decimal integer specifying the number in bytes; the default
25058 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25059 block size, to display.
25060
25061 @var{addr} is the address in user address space where you want @value{GDBN}
25062 to begin displaying the ADI version tags.
25063
25064 Below is an example of displaying ADI versions of variable "shmaddr".
25065
25066 @smallexample
25067 (@value{GDBP}) adi x/100 shmaddr
25068 0xfff800010002c000: 0 0
25069 @end smallexample
25070
25071 @kindex adi assign
25072 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25073
25074 The @code{adi assign} command is used to assign new ADI version tag
25075 to an address.
25076
25077 @var{n} is a decimal integer specifying the number in bytes;
25078 the default is 1. It specifies how much ADI version information, at the
25079 ratio of 1:ADI block size, to modify.
25080
25081 @var{addr} is the address in user address space where you want @value{GDBN}
25082 to begin modifying the ADI version tags.
25083
25084 @var{tag} is the new ADI version tag.
25085
25086 For example, do the following to modify then verify ADI versions of
25087 variable "shmaddr":
25088
25089 @smallexample
25090 (@value{GDBP}) adi a/100 shmaddr = 7
25091 (@value{GDBP}) adi x/100 shmaddr
25092 0xfff800010002c000: 7 7
25093 @end smallexample
25094
25095 @end table
25096
25097 @node S12Z
25098 @subsection S12Z
25099 @cindex S12Z support
25100
25101 When @value{GDBN} is debugging the S12Z architecture,
25102 it provides the following special command:
25103
25104 @table @code
25105 @item maint info bdccsr
25106 @kindex maint info bdccsr@r{, S12Z}
25107 This command displays the current value of the microprocessor's
25108 BDCCSR register.
25109 @end table
25110
25111
25112 @node Controlling GDB
25113 @chapter Controlling @value{GDBN}
25114
25115 You can alter the way @value{GDBN} interacts with you by using the
25116 @code{set} command. For commands controlling how @value{GDBN} displays
25117 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25118 described here.
25119
25120 @menu
25121 * Prompt:: Prompt
25122 * Editing:: Command editing
25123 * Command History:: Command history
25124 * Screen Size:: Screen size
25125 * Output Styling:: Output styling
25126 * Numbers:: Numbers
25127 * ABI:: Configuring the current ABI
25128 * Auto-loading:: Automatically loading associated files
25129 * Messages/Warnings:: Optional warnings and messages
25130 * Debugging Output:: Optional messages about internal happenings
25131 * Other Misc Settings:: Other Miscellaneous Settings
25132 @end menu
25133
25134 @node Prompt
25135 @section Prompt
25136
25137 @cindex prompt
25138
25139 @value{GDBN} indicates its readiness to read a command by printing a string
25140 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25141 can change the prompt string with the @code{set prompt} command. For
25142 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25143 the prompt in one of the @value{GDBN} sessions so that you can always tell
25144 which one you are talking to.
25145
25146 @emph{Note:} @code{set prompt} does not add a space for you after the
25147 prompt you set. This allows you to set a prompt which ends in a space
25148 or a prompt that does not.
25149
25150 @table @code
25151 @kindex set prompt
25152 @item set prompt @var{newprompt}
25153 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25154
25155 @kindex show prompt
25156 @item show prompt
25157 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25158 @end table
25159
25160 Versions of @value{GDBN} that ship with Python scripting enabled have
25161 prompt extensions. The commands for interacting with these extensions
25162 are:
25163
25164 @table @code
25165 @kindex set extended-prompt
25166 @item set extended-prompt @var{prompt}
25167 Set an extended prompt that allows for substitutions.
25168 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25169 substitution. Any escape sequences specified as part of the prompt
25170 string are replaced with the corresponding strings each time the prompt
25171 is displayed.
25172
25173 For example:
25174
25175 @smallexample
25176 set extended-prompt Current working directory: \w (gdb)
25177 @end smallexample
25178
25179 Note that when an extended-prompt is set, it takes control of the
25180 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25181
25182 @kindex show extended-prompt
25183 @item show extended-prompt
25184 Prints the extended prompt. Any escape sequences specified as part of
25185 the prompt string with @code{set extended-prompt}, are replaced with the
25186 corresponding strings each time the prompt is displayed.
25187 @end table
25188
25189 @node Editing
25190 @section Command Editing
25191 @cindex readline
25192 @cindex command line editing
25193
25194 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25195 @sc{gnu} library provides consistent behavior for programs which provide a
25196 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25197 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25198 substitution, and a storage and recall of command history across
25199 debugging sessions.
25200
25201 You may control the behavior of command line editing in @value{GDBN} with the
25202 command @code{set}.
25203
25204 @table @code
25205 @kindex set editing
25206 @cindex editing
25207 @item set editing
25208 @itemx set editing on
25209 Enable command line editing (enabled by default).
25210
25211 @item set editing off
25212 Disable command line editing.
25213
25214 @kindex show editing
25215 @item show editing
25216 Show whether command line editing is enabled.
25217 @end table
25218
25219 @ifset SYSTEM_READLINE
25220 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25221 @end ifset
25222 @ifclear SYSTEM_READLINE
25223 @xref{Command Line Editing},
25224 @end ifclear
25225 for more details about the Readline
25226 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25227 encouraged to read that chapter.
25228
25229 @cindex Readline application name
25230 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25231 is useful for conditions in @file{.inputrc}.
25232
25233 @cindex operate-and-get-next
25234 @value{GDBN} defines a bindable Readline command,
25235 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25236 This command accepts the current line for execution and fetches the
25237 next line relative to the current line from the history for editing.
25238 Any argument is ignored.
25239
25240 @node Command History
25241 @section Command History
25242 @cindex command history
25243
25244 @value{GDBN} can keep track of the commands you type during your
25245 debugging sessions, so that you can be certain of precisely what
25246 happened. Use these commands to manage the @value{GDBN} command
25247 history facility.
25248
25249 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25250 package, to provide the history facility.
25251 @ifset SYSTEM_READLINE
25252 @xref{Using History Interactively, , , history, GNU History Library},
25253 @end ifset
25254 @ifclear SYSTEM_READLINE
25255 @xref{Using History Interactively},
25256 @end ifclear
25257 for the detailed description of the History library.
25258
25259 To issue a command to @value{GDBN} without affecting certain aspects of
25260 the state which is seen by users, prefix it with @samp{server }
25261 (@pxref{Server Prefix}). This
25262 means that this command will not affect the command history, nor will it
25263 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25264 pressed on a line by itself.
25265
25266 @cindex @code{server}, command prefix
25267 The server prefix does not affect the recording of values into the value
25268 history; to print a value without recording it into the value history,
25269 use the @code{output} command instead of the @code{print} command.
25270
25271 Here is the description of @value{GDBN} commands related to command
25272 history.
25273
25274 @table @code
25275 @cindex history substitution
25276 @cindex history file
25277 @kindex set history filename
25278 @cindex @env{GDBHISTFILE}, environment variable
25279 @item set history filename @var{fname}
25280 Set the name of the @value{GDBN} command history file to @var{fname}.
25281 This is the file where @value{GDBN} reads an initial command history
25282 list, and where it writes the command history from this session when it
25283 exits. You can access this list through history expansion or through
25284 the history command editing characters listed below. This file defaults
25285 to the value of the environment variable @code{GDBHISTFILE}, or to
25286 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25287 is not set.
25288
25289 @cindex save command history
25290 @kindex set history save
25291 @item set history save
25292 @itemx set history save on
25293 Record command history in a file, whose name may be specified with the
25294 @code{set history filename} command. By default, this option is disabled.
25295
25296 @item set history save off
25297 Stop recording command history in a file.
25298
25299 @cindex history size
25300 @kindex set history size
25301 @cindex @env{GDBHISTSIZE}, environment variable
25302 @item set history size @var{size}
25303 @itemx set history size unlimited
25304 Set the number of commands which @value{GDBN} keeps in its history list.
25305 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25306 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25307 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25308 either a negative number or the empty string, then the number of commands
25309 @value{GDBN} keeps in the history list is unlimited.
25310
25311 @cindex remove duplicate history
25312 @kindex set history remove-duplicates
25313 @item set history remove-duplicates @var{count}
25314 @itemx set history remove-duplicates unlimited
25315 Control the removal of duplicate history entries in the command history list.
25316 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25317 history entries and remove the first entry that is a duplicate of the current
25318 entry being added to the command history list. If @var{count} is
25319 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25320 removal of duplicate history entries is disabled.
25321
25322 Only history entries added during the current session are considered for
25323 removal. This option is set to 0 by default.
25324
25325 @end table
25326
25327 History expansion assigns special meaning to the character @kbd{!}.
25328 @ifset SYSTEM_READLINE
25329 @xref{Event Designators, , , history, GNU History Library},
25330 @end ifset
25331 @ifclear SYSTEM_READLINE
25332 @xref{Event Designators},
25333 @end ifclear
25334 for more details.
25335
25336 @cindex history expansion, turn on/off
25337 Since @kbd{!} is also the logical not operator in C, history expansion
25338 is off by default. If you decide to enable history expansion with the
25339 @code{set history expansion on} command, you may sometimes need to
25340 follow @kbd{!} (when it is used as logical not, in an expression) with
25341 a space or a tab to prevent it from being expanded. The readline
25342 history facilities do not attempt substitution on the strings
25343 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25344
25345 The commands to control history expansion are:
25346
25347 @table @code
25348 @item set history expansion on
25349 @itemx set history expansion
25350 @kindex set history expansion
25351 Enable history expansion. History expansion is off by default.
25352
25353 @item set history expansion off
25354 Disable history expansion.
25355
25356 @c @group
25357 @kindex show history
25358 @item show history
25359 @itemx show history filename
25360 @itemx show history save
25361 @itemx show history size
25362 @itemx show history expansion
25363 These commands display the state of the @value{GDBN} history parameters.
25364 @code{show history} by itself displays all four states.
25365 @c @end group
25366 @end table
25367
25368 @table @code
25369 @kindex show commands
25370 @cindex show last commands
25371 @cindex display command history
25372 @item show commands
25373 Display the last ten commands in the command history.
25374
25375 @item show commands @var{n}
25376 Print ten commands centered on command number @var{n}.
25377
25378 @item show commands +
25379 Print ten commands just after the commands last printed.
25380 @end table
25381
25382 @node Screen Size
25383 @section Screen Size
25384 @cindex size of screen
25385 @cindex screen size
25386 @cindex pagination
25387 @cindex page size
25388 @cindex pauses in output
25389
25390 Certain commands to @value{GDBN} may produce large amounts of
25391 information output to the screen. To help you read all of it,
25392 @value{GDBN} pauses and asks you for input at the end of each page of
25393 output. Type @key{RET} when you want to see one more page of output,
25394 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25395 without paging for the rest of the current command. Also, the screen
25396 width setting determines when to wrap lines of output. Depending on
25397 what is being printed, @value{GDBN} tries to break the line at a
25398 readable place, rather than simply letting it overflow onto the
25399 following line.
25400
25401 Normally @value{GDBN} knows the size of the screen from the terminal
25402 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25403 together with the value of the @code{TERM} environment variable and the
25404 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25405 you can override it with the @code{set height} and @code{set
25406 width} commands:
25407
25408 @table @code
25409 @kindex set height
25410 @kindex set width
25411 @kindex show width
25412 @kindex show height
25413 @item set height @var{lpp}
25414 @itemx set height unlimited
25415 @itemx show height
25416 @itemx set width @var{cpl}
25417 @itemx set width unlimited
25418 @itemx show width
25419 These @code{set} commands specify a screen height of @var{lpp} lines and
25420 a screen width of @var{cpl} characters. The associated @code{show}
25421 commands display the current settings.
25422
25423 If you specify a height of either @code{unlimited} or zero lines,
25424 @value{GDBN} does not pause during output no matter how long the
25425 output is. This is useful if output is to a file or to an editor
25426 buffer.
25427
25428 Likewise, you can specify @samp{set width unlimited} or @samp{set
25429 width 0} to prevent @value{GDBN} from wrapping its output.
25430
25431 @item set pagination on
25432 @itemx set pagination off
25433 @kindex set pagination
25434 Turn the output pagination on or off; the default is on. Turning
25435 pagination off is the alternative to @code{set height unlimited}. Note that
25436 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25437 Options, -batch}) also automatically disables pagination.
25438
25439 @item show pagination
25440 @kindex show pagination
25441 Show the current pagination mode.
25442 @end table
25443
25444 @node Output Styling
25445 @section Output Styling
25446 @cindex styling
25447 @cindex colors
25448
25449 @kindex set style
25450 @kindex show style
25451 @value{GDBN} can style its output on a capable terminal. This is
25452 enabled by default on most systems, but disabled by default when in
25453 batch mode (@pxref{Mode Options}). Various style settings are available;
25454 and styles can also be disabled entirely.
25455
25456 @table @code
25457 @item set style enabled @samp{on|off}
25458 Enable or disable all styling. The default is host-dependent, with
25459 most hosts defaulting to @samp{on}.
25460
25461 @item show style enabled
25462 Show the current state of styling.
25463
25464 @item set style sources @samp{on|off}
25465 Enable or disable source code styling. This affects whether source
25466 code, such as the output of the @code{list} command, is styled. Note
25467 that source styling only works if styling in general is enabled, and
25468 if @value{GDBN} was linked with the GNU Source Highlight library. The
25469 default is @samp{on}.
25470
25471 @item show style sources
25472 Show the current state of source code styling.
25473 @end table
25474
25475 Subcommands of @code{set style} control specific forms of styling.
25476 These subcommands all follow the same pattern: each style-able object
25477 can be styled with a foreground color, a background color, and an
25478 intensity.
25479
25480 For example, the style of file names can be controlled using the
25481 @code{set style filename} group of commands:
25482
25483 @table @code
25484 @item set style filename background @var{color}
25485 Set the background to @var{color}. Valid colors are @samp{none}
25486 (meaning the terminal's default color), @samp{black}, @samp{red},
25487 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25488 and@samp{white}.
25489
25490 @item set style filename foreground @var{color}
25491 Set the foreground to @var{color}. Valid colors are @samp{none}
25492 (meaning the terminal's default color), @samp{black}, @samp{red},
25493 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25494 and@samp{white}.
25495
25496 @item set style filename intensity @var{value}
25497 Set the intensity to @var{value}. Valid intensities are @samp{normal}
25498 (the default), @samp{bold}, and @samp{dim}.
25499 @end table
25500
25501 The @code{show style} command and its subcommands are styling
25502 a style name in their output using its own style.
25503 So, use @command{show style} to see the complete list of styles,
25504 their characteristics and the visual aspect of each style.
25505
25506 The style-able objects are:
25507 @table @code
25508 @item filename
25509 Control the styling of file names. By default, this style's
25510 foreground color is green.
25511
25512 @item function
25513 Control the styling of function names. These are managed with the
25514 @code{set style function} family of commands. By default, this
25515 style's foreground color is yellow.
25516
25517 @item variable
25518 Control the styling of variable names. These are managed with the
25519 @code{set style variable} family of commands. By default, this style's
25520 foreground color is cyan.
25521
25522 @item address
25523 Control the styling of addresses. These are managed with the
25524 @code{set style address} family of commands. By default, this style's
25525 foreground color is blue.
25526
25527 @item title
25528 Control the styling of titles. These are managed with the
25529 @code{set style title} family of commands. By default, this style's
25530 intensity is bold. Commands are using the title style to improve
25531 the readability of large output. For example, the commands
25532 @command{apropos} and @command{help} are using the title style
25533 for the command names.
25534
25535 @item highlight
25536 Control the styling of highlightings. These are managed with the
25537 @code{set style highlight} family of commands. By default, this style's
25538 foreground color is red. Commands are using the highlight style to draw
25539 the user attention to some specific parts of their output. For example,
25540 the command @command{apropos -v REGEXP} uses the highlight style to
25541 mark the documentation parts matching @var{regexp}.
25542
25543 @item tui-border
25544 Control the styling of the TUI border. Note that, unlike other
25545 styling options, only the color of the border can be controlled via
25546 @code{set style}. This was done for compatibility reasons, as TUI
25547 controls to set the border's intensity predated the addition of
25548 general styling to @value{GDBN}. @xref{TUI Configuration}.
25549
25550 @item tui-active-border
25551 Control the styling of the active TUI border; that is, the TUI window
25552 that has the focus.
25553
25554 @end table
25555
25556 @node Numbers
25557 @section Numbers
25558 @cindex number representation
25559 @cindex entering numbers
25560
25561 You can always enter numbers in octal, decimal, or hexadecimal in
25562 @value{GDBN} by the usual conventions: octal numbers begin with
25563 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
25564 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25565 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
25566 10; likewise, the default display for numbers---when no particular
25567 format is specified---is base 10. You can change the default base for
25568 both input and output with the commands described below.
25569
25570 @table @code
25571 @kindex set input-radix
25572 @item set input-radix @var{base}
25573 Set the default base for numeric input. Supported choices
25574 for @var{base} are decimal 8, 10, or 16. The base must itself be
25575 specified either unambiguously or using the current input radix; for
25576 example, any of
25577
25578 @smallexample
25579 set input-radix 012
25580 set input-radix 10.
25581 set input-radix 0xa
25582 @end smallexample
25583
25584 @noindent
25585 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
25586 leaves the input radix unchanged, no matter what it was, since
25587 @samp{10}, being without any leading or trailing signs of its base, is
25588 interpreted in the current radix. Thus, if the current radix is 16,
25589 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25590 change the radix.
25591
25592 @kindex set output-radix
25593 @item set output-radix @var{base}
25594 Set the default base for numeric display. Supported choices
25595 for @var{base} are decimal 8, 10, or 16. The base must itself be
25596 specified either unambiguously or using the current input radix.
25597
25598 @kindex show input-radix
25599 @item show input-radix
25600 Display the current default base for numeric input.
25601
25602 @kindex show output-radix
25603 @item show output-radix
25604 Display the current default base for numeric display.
25605
25606 @item set radix @r{[}@var{base}@r{]}
25607 @itemx show radix
25608 @kindex set radix
25609 @kindex show radix
25610 These commands set and show the default base for both input and output
25611 of numbers. @code{set radix} sets the radix of input and output to
25612 the same base; without an argument, it resets the radix back to its
25613 default value of 10.
25614
25615 @end table
25616
25617 @node ABI
25618 @section Configuring the Current ABI
25619
25620 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25621 application automatically. However, sometimes you need to override its
25622 conclusions. Use these commands to manage @value{GDBN}'s view of the
25623 current ABI.
25624
25625 @cindex OS ABI
25626 @kindex set osabi
25627 @kindex show osabi
25628 @cindex Newlib OS ABI and its influence on the longjmp handling
25629
25630 One @value{GDBN} configuration can debug binaries for multiple operating
25631 system targets, either via remote debugging or native emulation.
25632 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25633 but you can override its conclusion using the @code{set osabi} command.
25634 One example where this is useful is in debugging of binaries which use
25635 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25636 not have the same identifying marks that the standard C library for your
25637 platform provides.
25638
25639 When @value{GDBN} is debugging the AArch64 architecture, it provides a
25640 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25641 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25642 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25643
25644 @table @code
25645 @item show osabi
25646 Show the OS ABI currently in use.
25647
25648 @item set osabi
25649 With no argument, show the list of registered available OS ABI's.
25650
25651 @item set osabi @var{abi}
25652 Set the current OS ABI to @var{abi}.
25653 @end table
25654
25655 @cindex float promotion
25656
25657 Generally, the way that an argument of type @code{float} is passed to a
25658 function depends on whether the function is prototyped. For a prototyped
25659 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25660 according to the architecture's convention for @code{float}. For unprototyped
25661 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25662 @code{double} and then passed.
25663
25664 Unfortunately, some forms of debug information do not reliably indicate whether
25665 a function is prototyped. If @value{GDBN} calls a function that is not marked
25666 as prototyped, it consults @kbd{set coerce-float-to-double}.
25667
25668 @table @code
25669 @kindex set coerce-float-to-double
25670 @item set coerce-float-to-double
25671 @itemx set coerce-float-to-double on
25672 Arguments of type @code{float} will be promoted to @code{double} when passed
25673 to an unprototyped function. This is the default setting.
25674
25675 @item set coerce-float-to-double off
25676 Arguments of type @code{float} will be passed directly to unprototyped
25677 functions.
25678
25679 @kindex show coerce-float-to-double
25680 @item show coerce-float-to-double
25681 Show the current setting of promoting @code{float} to @code{double}.
25682 @end table
25683
25684 @kindex set cp-abi
25685 @kindex show cp-abi
25686 @value{GDBN} needs to know the ABI used for your program's C@t{++}
25687 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25688 used to build your application. @value{GDBN} only fully supports
25689 programs with a single C@t{++} ABI; if your program contains code using
25690 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25691 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25692 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25693 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25694 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25695 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25696 ``auto''.
25697
25698 @table @code
25699 @item show cp-abi
25700 Show the C@t{++} ABI currently in use.
25701
25702 @item set cp-abi
25703 With no argument, show the list of supported C@t{++} ABI's.
25704
25705 @item set cp-abi @var{abi}
25706 @itemx set cp-abi auto
25707 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25708 @end table
25709
25710 @node Auto-loading
25711 @section Automatically loading associated files
25712 @cindex auto-loading
25713
25714 @value{GDBN} sometimes reads files with commands and settings automatically,
25715 without being explicitly told so by the user. We call this feature
25716 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
25717 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
25718 results or introduce security risks (e.g., if the file comes from untrusted
25719 sources).
25720
25721 @menu
25722 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25723 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25724
25725 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25726 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
25727 @end menu
25728
25729 There are various kinds of files @value{GDBN} can automatically load.
25730 In addition to these files, @value{GDBN} supports auto-loading code written
25731 in various extension languages. @xref{Auto-loading extensions}.
25732
25733 Note that loading of these associated files (including the local @file{.gdbinit}
25734 file) requires accordingly configured @code{auto-load safe-path}
25735 (@pxref{Auto-loading safe path}).
25736
25737 For these reasons, @value{GDBN} includes commands and options to let you
25738 control when to auto-load files and which files should be auto-loaded.
25739
25740 @table @code
25741 @anchor{set auto-load off}
25742 @kindex set auto-load off
25743 @item set auto-load off
25744 Globally disable loading of all auto-loaded files.
25745 You may want to use this command with the @samp{-iex} option
25746 (@pxref{Option -init-eval-command}) such as:
25747 @smallexample
25748 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25749 @end smallexample
25750
25751 Be aware that system init file (@pxref{System-wide configuration})
25752 and init files from your home directory (@pxref{Home Directory Init File})
25753 still get read (as they come from generally trusted directories).
25754 To prevent @value{GDBN} from auto-loading even those init files, use the
25755 @option{-nx} option (@pxref{Mode Options}), in addition to
25756 @code{set auto-load no}.
25757
25758 @anchor{show auto-load}
25759 @kindex show auto-load
25760 @item show auto-load
25761 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25762 or disabled.
25763
25764 @smallexample
25765 (gdb) show auto-load
25766 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25767 libthread-db: Auto-loading of inferior specific libthread_db is on.
25768 local-gdbinit: Auto-loading of .gdbinit script from current directory
25769 is on.
25770 python-scripts: Auto-loading of Python scripts is on.
25771 safe-path: List of directories from which it is safe to auto-load files
25772 is $debugdir:$datadir/auto-load.
25773 scripts-directory: List of directories from which to load auto-loaded scripts
25774 is $debugdir:$datadir/auto-load.
25775 @end smallexample
25776
25777 @anchor{info auto-load}
25778 @kindex info auto-load
25779 @item info auto-load
25780 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25781 not.
25782
25783 @smallexample
25784 (gdb) info auto-load
25785 gdb-scripts:
25786 Loaded Script
25787 Yes /home/user/gdb/gdb-gdb.gdb
25788 libthread-db: No auto-loaded libthread-db.
25789 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25790 loaded.
25791 python-scripts:
25792 Loaded Script
25793 Yes /home/user/gdb/gdb-gdb.py
25794 @end smallexample
25795 @end table
25796
25797 These are @value{GDBN} control commands for the auto-loading:
25798
25799 @multitable @columnfractions .5 .5
25800 @item @xref{set auto-load off}.
25801 @tab Disable auto-loading globally.
25802 @item @xref{show auto-load}.
25803 @tab Show setting of all kinds of files.
25804 @item @xref{info auto-load}.
25805 @tab Show state of all kinds of files.
25806 @item @xref{set auto-load gdb-scripts}.
25807 @tab Control for @value{GDBN} command scripts.
25808 @item @xref{show auto-load gdb-scripts}.
25809 @tab Show setting of @value{GDBN} command scripts.
25810 @item @xref{info auto-load gdb-scripts}.
25811 @tab Show state of @value{GDBN} command scripts.
25812 @item @xref{set auto-load python-scripts}.
25813 @tab Control for @value{GDBN} Python scripts.
25814 @item @xref{show auto-load python-scripts}.
25815 @tab Show setting of @value{GDBN} Python scripts.
25816 @item @xref{info auto-load python-scripts}.
25817 @tab Show state of @value{GDBN} Python scripts.
25818 @item @xref{set auto-load guile-scripts}.
25819 @tab Control for @value{GDBN} Guile scripts.
25820 @item @xref{show auto-load guile-scripts}.
25821 @tab Show setting of @value{GDBN} Guile scripts.
25822 @item @xref{info auto-load guile-scripts}.
25823 @tab Show state of @value{GDBN} Guile scripts.
25824 @item @xref{set auto-load scripts-directory}.
25825 @tab Control for @value{GDBN} auto-loaded scripts location.
25826 @item @xref{show auto-load scripts-directory}.
25827 @tab Show @value{GDBN} auto-loaded scripts location.
25828 @item @xref{add-auto-load-scripts-directory}.
25829 @tab Add directory for auto-loaded scripts location list.
25830 @item @xref{set auto-load local-gdbinit}.
25831 @tab Control for init file in the current directory.
25832 @item @xref{show auto-load local-gdbinit}.
25833 @tab Show setting of init file in the current directory.
25834 @item @xref{info auto-load local-gdbinit}.
25835 @tab Show state of init file in the current directory.
25836 @item @xref{set auto-load libthread-db}.
25837 @tab Control for thread debugging library.
25838 @item @xref{show auto-load libthread-db}.
25839 @tab Show setting of thread debugging library.
25840 @item @xref{info auto-load libthread-db}.
25841 @tab Show state of thread debugging library.
25842 @item @xref{set auto-load safe-path}.
25843 @tab Control directories trusted for automatic loading.
25844 @item @xref{show auto-load safe-path}.
25845 @tab Show directories trusted for automatic loading.
25846 @item @xref{add-auto-load-safe-path}.
25847 @tab Add directory trusted for automatic loading.
25848 @end multitable
25849
25850 @node Init File in the Current Directory
25851 @subsection Automatically loading init file in the current directory
25852 @cindex auto-loading init file in the current directory
25853
25854 By default, @value{GDBN} reads and executes the canned sequences of commands
25855 from init file (if any) in the current working directory,
25856 see @ref{Init File in the Current Directory during Startup}.
25857
25858 Note that loading of this local @file{.gdbinit} file also requires accordingly
25859 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25860
25861 @table @code
25862 @anchor{set auto-load local-gdbinit}
25863 @kindex set auto-load local-gdbinit
25864 @item set auto-load local-gdbinit [on|off]
25865 Enable or disable the auto-loading of canned sequences of commands
25866 (@pxref{Sequences}) found in init file in the current directory.
25867
25868 @anchor{show auto-load local-gdbinit}
25869 @kindex show auto-load local-gdbinit
25870 @item show auto-load local-gdbinit
25871 Show whether auto-loading of canned sequences of commands from init file in the
25872 current directory is enabled or disabled.
25873
25874 @anchor{info auto-load local-gdbinit}
25875 @kindex info auto-load local-gdbinit
25876 @item info auto-load local-gdbinit
25877 Print whether canned sequences of commands from init file in the
25878 current directory have been auto-loaded.
25879 @end table
25880
25881 @node libthread_db.so.1 file
25882 @subsection Automatically loading thread debugging library
25883 @cindex auto-loading libthread_db.so.1
25884
25885 This feature is currently present only on @sc{gnu}/Linux native hosts.
25886
25887 @value{GDBN} reads in some cases thread debugging library from places specific
25888 to the inferior (@pxref{set libthread-db-search-path}).
25889
25890 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
25891 without checking this @samp{set auto-load libthread-db} switch as system
25892 libraries have to be trusted in general. In all other cases of
25893 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
25894 auto-load libthread-db} is enabled before trying to open such thread debugging
25895 library.
25896
25897 Note that loading of this debugging library also requires accordingly configured
25898 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25899
25900 @table @code
25901 @anchor{set auto-load libthread-db}
25902 @kindex set auto-load libthread-db
25903 @item set auto-load libthread-db [on|off]
25904 Enable or disable the auto-loading of inferior specific thread debugging library.
25905
25906 @anchor{show auto-load libthread-db}
25907 @kindex show auto-load libthread-db
25908 @item show auto-load libthread-db
25909 Show whether auto-loading of inferior specific thread debugging library is
25910 enabled or disabled.
25911
25912 @anchor{info auto-load libthread-db}
25913 @kindex info auto-load libthread-db
25914 @item info auto-load libthread-db
25915 Print the list of all loaded inferior specific thread debugging libraries and
25916 for each such library print list of inferior @var{pid}s using it.
25917 @end table
25918
25919 @node Auto-loading safe path
25920 @subsection Security restriction for auto-loading
25921 @cindex auto-loading safe-path
25922
25923 As the files of inferior can come from untrusted source (such as submitted by
25924 an application user) @value{GDBN} does not always load any files automatically.
25925 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
25926 directories trusted for loading files not explicitly requested by user.
25927 Each directory can also be a shell wildcard pattern.
25928
25929 If the path is not set properly you will see a warning and the file will not
25930 get loaded:
25931
25932 @smallexample
25933 $ ./gdb -q ./gdb
25934 Reading symbols from /home/user/gdb/gdb...done.
25935 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
25936 declined by your `auto-load safe-path' set
25937 to "$debugdir:$datadir/auto-load".
25938 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
25939 declined by your `auto-load safe-path' set
25940 to "$debugdir:$datadir/auto-load".
25941 @end smallexample
25942
25943 @noindent
25944 To instruct @value{GDBN} to go ahead and use the init files anyway,
25945 invoke @value{GDBN} like this:
25946
25947 @smallexample
25948 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
25949 @end smallexample
25950
25951 The list of trusted directories is controlled by the following commands:
25952
25953 @table @code
25954 @anchor{set auto-load safe-path}
25955 @kindex set auto-load safe-path
25956 @item set auto-load safe-path @r{[}@var{directories}@r{]}
25957 Set the list of directories (and their subdirectories) trusted for automatic
25958 loading and execution of scripts. You can also enter a specific trusted file.
25959 Each directory can also be a shell wildcard pattern; wildcards do not match
25960 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
25961 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
25962 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
25963 its default value as specified during @value{GDBN} compilation.
25964
25965 The list of directories uses path separator (@samp{:} on GNU and Unix
25966 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
25967 to the @env{PATH} environment variable.
25968
25969 @anchor{show auto-load safe-path}
25970 @kindex show auto-load safe-path
25971 @item show auto-load safe-path
25972 Show the list of directories trusted for automatic loading and execution of
25973 scripts.
25974
25975 @anchor{add-auto-load-safe-path}
25976 @kindex add-auto-load-safe-path
25977 @item add-auto-load-safe-path
25978 Add an entry (or list of entries) to the list of directories trusted for
25979 automatic loading and execution of scripts. Multiple entries may be delimited
25980 by the host platform path separator in use.
25981 @end table
25982
25983 This variable defaults to what @code{--with-auto-load-dir} has been configured
25984 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
25985 substitution applies the same as for @ref{set auto-load scripts-directory}.
25986 The default @code{set auto-load safe-path} value can be also overriden by
25987 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
25988
25989 Setting this variable to @file{/} disables this security protection,
25990 corresponding @value{GDBN} configuration option is
25991 @option{--without-auto-load-safe-path}.
25992 This variable is supposed to be set to the system directories writable by the
25993 system superuser only. Users can add their source directories in init files in
25994 their home directories (@pxref{Home Directory Init File}). See also deprecated
25995 init file in the current directory
25996 (@pxref{Init File in the Current Directory during Startup}).
25997
25998 To force @value{GDBN} to load the files it declined to load in the previous
25999 example, you could use one of the following ways:
26000
26001 @table @asis
26002 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26003 Specify this trusted directory (or a file) as additional component of the list.
26004 You have to specify also any existing directories displayed by
26005 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26006
26007 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26008 Specify this directory as in the previous case but just for a single
26009 @value{GDBN} session.
26010
26011 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26012 Disable auto-loading safety for a single @value{GDBN} session.
26013 This assumes all the files you debug during this @value{GDBN} session will come
26014 from trusted sources.
26015
26016 @item @kbd{./configure --without-auto-load-safe-path}
26017 During compilation of @value{GDBN} you may disable any auto-loading safety.
26018 This assumes all the files you will ever debug with this @value{GDBN} come from
26019 trusted sources.
26020 @end table
26021
26022 On the other hand you can also explicitly forbid automatic files loading which
26023 also suppresses any such warning messages:
26024
26025 @table @asis
26026 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26027 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26028
26029 @item @file{~/.gdbinit}: @samp{set auto-load no}
26030 Disable auto-loading globally for the user
26031 (@pxref{Home Directory Init File}). While it is improbable, you could also
26032 use system init file instead (@pxref{System-wide configuration}).
26033 @end table
26034
26035 This setting applies to the file names as entered by user. If no entry matches
26036 @value{GDBN} tries as a last resort to also resolve all the file names into
26037 their canonical form (typically resolving symbolic links) and compare the
26038 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26039 own before starting the comparison so a canonical form of directories is
26040 recommended to be entered.
26041
26042 @node Auto-loading verbose mode
26043 @subsection Displaying files tried for auto-load
26044 @cindex auto-loading verbose mode
26045
26046 For better visibility of all the file locations where you can place scripts to
26047 be auto-loaded with inferior --- or to protect yourself against accidental
26048 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26049 all the files attempted to be loaded. Both existing and non-existing files may
26050 be printed.
26051
26052 For example the list of directories from which it is safe to auto-load files
26053 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26054 may not be too obvious while setting it up.
26055
26056 @smallexample
26057 (gdb) set debug auto-load on
26058 (gdb) file ~/src/t/true
26059 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26060 for objfile "/tmp/true".
26061 auto-load: Updating directories of "/usr:/opt".
26062 auto-load: Using directory "/usr".
26063 auto-load: Using directory "/opt".
26064 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26065 by your `auto-load safe-path' set to "/usr:/opt".
26066 @end smallexample
26067
26068 @table @code
26069 @anchor{set debug auto-load}
26070 @kindex set debug auto-load
26071 @item set debug auto-load [on|off]
26072 Set whether to print the filenames attempted to be auto-loaded.
26073
26074 @anchor{show debug auto-load}
26075 @kindex show debug auto-load
26076 @item show debug auto-load
26077 Show whether printing of the filenames attempted to be auto-loaded is turned
26078 on or off.
26079 @end table
26080
26081 @node Messages/Warnings
26082 @section Optional Warnings and Messages
26083
26084 @cindex verbose operation
26085 @cindex optional warnings
26086 By default, @value{GDBN} is silent about its inner workings. If you are
26087 running on a slow machine, you may want to use the @code{set verbose}
26088 command. This makes @value{GDBN} tell you when it does a lengthy
26089 internal operation, so you will not think it has crashed.
26090
26091 Currently, the messages controlled by @code{set verbose} are those
26092 which announce that the symbol table for a source file is being read;
26093 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26094
26095 @table @code
26096 @kindex set verbose
26097 @item set verbose on
26098 Enables @value{GDBN} output of certain informational messages.
26099
26100 @item set verbose off
26101 Disables @value{GDBN} output of certain informational messages.
26102
26103 @kindex show verbose
26104 @item show verbose
26105 Displays whether @code{set verbose} is on or off.
26106 @end table
26107
26108 By default, if @value{GDBN} encounters bugs in the symbol table of an
26109 object file, it is silent; but if you are debugging a compiler, you may
26110 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26111 Symbol Files}).
26112
26113 @table @code
26114
26115 @kindex set complaints
26116 @item set complaints @var{limit}
26117 Permits @value{GDBN} to output @var{limit} complaints about each type of
26118 unusual symbols before becoming silent about the problem. Set
26119 @var{limit} to zero to suppress all complaints; set it to a large number
26120 to prevent complaints from being suppressed.
26121
26122 @kindex show complaints
26123 @item show complaints
26124 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26125
26126 @end table
26127
26128 @anchor{confirmation requests}
26129 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26130 lot of stupid questions to confirm certain commands. For example, if
26131 you try to run a program which is already running:
26132
26133 @smallexample
26134 (@value{GDBP}) run
26135 The program being debugged has been started already.
26136 Start it from the beginning? (y or n)
26137 @end smallexample
26138
26139 If you are willing to unflinchingly face the consequences of your own
26140 commands, you can disable this ``feature'':
26141
26142 @table @code
26143
26144 @kindex set confirm
26145 @cindex flinching
26146 @cindex confirmation
26147 @cindex stupid questions
26148 @item set confirm off
26149 Disables confirmation requests. Note that running @value{GDBN} with
26150 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26151 automatically disables confirmation requests.
26152
26153 @item set confirm on
26154 Enables confirmation requests (the default).
26155
26156 @kindex show confirm
26157 @item show confirm
26158 Displays state of confirmation requests.
26159
26160 @end table
26161
26162 @cindex command tracing
26163 If you need to debug user-defined commands or sourced files you may find it
26164 useful to enable @dfn{command tracing}. In this mode each command will be
26165 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26166 quantity denoting the call depth of each command.
26167
26168 @table @code
26169 @kindex set trace-commands
26170 @cindex command scripts, debugging
26171 @item set trace-commands on
26172 Enable command tracing.
26173 @item set trace-commands off
26174 Disable command tracing.
26175 @item show trace-commands
26176 Display the current state of command tracing.
26177 @end table
26178
26179 @node Debugging Output
26180 @section Optional Messages about Internal Happenings
26181 @cindex optional debugging messages
26182
26183 @value{GDBN} has commands that enable optional debugging messages from
26184 various @value{GDBN} subsystems; normally these commands are of
26185 interest to @value{GDBN} maintainers, or when reporting a bug. This
26186 section documents those commands.
26187
26188 @table @code
26189 @kindex set exec-done-display
26190 @item set exec-done-display
26191 Turns on or off the notification of asynchronous commands'
26192 completion. When on, @value{GDBN} will print a message when an
26193 asynchronous command finishes its execution. The default is off.
26194 @kindex show exec-done-display
26195 @item show exec-done-display
26196 Displays the current setting of asynchronous command completion
26197 notification.
26198 @kindex set debug
26199 @cindex ARM AArch64
26200 @item set debug aarch64
26201 Turns on or off display of debugging messages related to ARM AArch64.
26202 The default is off.
26203 @kindex show debug
26204 @item show debug aarch64
26205 Displays the current state of displaying debugging messages related to
26206 ARM AArch64.
26207 @cindex gdbarch debugging info
26208 @cindex architecture debugging info
26209 @item set debug arch
26210 Turns on or off display of gdbarch debugging info. The default is off
26211 @item show debug arch
26212 Displays the current state of displaying gdbarch debugging info.
26213 @item set debug aix-solib
26214 @cindex AIX shared library debugging
26215 Control display of debugging messages from the AIX shared library
26216 support module. The default is off.
26217 @item show debug aix-thread
26218 Show the current state of displaying AIX shared library debugging messages.
26219 @item set debug aix-thread
26220 @cindex AIX threads
26221 Display debugging messages about inner workings of the AIX thread
26222 module.
26223 @item show debug aix-thread
26224 Show the current state of AIX thread debugging info display.
26225 @item set debug check-physname
26226 @cindex physname
26227 Check the results of the ``physname'' computation. When reading DWARF
26228 debugging information for C@t{++}, @value{GDBN} attempts to compute
26229 each entity's name. @value{GDBN} can do this computation in two
26230 different ways, depending on exactly what information is present.
26231 When enabled, this setting causes @value{GDBN} to compute the names
26232 both ways and display any discrepancies.
26233 @item show debug check-physname
26234 Show the current state of ``physname'' checking.
26235 @item set debug coff-pe-read
26236 @cindex COFF/PE exported symbols
26237 Control display of debugging messages related to reading of COFF/PE
26238 exported symbols. The default is off.
26239 @item show debug coff-pe-read
26240 Displays the current state of displaying debugging messages related to
26241 reading of COFF/PE exported symbols.
26242 @item set debug dwarf-die
26243 @cindex DWARF DIEs
26244 Dump DWARF DIEs after they are read in.
26245 The value is the number of nesting levels to print.
26246 A value of zero turns off the display.
26247 @item show debug dwarf-die
26248 Show the current state of DWARF DIE debugging.
26249 @item set debug dwarf-line
26250 @cindex DWARF Line Tables
26251 Turns on or off display of debugging messages related to reading
26252 DWARF line tables. The default is 0 (off).
26253 A value of 1 provides basic information.
26254 A value greater than 1 provides more verbose information.
26255 @item show debug dwarf-line
26256 Show the current state of DWARF line table debugging.
26257 @item set debug dwarf-read
26258 @cindex DWARF Reading
26259 Turns on or off display of debugging messages related to reading
26260 DWARF debug info. The default is 0 (off).
26261 A value of 1 provides basic information.
26262 A value greater than 1 provides more verbose information.
26263 @item show debug dwarf-read
26264 Show the current state of DWARF reader debugging.
26265 @item set debug displaced
26266 @cindex displaced stepping debugging info
26267 Turns on or off display of @value{GDBN} debugging info for the
26268 displaced stepping support. The default is off.
26269 @item show debug displaced
26270 Displays the current state of displaying @value{GDBN} debugging info
26271 related to displaced stepping.
26272 @item set debug event
26273 @cindex event debugging info
26274 Turns on or off display of @value{GDBN} event debugging info. The
26275 default is off.
26276 @item show debug event
26277 Displays the current state of displaying @value{GDBN} event debugging
26278 info.
26279 @item set debug expression
26280 @cindex expression debugging info
26281 Turns on or off display of debugging info about @value{GDBN}
26282 expression parsing. The default is off.
26283 @item show debug expression
26284 Displays the current state of displaying debugging info about
26285 @value{GDBN} expression parsing.
26286 @item set debug fbsd-lwp
26287 @cindex FreeBSD LWP debug messages
26288 Turns on or off debugging messages from the FreeBSD LWP debug support.
26289 @item show debug fbsd-lwp
26290 Show the current state of FreeBSD LWP debugging messages.
26291 @item set debug fbsd-nat
26292 @cindex FreeBSD native target debug messages
26293 Turns on or off debugging messages from the FreeBSD native target.
26294 @item show debug fbsd-nat
26295 Show the current state of FreeBSD native target debugging messages.
26296 @item set debug frame
26297 @cindex frame debugging info
26298 Turns on or off display of @value{GDBN} frame debugging info. The
26299 default is off.
26300 @item show debug frame
26301 Displays the current state of displaying @value{GDBN} frame debugging
26302 info.
26303 @item set debug gnu-nat
26304 @cindex @sc{gnu}/Hurd debug messages
26305 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26306 @item show debug gnu-nat
26307 Show the current state of @sc{gnu}/Hurd debugging messages.
26308 @item set debug infrun
26309 @cindex inferior debugging info
26310 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26311 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26312 for implementing operations such as single-stepping the inferior.
26313 @item show debug infrun
26314 Displays the current state of @value{GDBN} inferior debugging.
26315 @item set debug jit
26316 @cindex just-in-time compilation, debugging messages
26317 Turn on or off debugging messages from JIT debug support.
26318 @item show debug jit
26319 Displays the current state of @value{GDBN} JIT debugging.
26320 @item set debug lin-lwp
26321 @cindex @sc{gnu}/Linux LWP debug messages
26322 @cindex Linux lightweight processes
26323 Turn on or off debugging messages from the Linux LWP debug support.
26324 @item show debug lin-lwp
26325 Show the current state of Linux LWP debugging messages.
26326 @item set debug linux-namespaces
26327 @cindex @sc{gnu}/Linux namespaces debug messages
26328 Turn on or off debugging messages from the Linux namespaces debug support.
26329 @item show debug linux-namespaces
26330 Show the current state of Linux namespaces debugging messages.
26331 @item set debug mach-o
26332 @cindex Mach-O symbols processing
26333 Control display of debugging messages related to Mach-O symbols
26334 processing. The default is off.
26335 @item show debug mach-o
26336 Displays the current state of displaying debugging messages related to
26337 reading of COFF/PE exported symbols.
26338 @item set debug notification
26339 @cindex remote async notification debugging info
26340 Turn on or off debugging messages about remote async notification.
26341 The default is off.
26342 @item show debug notification
26343 Displays the current state of remote async notification debugging messages.
26344 @item set debug observer
26345 @cindex observer debugging info
26346 Turns on or off display of @value{GDBN} observer debugging. This
26347 includes info such as the notification of observable events.
26348 @item show debug observer
26349 Displays the current state of observer debugging.
26350 @item set debug overload
26351 @cindex C@t{++} overload debugging info
26352 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26353 info. This includes info such as ranking of functions, etc. The default
26354 is off.
26355 @item show debug overload
26356 Displays the current state of displaying @value{GDBN} C@t{++} overload
26357 debugging info.
26358 @cindex expression parser, debugging info
26359 @cindex debug expression parser
26360 @item set debug parser
26361 Turns on or off the display of expression parser debugging output.
26362 Internally, this sets the @code{yydebug} variable in the expression
26363 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26364 details. The default is off.
26365 @item show debug parser
26366 Show the current state of expression parser debugging.
26367 @cindex packets, reporting on stdout
26368 @cindex serial connections, debugging
26369 @cindex debug remote protocol
26370 @cindex remote protocol debugging
26371 @cindex display remote packets
26372 @item set debug remote
26373 Turns on or off display of reports on all packets sent back and forth across
26374 the serial line to the remote machine. The info is printed on the
26375 @value{GDBN} standard output stream. The default is off.
26376 @item show debug remote
26377 Displays the state of display of remote packets.
26378
26379 @item set debug remote-packet-max-chars
26380 Sets the maximum number of characters to display for each remote packet when
26381 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26382 displaying lengthy remote packets and polluting the console.
26383
26384 The default value is @code{512}, which means @value{GDBN} will truncate each
26385 remote packet after 512 bytes.
26386
26387 Setting this option to @code{unlimited} will disable truncation and will output
26388 the full length of the remote packets.
26389 @item show debug remote-packet-max-chars
26390 Displays the number of bytes to output for remote packet debugging.
26391
26392 @item set debug separate-debug-file
26393 Turns on or off display of debug output about separate debug file search.
26394 @item show debug separate-debug-file
26395 Displays the state of separate debug file search debug output.
26396
26397 @item set debug serial
26398 Turns on or off display of @value{GDBN} serial debugging info. The
26399 default is off.
26400 @item show debug serial
26401 Displays the current state of displaying @value{GDBN} serial debugging
26402 info.
26403 @item set debug solib-frv
26404 @cindex FR-V shared-library debugging
26405 Turn on or off debugging messages for FR-V shared-library code.
26406 @item show debug solib-frv
26407 Display the current state of FR-V shared-library code debugging
26408 messages.
26409 @item set debug symbol-lookup
26410 @cindex symbol lookup
26411 Turns on or off display of debugging messages related to symbol lookup.
26412 The default is 0 (off).
26413 A value of 1 provides basic information.
26414 A value greater than 1 provides more verbose information.
26415 @item show debug symbol-lookup
26416 Show the current state of symbol lookup debugging messages.
26417 @item set debug symfile
26418 @cindex symbol file functions
26419 Turns on or off display of debugging messages related to symbol file functions.
26420 The default is off. @xref{Files}.
26421 @item show debug symfile
26422 Show the current state of symbol file debugging messages.
26423 @item set debug symtab-create
26424 @cindex symbol table creation
26425 Turns on or off display of debugging messages related to symbol table creation.
26426 The default is 0 (off).
26427 A value of 1 provides basic information.
26428 A value greater than 1 provides more verbose information.
26429 @item show debug symtab-create
26430 Show the current state of symbol table creation debugging.
26431 @item set debug target
26432 @cindex target debugging info
26433 Turns on or off display of @value{GDBN} target debugging info. This info
26434 includes what is going on at the target level of GDB, as it happens. The
26435 default is 0. Set it to 1 to track events, and to 2 to also track the
26436 value of large memory transfers.
26437 @item show debug target
26438 Displays the current state of displaying @value{GDBN} target debugging
26439 info.
26440 @item set debug timestamp
26441 @cindex timestamping debugging info
26442 Turns on or off display of timestamps with @value{GDBN} debugging info.
26443 When enabled, seconds and microseconds are displayed before each debugging
26444 message.
26445 @item show debug timestamp
26446 Displays the current state of displaying timestamps with @value{GDBN}
26447 debugging info.
26448 @item set debug varobj
26449 @cindex variable object debugging info
26450 Turns on or off display of @value{GDBN} variable object debugging
26451 info. The default is off.
26452 @item show debug varobj
26453 Displays the current state of displaying @value{GDBN} variable object
26454 debugging info.
26455 @item set debug xml
26456 @cindex XML parser debugging
26457 Turn on or off debugging messages for built-in XML parsers.
26458 @item show debug xml
26459 Displays the current state of XML debugging messages.
26460 @end table
26461
26462 @node Other Misc Settings
26463 @section Other Miscellaneous Settings
26464 @cindex miscellaneous settings
26465
26466 @table @code
26467 @kindex set interactive-mode
26468 @item set interactive-mode
26469 If @code{on}, forces @value{GDBN} to assume that GDB was started
26470 in a terminal. In practice, this means that @value{GDBN} should wait
26471 for the user to answer queries generated by commands entered at
26472 the command prompt. If @code{off}, forces @value{GDBN} to operate
26473 in the opposite mode, and it uses the default answers to all queries.
26474 If @code{auto} (the default), @value{GDBN} tries to determine whether
26475 its standard input is a terminal, and works in interactive-mode if it
26476 is, non-interactively otherwise.
26477
26478 In the vast majority of cases, the debugger should be able to guess
26479 correctly which mode should be used. But this setting can be useful
26480 in certain specific cases, such as running a MinGW @value{GDBN}
26481 inside a cygwin window.
26482
26483 @kindex show interactive-mode
26484 @item show interactive-mode
26485 Displays whether the debugger is operating in interactive mode or not.
26486 @end table
26487
26488 @node Extending GDB
26489 @chapter Extending @value{GDBN}
26490 @cindex extending GDB
26491
26492 @value{GDBN} provides several mechanisms for extension.
26493 @value{GDBN} also provides the ability to automatically load
26494 extensions when it reads a file for debugging. This allows the
26495 user to automatically customize @value{GDBN} for the program
26496 being debugged.
26497
26498 @menu
26499 * Sequences:: Canned Sequences of @value{GDBN} Commands
26500 * Python:: Extending @value{GDBN} using Python
26501 * Guile:: Extending @value{GDBN} using Guile
26502 * Auto-loading extensions:: Automatically loading extensions
26503 * Multiple Extension Languages:: Working with multiple extension languages
26504 * Aliases:: Creating new spellings of existing commands
26505 @end menu
26506
26507 To facilitate the use of extension languages, @value{GDBN} is capable
26508 of evaluating the contents of a file. When doing so, @value{GDBN}
26509 can recognize which extension language is being used by looking at
26510 the filename extension. Files with an unrecognized filename extension
26511 are always treated as a @value{GDBN} Command Files.
26512 @xref{Command Files,, Command files}.
26513
26514 You can control how @value{GDBN} evaluates these files with the following
26515 setting:
26516
26517 @table @code
26518 @kindex set script-extension
26519 @kindex show script-extension
26520 @item set script-extension off
26521 All scripts are always evaluated as @value{GDBN} Command Files.
26522
26523 @item set script-extension soft
26524 The debugger determines the scripting language based on filename
26525 extension. If this scripting language is supported, @value{GDBN}
26526 evaluates the script using that language. Otherwise, it evaluates
26527 the file as a @value{GDBN} Command File.
26528
26529 @item set script-extension strict
26530 The debugger determines the scripting language based on filename
26531 extension, and evaluates the script using that language. If the
26532 language is not supported, then the evaluation fails.
26533
26534 @item show script-extension
26535 Display the current value of the @code{script-extension} option.
26536
26537 @end table
26538
26539 @ifset SYSTEM_GDBINIT_DIR
26540 This setting is not used for files in the system-wide gdbinit directory.
26541 Files in that directory must have an extension matching their language,
26542 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26543 commands. @xref{Startup}.
26544 @end ifset
26545
26546 @node Sequences
26547 @section Canned Sequences of Commands
26548
26549 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
26550 Command Lists}), @value{GDBN} provides two ways to store sequences of
26551 commands for execution as a unit: user-defined commands and command
26552 files.
26553
26554 @menu
26555 * Define:: How to define your own commands
26556 * Hooks:: Hooks for user-defined commands
26557 * Command Files:: How to write scripts of commands to be stored in a file
26558 * Output:: Commands for controlled output
26559 * Auto-loading sequences:: Controlling auto-loaded command files
26560 @end menu
26561
26562 @node Define
26563 @subsection User-defined Commands
26564
26565 @cindex user-defined command
26566 @cindex arguments, to user-defined commands
26567 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26568 which you assign a new name as a command. This is done with the
26569 @code{define} command. User commands may accept an unlimited number of arguments
26570 separated by whitespace. Arguments are accessed within the user command
26571 via @code{$arg0@dots{}$argN}. A trivial example:
26572
26573 @smallexample
26574 define adder
26575 print $arg0 + $arg1 + $arg2
26576 end
26577 @end smallexample
26578
26579 @noindent
26580 To execute the command use:
26581
26582 @smallexample
26583 adder 1 2 3
26584 @end smallexample
26585
26586 @noindent
26587 This defines the command @code{adder}, which prints the sum of
26588 its three arguments. Note the arguments are text substitutions, so they may
26589 reference variables, use complex expressions, or even perform inferior
26590 functions calls.
26591
26592 @cindex argument count in user-defined commands
26593 @cindex how many arguments (user-defined commands)
26594 In addition, @code{$argc} may be used to find out how many arguments have
26595 been passed.
26596
26597 @smallexample
26598 define adder
26599 if $argc == 2
26600 print $arg0 + $arg1
26601 end
26602 if $argc == 3
26603 print $arg0 + $arg1 + $arg2
26604 end
26605 end
26606 @end smallexample
26607
26608 Combining with the @code{eval} command (@pxref{eval}) makes it easier
26609 to process a variable number of arguments:
26610
26611 @smallexample
26612 define adder
26613 set $i = 0
26614 set $sum = 0
26615 while $i < $argc
26616 eval "set $sum = $sum + $arg%d", $i
26617 set $i = $i + 1
26618 end
26619 print $sum
26620 end
26621 @end smallexample
26622
26623 @table @code
26624
26625 @kindex define
26626 @item define @var{commandname}
26627 Define a command named @var{commandname}. If there is already a command
26628 by that name, you are asked to confirm that you want to redefine it.
26629 The argument @var{commandname} may be a bare command name consisting of letters,
26630 numbers, dashes, dots, and underscores. It may also start with any
26631 predefined or user-defined prefix command.
26632 For example, @samp{define target my-target} creates
26633 a user-defined @samp{target my-target} command.
26634
26635 The definition of the command is made up of other @value{GDBN} command lines,
26636 which are given following the @code{define} command. The end of these
26637 commands is marked by a line containing @code{end}.
26638
26639 @kindex document
26640 @kindex end@r{ (user-defined commands)}
26641 @item document @var{commandname}
26642 Document the user-defined command @var{commandname}, so that it can be
26643 accessed by @code{help}. The command @var{commandname} must already be
26644 defined. This command reads lines of documentation just as @code{define}
26645 reads the lines of the command definition, ending with @code{end}.
26646 After the @code{document} command is finished, @code{help} on command
26647 @var{commandname} displays the documentation you have written.
26648
26649 You may use the @code{document} command again to change the
26650 documentation of a command. Redefining the command with @code{define}
26651 does not change the documentation.
26652
26653 @kindex define-prefix
26654 @item define-prefix @var{commandname}
26655 Define or mark the command @var{commandname} as a user-defined prefix
26656 command. Once marked, @var{commandname} can be used as prefix command
26657 by the @code{define} command.
26658 Note that @code{define-prefix} can be used with a not yet defined
26659 @var{commandname}. In such a case, @var{commandname} is defined as
26660 an empty user-defined command.
26661 In case you redefine a command that was marked as a user-defined
26662 prefix command, the subcommands of the redefined command are kept
26663 (and @value{GDBN} indicates so to the user).
26664
26665 Example:
26666 @example
26667 (gdb) define-prefix abc
26668 (gdb) define-prefix abc def
26669 (gdb) define abc def
26670 Type commands for definition of "abc def".
26671 End with a line saying just "end".
26672 >echo command initial def\n
26673 >end
26674 (gdb) define abc def ghi
26675 Type commands for definition of "abc def ghi".
26676 End with a line saying just "end".
26677 >echo command ghi\n
26678 >end
26679 (gdb) define abc def
26680 Keeping subcommands of prefix command "def".
26681 Redefine command "def"? (y or n) y
26682 Type commands for definition of "abc def".
26683 End with a line saying just "end".
26684 >echo command def\n
26685 >end
26686 (gdb) abc def ghi
26687 command ghi
26688 (gdb) abc def
26689 command def
26690 (gdb)
26691 @end example
26692
26693 @kindex dont-repeat
26694 @cindex don't repeat command
26695 @item dont-repeat
26696 Used inside a user-defined command, this tells @value{GDBN} that this
26697 command should not be repeated when the user hits @key{RET}
26698 (@pxref{Command Syntax, repeat last command}).
26699
26700 @kindex help user-defined
26701 @item help user-defined
26702 List all user-defined commands and all python commands defined in class
26703 COMMAND_USER. The first line of the documentation or docstring is
26704 included (if any).
26705
26706 @kindex show user
26707 @item show user
26708 @itemx show user @var{commandname}
26709 Display the @value{GDBN} commands used to define @var{commandname} (but
26710 not its documentation). If no @var{commandname} is given, display the
26711 definitions for all user-defined commands.
26712 This does not work for user-defined python commands.
26713
26714 @cindex infinite recursion in user-defined commands
26715 @kindex show max-user-call-depth
26716 @kindex set max-user-call-depth
26717 @item show max-user-call-depth
26718 @itemx set max-user-call-depth
26719 The value of @code{max-user-call-depth} controls how many recursion
26720 levels are allowed in user-defined commands before @value{GDBN} suspects an
26721 infinite recursion and aborts the command.
26722 This does not apply to user-defined python commands.
26723 @end table
26724
26725 In addition to the above commands, user-defined commands frequently
26726 use control flow commands, described in @ref{Command Files}.
26727
26728 When user-defined commands are executed, the
26729 commands of the definition are not printed. An error in any command
26730 stops execution of the user-defined command.
26731
26732 If used interactively, commands that would ask for confirmation proceed
26733 without asking when used inside a user-defined command. Many @value{GDBN}
26734 commands that normally print messages to say what they are doing omit the
26735 messages when used in a user-defined command.
26736
26737 @node Hooks
26738 @subsection User-defined Command Hooks
26739 @cindex command hooks
26740 @cindex hooks, for commands
26741 @cindex hooks, pre-command
26742
26743 @kindex hook
26744 You may define @dfn{hooks}, which are a special kind of user-defined
26745 command. Whenever you run the command @samp{foo}, if the user-defined
26746 command @samp{hook-foo} exists, it is executed (with no arguments)
26747 before that command.
26748
26749 @cindex hooks, post-command
26750 @kindex hookpost
26751 A hook may also be defined which is run after the command you executed.
26752 Whenever you run the command @samp{foo}, if the user-defined command
26753 @samp{hookpost-foo} exists, it is executed (with no arguments) after
26754 that command. Post-execution hooks may exist simultaneously with
26755 pre-execution hooks, for the same command.
26756
26757 It is valid for a hook to call the command which it hooks. If this
26758 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
26759
26760 @c It would be nice if hookpost could be passed a parameter indicating
26761 @c if the command it hooks executed properly or not. FIXME!
26762
26763 @kindex stop@r{, a pseudo-command}
26764 In addition, a pseudo-command, @samp{stop} exists. Defining
26765 (@samp{hook-stop}) makes the associated commands execute every time
26766 execution stops in your program: before breakpoint commands are run,
26767 displays are printed, or the stack frame is printed.
26768
26769 For example, to ignore @code{SIGALRM} signals while
26770 single-stepping, but treat them normally during normal execution,
26771 you could define:
26772
26773 @smallexample
26774 define hook-stop
26775 handle SIGALRM nopass
26776 end
26777
26778 define hook-run
26779 handle SIGALRM pass
26780 end
26781
26782 define hook-continue
26783 handle SIGALRM pass
26784 end
26785 @end smallexample
26786
26787 As a further example, to hook at the beginning and end of the @code{echo}
26788 command, and to add extra text to the beginning and end of the message,
26789 you could define:
26790
26791 @smallexample
26792 define hook-echo
26793 echo <<<---
26794 end
26795
26796 define hookpost-echo
26797 echo --->>>\n
26798 end
26799
26800 (@value{GDBP}) echo Hello World
26801 <<<---Hello World--->>>
26802 (@value{GDBP})
26803
26804 @end smallexample
26805
26806 You can define a hook for any single-word command in @value{GDBN}, but
26807 not for command aliases; you should define a hook for the basic command
26808 name, e.g.@: @code{backtrace} rather than @code{bt}.
26809 @c FIXME! So how does Joe User discover whether a command is an alias
26810 @c or not?
26811 You can hook a multi-word command by adding @code{hook-} or
26812 @code{hookpost-} to the last word of the command, e.g.@:
26813 @samp{define target hook-remote} to add a hook to @samp{target remote}.
26814
26815 If an error occurs during the execution of your hook, execution of
26816 @value{GDBN} commands stops and @value{GDBN} issues a prompt
26817 (before the command that you actually typed had a chance to run).
26818
26819 If you try to define a hook which does not match any known command, you
26820 get a warning from the @code{define} command.
26821
26822 @node Command Files
26823 @subsection Command Files
26824
26825 @cindex command files
26826 @cindex scripting commands
26827 A command file for @value{GDBN} is a text file made of lines that are
26828 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26829 also be included. An empty line in a command file does nothing; it
26830 does not mean to repeat the last command, as it would from the
26831 terminal.
26832
26833 You can request the execution of a command file with the @code{source}
26834 command. Note that the @code{source} command is also used to evaluate
26835 scripts that are not Command Files. The exact behavior can be configured
26836 using the @code{script-extension} setting.
26837 @xref{Extending GDB,, Extending GDB}.
26838
26839 @table @code
26840 @kindex source
26841 @cindex execute commands from a file
26842 @item source [-s] [-v] @var{filename}
26843 Execute the command file @var{filename}.
26844 @end table
26845
26846 The lines in a command file are generally executed sequentially,
26847 unless the order of execution is changed by one of the
26848 @emph{flow-control commands} described below. The commands are not
26849 printed as they are executed. An error in any command terminates
26850 execution of the command file and control is returned to the console.
26851
26852 @value{GDBN} first searches for @var{filename} in the current directory.
26853 If the file is not found there, and @var{filename} does not specify a
26854 directory, then @value{GDBN} also looks for the file on the source search path
26855 (specified with the @samp{directory} command);
26856 except that @file{$cdir} is not searched because the compilation directory
26857 is not relevant to scripts.
26858
26859 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
26860 on the search path even if @var{filename} specifies a directory.
26861 The search is done by appending @var{filename} to each element of the
26862 search path. So, for example, if @var{filename} is @file{mylib/myscript}
26863 and the search path contains @file{/home/user} then @value{GDBN} will
26864 look for the script @file{/home/user/mylib/myscript}.
26865 The search is also done if @var{filename} is an absolute path.
26866 For example, if @var{filename} is @file{/tmp/myscript} and
26867 the search path contains @file{/home/user} then @value{GDBN} will
26868 look for the script @file{/home/user/tmp/myscript}.
26869 For DOS-like systems, if @var{filename} contains a drive specification,
26870 it is stripped before concatenation. For example, if @var{filename} is
26871 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
26872 will look for the script @file{c:/tmp/myscript}.
26873
26874 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
26875 each command as it is executed. The option must be given before
26876 @var{filename}, and is interpreted as part of the filename anywhere else.
26877
26878 Commands that would ask for confirmation if used interactively proceed
26879 without asking when used in a command file. Many @value{GDBN} commands that
26880 normally print messages to say what they are doing omit the messages
26881 when called from command files.
26882
26883 @value{GDBN} also accepts command input from standard input. In this
26884 mode, normal output goes to standard output and error output goes to
26885 standard error. Errors in a command file supplied on standard input do
26886 not terminate execution of the command file---execution continues with
26887 the next command.
26888
26889 @smallexample
26890 gdb < cmds > log 2>&1
26891 @end smallexample
26892
26893 (The syntax above will vary depending on the shell used.) This example
26894 will execute commands from the file @file{cmds}. All output and errors
26895 would be directed to @file{log}.
26896
26897 Since commands stored on command files tend to be more general than
26898 commands typed interactively, they frequently need to deal with
26899 complicated situations, such as different or unexpected values of
26900 variables and symbols, changes in how the program being debugged is
26901 built, etc. @value{GDBN} provides a set of flow-control commands to
26902 deal with these complexities. Using these commands, you can write
26903 complex scripts that loop over data structures, execute commands
26904 conditionally, etc.
26905
26906 @table @code
26907 @kindex if
26908 @kindex else
26909 @item if
26910 @itemx else
26911 This command allows to include in your script conditionally executed
26912 commands. The @code{if} command takes a single argument, which is an
26913 expression to evaluate. It is followed by a series of commands that
26914 are executed only if the expression is true (its value is nonzero).
26915 There can then optionally be an @code{else} line, followed by a series
26916 of commands that are only executed if the expression was false. The
26917 end of the list is marked by a line containing @code{end}.
26918
26919 @kindex while
26920 @item while
26921 This command allows to write loops. Its syntax is similar to
26922 @code{if}: the command takes a single argument, which is an expression
26923 to evaluate, and must be followed by the commands to execute, one per
26924 line, terminated by an @code{end}. These commands are called the
26925 @dfn{body} of the loop. The commands in the body of @code{while} are
26926 executed repeatedly as long as the expression evaluates to true.
26927
26928 @kindex loop_break
26929 @item loop_break
26930 This command exits the @code{while} loop in whose body it is included.
26931 Execution of the script continues after that @code{while}s @code{end}
26932 line.
26933
26934 @kindex loop_continue
26935 @item loop_continue
26936 This command skips the execution of the rest of the body of commands
26937 in the @code{while} loop in whose body it is included. Execution
26938 branches to the beginning of the @code{while} loop, where it evaluates
26939 the controlling expression.
26940
26941 @kindex end@r{ (if/else/while commands)}
26942 @item end
26943 Terminate the block of commands that are the body of @code{if},
26944 @code{else}, or @code{while} flow-control commands.
26945 @end table
26946
26947
26948 @node Output
26949 @subsection Commands for Controlled Output
26950
26951 During the execution of a command file or a user-defined command, normal
26952 @value{GDBN} output is suppressed; the only output that appears is what is
26953 explicitly printed by the commands in the definition. This section
26954 describes three commands useful for generating exactly the output you
26955 want.
26956
26957 @table @code
26958 @kindex echo
26959 @item echo @var{text}
26960 @c I do not consider backslash-space a standard C escape sequence
26961 @c because it is not in ANSI.
26962 Print @var{text}. Nonprinting characters can be included in
26963 @var{text} using C escape sequences, such as @samp{\n} to print a
26964 newline. @strong{No newline is printed unless you specify one.}
26965 In addition to the standard C escape sequences, a backslash followed
26966 by a space stands for a space. This is useful for displaying a
26967 string with spaces at the beginning or the end, since leading and
26968 trailing spaces are otherwise trimmed from all arguments.
26969 To print @samp{@w{ }and foo =@w{ }}, use the command
26970 @samp{echo \@w{ }and foo = \@w{ }}.
26971
26972 A backslash at the end of @var{text} can be used, as in C, to continue
26973 the command onto subsequent lines. For example,
26974
26975 @smallexample
26976 echo This is some text\n\
26977 which is continued\n\
26978 onto several lines.\n
26979 @end smallexample
26980
26981 produces the same output as
26982
26983 @smallexample
26984 echo This is some text\n
26985 echo which is continued\n
26986 echo onto several lines.\n
26987 @end smallexample
26988
26989 @kindex output
26990 @item output @var{expression}
26991 Print the value of @var{expression} and nothing but that value: no
26992 newlines, no @samp{$@var{nn} = }. The value is not entered in the
26993 value history either. @xref{Expressions, ,Expressions}, for more information
26994 on expressions.
26995
26996 @item output/@var{fmt} @var{expression}
26997 Print the value of @var{expression} in format @var{fmt}. You can use
26998 the same formats as for @code{print}. @xref{Output Formats,,Output
26999 Formats}, for more information.
27000
27001 @kindex printf
27002 @item printf @var{template}, @var{expressions}@dots{}
27003 Print the values of one or more @var{expressions} under the control of
27004 the string @var{template}. To print several values, make
27005 @var{expressions} be a comma-separated list of individual expressions,
27006 which may be either numbers or pointers. Their values are printed as
27007 specified by @var{template}, exactly as a C program would do by
27008 executing the code below:
27009
27010 @smallexample
27011 printf (@var{template}, @var{expressions}@dots{});
27012 @end smallexample
27013
27014 As in @code{C} @code{printf}, ordinary characters in @var{template}
27015 are printed verbatim, while @dfn{conversion specification} introduced
27016 by the @samp{%} character cause subsequent @var{expressions} to be
27017 evaluated, their values converted and formatted according to type and
27018 style information encoded in the conversion specifications, and then
27019 printed.
27020
27021 For example, you can print two values in hex like this:
27022
27023 @smallexample
27024 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27025 @end smallexample
27026
27027 @code{printf} supports all the standard @code{C} conversion
27028 specifications, including the flags and modifiers between the @samp{%}
27029 character and the conversion letter, with the following exceptions:
27030
27031 @itemize @bullet
27032 @item
27033 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27034
27035 @item
27036 The modifier @samp{*} is not supported for specifying precision or
27037 width.
27038
27039 @item
27040 The @samp{'} flag (for separation of digits into groups according to
27041 @code{LC_NUMERIC'}) is not supported.
27042
27043 @item
27044 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27045 supported.
27046
27047 @item
27048 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27049
27050 @item
27051 The conversion letters @samp{a} and @samp{A} are not supported.
27052 @end itemize
27053
27054 @noindent
27055 Note that the @samp{ll} type modifier is supported only if the
27056 underlying @code{C} implementation used to build @value{GDBN} supports
27057 the @code{long long int} type, and the @samp{L} type modifier is
27058 supported only if @code{long double} type is available.
27059
27060 As in @code{C}, @code{printf} supports simple backslash-escape
27061 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27062 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27063 single character. Octal and hexadecimal escape sequences are not
27064 supported.
27065
27066 Additionally, @code{printf} supports conversion specifications for DFP
27067 (@dfn{Decimal Floating Point}) types using the following length modifiers
27068 together with a floating point specifier.
27069 letters:
27070
27071 @itemize @bullet
27072 @item
27073 @samp{H} for printing @code{Decimal32} types.
27074
27075 @item
27076 @samp{D} for printing @code{Decimal64} types.
27077
27078 @item
27079 @samp{DD} for printing @code{Decimal128} types.
27080 @end itemize
27081
27082 If the underlying @code{C} implementation used to build @value{GDBN} has
27083 support for the three length modifiers for DFP types, other modifiers
27084 such as width and precision will also be available for @value{GDBN} to use.
27085
27086 In case there is no such @code{C} support, no additional modifiers will be
27087 available and the value will be printed in the standard way.
27088
27089 Here's an example of printing DFP types using the above conversion letters:
27090 @smallexample
27091 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27092 @end smallexample
27093
27094 @anchor{eval}
27095 @kindex eval
27096 @item eval @var{template}, @var{expressions}@dots{}
27097 Convert the values of one or more @var{expressions} under the control of
27098 the string @var{template} to a command line, and call it.
27099
27100 @end table
27101
27102 @node Auto-loading sequences
27103 @subsection Controlling auto-loading native @value{GDBN} scripts
27104 @cindex native script auto-loading
27105
27106 When a new object file is read (for example, due to the @code{file}
27107 command, or because the inferior has loaded a shared library),
27108 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27109 @xref{Auto-loading extensions}.
27110
27111 Auto-loading can be enabled or disabled,
27112 and the list of auto-loaded scripts can be printed.
27113
27114 @table @code
27115 @anchor{set auto-load gdb-scripts}
27116 @kindex set auto-load gdb-scripts
27117 @item set auto-load gdb-scripts [on|off]
27118 Enable or disable the auto-loading of canned sequences of commands scripts.
27119
27120 @anchor{show auto-load gdb-scripts}
27121 @kindex show auto-load gdb-scripts
27122 @item show auto-load gdb-scripts
27123 Show whether auto-loading of canned sequences of commands scripts is enabled or
27124 disabled.
27125
27126 @anchor{info auto-load gdb-scripts}
27127 @kindex info auto-load gdb-scripts
27128 @cindex print list of auto-loaded canned sequences of commands scripts
27129 @item info auto-load gdb-scripts [@var{regexp}]
27130 Print the list of all canned sequences of commands scripts that @value{GDBN}
27131 auto-loaded.
27132 @end table
27133
27134 If @var{regexp} is supplied only canned sequences of commands scripts with
27135 matching names are printed.
27136
27137 @c Python docs live in a separate file.
27138 @include python.texi
27139
27140 @c Guile docs live in a separate file.
27141 @include guile.texi
27142
27143 @node Auto-loading extensions
27144 @section Auto-loading extensions
27145 @cindex auto-loading extensions
27146
27147 @value{GDBN} provides two mechanisms for automatically loading extensions
27148 when a new object file is read (for example, due to the @code{file}
27149 command, or because the inferior has loaded a shared library):
27150 @file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27151 section of modern file formats like ELF.
27152
27153 @menu
27154 * objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27155 * .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27156 * Which flavor to choose?::
27157 @end menu
27158
27159 The auto-loading feature is useful for supplying application-specific
27160 debugging commands and features.
27161
27162 Auto-loading can be enabled or disabled,
27163 and the list of auto-loaded scripts can be printed.
27164 See the @samp{auto-loading} section of each extension language
27165 for more information.
27166 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27167 For Python files see @ref{Python Auto-loading}.
27168
27169 Note that loading of this script file also requires accordingly configured
27170 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27171
27172 @node objfile-gdbdotext file
27173 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27174 @cindex @file{@var{objfile}-gdb.gdb}
27175 @cindex @file{@var{objfile}-gdb.py}
27176 @cindex @file{@var{objfile}-gdb.scm}
27177
27178 When a new object file is read, @value{GDBN} looks for a file named
27179 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27180 where @var{objfile} is the object file's name and
27181 where @var{ext} is the file extension for the extension language:
27182
27183 @table @code
27184 @item @file{@var{objfile}-gdb.gdb}
27185 GDB's own command language
27186 @item @file{@var{objfile}-gdb.py}
27187 Python
27188 @item @file{@var{objfile}-gdb.scm}
27189 Guile
27190 @end table
27191
27192 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27193 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27194 components, and appending the @file{-gdb.@var{ext}} suffix.
27195 If this file exists and is readable, @value{GDBN} will evaluate it as a
27196 script in the specified extension language.
27197
27198 If this file does not exist, then @value{GDBN} will look for
27199 @var{script-name} file in all of the directories as specified below.
27200
27201 Note that loading of these files requires an accordingly configured
27202 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27203
27204 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27205 scripts normally according to its @file{.exe} filename. But if no scripts are
27206 found @value{GDBN} also tries script filenames matching the object file without
27207 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27208 is attempted on any platform. This makes the script filenames compatible
27209 between Unix and MS-Windows hosts.
27210
27211 @table @code
27212 @anchor{set auto-load scripts-directory}
27213 @kindex set auto-load scripts-directory
27214 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27215 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27216 may be delimited by the host platform path separator in use
27217 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27218
27219 Each entry here needs to be covered also by the security setting
27220 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27221
27222 @anchor{with-auto-load-dir}
27223 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27224 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27225 configuration option @option{--with-auto-load-dir}.
27226
27227 Any reference to @file{$debugdir} will get replaced by
27228 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27229 reference to @file{$datadir} will get replaced by @var{data-directory} which is
27230 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27231 @file{$datadir} must be placed as a directory component --- either alone or
27232 delimited by @file{/} or @file{\} directory separators, depending on the host
27233 platform.
27234
27235 The list of directories uses path separator (@samp{:} on GNU and Unix
27236 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27237 to the @env{PATH} environment variable.
27238
27239 @anchor{show auto-load scripts-directory}
27240 @kindex show auto-load scripts-directory
27241 @item show auto-load scripts-directory
27242 Show @value{GDBN} auto-loaded scripts location.
27243
27244 @anchor{add-auto-load-scripts-directory}
27245 @kindex add-auto-load-scripts-directory
27246 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27247 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27248 Multiple entries may be delimited by the host platform path separator in use.
27249 @end table
27250
27251 @value{GDBN} does not track which files it has already auto-loaded this way.
27252 @value{GDBN} will load the associated script every time the corresponding
27253 @var{objfile} is opened.
27254 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27255 is evaluated more than once.
27256
27257 @node dotdebug_gdb_scripts section
27258 @subsection The @code{.debug_gdb_scripts} section
27259 @cindex @code{.debug_gdb_scripts} section
27260
27261 For systems using file formats like ELF and COFF,
27262 when @value{GDBN} loads a new object file
27263 it will look for a special section named @code{.debug_gdb_scripts}.
27264 If this section exists, its contents is a list of null-terminated entries
27265 specifying scripts to load. Each entry begins with a non-null prefix byte that
27266 specifies the kind of entry, typically the extension language and whether the
27267 script is in a file or inlined in @code{.debug_gdb_scripts}.
27268
27269 The following entries are supported:
27270
27271 @table @code
27272 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27273 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27274 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27275 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27276 @end table
27277
27278 @subsubsection Script File Entries
27279
27280 If the entry specifies a file, @value{GDBN} will look for the file first
27281 in the current directory and then along the source search path
27282 (@pxref{Source Path, ,Specifying Source Directories}),
27283 except that @file{$cdir} is not searched, since the compilation
27284 directory is not relevant to scripts.
27285
27286 File entries can be placed in section @code{.debug_gdb_scripts} with,
27287 for example, this GCC macro for Python scripts.
27288
27289 @example
27290 /* Note: The "MS" section flags are to remove duplicates. */
27291 #define DEFINE_GDB_PY_SCRIPT(script_name) \
27292 asm("\
27293 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27294 .byte 1 /* Python */\n\
27295 .asciz \"" script_name "\"\n\
27296 .popsection \n\
27297 ");
27298 @end example
27299
27300 @noindent
27301 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
27302 Then one can reference the macro in a header or source file like this:
27303
27304 @example
27305 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27306 @end example
27307
27308 The script name may include directories if desired.
27309
27310 Note that loading of this script file also requires accordingly configured
27311 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27312
27313 If the macro invocation is put in a header, any application or library
27314 using this header will get a reference to the specified script,
27315 and with the use of @code{"MS"} attributes on the section, the linker
27316 will remove duplicates.
27317
27318 @subsubsection Script Text Entries
27319
27320 Script text entries allow to put the executable script in the entry
27321 itself instead of loading it from a file.
27322 The first line of the entry, everything after the prefix byte and up to
27323 the first newline (@code{0xa}) character, is the script name, and must not
27324 contain any kind of space character, e.g., spaces or tabs.
27325 The rest of the entry, up to the trailing null byte, is the script to
27326 execute in the specified language. The name needs to be unique among
27327 all script names, as @value{GDBN} executes each script only once based
27328 on its name.
27329
27330 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27331 testsuite.
27332
27333 @example
27334 #include "symcat.h"
27335 #include "gdb/section-scripts.h"
27336 asm(
27337 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27338 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27339 ".ascii \"gdb.inlined-script\\n\"\n"
27340 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27341 ".ascii \" def __init__ (self):\\n\"\n"
27342 ".ascii \" super (test_cmd, self).__init__ ("
27343 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27344 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27345 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27346 ".ascii \"test_cmd ()\\n\"\n"
27347 ".byte 0\n"
27348 ".popsection\n"
27349 );
27350 @end example
27351
27352 Loading of inlined scripts requires a properly configured
27353 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27354 The path to specify in @code{auto-load safe-path} is the path of the file
27355 containing the @code{.debug_gdb_scripts} section.
27356
27357 @node Which flavor to choose?
27358 @subsection Which flavor to choose?
27359
27360 Given the multiple ways of auto-loading extensions, it might not always
27361 be clear which one to choose. This section provides some guidance.
27362
27363 @noindent
27364 Benefits of the @file{-gdb.@var{ext}} way:
27365
27366 @itemize @bullet
27367 @item
27368 Can be used with file formats that don't support multiple sections.
27369
27370 @item
27371 Ease of finding scripts for public libraries.
27372
27373 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27374 in the source search path.
27375 For publicly installed libraries, e.g., @file{libstdc++}, there typically
27376 isn't a source directory in which to find the script.
27377
27378 @item
27379 Doesn't require source code additions.
27380 @end itemize
27381
27382 @noindent
27383 Benefits of the @code{.debug_gdb_scripts} way:
27384
27385 @itemize @bullet
27386 @item
27387 Works with static linking.
27388
27389 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27390 trigger their loading. When an application is statically linked the only
27391 objfile available is the executable, and it is cumbersome to attach all the
27392 scripts from all the input libraries to the executable's
27393 @file{-gdb.@var{ext}} script.
27394
27395 @item
27396 Works with classes that are entirely inlined.
27397
27398 Some classes can be entirely inlined, and thus there may not be an associated
27399 shared library to attach a @file{-gdb.@var{ext}} script to.
27400
27401 @item
27402 Scripts needn't be copied out of the source tree.
27403
27404 In some circumstances, apps can be built out of large collections of internal
27405 libraries, and the build infrastructure necessary to install the
27406 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27407 cumbersome. It may be easier to specify the scripts in the
27408 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
27409 top of the source tree to the source search path.
27410 @end itemize
27411
27412 @node Multiple Extension Languages
27413 @section Multiple Extension Languages
27414
27415 The Guile and Python extension languages do not share any state,
27416 and generally do not interfere with each other.
27417 There are some things to be aware of, however.
27418
27419 @subsection Python comes first
27420
27421 Python was @value{GDBN}'s first extension language, and to avoid breaking
27422 existing behaviour Python comes first. This is generally solved by the
27423 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
27424 extension languages, and when it makes a call to an extension language,
27425 (say to pretty-print a value), it tries each in turn until an extension
27426 language indicates it has performed the request (e.g., has returned the
27427 pretty-printed form of a value).
27428 This extends to errors while performing such requests: If an error happens
27429 while, for example, trying to pretty-print an object then the error is
27430 reported and any following extension languages are not tried.
27431
27432 @node Aliases
27433 @section Creating new spellings of existing commands
27434 @cindex aliases for commands
27435
27436 It is often useful to define alternate spellings of existing commands.
27437 For example, if a new @value{GDBN} command defined in Python has
27438 a long name to type, it is handy to have an abbreviated version of it
27439 that involves less typing.
27440
27441 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27442 of the @samp{step} command even though it is otherwise an ambiguous
27443 abbreviation of other commands like @samp{set} and @samp{show}.
27444
27445 Aliases are also used to provide shortened or more common versions
27446 of multi-word commands. For example, @value{GDBN} provides the
27447 @samp{tty} alias of the @samp{set inferior-tty} command.
27448
27449 You can define a new alias with the @samp{alias} command.
27450
27451 @table @code
27452
27453 @kindex alias
27454 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
27455
27456 @end table
27457
27458 @var{ALIAS} specifies the name of the new alias.
27459 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27460 underscores.
27461
27462 @var{COMMAND} specifies the name of an existing command
27463 that is being aliased.
27464
27465 The @samp{-a} option specifies that the new alias is an abbreviation
27466 of the command. Abbreviations are not shown in command
27467 lists displayed by the @samp{help} command.
27468
27469 The @samp{--} option specifies the end of options,
27470 and is useful when @var{ALIAS} begins with a dash.
27471
27472 Here is a simple example showing how to make an abbreviation
27473 of a command so that there is less to type.
27474 Suppose you were tired of typing @samp{disas}, the current
27475 shortest unambiguous abbreviation of the @samp{disassemble} command
27476 and you wanted an even shorter version named @samp{di}.
27477 The following will accomplish this.
27478
27479 @smallexample
27480 (gdb) alias -a di = disas
27481 @end smallexample
27482
27483 Note that aliases are different from user-defined commands.
27484 With a user-defined command, you also need to write documentation
27485 for it with the @samp{document} command.
27486 An alias automatically picks up the documentation of the existing command.
27487
27488 Here is an example where we make @samp{elms} an abbreviation of
27489 @samp{elements} in the @samp{set print elements} command.
27490 This is to show that you can make an abbreviation of any part
27491 of a command.
27492
27493 @smallexample
27494 (gdb) alias -a set print elms = set print elements
27495 (gdb) alias -a show print elms = show print elements
27496 (gdb) set p elms 20
27497 (gdb) show p elms
27498 Limit on string chars or array elements to print is 200.
27499 @end smallexample
27500
27501 Note that if you are defining an alias of a @samp{set} command,
27502 and you want to have an alias for the corresponding @samp{show}
27503 command, then you need to define the latter separately.
27504
27505 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27506 @var{ALIAS}, just as they are normally.
27507
27508 @smallexample
27509 (gdb) alias -a set pr elms = set p ele
27510 @end smallexample
27511
27512 Finally, here is an example showing the creation of a one word
27513 alias for a more complex command.
27514 This creates alias @samp{spe} of the command @samp{set print elements}.
27515
27516 @smallexample
27517 (gdb) alias spe = set print elements
27518 (gdb) spe 20
27519 @end smallexample
27520
27521 @node Interpreters
27522 @chapter Command Interpreters
27523 @cindex command interpreters
27524
27525 @value{GDBN} supports multiple command interpreters, and some command
27526 infrastructure to allow users or user interface writers to switch
27527 between interpreters or run commands in other interpreters.
27528
27529 @value{GDBN} currently supports two command interpreters, the console
27530 interpreter (sometimes called the command-line interpreter or @sc{cli})
27531 and the machine interface interpreter (or @sc{gdb/mi}). This manual
27532 describes both of these interfaces in great detail.
27533
27534 By default, @value{GDBN} will start with the console interpreter.
27535 However, the user may choose to start @value{GDBN} with another
27536 interpreter by specifying the @option{-i} or @option{--interpreter}
27537 startup options. Defined interpreters include:
27538
27539 @table @code
27540 @item console
27541 @cindex console interpreter
27542 The traditional console or command-line interpreter. This is the most often
27543 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27544 @value{GDBN} will use this interpreter.
27545
27546 @item mi
27547 @cindex mi interpreter
27548 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
27549 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27550 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27551 Interface}.
27552
27553 @item mi3
27554 @cindex mi3 interpreter
27555 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27556
27557 @item mi2
27558 @cindex mi2 interpreter
27559 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
27560
27561 @item mi1
27562 @cindex mi1 interpreter
27563 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
27564
27565 @end table
27566
27567 @cindex invoke another interpreter
27568
27569 @kindex interpreter-exec
27570 You may execute commands in any interpreter from the current
27571 interpreter using the appropriate command. If you are running the
27572 console interpreter, simply use the @code{interpreter-exec} command:
27573
27574 @smallexample
27575 interpreter-exec mi "-data-list-register-names"
27576 @end smallexample
27577
27578 @sc{gdb/mi} has a similar command, although it is only available in versions of
27579 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27580
27581 Note that @code{interpreter-exec} only changes the interpreter for the
27582 duration of the specified command. It does not change the interpreter
27583 permanently.
27584
27585 @cindex start a new independent interpreter
27586
27587 Although you may only choose a single interpreter at startup, it is
27588 possible to run an independent interpreter on a specified input/output
27589 device (usually a tty).
27590
27591 For example, consider a debugger GUI or IDE that wants to provide a
27592 @value{GDBN} console view. It may do so by embedding a terminal
27593 emulator widget in its GUI, starting @value{GDBN} in the traditional
27594 command-line mode with stdin/stdout/stderr redirected to that
27595 terminal, and then creating an MI interpreter running on a specified
27596 input/output device. The console interpreter created by @value{GDBN}
27597 at startup handles commands the user types in the terminal widget,
27598 while the GUI controls and synchronizes state with @value{GDBN} using
27599 the separate MI interpreter.
27600
27601 To start a new secondary @dfn{user interface} running MI, use the
27602 @code{new-ui} command:
27603
27604 @kindex new-ui
27605 @cindex new user interface
27606 @smallexample
27607 new-ui @var{interpreter} @var{tty}
27608 @end smallexample
27609
27610 The @var{interpreter} parameter specifies the interpreter to run.
27611 This accepts the same values as the @code{interpreter-exec} command.
27612 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27613 @var{tty} parameter specifies the name of the bidirectional file the
27614 interpreter uses for input/output, usually the name of a
27615 pseudoterminal slave on Unix systems. For example:
27616
27617 @smallexample
27618 (@value{GDBP}) new-ui mi /dev/pts/9
27619 @end smallexample
27620
27621 @noindent
27622 runs an MI interpreter on @file{/dev/pts/9}.
27623
27624 @node TUI
27625 @chapter @value{GDBN} Text User Interface
27626 @cindex TUI
27627 @cindex Text User Interface
27628
27629 @menu
27630 * TUI Overview:: TUI overview
27631 * TUI Keys:: TUI key bindings
27632 * TUI Single Key Mode:: TUI single key mode
27633 * TUI Commands:: TUI-specific commands
27634 * TUI Configuration:: TUI configuration variables
27635 @end menu
27636
27637 The @value{GDBN} Text User Interface (TUI) is a terminal
27638 interface which uses the @code{curses} library to show the source
27639 file, the assembly output, the program registers and @value{GDBN}
27640 commands in separate text windows. The TUI mode is supported only
27641 on platforms where a suitable version of the @code{curses} library
27642 is available.
27643
27644 The TUI mode is enabled by default when you invoke @value{GDBN} as
27645 @samp{@value{GDBP} -tui}.
27646 You can also switch in and out of TUI mode while @value{GDBN} runs by
27647 using various TUI commands and key bindings, such as @command{tui
27648 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
27649 @ref{TUI Keys, ,TUI Key Bindings}.
27650
27651 @node TUI Overview
27652 @section TUI Overview
27653
27654 In TUI mode, @value{GDBN} can display several text windows:
27655
27656 @table @emph
27657 @item command
27658 This window is the @value{GDBN} command window with the @value{GDBN}
27659 prompt and the @value{GDBN} output. The @value{GDBN} input is still
27660 managed using readline.
27661
27662 @item source
27663 The source window shows the source file of the program. The current
27664 line and active breakpoints are displayed in this window.
27665
27666 @item assembly
27667 The assembly window shows the disassembly output of the program.
27668
27669 @item register
27670 This window shows the processor registers. Registers are highlighted
27671 when their values change.
27672 @end table
27673
27674 The source and assembly windows show the current program position
27675 by highlighting the current line and marking it with a @samp{>} marker.
27676 Breakpoints are indicated with two markers. The first marker
27677 indicates the breakpoint type:
27678
27679 @table @code
27680 @item B
27681 Breakpoint which was hit at least once.
27682
27683 @item b
27684 Breakpoint which was never hit.
27685
27686 @item H
27687 Hardware breakpoint which was hit at least once.
27688
27689 @item h
27690 Hardware breakpoint which was never hit.
27691 @end table
27692
27693 The second marker indicates whether the breakpoint is enabled or not:
27694
27695 @table @code
27696 @item +
27697 Breakpoint is enabled.
27698
27699 @item -
27700 Breakpoint is disabled.
27701 @end table
27702
27703 The source, assembly and register windows are updated when the current
27704 thread changes, when the frame changes, or when the program counter
27705 changes.
27706
27707 These windows are not all visible at the same time. The command
27708 window is always visible. The others can be arranged in several
27709 layouts:
27710
27711 @itemize @bullet
27712 @item
27713 source only,
27714
27715 @item
27716 assembly only,
27717
27718 @item
27719 source and assembly,
27720
27721 @item
27722 source and registers, or
27723
27724 @item
27725 assembly and registers.
27726 @end itemize
27727
27728 A status line above the command window shows the following information:
27729
27730 @table @emph
27731 @item target
27732 Indicates the current @value{GDBN} target.
27733 (@pxref{Targets, ,Specifying a Debugging Target}).
27734
27735 @item process
27736 Gives the current process or thread number.
27737 When no process is being debugged, this field is set to @code{No process}.
27738
27739 @item function
27740 Gives the current function name for the selected frame.
27741 The name is demangled if demangling is turned on (@pxref{Print Settings}).
27742 When there is no symbol corresponding to the current program counter,
27743 the string @code{??} is displayed.
27744
27745 @item line
27746 Indicates the current line number for the selected frame.
27747 When the current line number is not known, the string @code{??} is displayed.
27748
27749 @item pc
27750 Indicates the current program counter address.
27751 @end table
27752
27753 @node TUI Keys
27754 @section TUI Key Bindings
27755 @cindex TUI key bindings
27756
27757 The TUI installs several key bindings in the readline keymaps
27758 @ifset SYSTEM_READLINE
27759 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27760 @end ifset
27761 @ifclear SYSTEM_READLINE
27762 (@pxref{Command Line Editing}).
27763 @end ifclear
27764 The following key bindings are installed for both TUI mode and the
27765 @value{GDBN} standard mode.
27766
27767 @table @kbd
27768 @kindex C-x C-a
27769 @item C-x C-a
27770 @kindex C-x a
27771 @itemx C-x a
27772 @kindex C-x A
27773 @itemx C-x A
27774 Enter or leave the TUI mode. When leaving the TUI mode,
27775 the curses window management stops and @value{GDBN} operates using
27776 its standard mode, writing on the terminal directly. When reentering
27777 the TUI mode, control is given back to the curses windows.
27778 The screen is then refreshed.
27779
27780 This key binding uses the bindable Readline function
27781 @code{tui-switch-mode}.
27782
27783 @kindex C-x 1
27784 @item C-x 1
27785 Use a TUI layout with only one window. The layout will
27786 either be @samp{source} or @samp{assembly}. When the TUI mode
27787 is not active, it will switch to the TUI mode.
27788
27789 Think of this key binding as the Emacs @kbd{C-x 1} binding.
27790
27791 This key binding uses the bindable Readline function
27792 @code{tui-delete-other-windows}.
27793
27794 @kindex C-x 2
27795 @item C-x 2
27796 Use a TUI layout with at least two windows. When the current
27797 layout already has two windows, the next layout with two windows is used.
27798 When a new layout is chosen, one window will always be common to the
27799 previous layout and the new one.
27800
27801 Think of it as the Emacs @kbd{C-x 2} binding.
27802
27803 This key binding uses the bindable Readline function
27804 @code{tui-change-windows}.
27805
27806 @kindex C-x o
27807 @item C-x o
27808 Change the active window. The TUI associates several key bindings
27809 (like scrolling and arrow keys) with the active window. This command
27810 gives the focus to the next TUI window.
27811
27812 Think of it as the Emacs @kbd{C-x o} binding.
27813
27814 This key binding uses the bindable Readline function
27815 @code{tui-other-window}.
27816
27817 @kindex C-x s
27818 @item C-x s
27819 Switch in and out of the TUI SingleKey mode that binds single
27820 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
27821
27822 This key binding uses the bindable Readline function
27823 @code{next-keymap}.
27824 @end table
27825
27826 The following key bindings only work in the TUI mode:
27827
27828 @table @asis
27829 @kindex PgUp
27830 @item @key{PgUp}
27831 Scroll the active window one page up.
27832
27833 @kindex PgDn
27834 @item @key{PgDn}
27835 Scroll the active window one page down.
27836
27837 @kindex Up
27838 @item @key{Up}
27839 Scroll the active window one line up.
27840
27841 @kindex Down
27842 @item @key{Down}
27843 Scroll the active window one line down.
27844
27845 @kindex Left
27846 @item @key{Left}
27847 Scroll the active window one column left.
27848
27849 @kindex Right
27850 @item @key{Right}
27851 Scroll the active window one column right.
27852
27853 @kindex C-L
27854 @item @kbd{C-L}
27855 Refresh the screen.
27856 @end table
27857
27858 Because the arrow keys scroll the active window in the TUI mode, they
27859 are not available for their normal use by readline unless the command
27860 window has the focus. When another window is active, you must use
27861 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
27862 and @kbd{C-f} to control the command window.
27863
27864 @node TUI Single Key Mode
27865 @section TUI Single Key Mode
27866 @cindex TUI single key mode
27867
27868 The TUI also provides a @dfn{SingleKey} mode, which binds several
27869 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
27870 switch into this mode, where the following key bindings are used:
27871
27872 @table @kbd
27873 @kindex c @r{(SingleKey TUI key)}
27874 @item c
27875 continue
27876
27877 @kindex d @r{(SingleKey TUI key)}
27878 @item d
27879 down
27880
27881 @kindex f @r{(SingleKey TUI key)}
27882 @item f
27883 finish
27884
27885 @kindex n @r{(SingleKey TUI key)}
27886 @item n
27887 next
27888
27889 @kindex o @r{(SingleKey TUI key)}
27890 @item o
27891 nexti. The shortcut letter @samp{o} stands for ``step Over''.
27892
27893 @kindex q @r{(SingleKey TUI key)}
27894 @item q
27895 exit the SingleKey mode.
27896
27897 @kindex r @r{(SingleKey TUI key)}
27898 @item r
27899 run
27900
27901 @kindex s @r{(SingleKey TUI key)}
27902 @item s
27903 step
27904
27905 @kindex i @r{(SingleKey TUI key)}
27906 @item i
27907 stepi. The shortcut letter @samp{i} stands for ``step Into''.
27908
27909 @kindex u @r{(SingleKey TUI key)}
27910 @item u
27911 up
27912
27913 @kindex v @r{(SingleKey TUI key)}
27914 @item v
27915 info locals
27916
27917 @kindex w @r{(SingleKey TUI key)}
27918 @item w
27919 where
27920 @end table
27921
27922 Other keys temporarily switch to the @value{GDBN} command prompt.
27923 The key that was pressed is inserted in the editing buffer so that
27924 it is possible to type most @value{GDBN} commands without interaction
27925 with the TUI SingleKey mode. Once the command is entered the TUI
27926 SingleKey mode is restored. The only way to permanently leave
27927 this mode is by typing @kbd{q} or @kbd{C-x s}.
27928
27929 @cindex SingleKey keymap name
27930 If @value{GDBN} was built with Readline 8.0 or later, the TUI
27931 SingleKey keymap will be named @samp{SingleKey}. This can be used in
27932 @file{.inputrc} to add additional bindings to this keymap.
27933
27934 @node TUI Commands
27935 @section TUI-specific Commands
27936 @cindex TUI commands
27937
27938 The TUI has specific commands to control the text windows.
27939 These commands are always available, even when @value{GDBN} is not in
27940 the TUI mode. When @value{GDBN} is in the standard mode, most
27941 of these commands will automatically switch to the TUI mode.
27942
27943 Note that if @value{GDBN}'s @code{stdout} is not connected to a
27944 terminal, or @value{GDBN} has been started with the machine interface
27945 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27946 these commands will fail with an error, because it would not be
27947 possible or desirable to enable curses window management.
27948
27949 @table @code
27950 @item tui enable
27951 @kindex tui enable
27952 Activate TUI mode. The last active TUI window layout will be used if
27953 TUI mode has previously been used in the current debugging session,
27954 otherwise a default layout is used.
27955
27956 @item tui disable
27957 @kindex tui disable
27958 Disable TUI mode, returning to the console interpreter.
27959
27960 @item info win
27961 @kindex info win
27962 List and give the size of all displayed windows.
27963
27964 @item layout @var{name}
27965 @kindex layout
27966 Changes which TUI windows are displayed. In each layout the command
27967 window is always displayed, the @var{name} parameter controls which
27968 additional windows are displayed, and can be any of the following:
27969
27970 @table @code
27971 @item next
27972 Display the next layout.
27973
27974 @item prev
27975 Display the previous layout.
27976
27977 @item src
27978 Display the source and command windows.
27979
27980 @item asm
27981 Display the assembly and command windows.
27982
27983 @item split
27984 Display the source, assembly, and command windows.
27985
27986 @item regs
27987 When in @code{src} layout display the register, source, and command
27988 windows. When in @code{asm} or @code{split} layout display the
27989 register, assembler, and command windows.
27990 @end table
27991
27992 @item focus @var{name}
27993 @kindex focus
27994 Changes which TUI window is currently active for scrolling. The
27995 @var{name} parameter can be any of the following:
27996
27997 @table @code
27998 @item next
27999 Make the next window active for scrolling.
28000
28001 @item prev
28002 Make the previous window active for scrolling.
28003
28004 @item src
28005 Make the source window active for scrolling.
28006
28007 @item asm
28008 Make the assembly window active for scrolling.
28009
28010 @item regs
28011 Make the register window active for scrolling.
28012
28013 @item cmd
28014 Make the command window active for scrolling.
28015 @end table
28016
28017 @item refresh
28018 @kindex refresh
28019 Refresh the screen. This is similar to typing @kbd{C-L}.
28020
28021 @item tui reg @var{group}
28022 @kindex tui reg
28023 Changes the register group displayed in the tui register window to
28024 @var{group}. If the register window is not currently displayed this
28025 command will cause the register window to be displayed. The list of
28026 register groups, as well as their order is target specific. The
28027 following groups are available on most targets:
28028 @table @code
28029 @item next
28030 Repeatedly selecting this group will cause the display to cycle
28031 through all of the available register groups.
28032
28033 @item prev
28034 Repeatedly selecting this group will cause the display to cycle
28035 through all of the available register groups in the reverse order to
28036 @var{next}.
28037
28038 @item general
28039 Display the general registers.
28040 @item float
28041 Display the floating point registers.
28042 @item system
28043 Display the system registers.
28044 @item vector
28045 Display the vector registers.
28046 @item all
28047 Display all registers.
28048 @end table
28049
28050 @item update
28051 @kindex update
28052 Update the source window and the current execution point.
28053
28054 @item winheight @var{name} +@var{count}
28055 @itemx winheight @var{name} -@var{count}
28056 @kindex winheight
28057 Change the height of the window @var{name} by @var{count}
28058 lines. Positive counts increase the height, while negative counts
28059 decrease it. The @var{name} parameter can be one of @code{src} (the
28060 source window), @code{cmd} (the command window), @code{asm} (the
28061 disassembly window), or @code{regs} (the register display window).
28062 @end table
28063
28064 @node TUI Configuration
28065 @section TUI Configuration Variables
28066 @cindex TUI configuration variables
28067
28068 Several configuration variables control the appearance of TUI windows.
28069
28070 @table @code
28071 @item set tui border-kind @var{kind}
28072 @kindex set tui border-kind
28073 Select the border appearance for the source, assembly and register windows.
28074 The possible values are the following:
28075 @table @code
28076 @item space
28077 Use a space character to draw the border.
28078
28079 @item ascii
28080 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28081
28082 @item acs
28083 Use the Alternate Character Set to draw the border. The border is
28084 drawn using character line graphics if the terminal supports them.
28085 @end table
28086
28087 @item set tui border-mode @var{mode}
28088 @kindex set tui border-mode
28089 @itemx set tui active-border-mode @var{mode}
28090 @kindex set tui active-border-mode
28091 Select the display attributes for the borders of the inactive windows
28092 or the active window. The @var{mode} can be one of the following:
28093 @table @code
28094 @item normal
28095 Use normal attributes to display the border.
28096
28097 @item standout
28098 Use standout mode.
28099
28100 @item reverse
28101 Use reverse video mode.
28102
28103 @item half
28104 Use half bright mode.
28105
28106 @item half-standout
28107 Use half bright and standout mode.
28108
28109 @item bold
28110 Use extra bright or bold mode.
28111
28112 @item bold-standout
28113 Use extra bright or bold and standout mode.
28114 @end table
28115
28116 @item set tui tab-width @var{nchars}
28117 @kindex set tui tab-width
28118 @kindex tabset
28119 Set the width of tab stops to be @var{nchars} characters. This
28120 setting affects the display of TAB characters in the source and
28121 assembly windows.
28122
28123 @item set tui compact-source @r{[}on@r{|}off@r{]}
28124 @kindex set tui compact-source
28125 Set whether the TUI source window is displayed in ``compact'' form.
28126 The default display uses more space for line numbers and starts the
28127 source text at the next tab stop; the compact display uses only as
28128 much space as is needed for the line numbers in the current file, and
28129 only a single space to separate the line numbers from the source.
28130 @end table
28131
28132 Note that the colors of the TUI borders can be controlled using the
28133 appropriate @code{set style} commands. @xref{Output Styling}.
28134
28135 @node Emacs
28136 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28137
28138 @cindex Emacs
28139 @cindex @sc{gnu} Emacs
28140 A special interface allows you to use @sc{gnu} Emacs to view (and
28141 edit) the source files for the program you are debugging with
28142 @value{GDBN}.
28143
28144 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28145 executable file you want to debug as an argument. This command starts
28146 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28147 created Emacs buffer.
28148 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28149
28150 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28151 things:
28152
28153 @itemize @bullet
28154 @item
28155 All ``terminal'' input and output goes through an Emacs buffer, called
28156 the GUD buffer.
28157
28158 This applies both to @value{GDBN} commands and their output, and to the input
28159 and output done by the program you are debugging.
28160
28161 This is useful because it means that you can copy the text of previous
28162 commands and input them again; you can even use parts of the output
28163 in this way.
28164
28165 All the facilities of Emacs' Shell mode are available for interacting
28166 with your program. In particular, you can send signals the usual
28167 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28168 stop.
28169
28170 @item
28171 @value{GDBN} displays source code through Emacs.
28172
28173 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28174 source file for that frame and puts an arrow (@samp{=>}) at the
28175 left margin of the current line. Emacs uses a separate buffer for
28176 source display, and splits the screen to show both your @value{GDBN} session
28177 and the source.
28178
28179 Explicit @value{GDBN} @code{list} or search commands still produce output as
28180 usual, but you probably have no reason to use them from Emacs.
28181 @end itemize
28182
28183 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28184 a graphical mode, enabled by default, which provides further buffers
28185 that can control the execution and describe the state of your program.
28186 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28187
28188 If you specify an absolute file name when prompted for the @kbd{M-x
28189 gdb} argument, then Emacs sets your current working directory to where
28190 your program resides. If you only specify the file name, then Emacs
28191 sets your current working directory to the directory associated
28192 with the previous buffer. In this case, @value{GDBN} may find your
28193 program by searching your environment's @code{PATH} variable, but on
28194 some operating systems it might not find the source. So, although the
28195 @value{GDBN} input and output session proceeds normally, the auxiliary
28196 buffer does not display the current source and line of execution.
28197
28198 The initial working directory of @value{GDBN} is printed on the top
28199 line of the GUD buffer and this serves as a default for the commands
28200 that specify files for @value{GDBN} to operate on. @xref{Files,
28201 ,Commands to Specify Files}.
28202
28203 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28204 need to call @value{GDBN} by a different name (for example, if you
28205 keep several configurations around, with different names) you can
28206 customize the Emacs variable @code{gud-gdb-command-name} to run the
28207 one you want.
28208
28209 In the GUD buffer, you can use these special Emacs commands in
28210 addition to the standard Shell mode commands:
28211
28212 @table @kbd
28213 @item C-h m
28214 Describe the features of Emacs' GUD Mode.
28215
28216 @item C-c C-s
28217 Execute to another source line, like the @value{GDBN} @code{step} command; also
28218 update the display window to show the current file and location.
28219
28220 @item C-c C-n
28221 Execute to next source line in this function, skipping all function
28222 calls, like the @value{GDBN} @code{next} command. Then update the display window
28223 to show the current file and location.
28224
28225 @item C-c C-i
28226 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28227 display window accordingly.
28228
28229 @item C-c C-f
28230 Execute until exit from the selected stack frame, like the @value{GDBN}
28231 @code{finish} command.
28232
28233 @item C-c C-r
28234 Continue execution of your program, like the @value{GDBN} @code{continue}
28235 command.
28236
28237 @item C-c <
28238 Go up the number of frames indicated by the numeric argument
28239 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28240 like the @value{GDBN} @code{up} command.
28241
28242 @item C-c >
28243 Go down the number of frames indicated by the numeric argument, like the
28244 @value{GDBN} @code{down} command.
28245 @end table
28246
28247 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28248 tells @value{GDBN} to set a breakpoint on the source line point is on.
28249
28250 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28251 separate frame which shows a backtrace when the GUD buffer is current.
28252 Move point to any frame in the stack and type @key{RET} to make it
28253 become the current frame and display the associated source in the
28254 source buffer. Alternatively, click @kbd{Mouse-2} to make the
28255 selected frame become the current one. In graphical mode, the
28256 speedbar displays watch expressions.
28257
28258 If you accidentally delete the source-display buffer, an easy way to get
28259 it back is to type the command @code{f} in the @value{GDBN} buffer, to
28260 request a frame display; when you run under Emacs, this recreates
28261 the source buffer if necessary to show you the context of the current
28262 frame.
28263
28264 The source files displayed in Emacs are in ordinary Emacs buffers
28265 which are visiting the source files in the usual way. You can edit
28266 the files with these buffers if you wish; but keep in mind that @value{GDBN}
28267 communicates with Emacs in terms of line numbers. If you add or
28268 delete lines from the text, the line numbers that @value{GDBN} knows cease
28269 to correspond properly with the code.
28270
28271 A more detailed description of Emacs' interaction with @value{GDBN} is
28272 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28273 Emacs Manual}).
28274
28275 @node GDB/MI
28276 @chapter The @sc{gdb/mi} Interface
28277
28278 @unnumberedsec Function and Purpose
28279
28280 @cindex @sc{gdb/mi}, its purpose
28281 @sc{gdb/mi} is a line based machine oriented text interface to
28282 @value{GDBN} and is activated by specifying using the
28283 @option{--interpreter} command line option (@pxref{Mode Options}). It
28284 is specifically intended to support the development of systems which
28285 use the debugger as just one small component of a larger system.
28286
28287 This chapter is a specification of the @sc{gdb/mi} interface. It is written
28288 in the form of a reference manual.
28289
28290 Note that @sc{gdb/mi} is still under construction, so some of the
28291 features described below are incomplete and subject to change
28292 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28293
28294 @unnumberedsec Notation and Terminology
28295
28296 @cindex notational conventions, for @sc{gdb/mi}
28297 This chapter uses the following notation:
28298
28299 @itemize @bullet
28300 @item
28301 @code{|} separates two alternatives.
28302
28303 @item
28304 @code{[ @var{something} ]} indicates that @var{something} is optional:
28305 it may or may not be given.
28306
28307 @item
28308 @code{( @var{group} )*} means that @var{group} inside the parentheses
28309 may repeat zero or more times.
28310
28311 @item
28312 @code{( @var{group} )+} means that @var{group} inside the parentheses
28313 may repeat one or more times.
28314
28315 @item
28316 @code{"@var{string}"} means a literal @var{string}.
28317 @end itemize
28318
28319 @ignore
28320 @heading Dependencies
28321 @end ignore
28322
28323 @menu
28324 * GDB/MI General Design::
28325 * GDB/MI Command Syntax::
28326 * GDB/MI Compatibility with CLI::
28327 * GDB/MI Development and Front Ends::
28328 * GDB/MI Output Records::
28329 * GDB/MI Simple Examples::
28330 * GDB/MI Command Description Format::
28331 * GDB/MI Breakpoint Commands::
28332 * GDB/MI Catchpoint Commands::
28333 * GDB/MI Program Context::
28334 * GDB/MI Thread Commands::
28335 * GDB/MI Ada Tasking Commands::
28336 * GDB/MI Program Execution::
28337 * GDB/MI Stack Manipulation::
28338 * GDB/MI Variable Objects::
28339 * GDB/MI Data Manipulation::
28340 * GDB/MI Tracepoint Commands::
28341 * GDB/MI Symbol Query::
28342 * GDB/MI File Commands::
28343 @ignore
28344 * GDB/MI Kod Commands::
28345 * GDB/MI Memory Overlay Commands::
28346 * GDB/MI Signal Handling Commands::
28347 @end ignore
28348 * GDB/MI Target Manipulation::
28349 * GDB/MI File Transfer Commands::
28350 * GDB/MI Ada Exceptions Commands::
28351 * GDB/MI Support Commands::
28352 * GDB/MI Miscellaneous Commands::
28353 @end menu
28354
28355 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28356 @node GDB/MI General Design
28357 @section @sc{gdb/mi} General Design
28358 @cindex GDB/MI General Design
28359
28360 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28361 parts---commands sent to @value{GDBN}, responses to those commands
28362 and notifications. Each command results in exactly one response,
28363 indicating either successful completion of the command, or an error.
28364 For the commands that do not resume the target, the response contains the
28365 requested information. For the commands that resume the target, the
28366 response only indicates whether the target was successfully resumed.
28367 Notifications is the mechanism for reporting changes in the state of the
28368 target, or in @value{GDBN} state, that cannot conveniently be associated with
28369 a command and reported as part of that command response.
28370
28371 The important examples of notifications are:
28372 @itemize @bullet
28373
28374 @item
28375 Exec notifications. These are used to report changes in
28376 target state---when a target is resumed, or stopped. It would not
28377 be feasible to include this information in response of resuming
28378 commands, because one resume commands can result in multiple events in
28379 different threads. Also, quite some time may pass before any event
28380 happens in the target, while a frontend needs to know whether the resuming
28381 command itself was successfully executed.
28382
28383 @item
28384 Console output, and status notifications. Console output
28385 notifications are used to report output of CLI commands, as well as
28386 diagnostics for other commands. Status notifications are used to
28387 report the progress of a long-running operation. Naturally, including
28388 this information in command response would mean no output is produced
28389 until the command is finished, which is undesirable.
28390
28391 @item
28392 General notifications. Commands may have various side effects on
28393 the @value{GDBN} or target state beyond their official purpose. For example,
28394 a command may change the selected thread. Although such changes can
28395 be included in command response, using notification allows for more
28396 orthogonal frontend design.
28397
28398 @end itemize
28399
28400 There's no guarantee that whenever an MI command reports an error,
28401 @value{GDBN} or the target are in any specific state, and especially,
28402 the state is not reverted to the state before the MI command was
28403 processed. Therefore, whenever an MI command results in an error,
28404 we recommend that the frontend refreshes all the information shown in
28405 the user interface.
28406
28407
28408 @menu
28409 * Context management::
28410 * Asynchronous and non-stop modes::
28411 * Thread groups::
28412 @end menu
28413
28414 @node Context management
28415 @subsection Context management
28416
28417 @subsubsection Threads and Frames
28418
28419 In most cases when @value{GDBN} accesses the target, this access is
28420 done in context of a specific thread and frame (@pxref{Frames}).
28421 Often, even when accessing global data, the target requires that a thread
28422 be specified. The CLI interface maintains the selected thread and frame,
28423 and supplies them to target on each command. This is convenient,
28424 because a command line user would not want to specify that information
28425 explicitly on each command, and because user interacts with
28426 @value{GDBN} via a single terminal, so no confusion is possible as
28427 to what thread and frame are the current ones.
28428
28429 In the case of MI, the concept of selected thread and frame is less
28430 useful. First, a frontend can easily remember this information
28431 itself. Second, a graphical frontend can have more than one window,
28432 each one used for debugging a different thread, and the frontend might
28433 want to access additional threads for internal purposes. This
28434 increases the risk that by relying on implicitly selected thread, the
28435 frontend may be operating on a wrong one. Therefore, each MI command
28436 should explicitly specify which thread and frame to operate on. To
28437 make it possible, each MI command accepts the @samp{--thread} and
28438 @samp{--frame} options, the value to each is @value{GDBN} global
28439 identifier for thread and frame to operate on.
28440
28441 Usually, each top-level window in a frontend allows the user to select
28442 a thread and a frame, and remembers the user selection for further
28443 operations. However, in some cases @value{GDBN} may suggest that the
28444 current thread or frame be changed. For example, when stopping on a
28445 breakpoint it is reasonable to switch to the thread where breakpoint is
28446 hit. For another example, if the user issues the CLI @samp{thread} or
28447 @samp{frame} commands via the frontend, it is desirable to change the
28448 frontend's selection to the one specified by user. @value{GDBN}
28449 communicates the suggestion to change current thread and frame using the
28450 @samp{=thread-selected} notification.
28451
28452 Note that historically, MI shares the selected thread with CLI, so
28453 frontends used the @code{-thread-select} to execute commands in the
28454 right context. However, getting this to work right is cumbersome. The
28455 simplest way is for frontend to emit @code{-thread-select} command
28456 before every command. This doubles the number of commands that need
28457 to be sent. The alternative approach is to suppress @code{-thread-select}
28458 if the selected thread in @value{GDBN} is supposed to be identical to the
28459 thread the frontend wants to operate on. However, getting this
28460 optimization right can be tricky. In particular, if the frontend
28461 sends several commands to @value{GDBN}, and one of the commands changes the
28462 selected thread, then the behaviour of subsequent commands will
28463 change. So, a frontend should either wait for response from such
28464 problematic commands, or explicitly add @code{-thread-select} for
28465 all subsequent commands. No frontend is known to do this exactly
28466 right, so it is suggested to just always pass the @samp{--thread} and
28467 @samp{--frame} options.
28468
28469 @subsubsection Language
28470
28471 The execution of several commands depends on which language is selected.
28472 By default, the current language (@pxref{show language}) is used.
28473 But for commands known to be language-sensitive, it is recommended
28474 to use the @samp{--language} option. This option takes one argument,
28475 which is the name of the language to use while executing the command.
28476 For instance:
28477
28478 @smallexample
28479 -data-evaluate-expression --language c "sizeof (void*)"
28480 ^done,value="4"
28481 (gdb)
28482 @end smallexample
28483
28484 The valid language names are the same names accepted by the
28485 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28486 @samp{local} or @samp{unknown}.
28487
28488 @node Asynchronous and non-stop modes
28489 @subsection Asynchronous command execution and non-stop mode
28490
28491 On some targets, @value{GDBN} is capable of processing MI commands
28492 even while the target is running. This is called @dfn{asynchronous
28493 command execution} (@pxref{Background Execution}). The frontend may
28494 specify a preference for asynchronous execution using the
28495 @code{-gdb-set mi-async 1} command, which should be emitted before
28496 either running the executable or attaching to the target. After the
28497 frontend has started the executable or attached to the target, it can
28498 find if asynchronous execution is enabled using the
28499 @code{-list-target-features} command.
28500
28501 @table @code
28502 @item -gdb-set mi-async on
28503 @item -gdb-set mi-async off
28504 Set whether MI is in asynchronous mode.
28505
28506 When @code{off}, which is the default, MI execution commands (e.g.,
28507 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28508 for the program to stop before processing further commands.
28509
28510 When @code{on}, MI execution commands are background execution
28511 commands (e.g., @code{-exec-continue} becomes the equivalent of the
28512 @code{c&} CLI command), and so @value{GDBN} is capable of processing
28513 MI commands even while the target is running.
28514
28515 @item -gdb-show mi-async
28516 Show whether MI asynchronous mode is enabled.
28517 @end table
28518
28519 Note: In @value{GDBN} version 7.7 and earlier, this option was called
28520 @code{target-async} instead of @code{mi-async}, and it had the effect
28521 of both putting MI in asynchronous mode and making CLI background
28522 commands possible. CLI background commands are now always possible
28523 ``out of the box'' if the target supports them. The old spelling is
28524 kept as a deprecated alias for backwards compatibility.
28525
28526 Even if @value{GDBN} can accept a command while target is running,
28527 many commands that access the target do not work when the target is
28528 running. Therefore, asynchronous command execution is most useful
28529 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28530 it is possible to examine the state of one thread, while other threads
28531 are running.
28532
28533 When a given thread is running, MI commands that try to access the
28534 target in the context of that thread may not work, or may work only on
28535 some targets. In particular, commands that try to operate on thread's
28536 stack will not work, on any target. Commands that read memory, or
28537 modify breakpoints, may work or not work, depending on the target. Note
28538 that even commands that operate on global state, such as @code{print},
28539 @code{set}, and breakpoint commands, still access the target in the
28540 context of a specific thread, so frontend should try to find a
28541 stopped thread and perform the operation on that thread (using the
28542 @samp{--thread} option).
28543
28544 Which commands will work in the context of a running thread is
28545 highly target dependent. However, the two commands
28546 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28547 to find the state of a thread, will always work.
28548
28549 @node Thread groups
28550 @subsection Thread groups
28551 @value{GDBN} may be used to debug several processes at the same time.
28552 On some platforms, @value{GDBN} may support debugging of several
28553 hardware systems, each one having several cores with several different
28554 processes running on each core. This section describes the MI
28555 mechanism to support such debugging scenarios.
28556
28557 The key observation is that regardless of the structure of the
28558 target, MI can have a global list of threads, because most commands that
28559 accept the @samp{--thread} option do not need to know what process that
28560 thread belongs to. Therefore, it is not necessary to introduce
28561 neither additional @samp{--process} option, nor an notion of the
28562 current process in the MI interface. The only strictly new feature
28563 that is required is the ability to find how the threads are grouped
28564 into processes.
28565
28566 To allow the user to discover such grouping, and to support arbitrary
28567 hierarchy of machines/cores/processes, MI introduces the concept of a
28568 @dfn{thread group}. Thread group is a collection of threads and other
28569 thread groups. A thread group always has a string identifier, a type,
28570 and may have additional attributes specific to the type. A new
28571 command, @code{-list-thread-groups}, returns the list of top-level
28572 thread groups, which correspond to processes that @value{GDBN} is
28573 debugging at the moment. By passing an identifier of a thread group
28574 to the @code{-list-thread-groups} command, it is possible to obtain
28575 the members of specific thread group.
28576
28577 To allow the user to easily discover processes, and other objects, he
28578 wishes to debug, a concept of @dfn{available thread group} is
28579 introduced. Available thread group is an thread group that
28580 @value{GDBN} is not debugging, but that can be attached to, using the
28581 @code{-target-attach} command. The list of available top-level thread
28582 groups can be obtained using @samp{-list-thread-groups --available}.
28583 In general, the content of a thread group may be only retrieved only
28584 after attaching to that thread group.
28585
28586 Thread groups are related to inferiors (@pxref{Inferiors Connections and
28587 Programs}). Each inferior corresponds to a thread group of a special
28588 type @samp{process}, and some additional operations are permitted on
28589 such thread groups.
28590
28591 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28592 @node GDB/MI Command Syntax
28593 @section @sc{gdb/mi} Command Syntax
28594
28595 @menu
28596 * GDB/MI Input Syntax::
28597 * GDB/MI Output Syntax::
28598 @end menu
28599
28600 @node GDB/MI Input Syntax
28601 @subsection @sc{gdb/mi} Input Syntax
28602
28603 @cindex input syntax for @sc{gdb/mi}
28604 @cindex @sc{gdb/mi}, input syntax
28605 @table @code
28606 @item @var{command} @expansion{}
28607 @code{@var{cli-command} | @var{mi-command}}
28608
28609 @item @var{cli-command} @expansion{}
28610 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28611 @var{cli-command} is any existing @value{GDBN} CLI command.
28612
28613 @item @var{mi-command} @expansion{}
28614 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28615 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28616
28617 @item @var{token} @expansion{}
28618 "any sequence of digits"
28619
28620 @item @var{option} @expansion{}
28621 @code{"-" @var{parameter} [ " " @var{parameter} ]}
28622
28623 @item @var{parameter} @expansion{}
28624 @code{@var{non-blank-sequence} | @var{c-string}}
28625
28626 @item @var{operation} @expansion{}
28627 @emph{any of the operations described in this chapter}
28628
28629 @item @var{non-blank-sequence} @expansion{}
28630 @emph{anything, provided it doesn't contain special characters such as
28631 "-", @var{nl}, """ and of course " "}
28632
28633 @item @var{c-string} @expansion{}
28634 @code{""" @var{seven-bit-iso-c-string-content} """}
28635
28636 @item @var{nl} @expansion{}
28637 @code{CR | CR-LF}
28638 @end table
28639
28640 @noindent
28641 Notes:
28642
28643 @itemize @bullet
28644 @item
28645 The CLI commands are still handled by the @sc{mi} interpreter; their
28646 output is described below.
28647
28648 @item
28649 The @code{@var{token}}, when present, is passed back when the command
28650 finishes.
28651
28652 @item
28653 Some @sc{mi} commands accept optional arguments as part of the parameter
28654 list. Each option is identified by a leading @samp{-} (dash) and may be
28655 followed by an optional argument parameter. Options occur first in the
28656 parameter list and can be delimited from normal parameters using
28657 @samp{--} (this is useful when some parameters begin with a dash).
28658 @end itemize
28659
28660 Pragmatics:
28661
28662 @itemize @bullet
28663 @item
28664 We want easy access to the existing CLI syntax (for debugging).
28665
28666 @item
28667 We want it to be easy to spot a @sc{mi} operation.
28668 @end itemize
28669
28670 @node GDB/MI Output Syntax
28671 @subsection @sc{gdb/mi} Output Syntax
28672
28673 @cindex output syntax of @sc{gdb/mi}
28674 @cindex @sc{gdb/mi}, output syntax
28675 The output from @sc{gdb/mi} consists of zero or more out-of-band records
28676 followed, optionally, by a single result record. This result record
28677 is for the most recent command. The sequence of output records is
28678 terminated by @samp{(gdb)}.
28679
28680 If an input command was prefixed with a @code{@var{token}} then the
28681 corresponding output for that command will also be prefixed by that same
28682 @var{token}.
28683
28684 @table @code
28685 @item @var{output} @expansion{}
28686 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
28687
28688 @item @var{result-record} @expansion{}
28689 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28690
28691 @item @var{out-of-band-record} @expansion{}
28692 @code{@var{async-record} | @var{stream-record}}
28693
28694 @item @var{async-record} @expansion{}
28695 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28696
28697 @item @var{exec-async-output} @expansion{}
28698 @code{[ @var{token} ] "*" @var{async-output nl}}
28699
28700 @item @var{status-async-output} @expansion{}
28701 @code{[ @var{token} ] "+" @var{async-output nl}}
28702
28703 @item @var{notify-async-output} @expansion{}
28704 @code{[ @var{token} ] "=" @var{async-output nl}}
28705
28706 @item @var{async-output} @expansion{}
28707 @code{@var{async-class} ( "," @var{result} )*}
28708
28709 @item @var{result-class} @expansion{}
28710 @code{"done" | "running" | "connected" | "error" | "exit"}
28711
28712 @item @var{async-class} @expansion{}
28713 @code{"stopped" | @var{others}} (where @var{others} will be added
28714 depending on the needs---this is still in development).
28715
28716 @item @var{result} @expansion{}
28717 @code{ @var{variable} "=" @var{value}}
28718
28719 @item @var{variable} @expansion{}
28720 @code{ @var{string} }
28721
28722 @item @var{value} @expansion{}
28723 @code{ @var{const} | @var{tuple} | @var{list} }
28724
28725 @item @var{const} @expansion{}
28726 @code{@var{c-string}}
28727
28728 @item @var{tuple} @expansion{}
28729 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28730
28731 @item @var{list} @expansion{}
28732 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28733 @var{result} ( "," @var{result} )* "]" }
28734
28735 @item @var{stream-record} @expansion{}
28736 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28737
28738 @item @var{console-stream-output} @expansion{}
28739 @code{"~" @var{c-string nl}}
28740
28741 @item @var{target-stream-output} @expansion{}
28742 @code{"@@" @var{c-string nl}}
28743
28744 @item @var{log-stream-output} @expansion{}
28745 @code{"&" @var{c-string nl}}
28746
28747 @item @var{nl} @expansion{}
28748 @code{CR | CR-LF}
28749
28750 @item @var{token} @expansion{}
28751 @emph{any sequence of digits}.
28752 @end table
28753
28754 @noindent
28755 Notes:
28756
28757 @itemize @bullet
28758 @item
28759 All output sequences end in a single line containing a period.
28760
28761 @item
28762 The @code{@var{token}} is from the corresponding request. Note that
28763 for all async output, while the token is allowed by the grammar and
28764 may be output by future versions of @value{GDBN} for select async
28765 output messages, it is generally omitted. Frontends should treat
28766 all async output as reporting general changes in the state of the
28767 target and there should be no need to associate async output to any
28768 prior command.
28769
28770 @item
28771 @cindex status output in @sc{gdb/mi}
28772 @var{status-async-output} contains on-going status information about the
28773 progress of a slow operation. It can be discarded. All status output is
28774 prefixed by @samp{+}.
28775
28776 @item
28777 @cindex async output in @sc{gdb/mi}
28778 @var{exec-async-output} contains asynchronous state change on the target
28779 (stopped, started, disappeared). All async output is prefixed by
28780 @samp{*}.
28781
28782 @item
28783 @cindex notify output in @sc{gdb/mi}
28784 @var{notify-async-output} contains supplementary information that the
28785 client should handle (e.g., a new breakpoint information). All notify
28786 output is prefixed by @samp{=}.
28787
28788 @item
28789 @cindex console output in @sc{gdb/mi}
28790 @var{console-stream-output} is output that should be displayed as is in the
28791 console. It is the textual response to a CLI command. All the console
28792 output is prefixed by @samp{~}.
28793
28794 @item
28795 @cindex target output in @sc{gdb/mi}
28796 @var{target-stream-output} is the output produced by the target program.
28797 All the target output is prefixed by @samp{@@}.
28798
28799 @item
28800 @cindex log output in @sc{gdb/mi}
28801 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
28802 instance messages that should be displayed as part of an error log. All
28803 the log output is prefixed by @samp{&}.
28804
28805 @item
28806 @cindex list output in @sc{gdb/mi}
28807 New @sc{gdb/mi} commands should only output @var{lists} containing
28808 @var{values}.
28809
28810
28811 @end itemize
28812
28813 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
28814 details about the various output records.
28815
28816 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28817 @node GDB/MI Compatibility with CLI
28818 @section @sc{gdb/mi} Compatibility with CLI
28819
28820 @cindex compatibility, @sc{gdb/mi} and CLI
28821 @cindex @sc{gdb/mi}, compatibility with CLI
28822
28823 For the developers convenience CLI commands can be entered directly,
28824 but there may be some unexpected behaviour. For example, commands
28825 that query the user will behave as if the user replied yes, breakpoint
28826 command lists are not executed and some CLI commands, such as
28827 @code{if}, @code{when} and @code{define}, prompt for further input with
28828 @samp{>}, which is not valid MI output.
28829
28830 This feature may be removed at some stage in the future and it is
28831 recommended that front ends use the @code{-interpreter-exec} command
28832 (@pxref{-interpreter-exec}).
28833
28834 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28835 @node GDB/MI Development and Front Ends
28836 @section @sc{gdb/mi} Development and Front Ends
28837 @cindex @sc{gdb/mi} development
28838
28839 The application which takes the MI output and presents the state of the
28840 program being debugged to the user is called a @dfn{front end}.
28841
28842 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
28843 to the MI interface may break existing usage. This section describes how the
28844 protocol changes and how to request previous version of the protocol when it
28845 does.
28846
28847 Some changes in MI need not break a carefully designed front end, and
28848 for these the MI version will remain unchanged. The following is a
28849 list of changes that may occur within one level, so front ends should
28850 parse MI output in a way that can handle them:
28851
28852 @itemize @bullet
28853 @item
28854 New MI commands may be added.
28855
28856 @item
28857 New fields may be added to the output of any MI command.
28858
28859 @item
28860 The range of values for fields with specified values, e.g.,
28861 @code{in_scope} (@pxref{-var-update}) may be extended.
28862
28863 @c The format of field's content e.g type prefix, may change so parse it
28864 @c at your own risk. Yes, in general?
28865
28866 @c The order of fields may change? Shouldn't really matter but it might
28867 @c resolve inconsistencies.
28868 @end itemize
28869
28870 If the changes are likely to break front ends, the MI version level
28871 will be increased by one. The new versions of the MI protocol are not compatible
28872 with the old versions. Old versions of MI remain available, allowing front ends
28873 to keep using them until they are modified to use the latest MI version.
28874
28875 Since @code{--interpreter=mi} always points to the latest MI version, it is
28876 recommended that front ends request a specific version of MI when launching
28877 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
28878 interpreter with the MI version they expect.
28879
28880 The following table gives a summary of the the released versions of the MI
28881 interface: the version number, the version of GDB in which it first appeared
28882 and the breaking changes compared to the previous version.
28883
28884 @multitable @columnfractions .05 .05 .9
28885 @headitem MI version @tab GDB version @tab Breaking changes
28886
28887 @item
28888 @center 1
28889 @tab
28890 @center 5.1
28891 @tab
28892 None
28893
28894 @item
28895 @center 2
28896 @tab
28897 @center 6.0
28898 @tab
28899
28900 @itemize
28901 @item
28902 The @code{-environment-pwd}, @code{-environment-directory} and
28903 @code{-environment-path} commands now returns values using the MI output
28904 syntax, rather than CLI output syntax.
28905
28906 @item
28907 @code{-var-list-children}'s @code{children} result field is now a list, rather
28908 than a tuple.
28909
28910 @item
28911 @code{-var-update}'s @code{changelist} result field is now a list, rather than
28912 a tuple.
28913 @end itemize
28914
28915 @item
28916 @center 3
28917 @tab
28918 @center 9.1
28919 @tab
28920
28921 @itemize
28922 @item
28923 The output of information about multi-location breakpoints has changed in the
28924 responses to the @code{-break-insert} and @code{-break-info} commands, as well
28925 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
28926 The multiple locations are now placed in a @code{locations} field, whose value
28927 is a list.
28928 @end itemize
28929
28930 @end multitable
28931
28932 If your front end cannot yet migrate to a more recent version of the
28933 MI protocol, you can nevertheless selectively enable specific features
28934 available in those recent MI versions, using the following commands:
28935
28936 @table @code
28937
28938 @item -fix-multi-location-breakpoint-output
28939 Use the output for multi-location breakpoints which was introduced by
28940 MI 3, even when using MI versions 2 or 1. This command has no
28941 effect when using MI version 3 or later.
28942
28943 @end table
28944
28945 The best way to avoid unexpected changes in MI that might break your front
28946 end is to make your project known to @value{GDBN} developers and
28947 follow development on @email{gdb@@sourceware.org} and
28948 @email{gdb-patches@@sourceware.org}.
28949 @cindex mailing lists
28950
28951 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28952 @node GDB/MI Output Records
28953 @section @sc{gdb/mi} Output Records
28954
28955 @menu
28956 * GDB/MI Result Records::
28957 * GDB/MI Stream Records::
28958 * GDB/MI Async Records::
28959 * GDB/MI Breakpoint Information::
28960 * GDB/MI Frame Information::
28961 * GDB/MI Thread Information::
28962 * GDB/MI Ada Exception Information::
28963 @end menu
28964
28965 @node GDB/MI Result Records
28966 @subsection @sc{gdb/mi} Result Records
28967
28968 @cindex result records in @sc{gdb/mi}
28969 @cindex @sc{gdb/mi}, result records
28970 In addition to a number of out-of-band notifications, the response to a
28971 @sc{gdb/mi} command includes one of the following result indications:
28972
28973 @table @code
28974 @findex ^done
28975 @item "^done" [ "," @var{results} ]
28976 The synchronous operation was successful, @code{@var{results}} are the return
28977 values.
28978
28979 @item "^running"
28980 @findex ^running
28981 This result record is equivalent to @samp{^done}. Historically, it
28982 was output instead of @samp{^done} if the command has resumed the
28983 target. This behaviour is maintained for backward compatibility, but
28984 all frontends should treat @samp{^done} and @samp{^running}
28985 identically and rely on the @samp{*running} output record to determine
28986 which threads are resumed.
28987
28988 @item "^connected"
28989 @findex ^connected
28990 @value{GDBN} has connected to a remote target.
28991
28992 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
28993 @findex ^error
28994 The operation failed. The @code{msg=@var{c-string}} variable contains
28995 the corresponding error message.
28996
28997 If present, the @code{code=@var{c-string}} variable provides an error
28998 code on which consumers can rely on to detect the corresponding
28999 error condition. At present, only one error code is defined:
29000
29001 @table @samp
29002 @item "undefined-command"
29003 Indicates that the command causing the error does not exist.
29004 @end table
29005
29006 @item "^exit"
29007 @findex ^exit
29008 @value{GDBN} has terminated.
29009
29010 @end table
29011
29012 @node GDB/MI Stream Records
29013 @subsection @sc{gdb/mi} Stream Records
29014
29015 @cindex @sc{gdb/mi}, stream records
29016 @cindex stream records in @sc{gdb/mi}
29017 @value{GDBN} internally maintains a number of output streams: the console, the
29018 target, and the log. The output intended for each of these streams is
29019 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29020
29021 Each stream record begins with a unique @dfn{prefix character} which
29022 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29023 Syntax}). In addition to the prefix, each stream record contains a
29024 @code{@var{string-output}}. This is either raw text (with an implicit new
29025 line) or a quoted C string (which does not contain an implicit newline).
29026
29027 @table @code
29028 @item "~" @var{string-output}
29029 The console output stream contains text that should be displayed in the
29030 CLI console window. It contains the textual responses to CLI commands.
29031
29032 @item "@@" @var{string-output}
29033 The target output stream contains any textual output from the running
29034 target. This is only present when GDB's event loop is truly
29035 asynchronous, which is currently only the case for remote targets.
29036
29037 @item "&" @var{string-output}
29038 The log stream contains debugging messages being produced by @value{GDBN}'s
29039 internals.
29040 @end table
29041
29042 @node GDB/MI Async Records
29043 @subsection @sc{gdb/mi} Async Records
29044
29045 @cindex async records in @sc{gdb/mi}
29046 @cindex @sc{gdb/mi}, async records
29047 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29048 additional changes that have occurred. Those changes can either be a
29049 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29050 target activity (e.g., target stopped).
29051
29052 The following is the list of possible async records:
29053
29054 @table @code
29055
29056 @item *running,thread-id="@var{thread}"
29057 The target is now running. The @var{thread} field can be the global
29058 thread ID of the the thread that is now running, and it can be
29059 @samp{all} if all threads are running. The frontend should assume
29060 that no interaction with a running thread is possible after this
29061 notification is produced. The frontend should not assume that this
29062 notification is output only once for any command. @value{GDBN} may
29063 emit this notification several times, either for different threads,
29064 because it cannot resume all threads together, or even for a single
29065 thread, if the thread must be stepped though some code before letting
29066 it run freely.
29067
29068 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29069 The target has stopped. The @var{reason} field can have one of the
29070 following values:
29071
29072 @table @code
29073 @item breakpoint-hit
29074 A breakpoint was reached.
29075 @item watchpoint-trigger
29076 A watchpoint was triggered.
29077 @item read-watchpoint-trigger
29078 A read watchpoint was triggered.
29079 @item access-watchpoint-trigger
29080 An access watchpoint was triggered.
29081 @item function-finished
29082 An -exec-finish or similar CLI command was accomplished.
29083 @item location-reached
29084 An -exec-until or similar CLI command was accomplished.
29085 @item watchpoint-scope
29086 A watchpoint has gone out of scope.
29087 @item end-stepping-range
29088 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29089 similar CLI command was accomplished.
29090 @item exited-signalled
29091 The inferior exited because of a signal.
29092 @item exited
29093 The inferior exited.
29094 @item exited-normally
29095 The inferior exited normally.
29096 @item signal-received
29097 A signal was received by the inferior.
29098 @item solib-event
29099 The inferior has stopped due to a library being loaded or unloaded.
29100 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29101 set or when a @code{catch load} or @code{catch unload} catchpoint is
29102 in use (@pxref{Set Catchpoints}).
29103 @item fork
29104 The inferior has forked. This is reported when @code{catch fork}
29105 (@pxref{Set Catchpoints}) has been used.
29106 @item vfork
29107 The inferior has vforked. This is reported in when @code{catch vfork}
29108 (@pxref{Set Catchpoints}) has been used.
29109 @item syscall-entry
29110 The inferior entered a system call. This is reported when @code{catch
29111 syscall} (@pxref{Set Catchpoints}) has been used.
29112 @item syscall-return
29113 The inferior returned from a system call. This is reported when
29114 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29115 @item exec
29116 The inferior called @code{exec}. This is reported when @code{catch exec}
29117 (@pxref{Set Catchpoints}) has been used.
29118 @end table
29119
29120 The @var{id} field identifies the global thread ID of the thread
29121 that directly caused the stop -- for example by hitting a breakpoint.
29122 Depending on whether all-stop
29123 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29124 stop all threads, or only the thread that directly triggered the stop.
29125 If all threads are stopped, the @var{stopped} field will have the
29126 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29127 field will be a list of thread identifiers. Presently, this list will
29128 always include a single thread, but frontend should be prepared to see
29129 several threads in the list. The @var{core} field reports the
29130 processor core on which the stop event has happened. This field may be absent
29131 if such information is not available.
29132
29133 @item =thread-group-added,id="@var{id}"
29134 @itemx =thread-group-removed,id="@var{id}"
29135 A thread group was either added or removed. The @var{id} field
29136 contains the @value{GDBN} identifier of the thread group. When a thread
29137 group is added, it generally might not be associated with a running
29138 process. When a thread group is removed, its id becomes invalid and
29139 cannot be used in any way.
29140
29141 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29142 A thread group became associated with a running program,
29143 either because the program was just started or the thread group
29144 was attached to a program. The @var{id} field contains the
29145 @value{GDBN} identifier of the thread group. The @var{pid} field
29146 contains process identifier, specific to the operating system.
29147
29148 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29149 A thread group is no longer associated with a running program,
29150 either because the program has exited, or because it was detached
29151 from. The @var{id} field contains the @value{GDBN} identifier of the
29152 thread group. The @var{code} field is the exit code of the inferior; it exists
29153 only when the inferior exited with some code.
29154
29155 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29156 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29157 A thread either was created, or has exited. The @var{id} field
29158 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29159 field identifies the thread group this thread belongs to.
29160
29161 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29162 Informs that the selected thread or frame were changed. This notification
29163 is not emitted as result of the @code{-thread-select} or
29164 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29165 that is not documented to change the selected thread and frame actually
29166 changes them. In particular, invoking, directly or indirectly
29167 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29168 will generate this notification. Changing the thread or frame from another
29169 user interface (see @ref{Interpreters}) will also generate this notification.
29170
29171 The @var{frame} field is only present if the newly selected thread is
29172 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29173
29174 We suggest that in response to this notification, front ends
29175 highlight the selected thread and cause subsequent commands to apply to
29176 that thread.
29177
29178 @item =library-loaded,...
29179 Reports that a new library file was loaded by the program. This
29180 notification has 5 fields---@var{id}, @var{target-name},
29181 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29182 opaque identifier of the library. For remote debugging case,
29183 @var{target-name} and @var{host-name} fields give the name of the
29184 library file on the target, and on the host respectively. For native
29185 debugging, both those fields have the same value. The
29186 @var{symbols-loaded} field is emitted only for backward compatibility
29187 and should not be relied on to convey any useful information. The
29188 @var{thread-group} field, if present, specifies the id of the thread
29189 group in whose context the library was loaded. If the field is
29190 absent, it means the library was loaded in the context of all present
29191 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29192 to this library.
29193
29194 @item =library-unloaded,...
29195 Reports that a library was unloaded by the program. This notification
29196 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29197 the same meaning as for the @code{=library-loaded} notification.
29198 The @var{thread-group} field, if present, specifies the id of the
29199 thread group in whose context the library was unloaded. If the field is
29200 absent, it means the library was unloaded in the context of all present
29201 thread groups.
29202
29203 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29204 @itemx =traceframe-changed,end
29205 Reports that the trace frame was changed and its new number is
29206 @var{tfnum}. The number of the tracepoint associated with this trace
29207 frame is @var{tpnum}.
29208
29209 @item =tsv-created,name=@var{name},initial=@var{initial}
29210 Reports that the new trace state variable @var{name} is created with
29211 initial value @var{initial}.
29212
29213 @item =tsv-deleted,name=@var{name}
29214 @itemx =tsv-deleted
29215 Reports that the trace state variable @var{name} is deleted or all
29216 trace state variables are deleted.
29217
29218 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29219 Reports that the trace state variable @var{name} is modified with
29220 the initial value @var{initial}. The current value @var{current} of
29221 trace state variable is optional and is reported if the current
29222 value of trace state variable is known.
29223
29224 @item =breakpoint-created,bkpt=@{...@}
29225 @itemx =breakpoint-modified,bkpt=@{...@}
29226 @itemx =breakpoint-deleted,id=@var{number}
29227 Reports that a breakpoint was created, modified, or deleted,
29228 respectively. Only user-visible breakpoints are reported to the MI
29229 user.
29230
29231 The @var{bkpt} argument is of the same form as returned by the various
29232 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29233 @var{number} is the ordinal number of the breakpoint.
29234
29235 Note that if a breakpoint is emitted in the result record of a
29236 command, then it will not also be emitted in an async record.
29237
29238 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29239 @itemx =record-stopped,thread-group="@var{id}"
29240 Execution log recording was either started or stopped on an
29241 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29242 group corresponding to the affected inferior.
29243
29244 The @var{method} field indicates the method used to record execution. If the
29245 method in use supports multiple recording formats, @var{format} will be present
29246 and contain the currently used format. @xref{Process Record and Replay},
29247 for existing method and format values.
29248
29249 @item =cmd-param-changed,param=@var{param},value=@var{value}
29250 Reports that a parameter of the command @code{set @var{param}} is
29251 changed to @var{value}. In the multi-word @code{set} command,
29252 the @var{param} is the whole parameter list to @code{set} command.
29253 For example, In command @code{set check type on}, @var{param}
29254 is @code{check type} and @var{value} is @code{on}.
29255
29256 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29257 Reports that bytes from @var{addr} to @var{data} + @var{len} were
29258 written in an inferior. The @var{id} is the identifier of the
29259 thread group corresponding to the affected inferior. The optional
29260 @code{type="code"} part is reported if the memory written to holds
29261 executable code.
29262 @end table
29263
29264 @node GDB/MI Breakpoint Information
29265 @subsection @sc{gdb/mi} Breakpoint Information
29266
29267 When @value{GDBN} reports information about a breakpoint, a
29268 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29269 following fields:
29270
29271 @table @code
29272 @item number
29273 The breakpoint number.
29274
29275 @item type
29276 The type of the breakpoint. For ordinary breakpoints this will be
29277 @samp{breakpoint}, but many values are possible.
29278
29279 @item catch-type
29280 If the type of the breakpoint is @samp{catchpoint}, then this
29281 indicates the exact type of catchpoint.
29282
29283 @item disp
29284 This is the breakpoint disposition---either @samp{del}, meaning that
29285 the breakpoint will be deleted at the next stop, or @samp{keep},
29286 meaning that the breakpoint will not be deleted.
29287
29288 @item enabled
29289 This indicates whether the breakpoint is enabled, in which case the
29290 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29291 Note that this is not the same as the field @code{enable}.
29292
29293 @item addr
29294 The address of the breakpoint. This may be a hexidecimal number,
29295 giving the address; or the string @samp{<PENDING>}, for a pending
29296 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29297 multiple locations. This field will not be present if no address can
29298 be determined. For example, a watchpoint does not have an address.
29299
29300 @item addr_flags
29301 Optional field containing any flags related to the address. These flags are
29302 architecture-dependent; see @ref{Architectures} for their meaning for a
29303 particular CPU.
29304
29305 @item func
29306 If known, the function in which the breakpoint appears.
29307 If not known, this field is not present.
29308
29309 @item filename
29310 The name of the source file which contains this function, if known.
29311 If not known, this field is not present.
29312
29313 @item fullname
29314 The full file name of the source file which contains this function, if
29315 known. If not known, this field is not present.
29316
29317 @item line
29318 The line number at which this breakpoint appears, if known.
29319 If not known, this field is not present.
29320
29321 @item at
29322 If the source file is not known, this field may be provided. If
29323 provided, this holds the address of the breakpoint, possibly followed
29324 by a symbol name.
29325
29326 @item pending
29327 If this breakpoint is pending, this field is present and holds the
29328 text used to set the breakpoint, as entered by the user.
29329
29330 @item evaluated-by
29331 Where this breakpoint's condition is evaluated, either @samp{host} or
29332 @samp{target}.
29333
29334 @item thread
29335 If this is a thread-specific breakpoint, then this identifies the
29336 thread in which the breakpoint can trigger.
29337
29338 @item task
29339 If this breakpoint is restricted to a particular Ada task, then this
29340 field will hold the task identifier.
29341
29342 @item cond
29343 If the breakpoint is conditional, this is the condition expression.
29344
29345 @item ignore
29346 The ignore count of the breakpoint.
29347
29348 @item enable
29349 The enable count of the breakpoint.
29350
29351 @item traceframe-usage
29352 FIXME.
29353
29354 @item static-tracepoint-marker-string-id
29355 For a static tracepoint, the name of the static tracepoint marker.
29356
29357 @item mask
29358 For a masked watchpoint, this is the mask.
29359
29360 @item pass
29361 A tracepoint's pass count.
29362
29363 @item original-location
29364 The location of the breakpoint as originally specified by the user.
29365 This field is optional.
29366
29367 @item times
29368 The number of times the breakpoint has been hit.
29369
29370 @item installed
29371 This field is only given for tracepoints. This is either @samp{y},
29372 meaning that the tracepoint is installed, or @samp{n}, meaning that it
29373 is not.
29374
29375 @item what
29376 Some extra data, the exact contents of which are type-dependent.
29377
29378 @item locations
29379 This field is present if the breakpoint has multiple locations. It is also
29380 exceptionally present if the breakpoint is enabled and has a single, disabled
29381 location.
29382
29383 The value is a list of locations. The format of a location is described below.
29384
29385 @end table
29386
29387 A location in a multi-location breakpoint is represented as a tuple with the
29388 following fields:
29389
29390 @table @code
29391
29392 @item number
29393 The location number as a dotted pair, like @samp{1.2}. The first digit is the
29394 number of the parent breakpoint. The second digit is the number of the
29395 location within that breakpoint.
29396
29397 @item enabled
29398 This indicates whether the location is enabled, in which case the
29399 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29400 Note that this is not the same as the field @code{enable}.
29401
29402 @item addr
29403 The address of this location as an hexidecimal number.
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 location appears.
29412 If not known, this field is not present.
29413
29414 @item file
29415 The name of the source file which contains this location, 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 location, if
29420 known. If not known, this field is not present.
29421
29422 @item line
29423 The line number at which this location appears, if known.
29424 If not known, this field is not present.
29425
29426 @item thread-groups
29427 The thread groups this location is in.
29428
29429 @end table
29430
29431 For example, here is what the output of @code{-break-insert}
29432 (@pxref{GDB/MI Breakpoint Commands}) might be:
29433
29434 @smallexample
29435 -> -break-insert main
29436 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29437 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29438 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29439 times="0"@}
29440 <- (gdb)
29441 @end smallexample
29442
29443 @node GDB/MI Frame Information
29444 @subsection @sc{gdb/mi} Frame Information
29445
29446 Response from many MI commands includes an information about stack
29447 frame. This information is a tuple that may have the following
29448 fields:
29449
29450 @table @code
29451 @item level
29452 The level of the stack frame. The innermost frame has the level of
29453 zero. This field is always present.
29454
29455 @item func
29456 The name of the function corresponding to the frame. This field may
29457 be absent if @value{GDBN} is unable to determine the function name.
29458
29459 @item addr
29460 The code address for the frame. This field is always present.
29461
29462 @item addr_flags
29463 Optional field containing any flags related to the address. These flags are
29464 architecture-dependent; see @ref{Architectures} for their meaning for a
29465 particular CPU.
29466
29467 @item file
29468 The name of the source files that correspond to the frame's code
29469 address. This field may be absent.
29470
29471 @item line
29472 The source line corresponding to the frames' code address. This field
29473 may be absent.
29474
29475 @item from
29476 The name of the binary file (either executable or shared library) the
29477 corresponds to the frame's code address. This field may be absent.
29478
29479 @end table
29480
29481 @node GDB/MI Thread Information
29482 @subsection @sc{gdb/mi} Thread Information
29483
29484 Whenever @value{GDBN} has to report an information about a thread, it
29485 uses a tuple with the following fields. The fields are always present unless
29486 stated otherwise.
29487
29488 @table @code
29489 @item id
29490 The global numeric id assigned to the thread by @value{GDBN}.
29491
29492 @item target-id
29493 The target-specific string identifying the thread.
29494
29495 @item details
29496 Additional information about the thread provided by the target.
29497 It is supposed to be human-readable and not interpreted by the
29498 frontend. This field is optional.
29499
29500 @item name
29501 The name of the thread. If the user specified a name using the
29502 @code{thread name} command, then this name is given. Otherwise, if
29503 @value{GDBN} can extract the thread name from the target, then that
29504 name is given. If @value{GDBN} cannot find the thread name, then this
29505 field is omitted.
29506
29507 @item state
29508 The execution state of the thread, either @samp{stopped} or @samp{running},
29509 depending on whether the thread is presently running.
29510
29511 @item frame
29512 The stack frame currently executing in the thread. This field is only present
29513 if the thread is stopped. Its format is documented in
29514 @ref{GDB/MI Frame Information}.
29515
29516 @item core
29517 The value of this field is an integer number of the processor core the
29518 thread was last seen on. This field is optional.
29519 @end table
29520
29521 @node GDB/MI Ada Exception Information
29522 @subsection @sc{gdb/mi} Ada Exception Information
29523
29524 Whenever a @code{*stopped} record is emitted because the program
29525 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29526 @value{GDBN} provides the name of the exception that was raised via
29527 the @code{exception-name} field. Also, for exceptions that were raised
29528 with an exception message, @value{GDBN} provides that message via
29529 the @code{exception-message} field.
29530
29531 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29532 @node GDB/MI Simple Examples
29533 @section Simple Examples of @sc{gdb/mi} Interaction
29534 @cindex @sc{gdb/mi}, simple examples
29535
29536 This subsection presents several simple examples of interaction using
29537 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29538 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29539 the output received from @sc{gdb/mi}.
29540
29541 Note the line breaks shown in the examples are here only for
29542 readability, they don't appear in the real output.
29543
29544 @subheading Setting a Breakpoint
29545
29546 Setting a breakpoint generates synchronous output which contains detailed
29547 information of the breakpoint.
29548
29549 @smallexample
29550 -> -break-insert main
29551 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29552 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29553 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29554 times="0"@}
29555 <- (gdb)
29556 @end smallexample
29557
29558 @subheading Program Execution
29559
29560 Program execution generates asynchronous records and MI gives the
29561 reason that execution stopped.
29562
29563 @smallexample
29564 -> -exec-run
29565 <- ^running
29566 <- (gdb)
29567 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
29568 frame=@{addr="0x08048564",func="main",
29569 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
29570 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29571 arch="i386:x86_64"@}
29572 <- (gdb)
29573 -> -exec-continue
29574 <- ^running
29575 <- (gdb)
29576 <- *stopped,reason="exited-normally"
29577 <- (gdb)
29578 @end smallexample
29579
29580 @subheading Quitting @value{GDBN}
29581
29582 Quitting @value{GDBN} just prints the result class @samp{^exit}.
29583
29584 @smallexample
29585 -> (gdb)
29586 <- -gdb-exit
29587 <- ^exit
29588 @end smallexample
29589
29590 Please note that @samp{^exit} is printed immediately, but it might
29591 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29592 performs necessary cleanups, including killing programs being debugged
29593 or disconnecting from debug hardware, so the frontend should wait till
29594 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29595 fails to exit in reasonable time.
29596
29597 @subheading A Bad Command
29598
29599 Here's what happens if you pass a non-existent command:
29600
29601 @smallexample
29602 -> -rubbish
29603 <- ^error,msg="Undefined MI command: rubbish"
29604 <- (gdb)
29605 @end smallexample
29606
29607
29608 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29609 @node GDB/MI Command Description Format
29610 @section @sc{gdb/mi} Command Description Format
29611
29612 The remaining sections describe blocks of commands. Each block of
29613 commands is laid out in a fashion similar to this section.
29614
29615 @subheading Motivation
29616
29617 The motivation for this collection of commands.
29618
29619 @subheading Introduction
29620
29621 A brief introduction to this collection of commands as a whole.
29622
29623 @subheading Commands
29624
29625 For each command in the block, the following is described:
29626
29627 @subsubheading Synopsis
29628
29629 @smallexample
29630 -command @var{args}@dots{}
29631 @end smallexample
29632
29633 @subsubheading Result
29634
29635 @subsubheading @value{GDBN} Command
29636
29637 The corresponding @value{GDBN} CLI command(s), if any.
29638
29639 @subsubheading Example
29640
29641 Example(s) formatted for readability. Some of the described commands have
29642 not been implemented yet and these are labeled N.A.@: (not available).
29643
29644
29645 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29646 @node GDB/MI Breakpoint Commands
29647 @section @sc{gdb/mi} Breakpoint Commands
29648
29649 @cindex breakpoint commands for @sc{gdb/mi}
29650 @cindex @sc{gdb/mi}, breakpoint commands
29651 This section documents @sc{gdb/mi} commands for manipulating
29652 breakpoints.
29653
29654 @subheading The @code{-break-after} Command
29655 @findex -break-after
29656
29657 @subsubheading Synopsis
29658
29659 @smallexample
29660 -break-after @var{number} @var{count}
29661 @end smallexample
29662
29663 The breakpoint number @var{number} is not in effect until it has been
29664 hit @var{count} times. To see how this is reflected in the output of
29665 the @samp{-break-list} command, see the description of the
29666 @samp{-break-list} command below.
29667
29668 @subsubheading @value{GDBN} Command
29669
29670 The corresponding @value{GDBN} command is @samp{ignore}.
29671
29672 @subsubheading Example
29673
29674 @smallexample
29675 (gdb)
29676 -break-insert main
29677 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29678 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29679 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29680 times="0"@}
29681 (gdb)
29682 -break-after 1 3
29683 ~
29684 ^done
29685 (gdb)
29686 -break-list
29687 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29688 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29689 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29690 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29691 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29692 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29693 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29694 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29695 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29696 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
29697 (gdb)
29698 @end smallexample
29699
29700 @ignore
29701 @subheading The @code{-break-catch} Command
29702 @findex -break-catch
29703 @end ignore
29704
29705 @subheading The @code{-break-commands} Command
29706 @findex -break-commands
29707
29708 @subsubheading Synopsis
29709
29710 @smallexample
29711 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29712 @end smallexample
29713
29714 Specifies the CLI commands that should be executed when breakpoint
29715 @var{number} is hit. The parameters @var{command1} to @var{commandN}
29716 are the commands. If no command is specified, any previously-set
29717 commands are cleared. @xref{Break Commands}. Typical use of this
29718 functionality is tracing a program, that is, printing of values of
29719 some variables whenever breakpoint is hit and then continuing.
29720
29721 @subsubheading @value{GDBN} Command
29722
29723 The corresponding @value{GDBN} command is @samp{commands}.
29724
29725 @subsubheading Example
29726
29727 @smallexample
29728 (gdb)
29729 -break-insert main
29730 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29731 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29732 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29733 times="0"@}
29734 (gdb)
29735 -break-commands 1 "print v" "continue"
29736 ^done
29737 (gdb)
29738 @end smallexample
29739
29740 @subheading The @code{-break-condition} Command
29741 @findex -break-condition
29742
29743 @subsubheading Synopsis
29744
29745 @smallexample
29746 -break-condition @var{number} @var{expr}
29747 @end smallexample
29748
29749 Breakpoint @var{number} will stop the program only if the condition in
29750 @var{expr} is true. The condition becomes part of the
29751 @samp{-break-list} output (see the description of the @samp{-break-list}
29752 command below).
29753
29754 @subsubheading @value{GDBN} Command
29755
29756 The corresponding @value{GDBN} command is @samp{condition}.
29757
29758 @subsubheading Example
29759
29760 @smallexample
29761 (gdb)
29762 -break-condition 1 1
29763 ^done
29764 (gdb)
29765 -break-list
29766 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29767 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29768 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29769 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29770 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29771 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29772 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29773 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29774 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29775 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
29776 (gdb)
29777 @end smallexample
29778
29779 @subheading The @code{-break-delete} Command
29780 @findex -break-delete
29781
29782 @subsubheading Synopsis
29783
29784 @smallexample
29785 -break-delete ( @var{breakpoint} )+
29786 @end smallexample
29787
29788 Delete the breakpoint(s) whose number(s) are specified in the argument
29789 list. This is obviously reflected in the breakpoint list.
29790
29791 @subsubheading @value{GDBN} Command
29792
29793 The corresponding @value{GDBN} command is @samp{delete}.
29794
29795 @subsubheading Example
29796
29797 @smallexample
29798 (gdb)
29799 -break-delete 1
29800 ^done
29801 (gdb)
29802 -break-list
29803 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29804 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29805 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29806 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29807 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29808 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29809 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29810 body=[]@}
29811 (gdb)
29812 @end smallexample
29813
29814 @subheading The @code{-break-disable} Command
29815 @findex -break-disable
29816
29817 @subsubheading Synopsis
29818
29819 @smallexample
29820 -break-disable ( @var{breakpoint} )+
29821 @end smallexample
29822
29823 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
29824 break list is now set to @samp{n} for the named @var{breakpoint}(s).
29825
29826 @subsubheading @value{GDBN} Command
29827
29828 The corresponding @value{GDBN} command is @samp{disable}.
29829
29830 @subsubheading Example
29831
29832 @smallexample
29833 (gdb)
29834 -break-disable 2
29835 ^done
29836 (gdb)
29837 -break-list
29838 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29839 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29840 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29841 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29842 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29843 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29844 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29845 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
29846 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29847 line="5",thread-groups=["i1"],times="0"@}]@}
29848 (gdb)
29849 @end smallexample
29850
29851 @subheading The @code{-break-enable} Command
29852 @findex -break-enable
29853
29854 @subsubheading Synopsis
29855
29856 @smallexample
29857 -break-enable ( @var{breakpoint} )+
29858 @end smallexample
29859
29860 Enable (previously disabled) @var{breakpoint}(s).
29861
29862 @subsubheading @value{GDBN} Command
29863
29864 The corresponding @value{GDBN} command is @samp{enable}.
29865
29866 @subsubheading Example
29867
29868 @smallexample
29869 (gdb)
29870 -break-enable 2
29871 ^done
29872 (gdb)
29873 -break-list
29874 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29875 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29876 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29877 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29878 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29879 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29880 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29881 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
29882 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29883 line="5",thread-groups=["i1"],times="0"@}]@}
29884 (gdb)
29885 @end smallexample
29886
29887 @subheading The @code{-break-info} Command
29888 @findex -break-info
29889
29890 @subsubheading Synopsis
29891
29892 @smallexample
29893 -break-info @var{breakpoint}
29894 @end smallexample
29895
29896 @c REDUNDANT???
29897 Get information about a single breakpoint.
29898
29899 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
29900 Information}, for details on the format of each breakpoint in the
29901 table.
29902
29903 @subsubheading @value{GDBN} Command
29904
29905 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
29906
29907 @subsubheading Example
29908 N.A.
29909
29910 @subheading The @code{-break-insert} Command
29911 @findex -break-insert
29912 @anchor{-break-insert}
29913
29914 @subsubheading Synopsis
29915
29916 @smallexample
29917 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
29918 [ -c @var{condition} ] [ -i @var{ignore-count} ]
29919 [ -p @var{thread-id} ] [ @var{location} ]
29920 @end smallexample
29921
29922 @noindent
29923 If specified, @var{location}, can be one of:
29924
29925 @table @var
29926 @item linespec location
29927 A linespec location. @xref{Linespec Locations}.
29928
29929 @item explicit location
29930 An explicit location. @sc{gdb/mi} explicit locations are
29931 analogous to the CLI's explicit locations using the option names
29932 listed below. @xref{Explicit Locations}.
29933
29934 @table @samp
29935 @item --source @var{filename}
29936 The source file name of the location. This option requires the use
29937 of either @samp{--function} or @samp{--line}.
29938
29939 @item --function @var{function}
29940 The name of a function or method.
29941
29942 @item --label @var{label}
29943 The name of a label.
29944
29945 @item --line @var{lineoffset}
29946 An absolute or relative line offset from the start of the location.
29947 @end table
29948
29949 @item address location
29950 An address location, *@var{address}. @xref{Address Locations}.
29951 @end table
29952
29953 @noindent
29954 The possible optional parameters of this command are:
29955
29956 @table @samp
29957 @item -t
29958 Insert a temporary breakpoint.
29959 @item -h
29960 Insert a hardware breakpoint.
29961 @item -f
29962 If @var{location} cannot be parsed (for example if it
29963 refers to unknown files or functions), create a pending
29964 breakpoint. Without this flag, @value{GDBN} will report
29965 an error, and won't create a breakpoint, if @var{location}
29966 cannot be parsed.
29967 @item -d
29968 Create a disabled breakpoint.
29969 @item -a
29970 Create a tracepoint. @xref{Tracepoints}. When this parameter
29971 is used together with @samp{-h}, a fast tracepoint is created.
29972 @item -c @var{condition}
29973 Make the breakpoint conditional on @var{condition}.
29974 @item -i @var{ignore-count}
29975 Initialize the @var{ignore-count}.
29976 @item -p @var{thread-id}
29977 Restrict the breakpoint to the thread with the specified global
29978 @var{thread-id}.
29979 @end table
29980
29981 @subsubheading Result
29982
29983 @xref{GDB/MI Breakpoint Information}, for details on the format of the
29984 resulting breakpoint.
29985
29986 Note: this format is open to change.
29987 @c An out-of-band breakpoint instead of part of the result?
29988
29989 @subsubheading @value{GDBN} Command
29990
29991 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
29992 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
29993
29994 @subsubheading Example
29995
29996 @smallexample
29997 (gdb)
29998 -break-insert main
29999 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30000 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30001 times="0"@}
30002 (gdb)
30003 -break-insert -t foo
30004 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30005 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30006 times="0"@}
30007 (gdb)
30008 -break-list
30009 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30010 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30011 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30012 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30013 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30014 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30015 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30016 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30017 addr="0x0001072c", func="main",file="recursive2.c",
30018 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30019 times="0"@},
30020 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30021 addr="0x00010774",func="foo",file="recursive2.c",
30022 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30023 times="0"@}]@}
30024 (gdb)
30025 @c -break-insert -r foo.*
30026 @c ~int foo(int, int);
30027 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30028 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30029 @c times="0"@}
30030 @c (gdb)
30031 @end smallexample
30032
30033 @subheading The @code{-dprintf-insert} Command
30034 @findex -dprintf-insert
30035
30036 @subsubheading Synopsis
30037
30038 @smallexample
30039 -dprintf-insert [ -t ] [ -f ] [ -d ]
30040 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30041 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30042 [ @var{argument} ]
30043 @end smallexample
30044
30045 @noindent
30046 If supplied, @var{location} may be specified the same way as for
30047 the @code{-break-insert} command. @xref{-break-insert}.
30048
30049 The possible optional parameters of this command are:
30050
30051 @table @samp
30052 @item -t
30053 Insert a temporary breakpoint.
30054 @item -f
30055 If @var{location} cannot be parsed (for example, if it
30056 refers to unknown files or functions), create a pending
30057 breakpoint. Without this flag, @value{GDBN} will report
30058 an error, and won't create a breakpoint, if @var{location}
30059 cannot be parsed.
30060 @item -d
30061 Create a disabled breakpoint.
30062 @item -c @var{condition}
30063 Make the breakpoint conditional on @var{condition}.
30064 @item -i @var{ignore-count}
30065 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30066 to @var{ignore-count}.
30067 @item -p @var{thread-id}
30068 Restrict the breakpoint to the thread with the specified global
30069 @var{thread-id}.
30070 @end table
30071
30072 @subsubheading Result
30073
30074 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30075 resulting breakpoint.
30076
30077 @c An out-of-band breakpoint instead of part of the result?
30078
30079 @subsubheading @value{GDBN} Command
30080
30081 The corresponding @value{GDBN} command is @samp{dprintf}.
30082
30083 @subsubheading Example
30084
30085 @smallexample
30086 (gdb)
30087 4-dprintf-insert foo "At foo entry\n"
30088 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30089 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30090 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30091 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30092 original-location="foo"@}
30093 (gdb)
30094 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30095 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30096 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30097 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30098 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30099 original-location="mi-dprintf.c:26"@}
30100 (gdb)
30101 @end smallexample
30102
30103 @subheading The @code{-break-list} Command
30104 @findex -break-list
30105
30106 @subsubheading Synopsis
30107
30108 @smallexample
30109 -break-list
30110 @end smallexample
30111
30112 Displays the list of inserted breakpoints, showing the following fields:
30113
30114 @table @samp
30115 @item Number
30116 number of the breakpoint
30117 @item Type
30118 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30119 @item Disposition
30120 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30121 or @samp{nokeep}
30122 @item Enabled
30123 is the breakpoint enabled or no: @samp{y} or @samp{n}
30124 @item Address
30125 memory location at which the breakpoint is set
30126 @item What
30127 logical location of the breakpoint, expressed by function name, file
30128 name, line number
30129 @item Thread-groups
30130 list of thread groups to which this breakpoint applies
30131 @item Times
30132 number of times the breakpoint has been hit
30133 @end table
30134
30135 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30136 @code{body} field is an empty list.
30137
30138 @subsubheading @value{GDBN} Command
30139
30140 The corresponding @value{GDBN} command is @samp{info break}.
30141
30142 @subsubheading Example
30143
30144 @smallexample
30145 (gdb)
30146 -break-list
30147 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30148 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30149 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30150 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30151 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30152 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30153 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30154 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30155 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30156 times="0"@},
30157 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30158 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30159 line="13",thread-groups=["i1"],times="0"@}]@}
30160 (gdb)
30161 @end smallexample
30162
30163 Here's an example of the result when there are no breakpoints:
30164
30165 @smallexample
30166 (gdb)
30167 -break-list
30168 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30169 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30170 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30171 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30172 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30173 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30174 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30175 body=[]@}
30176 (gdb)
30177 @end smallexample
30178
30179 @subheading The @code{-break-passcount} Command
30180 @findex -break-passcount
30181
30182 @subsubheading Synopsis
30183
30184 @smallexample
30185 -break-passcount @var{tracepoint-number} @var{passcount}
30186 @end smallexample
30187
30188 Set the passcount for tracepoint @var{tracepoint-number} to
30189 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30190 is not a tracepoint, error is emitted. This corresponds to CLI
30191 command @samp{passcount}.
30192
30193 @subheading The @code{-break-watch} Command
30194 @findex -break-watch
30195
30196 @subsubheading Synopsis
30197
30198 @smallexample
30199 -break-watch [ -a | -r ]
30200 @end smallexample
30201
30202 Create a watchpoint. With the @samp{-a} option it will create an
30203 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30204 read from or on a write to the memory location. With the @samp{-r}
30205 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30206 trigger only when the memory location is accessed for reading. Without
30207 either of the options, the watchpoint created is a regular watchpoint,
30208 i.e., it will trigger when the memory location is accessed for writing.
30209 @xref{Set Watchpoints, , Setting Watchpoints}.
30210
30211 Note that @samp{-break-list} will report a single list of watchpoints and
30212 breakpoints inserted.
30213
30214 @subsubheading @value{GDBN} Command
30215
30216 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30217 @samp{rwatch}.
30218
30219 @subsubheading Example
30220
30221 Setting a watchpoint on a variable in the @code{main} function:
30222
30223 @smallexample
30224 (gdb)
30225 -break-watch x
30226 ^done,wpt=@{number="2",exp="x"@}
30227 (gdb)
30228 -exec-continue
30229 ^running
30230 (gdb)
30231 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30232 value=@{old="-268439212",new="55"@},
30233 frame=@{func="main",args=[],file="recursive2.c",
30234 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30235 (gdb)
30236 @end smallexample
30237
30238 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30239 the program execution twice: first for the variable changing value, then
30240 for the watchpoint going out of scope.
30241
30242 @smallexample
30243 (gdb)
30244 -break-watch C
30245 ^done,wpt=@{number="5",exp="C"@}
30246 (gdb)
30247 -exec-continue
30248 ^running
30249 (gdb)
30250 *stopped,reason="watchpoint-trigger",
30251 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30252 frame=@{func="callee4",args=[],
30253 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30254 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30255 arch="i386:x86_64"@}
30256 (gdb)
30257 -exec-continue
30258 ^running
30259 (gdb)
30260 *stopped,reason="watchpoint-scope",wpnum="5",
30261 frame=@{func="callee3",args=[@{name="strarg",
30262 value="0x11940 \"A string argument.\""@}],
30263 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30264 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30265 arch="i386:x86_64"@}
30266 (gdb)
30267 @end smallexample
30268
30269 Listing breakpoints and watchpoints, at different points in the program
30270 execution. Note that once the watchpoint goes out of scope, it is
30271 deleted.
30272
30273 @smallexample
30274 (gdb)
30275 -break-watch C
30276 ^done,wpt=@{number="2",exp="C"@}
30277 (gdb)
30278 -break-list
30279 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30280 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30281 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30282 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30283 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30284 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30285 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30286 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30287 addr="0x00010734",func="callee4",
30288 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30289 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30290 times="1"@},
30291 bkpt=@{number="2",type="watchpoint",disp="keep",
30292 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30293 (gdb)
30294 -exec-continue
30295 ^running
30296 (gdb)
30297 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30298 value=@{old="-276895068",new="3"@},
30299 frame=@{func="callee4",args=[],
30300 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30301 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30302 arch="i386:x86_64"@}
30303 (gdb)
30304 -break-list
30305 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30306 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30307 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30308 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30309 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30310 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30311 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30312 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30313 addr="0x00010734",func="callee4",
30314 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30315 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30316 times="1"@},
30317 bkpt=@{number="2",type="watchpoint",disp="keep",
30318 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30319 (gdb)
30320 -exec-continue
30321 ^running
30322 ^done,reason="watchpoint-scope",wpnum="2",
30323 frame=@{func="callee3",args=[@{name="strarg",
30324 value="0x11940 \"A string argument.\""@}],
30325 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30326 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30327 arch="i386:x86_64"@}
30328 (gdb)
30329 -break-list
30330 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30331 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30332 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30333 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30334 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30335 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30336 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30337 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30338 addr="0x00010734",func="callee4",
30339 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30340 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30341 thread-groups=["i1"],times="1"@}]@}
30342 (gdb)
30343 @end smallexample
30344
30345
30346 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30347 @node GDB/MI Catchpoint Commands
30348 @section @sc{gdb/mi} Catchpoint Commands
30349
30350 This section documents @sc{gdb/mi} commands for manipulating
30351 catchpoints.
30352
30353 @menu
30354 * Shared Library GDB/MI Catchpoint Commands::
30355 * Ada Exception GDB/MI Catchpoint Commands::
30356 * C++ Exception GDB/MI Catchpoint Commands::
30357 @end menu
30358
30359 @node Shared Library GDB/MI Catchpoint Commands
30360 @subsection Shared Library @sc{gdb/mi} Catchpoints
30361
30362 @subheading The @code{-catch-load} Command
30363 @findex -catch-load
30364
30365 @subsubheading Synopsis
30366
30367 @smallexample
30368 -catch-load [ -t ] [ -d ] @var{regexp}
30369 @end smallexample
30370
30371 Add a catchpoint for library load events. If the @samp{-t} option is used,
30372 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30373 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30374 in a disabled state. The @samp{regexp} argument is a regular
30375 expression used to match the name of the loaded library.
30376
30377
30378 @subsubheading @value{GDBN} Command
30379
30380 The corresponding @value{GDBN} command is @samp{catch load}.
30381
30382 @subsubheading Example
30383
30384 @smallexample
30385 -catch-load -t foo.so
30386 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30387 what="load of library matching foo.so",catch-type="load",times="0"@}
30388 (gdb)
30389 @end smallexample
30390
30391
30392 @subheading The @code{-catch-unload} Command
30393 @findex -catch-unload
30394
30395 @subsubheading Synopsis
30396
30397 @smallexample
30398 -catch-unload [ -t ] [ -d ] @var{regexp}
30399 @end smallexample
30400
30401 Add a catchpoint for library unload events. If the @samp{-t} option is
30402 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30403 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30404 created in a disabled state. The @samp{regexp} argument is a regular
30405 expression used to match the name of the unloaded library.
30406
30407 @subsubheading @value{GDBN} Command
30408
30409 The corresponding @value{GDBN} command is @samp{catch unload}.
30410
30411 @subsubheading Example
30412
30413 @smallexample
30414 -catch-unload -d bar.so
30415 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30416 what="load of library matching bar.so",catch-type="unload",times="0"@}
30417 (gdb)
30418 @end smallexample
30419
30420 @node Ada Exception GDB/MI Catchpoint Commands
30421 @subsection Ada Exception @sc{gdb/mi} Catchpoints
30422
30423 The following @sc{gdb/mi} commands can be used to create catchpoints
30424 that stop the execution when Ada exceptions are being raised.
30425
30426 @subheading The @code{-catch-assert} Command
30427 @findex -catch-assert
30428
30429 @subsubheading Synopsis
30430
30431 @smallexample
30432 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30433 @end smallexample
30434
30435 Add a catchpoint for failed Ada assertions.
30436
30437 The possible optional parameters for this command are:
30438
30439 @table @samp
30440 @item -c @var{condition}
30441 Make the catchpoint conditional on @var{condition}.
30442 @item -d
30443 Create a disabled catchpoint.
30444 @item -t
30445 Create a temporary catchpoint.
30446 @end table
30447
30448 @subsubheading @value{GDBN} Command
30449
30450 The corresponding @value{GDBN} command is @samp{catch assert}.
30451
30452 @subsubheading Example
30453
30454 @smallexample
30455 -catch-assert
30456 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30457 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30458 thread-groups=["i1"],times="0",
30459 original-location="__gnat_debug_raise_assert_failure"@}
30460 (gdb)
30461 @end smallexample
30462
30463 @subheading The @code{-catch-exception} Command
30464 @findex -catch-exception
30465
30466 @subsubheading Synopsis
30467
30468 @smallexample
30469 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30470 [ -t ] [ -u ]
30471 @end smallexample
30472
30473 Add a catchpoint stopping when Ada exceptions are raised.
30474 By default, the command stops the program when any Ada exception
30475 gets raised. But it is also possible, by using some of the
30476 optional parameters described below, to create more selective
30477 catchpoints.
30478
30479 The possible optional parameters for this command are:
30480
30481 @table @samp
30482 @item -c @var{condition}
30483 Make the catchpoint conditional on @var{condition}.
30484 @item -d
30485 Create a disabled catchpoint.
30486 @item -e @var{exception-name}
30487 Only stop when @var{exception-name} is raised. This option cannot
30488 be used combined with @samp{-u}.
30489 @item -t
30490 Create a temporary catchpoint.
30491 @item -u
30492 Stop only when an unhandled exception gets raised. This option
30493 cannot be used combined with @samp{-e}.
30494 @end table
30495
30496 @subsubheading @value{GDBN} Command
30497
30498 The corresponding @value{GDBN} commands are @samp{catch exception}
30499 and @samp{catch exception unhandled}.
30500
30501 @subsubheading Example
30502
30503 @smallexample
30504 -catch-exception -e Program_Error
30505 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30506 enabled="y",addr="0x0000000000404874",
30507 what="`Program_Error' Ada exception", thread-groups=["i1"],
30508 times="0",original-location="__gnat_debug_raise_exception"@}
30509 (gdb)
30510 @end smallexample
30511
30512 @subheading The @code{-catch-handlers} Command
30513 @findex -catch-handlers
30514
30515 @subsubheading Synopsis
30516
30517 @smallexample
30518 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30519 [ -t ]
30520 @end smallexample
30521
30522 Add a catchpoint stopping when Ada exceptions are handled.
30523 By default, the command stops the program when any Ada exception
30524 gets handled. But it is also possible, by using some of the
30525 optional parameters described below, to create more selective
30526 catchpoints.
30527
30528 The possible optional parameters for this command are:
30529
30530 @table @samp
30531 @item -c @var{condition}
30532 Make the catchpoint conditional on @var{condition}.
30533 @item -d
30534 Create a disabled catchpoint.
30535 @item -e @var{exception-name}
30536 Only stop when @var{exception-name} is handled.
30537 @item -t
30538 Create a temporary catchpoint.
30539 @end table
30540
30541 @subsubheading @value{GDBN} Command
30542
30543 The corresponding @value{GDBN} command is @samp{catch handlers}.
30544
30545 @subsubheading Example
30546
30547 @smallexample
30548 -catch-handlers -e Constraint_Error
30549 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30550 enabled="y",addr="0x0000000000402f68",
30551 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30552 times="0",original-location="__gnat_begin_handler"@}
30553 (gdb)
30554 @end smallexample
30555
30556 @node C++ Exception GDB/MI Catchpoint Commands
30557 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30558
30559 The following @sc{gdb/mi} commands can be used to create catchpoints
30560 that stop the execution when C@t{++} exceptions are being throw, rethrown,
30561 or caught.
30562
30563 @subheading The @code{-catch-throw} Command
30564 @findex -catch-throw
30565
30566 @subsubheading Synopsis
30567
30568 @smallexample
30569 -catch-throw [ -t ] [ -r @var{regexp}]
30570 @end smallexample
30571
30572 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30573 given, then only exceptions whose type matches the regular expression
30574 will be caught.
30575
30576 If @samp{-t} is given, then the catchpoint is enabled only for one
30577 stop, the catchpoint is automatically deleted after stopping once for
30578 the event.
30579
30580 @subsubheading @value{GDBN} Command
30581
30582 The corresponding @value{GDBN} commands are @samp{catch throw}
30583 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30584
30585 @subsubheading Example
30586
30587 @smallexample
30588 -catch-throw -r exception_type
30589 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30590 what="exception throw",catch-type="throw",
30591 thread-groups=["i1"],
30592 regexp="exception_type",times="0"@}
30593 (gdb)
30594 -exec-run
30595 ^running
30596 (gdb)
30597 ~"\n"
30598 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30599 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30600 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30601 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30602 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30603 thread-id="1",stopped-threads="all",core="6"
30604 (gdb)
30605 @end smallexample
30606
30607 @subheading The @code{-catch-rethrow} Command
30608 @findex -catch-rethrow
30609
30610 @subsubheading Synopsis
30611
30612 @smallexample
30613 -catch-rethrow [ -t ] [ -r @var{regexp}]
30614 @end smallexample
30615
30616 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30617 then only exceptions whose type matches the regular expression will be
30618 caught.
30619
30620 If @samp{-t} is given, then the catchpoint is enabled only for one
30621 stop, the catchpoint is automatically deleted after the first event is
30622 caught.
30623
30624 @subsubheading @value{GDBN} Command
30625
30626 The corresponding @value{GDBN} commands are @samp{catch rethrow}
30627 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30628
30629 @subsubheading Example
30630
30631 @smallexample
30632 -catch-rethrow -r exception_type
30633 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30634 what="exception rethrow",catch-type="rethrow",
30635 thread-groups=["i1"],
30636 regexp="exception_type",times="0"@}
30637 (gdb)
30638 -exec-run
30639 ^running
30640 (gdb)
30641 ~"\n"
30642 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30643 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30644 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30645 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30646 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30647 thread-id="1",stopped-threads="all",core="6"
30648 (gdb)
30649 @end smallexample
30650
30651 @subheading The @code{-catch-catch} Command
30652 @findex -catch-catch
30653
30654 @subsubheading Synopsis
30655
30656 @smallexample
30657 -catch-catch [ -t ] [ -r @var{regexp}]
30658 @end smallexample
30659
30660 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30661 is given, then only exceptions whose type matches the regular
30662 expression will be caught.
30663
30664 If @samp{-t} is given, then the catchpoint is enabled only for one
30665 stop, the catchpoint is automatically deleted after the first event is
30666 caught.
30667
30668 @subsubheading @value{GDBN} Command
30669
30670 The corresponding @value{GDBN} commands are @samp{catch catch}
30671 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30672
30673 @subsubheading Example
30674
30675 @smallexample
30676 -catch-catch -r exception_type
30677 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30678 what="exception catch",catch-type="catch",
30679 thread-groups=["i1"],
30680 regexp="exception_type",times="0"@}
30681 (gdb)
30682 -exec-run
30683 ^running
30684 (gdb)
30685 ~"\n"
30686 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30687 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30688 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30689 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30690 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30691 thread-id="1",stopped-threads="all",core="6"
30692 (gdb)
30693 @end smallexample
30694
30695 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30696 @node GDB/MI Program Context
30697 @section @sc{gdb/mi} Program Context
30698
30699 @subheading The @code{-exec-arguments} Command
30700 @findex -exec-arguments
30701
30702
30703 @subsubheading Synopsis
30704
30705 @smallexample
30706 -exec-arguments @var{args}
30707 @end smallexample
30708
30709 Set the inferior program arguments, to be used in the next
30710 @samp{-exec-run}.
30711
30712 @subsubheading @value{GDBN} Command
30713
30714 The corresponding @value{GDBN} command is @samp{set args}.
30715
30716 @subsubheading Example
30717
30718 @smallexample
30719 (gdb)
30720 -exec-arguments -v word
30721 ^done
30722 (gdb)
30723 @end smallexample
30724
30725
30726 @ignore
30727 @subheading The @code{-exec-show-arguments} Command
30728 @findex -exec-show-arguments
30729
30730 @subsubheading Synopsis
30731
30732 @smallexample
30733 -exec-show-arguments
30734 @end smallexample
30735
30736 Print the arguments of the program.
30737
30738 @subsubheading @value{GDBN} Command
30739
30740 The corresponding @value{GDBN} command is @samp{show args}.
30741
30742 @subsubheading Example
30743 N.A.
30744 @end ignore
30745
30746
30747 @subheading The @code{-environment-cd} Command
30748 @findex -environment-cd
30749
30750 @subsubheading Synopsis
30751
30752 @smallexample
30753 -environment-cd @var{pathdir}
30754 @end smallexample
30755
30756 Set @value{GDBN}'s working directory.
30757
30758 @subsubheading @value{GDBN} Command
30759
30760 The corresponding @value{GDBN} command is @samp{cd}.
30761
30762 @subsubheading Example
30763
30764 @smallexample
30765 (gdb)
30766 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30767 ^done
30768 (gdb)
30769 @end smallexample
30770
30771
30772 @subheading The @code{-environment-directory} Command
30773 @findex -environment-directory
30774
30775 @subsubheading Synopsis
30776
30777 @smallexample
30778 -environment-directory [ -r ] [ @var{pathdir} ]+
30779 @end smallexample
30780
30781 Add directories @var{pathdir} to beginning of search path for source files.
30782 If the @samp{-r} option is used, the search path is reset to the default
30783 search path. If directories @var{pathdir} are supplied in addition to the
30784 @samp{-r} option, the search path is first reset and then addition
30785 occurs as normal.
30786 Multiple directories may be specified, separated by blanks. Specifying
30787 multiple directories in a single command
30788 results in the directories added to the beginning of the
30789 search path in the same order they were presented in the command.
30790 If blanks are needed as
30791 part of a directory name, double-quotes should be used around
30792 the name. In the command output, the path will show up separated
30793 by the system directory-separator character. The directory-separator
30794 character must not be used
30795 in any directory name.
30796 If no directories are specified, the current search path is displayed.
30797
30798 @subsubheading @value{GDBN} Command
30799
30800 The corresponding @value{GDBN} command is @samp{dir}.
30801
30802 @subsubheading Example
30803
30804 @smallexample
30805 (gdb)
30806 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30807 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30808 (gdb)
30809 -environment-directory ""
30810 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30811 (gdb)
30812 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
30813 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
30814 (gdb)
30815 -environment-directory -r
30816 ^done,source-path="$cdir:$cwd"
30817 (gdb)
30818 @end smallexample
30819
30820
30821 @subheading The @code{-environment-path} Command
30822 @findex -environment-path
30823
30824 @subsubheading Synopsis
30825
30826 @smallexample
30827 -environment-path [ -r ] [ @var{pathdir} ]+
30828 @end smallexample
30829
30830 Add directories @var{pathdir} to beginning of search path for object files.
30831 If the @samp{-r} option is used, the search path is reset to the original
30832 search path that existed at gdb start-up. If directories @var{pathdir} are
30833 supplied in addition to the
30834 @samp{-r} option, the search path is first reset and then addition
30835 occurs as normal.
30836 Multiple directories may be specified, separated by blanks. Specifying
30837 multiple directories in a single command
30838 results in the directories added to the beginning of the
30839 search path in the same order they were presented in the command.
30840 If blanks are needed as
30841 part of a directory name, double-quotes should be used around
30842 the name. In the command output, the path will show up separated
30843 by the system directory-separator character. The directory-separator
30844 character must not be used
30845 in any directory name.
30846 If no directories are specified, the current path is displayed.
30847
30848
30849 @subsubheading @value{GDBN} Command
30850
30851 The corresponding @value{GDBN} command is @samp{path}.
30852
30853 @subsubheading Example
30854
30855 @smallexample
30856 (gdb)
30857 -environment-path
30858 ^done,path="/usr/bin"
30859 (gdb)
30860 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
30861 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
30862 (gdb)
30863 -environment-path -r /usr/local/bin
30864 ^done,path="/usr/local/bin:/usr/bin"
30865 (gdb)
30866 @end smallexample
30867
30868
30869 @subheading The @code{-environment-pwd} Command
30870 @findex -environment-pwd
30871
30872 @subsubheading Synopsis
30873
30874 @smallexample
30875 -environment-pwd
30876 @end smallexample
30877
30878 Show the current working directory.
30879
30880 @subsubheading @value{GDBN} Command
30881
30882 The corresponding @value{GDBN} command is @samp{pwd}.
30883
30884 @subsubheading Example
30885
30886 @smallexample
30887 (gdb)
30888 -environment-pwd
30889 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
30890 (gdb)
30891 @end smallexample
30892
30893 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30894 @node GDB/MI Thread Commands
30895 @section @sc{gdb/mi} Thread Commands
30896
30897
30898 @subheading The @code{-thread-info} Command
30899 @findex -thread-info
30900
30901 @subsubheading Synopsis
30902
30903 @smallexample
30904 -thread-info [ @var{thread-id} ]
30905 @end smallexample
30906
30907 Reports information about either a specific thread, if the
30908 @var{thread-id} parameter is present, or about all threads.
30909 @var{thread-id} is the thread's global thread ID. When printing
30910 information about all threads, also reports the global ID of the
30911 current thread.
30912
30913 @subsubheading @value{GDBN} Command
30914
30915 The @samp{info thread} command prints the same information
30916 about all threads.
30917
30918 @subsubheading Result
30919
30920 The result contains the following attributes:
30921
30922 @table @samp
30923 @item threads
30924 A list of threads. The format of the elements of the list is described in
30925 @ref{GDB/MI Thread Information}.
30926
30927 @item current-thread-id
30928 The global id of the currently selected thread. This field is omitted if there
30929 is no selected thread (for example, when the selected inferior is not running,
30930 and therefore has no threads) or if a @var{thread-id} argument was passed to
30931 the command.
30932
30933 @end table
30934
30935 @subsubheading Example
30936
30937 @smallexample
30938 -thread-info
30939 ^done,threads=[
30940 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
30941 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
30942 args=[]@},state="running"@},
30943 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
30944 frame=@{level="0",addr="0x0804891f",func="foo",
30945 args=[@{name="i",value="10"@}],
30946 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
30947 state="running"@}],
30948 current-thread-id="1"
30949 (gdb)
30950 @end smallexample
30951
30952 @subheading The @code{-thread-list-ids} Command
30953 @findex -thread-list-ids
30954
30955 @subsubheading Synopsis
30956
30957 @smallexample
30958 -thread-list-ids
30959 @end smallexample
30960
30961 Produces a list of the currently known global @value{GDBN} thread ids.
30962 At the end of the list it also prints the total number of such
30963 threads.
30964
30965 This command is retained for historical reasons, the
30966 @code{-thread-info} command should be used instead.
30967
30968 @subsubheading @value{GDBN} Command
30969
30970 Part of @samp{info threads} supplies the same information.
30971
30972 @subsubheading Example
30973
30974 @smallexample
30975 (gdb)
30976 -thread-list-ids
30977 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
30978 current-thread-id="1",number-of-threads="3"
30979 (gdb)
30980 @end smallexample
30981
30982
30983 @subheading The @code{-thread-select} Command
30984 @findex -thread-select
30985
30986 @subsubheading Synopsis
30987
30988 @smallexample
30989 -thread-select @var{thread-id}
30990 @end smallexample
30991
30992 Make thread with global thread number @var{thread-id} the current
30993 thread. It prints the number of the new current thread, and the
30994 topmost frame for that thread.
30995
30996 This command is deprecated in favor of explicitly using the
30997 @samp{--thread} option to each command.
30998
30999 @subsubheading @value{GDBN} Command
31000
31001 The corresponding @value{GDBN} command is @samp{thread}.
31002
31003 @subsubheading Example
31004
31005 @smallexample
31006 (gdb)
31007 -exec-next
31008 ^running
31009 (gdb)
31010 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31011 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31012 (gdb)
31013 -thread-list-ids
31014 ^done,
31015 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31016 number-of-threads="3"
31017 (gdb)
31018 -thread-select 3
31019 ^done,new-thread-id="3",
31020 frame=@{level="0",func="vprintf",
31021 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31022 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31023 (gdb)
31024 @end smallexample
31025
31026 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31027 @node GDB/MI Ada Tasking Commands
31028 @section @sc{gdb/mi} Ada Tasking Commands
31029
31030 @subheading The @code{-ada-task-info} Command
31031 @findex -ada-task-info
31032
31033 @subsubheading Synopsis
31034
31035 @smallexample
31036 -ada-task-info [ @var{task-id} ]
31037 @end smallexample
31038
31039 Reports information about either a specific Ada task, if the
31040 @var{task-id} parameter is present, or about all Ada tasks.
31041
31042 @subsubheading @value{GDBN} Command
31043
31044 The @samp{info tasks} command prints the same information
31045 about all Ada tasks (@pxref{Ada Tasks}).
31046
31047 @subsubheading Result
31048
31049 The result is a table of Ada tasks. The following columns are
31050 defined for each Ada task:
31051
31052 @table @samp
31053 @item current
31054 This field exists only for the current thread. It has the value @samp{*}.
31055
31056 @item id
31057 The identifier that @value{GDBN} uses to refer to the Ada task.
31058
31059 @item task-id
31060 The identifier that the target uses to refer to the Ada task.
31061
31062 @item thread-id
31063 The global thread identifier of the thread corresponding to the Ada
31064 task.
31065
31066 This field should always exist, as Ada tasks are always implemented
31067 on top of a thread. But if @value{GDBN} cannot find this corresponding
31068 thread for any reason, the field is omitted.
31069
31070 @item parent-id
31071 This field exists only when the task was created by another task.
31072 In this case, it provides the ID of the parent task.
31073
31074 @item priority
31075 The base priority of the task.
31076
31077 @item state
31078 The current state of the task. For a detailed description of the
31079 possible states, see @ref{Ada Tasks}.
31080
31081 @item name
31082 The name of the task.
31083
31084 @end table
31085
31086 @subsubheading Example
31087
31088 @smallexample
31089 -ada-task-info
31090 ^done,tasks=@{nr_rows="3",nr_cols="8",
31091 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31092 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31093 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31094 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31095 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31096 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31097 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31098 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31099 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31100 state="Child Termination Wait",name="main_task"@}]@}
31101 (gdb)
31102 @end smallexample
31103
31104 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31105 @node GDB/MI Program Execution
31106 @section @sc{gdb/mi} Program Execution
31107
31108 These are the asynchronous commands which generate the out-of-band
31109 record @samp{*stopped}. Currently @value{GDBN} only really executes
31110 asynchronously with remote targets and this interaction is mimicked in
31111 other cases.
31112
31113 @subheading The @code{-exec-continue} Command
31114 @findex -exec-continue
31115
31116 @subsubheading Synopsis
31117
31118 @smallexample
31119 -exec-continue [--reverse] [--all|--thread-group N]
31120 @end smallexample
31121
31122 Resumes the execution of the inferior program, which will continue
31123 to execute until it reaches a debugger stop event. If the
31124 @samp{--reverse} option is specified, execution resumes in reverse until
31125 it reaches a stop event. Stop events may include
31126 @itemize @bullet
31127 @item
31128 breakpoints or watchpoints
31129 @item
31130 signals or exceptions
31131 @item
31132 the end of the process (or its beginning under @samp{--reverse})
31133 @item
31134 the end or beginning of a replay log if one is being used.
31135 @end itemize
31136 In all-stop mode (@pxref{All-Stop
31137 Mode}), may resume only one thread, or all threads, depending on the
31138 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31139 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31140 ignored in all-stop mode. If the @samp{--thread-group} options is
31141 specified, then all threads in that thread group are resumed.
31142
31143 @subsubheading @value{GDBN} Command
31144
31145 The corresponding @value{GDBN} corresponding is @samp{continue}.
31146
31147 @subsubheading Example
31148
31149 @smallexample
31150 -exec-continue
31151 ^running
31152 (gdb)
31153 @@Hello world
31154 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31155 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31156 line="13",arch="i386:x86_64"@}
31157 (gdb)
31158 @end smallexample
31159
31160
31161 @subheading The @code{-exec-finish} Command
31162 @findex -exec-finish
31163
31164 @subsubheading Synopsis
31165
31166 @smallexample
31167 -exec-finish [--reverse]
31168 @end smallexample
31169
31170 Resumes the execution of the inferior program until the current
31171 function is exited. Displays the results returned by the function.
31172 If the @samp{--reverse} option is specified, resumes the reverse
31173 execution of the inferior program until the point where current
31174 function was called.
31175
31176 @subsubheading @value{GDBN} Command
31177
31178 The corresponding @value{GDBN} command is @samp{finish}.
31179
31180 @subsubheading Example
31181
31182 Function returning @code{void}.
31183
31184 @smallexample
31185 -exec-finish
31186 ^running
31187 (gdb)
31188 @@hello from foo
31189 *stopped,reason="function-finished",frame=@{func="main",args=[],
31190 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31191 (gdb)
31192 @end smallexample
31193
31194 Function returning other than @code{void}. The name of the internal
31195 @value{GDBN} variable storing the result is printed, together with the
31196 value itself.
31197
31198 @smallexample
31199 -exec-finish
31200 ^running
31201 (gdb)
31202 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31203 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31204 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31205 arch="i386:x86_64"@},
31206 gdb-result-var="$1",return-value="0"
31207 (gdb)
31208 @end smallexample
31209
31210
31211 @subheading The @code{-exec-interrupt} Command
31212 @findex -exec-interrupt
31213
31214 @subsubheading Synopsis
31215
31216 @smallexample
31217 -exec-interrupt [--all|--thread-group N]
31218 @end smallexample
31219
31220 Interrupts the background execution of the target. Note how the token
31221 associated with the stop message is the one for the execution command
31222 that has been interrupted. The token for the interrupt itself only
31223 appears in the @samp{^done} output. If the user is trying to
31224 interrupt a non-running program, an error message will be printed.
31225
31226 Note that when asynchronous execution is enabled, this command is
31227 asynchronous just like other execution commands. That is, first the
31228 @samp{^done} response will be printed, and the target stop will be
31229 reported after that using the @samp{*stopped} notification.
31230
31231 In non-stop mode, only the context thread is interrupted by default.
31232 All threads (in all inferiors) will be interrupted if the
31233 @samp{--all} option is specified. If the @samp{--thread-group}
31234 option is specified, all threads in that group will be interrupted.
31235
31236 @subsubheading @value{GDBN} Command
31237
31238 The corresponding @value{GDBN} command is @samp{interrupt}.
31239
31240 @subsubheading Example
31241
31242 @smallexample
31243 (gdb)
31244 111-exec-continue
31245 111^running
31246
31247 (gdb)
31248 222-exec-interrupt
31249 222^done
31250 (gdb)
31251 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
31252 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
31253 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
31254 (gdb)
31255
31256 (gdb)
31257 -exec-interrupt
31258 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
31259 (gdb)
31260 @end smallexample
31261
31262 @subheading The @code{-exec-jump} Command
31263 @findex -exec-jump
31264
31265 @subsubheading Synopsis
31266
31267 @smallexample
31268 -exec-jump @var{location}
31269 @end smallexample
31270
31271 Resumes execution of the inferior program at the location specified by
31272 parameter. @xref{Specify Location}, for a description of the
31273 different forms of @var{location}.
31274
31275 @subsubheading @value{GDBN} Command
31276
31277 The corresponding @value{GDBN} command is @samp{jump}.
31278
31279 @subsubheading Example
31280
31281 @smallexample
31282 -exec-jump foo.c:10
31283 *running,thread-id="all"
31284 ^running
31285 @end smallexample
31286
31287
31288 @subheading The @code{-exec-next} Command
31289 @findex -exec-next
31290
31291 @subsubheading Synopsis
31292
31293 @smallexample
31294 -exec-next [--reverse]
31295 @end smallexample
31296
31297 Resumes execution of the inferior program, stopping when the beginning
31298 of the next source line is reached.
31299
31300 If the @samp{--reverse} option is specified, resumes reverse execution
31301 of the inferior program, stopping at the beginning of the previous
31302 source line. If you issue this command on the first line of a
31303 function, it will take you back to the caller of that function, to the
31304 source line where the function was called.
31305
31306
31307 @subsubheading @value{GDBN} Command
31308
31309 The corresponding @value{GDBN} command is @samp{next}.
31310
31311 @subsubheading Example
31312
31313 @smallexample
31314 -exec-next
31315 ^running
31316 (gdb)
31317 *stopped,reason="end-stepping-range",line="8",file="hello.c"
31318 (gdb)
31319 @end smallexample
31320
31321
31322 @subheading The @code{-exec-next-instruction} Command
31323 @findex -exec-next-instruction
31324
31325 @subsubheading Synopsis
31326
31327 @smallexample
31328 -exec-next-instruction [--reverse]
31329 @end smallexample
31330
31331 Executes one machine instruction. If the instruction is a function
31332 call, continues until the function returns. If the program stops at an
31333 instruction in the middle of a source line, the address will be
31334 printed as well.
31335
31336 If the @samp{--reverse} option is specified, resumes reverse execution
31337 of the inferior program, stopping at the previous instruction. If the
31338 previously executed instruction was a return from another function,
31339 it will continue to execute in reverse until the call to that function
31340 (from the current stack frame) is reached.
31341
31342 @subsubheading @value{GDBN} Command
31343
31344 The corresponding @value{GDBN} command is @samp{nexti}.
31345
31346 @subsubheading Example
31347
31348 @smallexample
31349 (gdb)
31350 -exec-next-instruction
31351 ^running
31352
31353 (gdb)
31354 *stopped,reason="end-stepping-range",
31355 addr="0x000100d4",line="5",file="hello.c"
31356 (gdb)
31357 @end smallexample
31358
31359
31360 @subheading The @code{-exec-return} Command
31361 @findex -exec-return
31362
31363 @subsubheading Synopsis
31364
31365 @smallexample
31366 -exec-return
31367 @end smallexample
31368
31369 Makes current function return immediately. Doesn't execute the inferior.
31370 Displays the new current frame.
31371
31372 @subsubheading @value{GDBN} Command
31373
31374 The corresponding @value{GDBN} command is @samp{return}.
31375
31376 @subsubheading Example
31377
31378 @smallexample
31379 (gdb)
31380 200-break-insert callee4
31381 200^done,bkpt=@{number="1",addr="0x00010734",
31382 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31383 (gdb)
31384 000-exec-run
31385 000^running
31386 (gdb)
31387 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31388 frame=@{func="callee4",args=[],
31389 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31390 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31391 arch="i386:x86_64"@}
31392 (gdb)
31393 205-break-delete
31394 205^done
31395 (gdb)
31396 111-exec-return
31397 111^done,frame=@{level="0",func="callee3",
31398 args=[@{name="strarg",
31399 value="0x11940 \"A string argument.\""@}],
31400 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31401 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31402 arch="i386:x86_64"@}
31403 (gdb)
31404 @end smallexample
31405
31406
31407 @subheading The @code{-exec-run} Command
31408 @findex -exec-run
31409
31410 @subsubheading Synopsis
31411
31412 @smallexample
31413 -exec-run [ --all | --thread-group N ] [ --start ]
31414 @end smallexample
31415
31416 Starts execution of the inferior from the beginning. The inferior
31417 executes until either a breakpoint is encountered or the program
31418 exits. In the latter case the output will include an exit code, if
31419 the program has exited exceptionally.
31420
31421 When neither the @samp{--all} nor the @samp{--thread-group} option
31422 is specified, the current inferior is started. If the
31423 @samp{--thread-group} option is specified, it should refer to a thread
31424 group of type @samp{process}, and that thread group will be started.
31425 If the @samp{--all} option is specified, then all inferiors will be started.
31426
31427 Using the @samp{--start} option instructs the debugger to stop
31428 the execution at the start of the inferior's main subprogram,
31429 following the same behavior as the @code{start} command
31430 (@pxref{Starting}).
31431
31432 @subsubheading @value{GDBN} Command
31433
31434 The corresponding @value{GDBN} command is @samp{run}.
31435
31436 @subsubheading Examples
31437
31438 @smallexample
31439 (gdb)
31440 -break-insert main
31441 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31442 (gdb)
31443 -exec-run
31444 ^running
31445 (gdb)
31446 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31447 frame=@{func="main",args=[],file="recursive2.c",
31448 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
31449 (gdb)
31450 @end smallexample
31451
31452 @noindent
31453 Program exited normally:
31454
31455 @smallexample
31456 (gdb)
31457 -exec-run
31458 ^running
31459 (gdb)
31460 x = 55
31461 *stopped,reason="exited-normally"
31462 (gdb)
31463 @end smallexample
31464
31465 @noindent
31466 Program exited exceptionally:
31467
31468 @smallexample
31469 (gdb)
31470 -exec-run
31471 ^running
31472 (gdb)
31473 x = 55
31474 *stopped,reason="exited",exit-code="01"
31475 (gdb)
31476 @end smallexample
31477
31478 Another way the program can terminate is if it receives a signal such as
31479 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31480
31481 @smallexample
31482 (gdb)
31483 *stopped,reason="exited-signalled",signal-name="SIGINT",
31484 signal-meaning="Interrupt"
31485 @end smallexample
31486
31487
31488 @c @subheading -exec-signal
31489
31490
31491 @subheading The @code{-exec-step} Command
31492 @findex -exec-step
31493
31494 @subsubheading Synopsis
31495
31496 @smallexample
31497 -exec-step [--reverse]
31498 @end smallexample
31499
31500 Resumes execution of the inferior program, stopping when the beginning
31501 of the next source line is reached, if the next source line is not a
31502 function call. If it is, stop at the first instruction of the called
31503 function. If the @samp{--reverse} option is specified, resumes reverse
31504 execution of the inferior program, stopping at the beginning of the
31505 previously executed source line.
31506
31507 @subsubheading @value{GDBN} Command
31508
31509 The corresponding @value{GDBN} command is @samp{step}.
31510
31511 @subsubheading Example
31512
31513 Stepping into a function:
31514
31515 @smallexample
31516 -exec-step
31517 ^running
31518 (gdb)
31519 *stopped,reason="end-stepping-range",
31520 frame=@{func="foo",args=[@{name="a",value="10"@},
31521 @{name="b",value="0"@}],file="recursive2.c",
31522 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
31523 (gdb)
31524 @end smallexample
31525
31526 Regular stepping:
31527
31528 @smallexample
31529 -exec-step
31530 ^running
31531 (gdb)
31532 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
31533 (gdb)
31534 @end smallexample
31535
31536
31537 @subheading The @code{-exec-step-instruction} Command
31538 @findex -exec-step-instruction
31539
31540 @subsubheading Synopsis
31541
31542 @smallexample
31543 -exec-step-instruction [--reverse]
31544 @end smallexample
31545
31546 Resumes the inferior which executes one machine instruction. If the
31547 @samp{--reverse} option is specified, resumes reverse execution of the
31548 inferior program, stopping at the previously executed instruction.
31549 The output, once @value{GDBN} has stopped, will vary depending on
31550 whether we have stopped in the middle of a source line or not. In the
31551 former case, the address at which the program stopped will be printed
31552 as well.
31553
31554 @subsubheading @value{GDBN} Command
31555
31556 The corresponding @value{GDBN} command is @samp{stepi}.
31557
31558 @subsubheading Example
31559
31560 @smallexample
31561 (gdb)
31562 -exec-step-instruction
31563 ^running
31564
31565 (gdb)
31566 *stopped,reason="end-stepping-range",
31567 frame=@{func="foo",args=[],file="try.c",
31568 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31569 (gdb)
31570 -exec-step-instruction
31571 ^running
31572
31573 (gdb)
31574 *stopped,reason="end-stepping-range",
31575 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
31576 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31577 (gdb)
31578 @end smallexample
31579
31580
31581 @subheading The @code{-exec-until} Command
31582 @findex -exec-until
31583
31584 @subsubheading Synopsis
31585
31586 @smallexample
31587 -exec-until [ @var{location} ]
31588 @end smallexample
31589
31590 Executes the inferior until the @var{location} specified in the
31591 argument is reached. If there is no argument, the inferior executes
31592 until a source line greater than the current one is reached. The
31593 reason for stopping in this case will be @samp{location-reached}.
31594
31595 @subsubheading @value{GDBN} Command
31596
31597 The corresponding @value{GDBN} command is @samp{until}.
31598
31599 @subsubheading Example
31600
31601 @smallexample
31602 (gdb)
31603 -exec-until recursive2.c:6
31604 ^running
31605 (gdb)
31606 x = 55
31607 *stopped,reason="location-reached",frame=@{func="main",args=[],
31608 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31609 arch="i386:x86_64"@}
31610 (gdb)
31611 @end smallexample
31612
31613 @ignore
31614 @subheading -file-clear
31615 Is this going away????
31616 @end ignore
31617
31618 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31619 @node GDB/MI Stack Manipulation
31620 @section @sc{gdb/mi} Stack Manipulation Commands
31621
31622 @subheading The @code{-enable-frame-filters} Command
31623 @findex -enable-frame-filters
31624
31625 @smallexample
31626 -enable-frame-filters
31627 @end smallexample
31628
31629 @value{GDBN} allows Python-based frame filters to affect the output of
31630 the MI commands relating to stack traces. As there is no way to
31631 implement this in a fully backward-compatible way, a front end must
31632 request that this functionality be enabled.
31633
31634 Once enabled, this feature cannot be disabled.
31635
31636 Note that if Python support has not been compiled into @value{GDBN},
31637 this command will still succeed (and do nothing).
31638
31639 @subheading The @code{-stack-info-frame} Command
31640 @findex -stack-info-frame
31641
31642 @subsubheading Synopsis
31643
31644 @smallexample
31645 -stack-info-frame
31646 @end smallexample
31647
31648 Get info on the selected frame.
31649
31650 @subsubheading @value{GDBN} Command
31651
31652 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31653 (without arguments).
31654
31655 @subsubheading Example
31656
31657 @smallexample
31658 (gdb)
31659 -stack-info-frame
31660 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31661 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31662 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31663 arch="i386:x86_64"@}
31664 (gdb)
31665 @end smallexample
31666
31667 @subheading The @code{-stack-info-depth} Command
31668 @findex -stack-info-depth
31669
31670 @subsubheading Synopsis
31671
31672 @smallexample
31673 -stack-info-depth [ @var{max-depth} ]
31674 @end smallexample
31675
31676 Return the depth of the stack. If the integer argument @var{max-depth}
31677 is specified, do not count beyond @var{max-depth} frames.
31678
31679 @subsubheading @value{GDBN} Command
31680
31681 There's no equivalent @value{GDBN} command.
31682
31683 @subsubheading Example
31684
31685 For a stack with frame levels 0 through 11:
31686
31687 @smallexample
31688 (gdb)
31689 -stack-info-depth
31690 ^done,depth="12"
31691 (gdb)
31692 -stack-info-depth 4
31693 ^done,depth="4"
31694 (gdb)
31695 -stack-info-depth 12
31696 ^done,depth="12"
31697 (gdb)
31698 -stack-info-depth 11
31699 ^done,depth="11"
31700 (gdb)
31701 -stack-info-depth 13
31702 ^done,depth="12"
31703 (gdb)
31704 @end smallexample
31705
31706 @anchor{-stack-list-arguments}
31707 @subheading The @code{-stack-list-arguments} Command
31708 @findex -stack-list-arguments
31709
31710 @subsubheading Synopsis
31711
31712 @smallexample
31713 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31714 [ @var{low-frame} @var{high-frame} ]
31715 @end smallexample
31716
31717 Display a list of the arguments for the frames between @var{low-frame}
31718 and @var{high-frame} (inclusive). If @var{low-frame} and
31719 @var{high-frame} are not provided, list the arguments for the whole
31720 call stack. If the two arguments are equal, show the single frame
31721 at the corresponding level. It is an error if @var{low-frame} is
31722 larger than the actual number of frames. On the other hand,
31723 @var{high-frame} may be larger than the actual number of frames, in
31724 which case only existing frames will be returned.
31725
31726 If @var{print-values} is 0 or @code{--no-values}, print only the names of
31727 the variables; if it is 1 or @code{--all-values}, print also their
31728 values; and if it is 2 or @code{--simple-values}, print the name,
31729 type and value for simple data types, and the name and type for arrays,
31730 structures and unions. If the option @code{--no-frame-filters} is
31731 supplied, then Python frame filters will not be executed.
31732
31733 If the @code{--skip-unavailable} option is specified, arguments that
31734 are not available are not listed. Partially available arguments
31735 are still displayed, however.
31736
31737 Use of this command to obtain arguments in a single frame is
31738 deprecated in favor of the @samp{-stack-list-variables} command.
31739
31740 @subsubheading @value{GDBN} Command
31741
31742 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31743 @samp{gdb_get_args} command which partially overlaps with the
31744 functionality of @samp{-stack-list-arguments}.
31745
31746 @subsubheading Example
31747
31748 @smallexample
31749 (gdb)
31750 -stack-list-frames
31751 ^done,
31752 stack=[
31753 frame=@{level="0",addr="0x00010734",func="callee4",
31754 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31755 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31756 arch="i386:x86_64"@},
31757 frame=@{level="1",addr="0x0001076c",func="callee3",
31758 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31759 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31760 arch="i386:x86_64"@},
31761 frame=@{level="2",addr="0x0001078c",func="callee2",
31762 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31763 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31764 arch="i386:x86_64"@},
31765 frame=@{level="3",addr="0x000107b4",func="callee1",
31766 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31767 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31768 arch="i386:x86_64"@},
31769 frame=@{level="4",addr="0x000107e0",func="main",
31770 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31771 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31772 arch="i386:x86_64"@}]
31773 (gdb)
31774 -stack-list-arguments 0
31775 ^done,
31776 stack-args=[
31777 frame=@{level="0",args=[]@},
31778 frame=@{level="1",args=[name="strarg"]@},
31779 frame=@{level="2",args=[name="intarg",name="strarg"]@},
31780 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31781 frame=@{level="4",args=[]@}]
31782 (gdb)
31783 -stack-list-arguments 1
31784 ^done,
31785 stack-args=[
31786 frame=@{level="0",args=[]@},
31787 frame=@{level="1",
31788 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31789 frame=@{level="2",args=[
31790 @{name="intarg",value="2"@},
31791 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31792 @{frame=@{level="3",args=[
31793 @{name="intarg",value="2"@},
31794 @{name="strarg",value="0x11940 \"A string argument.\""@},
31795 @{name="fltarg",value="3.5"@}]@},
31796 frame=@{level="4",args=[]@}]
31797 (gdb)
31798 -stack-list-arguments 0 2 2
31799 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
31800 (gdb)
31801 -stack-list-arguments 1 2 2
31802 ^done,stack-args=[frame=@{level="2",
31803 args=[@{name="intarg",value="2"@},
31804 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
31805 (gdb)
31806 @end smallexample
31807
31808 @c @subheading -stack-list-exception-handlers
31809
31810
31811 @anchor{-stack-list-frames}
31812 @subheading The @code{-stack-list-frames} Command
31813 @findex -stack-list-frames
31814
31815 @subsubheading Synopsis
31816
31817 @smallexample
31818 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
31819 @end smallexample
31820
31821 List the frames currently on the stack. For each frame it displays the
31822 following info:
31823
31824 @table @samp
31825 @item @var{level}
31826 The frame number, 0 being the topmost frame, i.e., the innermost function.
31827 @item @var{addr}
31828 The @code{$pc} value for that frame.
31829 @item @var{func}
31830 Function name.
31831 @item @var{file}
31832 File name of the source file where the function lives.
31833 @item @var{fullname}
31834 The full file name of the source file where the function lives.
31835 @item @var{line}
31836 Line number corresponding to the @code{$pc}.
31837 @item @var{from}
31838 The shared library where this function is defined. This is only given
31839 if the frame's function is not known.
31840 @item @var{arch}
31841 Frame's architecture.
31842 @end table
31843
31844 If invoked without arguments, this command prints a backtrace for the
31845 whole stack. If given two integer arguments, it shows the frames whose
31846 levels are between the two arguments (inclusive). If the two arguments
31847 are equal, it shows the single frame at the corresponding level. It is
31848 an error if @var{low-frame} is larger than the actual number of
31849 frames. On the other hand, @var{high-frame} may be larger than the
31850 actual number of frames, in which case only existing frames will be
31851 returned. If the option @code{--no-frame-filters} is supplied, then
31852 Python frame filters will not be executed.
31853
31854 @subsubheading @value{GDBN} Command
31855
31856 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
31857
31858 @subsubheading Example
31859
31860 Full stack backtrace:
31861
31862 @smallexample
31863 (gdb)
31864 -stack-list-frames
31865 ^done,stack=
31866 [frame=@{level="0",addr="0x0001076c",func="foo",
31867 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
31868 arch="i386:x86_64"@},
31869 frame=@{level="1",addr="0x000107a4",func="foo",
31870 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31871 arch="i386:x86_64"@},
31872 frame=@{level="2",addr="0x000107a4",func="foo",
31873 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31874 arch="i386:x86_64"@},
31875 frame=@{level="3",addr="0x000107a4",func="foo",
31876 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31877 arch="i386:x86_64"@},
31878 frame=@{level="4",addr="0x000107a4",func="foo",
31879 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31880 arch="i386:x86_64"@},
31881 frame=@{level="5",addr="0x000107a4",func="foo",
31882 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31883 arch="i386:x86_64"@},
31884 frame=@{level="6",addr="0x000107a4",func="foo",
31885 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31886 arch="i386:x86_64"@},
31887 frame=@{level="7",addr="0x000107a4",func="foo",
31888 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31889 arch="i386:x86_64"@},
31890 frame=@{level="8",addr="0x000107a4",func="foo",
31891 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31892 arch="i386:x86_64"@},
31893 frame=@{level="9",addr="0x000107a4",func="foo",
31894 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31895 arch="i386:x86_64"@},
31896 frame=@{level="10",addr="0x000107a4",func="foo",
31897 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31898 arch="i386:x86_64"@},
31899 frame=@{level="11",addr="0x00010738",func="main",
31900 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
31901 arch="i386:x86_64"@}]
31902 (gdb)
31903 @end smallexample
31904
31905 Show frames between @var{low_frame} and @var{high_frame}:
31906
31907 @smallexample
31908 (gdb)
31909 -stack-list-frames 3 5
31910 ^done,stack=
31911 [frame=@{level="3",addr="0x000107a4",func="foo",
31912 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31913 arch="i386:x86_64"@},
31914 frame=@{level="4",addr="0x000107a4",func="foo",
31915 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31916 arch="i386:x86_64"@},
31917 frame=@{level="5",addr="0x000107a4",func="foo",
31918 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31919 arch="i386:x86_64"@}]
31920 (gdb)
31921 @end smallexample
31922
31923 Show a single frame:
31924
31925 @smallexample
31926 (gdb)
31927 -stack-list-frames 3 3
31928 ^done,stack=
31929 [frame=@{level="3",addr="0x000107a4",func="foo",
31930 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31931 arch="i386:x86_64"@}]
31932 (gdb)
31933 @end smallexample
31934
31935
31936 @subheading The @code{-stack-list-locals} Command
31937 @findex -stack-list-locals
31938 @anchor{-stack-list-locals}
31939
31940 @subsubheading Synopsis
31941
31942 @smallexample
31943 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31944 @end smallexample
31945
31946 Display the local variable names for the selected frame. If
31947 @var{print-values} is 0 or @code{--no-values}, print only the names of
31948 the variables; if it is 1 or @code{--all-values}, print also their
31949 values; and if it is 2 or @code{--simple-values}, print the name,
31950 type and value for simple data types, and the name and type for arrays,
31951 structures and unions. In this last case, a frontend can immediately
31952 display the value of simple data types and create variable objects for
31953 other data types when the user wishes to explore their values in
31954 more detail. If the option @code{--no-frame-filters} is supplied, then
31955 Python frame filters will not be executed.
31956
31957 If the @code{--skip-unavailable} option is specified, local variables
31958 that are not available are not listed. Partially available local
31959 variables are still displayed, however.
31960
31961 This command is deprecated in favor of the
31962 @samp{-stack-list-variables} command.
31963
31964 @subsubheading @value{GDBN} Command
31965
31966 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
31967
31968 @subsubheading Example
31969
31970 @smallexample
31971 (gdb)
31972 -stack-list-locals 0
31973 ^done,locals=[name="A",name="B",name="C"]
31974 (gdb)
31975 -stack-list-locals --all-values
31976 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
31977 @{name="C",value="@{1, 2, 3@}"@}]
31978 -stack-list-locals --simple-values
31979 ^done,locals=[@{name="A",type="int",value="1"@},
31980 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
31981 (gdb)
31982 @end smallexample
31983
31984 @anchor{-stack-list-variables}
31985 @subheading The @code{-stack-list-variables} Command
31986 @findex -stack-list-variables
31987
31988 @subsubheading Synopsis
31989
31990 @smallexample
31991 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31992 @end smallexample
31993
31994 Display the names of local variables and function arguments for the selected frame. If
31995 @var{print-values} is 0 or @code{--no-values}, print only the names of
31996 the variables; if it is 1 or @code{--all-values}, print also their
31997 values; and if it is 2 or @code{--simple-values}, print the name,
31998 type and value for simple data types, and the name and type for arrays,
31999 structures and unions. If the option @code{--no-frame-filters} is
32000 supplied, then Python frame filters will not be executed.
32001
32002 If the @code{--skip-unavailable} option is specified, local variables
32003 and arguments that are not available are not listed. Partially
32004 available arguments and local variables are still displayed, however.
32005
32006 @subsubheading Example
32007
32008 @smallexample
32009 (gdb)
32010 -stack-list-variables --thread 1 --frame 0 --all-values
32011 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32012 (gdb)
32013 @end smallexample
32014
32015
32016 @subheading The @code{-stack-select-frame} Command
32017 @findex -stack-select-frame
32018
32019 @subsubheading Synopsis
32020
32021 @smallexample
32022 -stack-select-frame @var{framenum}
32023 @end smallexample
32024
32025 Change the selected frame. Select a different frame @var{framenum} on
32026 the stack.
32027
32028 This command in deprecated in favor of passing the @samp{--frame}
32029 option to every command.
32030
32031 @subsubheading @value{GDBN} Command
32032
32033 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32034 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32035
32036 @subsubheading Example
32037
32038 @smallexample
32039 (gdb)
32040 -stack-select-frame 2
32041 ^done
32042 (gdb)
32043 @end smallexample
32044
32045 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32046 @node GDB/MI Variable Objects
32047 @section @sc{gdb/mi} Variable Objects
32048
32049 @ignore
32050
32051 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32052
32053 For the implementation of a variable debugger window (locals, watched
32054 expressions, etc.), we are proposing the adaptation of the existing code
32055 used by @code{Insight}.
32056
32057 The two main reasons for that are:
32058
32059 @enumerate 1
32060 @item
32061 It has been proven in practice (it is already on its second generation).
32062
32063 @item
32064 It will shorten development time (needless to say how important it is
32065 now).
32066 @end enumerate
32067
32068 The original interface was designed to be used by Tcl code, so it was
32069 slightly changed so it could be used through @sc{gdb/mi}. This section
32070 describes the @sc{gdb/mi} operations that will be available and gives some
32071 hints about their use.
32072
32073 @emph{Note}: In addition to the set of operations described here, we
32074 expect the @sc{gui} implementation of a variable window to require, at
32075 least, the following operations:
32076
32077 @itemize @bullet
32078 @item @code{-gdb-show} @code{output-radix}
32079 @item @code{-stack-list-arguments}
32080 @item @code{-stack-list-locals}
32081 @item @code{-stack-select-frame}
32082 @end itemize
32083
32084 @end ignore
32085
32086 @subheading Introduction to Variable Objects
32087
32088 @cindex variable objects in @sc{gdb/mi}
32089
32090 Variable objects are "object-oriented" MI interface for examining and
32091 changing values of expressions. Unlike some other MI interfaces that
32092 work with expressions, variable objects are specifically designed for
32093 simple and efficient presentation in the frontend. A variable object
32094 is identified by string name. When a variable object is created, the
32095 frontend specifies the expression for that variable object. The
32096 expression can be a simple variable, or it can be an arbitrary complex
32097 expression, and can even involve CPU registers. After creating a
32098 variable object, the frontend can invoke other variable object
32099 operations---for example to obtain or change the value of a variable
32100 object, or to change display format.
32101
32102 Variable objects have hierarchical tree structure. Any variable object
32103 that corresponds to a composite type, such as structure in C, has
32104 a number of child variable objects, for example corresponding to each
32105 element of a structure. A child variable object can itself have
32106 children, recursively. Recursion ends when we reach
32107 leaf variable objects, which always have built-in types. Child variable
32108 objects are created only by explicit request, so if a frontend
32109 is not interested in the children of a particular variable object, no
32110 child will be created.
32111
32112 For a leaf variable object it is possible to obtain its value as a
32113 string, or set the value from a string. String value can be also
32114 obtained for a non-leaf variable object, but it's generally a string
32115 that only indicates the type of the object, and does not list its
32116 contents. Assignment to a non-leaf variable object is not allowed.
32117
32118 A frontend does not need to read the values of all variable objects each time
32119 the program stops. Instead, MI provides an update command that lists all
32120 variable objects whose values has changed since the last update
32121 operation. This considerably reduces the amount of data that must
32122 be transferred to the frontend. As noted above, children variable
32123 objects are created on demand, and only leaf variable objects have a
32124 real value. As result, gdb will read target memory only for leaf
32125 variables that frontend has created.
32126
32127 The automatic update is not always desirable. For example, a frontend
32128 might want to keep a value of some expression for future reference,
32129 and never update it. For another example, fetching memory is
32130 relatively slow for embedded targets, so a frontend might want
32131 to disable automatic update for the variables that are either not
32132 visible on the screen, or ``closed''. This is possible using so
32133 called ``frozen variable objects''. Such variable objects are never
32134 implicitly updated.
32135
32136 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32137 fixed variable object, the expression is parsed when the variable
32138 object is created, including associating identifiers to specific
32139 variables. The meaning of expression never changes. For a floating
32140 variable object the values of variables whose names appear in the
32141 expressions are re-evaluated every time in the context of the current
32142 frame. Consider this example:
32143
32144 @smallexample
32145 void do_work(...)
32146 @{
32147 struct work_state state;
32148
32149 if (...)
32150 do_work(...);
32151 @}
32152 @end smallexample
32153
32154 If a fixed variable object for the @code{state} variable is created in
32155 this function, and we enter the recursive call, the variable
32156 object will report the value of @code{state} in the top-level
32157 @code{do_work} invocation. On the other hand, a floating variable
32158 object will report the value of @code{state} in the current frame.
32159
32160 If an expression specified when creating a fixed variable object
32161 refers to a local variable, the variable object becomes bound to the
32162 thread and frame in which the variable object is created. When such
32163 variable object is updated, @value{GDBN} makes sure that the
32164 thread/frame combination the variable object is bound to still exists,
32165 and re-evaluates the variable object in context of that thread/frame.
32166
32167 The following is the complete set of @sc{gdb/mi} operations defined to
32168 access this functionality:
32169
32170 @multitable @columnfractions .4 .6
32171 @item @strong{Operation}
32172 @tab @strong{Description}
32173
32174 @item @code{-enable-pretty-printing}
32175 @tab enable Python-based pretty-printing
32176 @item @code{-var-create}
32177 @tab create a variable object
32178 @item @code{-var-delete}
32179 @tab delete the variable object and/or its children
32180 @item @code{-var-set-format}
32181 @tab set the display format of this variable
32182 @item @code{-var-show-format}
32183 @tab show the display format of this variable
32184 @item @code{-var-info-num-children}
32185 @tab tells how many children this object has
32186 @item @code{-var-list-children}
32187 @tab return a list of the object's children
32188 @item @code{-var-info-type}
32189 @tab show the type of this variable object
32190 @item @code{-var-info-expression}
32191 @tab print parent-relative expression that this variable object represents
32192 @item @code{-var-info-path-expression}
32193 @tab print full expression that this variable object represents
32194 @item @code{-var-show-attributes}
32195 @tab is this variable editable? does it exist here?
32196 @item @code{-var-evaluate-expression}
32197 @tab get the value of this variable
32198 @item @code{-var-assign}
32199 @tab set the value of this variable
32200 @item @code{-var-update}
32201 @tab update the variable and its children
32202 @item @code{-var-set-frozen}
32203 @tab set frozenness attribute
32204 @item @code{-var-set-update-range}
32205 @tab set range of children to display on update
32206 @end multitable
32207
32208 In the next subsection we describe each operation in detail and suggest
32209 how it can be used.
32210
32211 @subheading Description And Use of Operations on Variable Objects
32212
32213 @subheading The @code{-enable-pretty-printing} Command
32214 @findex -enable-pretty-printing
32215
32216 @smallexample
32217 -enable-pretty-printing
32218 @end smallexample
32219
32220 @value{GDBN} allows Python-based visualizers to affect the output of the
32221 MI variable object commands. However, because there was no way to
32222 implement this in a fully backward-compatible way, a front end must
32223 request that this functionality be enabled.
32224
32225 Once enabled, this feature cannot be disabled.
32226
32227 Note that if Python support has not been compiled into @value{GDBN},
32228 this command will still succeed (and do nothing).
32229
32230 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32231 may work differently in future versions of @value{GDBN}.
32232
32233 @subheading The @code{-var-create} Command
32234 @findex -var-create
32235
32236 @subsubheading Synopsis
32237
32238 @smallexample
32239 -var-create @{@var{name} | "-"@}
32240 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32241 @end smallexample
32242
32243 This operation creates a variable object, which allows the monitoring of
32244 a variable, the result of an expression, a memory cell or a CPU
32245 register.
32246
32247 The @var{name} parameter is the string by which the object can be
32248 referenced. It must be unique. If @samp{-} is specified, the varobj
32249 system will generate a string ``varNNNNNN'' automatically. It will be
32250 unique provided that one does not specify @var{name} of that format.
32251 The command fails if a duplicate name is found.
32252
32253 The frame under which the expression should be evaluated can be
32254 specified by @var{frame-addr}. A @samp{*} indicates that the current
32255 frame should be used. A @samp{@@} indicates that a floating variable
32256 object must be created.
32257
32258 @var{expression} is any expression valid on the current language set (must not
32259 begin with a @samp{*}), or one of the following:
32260
32261 @itemize @bullet
32262 @item
32263 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
32264
32265 @item
32266 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
32267
32268 @item
32269 @samp{$@var{regname}} --- a CPU register name
32270 @end itemize
32271
32272 @cindex dynamic varobj
32273 A varobj's contents may be provided by a Python-based pretty-printer. In this
32274 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32275 have slightly different semantics in some cases. If the
32276 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32277 will never create a dynamic varobj. This ensures backward
32278 compatibility for existing clients.
32279
32280 @subsubheading Result
32281
32282 This operation returns attributes of the newly-created varobj. These
32283 are:
32284
32285 @table @samp
32286 @item name
32287 The name of the varobj.
32288
32289 @item numchild
32290 The number of children of the varobj. This number is not necessarily
32291 reliable for a dynamic varobj. Instead, you must examine the
32292 @samp{has_more} attribute.
32293
32294 @item value
32295 The varobj's scalar value. For a varobj whose type is some sort of
32296 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32297 will not be interesting.
32298
32299 @item type
32300 The varobj's type. This is a string representation of the type, as
32301 would be printed by the @value{GDBN} CLI. If @samp{print object}
32302 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32303 @emph{actual} (derived) type of the object is shown rather than the
32304 @emph{declared} one.
32305
32306 @item thread-id
32307 If a variable object is bound to a specific thread, then this is the
32308 thread's global identifier.
32309
32310 @item has_more
32311 For a dynamic varobj, this indicates whether there appear to be any
32312 children available. For a non-dynamic varobj, this will be 0.
32313
32314 @item dynamic
32315 This attribute will be present and have the value @samp{1} if the
32316 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32317 then this attribute will not be present.
32318
32319 @item displayhint
32320 A dynamic varobj can supply a display hint to the front end. The
32321 value comes directly from the Python pretty-printer object's
32322 @code{display_hint} method. @xref{Pretty Printing API}.
32323 @end table
32324
32325 Typical output will look like this:
32326
32327 @smallexample
32328 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32329 has_more="@var{has_more}"
32330 @end smallexample
32331
32332
32333 @subheading The @code{-var-delete} Command
32334 @findex -var-delete
32335
32336 @subsubheading Synopsis
32337
32338 @smallexample
32339 -var-delete [ -c ] @var{name}
32340 @end smallexample
32341
32342 Deletes a previously created variable object and all of its children.
32343 With the @samp{-c} option, just deletes the children.
32344
32345 Returns an error if the object @var{name} is not found.
32346
32347
32348 @subheading The @code{-var-set-format} Command
32349 @findex -var-set-format
32350
32351 @subsubheading Synopsis
32352
32353 @smallexample
32354 -var-set-format @var{name} @var{format-spec}
32355 @end smallexample
32356
32357 Sets the output format for the value of the object @var{name} to be
32358 @var{format-spec}.
32359
32360 @anchor{-var-set-format}
32361 The syntax for the @var{format-spec} is as follows:
32362
32363 @smallexample
32364 @var{format-spec} @expansion{}
32365 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
32366 @end smallexample
32367
32368 The natural format is the default format choosen automatically
32369 based on the variable type (like decimal for an @code{int}, hex
32370 for pointers, etc.).
32371
32372 The zero-hexadecimal format has a representation similar to hexadecimal
32373 but with padding zeroes to the left of the value. For example, a 32-bit
32374 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32375 zero-hexadecimal format.
32376
32377 For a variable with children, the format is set only on the
32378 variable itself, and the children are not affected.
32379
32380 @subheading The @code{-var-show-format} Command
32381 @findex -var-show-format
32382
32383 @subsubheading Synopsis
32384
32385 @smallexample
32386 -var-show-format @var{name}
32387 @end smallexample
32388
32389 Returns the format used to display the value of the object @var{name}.
32390
32391 @smallexample
32392 @var{format} @expansion{}
32393 @var{format-spec}
32394 @end smallexample
32395
32396
32397 @subheading The @code{-var-info-num-children} Command
32398 @findex -var-info-num-children
32399
32400 @subsubheading Synopsis
32401
32402 @smallexample
32403 -var-info-num-children @var{name}
32404 @end smallexample
32405
32406 Returns the number of children of a variable object @var{name}:
32407
32408 @smallexample
32409 numchild=@var{n}
32410 @end smallexample
32411
32412 Note that this number is not completely reliable for a dynamic varobj.
32413 It will return the current number of children, but more children may
32414 be available.
32415
32416
32417 @subheading The @code{-var-list-children} Command
32418 @findex -var-list-children
32419
32420 @subsubheading Synopsis
32421
32422 @smallexample
32423 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32424 @end smallexample
32425 @anchor{-var-list-children}
32426
32427 Return a list of the children of the specified variable object and
32428 create variable objects for them, if they do not already exist. With
32429 a single argument or if @var{print-values} has a value of 0 or
32430 @code{--no-values}, print only the names of the variables; if
32431 @var{print-values} is 1 or @code{--all-values}, also print their
32432 values; and if it is 2 or @code{--simple-values} print the name and
32433 value for simple data types and just the name for arrays, structures
32434 and unions.
32435
32436 @var{from} and @var{to}, if specified, indicate the range of children
32437 to report. If @var{from} or @var{to} is less than zero, the range is
32438 reset and all children will be reported. Otherwise, children starting
32439 at @var{from} (zero-based) and up to and excluding @var{to} will be
32440 reported.
32441
32442 If a child range is requested, it will only affect the current call to
32443 @code{-var-list-children}, but not future calls to @code{-var-update}.
32444 For this, you must instead use @code{-var-set-update-range}. The
32445 intent of this approach is to enable a front end to implement any
32446 update approach it likes; for example, scrolling a view may cause the
32447 front end to request more children with @code{-var-list-children}, and
32448 then the front end could call @code{-var-set-update-range} with a
32449 different range to ensure that future updates are restricted to just
32450 the visible items.
32451
32452 For each child the following results are returned:
32453
32454 @table @var
32455
32456 @item name
32457 Name of the variable object created for this child.
32458
32459 @item exp
32460 The expression to be shown to the user by the front end to designate this child.
32461 For example this may be the name of a structure member.
32462
32463 For a dynamic varobj, this value cannot be used to form an
32464 expression. There is no way to do this at all with a dynamic varobj.
32465
32466 For C/C@t{++} structures there are several pseudo children returned to
32467 designate access qualifiers. For these pseudo children @var{exp} is
32468 @samp{public}, @samp{private}, or @samp{protected}. In this case the
32469 type and value are not present.
32470
32471 A dynamic varobj will not report the access qualifying
32472 pseudo-children, regardless of the language. This information is not
32473 available at all with a dynamic varobj.
32474
32475 @item numchild
32476 Number of children this child has. For a dynamic varobj, this will be
32477 0.
32478
32479 @item type
32480 The type of the child. If @samp{print object}
32481 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32482 @emph{actual} (derived) type of the object is shown rather than the
32483 @emph{declared} one.
32484
32485 @item value
32486 If values were requested, this is the value.
32487
32488 @item thread-id
32489 If this variable object is associated with a thread, this is the
32490 thread's global thread id. Otherwise this result is not present.
32491
32492 @item frozen
32493 If the variable object is frozen, this variable will be present with a value of 1.
32494
32495 @item displayhint
32496 A dynamic varobj can supply a display hint to the front end. The
32497 value comes directly from the Python pretty-printer object's
32498 @code{display_hint} method. @xref{Pretty Printing API}.
32499
32500 @item dynamic
32501 This attribute will be present and have the value @samp{1} if the
32502 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32503 then this attribute will not be present.
32504
32505 @end table
32506
32507 The result may have its own attributes:
32508
32509 @table @samp
32510 @item displayhint
32511 A dynamic varobj can supply a display hint to the front end. The
32512 value comes directly from the Python pretty-printer object's
32513 @code{display_hint} method. @xref{Pretty Printing API}.
32514
32515 @item has_more
32516 This is an integer attribute which is nonzero if there are children
32517 remaining after the end of the selected range.
32518 @end table
32519
32520 @subsubheading Example
32521
32522 @smallexample
32523 (gdb)
32524 -var-list-children n
32525 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32526 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
32527 (gdb)
32528 -var-list-children --all-values n
32529 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32530 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
32531 @end smallexample
32532
32533
32534 @subheading The @code{-var-info-type} Command
32535 @findex -var-info-type
32536
32537 @subsubheading Synopsis
32538
32539 @smallexample
32540 -var-info-type @var{name}
32541 @end smallexample
32542
32543 Returns the type of the specified variable @var{name}. The type is
32544 returned as a string in the same format as it is output by the
32545 @value{GDBN} CLI:
32546
32547 @smallexample
32548 type=@var{typename}
32549 @end smallexample
32550
32551
32552 @subheading The @code{-var-info-expression} Command
32553 @findex -var-info-expression
32554
32555 @subsubheading Synopsis
32556
32557 @smallexample
32558 -var-info-expression @var{name}
32559 @end smallexample
32560
32561 Returns a string that is suitable for presenting this
32562 variable object in user interface. The string is generally
32563 not valid expression in the current language, and cannot be evaluated.
32564
32565 For example, if @code{a} is an array, and variable object
32566 @code{A} was created for @code{a}, then we'll get this output:
32567
32568 @smallexample
32569 (gdb) -var-info-expression A.1
32570 ^done,lang="C",exp="1"
32571 @end smallexample
32572
32573 @noindent
32574 Here, the value of @code{lang} is the language name, which can be
32575 found in @ref{Supported Languages}.
32576
32577 Note that the output of the @code{-var-list-children} command also
32578 includes those expressions, so the @code{-var-info-expression} command
32579 is of limited use.
32580
32581 @subheading The @code{-var-info-path-expression} Command
32582 @findex -var-info-path-expression
32583
32584 @subsubheading Synopsis
32585
32586 @smallexample
32587 -var-info-path-expression @var{name}
32588 @end smallexample
32589
32590 Returns an expression that can be evaluated in the current
32591 context and will yield the same value that a variable object has.
32592 Compare this with the @code{-var-info-expression} command, which
32593 result can be used only for UI presentation. Typical use of
32594 the @code{-var-info-path-expression} command is creating a
32595 watchpoint from a variable object.
32596
32597 This command is currently not valid for children of a dynamic varobj,
32598 and will give an error when invoked on one.
32599
32600 For example, suppose @code{C} is a C@t{++} class, derived from class
32601 @code{Base}, and that the @code{Base} class has a member called
32602 @code{m_size}. Assume a variable @code{c} is has the type of
32603 @code{C} and a variable object @code{C} was created for variable
32604 @code{c}. Then, we'll get this output:
32605 @smallexample
32606 (gdb) -var-info-path-expression C.Base.public.m_size
32607 ^done,path_expr=((Base)c).m_size)
32608 @end smallexample
32609
32610 @subheading The @code{-var-show-attributes} Command
32611 @findex -var-show-attributes
32612
32613 @subsubheading Synopsis
32614
32615 @smallexample
32616 -var-show-attributes @var{name}
32617 @end smallexample
32618
32619 List attributes of the specified variable object @var{name}:
32620
32621 @smallexample
32622 status=@var{attr} [ ( ,@var{attr} )* ]
32623 @end smallexample
32624
32625 @noindent
32626 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32627
32628 @subheading The @code{-var-evaluate-expression} Command
32629 @findex -var-evaluate-expression
32630
32631 @subsubheading Synopsis
32632
32633 @smallexample
32634 -var-evaluate-expression [-f @var{format-spec}] @var{name}
32635 @end smallexample
32636
32637 Evaluates the expression that is represented by the specified variable
32638 object and returns its value as a string. The format of the string
32639 can be specified with the @samp{-f} option. The possible values of
32640 this option are the same as for @code{-var-set-format}
32641 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32642 the current display format will be used. The current display format
32643 can be changed using the @code{-var-set-format} command.
32644
32645 @smallexample
32646 value=@var{value}
32647 @end smallexample
32648
32649 Note that one must invoke @code{-var-list-children} for a variable
32650 before the value of a child variable can be evaluated.
32651
32652 @subheading The @code{-var-assign} Command
32653 @findex -var-assign
32654
32655 @subsubheading Synopsis
32656
32657 @smallexample
32658 -var-assign @var{name} @var{expression}
32659 @end smallexample
32660
32661 Assigns the value of @var{expression} to the variable object specified
32662 by @var{name}. The object must be @samp{editable}. If the variable's
32663 value is altered by the assign, the variable will show up in any
32664 subsequent @code{-var-update} list.
32665
32666 @subsubheading Example
32667
32668 @smallexample
32669 (gdb)
32670 -var-assign var1 3
32671 ^done,value="3"
32672 (gdb)
32673 -var-update *
32674 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
32675 (gdb)
32676 @end smallexample
32677
32678 @subheading The @code{-var-update} Command
32679 @findex -var-update
32680
32681 @subsubheading Synopsis
32682
32683 @smallexample
32684 -var-update [@var{print-values}] @{@var{name} | "*"@}
32685 @end smallexample
32686
32687 Reevaluate the expressions corresponding to the variable object
32688 @var{name} and all its direct and indirect children, and return the
32689 list of variable objects whose values have changed; @var{name} must
32690 be a root variable object. Here, ``changed'' means that the result of
32691 @code{-var-evaluate-expression} before and after the
32692 @code{-var-update} is different. If @samp{*} is used as the variable
32693 object names, all existing variable objects are updated, except
32694 for frozen ones (@pxref{-var-set-frozen}). The option
32695 @var{print-values} determines whether both names and values, or just
32696 names are printed. The possible values of this option are the same
32697 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32698 recommended to use the @samp{--all-values} option, to reduce the
32699 number of MI commands needed on each program stop.
32700
32701 With the @samp{*} parameter, if a variable object is bound to a
32702 currently running thread, it will not be updated, without any
32703 diagnostic.
32704
32705 If @code{-var-set-update-range} was previously used on a varobj, then
32706 only the selected range of children will be reported.
32707
32708 @code{-var-update} reports all the changed varobjs in a tuple named
32709 @samp{changelist}.
32710
32711 Each item in the change list is itself a tuple holding:
32712
32713 @table @samp
32714 @item name
32715 The name of the varobj.
32716
32717 @item value
32718 If values were requested for this update, then this field will be
32719 present and will hold the value of the varobj.
32720
32721 @item in_scope
32722 @anchor{-var-update}
32723 This field is a string which may take one of three values:
32724
32725 @table @code
32726 @item "true"
32727 The variable object's current value is valid.
32728
32729 @item "false"
32730 The variable object does not currently hold a valid value but it may
32731 hold one in the future if its associated expression comes back into
32732 scope.
32733
32734 @item "invalid"
32735 The variable object no longer holds a valid value.
32736 This can occur when the executable file being debugged has changed,
32737 either through recompilation or by using the @value{GDBN} @code{file}
32738 command. The front end should normally choose to delete these variable
32739 objects.
32740 @end table
32741
32742 In the future new values may be added to this list so the front should
32743 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32744
32745 @item type_changed
32746 This is only present if the varobj is still valid. If the type
32747 changed, then this will be the string @samp{true}; otherwise it will
32748 be @samp{false}.
32749
32750 When a varobj's type changes, its children are also likely to have
32751 become incorrect. Therefore, the varobj's children are automatically
32752 deleted when this attribute is @samp{true}. Also, the varobj's update
32753 range, when set using the @code{-var-set-update-range} command, is
32754 unset.
32755
32756 @item new_type
32757 If the varobj's type changed, then this field will be present and will
32758 hold the new type.
32759
32760 @item new_num_children
32761 For a dynamic varobj, if the number of children changed, or if the
32762 type changed, this will be the new number of children.
32763
32764 The @samp{numchild} field in other varobj responses is generally not
32765 valid for a dynamic varobj -- it will show the number of children that
32766 @value{GDBN} knows about, but because dynamic varobjs lazily
32767 instantiate their children, this will not reflect the number of
32768 children which may be available.
32769
32770 The @samp{new_num_children} attribute only reports changes to the
32771 number of children known by @value{GDBN}. This is the only way to
32772 detect whether an update has removed children (which necessarily can
32773 only happen at the end of the update range).
32774
32775 @item displayhint
32776 The display hint, if any.
32777
32778 @item has_more
32779 This is an integer value, which will be 1 if there are more children
32780 available outside the varobj's update range.
32781
32782 @item dynamic
32783 This attribute will be present and have the value @samp{1} if the
32784 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32785 then this attribute will not be present.
32786
32787 @item new_children
32788 If new children were added to a dynamic varobj within the selected
32789 update range (as set by @code{-var-set-update-range}), then they will
32790 be listed in this attribute.
32791 @end table
32792
32793 @subsubheading Example
32794
32795 @smallexample
32796 (gdb)
32797 -var-assign var1 3
32798 ^done,value="3"
32799 (gdb)
32800 -var-update --all-values var1
32801 ^done,changelist=[@{name="var1",value="3",in_scope="true",
32802 type_changed="false"@}]
32803 (gdb)
32804 @end smallexample
32805
32806 @subheading The @code{-var-set-frozen} Command
32807 @findex -var-set-frozen
32808 @anchor{-var-set-frozen}
32809
32810 @subsubheading Synopsis
32811
32812 @smallexample
32813 -var-set-frozen @var{name} @var{flag}
32814 @end smallexample
32815
32816 Set the frozenness flag on the variable object @var{name}. The
32817 @var{flag} parameter should be either @samp{1} to make the variable
32818 frozen or @samp{0} to make it unfrozen. If a variable object is
32819 frozen, then neither itself, nor any of its children, are
32820 implicitly updated by @code{-var-update} of
32821 a parent variable or by @code{-var-update *}. Only
32822 @code{-var-update} of the variable itself will update its value and
32823 values of its children. After a variable object is unfrozen, it is
32824 implicitly updated by all subsequent @code{-var-update} operations.
32825 Unfreezing a variable does not update it, only subsequent
32826 @code{-var-update} does.
32827
32828 @subsubheading Example
32829
32830 @smallexample
32831 (gdb)
32832 -var-set-frozen V 1
32833 ^done
32834 (gdb)
32835 @end smallexample
32836
32837 @subheading The @code{-var-set-update-range} command
32838 @findex -var-set-update-range
32839 @anchor{-var-set-update-range}
32840
32841 @subsubheading Synopsis
32842
32843 @smallexample
32844 -var-set-update-range @var{name} @var{from} @var{to}
32845 @end smallexample
32846
32847 Set the range of children to be returned by future invocations of
32848 @code{-var-update}.
32849
32850 @var{from} and @var{to} indicate the range of children to report. If
32851 @var{from} or @var{to} is less than zero, the range is reset and all
32852 children will be reported. Otherwise, children starting at @var{from}
32853 (zero-based) and up to and excluding @var{to} will be reported.
32854
32855 @subsubheading Example
32856
32857 @smallexample
32858 (gdb)
32859 -var-set-update-range V 1 2
32860 ^done
32861 @end smallexample
32862
32863 @subheading The @code{-var-set-visualizer} command
32864 @findex -var-set-visualizer
32865 @anchor{-var-set-visualizer}
32866
32867 @subsubheading Synopsis
32868
32869 @smallexample
32870 -var-set-visualizer @var{name} @var{visualizer}
32871 @end smallexample
32872
32873 Set a visualizer for the variable object @var{name}.
32874
32875 @var{visualizer} is the visualizer to use. The special value
32876 @samp{None} means to disable any visualizer in use.
32877
32878 If not @samp{None}, @var{visualizer} must be a Python expression.
32879 This expression must evaluate to a callable object which accepts a
32880 single argument. @value{GDBN} will call this object with the value of
32881 the varobj @var{name} as an argument (this is done so that the same
32882 Python pretty-printing code can be used for both the CLI and MI).
32883 When called, this object must return an object which conforms to the
32884 pretty-printing interface (@pxref{Pretty Printing API}).
32885
32886 The pre-defined function @code{gdb.default_visualizer} may be used to
32887 select a visualizer by following the built-in process
32888 (@pxref{Selecting Pretty-Printers}). This is done automatically when
32889 a varobj is created, and so ordinarily is not needed.
32890
32891 This feature is only available if Python support is enabled. The MI
32892 command @code{-list-features} (@pxref{GDB/MI Support Commands})
32893 can be used to check this.
32894
32895 @subsubheading Example
32896
32897 Resetting the visualizer:
32898
32899 @smallexample
32900 (gdb)
32901 -var-set-visualizer V None
32902 ^done
32903 @end smallexample
32904
32905 Reselecting the default (type-based) visualizer:
32906
32907 @smallexample
32908 (gdb)
32909 -var-set-visualizer V gdb.default_visualizer
32910 ^done
32911 @end smallexample
32912
32913 Suppose @code{SomeClass} is a visualizer class. A lambda expression
32914 can be used to instantiate this class for a varobj:
32915
32916 @smallexample
32917 (gdb)
32918 -var-set-visualizer V "lambda val: SomeClass()"
32919 ^done
32920 @end smallexample
32921
32922 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32923 @node GDB/MI Data Manipulation
32924 @section @sc{gdb/mi} Data Manipulation
32925
32926 @cindex data manipulation, in @sc{gdb/mi}
32927 @cindex @sc{gdb/mi}, data manipulation
32928 This section describes the @sc{gdb/mi} commands that manipulate data:
32929 examine memory and registers, evaluate expressions, etc.
32930
32931 For details about what an addressable memory unit is,
32932 @pxref{addressable memory unit}.
32933
32934 @c REMOVED FROM THE INTERFACE.
32935 @c @subheading -data-assign
32936 @c Change the value of a program variable. Plenty of side effects.
32937 @c @subsubheading GDB Command
32938 @c set variable
32939 @c @subsubheading Example
32940 @c N.A.
32941
32942 @subheading The @code{-data-disassemble} Command
32943 @findex -data-disassemble
32944
32945 @subsubheading Synopsis
32946
32947 @smallexample
32948 -data-disassemble
32949 [ -s @var{start-addr} -e @var{end-addr} ]
32950 | [ -a @var{addr} ]
32951 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
32952 -- @var{mode}
32953 @end smallexample
32954
32955 @noindent
32956 Where:
32957
32958 @table @samp
32959 @item @var{start-addr}
32960 is the beginning address (or @code{$pc})
32961 @item @var{end-addr}
32962 is the end address
32963 @item @var{addr}
32964 is an address anywhere within (or the name of) the function to
32965 disassemble. If an address is specified, the whole function
32966 surrounding that address will be disassembled. If a name is
32967 specified, the whole function with that name will be disassembled.
32968 @item @var{filename}
32969 is the name of the file to disassemble
32970 @item @var{linenum}
32971 is the line number to disassemble around
32972 @item @var{lines}
32973 is the number of disassembly lines to be produced. If it is -1,
32974 the whole function will be disassembled, in case no @var{end-addr} is
32975 specified. If @var{end-addr} is specified as a non-zero value, and
32976 @var{lines} is lower than the number of disassembly lines between
32977 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
32978 displayed; if @var{lines} is higher than the number of lines between
32979 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
32980 are displayed.
32981 @item @var{mode}
32982 is one of:
32983 @itemize @bullet
32984 @item 0 disassembly only
32985 @item 1 mixed source and disassembly (deprecated)
32986 @item 2 disassembly with raw opcodes
32987 @item 3 mixed source and disassembly with raw opcodes (deprecated)
32988 @item 4 mixed source and disassembly
32989 @item 5 mixed source and disassembly with raw opcodes
32990 @end itemize
32991
32992 Modes 1 and 3 are deprecated. The output is ``source centric''
32993 which hasn't proved useful in practice.
32994 @xref{Machine Code}, for a discussion of the difference between
32995 @code{/m} and @code{/s} output of the @code{disassemble} command.
32996 @end table
32997
32998 @subsubheading Result
32999
33000 The result of the @code{-data-disassemble} command will be a list named
33001 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33002 used with the @code{-data-disassemble} command.
33003
33004 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33005 following fields:
33006
33007 @table @code
33008 @item address
33009 The address at which this instruction was disassembled.
33010
33011 @item func-name
33012 The name of the function this instruction is within.
33013
33014 @item offset
33015 The decimal offset in bytes from the start of @samp{func-name}.
33016
33017 @item inst
33018 The text disassembly for this @samp{address}.
33019
33020 @item opcodes
33021 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33022 bytes for the @samp{inst} field.
33023
33024 @end table
33025
33026 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33027 @samp{src_and_asm_line}, each of which has the following fields:
33028
33029 @table @code
33030 @item line
33031 The line number within @samp{file}.
33032
33033 @item file
33034 The file name from the compilation unit. This might be an absolute
33035 file name or a relative file name depending on the compile command
33036 used.
33037
33038 @item fullname
33039 Absolute file name of @samp{file}. It is converted to a canonical form
33040 using the source file search path
33041 (@pxref{Source Path, ,Specifying Source Directories})
33042 and after resolving all the symbolic links.
33043
33044 If the source file is not found this field will contain the path as
33045 present in the debug information.
33046
33047 @item line_asm_insn
33048 This is a list of tuples containing the disassembly for @samp{line} in
33049 @samp{file}. The fields of each tuple are the same as for
33050 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33051 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33052 @samp{opcodes}.
33053
33054 @end table
33055
33056 Note that whatever included in the @samp{inst} field, is not
33057 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33058 adjust its format.
33059
33060 @subsubheading @value{GDBN} Command
33061
33062 The corresponding @value{GDBN} command is @samp{disassemble}.
33063
33064 @subsubheading Example
33065
33066 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33067
33068 @smallexample
33069 (gdb)
33070 -data-disassemble -s $pc -e "$pc + 20" -- 0
33071 ^done,
33072 asm_insns=[
33073 @{address="0x000107c0",func-name="main",offset="4",
33074 inst="mov 2, %o0"@},
33075 @{address="0x000107c4",func-name="main",offset="8",
33076 inst="sethi %hi(0x11800), %o2"@},
33077 @{address="0x000107c8",func-name="main",offset="12",
33078 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33079 @{address="0x000107cc",func-name="main",offset="16",
33080 inst="sethi %hi(0x11800), %o2"@},
33081 @{address="0x000107d0",func-name="main",offset="20",
33082 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33083 (gdb)
33084 @end smallexample
33085
33086 Disassemble the whole @code{main} function. Line 32 is part of
33087 @code{main}.
33088
33089 @smallexample
33090 -data-disassemble -f basics.c -l 32 -- 0
33091 ^done,asm_insns=[
33092 @{address="0x000107bc",func-name="main",offset="0",
33093 inst="save %sp, -112, %sp"@},
33094 @{address="0x000107c0",func-name="main",offset="4",
33095 inst="mov 2, %o0"@},
33096 @{address="0x000107c4",func-name="main",offset="8",
33097 inst="sethi %hi(0x11800), %o2"@},
33098 [@dots{}]
33099 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33100 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33101 (gdb)
33102 @end smallexample
33103
33104 Disassemble 3 instructions from the start of @code{main}:
33105
33106 @smallexample
33107 (gdb)
33108 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33109 ^done,asm_insns=[
33110 @{address="0x000107bc",func-name="main",offset="0",
33111 inst="save %sp, -112, %sp"@},
33112 @{address="0x000107c0",func-name="main",offset="4",
33113 inst="mov 2, %o0"@},
33114 @{address="0x000107c4",func-name="main",offset="8",
33115 inst="sethi %hi(0x11800), %o2"@}]
33116 (gdb)
33117 @end smallexample
33118
33119 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33120
33121 @smallexample
33122 (gdb)
33123 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33124 ^done,asm_insns=[
33125 src_and_asm_line=@{line="31",
33126 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33127 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33128 line_asm_insn=[@{address="0x000107bc",
33129 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33130 src_and_asm_line=@{line="32",
33131 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33132 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33133 line_asm_insn=[@{address="0x000107c0",
33134 func-name="main",offset="4",inst="mov 2, %o0"@},
33135 @{address="0x000107c4",func-name="main",offset="8",
33136 inst="sethi %hi(0x11800), %o2"@}]@}]
33137 (gdb)
33138 @end smallexample
33139
33140
33141 @subheading The @code{-data-evaluate-expression} Command
33142 @findex -data-evaluate-expression
33143
33144 @subsubheading Synopsis
33145
33146 @smallexample
33147 -data-evaluate-expression @var{expr}
33148 @end smallexample
33149
33150 Evaluate @var{expr} as an expression. The expression could contain an
33151 inferior function call. The function call will execute synchronously.
33152 If the expression contains spaces, it must be enclosed in double quotes.
33153
33154 @subsubheading @value{GDBN} Command
33155
33156 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33157 @samp{call}. In @code{gdbtk} only, there's a corresponding
33158 @samp{gdb_eval} command.
33159
33160 @subsubheading Example
33161
33162 In the following example, the numbers that precede the commands are the
33163 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33164 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33165 output.
33166
33167 @smallexample
33168 211-data-evaluate-expression A
33169 211^done,value="1"
33170 (gdb)
33171 311-data-evaluate-expression &A
33172 311^done,value="0xefffeb7c"
33173 (gdb)
33174 411-data-evaluate-expression A+3
33175 411^done,value="4"
33176 (gdb)
33177 511-data-evaluate-expression "A + 3"
33178 511^done,value="4"
33179 (gdb)
33180 @end smallexample
33181
33182
33183 @subheading The @code{-data-list-changed-registers} Command
33184 @findex -data-list-changed-registers
33185
33186 @subsubheading Synopsis
33187
33188 @smallexample
33189 -data-list-changed-registers
33190 @end smallexample
33191
33192 Display a list of the registers that have changed.
33193
33194 @subsubheading @value{GDBN} Command
33195
33196 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33197 has the corresponding command @samp{gdb_changed_register_list}.
33198
33199 @subsubheading Example
33200
33201 On a PPC MBX board:
33202
33203 @smallexample
33204 (gdb)
33205 -exec-continue
33206 ^running
33207
33208 (gdb)
33209 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33210 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33211 line="5",arch="powerpc"@}
33212 (gdb)
33213 -data-list-changed-registers
33214 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33215 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33216 "24","25","26","27","28","30","31","64","65","66","67","69"]
33217 (gdb)
33218 @end smallexample
33219
33220
33221 @subheading The @code{-data-list-register-names} Command
33222 @findex -data-list-register-names
33223
33224 @subsubheading Synopsis
33225
33226 @smallexample
33227 -data-list-register-names [ ( @var{regno} )+ ]
33228 @end smallexample
33229
33230 Show a list of register names for the current target. If no arguments
33231 are given, it shows a list of the names of all the registers. If
33232 integer numbers are given as arguments, it will print a list of the
33233 names of the registers corresponding to the arguments. To ensure
33234 consistency between a register name and its number, the output list may
33235 include empty register names.
33236
33237 @subsubheading @value{GDBN} Command
33238
33239 @value{GDBN} does not have a command which corresponds to
33240 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33241 corresponding command @samp{gdb_regnames}.
33242
33243 @subsubheading Example
33244
33245 For the PPC MBX board:
33246 @smallexample
33247 (gdb)
33248 -data-list-register-names
33249 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33250 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33251 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33252 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33253 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33254 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33255 "", "pc","ps","cr","lr","ctr","xer"]
33256 (gdb)
33257 -data-list-register-names 1 2 3
33258 ^done,register-names=["r1","r2","r3"]
33259 (gdb)
33260 @end smallexample
33261
33262 @subheading The @code{-data-list-register-values} Command
33263 @findex -data-list-register-values
33264
33265 @subsubheading Synopsis
33266
33267 @smallexample
33268 -data-list-register-values
33269 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
33270 @end smallexample
33271
33272 Display the registers' contents. The format according to which the
33273 registers' contents are to be returned is given by @var{fmt}, followed
33274 by an optional list of numbers specifying the registers to display. A
33275 missing list of numbers indicates that the contents of all the
33276 registers must be returned. The @code{--skip-unavailable} option
33277 indicates that only the available registers are to be returned.
33278
33279 Allowed formats for @var{fmt} are:
33280
33281 @table @code
33282 @item x
33283 Hexadecimal
33284 @item o
33285 Octal
33286 @item t
33287 Binary
33288 @item d
33289 Decimal
33290 @item r
33291 Raw
33292 @item N
33293 Natural
33294 @end table
33295
33296 @subsubheading @value{GDBN} Command
33297
33298 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33299 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
33300
33301 @subsubheading Example
33302
33303 For a PPC MBX board (note: line breaks are for readability only, they
33304 don't appear in the actual output):
33305
33306 @smallexample
33307 (gdb)
33308 -data-list-register-values r 64 65
33309 ^done,register-values=[@{number="64",value="0xfe00a300"@},
33310 @{number="65",value="0x00029002"@}]
33311 (gdb)
33312 -data-list-register-values x
33313 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
33314 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33315 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
33316 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33317 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33318 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33319 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
33320 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33321 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33322 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33323 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33324 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33325 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33326 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33327 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33328 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33329 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
33330 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
33331 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
33332 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
33333 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
33334 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
33335 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
33336 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
33337 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
33338 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
33339 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
33340 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
33341 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
33342 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
33343 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
33344 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
33345 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33346 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33347 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33348 @{number="69",value="0x20002b03"@}]
33349 (gdb)
33350 @end smallexample
33351
33352
33353 @subheading The @code{-data-read-memory} Command
33354 @findex -data-read-memory
33355
33356 This command is deprecated, use @code{-data-read-memory-bytes} instead.
33357
33358 @subsubheading Synopsis
33359
33360 @smallexample
33361 -data-read-memory [ -o @var{byte-offset} ]
33362 @var{address} @var{word-format} @var{word-size}
33363 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
33364 @end smallexample
33365
33366 @noindent
33367 where:
33368
33369 @table @samp
33370 @item @var{address}
33371 An expression specifying the address of the first memory word to be
33372 read. Complex expressions containing embedded white space should be
33373 quoted using the C convention.
33374
33375 @item @var{word-format}
33376 The format to be used to print the memory words. The notation is the
33377 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
33378 ,Output Formats}).
33379
33380 @item @var{word-size}
33381 The size of each memory word in bytes.
33382
33383 @item @var{nr-rows}
33384 The number of rows in the output table.
33385
33386 @item @var{nr-cols}
33387 The number of columns in the output table.
33388
33389 @item @var{aschar}
33390 If present, indicates that each row should include an @sc{ascii} dump. The
33391 value of @var{aschar} is used as a padding character when a byte is not a
33392 member of the printable @sc{ascii} character set (printable @sc{ascii}
33393 characters are those whose code is between 32 and 126, inclusively).
33394
33395 @item @var{byte-offset}
33396 An offset to add to the @var{address} before fetching memory.
33397 @end table
33398
33399 This command displays memory contents as a table of @var{nr-rows} by
33400 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
33401 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33402 (returned as @samp{total-bytes}). Should less than the requested number
33403 of bytes be returned by the target, the missing words are identified
33404 using @samp{N/A}. The number of bytes read from the target is returned
33405 in @samp{nr-bytes} and the starting address used to read memory in
33406 @samp{addr}.
33407
33408 The address of the next/previous row or page is available in
33409 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
33410 @samp{prev-page}.
33411
33412 @subsubheading @value{GDBN} Command
33413
33414 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33415 @samp{gdb_get_mem} memory read command.
33416
33417 @subsubheading Example
33418
33419 Read six bytes of memory starting at @code{bytes+6} but then offset by
33420 @code{-6} bytes. Format as three rows of two columns. One byte per
33421 word. Display each word in hex.
33422
33423 @smallexample
33424 (gdb)
33425 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
33426 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33427 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33428 prev-page="0x0000138a",memory=[
33429 @{addr="0x00001390",data=["0x00","0x01"]@},
33430 @{addr="0x00001392",data=["0x02","0x03"]@},
33431 @{addr="0x00001394",data=["0x04","0x05"]@}]
33432 (gdb)
33433 @end smallexample
33434
33435 Read two bytes of memory starting at address @code{shorts + 64} and
33436 display as a single word formatted in decimal.
33437
33438 @smallexample
33439 (gdb)
33440 5-data-read-memory shorts+64 d 2 1 1
33441 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33442 next-row="0x00001512",prev-row="0x0000150e",
33443 next-page="0x00001512",prev-page="0x0000150e",memory=[
33444 @{addr="0x00001510",data=["128"]@}]
33445 (gdb)
33446 @end smallexample
33447
33448 Read thirty two bytes of memory starting at @code{bytes+16} and format
33449 as eight rows of four columns. Include a string encoding with @samp{x}
33450 used as the non-printable character.
33451
33452 @smallexample
33453 (gdb)
33454 4-data-read-memory bytes+16 x 1 8 4 x
33455 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33456 next-row="0x000013c0",prev-row="0x0000139c",
33457 next-page="0x000013c0",prev-page="0x00001380",memory=[
33458 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33459 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33460 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33461 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33462 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33463 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33464 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33465 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33466 (gdb)
33467 @end smallexample
33468
33469 @subheading The @code{-data-read-memory-bytes} Command
33470 @findex -data-read-memory-bytes
33471
33472 @subsubheading Synopsis
33473
33474 @smallexample
33475 -data-read-memory-bytes [ -o @var{offset} ]
33476 @var{address} @var{count}
33477 @end smallexample
33478
33479 @noindent
33480 where:
33481
33482 @table @samp
33483 @item @var{address}
33484 An expression specifying the address of the first addressable memory unit
33485 to be read. Complex expressions containing embedded white space should be
33486 quoted using the C convention.
33487
33488 @item @var{count}
33489 The number of addressable memory units to read. This should be an integer
33490 literal.
33491
33492 @item @var{offset}
33493 The offset relative to @var{address} at which to start reading. This
33494 should be an integer literal. This option is provided so that a frontend
33495 is not required to first evaluate address and then perform address
33496 arithmetics itself.
33497
33498 @end table
33499
33500 This command attempts to read all accessible memory regions in the
33501 specified range. First, all regions marked as unreadable in the memory
33502 map (if one is defined) will be skipped. @xref{Memory Region
33503 Attributes}. Second, @value{GDBN} will attempt to read the remaining
33504 regions. For each one, if reading full region results in an errors,
33505 @value{GDBN} will try to read a subset of the region.
33506
33507 In general, every single memory unit in the region may be readable or not,
33508 and the only way to read every readable unit is to try a read at
33509 every address, which is not practical. Therefore, @value{GDBN} will
33510 attempt to read all accessible memory units at either beginning or the end
33511 of the region, using a binary division scheme. This heuristic works
33512 well for reading across a memory map boundary. Note that if a region
33513 has a readable range that is neither at the beginning or the end,
33514 @value{GDBN} will not read it.
33515
33516 The result record (@pxref{GDB/MI Result Records}) that is output of
33517 the command includes a field named @samp{memory} whose content is a
33518 list of tuples. Each tuple represent a successfully read memory block
33519 and has the following fields:
33520
33521 @table @code
33522 @item begin
33523 The start address of the memory block, as hexadecimal literal.
33524
33525 @item end
33526 The end address of the memory block, as hexadecimal literal.
33527
33528 @item offset
33529 The offset of the memory block, as hexadecimal literal, relative to
33530 the start address passed to @code{-data-read-memory-bytes}.
33531
33532 @item contents
33533 The contents of the memory block, in hex.
33534
33535 @end table
33536
33537
33538
33539 @subsubheading @value{GDBN} Command
33540
33541 The corresponding @value{GDBN} command is @samp{x}.
33542
33543 @subsubheading Example
33544
33545 @smallexample
33546 (gdb)
33547 -data-read-memory-bytes &a 10
33548 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33549 end="0xbffff15e",
33550 contents="01000000020000000300"@}]
33551 (gdb)
33552 @end smallexample
33553
33554
33555 @subheading The @code{-data-write-memory-bytes} Command
33556 @findex -data-write-memory-bytes
33557
33558 @subsubheading Synopsis
33559
33560 @smallexample
33561 -data-write-memory-bytes @var{address} @var{contents}
33562 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
33563 @end smallexample
33564
33565 @noindent
33566 where:
33567
33568 @table @samp
33569 @item @var{address}
33570 An expression specifying the address of the first addressable memory unit
33571 to be written. Complex expressions containing embedded white space should
33572 be quoted using the C convention.
33573
33574 @item @var{contents}
33575 The hex-encoded data to write. It is an error if @var{contents} does
33576 not represent an integral number of addressable memory units.
33577
33578 @item @var{count}
33579 Optional argument indicating the number of addressable memory units to be
33580 written. If @var{count} is greater than @var{contents}' length,
33581 @value{GDBN} will repeatedly write @var{contents} until it fills
33582 @var{count} memory units.
33583
33584 @end table
33585
33586 @subsubheading @value{GDBN} Command
33587
33588 There's no corresponding @value{GDBN} command.
33589
33590 @subsubheading Example
33591
33592 @smallexample
33593 (gdb)
33594 -data-write-memory-bytes &a "aabbccdd"
33595 ^done
33596 (gdb)
33597 @end smallexample
33598
33599 @smallexample
33600 (gdb)
33601 -data-write-memory-bytes &a "aabbccdd" 16e
33602 ^done
33603 (gdb)
33604 @end smallexample
33605
33606 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33607 @node GDB/MI Tracepoint Commands
33608 @section @sc{gdb/mi} Tracepoint Commands
33609
33610 The commands defined in this section implement MI support for
33611 tracepoints. For detailed introduction, see @ref{Tracepoints}.
33612
33613 @subheading The @code{-trace-find} Command
33614 @findex -trace-find
33615
33616 @subsubheading Synopsis
33617
33618 @smallexample
33619 -trace-find @var{mode} [@var{parameters}@dots{}]
33620 @end smallexample
33621
33622 Find a trace frame using criteria defined by @var{mode} and
33623 @var{parameters}. The following table lists permissible
33624 modes and their parameters. For details of operation, see @ref{tfind}.
33625
33626 @table @samp
33627
33628 @item none
33629 No parameters are required. Stops examining trace frames.
33630
33631 @item frame-number
33632 An integer is required as parameter. Selects tracepoint frame with
33633 that index.
33634
33635 @item tracepoint-number
33636 An integer is required as parameter. Finds next
33637 trace frame that corresponds to tracepoint with the specified number.
33638
33639 @item pc
33640 An address is required as parameter. Finds
33641 next trace frame that corresponds to any tracepoint at the specified
33642 address.
33643
33644 @item pc-inside-range
33645 Two addresses are required as parameters. Finds next trace
33646 frame that corresponds to a tracepoint at an address inside the
33647 specified range. Both bounds are considered to be inside the range.
33648
33649 @item pc-outside-range
33650 Two addresses are required as parameters. Finds
33651 next trace frame that corresponds to a tracepoint at an address outside
33652 the specified range. Both bounds are considered to be inside the range.
33653
33654 @item line
33655 Line specification is required as parameter. @xref{Specify Location}.
33656 Finds next trace frame that corresponds to a tracepoint at
33657 the specified location.
33658
33659 @end table
33660
33661 If @samp{none} was passed as @var{mode}, the response does not
33662 have fields. Otherwise, the response may have the following fields:
33663
33664 @table @samp
33665 @item found
33666 This field has either @samp{0} or @samp{1} as the value, depending
33667 on whether a matching tracepoint was found.
33668
33669 @item traceframe
33670 The index of the found traceframe. This field is present iff
33671 the @samp{found} field has value of @samp{1}.
33672
33673 @item tracepoint
33674 The index of the found tracepoint. This field is present iff
33675 the @samp{found} field has value of @samp{1}.
33676
33677 @item frame
33678 The information about the frame corresponding to the found trace
33679 frame. This field is present only if a trace frame was found.
33680 @xref{GDB/MI Frame Information}, for description of this field.
33681
33682 @end table
33683
33684 @subsubheading @value{GDBN} Command
33685
33686 The corresponding @value{GDBN} command is @samp{tfind}.
33687
33688 @subheading -trace-define-variable
33689 @findex -trace-define-variable
33690
33691 @subsubheading Synopsis
33692
33693 @smallexample
33694 -trace-define-variable @var{name} [ @var{value} ]
33695 @end smallexample
33696
33697 Create trace variable @var{name} if it does not exist. If
33698 @var{value} is specified, sets the initial value of the specified
33699 trace variable to that value. Note that the @var{name} should start
33700 with the @samp{$} character.
33701
33702 @subsubheading @value{GDBN} Command
33703
33704 The corresponding @value{GDBN} command is @samp{tvariable}.
33705
33706 @subheading The @code{-trace-frame-collected} Command
33707 @findex -trace-frame-collected
33708
33709 @subsubheading Synopsis
33710
33711 @smallexample
33712 -trace-frame-collected
33713 [--var-print-values @var{var_pval}]
33714 [--comp-print-values @var{comp_pval}]
33715 [--registers-format @var{regformat}]
33716 [--memory-contents]
33717 @end smallexample
33718
33719 This command returns the set of collected objects, register names,
33720 trace state variable names, memory ranges and computed expressions
33721 that have been collected at a particular trace frame. The optional
33722 parameters to the command affect the output format in different ways.
33723 See the output description table below for more details.
33724
33725 The reported names can be used in the normal manner to create
33726 varobjs and inspect the objects themselves. The items returned by
33727 this command are categorized so that it is clear which is a variable,
33728 which is a register, which is a trace state variable, which is a
33729 memory range and which is a computed expression.
33730
33731 For instance, if the actions were
33732 @smallexample
33733 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33734 collect *(int*)0xaf02bef0@@40
33735 @end smallexample
33736
33737 @noindent
33738 the object collected in its entirety would be @code{myVar}. The
33739 object @code{myArray} would be partially collected, because only the
33740 element at index @code{myIndex} would be collected. The remaining
33741 objects would be computed expressions.
33742
33743 An example output would be:
33744
33745 @smallexample
33746 (gdb)
33747 -trace-frame-collected
33748 ^done,
33749 explicit-variables=[@{name="myVar",value="1"@}],
33750 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33751 @{name="myObj.field",value="0"@},
33752 @{name="myPtr->field",value="1"@},
33753 @{name="myCount + 2",value="3"@},
33754 @{name="$tvar1 + 1",value="43970027"@}],
33755 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33756 @{number="1",value="0x0"@},
33757 @{number="2",value="0x4"@},
33758 ...
33759 @{number="125",value="0x0"@}],
33760 tvars=[@{name="$tvar1",current="43970026"@}],
33761 memory=[@{address="0x0000000000602264",length="4"@},
33762 @{address="0x0000000000615bc0",length="4"@}]
33763 (gdb)
33764 @end smallexample
33765
33766 Where:
33767
33768 @table @code
33769 @item explicit-variables
33770 The set of objects that have been collected in their entirety (as
33771 opposed to collecting just a few elements of an array or a few struct
33772 members). For each object, its name and value are printed.
33773 The @code{--var-print-values} option affects how or whether the value
33774 field is output. If @var{var_pval} is 0, then print only the names;
33775 if it is 1, print also their values; and if it is 2, print the name,
33776 type and value for simple data types, and the name and type for
33777 arrays, structures and unions.
33778
33779 @item computed-expressions
33780 The set of computed expressions that have been collected at the
33781 current trace frame. The @code{--comp-print-values} option affects
33782 this set like the @code{--var-print-values} option affects the
33783 @code{explicit-variables} set. See above.
33784
33785 @item registers
33786 The registers that have been collected at the current trace frame.
33787 For each register collected, the name and current value are returned.
33788 The value is formatted according to the @code{--registers-format}
33789 option. See the @command{-data-list-register-values} command for a
33790 list of the allowed formats. The default is @samp{x}.
33791
33792 @item tvars
33793 The trace state variables that have been collected at the current
33794 trace frame. For each trace state variable collected, the name and
33795 current value are returned.
33796
33797 @item memory
33798 The set of memory ranges that have been collected at the current trace
33799 frame. Its content is a list of tuples. Each tuple represents a
33800 collected memory range and has the following fields:
33801
33802 @table @code
33803 @item address
33804 The start address of the memory range, as hexadecimal literal.
33805
33806 @item length
33807 The length of the memory range, as decimal literal.
33808
33809 @item contents
33810 The contents of the memory block, in hex. This field is only present
33811 if the @code{--memory-contents} option is specified.
33812
33813 @end table
33814
33815 @end table
33816
33817 @subsubheading @value{GDBN} Command
33818
33819 There is no corresponding @value{GDBN} command.
33820
33821 @subsubheading Example
33822
33823 @subheading -trace-list-variables
33824 @findex -trace-list-variables
33825
33826 @subsubheading Synopsis
33827
33828 @smallexample
33829 -trace-list-variables
33830 @end smallexample
33831
33832 Return a table of all defined trace variables. Each element of the
33833 table has the following fields:
33834
33835 @table @samp
33836 @item name
33837 The name of the trace variable. This field is always present.
33838
33839 @item initial
33840 The initial value. This is a 64-bit signed integer. This
33841 field is always present.
33842
33843 @item current
33844 The value the trace variable has at the moment. This is a 64-bit
33845 signed integer. This field is absent iff current value is
33846 not defined, for example if the trace was never run, or is
33847 presently running.
33848
33849 @end table
33850
33851 @subsubheading @value{GDBN} Command
33852
33853 The corresponding @value{GDBN} command is @samp{tvariables}.
33854
33855 @subsubheading Example
33856
33857 @smallexample
33858 (gdb)
33859 -trace-list-variables
33860 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
33861 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
33862 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
33863 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
33864 body=[variable=@{name="$trace_timestamp",initial="0"@}
33865 variable=@{name="$foo",initial="10",current="15"@}]@}
33866 (gdb)
33867 @end smallexample
33868
33869 @subheading -trace-save
33870 @findex -trace-save
33871
33872 @subsubheading Synopsis
33873
33874 @smallexample
33875 -trace-save [ -r ] [ -ctf ] @var{filename}
33876 @end smallexample
33877
33878 Saves the collected trace data to @var{filename}. Without the
33879 @samp{-r} option, the data is downloaded from the target and saved
33880 in a local file. With the @samp{-r} option the target is asked
33881 to perform the save.
33882
33883 By default, this command will save the trace in the tfile format. You can
33884 supply the optional @samp{-ctf} argument to save it the CTF format. See
33885 @ref{Trace Files} for more information about CTF.
33886
33887 @subsubheading @value{GDBN} Command
33888
33889 The corresponding @value{GDBN} command is @samp{tsave}.
33890
33891
33892 @subheading -trace-start
33893 @findex -trace-start
33894
33895 @subsubheading Synopsis
33896
33897 @smallexample
33898 -trace-start
33899 @end smallexample
33900
33901 Starts a tracing experiment. The result of this command does not
33902 have any fields.
33903
33904 @subsubheading @value{GDBN} Command
33905
33906 The corresponding @value{GDBN} command is @samp{tstart}.
33907
33908 @subheading -trace-status
33909 @findex -trace-status
33910
33911 @subsubheading Synopsis
33912
33913 @smallexample
33914 -trace-status
33915 @end smallexample
33916
33917 Obtains the status of a tracing experiment. The result may include
33918 the following fields:
33919
33920 @table @samp
33921
33922 @item supported
33923 May have a value of either @samp{0}, when no tracing operations are
33924 supported, @samp{1}, when all tracing operations are supported, or
33925 @samp{file} when examining trace file. In the latter case, examining
33926 of trace frame is possible but new tracing experiement cannot be
33927 started. This field is always present.
33928
33929 @item running
33930 May have a value of either @samp{0} or @samp{1} depending on whether
33931 tracing experiement is in progress on target. This field is present
33932 if @samp{supported} field is not @samp{0}.
33933
33934 @item stop-reason
33935 Report the reason why the tracing was stopped last time. This field
33936 may be absent iff tracing was never stopped on target yet. The
33937 value of @samp{request} means the tracing was stopped as result of
33938 the @code{-trace-stop} command. The value of @samp{overflow} means
33939 the tracing buffer is full. The value of @samp{disconnection} means
33940 tracing was automatically stopped when @value{GDBN} has disconnected.
33941 The value of @samp{passcount} means tracing was stopped when a
33942 tracepoint was passed a maximal number of times for that tracepoint.
33943 This field is present if @samp{supported} field is not @samp{0}.
33944
33945 @item stopping-tracepoint
33946 The number of tracepoint whose passcount as exceeded. This field is
33947 present iff the @samp{stop-reason} field has the value of
33948 @samp{passcount}.
33949
33950 @item frames
33951 @itemx frames-created
33952 The @samp{frames} field is a count of the total number of trace frames
33953 in the trace buffer, while @samp{frames-created} is the total created
33954 during the run, including ones that were discarded, such as when a
33955 circular trace buffer filled up. Both fields are optional.
33956
33957 @item buffer-size
33958 @itemx buffer-free
33959 These fields tell the current size of the tracing buffer and the
33960 remaining space. These fields are optional.
33961
33962 @item circular
33963 The value of the circular trace buffer flag. @code{1} means that the
33964 trace buffer is circular and old trace frames will be discarded if
33965 necessary to make room, @code{0} means that the trace buffer is linear
33966 and may fill up.
33967
33968 @item disconnected
33969 The value of the disconnected tracing flag. @code{1} means that
33970 tracing will continue after @value{GDBN} disconnects, @code{0} means
33971 that the trace run will stop.
33972
33973 @item trace-file
33974 The filename of the trace file being examined. This field is
33975 optional, and only present when examining a trace file.
33976
33977 @end table
33978
33979 @subsubheading @value{GDBN} Command
33980
33981 The corresponding @value{GDBN} command is @samp{tstatus}.
33982
33983 @subheading -trace-stop
33984 @findex -trace-stop
33985
33986 @subsubheading Synopsis
33987
33988 @smallexample
33989 -trace-stop
33990 @end smallexample
33991
33992 Stops a tracing experiment. The result of this command has the same
33993 fields as @code{-trace-status}, except that the @samp{supported} and
33994 @samp{running} fields are not output.
33995
33996 @subsubheading @value{GDBN} Command
33997
33998 The corresponding @value{GDBN} command is @samp{tstop}.
33999
34000
34001 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34002 @node GDB/MI Symbol Query
34003 @section @sc{gdb/mi} Symbol Query Commands
34004
34005
34006 @ignore
34007 @subheading The @code{-symbol-info-address} Command
34008 @findex -symbol-info-address
34009
34010 @subsubheading Synopsis
34011
34012 @smallexample
34013 -symbol-info-address @var{symbol}
34014 @end smallexample
34015
34016 Describe where @var{symbol} is stored.
34017
34018 @subsubheading @value{GDBN} Command
34019
34020 The corresponding @value{GDBN} command is @samp{info address}.
34021
34022 @subsubheading Example
34023 N.A.
34024
34025
34026 @subheading The @code{-symbol-info-file} Command
34027 @findex -symbol-info-file
34028
34029 @subsubheading Synopsis
34030
34031 @smallexample
34032 -symbol-info-file
34033 @end smallexample
34034
34035 Show the file for the symbol.
34036
34037 @subsubheading @value{GDBN} Command
34038
34039 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34040 @samp{gdb_find_file}.
34041
34042 @subsubheading Example
34043 N.A.
34044 @end ignore
34045
34046 @subheading The @code{-symbol-info-functions} Command
34047 @findex -symbol-info-functions
34048 @anchor{-symbol-info-functions}
34049
34050 @subsubheading Synopsis
34051
34052 @smallexample
34053 -symbol-info-functions [--include-nondebug]
34054 [--type @var{type_regexp}]
34055 [--name @var{name_regexp}]
34056 [--max-results @var{limit}]
34057 @end smallexample
34058
34059 @noindent
34060 Return a list containing the names and types for all global functions
34061 taken from the debug information. The functions are grouped by source
34062 file, and shown with the line number on which each function is
34063 defined.
34064
34065 The @code{--include-nondebug} option causes the output to include
34066 code symbols from the symbol table.
34067
34068 The options @code{--type} and @code{--name} allow the symbols returned
34069 to be filtered based on either the name of the function, or the type
34070 signature of the function.
34071
34072 The option @code{--max-results} restricts the command to return no
34073 more than @var{limit} results. If exactly @var{limit} results are
34074 returned then there might be additional results available if a higher
34075 limit is used.
34076
34077 @subsubheading @value{GDBN} Command
34078
34079 The corresponding @value{GDBN} command is @samp{info functions}.
34080
34081 @subsubheading Example
34082 @smallexample
34083 @group
34084 (gdb)
34085 -symbol-info-functions
34086 ^done,symbols=
34087 @{debug=
34088 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34089 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34090 symbols=[@{line="36", name="f4", type="void (int *)",
34091 description="void f4(int *);"@},
34092 @{line="42", name="main", type="int ()",
34093 description="int main();"@},
34094 @{line="30", name="f1", type="my_int_t (int, int)",
34095 description="static my_int_t f1(int, int);"@}]@},
34096 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34097 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34098 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34099 description="float f2(another_float_t);"@},
34100 @{line="39", name="f3", type="int (another_int_t)",
34101 description="int f3(another_int_t);"@},
34102 @{line="27", name="f1", type="another_float_t (int)",
34103 description="static another_float_t f1(int);"@}]@}]@}
34104 @end group
34105 @group
34106 (gdb)
34107 -symbol-info-functions --name f1
34108 ^done,symbols=
34109 @{debug=
34110 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34111 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34112 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34113 description="static my_int_t f1(int, int);"@}]@},
34114 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34115 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34116 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34117 description="static another_float_t f1(int);"@}]@}]@}
34118 @end group
34119 @group
34120 (gdb)
34121 -symbol-info-functions --type void
34122 ^done,symbols=
34123 @{debug=
34124 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34125 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34126 symbols=[@{line="36", name="f4", type="void (int *)",
34127 description="void f4(int *);"@}]@}]@}
34128 @end group
34129 @group
34130 (gdb)
34131 -symbol-info-functions --include-nondebug
34132 ^done,symbols=
34133 @{debug=
34134 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34135 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34136 symbols=[@{line="36", name="f4", type="void (int *)",
34137 description="void f4(int *);"@},
34138 @{line="42", name="main", type="int ()",
34139 description="int main();"@},
34140 @{line="30", name="f1", type="my_int_t (int, int)",
34141 description="static my_int_t f1(int, int);"@}]@},
34142 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34143 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34144 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34145 description="float f2(another_float_t);"@},
34146 @{line="39", name="f3", type="int (another_int_t)",
34147 description="int f3(another_int_t);"@},
34148 @{line="27", name="f1", type="another_float_t (int)",
34149 description="static another_float_t f1(int);"@}]@}],
34150 nondebug=
34151 [@{address="0x0000000000400398",name="_init"@},
34152 @{address="0x00000000004003b0",name="_start"@},
34153 ...
34154 ]@}
34155 @end group
34156 @end smallexample
34157
34158 @subheading The @code{-symbol-info-module-functions} Command
34159 @findex -symbol-info-module-functions
34160 @anchor{-symbol-info-module-functions}
34161
34162 @subsubheading Synopsis
34163
34164 @smallexample
34165 -symbol-info-module-functions [--module @var{module_regexp}]
34166 [--name @var{name_regexp}]
34167 [--type @var{type_regexp}]
34168 @end smallexample
34169
34170 @noindent
34171 Return a list containing the names of all known functions within all
34172 know Fortran modules. The functions are grouped by source file and
34173 containing module, and shown with the line number on which each
34174 function is defined.
34175
34176 The option @code{--module} only returns results for modules matching
34177 @var{module_regexp}. The option @code{--name} only returns functions
34178 whose name matches @var{name_regexp}, and @code{--type} only returns
34179 functions whose type matches @var{type_regexp}.
34180
34181 @subsubheading @value{GDBN} Command
34182
34183 The corresponding @value{GDBN} command is @samp{info module functions}.
34184
34185 @subsubheading Example
34186
34187 @smallexample
34188 @group
34189 (gdb)
34190 -symbol-info-module-functions
34191 ^done,symbols=
34192 [@{module="mod1",
34193 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34194 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34195 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34196 description="void mod1::check_all(void);"@}]@}]@},
34197 @{module="mod2",
34198 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34199 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34200 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34201 description="void mod2::check_var_i(void);"@}]@}]@},
34202 @{module="mod3",
34203 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34204 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34205 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34206 description="void mod3::check_all(void);"@},
34207 @{line="27",name="mod3::check_mod2",type="void (void)",
34208 description="void mod3::check_mod2(void);"@}]@}]@},
34209 @{module="modmany",
34210 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34211 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34212 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34213 description="void modmany::check_some(void);"@}]@}]@},
34214 @{module="moduse",
34215 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34216 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34217 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34218 description="void moduse::check_all(void);"@},
34219 @{line="49",name="moduse::check_var_x",type="void (void)",
34220 description="void moduse::check_var_x(void);"@}]@}]@}]
34221 @end group
34222 @end smallexample
34223
34224 @subheading The @code{-symbol-info-module-variables} Command
34225 @findex -symbol-info-module-variables
34226 @anchor{-symbol-info-module-variables}
34227
34228 @subsubheading Synopsis
34229
34230 @smallexample
34231 -symbol-info-module-variables [--module @var{module_regexp}]
34232 [--name @var{name_regexp}]
34233 [--type @var{type_regexp}]
34234 @end smallexample
34235
34236 @noindent
34237 Return a list containing the names of all known variables within all
34238 know Fortran modules. The variables are grouped by source file and
34239 containing module, and shown with the line number on which each
34240 variable is defined.
34241
34242 The option @code{--module} only returns results for modules matching
34243 @var{module_regexp}. The option @code{--name} only returns variables
34244 whose name matches @var{name_regexp}, and @code{--type} only returns
34245 variables whose type matches @var{type_regexp}.
34246
34247 @subsubheading @value{GDBN} Command
34248
34249 The corresponding @value{GDBN} command is @samp{info module variables}.
34250
34251 @subsubheading Example
34252
34253 @smallexample
34254 @group
34255 (gdb)
34256 -symbol-info-module-variables
34257 ^done,symbols=
34258 [@{module="mod1",
34259 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34260 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34261 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34262 description="integer(kind=4) mod1::var_const;"@},
34263 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34264 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34265 @{module="mod2",
34266 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34267 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34268 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34269 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34270 @{module="mod3",
34271 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34272 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34273 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34274 description="integer(kind=4) mod3::mod1;"@},
34275 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34276 description="integer(kind=4) mod3::mod2;"@},
34277 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34278 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34279 @{module="modmany",
34280 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34281 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34282 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34283 description="integer(kind=4) modmany::var_a;"@},
34284 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34285 description="integer(kind=4) modmany::var_b;"@},
34286 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34287 description="integer(kind=4) modmany::var_c;"@},
34288 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34289 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34290 @{module="moduse",
34291 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34292 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34293 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34294 description="integer(kind=4) moduse::var_x;"@},
34295 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34296 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34297 @end group
34298 @end smallexample
34299
34300 @subheading The @code{-symbol-info-modules} Command
34301 @findex -symbol-info-modules
34302 @anchor{-symbol-info-modules}
34303
34304 @subsubheading Synopsis
34305
34306 @smallexample
34307 -symbol-info-modules [--name @var{name_regexp}]
34308 [--max-results @var{limit}]
34309
34310 @end smallexample
34311
34312 @noindent
34313 Return a list containing the names of all known Fortran modules. The
34314 modules are grouped by source file, and shown with the line number on
34315 which each modules is defined.
34316
34317 The option @code{--name} allows the modules returned to be filtered
34318 based the name of the module.
34319
34320 The option @code{--max-results} restricts the command to return no
34321 more than @var{limit} results. If exactly @var{limit} results are
34322 returned then there might be additional results available if a higher
34323 limit is used.
34324
34325 @subsubheading @value{GDBN} Command
34326
34327 The corresponding @value{GDBN} command is @samp{info modules}.
34328
34329 @subsubheading Example
34330 @smallexample
34331 @group
34332 (gdb)
34333 -symbol-info-modules
34334 ^done,symbols=
34335 @{debug=
34336 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34337 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34338 symbols=[@{line="16",name="mod1"@},
34339 @{line="22",name="mod2"@}]@},
34340 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34341 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34342 symbols=[@{line="16",name="mod3"@},
34343 @{line="22",name="modmany"@},
34344 @{line="26",name="moduse"@}]@}]@}
34345 @end group
34346 @group
34347 (gdb)
34348 -symbol-info-modules --name mod[123]
34349 ^done,symbols=
34350 @{debug=
34351 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34352 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34353 symbols=[@{line="16",name="mod1"@},
34354 @{line="22",name="mod2"@}]@},
34355 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34356 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34357 symbols=[@{line="16",name="mod3"@}]@}]@}
34358 @end group
34359 @end smallexample
34360
34361 @subheading The @code{-symbol-info-types} Command
34362 @findex -symbol-info-types
34363 @anchor{-symbol-info-types}
34364
34365 @subsubheading Synopsis
34366
34367 @smallexample
34368 -symbol-info-types [--name @var{name_regexp}]
34369 [--max-results @var{limit}]
34370
34371 @end smallexample
34372
34373 @noindent
34374 Return a list of all defined types. The types are grouped by source
34375 file, and shown with the line number on which each user defined type
34376 is defined. Some base types are not defined in the source code but
34377 are added to the debug information by the compiler, for example
34378 @code{int}, @code{float}, etc.; these types do not have an associated
34379 line number.
34380
34381 The option @code{--name} allows the list of types returned to be
34382 filtered by name.
34383
34384 The option @code{--max-results} restricts the command to return no
34385 more than @var{limit} results. If exactly @var{limit} results are
34386 returned then there might be additional results available if a higher
34387 limit is used.
34388
34389 @subsubheading @value{GDBN} Command
34390
34391 The corresponding @value{GDBN} command is @samp{info types}.
34392
34393 @subsubheading Example
34394 @smallexample
34395 @group
34396 (gdb)
34397 -symbol-info-types
34398 ^done,symbols=
34399 @{debug=
34400 [@{filename="gdb.mi/mi-sym-info-1.c",
34401 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34402 symbols=[@{name="float"@},
34403 @{name="int"@},
34404 @{line="27",name="typedef int my_int_t;"@}]@},
34405 @{filename="gdb.mi/mi-sym-info-2.c",
34406 fullname="/project/gdb.mi/mi-sym-info-2.c",
34407 symbols=[@{line="24",name="typedef float another_float_t;"@},
34408 @{line="23",name="typedef int another_int_t;"@},
34409 @{name="float"@},
34410 @{name="int"@}]@}]@}
34411 @end group
34412 @group
34413 (gdb)
34414 -symbol-info-types --name _int_
34415 ^done,symbols=
34416 @{debug=
34417 [@{filename="gdb.mi/mi-sym-info-1.c",
34418 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34419 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34420 @{filename="gdb.mi/mi-sym-info-2.c",
34421 fullname="/project/gdb.mi/mi-sym-info-2.c",
34422 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34423 @end group
34424 @end smallexample
34425
34426 @subheading The @code{-symbol-info-variables} Command
34427 @findex -symbol-info-variables
34428 @anchor{-symbol-info-variables}
34429
34430 @subsubheading Synopsis
34431
34432 @smallexample
34433 -symbol-info-variables [--include-nondebug]
34434 [--type @var{type_regexp}]
34435 [--name @var{name_regexp}]
34436 [--max-results @var{limit}]
34437
34438 @end smallexample
34439
34440 @noindent
34441 Return a list containing the names and types for all global variables
34442 taken from the debug information. The variables are grouped by source
34443 file, and shown with the line number on which each variable is
34444 defined.
34445
34446 The @code{--include-nondebug} option causes the output to include
34447 data symbols from the symbol table.
34448
34449 The options @code{--type} and @code{--name} allow the symbols returned
34450 to be filtered based on either the name of the variable, or the type
34451 of the variable.
34452
34453 The option @code{--max-results} restricts the command to return no
34454 more than @var{limit} results. If exactly @var{limit} results are
34455 returned then there might be additional results available if a higher
34456 limit is used.
34457
34458 @subsubheading @value{GDBN} Command
34459
34460 The corresponding @value{GDBN} command is @samp{info variables}.
34461
34462 @subsubheading Example
34463 @smallexample
34464 @group
34465 (gdb)
34466 -symbol-info-variables
34467 ^done,symbols=
34468 @{debug=
34469 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34470 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34471 symbols=[@{line="25",name="global_f1",type="float",
34472 description="static float global_f1;"@},
34473 @{line="24",name="global_i1",type="int",
34474 description="static int global_i1;"@}]@},
34475 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34476 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34477 symbols=[@{line="21",name="global_f2",type="int",
34478 description="int global_f2;"@},
34479 @{line="20",name="global_i2",type="int",
34480 description="int global_i2;"@},
34481 @{line="19",name="global_f1",type="float",
34482 description="static float global_f1;"@},
34483 @{line="18",name="global_i1",type="int",
34484 description="static int global_i1;"@}]@}]@}
34485 @end group
34486 @group
34487 (gdb)
34488 -symbol-info-variables --name f1
34489 ^done,symbols=
34490 @{debug=
34491 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34492 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34493 symbols=[@{line="25",name="global_f1",type="float",
34494 description="static float global_f1;"@}]@},
34495 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34496 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34497 symbols=[@{line="19",name="global_f1",type="float",
34498 description="static float global_f1;"@}]@}]@}
34499 @end group
34500 @group
34501 (gdb)
34502 -symbol-info-variables --type float
34503 ^done,symbols=
34504 @{debug=
34505 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34506 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34507 symbols=[@{line="25",name="global_f1",type="float",
34508 description="static float global_f1;"@}]@},
34509 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34510 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34511 symbols=[@{line="19",name="global_f1",type="float",
34512 description="static float global_f1;"@}]@}]@}
34513 @end group
34514 @group
34515 (gdb)
34516 -symbol-info-variables --include-nondebug
34517 ^done,symbols=
34518 @{debug=
34519 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34520 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34521 symbols=[@{line="25",name="global_f1",type="float",
34522 description="static float global_f1;"@},
34523 @{line="24",name="global_i1",type="int",
34524 description="static int global_i1;"@}]@},
34525 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34526 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34527 symbols=[@{line="21",name="global_f2",type="int",
34528 description="int global_f2;"@},
34529 @{line="20",name="global_i2",type="int",
34530 description="int global_i2;"@},
34531 @{line="19",name="global_f1",type="float",
34532 description="static float global_f1;"@},
34533 @{line="18",name="global_i1",type="int",
34534 description="static int global_i1;"@}]@}],
34535 nondebug=
34536 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34537 @{address="0x00000000004005d8",name="__dso_handle"@}
34538 ...
34539 ]@}
34540 @end group
34541 @end smallexample
34542
34543 @ignore
34544 @subheading The @code{-symbol-info-line} Command
34545 @findex -symbol-info-line
34546
34547 @subsubheading Synopsis
34548
34549 @smallexample
34550 -symbol-info-line
34551 @end smallexample
34552
34553 Show the core addresses of the code for a source line.
34554
34555 @subsubheading @value{GDBN} Command
34556
34557 The corresponding @value{GDBN} command is @samp{info line}.
34558 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
34559
34560 @subsubheading Example
34561 N.A.
34562
34563
34564 @subheading The @code{-symbol-info-symbol} Command
34565 @findex -symbol-info-symbol
34566
34567 @subsubheading Synopsis
34568
34569 @smallexample
34570 -symbol-info-symbol @var{addr}
34571 @end smallexample
34572
34573 Describe what symbol is at location @var{addr}.
34574
34575 @subsubheading @value{GDBN} Command
34576
34577 The corresponding @value{GDBN} command is @samp{info symbol}.
34578
34579 @subsubheading Example
34580 N.A.
34581
34582
34583 @subheading The @code{-symbol-list-functions} Command
34584 @findex -symbol-list-functions
34585
34586 @subsubheading Synopsis
34587
34588 @smallexample
34589 -symbol-list-functions
34590 @end smallexample
34591
34592 List the functions in the executable.
34593
34594 @subsubheading @value{GDBN} Command
34595
34596 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34597 @samp{gdb_search} in @code{gdbtk}.
34598
34599 @subsubheading Example
34600 N.A.
34601 @end ignore
34602
34603
34604 @subheading The @code{-symbol-list-lines} Command
34605 @findex -symbol-list-lines
34606
34607 @subsubheading Synopsis
34608
34609 @smallexample
34610 -symbol-list-lines @var{filename}
34611 @end smallexample
34612
34613 Print the list of lines that contain code and their associated program
34614 addresses for the given source filename. The entries are sorted in
34615 ascending PC order.
34616
34617 @subsubheading @value{GDBN} Command
34618
34619 There is no corresponding @value{GDBN} command.
34620
34621 @subsubheading Example
34622 @smallexample
34623 (gdb)
34624 -symbol-list-lines basics.c
34625 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
34626 (gdb)
34627 @end smallexample
34628
34629
34630 @ignore
34631 @subheading The @code{-symbol-list-types} Command
34632 @findex -symbol-list-types
34633
34634 @subsubheading Synopsis
34635
34636 @smallexample
34637 -symbol-list-types
34638 @end smallexample
34639
34640 List all the type names.
34641
34642 @subsubheading @value{GDBN} Command
34643
34644 The corresponding commands are @samp{info types} in @value{GDBN},
34645 @samp{gdb_search} in @code{gdbtk}.
34646
34647 @subsubheading Example
34648 N.A.
34649
34650
34651 @subheading The @code{-symbol-list-variables} Command
34652 @findex -symbol-list-variables
34653
34654 @subsubheading Synopsis
34655
34656 @smallexample
34657 -symbol-list-variables
34658 @end smallexample
34659
34660 List all the global and static variable names.
34661
34662 @subsubheading @value{GDBN} Command
34663
34664 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
34665
34666 @subsubheading Example
34667 N.A.
34668
34669
34670 @subheading The @code{-symbol-locate} Command
34671 @findex -symbol-locate
34672
34673 @subsubheading Synopsis
34674
34675 @smallexample
34676 -symbol-locate
34677 @end smallexample
34678
34679 @subsubheading @value{GDBN} Command
34680
34681 @samp{gdb_loc} in @code{gdbtk}.
34682
34683 @subsubheading Example
34684 N.A.
34685
34686
34687 @subheading The @code{-symbol-type} Command
34688 @findex -symbol-type
34689
34690 @subsubheading Synopsis
34691
34692 @smallexample
34693 -symbol-type @var{variable}
34694 @end smallexample
34695
34696 Show type of @var{variable}.
34697
34698 @subsubheading @value{GDBN} Command
34699
34700 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34701 @samp{gdb_obj_variable}.
34702
34703 @subsubheading Example
34704 N.A.
34705 @end ignore
34706
34707
34708 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34709 @node GDB/MI File Commands
34710 @section @sc{gdb/mi} File Commands
34711
34712 This section describes the GDB/MI commands to specify executable file names
34713 and to read in and obtain symbol table information.
34714
34715 @subheading The @code{-file-exec-and-symbols} Command
34716 @findex -file-exec-and-symbols
34717
34718 @subsubheading Synopsis
34719
34720 @smallexample
34721 -file-exec-and-symbols @var{file}
34722 @end smallexample
34723
34724 Specify the executable file to be debugged. This file is the one from
34725 which the symbol table is also read. If no file is specified, the
34726 command clears the executable and symbol information. If breakpoints
34727 are set when using this command with no arguments, @value{GDBN} will produce
34728 error messages. Otherwise, no output is produced, except a completion
34729 notification.
34730
34731 @subsubheading @value{GDBN} Command
34732
34733 The corresponding @value{GDBN} command is @samp{file}.
34734
34735 @subsubheading Example
34736
34737 @smallexample
34738 (gdb)
34739 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34740 ^done
34741 (gdb)
34742 @end smallexample
34743
34744
34745 @subheading The @code{-file-exec-file} Command
34746 @findex -file-exec-file
34747
34748 @subsubheading Synopsis
34749
34750 @smallexample
34751 -file-exec-file @var{file}
34752 @end smallexample
34753
34754 Specify the executable file to be debugged. Unlike
34755 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34756 from this file. If used without argument, @value{GDBN} clears the information
34757 about the executable file. No output is produced, except a completion
34758 notification.
34759
34760 @subsubheading @value{GDBN} Command
34761
34762 The corresponding @value{GDBN} command is @samp{exec-file}.
34763
34764 @subsubheading Example
34765
34766 @smallexample
34767 (gdb)
34768 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34769 ^done
34770 (gdb)
34771 @end smallexample
34772
34773
34774 @ignore
34775 @subheading The @code{-file-list-exec-sections} Command
34776 @findex -file-list-exec-sections
34777
34778 @subsubheading Synopsis
34779
34780 @smallexample
34781 -file-list-exec-sections
34782 @end smallexample
34783
34784 List the sections of the current executable file.
34785
34786 @subsubheading @value{GDBN} Command
34787
34788 The @value{GDBN} command @samp{info file} shows, among the rest, the same
34789 information as this command. @code{gdbtk} has a corresponding command
34790 @samp{gdb_load_info}.
34791
34792 @subsubheading Example
34793 N.A.
34794 @end ignore
34795
34796
34797 @subheading The @code{-file-list-exec-source-file} Command
34798 @findex -file-list-exec-source-file
34799
34800 @subsubheading Synopsis
34801
34802 @smallexample
34803 -file-list-exec-source-file
34804 @end smallexample
34805
34806 List the line number, the current source file, and the absolute path
34807 to the current source file for the current executable. The macro
34808 information field has a value of @samp{1} or @samp{0} depending on
34809 whether or not the file includes preprocessor macro information.
34810
34811 @subsubheading @value{GDBN} Command
34812
34813 The @value{GDBN} equivalent is @samp{info source}
34814
34815 @subsubheading Example
34816
34817 @smallexample
34818 (gdb)
34819 123-file-list-exec-source-file
34820 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
34821 (gdb)
34822 @end smallexample
34823
34824
34825 @subheading The @code{-file-list-exec-source-files} Command
34826 @findex -file-list-exec-source-files
34827
34828 @subsubheading Synopsis
34829
34830 @smallexample
34831 -file-list-exec-source-files
34832 @end smallexample
34833
34834 List the source files for the current executable.
34835
34836 It will always output both the filename and fullname (absolute file
34837 name) of a source file.
34838
34839 @subsubheading @value{GDBN} Command
34840
34841 The @value{GDBN} equivalent is @samp{info sources}.
34842 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
34843
34844 @subsubheading Example
34845 @smallexample
34846 (gdb)
34847 -file-list-exec-source-files
34848 ^done,files=[
34849 @{file=foo.c,fullname=/home/foo.c@},
34850 @{file=/home/bar.c,fullname=/home/bar.c@},
34851 @{file=gdb_could_not_find_fullpath.c@}]
34852 (gdb)
34853 @end smallexample
34854
34855 @subheading The @code{-file-list-shared-libraries} Command
34856 @findex -file-list-shared-libraries
34857
34858 @subsubheading Synopsis
34859
34860 @smallexample
34861 -file-list-shared-libraries [ @var{regexp} ]
34862 @end smallexample
34863
34864 List the shared libraries in the program.
34865 With a regular expression @var{regexp}, only those libraries whose
34866 names match @var{regexp} are listed.
34867
34868 @subsubheading @value{GDBN} Command
34869
34870 The corresponding @value{GDBN} command is @samp{info shared}. The fields
34871 have a similar meaning to the @code{=library-loaded} notification.
34872 The @code{ranges} field specifies the multiple segments belonging to this
34873 library. Each range has the following fields:
34874
34875 @table @samp
34876 @item from
34877 The address defining the inclusive lower bound of the segment.
34878 @item to
34879 The address defining the exclusive upper bound of the segment.
34880 @end table
34881
34882 @subsubheading Example
34883 @smallexample
34884 (gdb)
34885 -file-list-exec-source-files
34886 ^done,shared-libraries=[
34887 @{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"@}]@},
34888 @{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"@}]@}]
34889 (gdb)
34890 @end smallexample
34891
34892
34893 @ignore
34894 @subheading The @code{-file-list-symbol-files} Command
34895 @findex -file-list-symbol-files
34896
34897 @subsubheading Synopsis
34898
34899 @smallexample
34900 -file-list-symbol-files
34901 @end smallexample
34902
34903 List symbol files.
34904
34905 @subsubheading @value{GDBN} Command
34906
34907 The corresponding @value{GDBN} command is @samp{info file} (part of it).
34908
34909 @subsubheading Example
34910 N.A.
34911 @end ignore
34912
34913
34914 @subheading The @code{-file-symbol-file} Command
34915 @findex -file-symbol-file
34916
34917 @subsubheading Synopsis
34918
34919 @smallexample
34920 -file-symbol-file @var{file}
34921 @end smallexample
34922
34923 Read symbol table info from the specified @var{file} argument. When
34924 used without arguments, clears @value{GDBN}'s symbol table info. No output is
34925 produced, except for a completion notification.
34926
34927 @subsubheading @value{GDBN} Command
34928
34929 The corresponding @value{GDBN} command is @samp{symbol-file}.
34930
34931 @subsubheading Example
34932
34933 @smallexample
34934 (gdb)
34935 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34936 ^done
34937 (gdb)
34938 @end smallexample
34939
34940 @ignore
34941 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34942 @node GDB/MI Memory Overlay Commands
34943 @section @sc{gdb/mi} Memory Overlay Commands
34944
34945 The memory overlay commands are not implemented.
34946
34947 @c @subheading -overlay-auto
34948
34949 @c @subheading -overlay-list-mapping-state
34950
34951 @c @subheading -overlay-list-overlays
34952
34953 @c @subheading -overlay-map
34954
34955 @c @subheading -overlay-off
34956
34957 @c @subheading -overlay-on
34958
34959 @c @subheading -overlay-unmap
34960
34961 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34962 @node GDB/MI Signal Handling Commands
34963 @section @sc{gdb/mi} Signal Handling Commands
34964
34965 Signal handling commands are not implemented.
34966
34967 @c @subheading -signal-handle
34968
34969 @c @subheading -signal-list-handle-actions
34970
34971 @c @subheading -signal-list-signal-types
34972 @end ignore
34973
34974
34975 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34976 @node GDB/MI Target Manipulation
34977 @section @sc{gdb/mi} Target Manipulation Commands
34978
34979
34980 @subheading The @code{-target-attach} Command
34981 @findex -target-attach
34982
34983 @subsubheading Synopsis
34984
34985 @smallexample
34986 -target-attach @var{pid} | @var{gid} | @var{file}
34987 @end smallexample
34988
34989 Attach to a process @var{pid} or a file @var{file} outside of
34990 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
34991 group, the id previously returned by
34992 @samp{-list-thread-groups --available} must be used.
34993
34994 @subsubheading @value{GDBN} Command
34995
34996 The corresponding @value{GDBN} command is @samp{attach}.
34997
34998 @subsubheading Example
34999 @smallexample
35000 (gdb)
35001 -target-attach 34
35002 =thread-created,id="1"
35003 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35004 ^done
35005 (gdb)
35006 @end smallexample
35007
35008 @ignore
35009 @subheading The @code{-target-compare-sections} Command
35010 @findex -target-compare-sections
35011
35012 @subsubheading Synopsis
35013
35014 @smallexample
35015 -target-compare-sections [ @var{section} ]
35016 @end smallexample
35017
35018 Compare data of section @var{section} on target to the exec file.
35019 Without the argument, all sections are compared.
35020
35021 @subsubheading @value{GDBN} Command
35022
35023 The @value{GDBN} equivalent is @samp{compare-sections}.
35024
35025 @subsubheading Example
35026 N.A.
35027 @end ignore
35028
35029
35030 @subheading The @code{-target-detach} Command
35031 @findex -target-detach
35032
35033 @subsubheading Synopsis
35034
35035 @smallexample
35036 -target-detach [ @var{pid} | @var{gid} ]
35037 @end smallexample
35038
35039 Detach from the remote target which normally resumes its execution.
35040 If either @var{pid} or @var{gid} is specified, detaches from either
35041 the specified process, or specified thread group. There's no output.
35042
35043 @subsubheading @value{GDBN} Command
35044
35045 The corresponding @value{GDBN} command is @samp{detach}.
35046
35047 @subsubheading Example
35048
35049 @smallexample
35050 (gdb)
35051 -target-detach
35052 ^done
35053 (gdb)
35054 @end smallexample
35055
35056
35057 @subheading The @code{-target-disconnect} Command
35058 @findex -target-disconnect
35059
35060 @subsubheading Synopsis
35061
35062 @smallexample
35063 -target-disconnect
35064 @end smallexample
35065
35066 Disconnect from the remote target. There's no output and the target is
35067 generally not resumed.
35068
35069 @subsubheading @value{GDBN} Command
35070
35071 The corresponding @value{GDBN} command is @samp{disconnect}.
35072
35073 @subsubheading Example
35074
35075 @smallexample
35076 (gdb)
35077 -target-disconnect
35078 ^done
35079 (gdb)
35080 @end smallexample
35081
35082
35083 @subheading The @code{-target-download} Command
35084 @findex -target-download
35085
35086 @subsubheading Synopsis
35087
35088 @smallexample
35089 -target-download
35090 @end smallexample
35091
35092 Loads the executable onto the remote target.
35093 It prints out an update message every half second, which includes the fields:
35094
35095 @table @samp
35096 @item section
35097 The name of the section.
35098 @item section-sent
35099 The size of what has been sent so far for that section.
35100 @item section-size
35101 The size of the section.
35102 @item total-sent
35103 The total size of what was sent so far (the current and the previous sections).
35104 @item total-size
35105 The size of the overall executable to download.
35106 @end table
35107
35108 @noindent
35109 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35110 @sc{gdb/mi} Output Syntax}).
35111
35112 In addition, it prints the name and size of the sections, as they are
35113 downloaded. These messages include the following fields:
35114
35115 @table @samp
35116 @item section
35117 The name of the section.
35118 @item section-size
35119 The size of the section.
35120 @item total-size
35121 The size of the overall executable to download.
35122 @end table
35123
35124 @noindent
35125 At the end, a summary is printed.
35126
35127 @subsubheading @value{GDBN} Command
35128
35129 The corresponding @value{GDBN} command is @samp{load}.
35130
35131 @subsubheading Example
35132
35133 Note: each status message appears on a single line. Here the messages
35134 have been broken down so that they can fit onto a page.
35135
35136 @smallexample
35137 (gdb)
35138 -target-download
35139 +download,@{section=".text",section-size="6668",total-size="9880"@}
35140 +download,@{section=".text",section-sent="512",section-size="6668",
35141 total-sent="512",total-size="9880"@}
35142 +download,@{section=".text",section-sent="1024",section-size="6668",
35143 total-sent="1024",total-size="9880"@}
35144 +download,@{section=".text",section-sent="1536",section-size="6668",
35145 total-sent="1536",total-size="9880"@}
35146 +download,@{section=".text",section-sent="2048",section-size="6668",
35147 total-sent="2048",total-size="9880"@}
35148 +download,@{section=".text",section-sent="2560",section-size="6668",
35149 total-sent="2560",total-size="9880"@}
35150 +download,@{section=".text",section-sent="3072",section-size="6668",
35151 total-sent="3072",total-size="9880"@}
35152 +download,@{section=".text",section-sent="3584",section-size="6668",
35153 total-sent="3584",total-size="9880"@}
35154 +download,@{section=".text",section-sent="4096",section-size="6668",
35155 total-sent="4096",total-size="9880"@}
35156 +download,@{section=".text",section-sent="4608",section-size="6668",
35157 total-sent="4608",total-size="9880"@}
35158 +download,@{section=".text",section-sent="5120",section-size="6668",
35159 total-sent="5120",total-size="9880"@}
35160 +download,@{section=".text",section-sent="5632",section-size="6668",
35161 total-sent="5632",total-size="9880"@}
35162 +download,@{section=".text",section-sent="6144",section-size="6668",
35163 total-sent="6144",total-size="9880"@}
35164 +download,@{section=".text",section-sent="6656",section-size="6668",
35165 total-sent="6656",total-size="9880"@}
35166 +download,@{section=".init",section-size="28",total-size="9880"@}
35167 +download,@{section=".fini",section-size="28",total-size="9880"@}
35168 +download,@{section=".data",section-size="3156",total-size="9880"@}
35169 +download,@{section=".data",section-sent="512",section-size="3156",
35170 total-sent="7236",total-size="9880"@}
35171 +download,@{section=".data",section-sent="1024",section-size="3156",
35172 total-sent="7748",total-size="9880"@}
35173 +download,@{section=".data",section-sent="1536",section-size="3156",
35174 total-sent="8260",total-size="9880"@}
35175 +download,@{section=".data",section-sent="2048",section-size="3156",
35176 total-sent="8772",total-size="9880"@}
35177 +download,@{section=".data",section-sent="2560",section-size="3156",
35178 total-sent="9284",total-size="9880"@}
35179 +download,@{section=".data",section-sent="3072",section-size="3156",
35180 total-sent="9796",total-size="9880"@}
35181 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35182 write-rate="429"
35183 (gdb)
35184 @end smallexample
35185
35186
35187 @ignore
35188 @subheading The @code{-target-exec-status} Command
35189 @findex -target-exec-status
35190
35191 @subsubheading Synopsis
35192
35193 @smallexample
35194 -target-exec-status
35195 @end smallexample
35196
35197 Provide information on the state of the target (whether it is running or
35198 not, for instance).
35199
35200 @subsubheading @value{GDBN} Command
35201
35202 There's no equivalent @value{GDBN} command.
35203
35204 @subsubheading Example
35205 N.A.
35206
35207
35208 @subheading The @code{-target-list-available-targets} Command
35209 @findex -target-list-available-targets
35210
35211 @subsubheading Synopsis
35212
35213 @smallexample
35214 -target-list-available-targets
35215 @end smallexample
35216
35217 List the possible targets to connect to.
35218
35219 @subsubheading @value{GDBN} Command
35220
35221 The corresponding @value{GDBN} command is @samp{help target}.
35222
35223 @subsubheading Example
35224 N.A.
35225
35226
35227 @subheading The @code{-target-list-current-targets} Command
35228 @findex -target-list-current-targets
35229
35230 @subsubheading Synopsis
35231
35232 @smallexample
35233 -target-list-current-targets
35234 @end smallexample
35235
35236 Describe the current target.
35237
35238 @subsubheading @value{GDBN} Command
35239
35240 The corresponding information is printed by @samp{info file} (among
35241 other things).
35242
35243 @subsubheading Example
35244 N.A.
35245
35246
35247 @subheading The @code{-target-list-parameters} Command
35248 @findex -target-list-parameters
35249
35250 @subsubheading Synopsis
35251
35252 @smallexample
35253 -target-list-parameters
35254 @end smallexample
35255
35256 @c ????
35257 @end ignore
35258
35259 @subsubheading @value{GDBN} Command
35260
35261 No equivalent.
35262
35263 @subsubheading Example
35264 N.A.
35265
35266 @subheading The @code{-target-flash-erase} Command
35267 @findex -target-flash-erase
35268
35269 @subsubheading Synopsis
35270
35271 @smallexample
35272 -target-flash-erase
35273 @end smallexample
35274
35275 Erases all known flash memory regions on the target.
35276
35277 The corresponding @value{GDBN} command is @samp{flash-erase}.
35278
35279 The output is a list of flash regions that have been erased, with starting
35280 addresses and memory region sizes.
35281
35282 @smallexample
35283 (gdb)
35284 -target-flash-erase
35285 ^done,erased-regions=@{address="0x0",size="0x40000"@}
35286 (gdb)
35287 @end smallexample
35288
35289 @subheading The @code{-target-select} Command
35290 @findex -target-select
35291
35292 @subsubheading Synopsis
35293
35294 @smallexample
35295 -target-select @var{type} @var{parameters @dots{}}
35296 @end smallexample
35297
35298 Connect @value{GDBN} to the remote target. This command takes two args:
35299
35300 @table @samp
35301 @item @var{type}
35302 The type of target, for instance @samp{remote}, etc.
35303 @item @var{parameters}
35304 Device names, host names and the like. @xref{Target Commands, ,
35305 Commands for Managing Targets}, for more details.
35306 @end table
35307
35308 The output is a connection notification, followed by the address at
35309 which the target program is, in the following form:
35310
35311 @smallexample
35312 ^connected,addr="@var{address}",func="@var{function name}",
35313 args=[@var{arg list}]
35314 @end smallexample
35315
35316 @subsubheading @value{GDBN} Command
35317
35318 The corresponding @value{GDBN} command is @samp{target}.
35319
35320 @subsubheading Example
35321
35322 @smallexample
35323 (gdb)
35324 -target-select remote /dev/ttya
35325 ^connected,addr="0xfe00a300",func="??",args=[]
35326 (gdb)
35327 @end smallexample
35328
35329 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35330 @node GDB/MI File Transfer Commands
35331 @section @sc{gdb/mi} File Transfer Commands
35332
35333
35334 @subheading The @code{-target-file-put} Command
35335 @findex -target-file-put
35336
35337 @subsubheading Synopsis
35338
35339 @smallexample
35340 -target-file-put @var{hostfile} @var{targetfile}
35341 @end smallexample
35342
35343 Copy file @var{hostfile} from the host system (the machine running
35344 @value{GDBN}) to @var{targetfile} on the target system.
35345
35346 @subsubheading @value{GDBN} Command
35347
35348 The corresponding @value{GDBN} command is @samp{remote put}.
35349
35350 @subsubheading Example
35351
35352 @smallexample
35353 (gdb)
35354 -target-file-put localfile remotefile
35355 ^done
35356 (gdb)
35357 @end smallexample
35358
35359
35360 @subheading The @code{-target-file-get} Command
35361 @findex -target-file-get
35362
35363 @subsubheading Synopsis
35364
35365 @smallexample
35366 -target-file-get @var{targetfile} @var{hostfile}
35367 @end smallexample
35368
35369 Copy file @var{targetfile} from the target system to @var{hostfile}
35370 on the host system.
35371
35372 @subsubheading @value{GDBN} Command
35373
35374 The corresponding @value{GDBN} command is @samp{remote get}.
35375
35376 @subsubheading Example
35377
35378 @smallexample
35379 (gdb)
35380 -target-file-get remotefile localfile
35381 ^done
35382 (gdb)
35383 @end smallexample
35384
35385
35386 @subheading The @code{-target-file-delete} Command
35387 @findex -target-file-delete
35388
35389 @subsubheading Synopsis
35390
35391 @smallexample
35392 -target-file-delete @var{targetfile}
35393 @end smallexample
35394
35395 Delete @var{targetfile} from the target system.
35396
35397 @subsubheading @value{GDBN} Command
35398
35399 The corresponding @value{GDBN} command is @samp{remote delete}.
35400
35401 @subsubheading Example
35402
35403 @smallexample
35404 (gdb)
35405 -target-file-delete remotefile
35406 ^done
35407 (gdb)
35408 @end smallexample
35409
35410
35411 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35412 @node GDB/MI Ada Exceptions Commands
35413 @section Ada Exceptions @sc{gdb/mi} Commands
35414
35415 @subheading The @code{-info-ada-exceptions} Command
35416 @findex -info-ada-exceptions
35417
35418 @subsubheading Synopsis
35419
35420 @smallexample
35421 -info-ada-exceptions [ @var{regexp}]
35422 @end smallexample
35423
35424 List all Ada exceptions defined within the program being debugged.
35425 With a regular expression @var{regexp}, only those exceptions whose
35426 names match @var{regexp} are listed.
35427
35428 @subsubheading @value{GDBN} Command
35429
35430 The corresponding @value{GDBN} command is @samp{info exceptions}.
35431
35432 @subsubheading Result
35433
35434 The result is a table of Ada exceptions. The following columns are
35435 defined for each exception:
35436
35437 @table @samp
35438 @item name
35439 The name of the exception.
35440
35441 @item address
35442 The address of the exception.
35443
35444 @end table
35445
35446 @subsubheading Example
35447
35448 @smallexample
35449 -info-ada-exceptions aint
35450 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35451 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35452 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35453 body=[@{name="constraint_error",address="0x0000000000613da0"@},
35454 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35455 @end smallexample
35456
35457 @subheading Catching Ada Exceptions
35458
35459 The commands describing how to ask @value{GDBN} to stop when a program
35460 raises an exception are described at @ref{Ada Exception GDB/MI
35461 Catchpoint Commands}.
35462
35463
35464 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35465 @node GDB/MI Support Commands
35466 @section @sc{gdb/mi} Support Commands
35467
35468 Since new commands and features get regularly added to @sc{gdb/mi},
35469 some commands are available to help front-ends query the debugger
35470 about support for these capabilities. Similarly, it is also possible
35471 to query @value{GDBN} about target support of certain features.
35472
35473 @subheading The @code{-info-gdb-mi-command} Command
35474 @cindex @code{-info-gdb-mi-command}
35475 @findex -info-gdb-mi-command
35476
35477 @subsubheading Synopsis
35478
35479 @smallexample
35480 -info-gdb-mi-command @var{cmd_name}
35481 @end smallexample
35482
35483 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35484
35485 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35486 is technically not part of the command name (@pxref{GDB/MI Input
35487 Syntax}), and thus should be omitted in @var{cmd_name}. However,
35488 for ease of use, this command also accepts the form with the leading
35489 dash.
35490
35491 @subsubheading @value{GDBN} Command
35492
35493 There is no corresponding @value{GDBN} command.
35494
35495 @subsubheading Result
35496
35497 The result is a tuple. There is currently only one field:
35498
35499 @table @samp
35500 @item exists
35501 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35502 @code{"false"} otherwise.
35503
35504 @end table
35505
35506 @subsubheading Example
35507
35508 Here is an example where the @sc{gdb/mi} command does not exist:
35509
35510 @smallexample
35511 -info-gdb-mi-command unsupported-command
35512 ^done,command=@{exists="false"@}
35513 @end smallexample
35514
35515 @noindent
35516 And here is an example where the @sc{gdb/mi} command is known
35517 to the debugger:
35518
35519 @smallexample
35520 -info-gdb-mi-command symbol-list-lines
35521 ^done,command=@{exists="true"@}
35522 @end smallexample
35523
35524 @subheading The @code{-list-features} Command
35525 @findex -list-features
35526 @cindex supported @sc{gdb/mi} features, list
35527
35528 Returns a list of particular features of the MI protocol that
35529 this version of gdb implements. A feature can be a command,
35530 or a new field in an output of some command, or even an
35531 important bugfix. While a frontend can sometimes detect presence
35532 of a feature at runtime, it is easier to perform detection at debugger
35533 startup.
35534
35535 The command returns a list of strings, with each string naming an
35536 available feature. Each returned string is just a name, it does not
35537 have any internal structure. The list of possible feature names
35538 is given below.
35539
35540 Example output:
35541
35542 @smallexample
35543 (gdb) -list-features
35544 ^done,result=["feature1","feature2"]
35545 @end smallexample
35546
35547 The current list of features is:
35548
35549 @ftable @samp
35550 @item frozen-varobjs
35551 Indicates support for the @code{-var-set-frozen} command, as well
35552 as possible presence of the @code{frozen} field in the output
35553 of @code{-varobj-create}.
35554 @item pending-breakpoints
35555 Indicates support for the @option{-f} option to the @code{-break-insert}
35556 command.
35557 @item python
35558 Indicates Python scripting support, Python-based
35559 pretty-printing commands, and possible presence of the
35560 @samp{display_hint} field in the output of @code{-var-list-children}
35561 @item thread-info
35562 Indicates support for the @code{-thread-info} command.
35563 @item data-read-memory-bytes
35564 Indicates support for the @code{-data-read-memory-bytes} and the
35565 @code{-data-write-memory-bytes} commands.
35566 @item breakpoint-notifications
35567 Indicates that changes to breakpoints and breakpoints created via the
35568 CLI will be announced via async records.
35569 @item ada-task-info
35570 Indicates support for the @code{-ada-task-info} command.
35571 @item language-option
35572 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35573 option (@pxref{Context management}).
35574 @item info-gdb-mi-command
35575 Indicates support for the @code{-info-gdb-mi-command} command.
35576 @item undefined-command-error-code
35577 Indicates support for the "undefined-command" error code in error result
35578 records, produced when trying to execute an undefined @sc{gdb/mi} command
35579 (@pxref{GDB/MI Result Records}).
35580 @item exec-run-start-option
35581 Indicates that the @code{-exec-run} command supports the @option{--start}
35582 option (@pxref{GDB/MI Program Execution}).
35583 @item data-disassemble-a-option
35584 Indicates that the @code{-data-disassemble} command supports the @option{-a}
35585 option (@pxref{GDB/MI Data Manipulation}).
35586 @end ftable
35587
35588 @subheading The @code{-list-target-features} Command
35589 @findex -list-target-features
35590
35591 Returns a list of particular features that are supported by the
35592 target. Those features affect the permitted MI commands, but
35593 unlike the features reported by the @code{-list-features} command, the
35594 features depend on which target GDB is using at the moment. Whenever
35595 a target can change, due to commands such as @code{-target-select},
35596 @code{-target-attach} or @code{-exec-run}, the list of target features
35597 may change, and the frontend should obtain it again.
35598 Example output:
35599
35600 @smallexample
35601 (gdb) -list-target-features
35602 ^done,result=["async"]
35603 @end smallexample
35604
35605 The current list of features is:
35606
35607 @table @samp
35608 @item async
35609 Indicates that the target is capable of asynchronous command
35610 execution, which means that @value{GDBN} will accept further commands
35611 while the target is running.
35612
35613 @item reverse
35614 Indicates that the target is capable of reverse execution.
35615 @xref{Reverse Execution}, for more information.
35616
35617 @end table
35618
35619 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35620 @node GDB/MI Miscellaneous Commands
35621 @section Miscellaneous @sc{gdb/mi} Commands
35622
35623 @c @subheading -gdb-complete
35624
35625 @subheading The @code{-gdb-exit} Command
35626 @findex -gdb-exit
35627
35628 @subsubheading Synopsis
35629
35630 @smallexample
35631 -gdb-exit
35632 @end smallexample
35633
35634 Exit @value{GDBN} immediately.
35635
35636 @subsubheading @value{GDBN} Command
35637
35638 Approximately corresponds to @samp{quit}.
35639
35640 @subsubheading Example
35641
35642 @smallexample
35643 (gdb)
35644 -gdb-exit
35645 ^exit
35646 @end smallexample
35647
35648
35649 @ignore
35650 @subheading The @code{-exec-abort} Command
35651 @findex -exec-abort
35652
35653 @subsubheading Synopsis
35654
35655 @smallexample
35656 -exec-abort
35657 @end smallexample
35658
35659 Kill the inferior running program.
35660
35661 @subsubheading @value{GDBN} Command
35662
35663 The corresponding @value{GDBN} command is @samp{kill}.
35664
35665 @subsubheading Example
35666 N.A.
35667 @end ignore
35668
35669
35670 @subheading The @code{-gdb-set} Command
35671 @findex -gdb-set
35672
35673 @subsubheading Synopsis
35674
35675 @smallexample
35676 -gdb-set
35677 @end smallexample
35678
35679 Set an internal @value{GDBN} variable.
35680 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35681
35682 @subsubheading @value{GDBN} Command
35683
35684 The corresponding @value{GDBN} command is @samp{set}.
35685
35686 @subsubheading Example
35687
35688 @smallexample
35689 (gdb)
35690 -gdb-set $foo=3
35691 ^done
35692 (gdb)
35693 @end smallexample
35694
35695
35696 @subheading The @code{-gdb-show} Command
35697 @findex -gdb-show
35698
35699 @subsubheading Synopsis
35700
35701 @smallexample
35702 -gdb-show
35703 @end smallexample
35704
35705 Show the current value of a @value{GDBN} variable.
35706
35707 @subsubheading @value{GDBN} Command
35708
35709 The corresponding @value{GDBN} command is @samp{show}.
35710
35711 @subsubheading Example
35712
35713 @smallexample
35714 (gdb)
35715 -gdb-show annotate
35716 ^done,value="0"
35717 (gdb)
35718 @end smallexample
35719
35720 @c @subheading -gdb-source
35721
35722
35723 @subheading The @code{-gdb-version} Command
35724 @findex -gdb-version
35725
35726 @subsubheading Synopsis
35727
35728 @smallexample
35729 -gdb-version
35730 @end smallexample
35731
35732 Show version information for @value{GDBN}. Used mostly in testing.
35733
35734 @subsubheading @value{GDBN} Command
35735
35736 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35737 default shows this information when you start an interactive session.
35738
35739 @subsubheading Example
35740
35741 @c This example modifies the actual output from GDB to avoid overfull
35742 @c box in TeX.
35743 @smallexample
35744 (gdb)
35745 -gdb-version
35746 ~GNU gdb 5.2.1
35747 ~Copyright 2000 Free Software Foundation, Inc.
35748 ~GDB is free software, covered by the GNU General Public License, and
35749 ~you are welcome to change it and/or distribute copies of it under
35750 ~ certain conditions.
35751 ~Type "show copying" to see the conditions.
35752 ~There is absolutely no warranty for GDB. Type "show warranty" for
35753 ~ details.
35754 ~This GDB was configured as
35755 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35756 ^done
35757 (gdb)
35758 @end smallexample
35759
35760 @subheading The @code{-list-thread-groups} Command
35761 @findex -list-thread-groups
35762
35763 @subheading Synopsis
35764
35765 @smallexample
35766 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
35767 @end smallexample
35768
35769 Lists thread groups (@pxref{Thread groups}). When a single thread
35770 group is passed as the argument, lists the children of that group.
35771 When several thread group are passed, lists information about those
35772 thread groups. Without any parameters, lists information about all
35773 top-level thread groups.
35774
35775 Normally, thread groups that are being debugged are reported.
35776 With the @samp{--available} option, @value{GDBN} reports thread groups
35777 available on the target.
35778
35779 The output of this command may have either a @samp{threads} result or
35780 a @samp{groups} result. The @samp{thread} result has a list of tuples
35781 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35782 Information}). The @samp{groups} result has a list of tuples as value,
35783 each tuple describing a thread group. If top-level groups are
35784 requested (that is, no parameter is passed), or when several groups
35785 are passed, the output always has a @samp{groups} result. The format
35786 of the @samp{group} result is described below.
35787
35788 To reduce the number of roundtrips it's possible to list thread groups
35789 together with their children, by passing the @samp{--recurse} option
35790 and the recursion depth. Presently, only recursion depth of 1 is
35791 permitted. If this option is present, then every reported thread group
35792 will also include its children, either as @samp{group} or
35793 @samp{threads} field.
35794
35795 In general, any combination of option and parameters is permitted, with
35796 the following caveats:
35797
35798 @itemize @bullet
35799 @item
35800 When a single thread group is passed, the output will typically
35801 be the @samp{threads} result. Because threads may not contain
35802 anything, the @samp{recurse} option will be ignored.
35803
35804 @item
35805 When the @samp{--available} option is passed, limited information may
35806 be available. In particular, the list of threads of a process might
35807 be inaccessible. Further, specifying specific thread groups might
35808 not give any performance advantage over listing all thread groups.
35809 The frontend should assume that @samp{-list-thread-groups --available}
35810 is always an expensive operation and cache the results.
35811
35812 @end itemize
35813
35814 The @samp{groups} result is a list of tuples, where each tuple may
35815 have the following fields:
35816
35817 @table @code
35818 @item id
35819 Identifier of the thread group. This field is always present.
35820 The identifier is an opaque string; frontends should not try to
35821 convert it to an integer, even though it might look like one.
35822
35823 @item type
35824 The type of the thread group. At present, only @samp{process} is a
35825 valid type.
35826
35827 @item pid
35828 The target-specific process identifier. This field is only present
35829 for thread groups of type @samp{process} and only if the process exists.
35830
35831 @item exit-code
35832 The exit code of this group's last exited thread, formatted in octal.
35833 This field is only present for thread groups of type @samp{process} and
35834 only if the process is not running.
35835
35836 @item num_children
35837 The number of children this thread group has. This field may be
35838 absent for an available thread group.
35839
35840 @item threads
35841 This field has a list of tuples as value, each tuple describing a
35842 thread. It may be present if the @samp{--recurse} option is
35843 specified, and it's actually possible to obtain the threads.
35844
35845 @item cores
35846 This field is a list of integers, each identifying a core that one
35847 thread of the group is running on. This field may be absent if
35848 such information is not available.
35849
35850 @item executable
35851 The name of the executable file that corresponds to this thread group.
35852 The field is only present for thread groups of type @samp{process},
35853 and only if there is a corresponding executable file.
35854
35855 @end table
35856
35857 @subheading Example
35858
35859 @smallexample
35860 @value{GDBP}
35861 -list-thread-groups
35862 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
35863 -list-thread-groups 17
35864 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
35865 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
35866 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
35867 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
35868 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
35869 -list-thread-groups --available
35870 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
35871 -list-thread-groups --available --recurse 1
35872 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35873 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35874 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
35875 -list-thread-groups --available --recurse 1 17 18
35876 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35877 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35878 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
35879 @end smallexample
35880
35881 @subheading The @code{-info-os} Command
35882 @findex -info-os
35883
35884 @subsubheading Synopsis
35885
35886 @smallexample
35887 -info-os [ @var{type} ]
35888 @end smallexample
35889
35890 If no argument is supplied, the command returns a table of available
35891 operating-system-specific information types. If one of these types is
35892 supplied as an argument @var{type}, then the command returns a table
35893 of data of that type.
35894
35895 The types of information available depend on the target operating
35896 system.
35897
35898 @subsubheading @value{GDBN} Command
35899
35900 The corresponding @value{GDBN} command is @samp{info os}.
35901
35902 @subsubheading Example
35903
35904 When run on a @sc{gnu}/Linux system, the output will look something
35905 like this:
35906
35907 @smallexample
35908 @value{GDBP}
35909 -info-os
35910 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
35911 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
35912 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
35913 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
35914 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
35915 col2="CPUs"@},
35916 item=@{col0="files",col1="Listing of all file descriptors",
35917 col2="File descriptors"@},
35918 item=@{col0="modules",col1="Listing of all loaded kernel modules",
35919 col2="Kernel modules"@},
35920 item=@{col0="msg",col1="Listing of all message queues",
35921 col2="Message queues"@},
35922 item=@{col0="processes",col1="Listing of all processes",
35923 col2="Processes"@},
35924 item=@{col0="procgroups",col1="Listing of all process groups",
35925 col2="Process groups"@},
35926 item=@{col0="semaphores",col1="Listing of all semaphores",
35927 col2="Semaphores"@},
35928 item=@{col0="shm",col1="Listing of all shared-memory regions",
35929 col2="Shared-memory regions"@},
35930 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
35931 col2="Sockets"@},
35932 item=@{col0="threads",col1="Listing of all threads",
35933 col2="Threads"@}]
35934 @value{GDBP}
35935 -info-os processes
35936 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
35937 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
35938 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
35939 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
35940 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
35941 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
35942 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
35943 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
35944 ...
35945 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
35946 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
35947 (gdb)
35948 @end smallexample
35949
35950 (Note that the MI output here includes a @code{"Title"} column that
35951 does not appear in command-line @code{info os}; this column is useful
35952 for MI clients that want to enumerate the types of data, such as in a
35953 popup menu, but is needless clutter on the command line, and
35954 @code{info os} omits it.)
35955
35956 @subheading The @code{-add-inferior} Command
35957 @findex -add-inferior
35958
35959 @subheading Synopsis
35960
35961 @smallexample
35962 -add-inferior
35963 @end smallexample
35964
35965 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
35966 inferior is not associated with any executable. Such association may
35967 be established with the @samp{-file-exec-and-symbols} command
35968 (@pxref{GDB/MI File Commands}). The command response has a single
35969 field, @samp{inferior}, whose value is the identifier of the
35970 thread group corresponding to the new inferior.
35971
35972 @subheading Example
35973
35974 @smallexample
35975 @value{GDBP}
35976 -add-inferior
35977 ^done,inferior="i3"
35978 @end smallexample
35979
35980 @subheading The @code{-interpreter-exec} Command
35981 @findex -interpreter-exec
35982
35983 @subheading Synopsis
35984
35985 @smallexample
35986 -interpreter-exec @var{interpreter} @var{command}
35987 @end smallexample
35988 @anchor{-interpreter-exec}
35989
35990 Execute the specified @var{command} in the given @var{interpreter}.
35991
35992 @subheading @value{GDBN} Command
35993
35994 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
35995
35996 @subheading Example
35997
35998 @smallexample
35999 (gdb)
36000 -interpreter-exec console "break main"
36001 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36002 &"During symbol reading, bad structure-type format.\n"
36003 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36004 ^done
36005 (gdb)
36006 @end smallexample
36007
36008 @subheading The @code{-inferior-tty-set} Command
36009 @findex -inferior-tty-set
36010
36011 @subheading Synopsis
36012
36013 @smallexample
36014 -inferior-tty-set /dev/pts/1
36015 @end smallexample
36016
36017 Set terminal for future runs of the program being debugged.
36018
36019 @subheading @value{GDBN} Command
36020
36021 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36022
36023 @subheading Example
36024
36025 @smallexample
36026 (gdb)
36027 -inferior-tty-set /dev/pts/1
36028 ^done
36029 (gdb)
36030 @end smallexample
36031
36032 @subheading The @code{-inferior-tty-show} Command
36033 @findex -inferior-tty-show
36034
36035 @subheading Synopsis
36036
36037 @smallexample
36038 -inferior-tty-show
36039 @end smallexample
36040
36041 Show terminal for future runs of program being debugged.
36042
36043 @subheading @value{GDBN} Command
36044
36045 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36046
36047 @subheading Example
36048
36049 @smallexample
36050 (gdb)
36051 -inferior-tty-set /dev/pts/1
36052 ^done
36053 (gdb)
36054 -inferior-tty-show
36055 ^done,inferior_tty_terminal="/dev/pts/1"
36056 (gdb)
36057 @end smallexample
36058
36059 @subheading The @code{-enable-timings} Command
36060 @findex -enable-timings
36061
36062 @subheading Synopsis
36063
36064 @smallexample
36065 -enable-timings [yes | no]
36066 @end smallexample
36067
36068 Toggle the printing of the wallclock, user and system times for an MI
36069 command as a field in its output. This command is to help frontend
36070 developers optimize the performance of their code. No argument is
36071 equivalent to @samp{yes}.
36072
36073 @subheading @value{GDBN} Command
36074
36075 No equivalent.
36076
36077 @subheading Example
36078
36079 @smallexample
36080 (gdb)
36081 -enable-timings
36082 ^done
36083 (gdb)
36084 -break-insert main
36085 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36086 addr="0x080484ed",func="main",file="myprog.c",
36087 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36088 times="0"@},
36089 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36090 (gdb)
36091 -enable-timings no
36092 ^done
36093 (gdb)
36094 -exec-run
36095 ^running
36096 (gdb)
36097 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36098 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36099 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36100 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36101 (gdb)
36102 @end smallexample
36103
36104 @subheading The @code{-complete} Command
36105 @findex -complete
36106
36107 @subheading Synopsis
36108
36109 @smallexample
36110 -complete @var{command}
36111 @end smallexample
36112
36113 Show a list of completions for partially typed CLI @var{command}.
36114
36115 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36116 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36117 because @value{GDBN} is used remotely via a SSH connection.
36118
36119 @subheading Result
36120
36121 The result consists of two or three fields:
36122
36123 @table @samp
36124 @item completion
36125 This field contains the completed @var{command}. If @var{command}
36126 has no known completions, this field is omitted.
36127
36128 @item matches
36129 This field contains a (possibly empty) array of matches. It is always present.
36130
36131 @item max_completions_reached
36132 This field contains @code{1} if number of known completions is above
36133 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36134 @code{0}. It is always present.
36135
36136 @end table
36137
36138 @subheading @value{GDBN} Command
36139
36140 The corresponding @value{GDBN} command is @samp{complete}.
36141
36142 @subheading Example
36143
36144 @smallexample
36145 (gdb)
36146 -complete br
36147 ^done,completion="break",
36148 matches=["break","break-range"],
36149 max_completions_reached="0"
36150 (gdb)
36151 -complete "b ma"
36152 ^done,completion="b ma",
36153 matches=["b madvise","b main"],max_completions_reached="0"
36154 (gdb)
36155 -complete "b push_b"
36156 ^done,completion="b push_back(",
36157 matches=[
36158 "b A::push_back(void*)",
36159 "b std::string::push_back(char)",
36160 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36161 max_completions_reached="0"
36162 (gdb)
36163 -complete "nonexist"
36164 ^done,matches=[],max_completions_reached="0"
36165 (gdb)
36166
36167 @end smallexample
36168
36169 @node Annotations
36170 @chapter @value{GDBN} Annotations
36171
36172 This chapter describes annotations in @value{GDBN}. Annotations were
36173 designed to interface @value{GDBN} to graphical user interfaces or other
36174 similar programs which want to interact with @value{GDBN} at a
36175 relatively high level.
36176
36177 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36178 (@pxref{GDB/MI}).
36179
36180 @ignore
36181 This is Edition @value{EDITION}, @value{DATE}.
36182 @end ignore
36183
36184 @menu
36185 * Annotations Overview:: What annotations are; the general syntax.
36186 * Server Prefix:: Issuing a command without affecting user state.
36187 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36188 * Errors:: Annotations for error messages.
36189 * Invalidation:: Some annotations describe things now invalid.
36190 * Annotations for Running::
36191 Whether the program is running, how it stopped, etc.
36192 * Source Annotations:: Annotations describing source code.
36193 @end menu
36194
36195 @node Annotations Overview
36196 @section What is an Annotation?
36197 @cindex annotations
36198
36199 Annotations start with a newline character, two @samp{control-z}
36200 characters, and the name of the annotation. If there is no additional
36201 information associated with this annotation, the name of the annotation
36202 is followed immediately by a newline. If there is additional
36203 information, the name of the annotation is followed by a space, the
36204 additional information, and a newline. The additional information
36205 cannot contain newline characters.
36206
36207 Any output not beginning with a newline and two @samp{control-z}
36208 characters denotes literal output from @value{GDBN}. Currently there is
36209 no need for @value{GDBN} to output a newline followed by two
36210 @samp{control-z} characters, but if there was such a need, the
36211 annotations could be extended with an @samp{escape} annotation which
36212 means those three characters as output.
36213
36214 The annotation @var{level}, which is specified using the
36215 @option{--annotate} command line option (@pxref{Mode Options}), controls
36216 how much information @value{GDBN} prints together with its prompt,
36217 values of expressions, source lines, and other types of output. Level 0
36218 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36219 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36220 for programs that control @value{GDBN}, and level 2 annotations have
36221 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36222 Interface, annotate, GDB's Obsolete Annotations}).
36223
36224 @table @code
36225 @kindex set annotate
36226 @item set annotate @var{level}
36227 The @value{GDBN} command @code{set annotate} sets the level of
36228 annotations to the specified @var{level}.
36229
36230 @item show annotate
36231 @kindex show annotate
36232 Show the current annotation level.
36233 @end table
36234
36235 This chapter describes level 3 annotations.
36236
36237 A simple example of starting up @value{GDBN} with annotations is:
36238
36239 @smallexample
36240 $ @kbd{gdb --annotate=3}
36241 GNU gdb 6.0
36242 Copyright 2003 Free Software Foundation, Inc.
36243 GDB is free software, covered by the GNU General Public License,
36244 and you are welcome to change it and/or distribute copies of it
36245 under certain conditions.
36246 Type "show copying" to see the conditions.
36247 There is absolutely no warranty for GDB. Type "show warranty"
36248 for details.
36249 This GDB was configured as "i386-pc-linux-gnu"
36250
36251 ^Z^Zpre-prompt
36252 (@value{GDBP})
36253 ^Z^Zprompt
36254 @kbd{quit}
36255
36256 ^Z^Zpost-prompt
36257 $
36258 @end smallexample
36259
36260 Here @samp{quit} is input to @value{GDBN}; the rest is output from
36261 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36262 denotes a @samp{control-z} character) are annotations; the rest is
36263 output from @value{GDBN}.
36264
36265 @node Server Prefix
36266 @section The Server Prefix
36267 @cindex server prefix
36268
36269 If you prefix a command with @samp{server } then it will not affect
36270 the command history, nor will it affect @value{GDBN}'s notion of which
36271 command to repeat if @key{RET} is pressed on a line by itself. This
36272 means that commands can be run behind a user's back by a front-end in
36273 a transparent manner.
36274
36275 The @code{server } prefix does not affect the recording of values into
36276 the value history; to print a value without recording it into the
36277 value history, use the @code{output} command instead of the
36278 @code{print} command.
36279
36280 Using this prefix also disables confirmation requests
36281 (@pxref{confirmation requests}).
36282
36283 @node Prompting
36284 @section Annotation for @value{GDBN} Input
36285
36286 @cindex annotations for prompts
36287 When @value{GDBN} prompts for input, it annotates this fact so it is possible
36288 to know when to send output, when the output from a given command is
36289 over, etc.
36290
36291 Different kinds of input each have a different @dfn{input type}. Each
36292 input type has three annotations: a @code{pre-} annotation, which
36293 denotes the beginning of any prompt which is being output, a plain
36294 annotation, which denotes the end of the prompt, and then a @code{post-}
36295 annotation which denotes the end of any echo which may (or may not) be
36296 associated with the input. For example, the @code{prompt} input type
36297 features the following annotations:
36298
36299 @smallexample
36300 ^Z^Zpre-prompt
36301 ^Z^Zprompt
36302 ^Z^Zpost-prompt
36303 @end smallexample
36304
36305 The input types are
36306
36307 @table @code
36308 @findex pre-prompt annotation
36309 @findex prompt annotation
36310 @findex post-prompt annotation
36311 @item prompt
36312 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36313
36314 @findex pre-commands annotation
36315 @findex commands annotation
36316 @findex post-commands annotation
36317 @item commands
36318 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36319 command. The annotations are repeated for each command which is input.
36320
36321 @findex pre-overload-choice annotation
36322 @findex overload-choice annotation
36323 @findex post-overload-choice annotation
36324 @item overload-choice
36325 When @value{GDBN} wants the user to select between various overloaded functions.
36326
36327 @findex pre-query annotation
36328 @findex query annotation
36329 @findex post-query annotation
36330 @item query
36331 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36332
36333 @findex pre-prompt-for-continue annotation
36334 @findex prompt-for-continue annotation
36335 @findex post-prompt-for-continue annotation
36336 @item prompt-for-continue
36337 When @value{GDBN} is asking the user to press return to continue. Note: Don't
36338 expect this to work well; instead use @code{set height 0} to disable
36339 prompting. This is because the counting of lines is buggy in the
36340 presence of annotations.
36341 @end table
36342
36343 @node Errors
36344 @section Errors
36345 @cindex annotations for errors, warnings and interrupts
36346
36347 @findex quit annotation
36348 @smallexample
36349 ^Z^Zquit
36350 @end smallexample
36351
36352 This annotation occurs right before @value{GDBN} responds to an interrupt.
36353
36354 @findex error annotation
36355 @smallexample
36356 ^Z^Zerror
36357 @end smallexample
36358
36359 This annotation occurs right before @value{GDBN} responds to an error.
36360
36361 Quit and error annotations indicate that any annotations which @value{GDBN} was
36362 in the middle of may end abruptly. For example, if a
36363 @code{value-history-begin} annotation is followed by a @code{error}, one
36364 cannot expect to receive the matching @code{value-history-end}. One
36365 cannot expect not to receive it either, however; an error annotation
36366 does not necessarily mean that @value{GDBN} is immediately returning all the way
36367 to the top level.
36368
36369 @findex error-begin annotation
36370 A quit or error annotation may be preceded by
36371
36372 @smallexample
36373 ^Z^Zerror-begin
36374 @end smallexample
36375
36376 Any output between that and the quit or error annotation is the error
36377 message.
36378
36379 Warning messages are not yet annotated.
36380 @c If we want to change that, need to fix warning(), type_error(),
36381 @c range_error(), and possibly other places.
36382
36383 @node Invalidation
36384 @section Invalidation Notices
36385
36386 @cindex annotations for invalidation messages
36387 The following annotations say that certain pieces of state may have
36388 changed.
36389
36390 @table @code
36391 @findex frames-invalid annotation
36392 @item ^Z^Zframes-invalid
36393
36394 The frames (for example, output from the @code{backtrace} command) may
36395 have changed.
36396
36397 @findex breakpoints-invalid annotation
36398 @item ^Z^Zbreakpoints-invalid
36399
36400 The breakpoints may have changed. For example, the user just added or
36401 deleted a breakpoint.
36402 @end table
36403
36404 @node Annotations for Running
36405 @section Running the Program
36406 @cindex annotations for running programs
36407
36408 @findex starting annotation
36409 @findex stopping annotation
36410 When the program starts executing due to a @value{GDBN} command such as
36411 @code{step} or @code{continue},
36412
36413 @smallexample
36414 ^Z^Zstarting
36415 @end smallexample
36416
36417 is output. When the program stops,
36418
36419 @smallexample
36420 ^Z^Zstopped
36421 @end smallexample
36422
36423 is output. Before the @code{stopped} annotation, a variety of
36424 annotations describe how the program stopped.
36425
36426 @table @code
36427 @findex exited annotation
36428 @item ^Z^Zexited @var{exit-status}
36429 The program exited, and @var{exit-status} is the exit status (zero for
36430 successful exit, otherwise nonzero).
36431
36432 @findex signalled annotation
36433 @findex signal-name annotation
36434 @findex signal-name-end annotation
36435 @findex signal-string annotation
36436 @findex signal-string-end annotation
36437 @item ^Z^Zsignalled
36438 The program exited with a signal. After the @code{^Z^Zsignalled}, the
36439 annotation continues:
36440
36441 @smallexample
36442 @var{intro-text}
36443 ^Z^Zsignal-name
36444 @var{name}
36445 ^Z^Zsignal-name-end
36446 @var{middle-text}
36447 ^Z^Zsignal-string
36448 @var{string}
36449 ^Z^Zsignal-string-end
36450 @var{end-text}
36451 @end smallexample
36452
36453 @noindent
36454 where @var{name} is the name of the signal, such as @code{SIGILL} or
36455 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
36456 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
36457 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36458 user's benefit and have no particular format.
36459
36460 @findex signal annotation
36461 @item ^Z^Zsignal
36462 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36463 just saying that the program received the signal, not that it was
36464 terminated with it.
36465
36466 @findex breakpoint annotation
36467 @item ^Z^Zbreakpoint @var{number}
36468 The program hit breakpoint number @var{number}.
36469
36470 @findex watchpoint annotation
36471 @item ^Z^Zwatchpoint @var{number}
36472 The program hit watchpoint number @var{number}.
36473 @end table
36474
36475 @node Source Annotations
36476 @section Displaying Source
36477 @cindex annotations for source display
36478
36479 @findex source annotation
36480 The following annotation is used instead of displaying source code:
36481
36482 @smallexample
36483 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36484 @end smallexample
36485
36486 where @var{filename} is an absolute file name indicating which source
36487 file, @var{line} is the line number within that file (where 1 is the
36488 first line in the file), @var{character} is the character position
36489 within the file (where 0 is the first character in the file) (for most
36490 debug formats this will necessarily point to the beginning of a line),
36491 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
36492 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36493 @var{addr} is the address in the target program associated with the
36494 source which is being displayed. The @var{addr} is in the form @samp{0x}
36495 followed by one or more lowercase hex digits (note that this does not
36496 depend on the language).
36497
36498 @node JIT Interface
36499 @chapter JIT Compilation Interface
36500 @cindex just-in-time compilation
36501 @cindex JIT compilation interface
36502
36503 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36504 interface. A JIT compiler is a program or library that generates native
36505 executable code at runtime and executes it, usually in order to achieve good
36506 performance while maintaining platform independence.
36507
36508 Programs that use JIT compilation are normally difficult to debug because
36509 portions of their code are generated at runtime, instead of being loaded from
36510 object files, which is where @value{GDBN} normally finds the program's symbols
36511 and debug information. In order to debug programs that use JIT compilation,
36512 @value{GDBN} has an interface that allows the program to register in-memory
36513 symbol files with @value{GDBN} at runtime.
36514
36515 If you are using @value{GDBN} to debug a program that uses this interface, then
36516 it should work transparently so long as you have not stripped the binary. If
36517 you are developing a JIT compiler, then the interface is documented in the rest
36518 of this chapter. At this time, the only known client of this interface is the
36519 LLVM JIT.
36520
36521 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36522 JIT compiler communicates with @value{GDBN} by writing data into a global
36523 variable and calling a function at a well-known symbol. When @value{GDBN}
36524 attaches, it reads a linked list of symbol files from the global variable to
36525 find existing code, and puts a breakpoint in the function so that it can find
36526 out about additional code.
36527
36528 @menu
36529 * Declarations:: Relevant C struct declarations
36530 * Registering Code:: Steps to register code
36531 * Unregistering Code:: Steps to unregister code
36532 * Custom Debug Info:: Emit debug information in a custom format
36533 @end menu
36534
36535 @node Declarations
36536 @section JIT Declarations
36537
36538 These are the relevant struct declarations that a C program should include to
36539 implement the interface:
36540
36541 @smallexample
36542 typedef enum
36543 @{
36544 JIT_NOACTION = 0,
36545 JIT_REGISTER_FN,
36546 JIT_UNREGISTER_FN
36547 @} jit_actions_t;
36548
36549 struct jit_code_entry
36550 @{
36551 struct jit_code_entry *next_entry;
36552 struct jit_code_entry *prev_entry;
36553 const char *symfile_addr;
36554 uint64_t symfile_size;
36555 @};
36556
36557 struct jit_descriptor
36558 @{
36559 uint32_t version;
36560 /* This type should be jit_actions_t, but we use uint32_t
36561 to be explicit about the bitwidth. */
36562 uint32_t action_flag;
36563 struct jit_code_entry *relevant_entry;
36564 struct jit_code_entry *first_entry;
36565 @};
36566
36567 /* GDB puts a breakpoint in this function. */
36568 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36569
36570 /* Make sure to specify the version statically, because the
36571 debugger may check the version before we can set it. */
36572 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36573 @end smallexample
36574
36575 If the JIT is multi-threaded, then it is important that the JIT synchronize any
36576 modifications to this global data properly, which can easily be done by putting
36577 a global mutex around modifications to these structures.
36578
36579 @node Registering Code
36580 @section Registering Code
36581
36582 To register code with @value{GDBN}, the JIT should follow this protocol:
36583
36584 @itemize @bullet
36585 @item
36586 Generate an object file in memory with symbols and other desired debug
36587 information. The file must include the virtual addresses of the sections.
36588
36589 @item
36590 Create a code entry for the file, which gives the start and size of the symbol
36591 file.
36592
36593 @item
36594 Add it to the linked list in the JIT descriptor.
36595
36596 @item
36597 Point the relevant_entry field of the descriptor at the entry.
36598
36599 @item
36600 Set @code{action_flag} to @code{JIT_REGISTER} and call
36601 @code{__jit_debug_register_code}.
36602 @end itemize
36603
36604 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36605 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
36606 new code. However, the linked list must still be maintained in order to allow
36607 @value{GDBN} to attach to a running process and still find the symbol files.
36608
36609 @node Unregistering Code
36610 @section Unregistering Code
36611
36612 If code is freed, then the JIT should use the following protocol:
36613
36614 @itemize @bullet
36615 @item
36616 Remove the code entry corresponding to the code from the linked list.
36617
36618 @item
36619 Point the @code{relevant_entry} field of the descriptor at the code entry.
36620
36621 @item
36622 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36623 @code{__jit_debug_register_code}.
36624 @end itemize
36625
36626 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36627 and the JIT will leak the memory used for the associated symbol files.
36628
36629 @node Custom Debug Info
36630 @section Custom Debug Info
36631 @cindex custom JIT debug info
36632 @cindex JIT debug info reader
36633
36634 Generating debug information in platform-native file formats (like ELF
36635 or COFF) may be an overkill for JIT compilers; especially if all the
36636 debug info is used for is displaying a meaningful backtrace. The
36637 issue can be resolved by having the JIT writers decide on a debug info
36638 format and also provide a reader that parses the debug info generated
36639 by the JIT compiler. This section gives a brief overview on writing
36640 such a parser. More specific details can be found in the source file
36641 @file{gdb/jit-reader.in}, which is also installed as a header at
36642 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36643
36644 The reader is implemented as a shared object (so this functionality is
36645 not available on platforms which don't allow loading shared objects at
36646 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36647 @code{jit-reader-unload} are provided, to be used to load and unload
36648 the readers from a preconfigured directory. Once loaded, the shared
36649 object is used the parse the debug information emitted by the JIT
36650 compiler.
36651
36652 @menu
36653 * Using JIT Debug Info Readers:: How to use supplied readers correctly
36654 * Writing JIT Debug Info Readers:: Creating a debug-info reader
36655 @end menu
36656
36657 @node Using JIT Debug Info Readers
36658 @subsection Using JIT Debug Info Readers
36659 @kindex jit-reader-load
36660 @kindex jit-reader-unload
36661
36662 Readers can be loaded and unloaded using the @code{jit-reader-load}
36663 and @code{jit-reader-unload} commands.
36664
36665 @table @code
36666 @item jit-reader-load @var{reader}
36667 Load the JIT reader named @var{reader}, which is a shared
36668 object specified as either an absolute or a relative file name. In
36669 the latter case, @value{GDBN} will try to load the reader from a
36670 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36671 system (here @var{libdir} is the system library directory, often
36672 @file{/usr/local/lib}).
36673
36674 Only one reader can be active at a time; trying to load a second
36675 reader when one is already loaded will result in @value{GDBN}
36676 reporting an error. A new JIT reader can be loaded by first unloading
36677 the current one using @code{jit-reader-unload} and then invoking
36678 @code{jit-reader-load}.
36679
36680 @item jit-reader-unload
36681 Unload the currently loaded JIT reader.
36682
36683 @end table
36684
36685 @node Writing JIT Debug Info Readers
36686 @subsection Writing JIT Debug Info Readers
36687 @cindex writing JIT debug info readers
36688
36689 As mentioned, a reader is essentially a shared object conforming to a
36690 certain ABI. This ABI is described in @file{jit-reader.h}.
36691
36692 @file{jit-reader.h} defines the structures, macros and functions
36693 required to write a reader. It is installed (along with
36694 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36695 the system include directory.
36696
36697 Readers need to be released under a GPL compatible license. A reader
36698 can be declared as released under such a license by placing the macro
36699 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36700
36701 The entry point for readers is the symbol @code{gdb_init_reader},
36702 which is expected to be a function with the prototype
36703
36704 @findex gdb_init_reader
36705 @smallexample
36706 extern struct gdb_reader_funcs *gdb_init_reader (void);
36707 @end smallexample
36708
36709 @cindex @code{struct gdb_reader_funcs}
36710
36711 @code{struct gdb_reader_funcs} contains a set of pointers to callback
36712 functions. These functions are executed to read the debug info
36713 generated by the JIT compiler (@code{read}), to unwind stack frames
36714 (@code{unwind}) and to create canonical frame IDs
36715 (@code{get_frame_id}). It also has a callback that is called when the
36716 reader is being unloaded (@code{destroy}). The struct looks like this
36717
36718 @smallexample
36719 struct gdb_reader_funcs
36720 @{
36721 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36722 int reader_version;
36723
36724 /* For use by the reader. */
36725 void *priv_data;
36726
36727 gdb_read_debug_info *read;
36728 gdb_unwind_frame *unwind;
36729 gdb_get_frame_id *get_frame_id;
36730 gdb_destroy_reader *destroy;
36731 @};
36732 @end smallexample
36733
36734 @cindex @code{struct gdb_symbol_callbacks}
36735 @cindex @code{struct gdb_unwind_callbacks}
36736
36737 The callbacks are provided with another set of callbacks by
36738 @value{GDBN} to do their job. For @code{read}, these callbacks are
36739 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36740 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36741 @code{struct gdb_symbol_callbacks} has callbacks to create new object
36742 files and new symbol tables inside those object files. @code{struct
36743 gdb_unwind_callbacks} has callbacks to read registers off the current
36744 frame and to write out the values of the registers in the previous
36745 frame. Both have a callback (@code{target_read}) to read bytes off the
36746 target's address space.
36747
36748 @node In-Process Agent
36749 @chapter In-Process Agent
36750 @cindex debugging agent
36751 The traditional debugging model is conceptually low-speed, but works fine,
36752 because most bugs can be reproduced in debugging-mode execution. However,
36753 as multi-core or many-core processors are becoming mainstream, and
36754 multi-threaded programs become more and more popular, there should be more
36755 and more bugs that only manifest themselves at normal-mode execution, for
36756 example, thread races, because debugger's interference with the program's
36757 timing may conceal the bugs. On the other hand, in some applications,
36758 it is not feasible for the debugger to interrupt the program's execution
36759 long enough for the developer to learn anything helpful about its behavior.
36760 If the program's correctness depends on its real-time behavior, delays
36761 introduced by a debugger might cause the program to fail, even when the
36762 code itself is correct. It is useful to be able to observe the program's
36763 behavior without interrupting it.
36764
36765 Therefore, traditional debugging model is too intrusive to reproduce
36766 some bugs. In order to reduce the interference with the program, we can
36767 reduce the number of operations performed by debugger. The
36768 @dfn{In-Process Agent}, a shared library, is running within the same
36769 process with inferior, and is able to perform some debugging operations
36770 itself. As a result, debugger is only involved when necessary, and
36771 performance of debugging can be improved accordingly. Note that
36772 interference with program can be reduced but can't be removed completely,
36773 because the in-process agent will still stop or slow down the program.
36774
36775 The in-process agent can interpret and execute Agent Expressions
36776 (@pxref{Agent Expressions}) during performing debugging operations. The
36777 agent expressions can be used for different purposes, such as collecting
36778 data in tracepoints, and condition evaluation in breakpoints.
36779
36780 @anchor{Control Agent}
36781 You can control whether the in-process agent is used as an aid for
36782 debugging with the following commands:
36783
36784 @table @code
36785 @kindex set agent on
36786 @item set agent on
36787 Causes the in-process agent to perform some operations on behalf of the
36788 debugger. Just which operations requested by the user will be done
36789 by the in-process agent depends on the its capabilities. For example,
36790 if you request to evaluate breakpoint conditions in the in-process agent,
36791 and the in-process agent has such capability as well, then breakpoint
36792 conditions will be evaluated in the in-process agent.
36793
36794 @kindex set agent off
36795 @item set agent off
36796 Disables execution of debugging operations by the in-process agent. All
36797 of the operations will be performed by @value{GDBN}.
36798
36799 @kindex show agent
36800 @item show agent
36801 Display the current setting of execution of debugging operations by
36802 the in-process agent.
36803 @end table
36804
36805 @menu
36806 * In-Process Agent Protocol::
36807 @end menu
36808
36809 @node In-Process Agent Protocol
36810 @section In-Process Agent Protocol
36811 @cindex in-process agent protocol
36812
36813 The in-process agent is able to communicate with both @value{GDBN} and
36814 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
36815 used for communications between @value{GDBN} or GDBserver and the IPA.
36816 In general, @value{GDBN} or GDBserver sends commands
36817 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
36818 in-process agent replies back with the return result of the command, or
36819 some other information. The data sent to in-process agent is composed
36820 of primitive data types, such as 4-byte or 8-byte type, and composite
36821 types, which are called objects (@pxref{IPA Protocol Objects}).
36822
36823 @menu
36824 * IPA Protocol Objects::
36825 * IPA Protocol Commands::
36826 @end menu
36827
36828 @node IPA Protocol Objects
36829 @subsection IPA Protocol Objects
36830 @cindex ipa protocol objects
36831
36832 The commands sent to and results received from agent may contain some
36833 complex data types called @dfn{objects}.
36834
36835 The in-process agent is running on the same machine with @value{GDBN}
36836 or GDBserver, so it doesn't have to handle as much differences between
36837 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
36838 However, there are still some differences of two ends in two processes:
36839
36840 @enumerate
36841 @item
36842 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
36843 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
36844 @item
36845 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
36846 GDBserver is compiled with one, and in-process agent is compiled with
36847 the other one.
36848 @end enumerate
36849
36850 Here are the IPA Protocol Objects:
36851
36852 @enumerate
36853 @item
36854 agent expression object. It represents an agent expression
36855 (@pxref{Agent Expressions}).
36856 @anchor{agent expression object}
36857 @item
36858 tracepoint action object. It represents a tracepoint action
36859 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
36860 memory, static trace data and to evaluate expression.
36861 @anchor{tracepoint action object}
36862 @item
36863 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
36864 @anchor{tracepoint object}
36865
36866 @end enumerate
36867
36868 The following table describes important attributes of each IPA protocol
36869 object:
36870
36871 @multitable @columnfractions .30 .20 .50
36872 @headitem Name @tab Size @tab Description
36873 @item @emph{agent expression object} @tab @tab
36874 @item length @tab 4 @tab length of bytes code
36875 @item byte code @tab @var{length} @tab contents of byte code
36876 @item @emph{tracepoint action for collecting memory} @tab @tab
36877 @item 'M' @tab 1 @tab type of tracepoint action
36878 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
36879 address of the lowest byte to collect, otherwise @var{addr} is the offset
36880 of @var{basereg} for memory collecting.
36881 @item len @tab 8 @tab length of memory for collecting
36882 @item basereg @tab 4 @tab the register number containing the starting
36883 memory address for collecting.
36884 @item @emph{tracepoint action for collecting registers} @tab @tab
36885 @item 'R' @tab 1 @tab type of tracepoint action
36886 @item @emph{tracepoint action for collecting static trace data} @tab @tab
36887 @item 'L' @tab 1 @tab type of tracepoint action
36888 @item @emph{tracepoint action for expression evaluation} @tab @tab
36889 @item 'X' @tab 1 @tab type of tracepoint action
36890 @item agent expression @tab length of @tab @ref{agent expression object}
36891 @item @emph{tracepoint object} @tab @tab
36892 @item number @tab 4 @tab number of tracepoint
36893 @item address @tab 8 @tab address of tracepoint inserted on
36894 @item type @tab 4 @tab type of tracepoint
36895 @item enabled @tab 1 @tab enable or disable of tracepoint
36896 @item step_count @tab 8 @tab step
36897 @item pass_count @tab 8 @tab pass
36898 @item numactions @tab 4 @tab number of tracepoint actions
36899 @item hit count @tab 8 @tab hit count
36900 @item trace frame usage @tab 8 @tab trace frame usage
36901 @item compiled_cond @tab 8 @tab compiled condition
36902 @item orig_size @tab 8 @tab orig size
36903 @item condition @tab 4 if condition is NULL otherwise length of
36904 @ref{agent expression object}
36905 @tab zero if condition is NULL, otherwise is
36906 @ref{agent expression object}
36907 @item actions @tab variable
36908 @tab numactions number of @ref{tracepoint action object}
36909 @end multitable
36910
36911 @node IPA Protocol Commands
36912 @subsection IPA Protocol Commands
36913 @cindex ipa protocol commands
36914
36915 The spaces in each command are delimiters to ease reading this commands
36916 specification. They don't exist in real commands.
36917
36918 @table @samp
36919
36920 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
36921 Installs a new fast tracepoint described by @var{tracepoint_object}
36922 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
36923 head of @dfn{jumppad}, which is used to jump to data collection routine
36924 in IPA finally.
36925
36926 Replies:
36927 @table @samp
36928 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
36929 @var{target_address} is address of tracepoint in the inferior.
36930 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
36931 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
36932 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
36933 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
36934 @item E @var{NN}
36935 for an error
36936
36937 @end table
36938
36939 @item close
36940 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
36941 is about to kill inferiors.
36942
36943 @item qTfSTM
36944 @xref{qTfSTM}.
36945 @item qTsSTM
36946 @xref{qTsSTM}.
36947 @item qTSTMat
36948 @xref{qTSTMat}.
36949 @item probe_marker_at:@var{address}
36950 Asks in-process agent to probe the marker at @var{address}.
36951
36952 Replies:
36953 @table @samp
36954 @item E @var{NN}
36955 for an error
36956 @end table
36957 @item unprobe_marker_at:@var{address}
36958 Asks in-process agent to unprobe the marker at @var{address}.
36959 @end table
36960
36961 @node GDB Bugs
36962 @chapter Reporting Bugs in @value{GDBN}
36963 @cindex bugs in @value{GDBN}
36964 @cindex reporting bugs in @value{GDBN}
36965
36966 Your bug reports play an essential role in making @value{GDBN} reliable.
36967
36968 Reporting a bug may help you by bringing a solution to your problem, or it
36969 may not. But in any case the principal function of a bug report is to help
36970 the entire community by making the next version of @value{GDBN} work better. Bug
36971 reports are your contribution to the maintenance of @value{GDBN}.
36972
36973 In order for a bug report to serve its purpose, you must include the
36974 information that enables us to fix the bug.
36975
36976 @menu
36977 * Bug Criteria:: Have you found a bug?
36978 * Bug Reporting:: How to report bugs
36979 @end menu
36980
36981 @node Bug Criteria
36982 @section Have You Found a Bug?
36983 @cindex bug criteria
36984
36985 If you are not sure whether you have found a bug, here are some guidelines:
36986
36987 @itemize @bullet
36988 @cindex fatal signal
36989 @cindex debugger crash
36990 @cindex crash of debugger
36991 @item
36992 If the debugger gets a fatal signal, for any input whatever, that is a
36993 @value{GDBN} bug. Reliable debuggers never crash.
36994
36995 @cindex error on valid input
36996 @item
36997 If @value{GDBN} produces an error message for valid input, that is a
36998 bug. (Note that if you're cross debugging, the problem may also be
36999 somewhere in the connection to the target.)
37000
37001 @cindex invalid input
37002 @item
37003 If @value{GDBN} does not produce an error message for invalid input,
37004 that is a bug. However, you should note that your idea of
37005 ``invalid input'' might be our idea of ``an extension'' or ``support
37006 for traditional practice''.
37007
37008 @item
37009 If you are an experienced user of debugging tools, your suggestions
37010 for improvement of @value{GDBN} are welcome in any case.
37011 @end itemize
37012
37013 @node Bug Reporting
37014 @section How to Report Bugs
37015 @cindex bug reports
37016 @cindex @value{GDBN} bugs, reporting
37017
37018 A number of companies and individuals offer support for @sc{gnu} products.
37019 If you obtained @value{GDBN} from a support organization, we recommend you
37020 contact that organization first.
37021
37022 You can find contact information for many support companies and
37023 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37024 distribution.
37025 @c should add a web page ref...
37026
37027 @ifset BUGURL
37028 @ifset BUGURL_DEFAULT
37029 In any event, we also recommend that you submit bug reports for
37030 @value{GDBN}. The preferred method is to submit them directly using
37031 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37032 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37033 be used.
37034
37035 @strong{Do not send bug reports to @samp{info-gdb}, or to
37036 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37037 not want to receive bug reports. Those that do have arranged to receive
37038 @samp{bug-gdb}.
37039
37040 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37041 serves as a repeater. The mailing list and the newsgroup carry exactly
37042 the same messages. Often people think of posting bug reports to the
37043 newsgroup instead of mailing them. This appears to work, but it has one
37044 problem which can be crucial: a newsgroup posting often lacks a mail
37045 path back to the sender. Thus, if we need to ask for more information,
37046 we may be unable to reach you. For this reason, it is better to send
37047 bug reports to the mailing list.
37048 @end ifset
37049 @ifclear BUGURL_DEFAULT
37050 In any event, we also recommend that you submit bug reports for
37051 @value{GDBN} to @value{BUGURL}.
37052 @end ifclear
37053 @end ifset
37054
37055 The fundamental principle of reporting bugs usefully is this:
37056 @strong{report all the facts}. If you are not sure whether to state a
37057 fact or leave it out, state it!
37058
37059 Often people omit facts because they think they know what causes the
37060 problem and assume that some details do not matter. Thus, you might
37061 assume that the name of the variable you use in an example does not matter.
37062 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37063 stray memory reference which happens to fetch from the location where that
37064 name is stored in memory; perhaps, if the name were different, the contents
37065 of that location would fool the debugger into doing the right thing despite
37066 the bug. Play it safe and give a specific, complete example. That is the
37067 easiest thing for you to do, and the most helpful.
37068
37069 Keep in mind that the purpose of a bug report is to enable us to fix the
37070 bug. It may be that the bug has been reported previously, but neither
37071 you nor we can know that unless your bug report is complete and
37072 self-contained.
37073
37074 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37075 bell?'' Those bug reports are useless, and we urge everyone to
37076 @emph{refuse to respond to them} except to chide the sender to report
37077 bugs properly.
37078
37079 To enable us to fix the bug, you should include all these things:
37080
37081 @itemize @bullet
37082 @item
37083 The version of @value{GDBN}. @value{GDBN} announces it if you start
37084 with no arguments; you can also print it at any time using @code{show
37085 version}.
37086
37087 Without this, we will not know whether there is any point in looking for
37088 the bug in the current version of @value{GDBN}.
37089
37090 @item
37091 The type of machine you are using, and the operating system name and
37092 version number.
37093
37094 @item
37095 The details of the @value{GDBN} build-time configuration.
37096 @value{GDBN} shows these details if you invoke it with the
37097 @option{--configuration} command-line option, or if you type
37098 @code{show configuration} at @value{GDBN}'s prompt.
37099
37100 @item
37101 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37102 ``@value{GCC}--2.8.1''.
37103
37104 @item
37105 What compiler (and its version) was used to compile the program you are
37106 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37107 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37108 to get this information; for other compilers, see the documentation for
37109 those compilers.
37110
37111 @item
37112 The command arguments you gave the compiler to compile your example and
37113 observe the bug. For example, did you use @samp{-O}? To guarantee
37114 you will not omit something important, list them all. A copy of the
37115 Makefile (or the output from make) is sufficient.
37116
37117 If we were to try to guess the arguments, we would probably guess wrong
37118 and then we might not encounter the bug.
37119
37120 @item
37121 A complete input script, and all necessary source files, that will
37122 reproduce the bug.
37123
37124 @item
37125 A description of what behavior you observe that you believe is
37126 incorrect. For example, ``It gets a fatal signal.''
37127
37128 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37129 will certainly notice it. But if the bug is incorrect output, we might
37130 not notice unless it is glaringly wrong. You might as well not give us
37131 a chance to make a mistake.
37132
37133 Even if the problem you experience is a fatal signal, you should still
37134 say so explicitly. Suppose something strange is going on, such as, your
37135 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37136 the C library on your system. (This has happened!) Your copy might
37137 crash and ours would not. If you told us to expect a crash, then when
37138 ours fails to crash, we would know that the bug was not happening for
37139 us. If you had not told us to expect a crash, then we would not be able
37140 to draw any conclusion from our observations.
37141
37142 @pindex script
37143 @cindex recording a session script
37144 To collect all this information, you can use a session recording program
37145 such as @command{script}, which is available on many Unix systems.
37146 Just run your @value{GDBN} session inside @command{script} and then
37147 include the @file{typescript} file with your bug report.
37148
37149 Another way to record a @value{GDBN} session is to run @value{GDBN}
37150 inside Emacs and then save the entire buffer to a file.
37151
37152 @item
37153 If you wish to suggest changes to the @value{GDBN} source, send us context
37154 diffs. If you even discuss something in the @value{GDBN} source, refer to
37155 it by context, not by line number.
37156
37157 The line numbers in our development sources will not match those in your
37158 sources. Your line numbers would convey no useful information to us.
37159
37160 @end itemize
37161
37162 Here are some things that are not necessary:
37163
37164 @itemize @bullet
37165 @item
37166 A description of the envelope of the bug.
37167
37168 Often people who encounter a bug spend a lot of time investigating
37169 which changes to the input file will make the bug go away and which
37170 changes will not affect it.
37171
37172 This is often time consuming and not very useful, because the way we
37173 will find the bug is by running a single example under the debugger
37174 with breakpoints, not by pure deduction from a series of examples.
37175 We recommend that you save your time for something else.
37176
37177 Of course, if you can find a simpler example to report @emph{instead}
37178 of the original one, that is a convenience for us. Errors in the
37179 output will be easier to spot, running under the debugger will take
37180 less time, and so on.
37181
37182 However, simplification is not vital; if you do not want to do this,
37183 report the bug anyway and send us the entire test case you used.
37184
37185 @item
37186 A patch for the bug.
37187
37188 A patch for the bug does help us if it is a good one. But do not omit
37189 the necessary information, such as the test case, on the assumption that
37190 a patch is all we need. We might see problems with your patch and decide
37191 to fix the problem another way, or we might not understand it at all.
37192
37193 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37194 construct an example that will make the program follow a certain path
37195 through the code. If you do not send us the example, we will not be able
37196 to construct one, so we will not be able to verify that the bug is fixed.
37197
37198 And if we cannot understand what bug you are trying to fix, or why your
37199 patch should be an improvement, we will not install it. A test case will
37200 help us to understand.
37201
37202 @item
37203 A guess about what the bug is or what it depends on.
37204
37205 Such guesses are usually wrong. Even we cannot guess right about such
37206 things without first using the debugger to find the facts.
37207 @end itemize
37208
37209 @c The readline documentation is distributed with the readline code
37210 @c and consists of the two following files:
37211 @c rluser.texi
37212 @c hsuser.texi
37213 @c Use -I with makeinfo to point to the appropriate directory,
37214 @c environment var TEXINPUTS with TeX.
37215 @ifclear SYSTEM_READLINE
37216 @include rluser.texi
37217 @include hsuser.texi
37218 @end ifclear
37219
37220 @node In Memoriam
37221 @appendix In Memoriam
37222
37223 The @value{GDBN} project mourns the loss of the following long-time
37224 contributors:
37225
37226 @table @code
37227 @item Fred Fish
37228 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37229 to Free Software in general. Outside of @value{GDBN}, he was known in
37230 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37231
37232 @item Michael Snyder
37233 Michael was one of the Global Maintainers of the @value{GDBN} project,
37234 with contributions recorded as early as 1996, until 2011. In addition
37235 to his day to day participation, he was a large driving force behind
37236 adding Reverse Debugging to @value{GDBN}.
37237 @end table
37238
37239 Beyond their technical contributions to the project, they were also
37240 enjoyable members of the Free Software Community. We will miss them.
37241
37242 @node Formatting Documentation
37243 @appendix Formatting Documentation
37244
37245 @cindex @value{GDBN} reference card
37246 @cindex reference card
37247 The @value{GDBN} 4 release includes an already-formatted reference card, ready
37248 for printing with PostScript or Ghostscript, in the @file{gdb}
37249 subdirectory of the main source directory@footnote{In
37250 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37251 release.}. If you can use PostScript or Ghostscript with your printer,
37252 you can print the reference card immediately with @file{refcard.ps}.
37253
37254 The release also includes the source for the reference card. You
37255 can format it, using @TeX{}, by typing:
37256
37257 @smallexample
37258 make refcard.dvi
37259 @end smallexample
37260
37261 The @value{GDBN} reference card is designed to print in @dfn{landscape}
37262 mode on US ``letter'' size paper;
37263 that is, on a sheet 11 inches wide by 8.5 inches
37264 high. You will need to specify this form of printing as an option to
37265 your @sc{dvi} output program.
37266
37267 @cindex documentation
37268
37269 All the documentation for @value{GDBN} comes as part of the machine-readable
37270 distribution. The documentation is written in Texinfo format, which is
37271 a documentation system that uses a single source file to produce both
37272 on-line information and a printed manual. You can use one of the Info
37273 formatting commands to create the on-line version of the documentation
37274 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
37275
37276 @value{GDBN} includes an already formatted copy of the on-line Info
37277 version of this manual in the @file{gdb} subdirectory. The main Info
37278 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37279 subordinate files matching @samp{gdb.info*} in the same directory. If
37280 necessary, you can print out these files, or read them with any editor;
37281 but they are easier to read using the @code{info} subsystem in @sc{gnu}
37282 Emacs or the standalone @code{info} program, available as part of the
37283 @sc{gnu} Texinfo distribution.
37284
37285 If you want to format these Info files yourself, you need one of the
37286 Info formatting programs, such as @code{texinfo-format-buffer} or
37287 @code{makeinfo}.
37288
37289 If you have @code{makeinfo} installed, and are in the top level
37290 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37291 version @value{GDBVN}), you can make the Info file by typing:
37292
37293 @smallexample
37294 cd gdb
37295 make gdb.info
37296 @end smallexample
37297
37298 If you want to typeset and print copies of this manual, you need @TeX{},
37299 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37300 Texinfo definitions file.
37301
37302 @TeX{} is a typesetting program; it does not print files directly, but
37303 produces output files called @sc{dvi} files. To print a typeset
37304 document, you need a program to print @sc{dvi} files. If your system
37305 has @TeX{} installed, chances are it has such a program. The precise
37306 command to use depends on your system; @kbd{lpr -d} is common; another
37307 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37308 require a file name without any extension or a @samp{.dvi} extension.
37309
37310 @TeX{} also requires a macro definitions file called
37311 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37312 written in Texinfo format. On its own, @TeX{} cannot either read or
37313 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37314 and is located in the @file{gdb-@var{version-number}/texinfo}
37315 directory.
37316
37317 If you have @TeX{} and a @sc{dvi} printer program installed, you can
37318 typeset and print this manual. First switch to the @file{gdb}
37319 subdirectory of the main source directory (for example, to
37320 @file{gdb-@value{GDBVN}/gdb}) and type:
37321
37322 @smallexample
37323 make gdb.dvi
37324 @end smallexample
37325
37326 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
37327
37328 @node Installing GDB
37329 @appendix Installing @value{GDBN}
37330 @cindex installation
37331
37332 @menu
37333 * Requirements:: Requirements for building @value{GDBN}
37334 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
37335 * Separate Objdir:: Compiling @value{GDBN} in another directory
37336 * Config Names:: Specifying names for hosts and targets
37337 * Configure Options:: Summary of options for configure
37338 * System-wide configuration:: Having a system-wide init file
37339 @end menu
37340
37341 @node Requirements
37342 @section Requirements for Building @value{GDBN}
37343 @cindex building @value{GDBN}, requirements for
37344
37345 Building @value{GDBN} requires various tools and packages to be available.
37346 Other packages will be used only if they are found.
37347
37348 @heading Tools/Packages Necessary for Building @value{GDBN}
37349 @table @asis
37350 @item C@t{++}11 compiler
37351 @value{GDBN} is written in C@t{++}11. It should be buildable with any
37352 recent C@t{++}11 compiler, e.g.@: GCC.
37353
37354 @item GNU make
37355 @value{GDBN}'s build system relies on features only found in the GNU
37356 make program. Other variants of @code{make} will not work.
37357 @end table
37358
37359 @heading Tools/Packages Optional for Building @value{GDBN}
37360 @table @asis
37361 @item Expat
37362 @anchor{Expat}
37363 @value{GDBN} can use the Expat XML parsing library. This library may be
37364 included with your operating system distribution; if it is not, you
37365 can get the latest version from @url{http://expat.sourceforge.net}.
37366 The @file{configure} script will search for this library in several
37367 standard locations; if it is installed in an unusual path, you can
37368 use the @option{--with-libexpat-prefix} option to specify its location.
37369
37370 Expat is used for:
37371
37372 @itemize @bullet
37373 @item
37374 Remote protocol memory maps (@pxref{Memory Map Format})
37375 @item
37376 Target descriptions (@pxref{Target Descriptions})
37377 @item
37378 Remote shared library lists (@xref{Library List Format},
37379 or alternatively @pxref{Library List Format for SVR4 Targets})
37380 @item
37381 MS-Windows shared libraries (@pxref{Shared Libraries})
37382 @item
37383 Traceframe info (@pxref{Traceframe Info Format})
37384 @item
37385 Branch trace (@pxref{Branch Trace Format},
37386 @pxref{Branch Trace Configuration Format})
37387 @end itemize
37388
37389 @item Guile
37390 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37391 default, @value{GDBN} will be compiled if the Guile libraries are
37392 installed and are found by @file{configure}. You can use the
37393 @code{--with-guile} option to request Guile, and pass either the Guile
37394 version number or the file name of the relevant @code{pkg-config}
37395 program to choose a particular version of Guile.
37396
37397 @item iconv
37398 @value{GDBN}'s features related to character sets (@pxref{Character
37399 Sets}) require a functioning @code{iconv} implementation. If you are
37400 on a GNU system, then this is provided by the GNU C Library. Some
37401 other systems also provide a working @code{iconv}.
37402
37403 If @value{GDBN} is using the @code{iconv} program which is installed
37404 in a non-standard place, you will need to tell @value{GDBN} where to
37405 find it. This is done with @option{--with-iconv-bin} which specifies
37406 the directory that contains the @code{iconv} program. This program is
37407 run in order to make a list of the available character sets.
37408
37409 On systems without @code{iconv}, you can install GNU Libiconv. If
37410 Libiconv is installed in a standard place, @value{GDBN} will
37411 automatically use it if it is needed. If you have previously
37412 installed Libiconv in a non-standard place, you can use the
37413 @option{--with-libiconv-prefix} option to @file{configure}.
37414
37415 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37416 arrange to build Libiconv if a directory named @file{libiconv} appears
37417 in the top-most source directory. If Libiconv is built this way, and
37418 if the operating system does not provide a suitable @code{iconv}
37419 implementation, then the just-built library will automatically be used
37420 by @value{GDBN}. One easy way to set this up is to download GNU
37421 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37422 source tree, and then rename the directory holding the Libiconv source
37423 code to @samp{libiconv}.
37424
37425 @item lzma
37426 @value{GDBN} can support debugging sections that are compressed with
37427 the LZMA library. @xref{MiniDebugInfo}. If this library is not
37428 included with your operating system, you can find it in the xz package
37429 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37430 the usual place, then the @file{configure} script will use it
37431 automatically. If it is installed in an unusual path, you can use the
37432 @option{--with-lzma-prefix} option to specify its location.
37433
37434 @item MPFR
37435 @anchor{MPFR}
37436 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
37437 library. This library may be included with your operating system
37438 distribution; if it is not, you can get the latest version from
37439 @url{http://www.mpfr.org}. The @file{configure} script will search
37440 for this library in several standard locations; if it is installed
37441 in an unusual path, you can use the @option{--with-libmpfr-prefix}
37442 option to specify its location.
37443
37444 GNU MPFR is used to emulate target floating-point arithmetic during
37445 expression evaluation when the target uses different floating-point
37446 formats than the host. If GNU MPFR it is not available, @value{GDBN}
37447 will fall back to using host floating-point arithmetic.
37448
37449 @item Python
37450 @value{GDBN} can be scripted using Python language. @xref{Python}.
37451 By default, @value{GDBN} will be compiled if the Python libraries are
37452 installed and are found by @file{configure}. You can use the
37453 @code{--with-python} option to request Python, and pass either the
37454 file name of the relevant @code{python} executable, or the name of the
37455 directory in which Python is installed, to choose a particular
37456 installation of Python.
37457
37458 @item zlib
37459 @cindex compressed debug sections
37460 @value{GDBN} will use the @samp{zlib} library, if available, to read
37461 compressed debug sections. Some linkers, such as GNU gold, are capable
37462 of producing binaries with compressed debug sections. If @value{GDBN}
37463 is compiled with @samp{zlib}, it will be able to read the debug
37464 information in such binaries.
37465
37466 The @samp{zlib} library is likely included with your operating system
37467 distribution; if it is not, you can get the latest version from
37468 @url{http://zlib.net}.
37469 @end table
37470
37471 @node Running Configure
37472 @section Invoking the @value{GDBN} @file{configure} Script
37473 @cindex configuring @value{GDBN}
37474 @value{GDBN} comes with a @file{configure} script that automates the process
37475 of preparing @value{GDBN} for installation; you can then use @code{make} to
37476 build the @code{gdb} program.
37477 @iftex
37478 @c irrelevant in info file; it's as current as the code it lives with.
37479 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37480 look at the @file{README} file in the sources; we may have improved the
37481 installation procedures since publishing this manual.}
37482 @end iftex
37483
37484 The @value{GDBN} distribution includes all the source code you need for
37485 @value{GDBN} in a single directory, whose name is usually composed by
37486 appending the version number to @samp{gdb}.
37487
37488 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37489 @file{gdb-@value{GDBVN}} directory. That directory contains:
37490
37491 @table @code
37492 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37493 script for configuring @value{GDBN} and all its supporting libraries
37494
37495 @item gdb-@value{GDBVN}/gdb
37496 the source specific to @value{GDBN} itself
37497
37498 @item gdb-@value{GDBVN}/bfd
37499 source for the Binary File Descriptor library
37500
37501 @item gdb-@value{GDBVN}/include
37502 @sc{gnu} include files
37503
37504 @item gdb-@value{GDBVN}/libiberty
37505 source for the @samp{-liberty} free software library
37506
37507 @item gdb-@value{GDBVN}/opcodes
37508 source for the library of opcode tables and disassemblers
37509
37510 @item gdb-@value{GDBVN}/readline
37511 source for the @sc{gnu} command-line interface
37512 @end table
37513
37514 There may be other subdirectories as well.
37515
37516 The simplest way to configure and build @value{GDBN} is to run @file{configure}
37517 from the @file{gdb-@var{version-number}} source directory, which in
37518 this example is the @file{gdb-@value{GDBVN}} directory.
37519
37520 First switch to the @file{gdb-@var{version-number}} source directory
37521 if you are not already in it; then run @file{configure}. Pass the
37522 identifier for the platform on which @value{GDBN} will run as an
37523 argument.
37524
37525 For example:
37526
37527 @smallexample
37528 cd gdb-@value{GDBVN}
37529 ./configure
37530 make
37531 @end smallexample
37532
37533 Running @samp{configure} and then running @code{make} builds the
37534 included supporting libraries, then @code{gdb} itself. The configured
37535 source files, and the binaries, are left in the corresponding source
37536 directories.
37537
37538 @need 750
37539 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
37540 system does not recognize this automatically when you run a different
37541 shell, you may need to run @code{sh} on it explicitly:
37542
37543 @smallexample
37544 sh configure
37545 @end smallexample
37546
37547 You should run the @file{configure} script from the top directory in the
37548 source tree, the @file{gdb-@var{version-number}} directory. If you run
37549 @file{configure} from one of the subdirectories, you will configure only
37550 that subdirectory. That is usually not what you want. In particular,
37551 if you run the first @file{configure} from the @file{gdb} subdirectory
37552 of the @file{gdb-@var{version-number}} directory, you will omit the
37553 configuration of @file{bfd}, @file{readline}, and other sibling
37554 directories of the @file{gdb} subdirectory. This leads to build errors
37555 about missing include files such as @file{bfd/bfd.h}.
37556
37557 You can install @code{@value{GDBN}} anywhere. The best way to do this
37558 is to pass the @code{--prefix} option to @code{configure}, and then
37559 install it with @code{make install}.
37560
37561 @node Separate Objdir
37562 @section Compiling @value{GDBN} in Another Directory
37563
37564 If you want to run @value{GDBN} versions for several host or target machines,
37565 you need a different @code{gdb} compiled for each combination of
37566 host and target. @file{configure} is designed to make this easy by
37567 allowing you to generate each configuration in a separate subdirectory,
37568 rather than in the source directory. If your @code{make} program
37569 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37570 @code{make} in each of these directories builds the @code{gdb}
37571 program specified there.
37572
37573 To build @code{gdb} in a separate directory, run @file{configure}
37574 with the @samp{--srcdir} option to specify where to find the source.
37575 (You also need to specify a path to find @file{configure}
37576 itself from your working directory. If the path to @file{configure}
37577 would be the same as the argument to @samp{--srcdir}, you can leave out
37578 the @samp{--srcdir} option; it is assumed.)
37579
37580 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37581 separate directory for a Sun 4 like this:
37582
37583 @smallexample
37584 @group
37585 cd gdb-@value{GDBVN}
37586 mkdir ../gdb-sun4
37587 cd ../gdb-sun4
37588 ../gdb-@value{GDBVN}/configure
37589 make
37590 @end group
37591 @end smallexample
37592
37593 When @file{configure} builds a configuration using a remote source
37594 directory, it creates a tree for the binaries with the same structure
37595 (and using the same names) as the tree under the source directory. In
37596 the example, you'd find the Sun 4 library @file{libiberty.a} in the
37597 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37598 @file{gdb-sun4/gdb}.
37599
37600 Make sure that your path to the @file{configure} script has just one
37601 instance of @file{gdb} in it. If your path to @file{configure} looks
37602 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37603 one subdirectory of @value{GDBN}, not the whole package. This leads to
37604 build errors about missing include files such as @file{bfd/bfd.h}.
37605
37606 One popular reason to build several @value{GDBN} configurations in separate
37607 directories is to configure @value{GDBN} for cross-compiling (where
37608 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
37609 programs that run on another machine---the @dfn{target}).
37610 You specify a cross-debugging target by
37611 giving the @samp{--target=@var{target}} option to @file{configure}.
37612
37613 When you run @code{make} to build a program or library, you must run
37614 it in a configured directory---whatever directory you were in when you
37615 called @file{configure} (or one of its subdirectories).
37616
37617 The @code{Makefile} that @file{configure} generates in each source
37618 directory also runs recursively. If you type @code{make} in a source
37619 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37620 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37621 will build all the required libraries, and then build GDB.
37622
37623 When you have multiple hosts or targets configured in separate
37624 directories, you can run @code{make} on them in parallel (for example,
37625 if they are NFS-mounted on each of the hosts); they will not interfere
37626 with each other.
37627
37628 @node Config Names
37629 @section Specifying Names for Hosts and Targets
37630
37631 The specifications used for hosts and targets in the @file{configure}
37632 script are based on a three-part naming scheme, but some short predefined
37633 aliases are also supported. The full naming scheme encodes three pieces
37634 of information in the following pattern:
37635
37636 @smallexample
37637 @var{architecture}-@var{vendor}-@var{os}
37638 @end smallexample
37639
37640 For example, you can use the alias @code{sun4} as a @var{host} argument,
37641 or as the value for @var{target} in a @code{--target=@var{target}}
37642 option. The equivalent full name is @samp{sparc-sun-sunos4}.
37643
37644 The @file{configure} script accompanying @value{GDBN} does not provide
37645 any query facility to list all supported host and target names or
37646 aliases. @file{configure} calls the Bourne shell script
37647 @code{config.sub} to map abbreviations to full names; you can read the
37648 script, if you wish, or you can use it to test your guesses on
37649 abbreviations---for example:
37650
37651 @smallexample
37652 % sh config.sub i386-linux
37653 i386-pc-linux-gnu
37654 % sh config.sub alpha-linux
37655 alpha-unknown-linux-gnu
37656 % sh config.sub hp9k700
37657 hppa1.1-hp-hpux
37658 % sh config.sub sun4
37659 sparc-sun-sunos4.1.1
37660 % sh config.sub sun3
37661 m68k-sun-sunos4.1.1
37662 % sh config.sub i986v
37663 Invalid configuration `i986v': machine `i986v' not recognized
37664 @end smallexample
37665
37666 @noindent
37667 @code{config.sub} is also distributed in the @value{GDBN} source
37668 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
37669
37670 @node Configure Options
37671 @section @file{configure} Options
37672
37673 Here is a summary of the @file{configure} options and arguments that
37674 are most often useful for building @value{GDBN}. @file{configure}
37675 also has several other options not listed here. @inforef{Running
37676 configure scripts,,autoconf.info}, for a full
37677 explanation of @file{configure}.
37678
37679 @smallexample
37680 configure @r{[}--help@r{]}
37681 @r{[}--prefix=@var{dir}@r{]}
37682 @r{[}--exec-prefix=@var{dir}@r{]}
37683 @r{[}--srcdir=@var{dirname}@r{]}
37684 @r{[}--target=@var{target}@r{]}
37685 @end smallexample
37686
37687 @noindent
37688 You may introduce options with a single @samp{-} rather than
37689 @samp{--} if you prefer; but you may abbreviate option names if you use
37690 @samp{--}.
37691
37692 @table @code
37693 @item --help
37694 Display a quick summary of how to invoke @file{configure}.
37695
37696 @item --prefix=@var{dir}
37697 Configure the source to install programs and files under directory
37698 @file{@var{dir}}.
37699
37700 @item --exec-prefix=@var{dir}
37701 Configure the source to install programs under directory
37702 @file{@var{dir}}.
37703
37704 @c avoid splitting the warning from the explanation:
37705 @need 2000
37706 @item --srcdir=@var{dirname}
37707 Use this option to make configurations in directories separate from the
37708 @value{GDBN} source directories. Among other things, you can use this to
37709 build (or maintain) several configurations simultaneously, in separate
37710 directories. @file{configure} writes configuration-specific files in
37711 the current directory, but arranges for them to use the source in the
37712 directory @var{dirname}. @file{configure} creates directories under
37713 the working directory in parallel to the source directories below
37714 @var{dirname}.
37715
37716 @item --target=@var{target}
37717 Configure @value{GDBN} for cross-debugging programs running on the specified
37718 @var{target}. Without this option, @value{GDBN} is configured to debug
37719 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
37720
37721 There is no convenient way to generate a list of all available
37722 targets. Also see the @code{--enable-targets} option, below.
37723 @end table
37724
37725 There are many other options that are specific to @value{GDBN}. This
37726 lists just the most common ones; there are some very specialized
37727 options not described here.
37728
37729 @table @code
37730 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37731 @itemx --enable-targets=all
37732 Configure @value{GDBN} for cross-debugging programs running on the
37733 specified list of targets. The special value @samp{all} configures
37734 @value{GDBN} for debugging programs running on any target it supports.
37735
37736 @item --with-gdb-datadir=@var{path}
37737 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37738 here for certain supporting files or scripts. This defaults to the
37739 @file{gdb} subdirectory of @samp{datadir} (which can be set using
37740 @code{--datadir}).
37741
37742 @item --with-relocated-sources=@var{dir}
37743 Sets up the default source path substitution rule so that directory
37744 names recorded in debug information will be automatically adjusted for
37745 any directory under @var{dir}. @var{dir} should be a subdirectory of
37746 @value{GDBN}'s configured prefix, the one mentioned in the
37747 @code{--prefix} or @code{--exec-prefix} options to configure. This
37748 option is useful if GDB is supposed to be moved to a different place
37749 after it is built.
37750
37751 @item --enable-64-bit-bfd
37752 Enable 64-bit support in BFD on 32-bit hosts.
37753
37754 @item --disable-gdbmi
37755 Build @value{GDBN} without the GDB/MI machine interface
37756 (@pxref{GDB/MI}).
37757
37758 @item --enable-tui
37759 Build @value{GDBN} with the text-mode full-screen user interface
37760 (TUI). Requires a curses library (ncurses and cursesX are also
37761 supported).
37762
37763 @item --with-curses
37764 Use the curses library instead of the termcap library, for text-mode
37765 terminal operations.
37766
37767 @item --with-libunwind-ia64
37768 Use the libunwind library for unwinding function call stack on ia64
37769 target platforms. See http://www.nongnu.org/libunwind/index.html for
37770 details.
37771
37772 @item --with-system-readline
37773 Use the readline library installed on the host, rather than the
37774 library supplied as part of @value{GDBN}. Readline 7 or newer is
37775 required; this is enforced by the build system.
37776
37777 @item --with-system-zlib
37778 Use the zlib library installed on the host, rather than the library
37779 supplied as part of @value{GDBN}.
37780
37781 @item --with-expat
37782 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
37783 default if libexpat is installed and found at configure time.) This
37784 library is used to read XML files supplied with @value{GDBN}. If it
37785 is unavailable, some features, such as remote protocol memory maps,
37786 target descriptions, and shared library lists, that are based on XML
37787 files, will not be available in @value{GDBN}. If your host does not
37788 have libexpat installed, you can get the latest version from
37789 `http://expat.sourceforge.net'.
37790
37791 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
37792
37793 Build @value{GDBN} with GNU libiconv, a character set encoding
37794 conversion library. This is not done by default, as on GNU systems
37795 the @code{iconv} that is built in to the C library is sufficient. If
37796 your host does not have a working @code{iconv}, you can get the latest
37797 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
37798
37799 @value{GDBN}'s build system also supports building GNU libiconv as
37800 part of the overall build. @xref{Requirements}.
37801
37802 @item --with-lzma
37803 Build @value{GDBN} with LZMA, a compression library. (Done by default
37804 if liblzma is installed and found at configure time.) LZMA is used by
37805 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
37806 platforms using the ELF object file format. If your host does not
37807 have liblzma installed, you can get the latest version from
37808 `https://tukaani.org/xz/'.
37809
37810 @item --with-mpfr
37811 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
37812 floating-point computation with correct rounding. (Done by default if
37813 GNU MPFR is installed and found at configure time.) This library is
37814 used to emulate target floating-point arithmetic during expression
37815 evaluation when the target uses different floating-point formats than
37816 the host. If GNU MPFR is not available, @value{GDBN} will fall back
37817 to using host floating-point arithmetic. If your host does not have
37818 GNU MPFR installed, you can get the latest version from
37819 `http://www.mpfr.org'.
37820
37821 @item --with-python@r{[}=@var{python}@r{]}
37822 Build @value{GDBN} with Python scripting support. (Done by default if
37823 libpython is present and found at configure time.) Python makes
37824 @value{GDBN} scripting much more powerful than the restricted CLI
37825 scripting language. If your host does not have Python installed, you
37826 can find it on `http://www.python.org/download/'. The oldest version
37827 of Python supported by GDB is 2.6. The optional argument @var{python}
37828 is used to find the Python headers and libraries. It can be either
37829 the name of a Python executable, or the name of the directory in which
37830 Python is installed.
37831
37832 @item --with-guile[=GUILE]'
37833 Build @value{GDBN} with GNU Guile scripting support. (Done by default
37834 if libguile is present and found at configure time.) If your host
37835 does not have Guile installed, you can find it at
37836 `https://www.gnu.org/software/guile/'. The optional argument GUILE
37837 can be a version number, which will cause @code{configure} to try to
37838 use that version of Guile; or the file name of a @code{pkg-config}
37839 executable, which will be queried to find the information needed to
37840 compile and link against Guile.
37841
37842 @item --without-included-regex
37843 Don't use the regex library included with @value{GDBN} (as part of the
37844 libiberty library). This is the default on hosts with version 2 of
37845 the GNU C library.
37846
37847 @item --with-sysroot=@var{dir}
37848 Use @var{dir} as the default system root directory for libraries whose
37849 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
37850 @var{dir} can be modified at run time by using the @command{set
37851 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
37852 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
37853 default system root will be automatically adjusted if and when
37854 @value{GDBN} is moved to a different location.
37855
37856 @item --with-system-gdbinit=@var{file}
37857 Configure @value{GDBN} to automatically load a system-wide init file.
37858 @var{file} should be an absolute file name. If @var{file} is in a
37859 directory under the configured prefix, and @value{GDBN} is moved to
37860 another location after being built, the location of the system-wide
37861 init file will be adjusted accordingly.
37862
37863 @item --with-system-gdbinit-dir=@var{directory}
37864 Configure @value{GDBN} to automatically load init files from a
37865 system-wide directory. @var{directory} should be an absolute directory
37866 name. If @var{directory} is in a directory under the configured
37867 prefix, and @value{GDBN} is moved to another location after being
37868 built, the location of the system-wide init directory will be
37869 adjusted accordingly.
37870
37871 @item --enable-build-warnings
37872 When building the @value{GDBN} sources, ask the compiler to warn about
37873 any code which looks even vaguely suspicious. It passes many
37874 different warning flags, depending on the exact version of the
37875 compiler you are using.
37876
37877 @item --enable-werror
37878 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
37879 to the compiler, which will fail the compilation if the compiler
37880 outputs any warning messages.
37881
37882 @item --enable-ubsan
37883 Enable the GCC undefined behavior sanitizer. This is disabled by
37884 default, but passing @code{--enable-ubsan=yes} or
37885 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
37886 undefined behavior sanitizer checks for C@t{++} undefined behavior.
37887 It has a performance cost, so if you are looking at @value{GDBN}'s
37888 performance, you should disable it. The undefined behavior sanitizer
37889 was first introduced in GCC 4.9.
37890 @end table
37891
37892 @node System-wide configuration
37893 @section System-wide configuration and settings
37894 @cindex system-wide init file
37895
37896 @value{GDBN} can be configured to have a system-wide init file and a
37897 system-wide init file directory; this file and files in that directory
37898 (if they have a recognized file extension) will be read and executed at
37899 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
37900
37901 Here are the corresponding configure options:
37902
37903 @table @code
37904 @item --with-system-gdbinit=@var{file}
37905 Specify that the default location of the system-wide init file is
37906 @var{file}.
37907 @item --with-system-gdbinit-dir=@var{directory}
37908 Specify that the default location of the system-wide init file directory
37909 is @var{directory}.
37910 @end table
37911
37912 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
37913 they may be subject to relocation. Two possible cases:
37914
37915 @itemize @bullet
37916 @item
37917 If the default location of this init file/directory contains @file{$prefix},
37918 it will be subject to relocation. Suppose that the configure options
37919 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
37920 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
37921 init file is looked for as @file{$install/etc/gdbinit} instead of
37922 @file{$prefix/etc/gdbinit}.
37923
37924 @item
37925 By contrast, if the default location does not contain the prefix,
37926 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
37927 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
37928 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
37929 wherever @value{GDBN} is installed.
37930 @end itemize
37931
37932 If the configured location of the system-wide init file (as given by the
37933 @option{--with-system-gdbinit} option at configure time) is in the
37934 data-directory (as specified by @option{--with-gdb-datadir} at configure
37935 time) or in one of its subdirectories, then @value{GDBN} will look for the
37936 system-wide init file in the directory specified by the
37937 @option{--data-directory} command-line option.
37938 Note that the system-wide init file is only read once, during @value{GDBN}
37939 initialization. If the data-directory is changed after @value{GDBN} has
37940 started with the @code{set data-directory} command, the file will not be
37941 reread.
37942
37943 This applies similarly to the system-wide directory specified in
37944 @option{--with-system-gdbinit-dir}.
37945
37946 Any supported scripting language can be used for these init files, as long
37947 as the file extension matches the scripting language. To be interpreted
37948 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
37949 extension.
37950
37951 @menu
37952 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
37953 @end menu
37954
37955 @node System-wide Configuration Scripts
37956 @subsection Installed System-wide Configuration Scripts
37957 @cindex system-wide configuration scripts
37958
37959 The @file{system-gdbinit} directory, located inside the data-directory
37960 (as specified by @option{--with-gdb-datadir} at configure time) contains
37961 a number of scripts which can be used as system-wide init files. To
37962 automatically source those scripts at startup, @value{GDBN} should be
37963 configured with @option{--with-system-gdbinit}. Otherwise, any user
37964 should be able to source them by hand as needed.
37965
37966 The following scripts are currently available:
37967 @itemize @bullet
37968
37969 @item @file{elinos.py}
37970 @pindex elinos.py
37971 @cindex ELinOS system-wide configuration script
37972 This script is useful when debugging a program on an ELinOS target.
37973 It takes advantage of the environment variables defined in a standard
37974 ELinOS environment in order to determine the location of the system
37975 shared libraries, and then sets the @samp{solib-absolute-prefix}
37976 and @samp{solib-search-path} variables appropriately.
37977
37978 @item @file{wrs-linux.py}
37979 @pindex wrs-linux.py
37980 @cindex Wind River Linux system-wide configuration script
37981 This script is useful when debugging a program on a target running
37982 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
37983 the host-side sysroot used by the target system.
37984
37985 @end itemize
37986
37987 @node Maintenance Commands
37988 @appendix Maintenance Commands
37989 @cindex maintenance commands
37990 @cindex internal commands
37991
37992 In addition to commands intended for @value{GDBN} users, @value{GDBN}
37993 includes a number of commands intended for @value{GDBN} developers,
37994 that are not documented elsewhere in this manual. These commands are
37995 provided here for reference. (For commands that turn on debugging
37996 messages, see @ref{Debugging Output}.)
37997
37998 @table @code
37999 @kindex maint agent
38000 @kindex maint agent-eval
38001 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38002 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38003 Translate the given @var{expression} into remote agent bytecodes.
38004 This command is useful for debugging the Agent Expression mechanism
38005 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38006 expression useful for data collection, such as by tracepoints, while
38007 @samp{maint agent-eval} produces an expression that evaluates directly
38008 to a result. For instance, a collection expression for @code{globa +
38009 globb} will include bytecodes to record four bytes of memory at each
38010 of the addresses of @code{globa} and @code{globb}, while discarding
38011 the result of the addition, while an evaluation expression will do the
38012 addition and return the sum.
38013 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38014 If not, generate remote agent bytecode for current frame PC address.
38015
38016 @kindex maint agent-printf
38017 @item maint agent-printf @var{format},@var{expr},...
38018 Translate the given format string and list of argument expressions
38019 into remote agent bytecodes and display them as a disassembled list.
38020 This command is useful for debugging the agent version of dynamic
38021 printf (@pxref{Dynamic Printf}).
38022
38023 @kindex maint info breakpoints
38024 @item @anchor{maint info breakpoints}maint info breakpoints
38025 Using the same format as @samp{info breakpoints}, display both the
38026 breakpoints you've set explicitly, and those @value{GDBN} is using for
38027 internal purposes. Internal breakpoints are shown with negative
38028 breakpoint numbers. The type column identifies what kind of breakpoint
38029 is shown:
38030
38031 @table @code
38032 @item breakpoint
38033 Normal, explicitly set breakpoint.
38034
38035 @item watchpoint
38036 Normal, explicitly set watchpoint.
38037
38038 @item longjmp
38039 Internal breakpoint, used to handle correctly stepping through
38040 @code{longjmp} calls.
38041
38042 @item longjmp resume
38043 Internal breakpoint at the target of a @code{longjmp}.
38044
38045 @item until
38046 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38047
38048 @item finish
38049 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38050
38051 @item shlib events
38052 Shared library events.
38053
38054 @end table
38055
38056 @kindex maint info btrace
38057 @item maint info btrace
38058 Pint information about raw branch tracing data.
38059
38060 @kindex maint btrace packet-history
38061 @item maint btrace packet-history
38062 Print the raw branch trace packets that are used to compute the
38063 execution history for the @samp{record btrace} command. Both the
38064 information and the format in which it is printed depend on the btrace
38065 recording format.
38066
38067 @table @code
38068 @item bts
38069 For the BTS recording format, print a list of blocks of sequential
38070 code. For each block, the following information is printed:
38071
38072 @table @asis
38073 @item Block number
38074 Newer blocks have higher numbers. The oldest block has number zero.
38075 @item Lowest @samp{PC}
38076 @item Highest @samp{PC}
38077 @end table
38078
38079 @item pt
38080 For the Intel Processor Trace recording format, print a list of
38081 Intel Processor Trace packets. For each packet, the following
38082 information is printed:
38083
38084 @table @asis
38085 @item Packet number
38086 Newer packets have higher numbers. The oldest packet has number zero.
38087 @item Trace offset
38088 The packet's offset in the trace stream.
38089 @item Packet opcode and payload
38090 @end table
38091 @end table
38092
38093 @kindex maint btrace clear-packet-history
38094 @item maint btrace clear-packet-history
38095 Discards the cached packet history printed by the @samp{maint btrace
38096 packet-history} command. The history will be computed again when
38097 needed.
38098
38099 @kindex maint btrace clear
38100 @item maint btrace clear
38101 Discard the branch trace data. The data will be fetched anew and the
38102 branch trace will be recomputed when needed.
38103
38104 This implicitly truncates the branch trace to a single branch trace
38105 buffer. When updating branch trace incrementally, the branch trace
38106 available to @value{GDBN} may be bigger than a single branch trace
38107 buffer.
38108
38109 @kindex maint set btrace pt skip-pad
38110 @item maint set btrace pt skip-pad
38111 @kindex maint show btrace pt skip-pad
38112 @item maint show btrace pt skip-pad
38113 Control whether @value{GDBN} will skip PAD packets when computing the
38114 packet history.
38115
38116 @kindex set displaced-stepping
38117 @kindex show displaced-stepping
38118 @cindex displaced stepping support
38119 @cindex out-of-line single-stepping
38120 @item set displaced-stepping
38121 @itemx show displaced-stepping
38122 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38123 if the target supports it. Displaced stepping is a way to single-step
38124 over breakpoints without removing them from the inferior, by executing
38125 an out-of-line copy of the instruction that was originally at the
38126 breakpoint location. It is also known as out-of-line single-stepping.
38127
38128 @table @code
38129 @item set displaced-stepping on
38130 If the target architecture supports it, @value{GDBN} will use
38131 displaced stepping to step over breakpoints.
38132
38133 @item set displaced-stepping off
38134 @value{GDBN} will not use displaced stepping to step over breakpoints,
38135 even if such is supported by the target architecture.
38136
38137 @cindex non-stop mode, and @samp{set displaced-stepping}
38138 @item set displaced-stepping auto
38139 This is the default mode. @value{GDBN} will use displaced stepping
38140 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38141 architecture supports displaced stepping.
38142 @end table
38143
38144 @kindex maint check-psymtabs
38145 @item maint check-psymtabs
38146 Check the consistency of currently expanded psymtabs versus symtabs.
38147 Use this to check, for example, whether a symbol is in one but not the other.
38148
38149 @kindex maint check-symtabs
38150 @item maint check-symtabs
38151 Check the consistency of currently expanded symtabs.
38152
38153 @kindex maint expand-symtabs
38154 @item maint expand-symtabs [@var{regexp}]
38155 Expand symbol tables.
38156 If @var{regexp} is specified, only expand symbol tables for file
38157 names matching @var{regexp}.
38158
38159 @kindex maint set catch-demangler-crashes
38160 @kindex maint show catch-demangler-crashes
38161 @cindex demangler crashes
38162 @item maint set catch-demangler-crashes [on|off]
38163 @itemx maint show catch-demangler-crashes
38164 Control whether @value{GDBN} should attempt to catch crashes in the
38165 symbol name demangler. The default is to attempt to catch crashes.
38166 If enabled, the first time a crash is caught, a core file is created,
38167 the offending symbol is displayed and the user is presented with the
38168 option to terminate the current session.
38169
38170 @kindex maint cplus first_component
38171 @item maint cplus first_component @var{name}
38172 Print the first C@t{++} class/namespace component of @var{name}.
38173
38174 @kindex maint cplus namespace
38175 @item maint cplus namespace
38176 Print the list of possible C@t{++} namespaces.
38177
38178 @kindex maint deprecate
38179 @kindex maint undeprecate
38180 @cindex deprecated commands
38181 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38182 @itemx maint undeprecate @var{command}
38183 Deprecate or undeprecate the named @var{command}. Deprecated commands
38184 cause @value{GDBN} to issue a warning when you use them. The optional
38185 argument @var{replacement} says which newer command should be used in
38186 favor of the deprecated one; if it is given, @value{GDBN} will mention
38187 the replacement as part of the warning.
38188
38189 @kindex maint dump-me
38190 @item maint dump-me
38191 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38192 Cause a fatal signal in the debugger and force it to dump its core.
38193 This is supported only on systems which support aborting a program
38194 with the @code{SIGQUIT} signal.
38195
38196 @kindex maint internal-error
38197 @kindex maint internal-warning
38198 @kindex maint demangler-warning
38199 @cindex demangler crashes
38200 @item maint internal-error @r{[}@var{message-text}@r{]}
38201 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38202 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38203
38204 Cause @value{GDBN} to call the internal function @code{internal_error},
38205 @code{internal_warning} or @code{demangler_warning} and hence behave
38206 as though an internal problem has been detected. In addition to
38207 reporting the internal problem, these functions give the user the
38208 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38209 and @code{internal_warning}) create a core file of the current
38210 @value{GDBN} session.
38211
38212 These commands take an optional parameter @var{message-text} that is
38213 used as the text of the error or warning message.
38214
38215 Here's an example of using @code{internal-error}:
38216
38217 @smallexample
38218 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38219 @dots{}/maint.c:121: internal-error: testing, 1, 2
38220 A problem internal to GDB has been detected. Further
38221 debugging may prove unreliable.
38222 Quit this debugging session? (y or n) @kbd{n}
38223 Create a core file? (y or n) @kbd{n}
38224 (@value{GDBP})
38225 @end smallexample
38226
38227 @cindex @value{GDBN} internal error
38228 @cindex internal errors, control of @value{GDBN} behavior
38229 @cindex demangler crashes
38230
38231 @kindex maint set internal-error
38232 @kindex maint show internal-error
38233 @kindex maint set internal-warning
38234 @kindex maint show internal-warning
38235 @kindex maint set demangler-warning
38236 @kindex maint show demangler-warning
38237 @item maint set internal-error @var{action} [ask|yes|no]
38238 @itemx maint show internal-error @var{action}
38239 @itemx maint set internal-warning @var{action} [ask|yes|no]
38240 @itemx maint show internal-warning @var{action}
38241 @itemx maint set demangler-warning @var{action} [ask|yes|no]
38242 @itemx maint show demangler-warning @var{action}
38243 When @value{GDBN} reports an internal problem (error or warning) it
38244 gives the user the opportunity to both quit @value{GDBN} and create a
38245 core file of the current @value{GDBN} session. These commands let you
38246 override the default behaviour for each particular @var{action},
38247 described in the table below.
38248
38249 @table @samp
38250 @item quit
38251 You can specify that @value{GDBN} should always (yes) or never (no)
38252 quit. The default is to ask the user what to do.
38253
38254 @item corefile
38255 You can specify that @value{GDBN} should always (yes) or never (no)
38256 create a core file. The default is to ask the user what to do. Note
38257 that there is no @code{corefile} option for @code{demangler-warning}:
38258 demangler warnings always create a core file and this cannot be
38259 disabled.
38260 @end table
38261
38262 @kindex maint packet
38263 @item maint packet @var{text}
38264 If @value{GDBN} is talking to an inferior via the serial protocol,
38265 then this command sends the string @var{text} to the inferior, and
38266 displays the response packet. @value{GDBN} supplies the initial
38267 @samp{$} character, the terminating @samp{#} character, and the
38268 checksum.
38269
38270 @kindex maint print architecture
38271 @item maint print architecture @r{[}@var{file}@r{]}
38272 Print the entire architecture configuration. The optional argument
38273 @var{file} names the file where the output goes.
38274
38275 @kindex maint print c-tdesc @r{[}@var{file}@r{]}
38276 @item maint print c-tdesc
38277 Print the target description (@pxref{Target Descriptions}) as
38278 a C source file. By default, the target description is for the current
38279 target, but if the optional argument @var{file} is provided, that file
38280 is used to produce the description. The @var{file} should be an XML
38281 document, of the form described in @ref{Target Description Format}.
38282 The created source file is built into @value{GDBN} when @value{GDBN} is
38283 built again. This command is used by developers after they add or
38284 modify XML target descriptions.
38285
38286 @kindex maint check xml-descriptions
38287 @item maint check xml-descriptions @var{dir}
38288 Check that the target descriptions dynamically created by @value{GDBN}
38289 equal the descriptions created from XML files found in @var{dir}.
38290
38291 @anchor{maint check libthread-db}
38292 @kindex maint check libthread-db
38293 @item maint check libthread-db
38294 Run integrity checks on the current inferior's thread debugging
38295 library. This exercises all @code{libthread_db} functionality used by
38296 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
38297 @code{proc_service} functions provided by @value{GDBN} that
38298 @code{libthread_db} uses. Note that parts of the test may be skipped
38299 on some platforms when debugging core files.
38300
38301 @kindex maint print dummy-frames
38302 @item maint print dummy-frames
38303 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38304
38305 @smallexample
38306 (@value{GDBP}) @kbd{b add}
38307 @dots{}
38308 (@value{GDBP}) @kbd{print add(2,3)}
38309 Breakpoint 2, add (a=2, b=3) at @dots{}
38310 58 return (a + b);
38311 The program being debugged stopped while in a function called from GDB.
38312 @dots{}
38313 (@value{GDBP}) @kbd{maint print dummy-frames}
38314 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
38315 (@value{GDBP})
38316 @end smallexample
38317
38318 Takes an optional file parameter.
38319
38320 @kindex maint print registers
38321 @kindex maint print raw-registers
38322 @kindex maint print cooked-registers
38323 @kindex maint print register-groups
38324 @kindex maint print remote-registers
38325 @item maint print registers @r{[}@var{file}@r{]}
38326 @itemx maint print raw-registers @r{[}@var{file}@r{]}
38327 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
38328 @itemx maint print register-groups @r{[}@var{file}@r{]}
38329 @itemx maint print remote-registers @r{[}@var{file}@r{]}
38330 Print @value{GDBN}'s internal register data structures.
38331
38332 The command @code{maint print raw-registers} includes the contents of
38333 the raw register cache; the command @code{maint print
38334 cooked-registers} includes the (cooked) value of all registers,
38335 including registers which aren't available on the target nor visible
38336 to user; the command @code{maint print register-groups} includes the
38337 groups that each register is a member of; and the command @code{maint
38338 print remote-registers} includes the remote target's register numbers
38339 and offsets in the `G' packets.
38340
38341 These commands take an optional parameter, a file name to which to
38342 write the information.
38343
38344 @kindex maint print reggroups
38345 @item maint print reggroups @r{[}@var{file}@r{]}
38346 Print @value{GDBN}'s internal register group data structures. The
38347 optional argument @var{file} tells to what file to write the
38348 information.
38349
38350 The register groups info looks like this:
38351
38352 @smallexample
38353 (@value{GDBP}) @kbd{maint print reggroups}
38354 Group Type
38355 general user
38356 float user
38357 all user
38358 vector user
38359 system user
38360 save internal
38361 restore internal
38362 @end smallexample
38363
38364 @kindex flushregs
38365 @item flushregs
38366 This command forces @value{GDBN} to flush its internal register cache.
38367
38368 @kindex maint print objfiles
38369 @cindex info for known object files
38370 @item maint print objfiles @r{[}@var{regexp}@r{]}
38371 Print a dump of all known object files.
38372 If @var{regexp} is specified, only print object files whose names
38373 match @var{regexp}. For each object file, this command prints its name,
38374 address in memory, and all of its psymtabs and symtabs.
38375
38376 @kindex maint print user-registers
38377 @cindex user registers
38378 @item maint print user-registers
38379 List all currently available @dfn{user registers}. User registers
38380 typically provide alternate names for actual hardware registers. They
38381 include the four ``standard'' registers @code{$fp}, @code{$pc},
38382 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
38383 registers can be used in expressions in the same way as the canonical
38384 register names, but only the latter are listed by the @code{info
38385 registers} and @code{maint print registers} commands.
38386
38387 @kindex maint print section-scripts
38388 @cindex info for known .debug_gdb_scripts-loaded scripts
38389 @item maint print section-scripts [@var{regexp}]
38390 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38391 If @var{regexp} is specified, only print scripts loaded by object files
38392 matching @var{regexp}.
38393 For each script, this command prints its name as specified in the objfile,
38394 and the full path if known.
38395 @xref{dotdebug_gdb_scripts section}.
38396
38397 @kindex maint print statistics
38398 @cindex bcache statistics
38399 @item maint print statistics
38400 This command prints, for each object file in the program, various data
38401 about that object file followed by the byte cache (@dfn{bcache})
38402 statistics for the object file. The objfile data includes the number
38403 of minimal, partial, full, and stabs symbols, the number of types
38404 defined by the objfile, the number of as yet unexpanded psym tables,
38405 the number of line tables and string tables, and the amount of memory
38406 used by the various tables. The bcache statistics include the counts,
38407 sizes, and counts of duplicates of all and unique objects, max,
38408 average, and median entry size, total memory used and its overhead and
38409 savings, and various measures of the hash table size and chain
38410 lengths.
38411
38412 @kindex maint print target-stack
38413 @cindex target stack description
38414 @item maint print target-stack
38415 A @dfn{target} is an interface between the debugger and a particular
38416 kind of file or process. Targets can be stacked in @dfn{strata},
38417 so that more than one target can potentially respond to a request.
38418 In particular, memory accesses will walk down the stack of targets
38419 until they find a target that is interested in handling that particular
38420 address.
38421
38422 This command prints a short description of each layer that was pushed on
38423 the @dfn{target stack}, starting from the top layer down to the bottom one.
38424
38425 @kindex maint print type
38426 @cindex type chain of a data type
38427 @item maint print type @var{expr}
38428 Print the type chain for a type specified by @var{expr}. The argument
38429 can be either a type name or a symbol. If it is a symbol, the type of
38430 that symbol is described. The type chain produced by this command is
38431 a recursive definition of the data type as stored in @value{GDBN}'s
38432 data structures, including its flags and contained types.
38433
38434 @kindex maint selftest
38435 @cindex self tests
38436 @item maint selftest @r{[}@var{filter}@r{]}
38437 Run any self tests that were compiled in to @value{GDBN}. This will
38438 print a message showing how many tests were run, and how many failed.
38439 If a @var{filter} is passed, only the tests with @var{filter} in their
38440 name will by ran.
38441
38442 @kindex maint info selftests
38443 @cindex self tests
38444 @item maint info selftests
38445 List the selftests compiled in to @value{GDBN}.
38446
38447 @kindex maint set dwarf always-disassemble
38448 @kindex maint show dwarf always-disassemble
38449 @item maint set dwarf always-disassemble
38450 @item maint show dwarf always-disassemble
38451 Control the behavior of @code{info address} when using DWARF debugging
38452 information.
38453
38454 The default is @code{off}, which means that @value{GDBN} should try to
38455 describe a variable's location in an easily readable format. When
38456 @code{on}, @value{GDBN} will instead display the DWARF location
38457 expression in an assembly-like format. Note that some locations are
38458 too complex for @value{GDBN} to describe simply; in this case you will
38459 always see the disassembly form.
38460
38461 Here is an example of the resulting disassembly:
38462
38463 @smallexample
38464 (gdb) info addr argc
38465 Symbol "argc" is a complex DWARF expression:
38466 1: DW_OP_fbreg 0
38467 @end smallexample
38468
38469 For more information on these expressions, see
38470 @uref{http://www.dwarfstd.org/, the DWARF standard}.
38471
38472 @kindex maint set dwarf max-cache-age
38473 @kindex maint show dwarf max-cache-age
38474 @item maint set dwarf max-cache-age
38475 @itemx maint show dwarf max-cache-age
38476 Control the DWARF compilation unit cache.
38477
38478 @cindex DWARF compilation units cache
38479 In object files with inter-compilation-unit references, such as those
38480 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
38481 reader needs to frequently refer to previously read compilation units.
38482 This setting controls how long a compilation unit will remain in the
38483 cache if it is not referenced. A higher limit means that cached
38484 compilation units will be stored in memory longer, and more total
38485 memory will be used. Setting it to zero disables caching, which will
38486 slow down @value{GDBN} startup, but reduce memory consumption.
38487
38488 @kindex maint set dwarf unwinders
38489 @kindex maint show dwarf unwinders
38490 @item maint set dwarf unwinders
38491 @itemx maint show dwarf unwinders
38492 Control use of the DWARF frame unwinders.
38493
38494 @cindex DWARF frame unwinders
38495 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38496 frame unwinders to build the backtrace. Many of these targets will
38497 also have a second mechanism for building the backtrace for use in
38498 cases where DWARF information is not available, this second mechanism
38499 is often an analysis of a function's prologue.
38500
38501 In order to extend testing coverage of the second level stack
38502 unwinding mechanisms it is helpful to be able to disable the DWARF
38503 stack unwinders, this can be done with this switch.
38504
38505 In normal use of @value{GDBN} disabling the DWARF unwinders is not
38506 advisable, there are cases that are better handled through DWARF than
38507 prologue analysis, and the debug experience is likely to be better
38508 with the DWARF frame unwinders enabled.
38509
38510 If DWARF frame unwinders are not supported for a particular target
38511 architecture, then enabling this flag does not cause them to be used.
38512
38513 @kindex maint set worker-threads
38514 @kindex maint show worker-threads
38515 @item maint set worker-threads
38516 @item maint show worker-threads
38517 Control the number of worker threads that may be used by @value{GDBN}.
38518 On capable hosts, @value{GDBN} may use multiple threads to speed up
38519 certain CPU-intensive operations, such as demangling symbol names.
38520 While the number of threads used by @value{GDBN} may vary, this
38521 command can be used to set an upper bound on this number. The default
38522 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38523 number. Note that this only controls worker threads started by
38524 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
38525 of their own.
38526
38527 @kindex maint set profile
38528 @kindex maint show profile
38529 @cindex profiling GDB
38530 @item maint set profile
38531 @itemx maint show profile
38532 Control profiling of @value{GDBN}.
38533
38534 Profiling will be disabled until you use the @samp{maint set profile}
38535 command to enable it. When you enable profiling, the system will begin
38536 collecting timing and execution count data; when you disable profiling or
38537 exit @value{GDBN}, the results will be written to a log file. Remember that
38538 if you use profiling, @value{GDBN} will overwrite the profiling log file
38539 (often called @file{gmon.out}). If you have a record of important profiling
38540 data in a @file{gmon.out} file, be sure to move it to a safe location.
38541
38542 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
38543 compiled with the @samp{-pg} compiler option.
38544
38545 @kindex maint set show-debug-regs
38546 @kindex maint show show-debug-regs
38547 @cindex hardware debug registers
38548 @item maint set show-debug-regs
38549 @itemx maint show show-debug-regs
38550 Control whether to show variables that mirror the hardware debug
38551 registers. Use @code{on} to enable, @code{off} to disable. If
38552 enabled, the debug registers values are shown when @value{GDBN} inserts or
38553 removes a hardware breakpoint or watchpoint, and when the inferior
38554 triggers a hardware-assisted breakpoint or watchpoint.
38555
38556 @kindex maint set show-all-tib
38557 @kindex maint show show-all-tib
38558 @item maint set show-all-tib
38559 @itemx maint show show-all-tib
38560 Control whether to show all non zero areas within a 1k block starting
38561 at thread local base, when using the @samp{info w32 thread-information-block}
38562 command.
38563
38564 @kindex maint set target-async
38565 @kindex maint show target-async
38566 @item maint set target-async
38567 @itemx maint show target-async
38568 This controls whether @value{GDBN} targets operate in synchronous or
38569 asynchronous mode (@pxref{Background Execution}). Normally the
38570 default is asynchronous, if it is available; but this can be changed
38571 to more easily debug problems occurring only in synchronous mode.
38572
38573 @kindex maint set target-non-stop @var{mode} [on|off|auto]
38574 @kindex maint show target-non-stop
38575 @item maint set target-non-stop
38576 @itemx maint show target-non-stop
38577
38578 This controls whether @value{GDBN} targets always operate in non-stop
38579 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38580 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38581 if supported by the target.
38582
38583 @table @code
38584 @item maint set target-non-stop auto
38585 This is the default mode. @value{GDBN} controls the target in
38586 non-stop mode if the target supports it.
38587
38588 @item maint set target-non-stop on
38589 @value{GDBN} controls the target in non-stop mode even if the target
38590 does not indicate support.
38591
38592 @item maint set target-non-stop off
38593 @value{GDBN} does not control the target in non-stop mode even if the
38594 target supports it.
38595 @end table
38596
38597 @kindex maint set tui-resize-message
38598 @kindex maint show tui-resize-message
38599 @item maint set tui-resize-message
38600 @item maint show tui-resize-message
38601 Control whether @value{GDBN} displays a message each time the terminal
38602 is resized when in TUI mode. The default is @code{off}, which means
38603 that @value{GDBN} is silent during resizes. When @code{on},
38604 @value{GDBN} will display a message after a resize is completed; the
38605 message will include a number indicating how many times the terminal
38606 has been resized. This setting is intended for use by the test suite,
38607 where it would otherwise be difficult to determine when a resize and
38608 refresh has been completed.
38609
38610 @kindex maint set per-command
38611 @kindex maint show per-command
38612 @item maint set per-command
38613 @itemx maint show per-command
38614 @cindex resources used by commands
38615
38616 @value{GDBN} can display the resources used by each command.
38617 This is useful in debugging performance problems.
38618
38619 @table @code
38620 @item maint set per-command space [on|off]
38621 @itemx maint show per-command space
38622 Enable or disable the printing of the memory used by GDB for each command.
38623 If enabled, @value{GDBN} will display how much memory each command
38624 took, following the command's own output.
38625 This can also be requested by invoking @value{GDBN} with the
38626 @option{--statistics} command-line switch (@pxref{Mode Options}).
38627
38628 @item maint set per-command time [on|off]
38629 @itemx maint show per-command time
38630 Enable or disable the printing of the execution time of @value{GDBN}
38631 for each command.
38632 If enabled, @value{GDBN} will display how much time it
38633 took to execute each command, following the command's own output.
38634 Both CPU time and wallclock time are printed.
38635 Printing both is useful when trying to determine whether the cost is
38636 CPU or, e.g., disk/network latency.
38637 Note that the CPU time printed is for @value{GDBN} only, it does not include
38638 the execution time of the inferior because there's no mechanism currently
38639 to compute how much time was spent by @value{GDBN} and how much time was
38640 spent by the program been debugged.
38641 This can also be requested by invoking @value{GDBN} with the
38642 @option{--statistics} command-line switch (@pxref{Mode Options}).
38643
38644 @item maint set per-command symtab [on|off]
38645 @itemx maint show per-command symtab
38646 Enable or disable the printing of basic symbol table statistics
38647 for each command.
38648 If enabled, @value{GDBN} will display the following information:
38649
38650 @enumerate a
38651 @item
38652 number of symbol tables
38653 @item
38654 number of primary symbol tables
38655 @item
38656 number of blocks in the blockvector
38657 @end enumerate
38658 @end table
38659
38660 @kindex maint set check-libthread-db
38661 @kindex maint show check-libthread-db
38662 @item maint set check-libthread-db [on|off]
38663 @itemx maint show check-libthread-db
38664 Control whether @value{GDBN} should run integrity checks on inferior
38665 specific thread debugging libraries as they are loaded. The default
38666 is not to perform such checks. If any check fails @value{GDBN} will
38667 unload the library and continue searching for a suitable candidate as
38668 described in @ref{set libthread-db-search-path}. For more information
38669 about the tests, see @ref{maint check libthread-db}.
38670
38671 @kindex maint space
38672 @cindex memory used by commands
38673 @item maint space @var{value}
38674 An alias for @code{maint set per-command space}.
38675 A non-zero value enables it, zero disables it.
38676
38677 @kindex maint time
38678 @cindex time of command execution
38679 @item maint time @var{value}
38680 An alias for @code{maint set per-command time}.
38681 A non-zero value enables it, zero disables it.
38682
38683 @kindex maint translate-address
38684 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38685 Find the symbol stored at the location specified by the address
38686 @var{addr} and an optional section name @var{section}. If found,
38687 @value{GDBN} prints the name of the closest symbol and an offset from
38688 the symbol's location to the specified address. This is similar to
38689 the @code{info address} command (@pxref{Symbols}), except that this
38690 command also allows to find symbols in other sections.
38691
38692 If section was not specified, the section in which the symbol was found
38693 is also printed. For dynamically linked executables, the name of
38694 executable or shared library containing the symbol is printed as well.
38695
38696 @kindex maint test-options
38697 @item maint test-options require-delimiter
38698 @itemx maint test-options unknown-is-error
38699 @itemx maint test-options unknown-is-operand
38700 These commands are used by the testsuite to validate the command
38701 options framework. The @code{require-delimiter} variant requires a
38702 double-dash delimiter to indicate end of options. The
38703 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
38704 @code{unknown-is-error} variant throws an error on unknown option,
38705 while @code{unknown-is-operand} treats unknown options as the start of
38706 the command's operands. When run, the commands output the result of
38707 the processed options. When completed, the commands store the
38708 internal result of completion in a variable exposed by the @code{maint
38709 show test-options-completion-result} command.
38710
38711 @kindex maint show test-options-completion-result
38712 @item maint show test-options-completion-result
38713 Shows the result of completing the @code{maint test-options}
38714 subcommands. This is used by the testsuite to validate completion
38715 support in the command options framework.
38716
38717 @kindex maint set test-settings
38718 @kindex maint show test-settings
38719 @item maint set test-settings @var{kind}
38720 @itemx maint show test-settings @var{kind}
38721 These are representative commands for each @var{kind} of setting type
38722 @value{GDBN} supports. They are used by the testsuite for exercising
38723 the settings infrastructure.
38724
38725 @kindex maint with
38726 @item maint with @var{setting} [@var{value}] [-- @var{command}]
38727 Like the @code{with} command, but works with @code{maintenance set}
38728 variables. This is used by the testsuite to exercise the @code{with}
38729 command's infrastructure.
38730
38731 @end table
38732
38733 The following command is useful for non-interactive invocations of
38734 @value{GDBN}, such as in the test suite.
38735
38736 @table @code
38737 @item set watchdog @var{nsec}
38738 @kindex set watchdog
38739 @cindex watchdog timer
38740 @cindex timeout for commands
38741 Set the maximum number of seconds @value{GDBN} will wait for the
38742 target operation to finish. If this time expires, @value{GDBN}
38743 reports and error and the command is aborted.
38744
38745 @item show watchdog
38746 Show the current setting of the target wait timeout.
38747 @end table
38748
38749 @node Remote Protocol
38750 @appendix @value{GDBN} Remote Serial Protocol
38751
38752 @menu
38753 * Overview::
38754 * Packets::
38755 * Stop Reply Packets::
38756 * General Query Packets::
38757 * Architecture-Specific Protocol Details::
38758 * Tracepoint Packets::
38759 * Host I/O Packets::
38760 * Interrupts::
38761 * Notification Packets::
38762 * Remote Non-Stop::
38763 * Packet Acknowledgment::
38764 * Examples::
38765 * File-I/O Remote Protocol Extension::
38766 * Library List Format::
38767 * Library List Format for SVR4 Targets::
38768 * Memory Map Format::
38769 * Thread List Format::
38770 * Traceframe Info Format::
38771 * Branch Trace Format::
38772 * Branch Trace Configuration Format::
38773 @end menu
38774
38775 @node Overview
38776 @section Overview
38777
38778 There may be occasions when you need to know something about the
38779 protocol---for example, if there is only one serial port to your target
38780 machine, you might want your program to do something special if it
38781 recognizes a packet meant for @value{GDBN}.
38782
38783 In the examples below, @samp{->} and @samp{<-} are used to indicate
38784 transmitted and received data, respectively.
38785
38786 @cindex protocol, @value{GDBN} remote serial
38787 @cindex serial protocol, @value{GDBN} remote
38788 @cindex remote serial protocol
38789 All @value{GDBN} commands and responses (other than acknowledgments
38790 and notifications, see @ref{Notification Packets}) are sent as a
38791 @var{packet}. A @var{packet} is introduced with the character
38792 @samp{$}, the actual @var{packet-data}, and the terminating character
38793 @samp{#} followed by a two-digit @var{checksum}:
38794
38795 @smallexample
38796 @code{$}@var{packet-data}@code{#}@var{checksum}
38797 @end smallexample
38798 @noindent
38799
38800 @cindex checksum, for @value{GDBN} remote
38801 @noindent
38802 The two-digit @var{checksum} is computed as the modulo 256 sum of all
38803 characters between the leading @samp{$} and the trailing @samp{#} (an
38804 eight bit unsigned checksum).
38805
38806 Implementors should note that prior to @value{GDBN} 5.0 the protocol
38807 specification also included an optional two-digit @var{sequence-id}:
38808
38809 @smallexample
38810 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
38811 @end smallexample
38812
38813 @cindex sequence-id, for @value{GDBN} remote
38814 @noindent
38815 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
38816 has never output @var{sequence-id}s. Stubs that handle packets added
38817 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
38818
38819 When either the host or the target machine receives a packet, the first
38820 response expected is an acknowledgment: either @samp{+} (to indicate
38821 the package was received correctly) or @samp{-} (to request
38822 retransmission):
38823
38824 @smallexample
38825 -> @code{$}@var{packet-data}@code{#}@var{checksum}
38826 <- @code{+}
38827 @end smallexample
38828 @noindent
38829
38830 The @samp{+}/@samp{-} acknowledgments can be disabled
38831 once a connection is established.
38832 @xref{Packet Acknowledgment}, for details.
38833
38834 The host (@value{GDBN}) sends @var{command}s, and the target (the
38835 debugging stub incorporated in your program) sends a @var{response}. In
38836 the case of step and continue @var{command}s, the response is only sent
38837 when the operation has completed, and the target has again stopped all
38838 threads in all attached processes. This is the default all-stop mode
38839 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
38840 execution mode; see @ref{Remote Non-Stop}, for details.
38841
38842 @var{packet-data} consists of a sequence of characters with the
38843 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
38844 exceptions).
38845
38846 @cindex remote protocol, field separator
38847 Fields within the packet should be separated using @samp{,} @samp{;} or
38848 @samp{:}. Except where otherwise noted all numbers are represented in
38849 @sc{hex} with leading zeros suppressed.
38850
38851 Implementors should note that prior to @value{GDBN} 5.0, the character
38852 @samp{:} could not appear as the third character in a packet (as it
38853 would potentially conflict with the @var{sequence-id}).
38854
38855 @cindex remote protocol, binary data
38856 @anchor{Binary Data}
38857 Binary data in most packets is encoded either as two hexadecimal
38858 digits per byte of binary data. This allowed the traditional remote
38859 protocol to work over connections which were only seven-bit clean.
38860 Some packets designed more recently assume an eight-bit clean
38861 connection, and use a more efficient encoding to send and receive
38862 binary data.
38863
38864 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
38865 as an escape character. Any escaped byte is transmitted as the escape
38866 character followed by the original character XORed with @code{0x20}.
38867 For example, the byte @code{0x7d} would be transmitted as the two
38868 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
38869 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
38870 @samp{@}}) must always be escaped. Responses sent by the stub
38871 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
38872 is not interpreted as the start of a run-length encoded sequence
38873 (described next).
38874
38875 Response @var{data} can be run-length encoded to save space.
38876 Run-length encoding replaces runs of identical characters with one
38877 instance of the repeated character, followed by a @samp{*} and a
38878 repeat count. The repeat count is itself sent encoded, to avoid
38879 binary characters in @var{data}: a value of @var{n} is sent as
38880 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
38881 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
38882 code 32) for a repeat count of 3. (This is because run-length
38883 encoding starts to win for counts 3 or more.) Thus, for example,
38884 @samp{0* } is a run-length encoding of ``0000'': the space character
38885 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
38886 3}} more times.
38887
38888 The printable characters @samp{#} and @samp{$} or with a numeric value
38889 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
38890 seven repeats (@samp{$}) can be expanded using a repeat count of only
38891 five (@samp{"}). For example, @samp{00000000} can be encoded as
38892 @samp{0*"00}.
38893
38894 The error response returned for some packets includes a two character
38895 error number. That number is not well defined.
38896
38897 @cindex empty response, for unsupported packets
38898 For any @var{command} not supported by the stub, an empty response
38899 (@samp{$#00}) should be returned. That way it is possible to extend the
38900 protocol. A newer @value{GDBN} can tell if a packet is supported based
38901 on that response.
38902
38903 At a minimum, a stub is required to support the @samp{g} and @samp{G}
38904 commands for register access, and the @samp{m} and @samp{M} commands
38905 for memory access. Stubs that only control single-threaded targets
38906 can implement run control with the @samp{c} (continue), and @samp{s}
38907 (step) commands. Stubs that support multi-threading targets should
38908 support the @samp{vCont} command. All other commands are optional.
38909
38910 @node Packets
38911 @section Packets
38912
38913 The following table provides a complete list of all currently defined
38914 @var{command}s and their corresponding response @var{data}.
38915 @xref{File-I/O Remote Protocol Extension}, for details about the File
38916 I/O extension of the remote protocol.
38917
38918 Each packet's description has a template showing the packet's overall
38919 syntax, followed by an explanation of the packet's meaning. We
38920 include spaces in some of the templates for clarity; these are not
38921 part of the packet's syntax. No @value{GDBN} packet uses spaces to
38922 separate its components. For example, a template like @samp{foo
38923 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
38924 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
38925 @var{baz}. @value{GDBN} does not transmit a space character between the
38926 @samp{foo} and the @var{bar}, or between the @var{bar} and the
38927 @var{baz}.
38928
38929 @cindex @var{thread-id}, in remote protocol
38930 @anchor{thread-id syntax}
38931 Several packets and replies include a @var{thread-id} field to identify
38932 a thread. Normally these are positive numbers with a target-specific
38933 interpretation, formatted as big-endian hex strings. A @var{thread-id}
38934 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
38935 pick any thread.
38936
38937 In addition, the remote protocol supports a multiprocess feature in
38938 which the @var{thread-id} syntax is extended to optionally include both
38939 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
38940 The @var{pid} (process) and @var{tid} (thread) components each have the
38941 format described above: a positive number with target-specific
38942 interpretation formatted as a big-endian hex string, literal @samp{-1}
38943 to indicate all processes or threads (respectively), or @samp{0} to
38944 indicate an arbitrary process or thread. Specifying just a process, as
38945 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
38946 error to specify all processes but a specific thread, such as
38947 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
38948 for those packets and replies explicitly documented to include a process
38949 ID, rather than a @var{thread-id}.
38950
38951 The multiprocess @var{thread-id} syntax extensions are only used if both
38952 @value{GDBN} and the stub report support for the @samp{multiprocess}
38953 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
38954 more information.
38955
38956 Note that all packet forms beginning with an upper- or lower-case
38957 letter, other than those described here, are reserved for future use.
38958
38959 Here are the packet descriptions.
38960
38961 @table @samp
38962
38963 @item !
38964 @cindex @samp{!} packet
38965 @anchor{extended mode}
38966 Enable extended mode. In extended mode, the remote server is made
38967 persistent. The @samp{R} packet is used to restart the program being
38968 debugged.
38969
38970 Reply:
38971 @table @samp
38972 @item OK
38973 The remote target both supports and has enabled extended mode.
38974 @end table
38975
38976 @item ?
38977 @cindex @samp{?} packet
38978 @anchor{? packet}
38979 Indicate the reason the target halted. The reply is the same as for
38980 step and continue. This packet has a special interpretation when the
38981 target is in non-stop mode; see @ref{Remote Non-Stop}.
38982
38983 Reply:
38984 @xref{Stop Reply Packets}, for the reply specifications.
38985
38986 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
38987 @cindex @samp{A} packet
38988 Initialized @code{argv[]} array passed into program. @var{arglen}
38989 specifies the number of bytes in the hex encoded byte stream
38990 @var{arg}. See @code{gdbserver} for more details.
38991
38992 Reply:
38993 @table @samp
38994 @item OK
38995 The arguments were set.
38996 @item E @var{NN}
38997 An error occurred.
38998 @end table
38999
39000 @item b @var{baud}
39001 @cindex @samp{b} packet
39002 (Don't use this packet; its behavior is not well-defined.)
39003 Change the serial line speed to @var{baud}.
39004
39005 JTC: @emph{When does the transport layer state change? When it's
39006 received, or after the ACK is transmitted. In either case, there are
39007 problems if the command or the acknowledgment packet is dropped.}
39008
39009 Stan: @emph{If people really wanted to add something like this, and get
39010 it working for the first time, they ought to modify ser-unix.c to send
39011 some kind of out-of-band message to a specially-setup stub and have the
39012 switch happen "in between" packets, so that from remote protocol's point
39013 of view, nothing actually happened.}
39014
39015 @item B @var{addr},@var{mode}
39016 @cindex @samp{B} packet
39017 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39018 breakpoint at @var{addr}.
39019
39020 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39021 (@pxref{insert breakpoint or watchpoint packet}).
39022
39023 @cindex @samp{bc} packet
39024 @anchor{bc}
39025 @item bc
39026 Backward continue. Execute the target system in reverse. No parameter.
39027 @xref{Reverse Execution}, for more information.
39028
39029 Reply:
39030 @xref{Stop Reply Packets}, for the reply specifications.
39031
39032 @cindex @samp{bs} packet
39033 @anchor{bs}
39034 @item bs
39035 Backward single step. Execute one instruction in reverse. No parameter.
39036 @xref{Reverse Execution}, for more information.
39037
39038 Reply:
39039 @xref{Stop Reply Packets}, for the reply specifications.
39040
39041 @item c @r{[}@var{addr}@r{]}
39042 @cindex @samp{c} packet
39043 Continue at @var{addr}, which is the address to resume. If @var{addr}
39044 is omitted, resume at current address.
39045
39046 This packet is deprecated for multi-threading support. @xref{vCont
39047 packet}.
39048
39049 Reply:
39050 @xref{Stop Reply Packets}, for the reply specifications.
39051
39052 @item C @var{sig}@r{[};@var{addr}@r{]}
39053 @cindex @samp{C} packet
39054 Continue with signal @var{sig} (hex signal number). If
39055 @samp{;@var{addr}} is omitted, resume at same address.
39056
39057 This packet is deprecated for multi-threading support. @xref{vCont
39058 packet}.
39059
39060 Reply:
39061 @xref{Stop Reply Packets}, for the reply specifications.
39062
39063 @item d
39064 @cindex @samp{d} packet
39065 Toggle debug flag.
39066
39067 Don't use this packet; instead, define a general set packet
39068 (@pxref{General Query Packets}).
39069
39070 @item D
39071 @itemx D;@var{pid}
39072 @cindex @samp{D} packet
39073 The first form of the packet is used to detach @value{GDBN} from the
39074 remote system. It is sent to the remote target
39075 before @value{GDBN} disconnects via the @code{detach} command.
39076
39077 The second form, including a process ID, is used when multiprocess
39078 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39079 detach only a specific process. The @var{pid} is specified as a
39080 big-endian hex string.
39081
39082 Reply:
39083 @table @samp
39084 @item OK
39085 for success
39086 @item E @var{NN}
39087 for an error
39088 @end table
39089
39090 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39091 @cindex @samp{F} packet
39092 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39093 This is part of the File-I/O protocol extension. @xref{File-I/O
39094 Remote Protocol Extension}, for the specification.
39095
39096 @item g
39097 @anchor{read registers packet}
39098 @cindex @samp{g} packet
39099 Read general registers.
39100
39101 Reply:
39102 @table @samp
39103 @item @var{XX@dots{}}
39104 Each byte of register data is described by two hex digits. The bytes
39105 with the register are transmitted in target byte order. The size of
39106 each register and their position within the @samp{g} packet are
39107 determined by the @value{GDBN} internal gdbarch functions
39108 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39109
39110 When reading registers from a trace frame (@pxref{Analyze Collected
39111 Data,,Using the Collected Data}), the stub may also return a string of
39112 literal @samp{x}'s in place of the register data digits, to indicate
39113 that the corresponding register has not been collected, thus its value
39114 is unavailable. For example, for an architecture with 4 registers of
39115 4 bytes each, the following reply indicates to @value{GDBN} that
39116 registers 0 and 2 have not been collected, while registers 1 and 3
39117 have been collected, and both have zero value:
39118
39119 @smallexample
39120 -> @code{g}
39121 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39122 @end smallexample
39123
39124 @item E @var{NN}
39125 for an error.
39126 @end table
39127
39128 @item G @var{XX@dots{}}
39129 @cindex @samp{G} packet
39130 Write general registers. @xref{read registers packet}, for a
39131 description of the @var{XX@dots{}} data.
39132
39133 Reply:
39134 @table @samp
39135 @item OK
39136 for success
39137 @item E @var{NN}
39138 for an error
39139 @end table
39140
39141 @item H @var{op} @var{thread-id}
39142 @cindex @samp{H} packet
39143 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39144 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39145 should be @samp{c} for step and continue operations (note that this
39146 is deprecated, supporting the @samp{vCont} command is a better
39147 option), and @samp{g} for other operations. The thread designator
39148 @var{thread-id} has the format and interpretation described in
39149 @ref{thread-id syntax}.
39150
39151 Reply:
39152 @table @samp
39153 @item OK
39154 for success
39155 @item E @var{NN}
39156 for an error
39157 @end table
39158
39159 @c FIXME: JTC:
39160 @c 'H': How restrictive (or permissive) is the thread model. If a
39161 @c thread is selected and stopped, are other threads allowed
39162 @c to continue to execute? As I mentioned above, I think the
39163 @c semantics of each command when a thread is selected must be
39164 @c described. For example:
39165 @c
39166 @c 'g': If the stub supports threads and a specific thread is
39167 @c selected, returns the register block from that thread;
39168 @c otherwise returns current registers.
39169 @c
39170 @c 'G' If the stub supports threads and a specific thread is
39171 @c selected, sets the registers of the register block of
39172 @c that thread; otherwise sets current registers.
39173
39174 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39175 @anchor{cycle step packet}
39176 @cindex @samp{i} packet
39177 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39178 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39179 step starting at that address.
39180
39181 @item I
39182 @cindex @samp{I} packet
39183 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39184 step packet}.
39185
39186 @item k
39187 @cindex @samp{k} packet
39188 Kill request.
39189
39190 The exact effect of this packet is not specified.
39191
39192 For a bare-metal target, it may power cycle or reset the target
39193 system. For that reason, the @samp{k} packet has no reply.
39194
39195 For a single-process target, it may kill that process if possible.
39196
39197 A multiple-process target may choose to kill just one process, or all
39198 that are under @value{GDBN}'s control. For more precise control, use
39199 the vKill packet (@pxref{vKill packet}).
39200
39201 If the target system immediately closes the connection in response to
39202 @samp{k}, @value{GDBN} does not consider the lack of packet
39203 acknowledgment to be an error, and assumes the kill was successful.
39204
39205 If connected using @kbd{target extended-remote}, and the target does
39206 not close the connection in response to a kill request, @value{GDBN}
39207 probes the target state as if a new connection was opened
39208 (@pxref{? packet}).
39209
39210 @item m @var{addr},@var{length}
39211 @cindex @samp{m} packet
39212 Read @var{length} addressable memory units starting at address @var{addr}
39213 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39214 any particular boundary.
39215
39216 The stub need not use any particular size or alignment when gathering
39217 data from memory for the response; even if @var{addr} is word-aligned
39218 and @var{length} is a multiple of the word size, the stub is free to
39219 use byte accesses, or not. For this reason, this packet may not be
39220 suitable for accessing memory-mapped I/O devices.
39221 @cindex alignment of remote memory accesses
39222 @cindex size of remote memory accesses
39223 @cindex memory, alignment and size of remote accesses
39224
39225 Reply:
39226 @table @samp
39227 @item @var{XX@dots{}}
39228 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39229 The reply may contain fewer addressable memory units than requested if the
39230 server was able to read only part of the region of memory.
39231 @item E @var{NN}
39232 @var{NN} is errno
39233 @end table
39234
39235 @item M @var{addr},@var{length}:@var{XX@dots{}}
39236 @cindex @samp{M} packet
39237 Write @var{length} addressable memory units starting at address @var{addr}
39238 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39239 byte is transmitted as a two-digit hexadecimal number.
39240
39241 Reply:
39242 @table @samp
39243 @item OK
39244 for success
39245 @item E @var{NN}
39246 for an error (this includes the case where only part of the data was
39247 written).
39248 @end table
39249
39250 @item p @var{n}
39251 @cindex @samp{p} packet
39252 Read the value of register @var{n}; @var{n} is in hex.
39253 @xref{read registers packet}, for a description of how the returned
39254 register value is encoded.
39255
39256 Reply:
39257 @table @samp
39258 @item @var{XX@dots{}}
39259 the register's value
39260 @item E @var{NN}
39261 for an error
39262 @item @w{}
39263 Indicating an unrecognized @var{query}.
39264 @end table
39265
39266 @item P @var{n@dots{}}=@var{r@dots{}}
39267 @anchor{write register packet}
39268 @cindex @samp{P} packet
39269 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
39270 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
39271 digits for each byte in the register (target byte order).
39272
39273 Reply:
39274 @table @samp
39275 @item OK
39276 for success
39277 @item E @var{NN}
39278 for an error
39279 @end table
39280
39281 @item q @var{name} @var{params}@dots{}
39282 @itemx Q @var{name} @var{params}@dots{}
39283 @cindex @samp{q} packet
39284 @cindex @samp{Q} packet
39285 General query (@samp{q}) and set (@samp{Q}). These packets are
39286 described fully in @ref{General Query Packets}.
39287
39288 @item r
39289 @cindex @samp{r} packet
39290 Reset the entire system.
39291
39292 Don't use this packet; use the @samp{R} packet instead.
39293
39294 @item R @var{XX}
39295 @cindex @samp{R} packet
39296 Restart the program being debugged. The @var{XX}, while needed, is ignored.
39297 This packet is only available in extended mode (@pxref{extended mode}).
39298
39299 The @samp{R} packet has no reply.
39300
39301 @item s @r{[}@var{addr}@r{]}
39302 @cindex @samp{s} packet
39303 Single step, resuming at @var{addr}. If
39304 @var{addr} is omitted, resume at same address.
39305
39306 This packet is deprecated for multi-threading support. @xref{vCont
39307 packet}.
39308
39309 Reply:
39310 @xref{Stop Reply Packets}, for the reply specifications.
39311
39312 @item S @var{sig}@r{[};@var{addr}@r{]}
39313 @anchor{step with signal packet}
39314 @cindex @samp{S} packet
39315 Step with signal. This is analogous to the @samp{C} packet, but
39316 requests a single-step, rather than a normal resumption of execution.
39317
39318 This packet is deprecated for multi-threading support. @xref{vCont
39319 packet}.
39320
39321 Reply:
39322 @xref{Stop Reply Packets}, for the reply specifications.
39323
39324 @item t @var{addr}:@var{PP},@var{MM}
39325 @cindex @samp{t} packet
39326 Search backwards starting at address @var{addr} for a match with pattern
39327 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
39328 There must be at least 3 digits in @var{addr}.
39329
39330 @item T @var{thread-id}
39331 @cindex @samp{T} packet
39332 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
39333
39334 Reply:
39335 @table @samp
39336 @item OK
39337 thread is still alive
39338 @item E @var{NN}
39339 thread is dead
39340 @end table
39341
39342 @item v
39343 Packets starting with @samp{v} are identified by a multi-letter name,
39344 up to the first @samp{;} or @samp{?} (or the end of the packet).
39345
39346 @item vAttach;@var{pid}
39347 @cindex @samp{vAttach} packet
39348 Attach to a new process with the specified process ID @var{pid}.
39349 The process ID is a
39350 hexadecimal integer identifying the process. In all-stop mode, all
39351 threads in the attached process are stopped; in non-stop mode, it may be
39352 attached without being stopped if that is supported by the target.
39353
39354 @c In non-stop mode, on a successful vAttach, the stub should set the
39355 @c current thread to a thread of the newly-attached process. After
39356 @c attaching, GDB queries for the attached process's thread ID with qC.
39357 @c Also note that, from a user perspective, whether or not the
39358 @c target is stopped on attach in non-stop mode depends on whether you
39359 @c use the foreground or background version of the attach command, not
39360 @c on what vAttach does; GDB does the right thing with respect to either
39361 @c stopping or restarting threads.
39362
39363 This packet is only available in extended mode (@pxref{extended mode}).
39364
39365 Reply:
39366 @table @samp
39367 @item E @var{nn}
39368 for an error
39369 @item @r{Any stop packet}
39370 for success in all-stop mode (@pxref{Stop Reply Packets})
39371 @item OK
39372 for success in non-stop mode (@pxref{Remote Non-Stop})
39373 @end table
39374
39375 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
39376 @cindex @samp{vCont} packet
39377 @anchor{vCont packet}
39378 Resume the inferior, specifying different actions for each thread.
39379
39380 For each inferior thread, the leftmost action with a matching
39381 @var{thread-id} is applied. Threads that don't match any action
39382 remain in their current state. Thread IDs are specified using the
39383 syntax described in @ref{thread-id syntax}. If multiprocess
39384 extensions (@pxref{multiprocess extensions}) are supported, actions
39385 can be specified to match all threads in a process by using the
39386 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39387 @var{thread-id} matches all threads. Specifying no actions is an
39388 error.
39389
39390 Currently supported actions are:
39391
39392 @table @samp
39393 @item c
39394 Continue.
39395 @item C @var{sig}
39396 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
39397 @item s
39398 Step.
39399 @item S @var{sig}
39400 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39401 @item t
39402 Stop.
39403 @item r @var{start},@var{end}
39404 Step once, and then keep stepping as long as the thread stops at
39405 addresses between @var{start} (inclusive) and @var{end} (exclusive).
39406 The remote stub reports a stop reply when either the thread goes out
39407 of the range or is stopped due to an unrelated reason, such as hitting
39408 a breakpoint. @xref{range stepping}.
39409
39410 If the range is empty (@var{start} == @var{end}), then the action
39411 becomes equivalent to the @samp{s} action. In other words,
39412 single-step once, and report the stop (even if the stepped instruction
39413 jumps to @var{start}).
39414
39415 (A stop reply may be sent at any point even if the PC is still within
39416 the stepping range; for example, it is valid to implement this packet
39417 in a degenerate way as a single instruction step operation.)
39418
39419 @end table
39420
39421 The optional argument @var{addr} normally associated with the
39422 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
39423 not supported in @samp{vCont}.
39424
39425 The @samp{t} action is only relevant in non-stop mode
39426 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
39427 A stop reply should be generated for any affected thread not already stopped.
39428 When a thread is stopped by means of a @samp{t} action,
39429 the corresponding stop reply should indicate that the thread has stopped with
39430 signal @samp{0}, regardless of whether the target uses some other signal
39431 as an implementation detail.
39432
39433 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39434 @samp{r} actions for threads that are already running. Conversely,
39435 the server must ignore @samp{t} actions for threads that are already
39436 stopped.
39437
39438 @emph{Note:} In non-stop mode, a thread is considered running until
39439 @value{GDBN} acknowledges an asynchronous stop notification for it with
39440 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39441
39442 The stub must support @samp{vCont} if it reports support for
39443 multiprocess extensions (@pxref{multiprocess extensions}).
39444
39445 Reply:
39446 @xref{Stop Reply Packets}, for the reply specifications.
39447
39448 @item vCont?
39449 @cindex @samp{vCont?} packet
39450 Request a list of actions supported by the @samp{vCont} packet.
39451
39452 Reply:
39453 @table @samp
39454 @item vCont@r{[};@var{action}@dots{}@r{]}
39455 The @samp{vCont} packet is supported. Each @var{action} is a supported
39456 command in the @samp{vCont} packet.
39457 @item @w{}
39458 The @samp{vCont} packet is not supported.
39459 @end table
39460
39461 @anchor{vCtrlC packet}
39462 @item vCtrlC
39463 @cindex @samp{vCtrlC} packet
39464 Interrupt remote target as if a control-C was pressed on the remote
39465 terminal. This is the equivalent to reacting to the @code{^C}
39466 (@samp{\003}, the control-C character) character in all-stop mode
39467 while the target is running, except this works in non-stop mode.
39468 @xref{interrupting remote targets}, for more info on the all-stop
39469 variant.
39470
39471 Reply:
39472 @table @samp
39473 @item E @var{nn}
39474 for an error
39475 @item OK
39476 for success
39477 @end table
39478
39479 @item vFile:@var{operation}:@var{parameter}@dots{}
39480 @cindex @samp{vFile} packet
39481 Perform a file operation on the target system. For details,
39482 see @ref{Host I/O Packets}.
39483
39484 @item vFlashErase:@var{addr},@var{length}
39485 @cindex @samp{vFlashErase} packet
39486 Direct the stub to erase @var{length} bytes of flash starting at
39487 @var{addr}. The region may enclose any number of flash blocks, but
39488 its start and end must fall on block boundaries, as indicated by the
39489 flash block size appearing in the memory map (@pxref{Memory Map
39490 Format}). @value{GDBN} groups flash memory programming operations
39491 together, and sends a @samp{vFlashDone} request after each group; the
39492 stub is allowed to delay erase operation until the @samp{vFlashDone}
39493 packet is received.
39494
39495 Reply:
39496 @table @samp
39497 @item OK
39498 for success
39499 @item E @var{NN}
39500 for an error
39501 @end table
39502
39503 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
39504 @cindex @samp{vFlashWrite} packet
39505 Direct the stub to write data to flash address @var{addr}. The data
39506 is passed in binary form using the same encoding as for the @samp{X}
39507 packet (@pxref{Binary Data}). The memory ranges specified by
39508 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39509 not overlap, and must appear in order of increasing addresses
39510 (although @samp{vFlashErase} packets for higher addresses may already
39511 have been received; the ordering is guaranteed only between
39512 @samp{vFlashWrite} packets). If a packet writes to an address that was
39513 neither erased by a preceding @samp{vFlashErase} packet nor by some other
39514 target-specific method, the results are unpredictable.
39515
39516
39517 Reply:
39518 @table @samp
39519 @item OK
39520 for success
39521 @item E.memtype
39522 for vFlashWrite addressing non-flash memory
39523 @item E @var{NN}
39524 for an error
39525 @end table
39526
39527 @item vFlashDone
39528 @cindex @samp{vFlashDone} packet
39529 Indicate to the stub that flash programming operation is finished.
39530 The stub is permitted to delay or batch the effects of a group of
39531 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
39532 @samp{vFlashDone} packet is received. The contents of the affected
39533 regions of flash memory are unpredictable until the @samp{vFlashDone}
39534 request is completed.
39535
39536 @item vKill;@var{pid}
39537 @cindex @samp{vKill} packet
39538 @anchor{vKill packet}
39539 Kill the process with the specified process ID @var{pid}, which is a
39540 hexadecimal integer identifying the process. This packet is used in
39541 preference to @samp{k} when multiprocess protocol extensions are
39542 supported; see @ref{multiprocess extensions}.
39543
39544 Reply:
39545 @table @samp
39546 @item E @var{nn}
39547 for an error
39548 @item OK
39549 for success
39550 @end table
39551
39552 @item vMustReplyEmpty
39553 @cindex @samp{vMustReplyEmpty} packet
39554 The correct reply to an unknown @samp{v} packet is to return the empty
39555 string, however, some older versions of @command{gdbserver} would
39556 incorrectly return @samp{OK} for unknown @samp{v} packets.
39557
39558 The @samp{vMustReplyEmpty} is used as a feature test to check how
39559 @command{gdbserver} handles unknown packets, it is important that this
39560 packet be handled in the same way as other unknown @samp{v} packets.
39561 If this packet is handled differently to other unknown @samp{v}
39562 packets then it is possible that @value{GDBN} may run into problems in
39563 other areas, specifically around use of @samp{vFile:setfs:}.
39564
39565 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39566 @cindex @samp{vRun} packet
39567 Run the program @var{filename}, passing it each @var{argument} on its
39568 command line. The file and arguments are hex-encoded strings. If
39569 @var{filename} is an empty string, the stub may use a default program
39570 (e.g.@: the last program run). The program is created in the stopped
39571 state.
39572
39573 @c FIXME: What about non-stop mode?
39574
39575 This packet is only available in extended mode (@pxref{extended mode}).
39576
39577 Reply:
39578 @table @samp
39579 @item E @var{nn}
39580 for an error
39581 @item @r{Any stop packet}
39582 for success (@pxref{Stop Reply Packets})
39583 @end table
39584
39585 @item vStopped
39586 @cindex @samp{vStopped} packet
39587 @xref{Notification Packets}.
39588
39589 @item X @var{addr},@var{length}:@var{XX@dots{}}
39590 @anchor{X packet}
39591 @cindex @samp{X} packet
39592 Write data to memory, where the data is transmitted in binary.
39593 Memory is specified by its address @var{addr} and number of addressable memory
39594 units @var{length} (@pxref{addressable memory unit});
39595 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
39596
39597 Reply:
39598 @table @samp
39599 @item OK
39600 for success
39601 @item E @var{NN}
39602 for an error
39603 @end table
39604
39605 @item z @var{type},@var{addr},@var{kind}
39606 @itemx Z @var{type},@var{addr},@var{kind}
39607 @anchor{insert breakpoint or watchpoint packet}
39608 @cindex @samp{z} packet
39609 @cindex @samp{Z} packets
39610 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
39611 watchpoint starting at address @var{address} of kind @var{kind}.
39612
39613 Each breakpoint and watchpoint packet @var{type} is documented
39614 separately.
39615
39616 @emph{Implementation notes: A remote target shall return an empty string
39617 for an unrecognized breakpoint or watchpoint packet @var{type}. A
39618 remote target shall support either both or neither of a given
39619 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
39620 avoid potential problems with duplicate packets, the operations should
39621 be implemented in an idempotent way.}
39622
39623 @item z0,@var{addr},@var{kind}
39624 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39625 @cindex @samp{z0} packet
39626 @cindex @samp{Z0} packet
39627 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
39628 @var{addr} of type @var{kind}.
39629
39630 A software breakpoint is implemented by replacing the instruction at
39631 @var{addr} with a software breakpoint or trap instruction. The
39632 @var{kind} is target-specific and typically indicates the size of the
39633 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39634 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39635 architectures have additional meanings for @var{kind}
39636 (@pxref{Architecture-Specific Protocol Details}); if no
39637 architecture-specific value is being used, it should be @samp{0}.
39638 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
39639 conditional expressions in bytecode form that should be evaluated on
39640 the target's side. These are the conditions that should be taken into
39641 consideration when deciding if the breakpoint trigger should be
39642 reported back to @value{GDBN}.
39643
39644 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
39645 for how to best report a software breakpoint event to @value{GDBN}.
39646
39647 The @var{cond_list} parameter is comprised of a series of expressions,
39648 concatenated without separators. Each expression has the following form:
39649
39650 @table @samp
39651
39652 @item X @var{len},@var{expr}
39653 @var{len} is the length of the bytecode expression and @var{expr} is the
39654 actual conditional expression in bytecode form.
39655
39656 @end table
39657
39658 The optional @var{cmd_list} parameter introduces commands that may be
39659 run on the target, rather than being reported back to @value{GDBN}.
39660 The parameter starts with a numeric flag @var{persist}; if the flag is
39661 nonzero, then the breakpoint may remain active and the commands
39662 continue to be run even when @value{GDBN} disconnects from the target.
39663 Following this flag is a series of expressions concatenated with no
39664 separators. Each expression has the following form:
39665
39666 @table @samp
39667
39668 @item X @var{len},@var{expr}
39669 @var{len} is the length of the bytecode expression and @var{expr} is the
39670 actual commands expression in bytecode form.
39671
39672 @end table
39673
39674 @emph{Implementation note: It is possible for a target to copy or move
39675 code that contains software breakpoints (e.g., when implementing
39676 overlays). The behavior of this packet, in the presence of such a
39677 target, is not defined.}
39678
39679 Reply:
39680 @table @samp
39681 @item OK
39682 success
39683 @item @w{}
39684 not supported
39685 @item E @var{NN}
39686 for an error
39687 @end table
39688
39689 @item z1,@var{addr},@var{kind}
39690 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39691 @cindex @samp{z1} packet
39692 @cindex @samp{Z1} packet
39693 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
39694 address @var{addr}.
39695
39696 A hardware breakpoint is implemented using a mechanism that is not
39697 dependent on being able to modify the target's memory. The
39698 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39699 same meaning as in @samp{Z0} packets.
39700
39701 @emph{Implementation note: A hardware breakpoint is not affected by code
39702 movement.}
39703
39704 Reply:
39705 @table @samp
39706 @item OK
39707 success
39708 @item @w{}
39709 not supported
39710 @item E @var{NN}
39711 for an error
39712 @end table
39713
39714 @item z2,@var{addr},@var{kind}
39715 @itemx Z2,@var{addr},@var{kind}
39716 @cindex @samp{z2} packet
39717 @cindex @samp{Z2} packet
39718 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
39719 The number of bytes to watch is specified by @var{kind}.
39720
39721 Reply:
39722 @table @samp
39723 @item OK
39724 success
39725 @item @w{}
39726 not supported
39727 @item E @var{NN}
39728 for an error
39729 @end table
39730
39731 @item z3,@var{addr},@var{kind}
39732 @itemx Z3,@var{addr},@var{kind}
39733 @cindex @samp{z3} packet
39734 @cindex @samp{Z3} packet
39735 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
39736 The number of bytes to watch is specified by @var{kind}.
39737
39738 Reply:
39739 @table @samp
39740 @item OK
39741 success
39742 @item @w{}
39743 not supported
39744 @item E @var{NN}
39745 for an error
39746 @end table
39747
39748 @item z4,@var{addr},@var{kind}
39749 @itemx Z4,@var{addr},@var{kind}
39750 @cindex @samp{z4} packet
39751 @cindex @samp{Z4} packet
39752 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
39753 The number of bytes to watch is specified by @var{kind}.
39754
39755 Reply:
39756 @table @samp
39757 @item OK
39758 success
39759 @item @w{}
39760 not supported
39761 @item E @var{NN}
39762 for an error
39763 @end table
39764
39765 @end table
39766
39767 @node Stop Reply Packets
39768 @section Stop Reply Packets
39769 @cindex stop reply packets
39770
39771 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
39772 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
39773 receive any of the below as a reply. Except for @samp{?}
39774 and @samp{vStopped}, that reply is only returned
39775 when the target halts. In the below the exact meaning of @dfn{signal
39776 number} is defined by the header @file{include/gdb/signals.h} in the
39777 @value{GDBN} source code.
39778
39779 In non-stop mode, the server will simply reply @samp{OK} to commands
39780 such as @samp{vCont}; any stop will be the subject of a future
39781 notification. @xref{Remote Non-Stop}.
39782
39783 As in the description of request packets, we include spaces in the
39784 reply templates for clarity; these are not part of the reply packet's
39785 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
39786 components.
39787
39788 @table @samp
39789
39790 @item S @var{AA}
39791 The program received signal number @var{AA} (a two-digit hexadecimal
39792 number). This is equivalent to a @samp{T} response with no
39793 @var{n}:@var{r} pairs.
39794
39795 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
39796 @cindex @samp{T} packet reply
39797 The program received signal number @var{AA} (a two-digit hexadecimal
39798 number). This is equivalent to an @samp{S} response, except that the
39799 @samp{@var{n}:@var{r}} pairs can carry values of important registers
39800 and other information directly in the stop reply packet, reducing
39801 round-trip latency. Single-step and breakpoint traps are reported
39802 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
39803
39804 @itemize @bullet
39805 @item
39806 If @var{n} is a hexadecimal number, it is a register number, and the
39807 corresponding @var{r} gives that register's value. The data @var{r} is a
39808 series of bytes in target byte order, with each byte given by a
39809 two-digit hex number.
39810
39811 @item
39812 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
39813 the stopped thread, as specified in @ref{thread-id syntax}.
39814
39815 @item
39816 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
39817 the core on which the stop event was detected.
39818
39819 @item
39820 If @var{n} is a recognized @dfn{stop reason}, it describes a more
39821 specific event that stopped the target. The currently defined stop
39822 reasons are listed below. The @var{aa} should be @samp{05}, the trap
39823 signal. At most one stop reason should be present.
39824
39825 @item
39826 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
39827 and go on to the next; this allows us to extend the protocol in the
39828 future.
39829 @end itemize
39830
39831 The currently defined stop reasons are:
39832
39833 @table @samp
39834 @item watch
39835 @itemx rwatch
39836 @itemx awatch
39837 The packet indicates a watchpoint hit, and @var{r} is the data address, in
39838 hex.
39839
39840 @item syscall_entry
39841 @itemx syscall_return
39842 The packet indicates a syscall entry or return, and @var{r} is the
39843 syscall number, in hex.
39844
39845 @cindex shared library events, remote reply
39846 @item library
39847 The packet indicates that the loaded libraries have changed.
39848 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
39849 list of loaded libraries. The @var{r} part is ignored.
39850
39851 @cindex replay log events, remote reply
39852 @item replaylog
39853 The packet indicates that the target cannot continue replaying
39854 logged execution events, because it has reached the end (or the
39855 beginning when executing backward) of the log. The value of @var{r}
39856 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
39857 for more information.
39858
39859 @item swbreak
39860 @anchor{swbreak stop reason}
39861 The packet indicates a software breakpoint instruction was executed,
39862 irrespective of whether it was @value{GDBN} that planted the
39863 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
39864 part must be left empty.
39865
39866 On some architectures, such as x86, at the architecture level, when a
39867 breakpoint instruction executes the program counter points at the
39868 breakpoint address plus an offset. On such targets, the stub is
39869 responsible for adjusting the PC to point back at the breakpoint
39870 address.
39871
39872 This packet should not be sent by default; older @value{GDBN} versions
39873 did not support it. @value{GDBN} requests it, by supplying an
39874 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39875 remote stub must also supply the appropriate @samp{qSupported} feature
39876 indicating support.
39877
39878 This packet is required for correct non-stop mode operation.
39879
39880 @item hwbreak
39881 The packet indicates the target stopped for a hardware breakpoint.
39882 The @var{r} part must be left empty.
39883
39884 The same remarks about @samp{qSupported} and non-stop mode above
39885 apply.
39886
39887 @cindex fork events, remote reply
39888 @item fork
39889 The packet indicates that @code{fork} was called, and @var{r}
39890 is the thread ID of the new child process. Refer to
39891 @ref{thread-id syntax} for the format of the @var{thread-id}
39892 field. This packet is only applicable to targets that support
39893 fork events.
39894
39895 This packet should not be sent by default; older @value{GDBN} versions
39896 did not support it. @value{GDBN} requests it, by supplying an
39897 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39898 remote stub must also supply the appropriate @samp{qSupported} feature
39899 indicating support.
39900
39901 @cindex vfork events, remote reply
39902 @item vfork
39903 The packet indicates that @code{vfork} was called, and @var{r}
39904 is the thread ID of the new child process. Refer to
39905 @ref{thread-id syntax} for the format of the @var{thread-id}
39906 field. This packet is only applicable to targets that support
39907 vfork events.
39908
39909 This packet should not be sent by default; older @value{GDBN} versions
39910 did not support it. @value{GDBN} requests it, by supplying an
39911 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39912 remote stub must also supply the appropriate @samp{qSupported} feature
39913 indicating support.
39914
39915 @cindex vforkdone events, remote reply
39916 @item vforkdone
39917 The packet indicates that a child process created by a vfork
39918 has either called @code{exec} or terminated, so that the
39919 address spaces of the parent and child process are no longer
39920 shared. The @var{r} part is ignored. This packet is only
39921 applicable to targets that support vforkdone events.
39922
39923 This packet should not be sent by default; older @value{GDBN} versions
39924 did not support it. @value{GDBN} requests it, by supplying an
39925 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39926 remote stub must also supply the appropriate @samp{qSupported} feature
39927 indicating support.
39928
39929 @cindex exec events, remote reply
39930 @item exec
39931 The packet indicates that @code{execve} was called, and @var{r}
39932 is the absolute pathname of the file that was executed, in hex.
39933 This packet is only applicable to targets that support exec events.
39934
39935 This packet should not be sent by default; older @value{GDBN} versions
39936 did not support it. @value{GDBN} requests it, by supplying an
39937 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39938 remote stub must also supply the appropriate @samp{qSupported} feature
39939 indicating support.
39940
39941 @cindex thread create event, remote reply
39942 @anchor{thread create event}
39943 @item create
39944 The packet indicates that the thread was just created. The new thread
39945 is stopped until @value{GDBN} sets it running with a resumption packet
39946 (@pxref{vCont packet}). This packet should not be sent by default;
39947 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
39948 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
39949 @var{r} part is ignored.
39950
39951 @end table
39952
39953 @item W @var{AA}
39954 @itemx W @var{AA} ; process:@var{pid}
39955 The process exited, and @var{AA} is the exit status. This is only
39956 applicable to certain targets.
39957
39958 The second form of the response, including the process ID of the
39959 exited process, can be used only when @value{GDBN} has reported
39960 support for multiprocess protocol extensions; see @ref{multiprocess
39961 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
39962 hex strings.
39963
39964 @item X @var{AA}
39965 @itemx X @var{AA} ; process:@var{pid}
39966 The process terminated with signal @var{AA}.
39967
39968 The second form of the response, including the process ID of the
39969 terminated process, can be used only when @value{GDBN} has reported
39970 support for multiprocess protocol extensions; see @ref{multiprocess
39971 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
39972 hex strings.
39973
39974 @anchor{thread exit event}
39975 @cindex thread exit event, remote reply
39976 @item w @var{AA} ; @var{tid}
39977
39978 The thread exited, and @var{AA} is the exit status. This response
39979 should not be sent by default; @value{GDBN} requests it with the
39980 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
39981 @var{AA} is formatted as a big-endian hex string.
39982
39983 @item N
39984 There are no resumed threads left in the target. In other words, even
39985 though the process is alive, the last resumed thread has exited. For
39986 example, say the target process has two threads: thread 1 and thread
39987 2. The client leaves thread 1 stopped, and resumes thread 2, which
39988 subsequently exits. At this point, even though the process is still
39989 alive, and thus no @samp{W} stop reply is sent, no thread is actually
39990 executing either. The @samp{N} stop reply thus informs the client
39991 that it can stop waiting for stop replies. This packet should not be
39992 sent by default; older @value{GDBN} versions did not support it.
39993 @value{GDBN} requests it, by supplying an appropriate
39994 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
39995 also supply the appropriate @samp{qSupported} feature indicating
39996 support.
39997
39998 @item O @var{XX}@dots{}
39999 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40000 written as the program's console output. This can happen at any time
40001 while the program is running and the debugger should continue to wait
40002 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40003
40004 @item F @var{call-id},@var{parameter}@dots{}
40005 @var{call-id} is the identifier which says which host system call should
40006 be called. This is just the name of the function. Translation into the
40007 correct system call is only applicable as it's defined in @value{GDBN}.
40008 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40009 system calls.
40010
40011 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40012 this very system call.
40013
40014 The target replies with this packet when it expects @value{GDBN} to
40015 call a host system call on behalf of the target. @value{GDBN} replies
40016 with an appropriate @samp{F} packet and keeps up waiting for the next
40017 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40018 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40019 Protocol Extension}, for more details.
40020
40021 @end table
40022
40023 @node General Query Packets
40024 @section General Query Packets
40025 @cindex remote query requests
40026
40027 Packets starting with @samp{q} are @dfn{general query packets};
40028 packets starting with @samp{Q} are @dfn{general set packets}. General
40029 query and set packets are a semi-unified form for retrieving and
40030 sending information to and from the stub.
40031
40032 The initial letter of a query or set packet is followed by a name
40033 indicating what sort of thing the packet applies to. For example,
40034 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40035 definitions with the stub. These packet names follow some
40036 conventions:
40037
40038 @itemize @bullet
40039 @item
40040 The name must not contain commas, colons or semicolons.
40041 @item
40042 Most @value{GDBN} query and set packets have a leading upper case
40043 letter.
40044 @item
40045 The names of custom vendor packets should use a company prefix, in
40046 lower case, followed by a period. For example, packets designed at
40047 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40048 foos) or @samp{Qacme.bar} (for setting bars).
40049 @end itemize
40050
40051 The name of a query or set packet should be separated from any
40052 parameters by a @samp{:}; the parameters themselves should be
40053 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40054 full packet name, and check for a separator or the end of the packet,
40055 in case two packet names share a common prefix. New packets should not begin
40056 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40057 packets predate these conventions, and have arguments without any terminator
40058 for the packet name; we suspect they are in widespread use in places that
40059 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40060 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40061 packet.}.
40062
40063 Like the descriptions of the other packets, each description here
40064 has a template showing the packet's overall syntax, followed by an
40065 explanation of the packet's meaning. We include spaces in some of the
40066 templates for clarity; these are not part of the packet's syntax. No
40067 @value{GDBN} packet uses spaces to separate its components.
40068
40069 Here are the currently defined query and set packets:
40070
40071 @table @samp
40072
40073 @item QAgent:1
40074 @itemx QAgent:0
40075 Turn on or off the agent as a helper to perform some debugging operations
40076 delegated from @value{GDBN} (@pxref{Control Agent}).
40077
40078 @item QAllow:@var{op}:@var{val}@dots{}
40079 @cindex @samp{QAllow} packet
40080 Specify which operations @value{GDBN} expects to request of the
40081 target, as a semicolon-separated list of operation name and value
40082 pairs. Possible values for @var{op} include @samp{WriteReg},
40083 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40084 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40085 indicating that @value{GDBN} will not request the operation, or 1,
40086 indicating that it may. (The target can then use this to set up its
40087 own internals optimally, for instance if the debugger never expects to
40088 insert breakpoints, it may not need to install its own trap handler.)
40089
40090 @item qC
40091 @cindex current thread, remote request
40092 @cindex @samp{qC} packet
40093 Return the current thread ID.
40094
40095 Reply:
40096 @table @samp
40097 @item QC @var{thread-id}
40098 Where @var{thread-id} is a thread ID as documented in
40099 @ref{thread-id syntax}.
40100 @item @r{(anything else)}
40101 Any other reply implies the old thread ID.
40102 @end table
40103
40104 @item qCRC:@var{addr},@var{length}
40105 @cindex CRC of memory block, remote request
40106 @cindex @samp{qCRC} packet
40107 @anchor{qCRC packet}
40108 Compute the CRC checksum of a block of memory using CRC-32 defined in
40109 IEEE 802.3. The CRC is computed byte at a time, taking the most
40110 significant bit of each byte first. The initial pattern code
40111 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40112
40113 @emph{Note:} This is the same CRC used in validating separate debug
40114 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40115 Files}). However the algorithm is slightly different. When validating
40116 separate debug files, the CRC is computed taking the @emph{least}
40117 significant bit of each byte first, and the final result is inverted to
40118 detect trailing zeros.
40119
40120 Reply:
40121 @table @samp
40122 @item E @var{NN}
40123 An error (such as memory fault)
40124 @item C @var{crc32}
40125 The specified memory region's checksum is @var{crc32}.
40126 @end table
40127
40128 @item QDisableRandomization:@var{value}
40129 @cindex disable address space randomization, remote request
40130 @cindex @samp{QDisableRandomization} packet
40131 Some target operating systems will randomize the virtual address space
40132 of the inferior process as a security feature, but provide a feature
40133 to disable such randomization, e.g.@: to allow for a more deterministic
40134 debugging experience. On such systems, this packet with a @var{value}
40135 of 1 directs the target to disable address space randomization for
40136 processes subsequently started via @samp{vRun} packets, while a packet
40137 with a @var{value} of 0 tells the target to enable address space
40138 randomization.
40139
40140 This packet is only available in extended mode (@pxref{extended mode}).
40141
40142 Reply:
40143 @table @samp
40144 @item OK
40145 The request succeeded.
40146
40147 @item E @var{nn}
40148 An error occurred. The error number @var{nn} is given as hex digits.
40149
40150 @item @w{}
40151 An empty reply indicates that @samp{QDisableRandomization} is not supported
40152 by the stub.
40153 @end table
40154
40155 This packet is not probed by default; the remote stub must request it,
40156 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40157 This should only be done on targets that actually support disabling
40158 address space randomization.
40159
40160 @item QStartupWithShell:@var{value}
40161 @cindex startup with shell, remote request
40162 @cindex @samp{QStartupWithShell} packet
40163 On UNIX-like targets, it is possible to start the inferior using a
40164 shell program. This is the default behavior on both @value{GDBN} and
40165 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40166 used to inform @command{gdbserver} whether it should start the
40167 inferior using a shell or not.
40168
40169 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40170 to start the inferior. If @var{value} is @samp{1},
40171 @command{gdbserver} will use a shell to start the inferior. All other
40172 values are considered an error.
40173
40174 This packet is only available in extended mode (@pxref{extended
40175 mode}).
40176
40177 Reply:
40178 @table @samp
40179 @item OK
40180 The request succeeded.
40181
40182 @item E @var{nn}
40183 An error occurred. The error number @var{nn} is given as hex digits.
40184 @end table
40185
40186 This packet is not probed by default; the remote stub must request it,
40187 by supplying an appropriate @samp{qSupported} response
40188 (@pxref{qSupported}). This should only be done on targets that
40189 actually support starting the inferior using a shell.
40190
40191 Use of this packet is controlled by the @code{set startup-with-shell}
40192 command; @pxref{set startup-with-shell}.
40193
40194 @item QEnvironmentHexEncoded:@var{hex-value}
40195 @anchor{QEnvironmentHexEncoded}
40196 @cindex set environment variable, remote request
40197 @cindex @samp{QEnvironmentHexEncoded} packet
40198 On UNIX-like targets, it is possible to set environment variables that
40199 will be passed to the inferior during the startup process. This
40200 packet is used to inform @command{gdbserver} of an environment
40201 variable that has been defined by the user on @value{GDBN} (@pxref{set
40202 environment}).
40203
40204 The packet is composed by @var{hex-value}, an hex encoded
40205 representation of the @var{name=value} format representing an
40206 environment variable. The name of the environment variable is
40207 represented by @var{name}, and the value to be assigned to the
40208 environment variable is represented by @var{value}. If the variable
40209 has no value (i.e., the value is @code{null}), then @var{value} will
40210 not be present.
40211
40212 This packet is only available in extended mode (@pxref{extended
40213 mode}).
40214
40215 Reply:
40216 @table @samp
40217 @item OK
40218 The request succeeded.
40219 @end table
40220
40221 This packet is not probed by default; the remote stub must request it,
40222 by supplying an appropriate @samp{qSupported} response
40223 (@pxref{qSupported}). This should only be done on targets that
40224 actually support passing environment variables to the starting
40225 inferior.
40226
40227 This packet is related to the @code{set environment} command;
40228 @pxref{set environment}.
40229
40230 @item QEnvironmentUnset:@var{hex-value}
40231 @anchor{QEnvironmentUnset}
40232 @cindex unset environment variable, remote request
40233 @cindex @samp{QEnvironmentUnset} packet
40234 On UNIX-like targets, it is possible to unset environment variables
40235 before starting the inferior in the remote target. This packet is
40236 used to inform @command{gdbserver} of an environment variable that has
40237 been unset by the user on @value{GDBN} (@pxref{unset environment}).
40238
40239 The packet is composed by @var{hex-value}, an hex encoded
40240 representation of the name of the environment variable to be unset.
40241
40242 This packet is only available in extended mode (@pxref{extended
40243 mode}).
40244
40245 Reply:
40246 @table @samp
40247 @item OK
40248 The request succeeded.
40249 @end table
40250
40251 This packet is not probed by default; the remote stub must request it,
40252 by supplying an appropriate @samp{qSupported} response
40253 (@pxref{qSupported}). This should only be done on targets that
40254 actually support passing environment variables to the starting
40255 inferior.
40256
40257 This packet is related to the @code{unset environment} command;
40258 @pxref{unset environment}.
40259
40260 @item QEnvironmentReset
40261 @anchor{QEnvironmentReset}
40262 @cindex reset environment, remote request
40263 @cindex @samp{QEnvironmentReset} packet
40264 On UNIX-like targets, this packet is used to reset the state of
40265 environment variables in the remote target before starting the
40266 inferior. In this context, reset means unsetting all environment
40267 variables that were previously set by the user (i.e., were not
40268 initially present in the environment). It is sent to
40269 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40270 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40271 (@pxref{QEnvironmentUnset}) packets.
40272
40273 This packet is only available in extended mode (@pxref{extended
40274 mode}).
40275
40276 Reply:
40277 @table @samp
40278 @item OK
40279 The request succeeded.
40280 @end table
40281
40282 This packet is not probed by default; the remote stub must request it,
40283 by supplying an appropriate @samp{qSupported} response
40284 (@pxref{qSupported}). This should only be done on targets that
40285 actually support passing environment variables to the starting
40286 inferior.
40287
40288 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
40289 @anchor{QSetWorkingDir packet}
40290 @cindex set working directory, remote request
40291 @cindex @samp{QSetWorkingDir} packet
40292 This packet is used to inform the remote server of the intended
40293 current working directory for programs that are going to be executed.
40294
40295 The packet is composed by @var{directory}, an hex encoded
40296 representation of the directory that the remote inferior will use as
40297 its current working directory. If @var{directory} is an empty string,
40298 the remote server should reset the inferior's current working
40299 directory to its original, empty value.
40300
40301 This packet is only available in extended mode (@pxref{extended
40302 mode}).
40303
40304 Reply:
40305 @table @samp
40306 @item OK
40307 The request succeeded.
40308 @end table
40309
40310 @item qfThreadInfo
40311 @itemx qsThreadInfo
40312 @cindex list active threads, remote request
40313 @cindex @samp{qfThreadInfo} packet
40314 @cindex @samp{qsThreadInfo} packet
40315 Obtain a list of all active thread IDs from the target (OS). Since there
40316 may be too many active threads to fit into one reply packet, this query
40317 works iteratively: it may require more than one query/reply sequence to
40318 obtain the entire list of threads. The first query of the sequence will
40319 be the @samp{qfThreadInfo} query; subsequent queries in the
40320 sequence will be the @samp{qsThreadInfo} query.
40321
40322 NOTE: This packet replaces the @samp{qL} query (see below).
40323
40324 Reply:
40325 @table @samp
40326 @item m @var{thread-id}
40327 A single thread ID
40328 @item m @var{thread-id},@var{thread-id}@dots{}
40329 a comma-separated list of thread IDs
40330 @item l
40331 (lower case letter @samp{L}) denotes end of list.
40332 @end table
40333
40334 In response to each query, the target will reply with a list of one or
40335 more thread IDs, separated by commas.
40336 @value{GDBN} will respond to each reply with a request for more thread
40337 ids (using the @samp{qs} form of the query), until the target responds
40338 with @samp{l} (lower-case ell, for @dfn{last}).
40339 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40340 fields.
40341
40342 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40343 initial connection with the remote target, and the very first thread ID
40344 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40345 message. Therefore, the stub should ensure that the first thread ID in
40346 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40347
40348 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
40349 @cindex get thread-local storage address, remote request
40350 @cindex @samp{qGetTLSAddr} packet
40351 Fetch the address associated with thread local storage specified
40352 by @var{thread-id}, @var{offset}, and @var{lm}.
40353
40354 @var{thread-id} is the thread ID associated with the
40355 thread for which to fetch the TLS address. @xref{thread-id syntax}.
40356
40357 @var{offset} is the (big endian, hex encoded) offset associated with the
40358 thread local variable. (This offset is obtained from the debug
40359 information associated with the variable.)
40360
40361 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
40362 load module associated with the thread local storage. For example,
40363 a @sc{gnu}/Linux system will pass the link map address of the shared
40364 object associated with the thread local storage under consideration.
40365 Other operating environments may choose to represent the load module
40366 differently, so the precise meaning of this parameter will vary.
40367
40368 Reply:
40369 @table @samp
40370 @item @var{XX}@dots{}
40371 Hex encoded (big endian) bytes representing the address of the thread
40372 local storage requested.
40373
40374 @item E @var{nn}
40375 An error occurred. The error number @var{nn} is given as hex digits.
40376
40377 @item @w{}
40378 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
40379 @end table
40380
40381 @item qGetTIBAddr:@var{thread-id}
40382 @cindex get thread information block address
40383 @cindex @samp{qGetTIBAddr} packet
40384 Fetch address of the Windows OS specific Thread Information Block.
40385
40386 @var{thread-id} is the thread ID associated with the thread.
40387
40388 Reply:
40389 @table @samp
40390 @item @var{XX}@dots{}
40391 Hex encoded (big endian) bytes representing the linear address of the
40392 thread information block.
40393
40394 @item E @var{nn}
40395 An error occured. This means that either the thread was not found, or the
40396 address could not be retrieved.
40397
40398 @item @w{}
40399 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40400 @end table
40401
40402 @item qL @var{startflag} @var{threadcount} @var{nextthread}
40403 Obtain thread information from RTOS. Where: @var{startflag} (one hex
40404 digit) is one to indicate the first query and zero to indicate a
40405 subsequent query; @var{threadcount} (two hex digits) is the maximum
40406 number of threads the response packet can contain; and @var{nextthread}
40407 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
40408 returned in the response as @var{argthread}.
40409
40410 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
40411
40412 Reply:
40413 @table @samp
40414 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
40415 Where: @var{count} (two hex digits) is the number of threads being
40416 returned; @var{done} (one hex digit) is zero to indicate more threads
40417 and one indicates no further threads; @var{argthreadid} (eight hex
40418 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
40419 is a sequence of thread IDs, @var{threadid} (eight hex
40420 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
40421 @end table
40422
40423 @item qOffsets
40424 @cindex section offsets, remote request
40425 @cindex @samp{qOffsets} packet
40426 Get section offsets that the target used when relocating the downloaded
40427 image.
40428
40429 Reply:
40430 @table @samp
40431 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40432 Relocate the @code{Text} section by @var{xxx} from its original address.
40433 Relocate the @code{Data} section by @var{yyy} from its original address.
40434 If the object file format provides segment information (e.g.@: @sc{elf}
40435 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40436 segments by the supplied offsets.
40437
40438 @emph{Note: while a @code{Bss} offset may be included in the response,
40439 @value{GDBN} ignores this and instead applies the @code{Data} offset
40440 to the @code{Bss} section.}
40441
40442 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40443 Relocate the first segment of the object file, which conventionally
40444 contains program code, to a starting address of @var{xxx}. If
40445 @samp{DataSeg} is specified, relocate the second segment, which
40446 conventionally contains modifiable data, to a starting address of
40447 @var{yyy}. @value{GDBN} will report an error if the object file
40448 does not contain segment information, or does not contain at least
40449 as many segments as mentioned in the reply. Extra segments are
40450 kept at fixed offsets relative to the last relocated segment.
40451 @end table
40452
40453 @item qP @var{mode} @var{thread-id}
40454 @cindex thread information, remote request
40455 @cindex @samp{qP} packet
40456 Returns information on @var{thread-id}. Where: @var{mode} is a hex
40457 encoded 32 bit mode; @var{thread-id} is a thread ID
40458 (@pxref{thread-id syntax}).
40459
40460 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40461 (see below).
40462
40463 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
40464
40465 @item QNonStop:1
40466 @itemx QNonStop:0
40467 @cindex non-stop mode, remote request
40468 @cindex @samp{QNonStop} packet
40469 @anchor{QNonStop}
40470 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40471 @xref{Remote Non-Stop}, for more information.
40472
40473 Reply:
40474 @table @samp
40475 @item OK
40476 The request succeeded.
40477
40478 @item E @var{nn}
40479 An error occurred. The error number @var{nn} is given as hex digits.
40480
40481 @item @w{}
40482 An empty reply indicates that @samp{QNonStop} is not supported by
40483 the stub.
40484 @end table
40485
40486 This packet is not probed by default; the remote stub must request it,
40487 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40488 Use of this packet is controlled by the @code{set non-stop} command;
40489 @pxref{Non-Stop Mode}.
40490
40491 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40492 @itemx QCatchSyscalls:0
40493 @cindex catch syscalls from inferior, remote request
40494 @cindex @samp{QCatchSyscalls} packet
40495 @anchor{QCatchSyscalls}
40496 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40497 catching syscalls from the inferior process.
40498
40499 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40500 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40501 is listed, every system call should be reported.
40502
40503 Note that if a syscall not in the list is reported, @value{GDBN} will
40504 still filter the event according to its own list from all corresponding
40505 @code{catch syscall} commands. However, it is more efficient to only
40506 report the requested syscalls.
40507
40508 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40509 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
40510
40511 If the inferior process execs, the state of @samp{QCatchSyscalls} is
40512 kept for the new process too. On targets where exec may affect syscall
40513 numbers, for example with exec between 32 and 64-bit processes, the
40514 client should send a new packet with the new syscall list.
40515
40516 Reply:
40517 @table @samp
40518 @item OK
40519 The request succeeded.
40520
40521 @item E @var{nn}
40522 An error occurred. @var{nn} are hex digits.
40523
40524 @item @w{}
40525 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40526 the stub.
40527 @end table
40528
40529 Use of this packet is controlled by the @code{set remote catch-syscalls}
40530 command (@pxref{Remote Configuration, set remote catch-syscalls}).
40531 This packet is not probed by default; the remote stub must request it,
40532 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40533
40534 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40535 @cindex pass signals to inferior, remote request
40536 @cindex @samp{QPassSignals} packet
40537 @anchor{QPassSignals}
40538 Each listed @var{signal} should be passed directly to the inferior process.
40539 Signals are numbered identically to continue packets and stop replies
40540 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40541 strictly greater than the previous item. These signals do not need to stop
40542 the inferior, or be reported to @value{GDBN}. All other signals should be
40543 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40544 combine; any earlier @samp{QPassSignals} list is completely replaced by the
40545 new list. This packet improves performance when using @samp{handle
40546 @var{signal} nostop noprint pass}.
40547
40548 Reply:
40549 @table @samp
40550 @item OK
40551 The request succeeded.
40552
40553 @item E @var{nn}
40554 An error occurred. The error number @var{nn} is given as hex digits.
40555
40556 @item @w{}
40557 An empty reply indicates that @samp{QPassSignals} is not supported by
40558 the stub.
40559 @end table
40560
40561 Use of this packet is controlled by the @code{set remote pass-signals}
40562 command (@pxref{Remote Configuration, set remote pass-signals}).
40563 This packet is not probed by default; the remote stub must request it,
40564 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40565
40566 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40567 @cindex signals the inferior may see, remote request
40568 @cindex @samp{QProgramSignals} packet
40569 @anchor{QProgramSignals}
40570 Each listed @var{signal} may be delivered to the inferior process.
40571 Others should be silently discarded.
40572
40573 In some cases, the remote stub may need to decide whether to deliver a
40574 signal to the program or not without @value{GDBN} involvement. One
40575 example of that is while detaching --- the program's threads may have
40576 stopped for signals that haven't yet had a chance of being reported to
40577 @value{GDBN}, and so the remote stub can use the signal list specified
40578 by this packet to know whether to deliver or ignore those pending
40579 signals.
40580
40581 This does not influence whether to deliver a signal as requested by a
40582 resumption packet (@pxref{vCont packet}).
40583
40584 Signals are numbered identically to continue packets and stop replies
40585 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40586 strictly greater than the previous item. Multiple
40587 @samp{QProgramSignals} packets do not combine; any earlier
40588 @samp{QProgramSignals} list is completely replaced by the new list.
40589
40590 Reply:
40591 @table @samp
40592 @item OK
40593 The request succeeded.
40594
40595 @item E @var{nn}
40596 An error occurred. The error number @var{nn} is given as hex digits.
40597
40598 @item @w{}
40599 An empty reply indicates that @samp{QProgramSignals} is not supported
40600 by the stub.
40601 @end table
40602
40603 Use of this packet is controlled by the @code{set remote program-signals}
40604 command (@pxref{Remote Configuration, set remote program-signals}).
40605 This packet is not probed by default; the remote stub must request it,
40606 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40607
40608 @anchor{QThreadEvents}
40609 @item QThreadEvents:1
40610 @itemx QThreadEvents:0
40611 @cindex thread create/exit events, remote request
40612 @cindex @samp{QThreadEvents} packet
40613
40614 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40615 reporting of thread create and exit events. @xref{thread create
40616 event}, for the reply specifications. For example, this is used in
40617 non-stop mode when @value{GDBN} stops a set of threads and
40618 synchronously waits for the their corresponding stop replies. Without
40619 exit events, if one of the threads exits, @value{GDBN} would hang
40620 forever not knowing that it should no longer expect a stop for that
40621 same thread. @value{GDBN} does not enable this feature unless the
40622 stub reports that it supports it by including @samp{QThreadEvents+} in
40623 its @samp{qSupported} reply.
40624
40625 Reply:
40626 @table @samp
40627 @item OK
40628 The request succeeded.
40629
40630 @item E @var{nn}
40631 An error occurred. The error number @var{nn} is given as hex digits.
40632
40633 @item @w{}
40634 An empty reply indicates that @samp{QThreadEvents} is not supported by
40635 the stub.
40636 @end table
40637
40638 Use of this packet is controlled by the @code{set remote thread-events}
40639 command (@pxref{Remote Configuration, set remote thread-events}).
40640
40641 @item qRcmd,@var{command}
40642 @cindex execute remote command, remote request
40643 @cindex @samp{qRcmd} packet
40644 @var{command} (hex encoded) is passed to the local interpreter for
40645 execution. Invalid commands should be reported using the output
40646 string. Before the final result packet, the target may also respond
40647 with a number of intermediate @samp{O@var{output}} console output
40648 packets. @emph{Implementors should note that providing access to a
40649 stubs's interpreter may have security implications}.
40650
40651 Reply:
40652 @table @samp
40653 @item OK
40654 A command response with no output.
40655 @item @var{OUTPUT}
40656 A command response with the hex encoded output string @var{OUTPUT}.
40657 @item E @var{NN}
40658 Indicate a badly formed request.
40659 @item @w{}
40660 An empty reply indicates that @samp{qRcmd} is not recognized.
40661 @end table
40662
40663 (Note that the @code{qRcmd} packet's name is separated from the
40664 command by a @samp{,}, not a @samp{:}, contrary to the naming
40665 conventions above. Please don't use this packet as a model for new
40666 packets.)
40667
40668 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40669 @cindex searching memory, in remote debugging
40670 @ifnotinfo
40671 @cindex @samp{qSearch:memory} packet
40672 @end ifnotinfo
40673 @cindex @samp{qSearch memory} packet
40674 @anchor{qSearch memory}
40675 Search @var{length} bytes at @var{address} for @var{search-pattern}.
40676 Both @var{address} and @var{length} are encoded in hex;
40677 @var{search-pattern} is a sequence of bytes, also hex encoded.
40678
40679 Reply:
40680 @table @samp
40681 @item 0
40682 The pattern was not found.
40683 @item 1,address
40684 The pattern was found at @var{address}.
40685 @item E @var{NN}
40686 A badly formed request or an error was encountered while searching memory.
40687 @item @w{}
40688 An empty reply indicates that @samp{qSearch:memory} is not recognized.
40689 @end table
40690
40691 @item QStartNoAckMode
40692 @cindex @samp{QStartNoAckMode} packet
40693 @anchor{QStartNoAckMode}
40694 Request that the remote stub disable the normal @samp{+}/@samp{-}
40695 protocol acknowledgments (@pxref{Packet Acknowledgment}).
40696
40697 Reply:
40698 @table @samp
40699 @item OK
40700 The stub has switched to no-acknowledgment mode.
40701 @value{GDBN} acknowledges this response,
40702 but neither the stub nor @value{GDBN} shall send or expect further
40703 @samp{+}/@samp{-} acknowledgments in the current connection.
40704 @item @w{}
40705 An empty reply indicates that the stub does not support no-acknowledgment mode.
40706 @end table
40707
40708 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40709 @cindex supported packets, remote query
40710 @cindex features of the remote protocol
40711 @cindex @samp{qSupported} packet
40712 @anchor{qSupported}
40713 Tell the remote stub about features supported by @value{GDBN}, and
40714 query the stub for features it supports. This packet allows
40715 @value{GDBN} and the remote stub to take advantage of each others'
40716 features. @samp{qSupported} also consolidates multiple feature probes
40717 at startup, to improve @value{GDBN} performance---a single larger
40718 packet performs better than multiple smaller probe packets on
40719 high-latency links. Some features may enable behavior which must not
40720 be on by default, e.g.@: because it would confuse older clients or
40721 stubs. Other features may describe packets which could be
40722 automatically probed for, but are not. These features must be
40723 reported before @value{GDBN} will use them. This ``default
40724 unsupported'' behavior is not appropriate for all packets, but it
40725 helps to keep the initial connection time under control with new
40726 versions of @value{GDBN} which support increasing numbers of packets.
40727
40728 Reply:
40729 @table @samp
40730 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40731 The stub supports or does not support each returned @var{stubfeature},
40732 depending on the form of each @var{stubfeature} (see below for the
40733 possible forms).
40734 @item @w{}
40735 An empty reply indicates that @samp{qSupported} is not recognized,
40736 or that no features needed to be reported to @value{GDBN}.
40737 @end table
40738
40739 The allowed forms for each feature (either a @var{gdbfeature} in the
40740 @samp{qSupported} packet, or a @var{stubfeature} in the response)
40741 are:
40742
40743 @table @samp
40744 @item @var{name}=@var{value}
40745 The remote protocol feature @var{name} is supported, and associated
40746 with the specified @var{value}. The format of @var{value} depends
40747 on the feature, but it must not include a semicolon.
40748 @item @var{name}+
40749 The remote protocol feature @var{name} is supported, and does not
40750 need an associated value.
40751 @item @var{name}-
40752 The remote protocol feature @var{name} is not supported.
40753 @item @var{name}?
40754 The remote protocol feature @var{name} may be supported, and
40755 @value{GDBN} should auto-detect support in some other way when it is
40756 needed. This form will not be used for @var{gdbfeature} notifications,
40757 but may be used for @var{stubfeature} responses.
40758 @end table
40759
40760 Whenever the stub receives a @samp{qSupported} request, the
40761 supplied set of @value{GDBN} features should override any previous
40762 request. This allows @value{GDBN} to put the stub in a known
40763 state, even if the stub had previously been communicating with
40764 a different version of @value{GDBN}.
40765
40766 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
40767 are defined:
40768
40769 @table @samp
40770 @item multiprocess
40771 This feature indicates whether @value{GDBN} supports multiprocess
40772 extensions to the remote protocol. @value{GDBN} does not use such
40773 extensions unless the stub also reports that it supports them by
40774 including @samp{multiprocess+} in its @samp{qSupported} reply.
40775 @xref{multiprocess extensions}, for details.
40776
40777 @item xmlRegisters
40778 This feature indicates that @value{GDBN} supports the XML target
40779 description. If the stub sees @samp{xmlRegisters=} with target
40780 specific strings separated by a comma, it will report register
40781 description.
40782
40783 @item qRelocInsn
40784 This feature indicates whether @value{GDBN} supports the
40785 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
40786 instruction reply packet}).
40787
40788 @item swbreak
40789 This feature indicates whether @value{GDBN} supports the swbreak stop
40790 reason in stop replies. @xref{swbreak stop reason}, for details.
40791
40792 @item hwbreak
40793 This feature indicates whether @value{GDBN} supports the hwbreak stop
40794 reason in stop replies. @xref{swbreak stop reason}, for details.
40795
40796 @item fork-events
40797 This feature indicates whether @value{GDBN} supports fork event
40798 extensions to the remote protocol. @value{GDBN} does not use such
40799 extensions unless the stub also reports that it supports them by
40800 including @samp{fork-events+} in its @samp{qSupported} reply.
40801
40802 @item vfork-events
40803 This feature indicates whether @value{GDBN} supports vfork event
40804 extensions to the remote protocol. @value{GDBN} does not use such
40805 extensions unless the stub also reports that it supports them by
40806 including @samp{vfork-events+} in its @samp{qSupported} reply.
40807
40808 @item exec-events
40809 This feature indicates whether @value{GDBN} supports exec event
40810 extensions to the remote protocol. @value{GDBN} does not use such
40811 extensions unless the stub also reports that it supports them by
40812 including @samp{exec-events+} in its @samp{qSupported} reply.
40813
40814 @item vContSupported
40815 This feature indicates whether @value{GDBN} wants to know the
40816 supported actions in the reply to @samp{vCont?} packet.
40817 @end table
40818
40819 Stubs should ignore any unknown values for
40820 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
40821 packet supports receiving packets of unlimited length (earlier
40822 versions of @value{GDBN} may reject overly long responses). Additional values
40823 for @var{gdbfeature} may be defined in the future to let the stub take
40824 advantage of new features in @value{GDBN}, e.g.@: incompatible
40825 improvements in the remote protocol---the @samp{multiprocess} feature is
40826 an example of such a feature. The stub's reply should be independent
40827 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
40828 describes all the features it supports, and then the stub replies with
40829 all the features it supports.
40830
40831 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
40832 responses, as long as each response uses one of the standard forms.
40833
40834 Some features are flags. A stub which supports a flag feature
40835 should respond with a @samp{+} form response. Other features
40836 require values, and the stub should respond with an @samp{=}
40837 form response.
40838
40839 Each feature has a default value, which @value{GDBN} will use if
40840 @samp{qSupported} is not available or if the feature is not mentioned
40841 in the @samp{qSupported} response. The default values are fixed; a
40842 stub is free to omit any feature responses that match the defaults.
40843
40844 Not all features can be probed, but for those which can, the probing
40845 mechanism is useful: in some cases, a stub's internal
40846 architecture may not allow the protocol layer to know some information
40847 about the underlying target in advance. This is especially common in
40848 stubs which may be configured for multiple targets.
40849
40850 These are the currently defined stub features and their properties:
40851
40852 @multitable @columnfractions 0.35 0.2 0.12 0.2
40853 @c NOTE: The first row should be @headitem, but we do not yet require
40854 @c a new enough version of Texinfo (4.7) to use @headitem.
40855 @item Feature Name
40856 @tab Value Required
40857 @tab Default
40858 @tab Probe Allowed
40859
40860 @item @samp{PacketSize}
40861 @tab Yes
40862 @tab @samp{-}
40863 @tab No
40864
40865 @item @samp{qXfer:auxv:read}
40866 @tab No
40867 @tab @samp{-}
40868 @tab Yes
40869
40870 @item @samp{qXfer:btrace:read}
40871 @tab No
40872 @tab @samp{-}
40873 @tab Yes
40874
40875 @item @samp{qXfer:btrace-conf:read}
40876 @tab No
40877 @tab @samp{-}
40878 @tab Yes
40879
40880 @item @samp{qXfer:exec-file:read}
40881 @tab No
40882 @tab @samp{-}
40883 @tab Yes
40884
40885 @item @samp{qXfer:features:read}
40886 @tab No
40887 @tab @samp{-}
40888 @tab Yes
40889
40890 @item @samp{qXfer:libraries:read}
40891 @tab No
40892 @tab @samp{-}
40893 @tab Yes
40894
40895 @item @samp{qXfer:libraries-svr4:read}
40896 @tab No
40897 @tab @samp{-}
40898 @tab Yes
40899
40900 @item @samp{augmented-libraries-svr4-read}
40901 @tab No
40902 @tab @samp{-}
40903 @tab No
40904
40905 @item @samp{qXfer:memory-map:read}
40906 @tab No
40907 @tab @samp{-}
40908 @tab Yes
40909
40910 @item @samp{qXfer:sdata:read}
40911 @tab No
40912 @tab @samp{-}
40913 @tab Yes
40914
40915 @item @samp{qXfer:siginfo:read}
40916 @tab No
40917 @tab @samp{-}
40918 @tab Yes
40919
40920 @item @samp{qXfer:siginfo:write}
40921 @tab No
40922 @tab @samp{-}
40923 @tab Yes
40924
40925 @item @samp{qXfer:threads:read}
40926 @tab No
40927 @tab @samp{-}
40928 @tab Yes
40929
40930 @item @samp{qXfer:traceframe-info:read}
40931 @tab No
40932 @tab @samp{-}
40933 @tab Yes
40934
40935 @item @samp{qXfer:uib:read}
40936 @tab No
40937 @tab @samp{-}
40938 @tab Yes
40939
40940 @item @samp{qXfer:fdpic:read}
40941 @tab No
40942 @tab @samp{-}
40943 @tab Yes
40944
40945 @item @samp{Qbtrace:off}
40946 @tab Yes
40947 @tab @samp{-}
40948 @tab Yes
40949
40950 @item @samp{Qbtrace:bts}
40951 @tab Yes
40952 @tab @samp{-}
40953 @tab Yes
40954
40955 @item @samp{Qbtrace:pt}
40956 @tab Yes
40957 @tab @samp{-}
40958 @tab Yes
40959
40960 @item @samp{Qbtrace-conf:bts:size}
40961 @tab Yes
40962 @tab @samp{-}
40963 @tab Yes
40964
40965 @item @samp{Qbtrace-conf:pt:size}
40966 @tab Yes
40967 @tab @samp{-}
40968 @tab Yes
40969
40970 @item @samp{QNonStop}
40971 @tab No
40972 @tab @samp{-}
40973 @tab Yes
40974
40975 @item @samp{QCatchSyscalls}
40976 @tab No
40977 @tab @samp{-}
40978 @tab Yes
40979
40980 @item @samp{QPassSignals}
40981 @tab No
40982 @tab @samp{-}
40983 @tab Yes
40984
40985 @item @samp{QStartNoAckMode}
40986 @tab No
40987 @tab @samp{-}
40988 @tab Yes
40989
40990 @item @samp{multiprocess}
40991 @tab No
40992 @tab @samp{-}
40993 @tab No
40994
40995 @item @samp{ConditionalBreakpoints}
40996 @tab No
40997 @tab @samp{-}
40998 @tab No
40999
41000 @item @samp{ConditionalTracepoints}
41001 @tab No
41002 @tab @samp{-}
41003 @tab No
41004
41005 @item @samp{ReverseContinue}
41006 @tab No
41007 @tab @samp{-}
41008 @tab No
41009
41010 @item @samp{ReverseStep}
41011 @tab No
41012 @tab @samp{-}
41013 @tab No
41014
41015 @item @samp{TracepointSource}
41016 @tab No
41017 @tab @samp{-}
41018 @tab No
41019
41020 @item @samp{QAgent}
41021 @tab No
41022 @tab @samp{-}
41023 @tab No
41024
41025 @item @samp{QAllow}
41026 @tab No
41027 @tab @samp{-}
41028 @tab No
41029
41030 @item @samp{QDisableRandomization}
41031 @tab No
41032 @tab @samp{-}
41033 @tab No
41034
41035 @item @samp{EnableDisableTracepoints}
41036 @tab No
41037 @tab @samp{-}
41038 @tab No
41039
41040 @item @samp{QTBuffer:size}
41041 @tab No
41042 @tab @samp{-}
41043 @tab No
41044
41045 @item @samp{tracenz}
41046 @tab No
41047 @tab @samp{-}
41048 @tab No
41049
41050 @item @samp{BreakpointCommands}
41051 @tab No
41052 @tab @samp{-}
41053 @tab No
41054
41055 @item @samp{swbreak}
41056 @tab No
41057 @tab @samp{-}
41058 @tab No
41059
41060 @item @samp{hwbreak}
41061 @tab No
41062 @tab @samp{-}
41063 @tab No
41064
41065 @item @samp{fork-events}
41066 @tab No
41067 @tab @samp{-}
41068 @tab No
41069
41070 @item @samp{vfork-events}
41071 @tab No
41072 @tab @samp{-}
41073 @tab No
41074
41075 @item @samp{exec-events}
41076 @tab No
41077 @tab @samp{-}
41078 @tab No
41079
41080 @item @samp{QThreadEvents}
41081 @tab No
41082 @tab @samp{-}
41083 @tab No
41084
41085 @item @samp{no-resumed}
41086 @tab No
41087 @tab @samp{-}
41088 @tab No
41089
41090 @end multitable
41091
41092 These are the currently defined stub features, in more detail:
41093
41094 @table @samp
41095 @cindex packet size, remote protocol
41096 @item PacketSize=@var{bytes}
41097 The remote stub can accept packets up to at least @var{bytes} in
41098 length. @value{GDBN} will send packets up to this size for bulk
41099 transfers, and will never send larger packets. This is a limit on the
41100 data characters in the packet, including the frame and checksum.
41101 There is no trailing NUL byte in a remote protocol packet; if the stub
41102 stores packets in a NUL-terminated format, it should allow an extra
41103 byte in its buffer for the NUL. If this stub feature is not supported,
41104 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41105
41106 @item qXfer:auxv:read
41107 The remote stub understands the @samp{qXfer:auxv:read} packet
41108 (@pxref{qXfer auxiliary vector read}).
41109
41110 @item qXfer:btrace:read
41111 The remote stub understands the @samp{qXfer:btrace:read}
41112 packet (@pxref{qXfer btrace read}).
41113
41114 @item qXfer:btrace-conf:read
41115 The remote stub understands the @samp{qXfer:btrace-conf:read}
41116 packet (@pxref{qXfer btrace-conf read}).
41117
41118 @item qXfer:exec-file:read
41119 The remote stub understands the @samp{qXfer:exec-file:read} packet
41120 (@pxref{qXfer executable filename read}).
41121
41122 @item qXfer:features:read
41123 The remote stub understands the @samp{qXfer:features:read} packet
41124 (@pxref{qXfer target description read}).
41125
41126 @item qXfer:libraries:read
41127 The remote stub understands the @samp{qXfer:libraries:read} packet
41128 (@pxref{qXfer library list read}).
41129
41130 @item qXfer:libraries-svr4:read
41131 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41132 (@pxref{qXfer svr4 library list read}).
41133
41134 @item augmented-libraries-svr4-read
41135 The remote stub understands the augmented form of the
41136 @samp{qXfer:libraries-svr4:read} packet
41137 (@pxref{qXfer svr4 library list read}).
41138
41139 @item qXfer:memory-map:read
41140 The remote stub understands the @samp{qXfer:memory-map:read} packet
41141 (@pxref{qXfer memory map read}).
41142
41143 @item qXfer:sdata:read
41144 The remote stub understands the @samp{qXfer:sdata:read} packet
41145 (@pxref{qXfer sdata read}).
41146
41147 @item qXfer:siginfo:read
41148 The remote stub understands the @samp{qXfer:siginfo:read} packet
41149 (@pxref{qXfer siginfo read}).
41150
41151 @item qXfer:siginfo:write
41152 The remote stub understands the @samp{qXfer:siginfo:write} packet
41153 (@pxref{qXfer siginfo write}).
41154
41155 @item qXfer:threads:read
41156 The remote stub understands the @samp{qXfer:threads:read} packet
41157 (@pxref{qXfer threads read}).
41158
41159 @item qXfer:traceframe-info:read
41160 The remote stub understands the @samp{qXfer:traceframe-info:read}
41161 packet (@pxref{qXfer traceframe info read}).
41162
41163 @item qXfer:uib:read
41164 The remote stub understands the @samp{qXfer:uib:read}
41165 packet (@pxref{qXfer unwind info block}).
41166
41167 @item qXfer:fdpic:read
41168 The remote stub understands the @samp{qXfer:fdpic:read}
41169 packet (@pxref{qXfer fdpic loadmap read}).
41170
41171 @item QNonStop
41172 The remote stub understands the @samp{QNonStop} packet
41173 (@pxref{QNonStop}).
41174
41175 @item QCatchSyscalls
41176 The remote stub understands the @samp{QCatchSyscalls} packet
41177 (@pxref{QCatchSyscalls}).
41178
41179 @item QPassSignals
41180 The remote stub understands the @samp{QPassSignals} packet
41181 (@pxref{QPassSignals}).
41182
41183 @item QStartNoAckMode
41184 The remote stub understands the @samp{QStartNoAckMode} packet and
41185 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41186
41187 @item multiprocess
41188 @anchor{multiprocess extensions}
41189 @cindex multiprocess extensions, in remote protocol
41190 The remote stub understands the multiprocess extensions to the remote
41191 protocol syntax. The multiprocess extensions affect the syntax of
41192 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41193 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41194 replies. Note that reporting this feature indicates support for the
41195 syntactic extensions only, not that the stub necessarily supports
41196 debugging of more than one process at a time. The stub must not use
41197 multiprocess extensions in packet replies unless @value{GDBN} has also
41198 indicated it supports them in its @samp{qSupported} request.
41199
41200 @item qXfer:osdata:read
41201 The remote stub understands the @samp{qXfer:osdata:read} packet
41202 ((@pxref{qXfer osdata read}).
41203
41204 @item ConditionalBreakpoints
41205 The target accepts and implements evaluation of conditional expressions
41206 defined for breakpoints. The target will only report breakpoint triggers
41207 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41208
41209 @item ConditionalTracepoints
41210 The remote stub accepts and implements conditional expressions defined
41211 for tracepoints (@pxref{Tracepoint Conditions}).
41212
41213 @item ReverseContinue
41214 The remote stub accepts and implements the reverse continue packet
41215 (@pxref{bc}).
41216
41217 @item ReverseStep
41218 The remote stub accepts and implements the reverse step packet
41219 (@pxref{bs}).
41220
41221 @item TracepointSource
41222 The remote stub understands the @samp{QTDPsrc} packet that supplies
41223 the source form of tracepoint definitions.
41224
41225 @item QAgent
41226 The remote stub understands the @samp{QAgent} packet.
41227
41228 @item QAllow
41229 The remote stub understands the @samp{QAllow} packet.
41230
41231 @item QDisableRandomization
41232 The remote stub understands the @samp{QDisableRandomization} packet.
41233
41234 @item StaticTracepoint
41235 @cindex static tracepoints, in remote protocol
41236 The remote stub supports static tracepoints.
41237
41238 @item InstallInTrace
41239 @anchor{install tracepoint in tracing}
41240 The remote stub supports installing tracepoint in tracing.
41241
41242 @item EnableDisableTracepoints
41243 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41244 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41245 to be enabled and disabled while a trace experiment is running.
41246
41247 @item QTBuffer:size
41248 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
41249 packet that allows to change the size of the trace buffer.
41250
41251 @item tracenz
41252 @cindex string tracing, in remote protocol
41253 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41254 See @ref{Bytecode Descriptions} for details about the bytecode.
41255
41256 @item BreakpointCommands
41257 @cindex breakpoint commands, in remote protocol
41258 The remote stub supports running a breakpoint's command list itself,
41259 rather than reporting the hit to @value{GDBN}.
41260
41261 @item Qbtrace:off
41262 The remote stub understands the @samp{Qbtrace:off} packet.
41263
41264 @item Qbtrace:bts
41265 The remote stub understands the @samp{Qbtrace:bts} packet.
41266
41267 @item Qbtrace:pt
41268 The remote stub understands the @samp{Qbtrace:pt} packet.
41269
41270 @item Qbtrace-conf:bts:size
41271 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41272
41273 @item Qbtrace-conf:pt:size
41274 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41275
41276 @item swbreak
41277 The remote stub reports the @samp{swbreak} stop reason for memory
41278 breakpoints.
41279
41280 @item hwbreak
41281 The remote stub reports the @samp{hwbreak} stop reason for hardware
41282 breakpoints.
41283
41284 @item fork-events
41285 The remote stub reports the @samp{fork} stop reason for fork events.
41286
41287 @item vfork-events
41288 The remote stub reports the @samp{vfork} stop reason for vfork events
41289 and vforkdone events.
41290
41291 @item exec-events
41292 The remote stub reports the @samp{exec} stop reason for exec events.
41293
41294 @item vContSupported
41295 The remote stub reports the supported actions in the reply to
41296 @samp{vCont?} packet.
41297
41298 @item QThreadEvents
41299 The remote stub understands the @samp{QThreadEvents} packet.
41300
41301 @item no-resumed
41302 The remote stub reports the @samp{N} stop reply.
41303
41304 @end table
41305
41306 @item qSymbol::
41307 @cindex symbol lookup, remote request
41308 @cindex @samp{qSymbol} packet
41309 Notify the target that @value{GDBN} is prepared to serve symbol lookup
41310 requests. Accept requests from the target for the values of symbols.
41311
41312 Reply:
41313 @table @samp
41314 @item OK
41315 The target does not need to look up any (more) symbols.
41316 @item qSymbol:@var{sym_name}
41317 The target requests the value of symbol @var{sym_name} (hex encoded).
41318 @value{GDBN} may provide the value by using the
41319 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41320 below.
41321 @end table
41322
41323 @item qSymbol:@var{sym_value}:@var{sym_name}
41324 Set the value of @var{sym_name} to @var{sym_value}.
41325
41326 @var{sym_name} (hex encoded) is the name of a symbol whose value the
41327 target has previously requested.
41328
41329 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41330 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
41331 will be empty.
41332
41333 Reply:
41334 @table @samp
41335 @item OK
41336 The target does not need to look up any (more) symbols.
41337 @item qSymbol:@var{sym_name}
41338 The target requests the value of a new symbol @var{sym_name} (hex
41339 encoded). @value{GDBN} will continue to supply the values of symbols
41340 (if available), until the target ceases to request them.
41341 @end table
41342
41343 @item qTBuffer
41344 @itemx QTBuffer
41345 @itemx QTDisconnected
41346 @itemx QTDP
41347 @itemx QTDPsrc
41348 @itemx QTDV
41349 @itemx qTfP
41350 @itemx qTfV
41351 @itemx QTFrame
41352 @itemx qTMinFTPILen
41353
41354 @xref{Tracepoint Packets}.
41355
41356 @item qThreadExtraInfo,@var{thread-id}
41357 @cindex thread attributes info, remote request
41358 @cindex @samp{qThreadExtraInfo} packet
41359 Obtain from the target OS a printable string description of thread
41360 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41361 for the forms of @var{thread-id}. This
41362 string may contain anything that the target OS thinks is interesting
41363 for @value{GDBN} to tell the user about the thread. The string is
41364 displayed in @value{GDBN}'s @code{info threads} display. Some
41365 examples of possible thread extra info strings are @samp{Runnable}, or
41366 @samp{Blocked on Mutex}.
41367
41368 Reply:
41369 @table @samp
41370 @item @var{XX}@dots{}
41371 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41372 comprising the printable string containing the extra information about
41373 the thread's attributes.
41374 @end table
41375
41376 (Note that the @code{qThreadExtraInfo} packet's name is separated from
41377 the command by a @samp{,}, not a @samp{:}, contrary to the naming
41378 conventions above. Please don't use this packet as a model for new
41379 packets.)
41380
41381 @item QTNotes
41382 @itemx qTP
41383 @itemx QTSave
41384 @itemx qTsP
41385 @itemx qTsV
41386 @itemx QTStart
41387 @itemx QTStop
41388 @itemx QTEnable
41389 @itemx QTDisable
41390 @itemx QTinit
41391 @itemx QTro
41392 @itemx qTStatus
41393 @itemx qTV
41394 @itemx qTfSTM
41395 @itemx qTsSTM
41396 @itemx qTSTMat
41397 @xref{Tracepoint Packets}.
41398
41399 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41400 @cindex read special object, remote request
41401 @cindex @samp{qXfer} packet
41402 @anchor{qXfer read}
41403 Read uninterpreted bytes from the target's special data area
41404 identified by the keyword @var{object}. Request @var{length} bytes
41405 starting at @var{offset} bytes into the data. The content and
41406 encoding of @var{annex} is specific to @var{object}; it can supply
41407 additional details about what data to access.
41408
41409 Reply:
41410 @table @samp
41411 @item m @var{data}
41412 Data @var{data} (@pxref{Binary Data}) has been read from the
41413 target. There may be more data at a higher address (although
41414 it is permitted to return @samp{m} even for the last valid
41415 block of data, as long as at least one byte of data was read).
41416 It is possible for @var{data} to have fewer bytes than the @var{length} in the
41417 request.
41418
41419 @item l @var{data}
41420 Data @var{data} (@pxref{Binary Data}) has been read from the target.
41421 There is no more data to be read. It is possible for @var{data} to
41422 have fewer bytes than the @var{length} in the request.
41423
41424 @item l
41425 The @var{offset} in the request is at the end of the data.
41426 There is no more data to be read.
41427
41428 @item E00
41429 The request was malformed, or @var{annex} was invalid.
41430
41431 @item E @var{nn}
41432 The offset was invalid, or there was an error encountered reading the data.
41433 The @var{nn} part is a hex-encoded @code{errno} value.
41434
41435 @item @w{}
41436 An empty reply indicates the @var{object} string was not recognized by
41437 the stub, or that the object does not support reading.
41438 @end table
41439
41440 Here are the specific requests of this form defined so far. All the
41441 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
41442 formats, listed above.
41443
41444 @table @samp
41445 @item qXfer:auxv:read::@var{offset},@var{length}
41446 @anchor{qXfer auxiliary vector read}
41447 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
41448 auxiliary vector}. Note @var{annex} must be empty.
41449
41450 This packet is not probed by default; the remote stub must request it,
41451 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41452
41453 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41454 @anchor{qXfer btrace read}
41455
41456 Return a description of the current branch trace.
41457 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41458 packet may have one of the following values:
41459
41460 @table @code
41461 @item all
41462 Returns all available branch trace.
41463
41464 @item new
41465 Returns all available branch trace if the branch trace changed since
41466 the last read request.
41467
41468 @item delta
41469 Returns the new branch trace since the last read request. Adds a new
41470 block to the end of the trace that begins at zero and ends at the source
41471 location of the first branch in the trace buffer. This extra block is
41472 used to stitch traces together.
41473
41474 If the trace buffer overflowed, returns an error indicating the overflow.
41475 @end table
41476
41477 This packet is not probed by default; the remote stub must request it
41478 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41479
41480 @item qXfer:btrace-conf:read::@var{offset},@var{length}
41481 @anchor{qXfer btrace-conf read}
41482
41483 Return a description of the current branch trace configuration.
41484 @xref{Branch Trace Configuration Format}.
41485
41486 This packet is not probed by default; the remote stub must request it
41487 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41488
41489 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41490 @anchor{qXfer executable filename read}
41491 Return the full absolute name of the file that was executed to create
41492 a process running on the remote system. The annex specifies the
41493 numeric process ID of the process to query, encoded as a hexadecimal
41494 number. If the annex part is empty the remote stub should return the
41495 filename corresponding to the currently executing process.
41496
41497 This packet is not probed by default; the remote stub must request it,
41498 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41499
41500 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41501 @anchor{qXfer target description read}
41502 Access the @dfn{target description}. @xref{Target Descriptions}. The
41503 annex specifies which XML document to access. The main description is
41504 always loaded from the @samp{target.xml} annex.
41505
41506 This packet is not probed by default; the remote stub must request it,
41507 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41508
41509 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41510 @anchor{qXfer library list read}
41511 Access the target's list of loaded libraries. @xref{Library List Format}.
41512 The annex part of the generic @samp{qXfer} packet must be empty
41513 (@pxref{qXfer read}).
41514
41515 Targets which maintain a list of libraries in the program's memory do
41516 not need to implement this packet; it is designed for platforms where
41517 the operating system manages the list of loaded libraries.
41518
41519 This packet is not probed by default; the remote stub must request it,
41520 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41521
41522 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41523 @anchor{qXfer svr4 library list read}
41524 Access the target's list of loaded libraries when the target is an SVR4
41525 platform. @xref{Library List Format for SVR4 Targets}. The annex part
41526 of the generic @samp{qXfer} packet must be empty unless the remote
41527 stub indicated it supports the augmented form of this packet
41528 by supplying an appropriate @samp{qSupported} response
41529 (@pxref{qXfer read}, @ref{qSupported}).
41530
41531 This packet is optional for better performance on SVR4 targets.
41532 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41533
41534 This packet is not probed by default; the remote stub must request it,
41535 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41536
41537 If the remote stub indicates it supports the augmented form of this
41538 packet then the annex part of the generic @samp{qXfer} packet may
41539 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41540 arguments. The currently supported arguments are:
41541
41542 @table @code
41543 @item start=@var{address}
41544 A hexadecimal number specifying the address of the @samp{struct
41545 link_map} to start reading the library list from. If unset or zero
41546 then the first @samp{struct link_map} in the library list will be
41547 chosen as the starting point.
41548
41549 @item prev=@var{address}
41550 A hexadecimal number specifying the address of the @samp{struct
41551 link_map} immediately preceding the @samp{struct link_map}
41552 specified by the @samp{start} argument. If unset or zero then
41553 the remote stub will expect that no @samp{struct link_map}
41554 exists prior to the starting point.
41555
41556 @end table
41557
41558 Arguments that are not understood by the remote stub will be silently
41559 ignored.
41560
41561 @item qXfer:memory-map:read::@var{offset},@var{length}
41562 @anchor{qXfer memory map read}
41563 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
41564 annex part of the generic @samp{qXfer} packet must be empty
41565 (@pxref{qXfer read}).
41566
41567 This packet is not probed by default; the remote stub must request it,
41568 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41569
41570 @item qXfer:sdata:read::@var{offset},@var{length}
41571 @anchor{qXfer sdata read}
41572
41573 Read contents of the extra collected static tracepoint marker
41574 information. The annex part of the generic @samp{qXfer} packet must
41575 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41576 Action Lists}.
41577
41578 This packet is not probed by default; the remote stub must request it,
41579 by supplying an appropriate @samp{qSupported} response
41580 (@pxref{qSupported}).
41581
41582 @item qXfer:siginfo:read::@var{offset},@var{length}
41583 @anchor{qXfer siginfo read}
41584 Read contents of the extra signal information on the target
41585 system. The annex part of the generic @samp{qXfer} packet must be
41586 empty (@pxref{qXfer read}).
41587
41588 This packet is not probed by default; the remote stub must request it,
41589 by supplying an appropriate @samp{qSupported} response
41590 (@pxref{qSupported}).
41591
41592 @item qXfer:threads:read::@var{offset},@var{length}
41593 @anchor{qXfer threads read}
41594 Access the list of threads on target. @xref{Thread List Format}. The
41595 annex part of the generic @samp{qXfer} packet must be empty
41596 (@pxref{qXfer read}).
41597
41598 This packet is not probed by default; the remote stub must request it,
41599 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41600
41601 @item qXfer:traceframe-info:read::@var{offset},@var{length}
41602 @anchor{qXfer traceframe info read}
41603
41604 Return a description of the current traceframe's contents.
41605 @xref{Traceframe Info Format}. The annex part of the generic
41606 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
41607
41608 This packet is not probed by default; the remote stub must request it,
41609 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41610
41611 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41612 @anchor{qXfer unwind info block}
41613
41614 Return the unwind information block for @var{pc}. This packet is used
41615 on OpenVMS/ia64 to ask the kernel unwind information.
41616
41617 This packet is not probed by default.
41618
41619 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41620 @anchor{qXfer fdpic loadmap read}
41621 Read contents of @code{loadmap}s on the target system. The
41622 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41623 executable @code{loadmap} or interpreter @code{loadmap} to read.
41624
41625 This packet is not probed by default; the remote stub must request it,
41626 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41627
41628 @item qXfer:osdata:read::@var{offset},@var{length}
41629 @anchor{qXfer osdata read}
41630 Access the target's @dfn{operating system information}.
41631 @xref{Operating System Information}.
41632
41633 @end table
41634
41635 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41636 @cindex write data into object, remote request
41637 @anchor{qXfer write}
41638 Write uninterpreted bytes into the target's special data area
41639 identified by the keyword @var{object}, starting at @var{offset} bytes
41640 into the data. The binary-encoded data (@pxref{Binary Data}) to be
41641 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41642 is specific to @var{object}; it can supply additional details about what data
41643 to access.
41644
41645 Reply:
41646 @table @samp
41647 @item @var{nn}
41648 @var{nn} (hex encoded) is the number of bytes written.
41649 This may be fewer bytes than supplied in the request.
41650
41651 @item E00
41652 The request was malformed, or @var{annex} was invalid.
41653
41654 @item E @var{nn}
41655 The offset was invalid, or there was an error encountered writing the data.
41656 The @var{nn} part is a hex-encoded @code{errno} value.
41657
41658 @item @w{}
41659 An empty reply indicates the @var{object} string was not
41660 recognized by the stub, or that the object does not support writing.
41661 @end table
41662
41663 Here are the specific requests of this form defined so far. All the
41664 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
41665 formats, listed above.
41666
41667 @table @samp
41668 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41669 @anchor{qXfer siginfo write}
41670 Write @var{data} to the extra signal information on the target system.
41671 The annex part of the generic @samp{qXfer} packet must be
41672 empty (@pxref{qXfer write}).
41673
41674 This packet is not probed by default; the remote stub must request it,
41675 by supplying an appropriate @samp{qSupported} response
41676 (@pxref{qSupported}).
41677 @end table
41678
41679 @item qXfer:@var{object}:@var{operation}:@dots{}
41680 Requests of this form may be added in the future. When a stub does
41681 not recognize the @var{object} keyword, or its support for
41682 @var{object} does not recognize the @var{operation} keyword, the stub
41683 must respond with an empty packet.
41684
41685 @item qAttached:@var{pid}
41686 @cindex query attached, remote request
41687 @cindex @samp{qAttached} packet
41688 Return an indication of whether the remote server attached to an
41689 existing process or created a new process. When the multiprocess
41690 protocol extensions are supported (@pxref{multiprocess extensions}),
41691 @var{pid} is an integer in hexadecimal format identifying the target
41692 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41693 the query packet will be simplified as @samp{qAttached}.
41694
41695 This query is used, for example, to know whether the remote process
41696 should be detached or killed when a @value{GDBN} session is ended with
41697 the @code{quit} command.
41698
41699 Reply:
41700 @table @samp
41701 @item 1
41702 The remote server attached to an existing process.
41703 @item 0
41704 The remote server created a new process.
41705 @item E @var{NN}
41706 A badly formed request or an error was encountered.
41707 @end table
41708
41709 @item Qbtrace:bts
41710 Enable branch tracing for the current thread using Branch Trace Store.
41711
41712 Reply:
41713 @table @samp
41714 @item OK
41715 Branch tracing has been enabled.
41716 @item E.errtext
41717 A badly formed request or an error was encountered.
41718 @end table
41719
41720 @item Qbtrace:pt
41721 Enable branch tracing for the current thread using Intel Processor Trace.
41722
41723 Reply:
41724 @table @samp
41725 @item OK
41726 Branch tracing has been enabled.
41727 @item E.errtext
41728 A badly formed request or an error was encountered.
41729 @end table
41730
41731 @item Qbtrace:off
41732 Disable branch tracing for the current thread.
41733
41734 Reply:
41735 @table @samp
41736 @item OK
41737 Branch tracing has been disabled.
41738 @item E.errtext
41739 A badly formed request or an error was encountered.
41740 @end table
41741
41742 @item Qbtrace-conf:bts:size=@var{value}
41743 Set the requested ring buffer size for new threads that use the
41744 btrace recording method in bts format.
41745
41746 Reply:
41747 @table @samp
41748 @item OK
41749 The ring buffer size has been set.
41750 @item E.errtext
41751 A badly formed request or an error was encountered.
41752 @end table
41753
41754 @item Qbtrace-conf:pt:size=@var{value}
41755 Set the requested ring buffer size for new threads that use the
41756 btrace recording method in pt format.
41757
41758 Reply:
41759 @table @samp
41760 @item OK
41761 The ring buffer size has been set.
41762 @item E.errtext
41763 A badly formed request or an error was encountered.
41764 @end table
41765
41766 @end table
41767
41768 @node Architecture-Specific Protocol Details
41769 @section Architecture-Specific Protocol Details
41770
41771 This section describes how the remote protocol is applied to specific
41772 target architectures. Also see @ref{Standard Target Features}, for
41773 details of XML target descriptions for each architecture.
41774
41775 @menu
41776 * ARM-Specific Protocol Details::
41777 * MIPS-Specific Protocol Details::
41778 @end menu
41779
41780 @node ARM-Specific Protocol Details
41781 @subsection @acronym{ARM}-specific Protocol Details
41782
41783 @menu
41784 * ARM Breakpoint Kinds::
41785 @end menu
41786
41787 @node ARM Breakpoint Kinds
41788 @subsubsection @acronym{ARM} Breakpoint Kinds
41789 @cindex breakpoint kinds, @acronym{ARM}
41790
41791 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41792
41793 @table @r
41794
41795 @item 2
41796 16-bit Thumb mode breakpoint.
41797
41798 @item 3
41799 32-bit Thumb mode (Thumb-2) breakpoint.
41800
41801 @item 4
41802 32-bit @acronym{ARM} mode breakpoint.
41803
41804 @end table
41805
41806 @node MIPS-Specific Protocol Details
41807 @subsection @acronym{MIPS}-specific Protocol Details
41808
41809 @menu
41810 * MIPS Register packet Format::
41811 * MIPS Breakpoint Kinds::
41812 @end menu
41813
41814 @node MIPS Register packet Format
41815 @subsubsection @acronym{MIPS} Register Packet Format
41816 @cindex register packet format, @acronym{MIPS}
41817
41818 The following @code{g}/@code{G} packets have previously been defined.
41819 In the below, some thirty-two bit registers are transferred as
41820 sixty-four bits. Those registers should be zero/sign extended (which?)
41821 to fill the space allocated. Register bytes are transferred in target
41822 byte order. The two nibbles within a register byte are transferred
41823 most-significant -- least-significant.
41824
41825 @table @r
41826
41827 @item MIPS32
41828 All registers are transferred as thirty-two bit quantities in the order:
41829 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
41830 registers; fsr; fir; fp.
41831
41832 @item MIPS64
41833 All registers are transferred as sixty-four bit quantities (including
41834 thirty-two bit registers such as @code{sr}). The ordering is the same
41835 as @code{MIPS32}.
41836
41837 @end table
41838
41839 @node MIPS Breakpoint Kinds
41840 @subsubsection @acronym{MIPS} Breakpoint Kinds
41841 @cindex breakpoint kinds, @acronym{MIPS}
41842
41843 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41844
41845 @table @r
41846
41847 @item 2
41848 16-bit @acronym{MIPS16} mode breakpoint.
41849
41850 @item 3
41851 16-bit @acronym{microMIPS} mode breakpoint.
41852
41853 @item 4
41854 32-bit standard @acronym{MIPS} mode breakpoint.
41855
41856 @item 5
41857 32-bit @acronym{microMIPS} mode breakpoint.
41858
41859 @end table
41860
41861 @node Tracepoint Packets
41862 @section Tracepoint Packets
41863 @cindex tracepoint packets
41864 @cindex packets, tracepoint
41865
41866 Here we describe the packets @value{GDBN} uses to implement
41867 tracepoints (@pxref{Tracepoints}).
41868
41869 @table @samp
41870
41871 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
41872 @cindex @samp{QTDP} packet
41873 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
41874 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
41875 the tracepoint is disabled. The @var{step} gives the tracepoint's step
41876 count, and @var{pass} gives its pass count. If an @samp{F} is present,
41877 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
41878 the number of bytes that the target should copy elsewhere to make room
41879 for the tracepoint. If an @samp{X} is present, it introduces a
41880 tracepoint condition, which consists of a hexadecimal length, followed
41881 by a comma and hex-encoded bytes, in a manner similar to action
41882 encodings as described below. If the trailing @samp{-} is present,
41883 further @samp{QTDP} packets will follow to specify this tracepoint's
41884 actions.
41885
41886 Replies:
41887 @table @samp
41888 @item OK
41889 The packet was understood and carried out.
41890 @item qRelocInsn
41891 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
41892 @item @w{}
41893 The packet was not recognized.
41894 @end table
41895
41896 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
41897 Define actions to be taken when a tracepoint is hit. The @var{n} and
41898 @var{addr} must be the same as in the initial @samp{QTDP} packet for
41899 this tracepoint. This packet may only be sent immediately after
41900 another @samp{QTDP} packet that ended with a @samp{-}. If the
41901 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
41902 specifying more actions for this tracepoint.
41903
41904 In the series of action packets for a given tracepoint, at most one
41905 can have an @samp{S} before its first @var{action}. If such a packet
41906 is sent, it and the following packets define ``while-stepping''
41907 actions. Any prior packets define ordinary actions --- that is, those
41908 taken when the tracepoint is first hit. If no action packet has an
41909 @samp{S}, then all the packets in the series specify ordinary
41910 tracepoint actions.
41911
41912 The @samp{@var{action}@dots{}} portion of the packet is a series of
41913 actions, concatenated without separators. Each action has one of the
41914 following forms:
41915
41916 @table @samp
41917
41918 @item R @var{mask}
41919 Collect the registers whose bits are set in @var{mask},
41920 a hexadecimal number whose @var{i}'th bit is set if register number
41921 @var{i} should be collected. (The least significant bit is numbered
41922 zero.) Note that @var{mask} may be any number of digits long; it may
41923 not fit in a 32-bit word.
41924
41925 @item M @var{basereg},@var{offset},@var{len}
41926 Collect @var{len} bytes of memory starting at the address in register
41927 number @var{basereg}, plus @var{offset}. If @var{basereg} is
41928 @samp{-1}, then the range has a fixed address: @var{offset} is the
41929 address of the lowest byte to collect. The @var{basereg},
41930 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
41931 values (the @samp{-1} value for @var{basereg} is a special case).
41932
41933 @item X @var{len},@var{expr}
41934 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
41935 it directs. The agent expression @var{expr} is as described in
41936 @ref{Agent Expressions}. Each byte of the expression is encoded as a
41937 two-digit hex number in the packet; @var{len} is the number of bytes
41938 in the expression (and thus one-half the number of hex digits in the
41939 packet).
41940
41941 @end table
41942
41943 Any number of actions may be packed together in a single @samp{QTDP}
41944 packet, as long as the packet does not exceed the maximum packet
41945 length (400 bytes, for many stubs). There may be only one @samp{R}
41946 action per tracepoint, and it must precede any @samp{M} or @samp{X}
41947 actions. Any registers referred to by @samp{M} and @samp{X} actions
41948 must be collected by a preceding @samp{R} action. (The
41949 ``while-stepping'' actions are treated as if they were attached to a
41950 separate tracepoint, as far as these restrictions are concerned.)
41951
41952 Replies:
41953 @table @samp
41954 @item OK
41955 The packet was understood and carried out.
41956 @item qRelocInsn
41957 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
41958 @item @w{}
41959 The packet was not recognized.
41960 @end table
41961
41962 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
41963 @cindex @samp{QTDPsrc} packet
41964 Specify a source string of tracepoint @var{n} at address @var{addr}.
41965 This is useful to get accurate reproduction of the tracepoints
41966 originally downloaded at the beginning of the trace run. The @var{type}
41967 is the name of the tracepoint part, such as @samp{cond} for the
41968 tracepoint's conditional expression (see below for a list of types), while
41969 @var{bytes} is the string, encoded in hexadecimal.
41970
41971 @var{start} is the offset of the @var{bytes} within the overall source
41972 string, while @var{slen} is the total length of the source string.
41973 This is intended for handling source strings that are longer than will
41974 fit in a single packet.
41975 @c Add detailed example when this info is moved into a dedicated
41976 @c tracepoint descriptions section.
41977
41978 The available string types are @samp{at} for the location,
41979 @samp{cond} for the conditional, and @samp{cmd} for an action command.
41980 @value{GDBN} sends a separate packet for each command in the action
41981 list, in the same order in which the commands are stored in the list.
41982
41983 The target does not need to do anything with source strings except
41984 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
41985 query packets.
41986
41987 Although this packet is optional, and @value{GDBN} will only send it
41988 if the target replies with @samp{TracepointSource} @xref{General
41989 Query Packets}, it makes both disconnected tracing and trace files
41990 much easier to use. Otherwise the user must be careful that the
41991 tracepoints in effect while looking at trace frames are identical to
41992 the ones in effect during the trace run; even a small discrepancy
41993 could cause @samp{tdump} not to work, or a particular trace frame not
41994 be found.
41995
41996 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
41997 @cindex define trace state variable, remote request
41998 @cindex @samp{QTDV} packet
41999 Create a new trace state variable, number @var{n}, with an initial
42000 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42001 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42002 the option of not using this packet for initial values of zero; the
42003 target should simply create the trace state variables as they are
42004 mentioned in expressions. The value @var{builtin} should be 1 (one)
42005 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42006 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42007 @samp{qTsV} packet had it set. The contents of @var{name} is the
42008 hex-encoded name (without the leading @samp{$}) of the trace state
42009 variable.
42010
42011 @item QTFrame:@var{n}
42012 @cindex @samp{QTFrame} packet
42013 Select the @var{n}'th tracepoint frame from the buffer, and use the
42014 register and memory contents recorded there to answer subsequent
42015 request packets from @value{GDBN}.
42016
42017 A successful reply from the stub indicates that the stub has found the
42018 requested frame. The response is a series of parts, concatenated
42019 without separators, describing the frame we selected. Each part has
42020 one of the following forms:
42021
42022 @table @samp
42023 @item F @var{f}
42024 The selected frame is number @var{n} in the trace frame buffer;
42025 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42026 was no frame matching the criteria in the request packet.
42027
42028 @item T @var{t}
42029 The selected trace frame records a hit of tracepoint number @var{t};
42030 @var{t} is a hexadecimal number.
42031
42032 @end table
42033
42034 @item QTFrame:pc:@var{addr}
42035 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42036 currently selected frame whose PC is @var{addr};
42037 @var{addr} is a hexadecimal number.
42038
42039 @item QTFrame:tdp:@var{t}
42040 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42041 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42042 is a hexadecimal number.
42043
42044 @item QTFrame:range:@var{start}:@var{end}
42045 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42046 currently selected frame whose PC is between @var{start} (inclusive)
42047 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42048 numbers.
42049
42050 @item QTFrame:outside:@var{start}:@var{end}
42051 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42052 frame @emph{outside} the given range of addresses (exclusive).
42053
42054 @item qTMinFTPILen
42055 @cindex @samp{qTMinFTPILen} packet
42056 This packet requests the minimum length of instruction at which a fast
42057 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42058 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42059 it depends on the target system being able to create trampolines in
42060 the first 64K of memory, which might or might not be possible for that
42061 system. So the reply to this packet will be 4 if it is able to
42062 arrange for that.
42063
42064 Replies:
42065
42066 @table @samp
42067 @item 0
42068 The minimum instruction length is currently unknown.
42069 @item @var{length}
42070 The minimum instruction length is @var{length}, where @var{length}
42071 is a hexadecimal number greater or equal to 1. A reply
42072 of 1 means that a fast tracepoint may be placed on any instruction
42073 regardless of size.
42074 @item E
42075 An error has occurred.
42076 @item @w{}
42077 An empty reply indicates that the request is not supported by the stub.
42078 @end table
42079
42080 @item QTStart
42081 @cindex @samp{QTStart} packet
42082 Begin the tracepoint experiment. Begin collecting data from
42083 tracepoint hits in the trace frame buffer. This packet supports the
42084 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42085 instruction reply packet}).
42086
42087 @item QTStop
42088 @cindex @samp{QTStop} packet
42089 End the tracepoint experiment. Stop collecting trace frames.
42090
42091 @item QTEnable:@var{n}:@var{addr}
42092 @anchor{QTEnable}
42093 @cindex @samp{QTEnable} packet
42094 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42095 experiment. If the tracepoint was previously disabled, then collection
42096 of data from it will resume.
42097
42098 @item QTDisable:@var{n}:@var{addr}
42099 @anchor{QTDisable}
42100 @cindex @samp{QTDisable} packet
42101 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42102 experiment. No more data will be collected from the tracepoint unless
42103 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42104
42105 @item QTinit
42106 @cindex @samp{QTinit} packet
42107 Clear the table of tracepoints, and empty the trace frame buffer.
42108
42109 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
42110 @cindex @samp{QTro} packet
42111 Establish the given ranges of memory as ``transparent''. The stub
42112 will answer requests for these ranges from memory's current contents,
42113 if they were not collected as part of the tracepoint hit.
42114
42115 @value{GDBN} uses this to mark read-only regions of memory, like those
42116 containing program code. Since these areas never change, they should
42117 still have the same contents they did when the tracepoint was hit, so
42118 there's no reason for the stub to refuse to provide their contents.
42119
42120 @item QTDisconnected:@var{value}
42121 @cindex @samp{QTDisconnected} packet
42122 Set the choice to what to do with the tracing run when @value{GDBN}
42123 disconnects from the target. A @var{value} of 1 directs the target to
42124 continue the tracing run, while 0 tells the target to stop tracing if
42125 @value{GDBN} is no longer in the picture.
42126
42127 @item qTStatus
42128 @cindex @samp{qTStatus} packet
42129 Ask the stub if there is a trace experiment running right now.
42130
42131 The reply has the form:
42132
42133 @table @samp
42134
42135 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
42136 @var{running} is a single digit @code{1} if the trace is presently
42137 running, or @code{0} if not. It is followed by semicolon-separated
42138 optional fields that an agent may use to report additional status.
42139
42140 @end table
42141
42142 If the trace is not running, the agent may report any of several
42143 explanations as one of the optional fields:
42144
42145 @table @samp
42146
42147 @item tnotrun:0
42148 No trace has been run yet.
42149
42150 @item tstop[:@var{text}]:0
42151 The trace was stopped by a user-originated stop command. The optional
42152 @var{text} field is a user-supplied string supplied as part of the
42153 stop command (for instance, an explanation of why the trace was
42154 stopped manually). It is hex-encoded.
42155
42156 @item tfull:0
42157 The trace stopped because the trace buffer filled up.
42158
42159 @item tdisconnected:0
42160 The trace stopped because @value{GDBN} disconnected from the target.
42161
42162 @item tpasscount:@var{tpnum}
42163 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42164
42165 @item terror:@var{text}:@var{tpnum}
42166 The trace stopped because tracepoint @var{tpnum} had an error. The
42167 string @var{text} is available to describe the nature of the error
42168 (for instance, a divide by zero in the condition expression); it
42169 is hex encoded.
42170
42171 @item tunknown:0
42172 The trace stopped for some other reason.
42173
42174 @end table
42175
42176 Additional optional fields supply statistical and other information.
42177 Although not required, they are extremely useful for users monitoring
42178 the progress of a trace run. If a trace has stopped, and these
42179 numbers are reported, they must reflect the state of the just-stopped
42180 trace.
42181
42182 @table @samp
42183
42184 @item tframes:@var{n}
42185 The number of trace frames in the buffer.
42186
42187 @item tcreated:@var{n}
42188 The total number of trace frames created during the run. This may
42189 be larger than the trace frame count, if the buffer is circular.
42190
42191 @item tsize:@var{n}
42192 The total size of the trace buffer, in bytes.
42193
42194 @item tfree:@var{n}
42195 The number of bytes still unused in the buffer.
42196
42197 @item circular:@var{n}
42198 The value of the circular trace buffer flag. @code{1} means that the
42199 trace buffer is circular and old trace frames will be discarded if
42200 necessary to make room, @code{0} means that the trace buffer is linear
42201 and may fill up.
42202
42203 @item disconn:@var{n}
42204 The value of the disconnected tracing flag. @code{1} means that
42205 tracing will continue after @value{GDBN} disconnects, @code{0} means
42206 that the trace run will stop.
42207
42208 @end table
42209
42210 @item qTP:@var{tp}:@var{addr}
42211 @cindex tracepoint status, remote request
42212 @cindex @samp{qTP} packet
42213 Ask the stub for the current state of tracepoint number @var{tp} at
42214 address @var{addr}.
42215
42216 Replies:
42217 @table @samp
42218 @item V@var{hits}:@var{usage}
42219 The tracepoint has been hit @var{hits} times so far during the trace
42220 run, and accounts for @var{usage} in the trace buffer. Note that
42221 @code{while-stepping} steps are not counted as separate hits, but the
42222 steps' space consumption is added into the usage number.
42223
42224 @end table
42225
42226 @item qTV:@var{var}
42227 @cindex trace state variable value, remote request
42228 @cindex @samp{qTV} packet
42229 Ask the stub for the value of the trace state variable number @var{var}.
42230
42231 Replies:
42232 @table @samp
42233 @item V@var{value}
42234 The value of the variable is @var{value}. This will be the current
42235 value of the variable if the user is examining a running target, or a
42236 saved value if the variable was collected in the trace frame that the
42237 user is looking at. Note that multiple requests may result in
42238 different reply values, such as when requesting values while the
42239 program is running.
42240
42241 @item U
42242 The value of the variable is unknown. This would occur, for example,
42243 if the user is examining a trace frame in which the requested variable
42244 was not collected.
42245 @end table
42246
42247 @item qTfP
42248 @cindex @samp{qTfP} packet
42249 @itemx qTsP
42250 @cindex @samp{qTsP} packet
42251 These packets request data about tracepoints that are being used by
42252 the target. @value{GDBN} sends @code{qTfP} to get the first piece
42253 of data, and multiple @code{qTsP} to get additional pieces. Replies
42254 to these packets generally take the form of the @code{QTDP} packets
42255 that define tracepoints. (FIXME add detailed syntax)
42256
42257 @item qTfV
42258 @cindex @samp{qTfV} packet
42259 @itemx qTsV
42260 @cindex @samp{qTsV} packet
42261 These packets request data about trace state variables that are on the
42262 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42263 and multiple @code{qTsV} to get additional variables. Replies to
42264 these packets follow the syntax of the @code{QTDV} packets that define
42265 trace state variables.
42266
42267 @item qTfSTM
42268 @itemx qTsSTM
42269 @anchor{qTfSTM}
42270 @anchor{qTsSTM}
42271 @cindex @samp{qTfSTM} packet
42272 @cindex @samp{qTsSTM} packet
42273 These packets request data about static tracepoint markers that exist
42274 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42275 first piece of data, and multiple @code{qTsSTM} to get additional
42276 pieces. Replies to these packets take the following form:
42277
42278 Reply:
42279 @table @samp
42280 @item m @var{address}:@var{id}:@var{extra}
42281 A single marker
42282 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42283 a comma-separated list of markers
42284 @item l
42285 (lower case letter @samp{L}) denotes end of list.
42286 @item E @var{nn}
42287 An error occurred. The error number @var{nn} is given as hex digits.
42288 @item @w{}
42289 An empty reply indicates that the request is not supported by the
42290 stub.
42291 @end table
42292
42293 The @var{address} is encoded in hex;
42294 @var{id} and @var{extra} are strings encoded in hex.
42295
42296 In response to each query, the target will reply with a list of one or
42297 more markers, separated by commas. @value{GDBN} will respond to each
42298 reply with a request for more markers (using the @samp{qs} form of the
42299 query), until the target responds with @samp{l} (lower-case ell, for
42300 @dfn{last}).
42301
42302 @item qTSTMat:@var{address}
42303 @anchor{qTSTMat}
42304 @cindex @samp{qTSTMat} packet
42305 This packets requests data about static tracepoint markers in the
42306 target program at @var{address}. Replies to this packet follow the
42307 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42308 tracepoint markers.
42309
42310 @item QTSave:@var{filename}
42311 @cindex @samp{QTSave} packet
42312 This packet directs the target to save trace data to the file name
42313 @var{filename} in the target's filesystem. The @var{filename} is encoded
42314 as a hex string; the interpretation of the file name (relative vs
42315 absolute, wild cards, etc) is up to the target.
42316
42317 @item qTBuffer:@var{offset},@var{len}
42318 @cindex @samp{qTBuffer} packet
42319 Return up to @var{len} bytes of the current contents of trace buffer,
42320 starting at @var{offset}. The trace buffer is treated as if it were
42321 a contiguous collection of traceframes, as per the trace file format.
42322 The reply consists as many hex-encoded bytes as the target can deliver
42323 in a packet; it is not an error to return fewer than were asked for.
42324 A reply consisting of just @code{l} indicates that no bytes are
42325 available.
42326
42327 @item QTBuffer:circular:@var{value}
42328 This packet directs the target to use a circular trace buffer if
42329 @var{value} is 1, or a linear buffer if the value is 0.
42330
42331 @item QTBuffer:size:@var{size}
42332 @anchor{QTBuffer-size}
42333 @cindex @samp{QTBuffer size} packet
42334 This packet directs the target to make the trace buffer be of size
42335 @var{size} if possible. A value of @code{-1} tells the target to
42336 use whatever size it prefers.
42337
42338 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
42339 @cindex @samp{QTNotes} packet
42340 This packet adds optional textual notes to the trace run. Allowable
42341 types include @code{user}, @code{notes}, and @code{tstop}, the
42342 @var{text} fields are arbitrary strings, hex-encoded.
42343
42344 @end table
42345
42346 @subsection Relocate instruction reply packet
42347 When installing fast tracepoints in memory, the target may need to
42348 relocate the instruction currently at the tracepoint address to a
42349 different address in memory. For most instructions, a simple copy is
42350 enough, but, for example, call instructions that implicitly push the
42351 return address on the stack, and relative branches or other
42352 PC-relative instructions require offset adjustment, so that the effect
42353 of executing the instruction at a different address is the same as if
42354 it had executed in the original location.
42355
42356 In response to several of the tracepoint packets, the target may also
42357 respond with a number of intermediate @samp{qRelocInsn} request
42358 packets before the final result packet, to have @value{GDBN} handle
42359 this relocation operation. If a packet supports this mechanism, its
42360 documentation will explicitly say so. See for example the above
42361 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42362 format of the request is:
42363
42364 @table @samp
42365 @item qRelocInsn:@var{from};@var{to}
42366
42367 This requests @value{GDBN} to copy instruction at address @var{from}
42368 to address @var{to}, possibly adjusted so that executing the
42369 instruction at @var{to} has the same effect as executing it at
42370 @var{from}. @value{GDBN} writes the adjusted instruction to target
42371 memory starting at @var{to}.
42372 @end table
42373
42374 Replies:
42375 @table @samp
42376 @item qRelocInsn:@var{adjusted_size}
42377 Informs the stub the relocation is complete. The @var{adjusted_size} is
42378 the length in bytes of resulting relocated instruction sequence.
42379 @item E @var{NN}
42380 A badly formed request was detected, or an error was encountered while
42381 relocating the instruction.
42382 @end table
42383
42384 @node Host I/O Packets
42385 @section Host I/O Packets
42386 @cindex Host I/O, remote protocol
42387 @cindex file transfer, remote protocol
42388
42389 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42390 operations on the far side of a remote link. For example, Host I/O is
42391 used to upload and download files to a remote target with its own
42392 filesystem. Host I/O uses the same constant values and data structure
42393 layout as the target-initiated File-I/O protocol. However, the
42394 Host I/O packets are structured differently. The target-initiated
42395 protocol relies on target memory to store parameters and buffers.
42396 Host I/O requests are initiated by @value{GDBN}, and the
42397 target's memory is not involved. @xref{File-I/O Remote Protocol
42398 Extension}, for more details on the target-initiated protocol.
42399
42400 The Host I/O request packets all encode a single operation along with
42401 its arguments. They have this format:
42402
42403 @table @samp
42404
42405 @item vFile:@var{operation}: @var{parameter}@dots{}
42406 @var{operation} is the name of the particular request; the target
42407 should compare the entire packet name up to the second colon when checking
42408 for a supported operation. The format of @var{parameter} depends on
42409 the operation. Numbers are always passed in hexadecimal. Negative
42410 numbers have an explicit minus sign (i.e.@: two's complement is not
42411 used). Strings (e.g.@: filenames) are encoded as a series of
42412 hexadecimal bytes. The last argument to a system call may be a
42413 buffer of escaped binary data (@pxref{Binary Data}).
42414
42415 @end table
42416
42417 The valid responses to Host I/O packets are:
42418
42419 @table @samp
42420
42421 @item F @var{result} [, @var{errno}] [; @var{attachment}]
42422 @var{result} is the integer value returned by this operation, usually
42423 non-negative for success and -1 for errors. If an error has occured,
42424 @var{errno} will be included in the result specifying a
42425 value defined by the File-I/O protocol (@pxref{Errno Values}). For
42426 operations which return data, @var{attachment} supplies the data as a
42427 binary buffer. Binary buffers in response packets are escaped in the
42428 normal way (@pxref{Binary Data}). See the individual packet
42429 documentation for the interpretation of @var{result} and
42430 @var{attachment}.
42431
42432 @item @w{}
42433 An empty response indicates that this operation is not recognized.
42434
42435 @end table
42436
42437 These are the supported Host I/O operations:
42438
42439 @table @samp
42440 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
42441 Open a file at @var{filename} and return a file descriptor for it, or
42442 return -1 if an error occurs. The @var{filename} is a string,
42443 @var{flags} is an integer indicating a mask of open flags
42444 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42445 of mode bits to use if the file is created (@pxref{mode_t Values}).
42446 @xref{open}, for details of the open flags and mode values.
42447
42448 @item vFile:close: @var{fd}
42449 Close the open file corresponding to @var{fd} and return 0, or
42450 -1 if an error occurs.
42451
42452 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
42453 Read data from the open file corresponding to @var{fd}. Up to
42454 @var{count} bytes will be read from the file, starting at @var{offset}
42455 relative to the start of the file. The target may read fewer bytes;
42456 common reasons include packet size limits and an end-of-file
42457 condition. The number of bytes read is returned. Zero should only be
42458 returned for a successful read at the end of the file, or if
42459 @var{count} was zero.
42460
42461 The data read should be returned as a binary attachment on success.
42462 If zero bytes were read, the response should include an empty binary
42463 attachment (i.e.@: a trailing semicolon). The return value is the
42464 number of target bytes read; the binary attachment may be longer if
42465 some characters were escaped.
42466
42467 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42468 Write @var{data} (a binary buffer) to the open file corresponding
42469 to @var{fd}. Start the write at @var{offset} from the start of the
42470 file. Unlike many @code{write} system calls, there is no
42471 separate @var{count} argument; the length of @var{data} in the
42472 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
42473 which may be shorter than the length of @var{data}, or -1 if an
42474 error occurred.
42475
42476 @item vFile:fstat: @var{fd}
42477 Get information about the open file corresponding to @var{fd}.
42478 On success the information is returned as a binary attachment
42479 and the return value is the size of this attachment in bytes.
42480 If an error occurs the return value is -1. The format of the
42481 returned binary attachment is as described in @ref{struct stat}.
42482
42483 @item vFile:unlink: @var{filename}
42484 Delete the file at @var{filename} on the target. Return 0,
42485 or -1 if an error occurs. The @var{filename} is a string.
42486
42487 @item vFile:readlink: @var{filename}
42488 Read value of symbolic link @var{filename} on the target. Return
42489 the number of bytes read, or -1 if an error occurs.
42490
42491 The data read should be returned as a binary attachment on success.
42492 If zero bytes were read, the response should include an empty binary
42493 attachment (i.e.@: a trailing semicolon). The return value is the
42494 number of target bytes read; the binary attachment may be longer if
42495 some characters were escaped.
42496
42497 @item vFile:setfs: @var{pid}
42498 Select the filesystem on which @code{vFile} operations with
42499 @var{filename} arguments will operate. This is required for
42500 @value{GDBN} to be able to access files on remote targets where
42501 the remote stub does not share a common filesystem with the
42502 inferior(s).
42503
42504 If @var{pid} is nonzero, select the filesystem as seen by process
42505 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
42506 the remote stub. Return 0 on success, or -1 if an error occurs.
42507 If @code{vFile:setfs:} indicates success, the selected filesystem
42508 remains selected until the next successful @code{vFile:setfs:}
42509 operation.
42510
42511 @end table
42512
42513 @node Interrupts
42514 @section Interrupts
42515 @cindex interrupts (remote protocol)
42516 @anchor{interrupting remote targets}
42517
42518 In all-stop mode, when a program on the remote target is running,
42519 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42520 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42521 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
42522
42523 The precise meaning of @code{BREAK} is defined by the transport
42524 mechanism and may, in fact, be undefined. @value{GDBN} does not
42525 currently define a @code{BREAK} mechanism for any of the network
42526 interfaces except for TCP, in which case @value{GDBN} sends the
42527 @code{telnet} BREAK sequence.
42528
42529 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
42530 transport mechanisms. It is represented by sending the single byte
42531 @code{0x03} without any of the usual packet overhead described in
42532 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42533 transmitted as part of a packet, it is considered to be packet data
42534 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
42535 (@pxref{X packet}), used for binary downloads, may include an unescaped
42536 @code{0x03} as part of its packet.
42537
42538 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42539 When Linux kernel receives this sequence from serial port,
42540 it stops execution and connects to gdb.
42541
42542 In non-stop mode, because packet resumptions are asynchronous
42543 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42544 command to the remote stub, even when the target is running. For that
42545 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42546 packet}) with the usual packet framing instead of the single byte
42547 @code{0x03}.
42548
42549 Stubs are not required to recognize these interrupt mechanisms and the
42550 precise meaning associated with receipt of the interrupt is
42551 implementation defined. If the target supports debugging of multiple
42552 threads and/or processes, it should attempt to interrupt all
42553 currently-executing threads and processes.
42554 If the stub is successful at interrupting the
42555 running program, it should send one of the stop
42556 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42557 of successfully stopping the program in all-stop mode, and a stop reply
42558 for each stopped thread in non-stop mode.
42559 Interrupts received while the
42560 program is stopped are queued and the program will be interrupted when
42561 it is resumed next time.
42562
42563 @node Notification Packets
42564 @section Notification Packets
42565 @cindex notification packets
42566 @cindex packets, notification
42567
42568 The @value{GDBN} remote serial protocol includes @dfn{notifications},
42569 packets that require no acknowledgment. Both the GDB and the stub
42570 may send notifications (although the only notifications defined at
42571 present are sent by the stub). Notifications carry information
42572 without incurring the round-trip latency of an acknowledgment, and so
42573 are useful for low-impact communications where occasional packet loss
42574 is not a problem.
42575
42576 A notification packet has the form @samp{% @var{data} #
42577 @var{checksum}}, where @var{data} is the content of the notification,
42578 and @var{checksum} is a checksum of @var{data}, computed and formatted
42579 as for ordinary @value{GDBN} packets. A notification's @var{data}
42580 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42581 receiving a notification, the recipient sends no @samp{+} or @samp{-}
42582 to acknowledge the notification's receipt or to report its corruption.
42583
42584 Every notification's @var{data} begins with a name, which contains no
42585 colon characters, followed by a colon character.
42586
42587 Recipients should silently ignore corrupted notifications and
42588 notifications they do not understand. Recipients should restart
42589 timeout periods on receipt of a well-formed notification, whether or
42590 not they understand it.
42591
42592 Senders should only send the notifications described here when this
42593 protocol description specifies that they are permitted. In the
42594 future, we may extend the protocol to permit existing notifications in
42595 new contexts; this rule helps older senders avoid confusing newer
42596 recipients.
42597
42598 (Older versions of @value{GDBN} ignore bytes received until they see
42599 the @samp{$} byte that begins an ordinary packet, so new stubs may
42600 transmit notifications without fear of confusing older clients. There
42601 are no notifications defined for @value{GDBN} to send at the moment, but we
42602 assume that most older stubs would ignore them, as well.)
42603
42604 Each notification is comprised of three parts:
42605 @table @samp
42606 @item @var{name}:@var{event}
42607 The notification packet is sent by the side that initiates the
42608 exchange (currently, only the stub does that), with @var{event}
42609 carrying the specific information about the notification, and
42610 @var{name} specifying the name of the notification.
42611 @item @var{ack}
42612 The acknowledge sent by the other side, usually @value{GDBN}, to
42613 acknowledge the exchange and request the event.
42614 @end table
42615
42616 The purpose of an asynchronous notification mechanism is to report to
42617 @value{GDBN} that something interesting happened in the remote stub.
42618
42619 The remote stub may send notification @var{name}:@var{event}
42620 at any time, but @value{GDBN} acknowledges the notification when
42621 appropriate. The notification event is pending before @value{GDBN}
42622 acknowledges. Only one notification at a time may be pending; if
42623 additional events occur before @value{GDBN} has acknowledged the
42624 previous notification, they must be queued by the stub for later
42625 synchronous transmission in response to @var{ack} packets from
42626 @value{GDBN}. Because the notification mechanism is unreliable,
42627 the stub is permitted to resend a notification if it believes
42628 @value{GDBN} may not have received it.
42629
42630 Specifically, notifications may appear when @value{GDBN} is not
42631 otherwise reading input from the stub, or when @value{GDBN} is
42632 expecting to read a normal synchronous response or a
42633 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
42634 Notification packets are distinct from any other communication from
42635 the stub so there is no ambiguity.
42636
42637 After receiving a notification, @value{GDBN} shall acknowledge it by
42638 sending a @var{ack} packet as a regular, synchronous request to the
42639 stub. Such acknowledgment is not required to happen immediately, as
42640 @value{GDBN} is permitted to send other, unrelated packets to the
42641 stub first, which the stub should process normally.
42642
42643 Upon receiving a @var{ack} packet, if the stub has other queued
42644 events to report to @value{GDBN}, it shall respond by sending a
42645 normal @var{event}. @value{GDBN} shall then send another @var{ack}
42646 packet to solicit further responses; again, it is permitted to send
42647 other, unrelated packets as well which the stub should process
42648 normally.
42649
42650 If the stub receives a @var{ack} packet and there are no additional
42651 @var{event} to report, the stub shall return an @samp{OK} response.
42652 At this point, @value{GDBN} has finished processing a notification
42653 and the stub has completed sending any queued events. @value{GDBN}
42654 won't accept any new notifications until the final @samp{OK} is
42655 received . If further notification events occur, the stub shall send
42656 a new notification, @value{GDBN} shall accept the notification, and
42657 the process shall be repeated.
42658
42659 The process of asynchronous notification can be illustrated by the
42660 following example:
42661 @smallexample
42662 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
42663 @code{...}
42664 -> @code{vStopped}
42665 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42666 -> @code{vStopped}
42667 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42668 -> @code{vStopped}
42669 <- @code{OK}
42670 @end smallexample
42671
42672 The following notifications are defined:
42673 @multitable @columnfractions 0.12 0.12 0.38 0.38
42674
42675 @item Notification
42676 @tab Ack
42677 @tab Event
42678 @tab Description
42679
42680 @item Stop
42681 @tab vStopped
42682 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
42683 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42684 for information on how these notifications are acknowledged by
42685 @value{GDBN}.
42686 @tab Report an asynchronous stop event in non-stop mode.
42687
42688 @end multitable
42689
42690 @node Remote Non-Stop
42691 @section Remote Protocol Support for Non-Stop Mode
42692
42693 @value{GDBN}'s remote protocol supports non-stop debugging of
42694 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42695 supports non-stop mode, it should report that to @value{GDBN} by including
42696 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42697
42698 @value{GDBN} typically sends a @samp{QNonStop} packet only when
42699 establishing a new connection with the stub. Entering non-stop mode
42700 does not alter the state of any currently-running threads, but targets
42701 must stop all threads in any already-attached processes when entering
42702 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42703 probe the target state after a mode change.
42704
42705 In non-stop mode, when an attached process encounters an event that
42706 would otherwise be reported with a stop reply, it uses the
42707 asynchronous notification mechanism (@pxref{Notification Packets}) to
42708 inform @value{GDBN}. In contrast to all-stop mode, where all threads
42709 in all processes are stopped when a stop reply is sent, in non-stop
42710 mode only the thread reporting the stop event is stopped. That is,
42711 when reporting a @samp{S} or @samp{T} response to indicate completion
42712 of a step operation, hitting a breakpoint, or a fault, only the
42713 affected thread is stopped; any other still-running threads continue
42714 to run. When reporting a @samp{W} or @samp{X} response, all running
42715 threads belonging to other attached processes continue to run.
42716
42717 In non-stop mode, the target shall respond to the @samp{?} packet as
42718 follows. First, any incomplete stop reply notification/@samp{vStopped}
42719 sequence in progress is abandoned. The target must begin a new
42720 sequence reporting stop events for all stopped threads, whether or not
42721 it has previously reported those events to @value{GDBN}. The first
42722 stop reply is sent as a synchronous reply to the @samp{?} packet, and
42723 subsequent stop replies are sent as responses to @samp{vStopped} packets
42724 using the mechanism described above. The target must not send
42725 asynchronous stop reply notifications until the sequence is complete.
42726 If all threads are running when the target receives the @samp{?} packet,
42727 or if the target is not attached to any process, it shall respond
42728 @samp{OK}.
42729
42730 If the stub supports non-stop mode, it should also support the
42731 @samp{swbreak} stop reason if software breakpoints are supported, and
42732 the @samp{hwbreak} stop reason if hardware breakpoints are supported
42733 (@pxref{swbreak stop reason}). This is because given the asynchronous
42734 nature of non-stop mode, between the time a thread hits a breakpoint
42735 and the time the event is finally processed by @value{GDBN}, the
42736 breakpoint may have already been removed from the target. Due to
42737 this, @value{GDBN} needs to be able to tell whether a trap stop was
42738 caused by a delayed breakpoint event, which should be ignored, as
42739 opposed to a random trap signal, which should be reported to the user.
42740 Note the @samp{swbreak} feature implies that the target is responsible
42741 for adjusting the PC when a software breakpoint triggers, if
42742 necessary, such as on the x86 architecture.
42743
42744 @node Packet Acknowledgment
42745 @section Packet Acknowledgment
42746
42747 @cindex acknowledgment, for @value{GDBN} remote
42748 @cindex packet acknowledgment, for @value{GDBN} remote
42749 By default, when either the host or the target machine receives a packet,
42750 the first response expected is an acknowledgment: either @samp{+} (to indicate
42751 the package was received correctly) or @samp{-} (to request retransmission).
42752 This mechanism allows the @value{GDBN} remote protocol to operate over
42753 unreliable transport mechanisms, such as a serial line.
42754
42755 In cases where the transport mechanism is itself reliable (such as a pipe or
42756 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42757 It may be desirable to disable them in that case to reduce communication
42758 overhead, or for other reasons. This can be accomplished by means of the
42759 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42760
42761 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42762 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
42763 and response format still includes the normal checksum, as described in
42764 @ref{Overview}, but the checksum may be ignored by the receiver.
42765
42766 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
42767 no-acknowledgment mode, it should report that to @value{GDBN}
42768 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
42769 @pxref{qSupported}.
42770 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
42771 disabled via the @code{set remote noack-packet off} command
42772 (@pxref{Remote Configuration}),
42773 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
42774 Only then may the stub actually turn off packet acknowledgments.
42775 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
42776 response, which can be safely ignored by the stub.
42777
42778 Note that @code{set remote noack-packet} command only affects negotiation
42779 between @value{GDBN} and the stub when subsequent connections are made;
42780 it does not affect the protocol acknowledgment state for any current
42781 connection.
42782 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
42783 new connection is established,
42784 there is also no protocol request to re-enable the acknowledgments
42785 for the current connection, once disabled.
42786
42787 @node Examples
42788 @section Examples
42789
42790 Example sequence of a target being re-started. Notice how the restart
42791 does not get any direct output:
42792
42793 @smallexample
42794 -> @code{R00}
42795 <- @code{+}
42796 @emph{target restarts}
42797 -> @code{?}
42798 <- @code{+}
42799 <- @code{T001:1234123412341234}
42800 -> @code{+}
42801 @end smallexample
42802
42803 Example sequence of a target being stepped by a single instruction:
42804
42805 @smallexample
42806 -> @code{G1445@dots{}}
42807 <- @code{+}
42808 -> @code{s}
42809 <- @code{+}
42810 @emph{time passes}
42811 <- @code{T001:1234123412341234}
42812 -> @code{+}
42813 -> @code{g}
42814 <- @code{+}
42815 <- @code{1455@dots{}}
42816 -> @code{+}
42817 @end smallexample
42818
42819 @node File-I/O Remote Protocol Extension
42820 @section File-I/O Remote Protocol Extension
42821 @cindex File-I/O remote protocol extension
42822
42823 @menu
42824 * File-I/O Overview::
42825 * Protocol Basics::
42826 * The F Request Packet::
42827 * The F Reply Packet::
42828 * The Ctrl-C Message::
42829 * Console I/O::
42830 * List of Supported Calls::
42831 * Protocol-specific Representation of Datatypes::
42832 * Constants::
42833 * File-I/O Examples::
42834 @end menu
42835
42836 @node File-I/O Overview
42837 @subsection File-I/O Overview
42838 @cindex file-i/o overview
42839
42840 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
42841 target to use the host's file system and console I/O to perform various
42842 system calls. System calls on the target system are translated into a
42843 remote protocol packet to the host system, which then performs the needed
42844 actions and returns a response packet to the target system.
42845 This simulates file system operations even on targets that lack file systems.
42846
42847 The protocol is defined to be independent of both the host and target systems.
42848 It uses its own internal representation of datatypes and values. Both
42849 @value{GDBN} and the target's @value{GDBN} stub are responsible for
42850 translating the system-dependent value representations into the internal
42851 protocol representations when data is transmitted.
42852
42853 The communication is synchronous. A system call is possible only when
42854 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
42855 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
42856 the target is stopped to allow deterministic access to the target's
42857 memory. Therefore File-I/O is not interruptible by target signals. On
42858 the other hand, it is possible to interrupt File-I/O by a user interrupt
42859 (@samp{Ctrl-C}) within @value{GDBN}.
42860
42861 The target's request to perform a host system call does not finish
42862 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
42863 after finishing the system call, the target returns to continuing the
42864 previous activity (continue, step). No additional continue or step
42865 request from @value{GDBN} is required.
42866
42867 @smallexample
42868 (@value{GDBP}) continue
42869 <- target requests 'system call X'
42870 target is stopped, @value{GDBN} executes system call
42871 -> @value{GDBN} returns result
42872 ... target continues, @value{GDBN} returns to wait for the target
42873 <- target hits breakpoint and sends a Txx packet
42874 @end smallexample
42875
42876 The protocol only supports I/O on the console and to regular files on
42877 the host file system. Character or block special devices, pipes,
42878 named pipes, sockets or any other communication method on the host
42879 system are not supported by this protocol.
42880
42881 File I/O is not supported in non-stop mode.
42882
42883 @node Protocol Basics
42884 @subsection Protocol Basics
42885 @cindex protocol basics, file-i/o
42886
42887 The File-I/O protocol uses the @code{F} packet as the request as well
42888 as reply packet. Since a File-I/O system call can only occur when
42889 @value{GDBN} is waiting for a response from the continuing or stepping target,
42890 the File-I/O request is a reply that @value{GDBN} has to expect as a result
42891 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
42892 This @code{F} packet contains all information needed to allow @value{GDBN}
42893 to call the appropriate host system call:
42894
42895 @itemize @bullet
42896 @item
42897 A unique identifier for the requested system call.
42898
42899 @item
42900 All parameters to the system call. Pointers are given as addresses
42901 in the target memory address space. Pointers to strings are given as
42902 pointer/length pair. Numerical values are given as they are.
42903 Numerical control flags are given in a protocol-specific representation.
42904
42905 @end itemize
42906
42907 At this point, @value{GDBN} has to perform the following actions.
42908
42909 @itemize @bullet
42910 @item
42911 If the parameters include pointer values to data needed as input to a
42912 system call, @value{GDBN} requests this data from the target with a
42913 standard @code{m} packet request. This additional communication has to be
42914 expected by the target implementation and is handled as any other @code{m}
42915 packet.
42916
42917 @item
42918 @value{GDBN} translates all value from protocol representation to host
42919 representation as needed. Datatypes are coerced into the host types.
42920
42921 @item
42922 @value{GDBN} calls the system call.
42923
42924 @item
42925 It then coerces datatypes back to protocol representation.
42926
42927 @item
42928 If the system call is expected to return data in buffer space specified
42929 by pointer parameters to the call, the data is transmitted to the
42930 target using a @code{M} or @code{X} packet. This packet has to be expected
42931 by the target implementation and is handled as any other @code{M} or @code{X}
42932 packet.
42933
42934 @end itemize
42935
42936 Eventually @value{GDBN} replies with another @code{F} packet which contains all
42937 necessary information for the target to continue. This at least contains
42938
42939 @itemize @bullet
42940 @item
42941 Return value.
42942
42943 @item
42944 @code{errno}, if has been changed by the system call.
42945
42946 @item
42947 ``Ctrl-C'' flag.
42948
42949 @end itemize
42950
42951 After having done the needed type and value coercion, the target continues
42952 the latest continue or step action.
42953
42954 @node The F Request Packet
42955 @subsection The @code{F} Request Packet
42956 @cindex file-i/o request packet
42957 @cindex @code{F} request packet
42958
42959 The @code{F} request packet has the following format:
42960
42961 @table @samp
42962 @item F@var{call-id},@var{parameter@dots{}}
42963
42964 @var{call-id} is the identifier to indicate the host system call to be called.
42965 This is just the name of the function.
42966
42967 @var{parameter@dots{}} are the parameters to the system call.
42968 Parameters are hexadecimal integer values, either the actual values in case
42969 of scalar datatypes, pointers to target buffer space in case of compound
42970 datatypes and unspecified memory areas, or pointer/length pairs in case
42971 of string parameters. These are appended to the @var{call-id} as a
42972 comma-delimited list. All values are transmitted in ASCII
42973 string representation, pointer/length pairs separated by a slash.
42974
42975 @end table
42976
42977
42978
42979 @node The F Reply Packet
42980 @subsection The @code{F} Reply Packet
42981 @cindex file-i/o reply packet
42982 @cindex @code{F} reply packet
42983
42984 The @code{F} reply packet has the following format:
42985
42986 @table @samp
42987
42988 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
42989
42990 @var{retcode} is the return code of the system call as hexadecimal value.
42991
42992 @var{errno} is the @code{errno} set by the call, in protocol-specific
42993 representation.
42994 This parameter can be omitted if the call was successful.
42995
42996 @var{Ctrl-C flag} is only sent if the user requested a break. In this
42997 case, @var{errno} must be sent as well, even if the call was successful.
42998 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
42999
43000 @smallexample
43001 F0,0,C
43002 @end smallexample
43003
43004 @noindent
43005 or, if the call was interrupted before the host call has been performed:
43006
43007 @smallexample
43008 F-1,4,C
43009 @end smallexample
43010
43011 @noindent
43012 assuming 4 is the protocol-specific representation of @code{EINTR}.
43013
43014 @end table
43015
43016
43017 @node The Ctrl-C Message
43018 @subsection The @samp{Ctrl-C} Message
43019 @cindex ctrl-c message, in file-i/o protocol
43020
43021 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43022 reply packet (@pxref{The F Reply Packet}),
43023 the target should behave as if it had
43024 gotten a break message. The meaning for the target is ``system call
43025 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43026 (as with a break message) and return to @value{GDBN} with a @code{T02}
43027 packet.
43028
43029 It's important for the target to know in which
43030 state the system call was interrupted. There are two possible cases:
43031
43032 @itemize @bullet
43033 @item
43034 The system call hasn't been performed on the host yet.
43035
43036 @item
43037 The system call on the host has been finished.
43038
43039 @end itemize
43040
43041 These two states can be distinguished by the target by the value of the
43042 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43043 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43044 on POSIX systems. In any other case, the target may presume that the
43045 system call has been finished --- successfully or not --- and should behave
43046 as if the break message arrived right after the system call.
43047
43048 @value{GDBN} must behave reliably. If the system call has not been called
43049 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43050 @code{errno} in the packet. If the system call on the host has been finished
43051 before the user requests a break, the full action must be finished by
43052 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43053 The @code{F} packet may only be sent when either nothing has happened
43054 or the full action has been completed.
43055
43056 @node Console I/O
43057 @subsection Console I/O
43058 @cindex console i/o as part of file-i/o
43059
43060 By default and if not explicitly closed by the target system, the file
43061 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43062 on the @value{GDBN} console is handled as any other file output operation
43063 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43064 by @value{GDBN} so that after the target read request from file descriptor
43065 0 all following typing is buffered until either one of the following
43066 conditions is met:
43067
43068 @itemize @bullet
43069 @item
43070 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43071 @code{read}
43072 system call is treated as finished.
43073
43074 @item
43075 The user presses @key{RET}. This is treated as end of input with a trailing
43076 newline.
43077
43078 @item
43079 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43080 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43081
43082 @end itemize
43083
43084 If the user has typed more characters than fit in the buffer given to
43085 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43086 either another @code{read(0, @dots{})} is requested by the target, or debugging
43087 is stopped at the user's request.
43088
43089
43090 @node List of Supported Calls
43091 @subsection List of Supported Calls
43092 @cindex list of supported file-i/o calls
43093
43094 @menu
43095 * open::
43096 * close::
43097 * read::
43098 * write::
43099 * lseek::
43100 * rename::
43101 * unlink::
43102 * stat/fstat::
43103 * gettimeofday::
43104 * isatty::
43105 * system::
43106 @end menu
43107
43108 @node open
43109 @unnumberedsubsubsec open
43110 @cindex open, file-i/o system call
43111
43112 @table @asis
43113 @item Synopsis:
43114 @smallexample
43115 int open(const char *pathname, int flags);
43116 int open(const char *pathname, int flags, mode_t mode);
43117 @end smallexample
43118
43119 @item Request:
43120 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43121
43122 @noindent
43123 @var{flags} is the bitwise @code{OR} of the following values:
43124
43125 @table @code
43126 @item O_CREAT
43127 If the file does not exist it will be created. The host
43128 rules apply as far as file ownership and time stamps
43129 are concerned.
43130
43131 @item O_EXCL
43132 When used with @code{O_CREAT}, if the file already exists it is
43133 an error and open() fails.
43134
43135 @item O_TRUNC
43136 If the file already exists and the open mode allows
43137 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43138 truncated to zero length.
43139
43140 @item O_APPEND
43141 The file is opened in append mode.
43142
43143 @item O_RDONLY
43144 The file is opened for reading only.
43145
43146 @item O_WRONLY
43147 The file is opened for writing only.
43148
43149 @item O_RDWR
43150 The file is opened for reading and writing.
43151 @end table
43152
43153 @noindent
43154 Other bits are silently ignored.
43155
43156
43157 @noindent
43158 @var{mode} is the bitwise @code{OR} of the following values:
43159
43160 @table @code
43161 @item S_IRUSR
43162 User has read permission.
43163
43164 @item S_IWUSR
43165 User has write permission.
43166
43167 @item S_IRGRP
43168 Group has read permission.
43169
43170 @item S_IWGRP
43171 Group has write permission.
43172
43173 @item S_IROTH
43174 Others have read permission.
43175
43176 @item S_IWOTH
43177 Others have write permission.
43178 @end table
43179
43180 @noindent
43181 Other bits are silently ignored.
43182
43183
43184 @item Return value:
43185 @code{open} returns the new file descriptor or -1 if an error
43186 occurred.
43187
43188 @item Errors:
43189
43190 @table @code
43191 @item EEXIST
43192 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
43193
43194 @item EISDIR
43195 @var{pathname} refers to a directory.
43196
43197 @item EACCES
43198 The requested access is not allowed.
43199
43200 @item ENAMETOOLONG
43201 @var{pathname} was too long.
43202
43203 @item ENOENT
43204 A directory component in @var{pathname} does not exist.
43205
43206 @item ENODEV
43207 @var{pathname} refers to a device, pipe, named pipe or socket.
43208
43209 @item EROFS
43210 @var{pathname} refers to a file on a read-only filesystem and
43211 write access was requested.
43212
43213 @item EFAULT
43214 @var{pathname} is an invalid pointer value.
43215
43216 @item ENOSPC
43217 No space on device to create the file.
43218
43219 @item EMFILE
43220 The process already has the maximum number of files open.
43221
43222 @item ENFILE
43223 The limit on the total number of files open on the system
43224 has been reached.
43225
43226 @item EINTR
43227 The call was interrupted by the user.
43228 @end table
43229
43230 @end table
43231
43232 @node close
43233 @unnumberedsubsubsec close
43234 @cindex close, file-i/o system call
43235
43236 @table @asis
43237 @item Synopsis:
43238 @smallexample
43239 int close(int fd);
43240 @end smallexample
43241
43242 @item Request:
43243 @samp{Fclose,@var{fd}}
43244
43245 @item Return value:
43246 @code{close} returns zero on success, or -1 if an error occurred.
43247
43248 @item Errors:
43249
43250 @table @code
43251 @item EBADF
43252 @var{fd} isn't a valid open file descriptor.
43253
43254 @item EINTR
43255 The call was interrupted by the user.
43256 @end table
43257
43258 @end table
43259
43260 @node read
43261 @unnumberedsubsubsec read
43262 @cindex read, file-i/o system call
43263
43264 @table @asis
43265 @item Synopsis:
43266 @smallexample
43267 int read(int fd, void *buf, unsigned int count);
43268 @end smallexample
43269
43270 @item Request:
43271 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
43272
43273 @item Return value:
43274 On success, the number of bytes read is returned.
43275 Zero indicates end of file. If count is zero, read
43276 returns zero as well. On error, -1 is returned.
43277
43278 @item Errors:
43279
43280 @table @code
43281 @item EBADF
43282 @var{fd} is not a valid file descriptor or is not open for
43283 reading.
43284
43285 @item EFAULT
43286 @var{bufptr} is an invalid pointer value.
43287
43288 @item EINTR
43289 The call was interrupted by the user.
43290 @end table
43291
43292 @end table
43293
43294 @node write
43295 @unnumberedsubsubsec write
43296 @cindex write, file-i/o system call
43297
43298 @table @asis
43299 @item Synopsis:
43300 @smallexample
43301 int write(int fd, const void *buf, unsigned int count);
43302 @end smallexample
43303
43304 @item Request:
43305 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
43306
43307 @item Return value:
43308 On success, the number of bytes written are returned.
43309 Zero indicates nothing was written. On error, -1
43310 is returned.
43311
43312 @item Errors:
43313
43314 @table @code
43315 @item EBADF
43316 @var{fd} is not a valid file descriptor or is not open for
43317 writing.
43318
43319 @item EFAULT
43320 @var{bufptr} is an invalid pointer value.
43321
43322 @item EFBIG
43323 An attempt was made to write a file that exceeds the
43324 host-specific maximum file size allowed.
43325
43326 @item ENOSPC
43327 No space on device to write the data.
43328
43329 @item EINTR
43330 The call was interrupted by the user.
43331 @end table
43332
43333 @end table
43334
43335 @node lseek
43336 @unnumberedsubsubsec lseek
43337 @cindex lseek, file-i/o system call
43338
43339 @table @asis
43340 @item Synopsis:
43341 @smallexample
43342 long lseek (int fd, long offset, int flag);
43343 @end smallexample
43344
43345 @item Request:
43346 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
43347
43348 @var{flag} is one of:
43349
43350 @table @code
43351 @item SEEK_SET
43352 The offset is set to @var{offset} bytes.
43353
43354 @item SEEK_CUR
43355 The offset is set to its current location plus @var{offset}
43356 bytes.
43357
43358 @item SEEK_END
43359 The offset is set to the size of the file plus @var{offset}
43360 bytes.
43361 @end table
43362
43363 @item Return value:
43364 On success, the resulting unsigned offset in bytes from
43365 the beginning of the file is returned. Otherwise, a
43366 value of -1 is returned.
43367
43368 @item Errors:
43369
43370 @table @code
43371 @item EBADF
43372 @var{fd} is not a valid open file descriptor.
43373
43374 @item ESPIPE
43375 @var{fd} is associated with the @value{GDBN} console.
43376
43377 @item EINVAL
43378 @var{flag} is not a proper value.
43379
43380 @item EINTR
43381 The call was interrupted by the user.
43382 @end table
43383
43384 @end table
43385
43386 @node rename
43387 @unnumberedsubsubsec rename
43388 @cindex rename, file-i/o system call
43389
43390 @table @asis
43391 @item Synopsis:
43392 @smallexample
43393 int rename(const char *oldpath, const char *newpath);
43394 @end smallexample
43395
43396 @item Request:
43397 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
43398
43399 @item Return value:
43400 On success, zero is returned. On error, -1 is returned.
43401
43402 @item Errors:
43403
43404 @table @code
43405 @item EISDIR
43406 @var{newpath} is an existing directory, but @var{oldpath} is not a
43407 directory.
43408
43409 @item EEXIST
43410 @var{newpath} is a non-empty directory.
43411
43412 @item EBUSY
43413 @var{oldpath} or @var{newpath} is a directory that is in use by some
43414 process.
43415
43416 @item EINVAL
43417 An attempt was made to make a directory a subdirectory
43418 of itself.
43419
43420 @item ENOTDIR
43421 A component used as a directory in @var{oldpath} or new
43422 path is not a directory. Or @var{oldpath} is a directory
43423 and @var{newpath} exists but is not a directory.
43424
43425 @item EFAULT
43426 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
43427
43428 @item EACCES
43429 No access to the file or the path of the file.
43430
43431 @item ENAMETOOLONG
43432
43433 @var{oldpath} or @var{newpath} was too long.
43434
43435 @item ENOENT
43436 A directory component in @var{oldpath} or @var{newpath} does not exist.
43437
43438 @item EROFS
43439 The file is on a read-only filesystem.
43440
43441 @item ENOSPC
43442 The device containing the file has no room for the new
43443 directory entry.
43444
43445 @item EINTR
43446 The call was interrupted by the user.
43447 @end table
43448
43449 @end table
43450
43451 @node unlink
43452 @unnumberedsubsubsec unlink
43453 @cindex unlink, file-i/o system call
43454
43455 @table @asis
43456 @item Synopsis:
43457 @smallexample
43458 int unlink(const char *pathname);
43459 @end smallexample
43460
43461 @item Request:
43462 @samp{Funlink,@var{pathnameptr}/@var{len}}
43463
43464 @item Return value:
43465 On success, zero is returned. On error, -1 is returned.
43466
43467 @item Errors:
43468
43469 @table @code
43470 @item EACCES
43471 No access to the file or the path of the file.
43472
43473 @item EPERM
43474 The system does not allow unlinking of directories.
43475
43476 @item EBUSY
43477 The file @var{pathname} cannot be unlinked because it's
43478 being used by another process.
43479
43480 @item EFAULT
43481 @var{pathnameptr} is an invalid pointer value.
43482
43483 @item ENAMETOOLONG
43484 @var{pathname} was too long.
43485
43486 @item ENOENT
43487 A directory component in @var{pathname} does not exist.
43488
43489 @item ENOTDIR
43490 A component of the path is not a directory.
43491
43492 @item EROFS
43493 The file is on a read-only filesystem.
43494
43495 @item EINTR
43496 The call was interrupted by the user.
43497 @end table
43498
43499 @end table
43500
43501 @node stat/fstat
43502 @unnumberedsubsubsec stat/fstat
43503 @cindex fstat, file-i/o system call
43504 @cindex stat, file-i/o system call
43505
43506 @table @asis
43507 @item Synopsis:
43508 @smallexample
43509 int stat(const char *pathname, struct stat *buf);
43510 int fstat(int fd, struct stat *buf);
43511 @end smallexample
43512
43513 @item Request:
43514 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43515 @samp{Ffstat,@var{fd},@var{bufptr}}
43516
43517 @item Return value:
43518 On success, zero is returned. On error, -1 is returned.
43519
43520 @item Errors:
43521
43522 @table @code
43523 @item EBADF
43524 @var{fd} is not a valid open file.
43525
43526 @item ENOENT
43527 A directory component in @var{pathname} does not exist or the
43528 path is an empty string.
43529
43530 @item ENOTDIR
43531 A component of the path is not a directory.
43532
43533 @item EFAULT
43534 @var{pathnameptr} is an invalid pointer value.
43535
43536 @item EACCES
43537 No access to the file or the path of the file.
43538
43539 @item ENAMETOOLONG
43540 @var{pathname} was too long.
43541
43542 @item EINTR
43543 The call was interrupted by the user.
43544 @end table
43545
43546 @end table
43547
43548 @node gettimeofday
43549 @unnumberedsubsubsec gettimeofday
43550 @cindex gettimeofday, file-i/o system call
43551
43552 @table @asis
43553 @item Synopsis:
43554 @smallexample
43555 int gettimeofday(struct timeval *tv, void *tz);
43556 @end smallexample
43557
43558 @item Request:
43559 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
43560
43561 @item Return value:
43562 On success, 0 is returned, -1 otherwise.
43563
43564 @item Errors:
43565
43566 @table @code
43567 @item EINVAL
43568 @var{tz} is a non-NULL pointer.
43569
43570 @item EFAULT
43571 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43572 @end table
43573
43574 @end table
43575
43576 @node isatty
43577 @unnumberedsubsubsec isatty
43578 @cindex isatty, file-i/o system call
43579
43580 @table @asis
43581 @item Synopsis:
43582 @smallexample
43583 int isatty(int fd);
43584 @end smallexample
43585
43586 @item Request:
43587 @samp{Fisatty,@var{fd}}
43588
43589 @item Return value:
43590 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
43591
43592 @item Errors:
43593
43594 @table @code
43595 @item EINTR
43596 The call was interrupted by the user.
43597 @end table
43598
43599 @end table
43600
43601 Note that the @code{isatty} call is treated as a special case: it returns
43602 1 to the target if the file descriptor is attached
43603 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43604 would require implementing @code{ioctl} and would be more complex than
43605 needed.
43606
43607
43608 @node system
43609 @unnumberedsubsubsec system
43610 @cindex system, file-i/o system call
43611
43612 @table @asis
43613 @item Synopsis:
43614 @smallexample
43615 int system(const char *command);
43616 @end smallexample
43617
43618 @item Request:
43619 @samp{Fsystem,@var{commandptr}/@var{len}}
43620
43621 @item Return value:
43622 If @var{len} is zero, the return value indicates whether a shell is
43623 available. A zero return value indicates a shell is not available.
43624 For non-zero @var{len}, the value returned is -1 on error and the
43625 return status of the command otherwise. Only the exit status of the
43626 command is returned, which is extracted from the host's @code{system}
43627 return value by calling @code{WEXITSTATUS(retval)}. In case
43628 @file{/bin/sh} could not be executed, 127 is returned.
43629
43630 @item Errors:
43631
43632 @table @code
43633 @item EINTR
43634 The call was interrupted by the user.
43635 @end table
43636
43637 @end table
43638
43639 @value{GDBN} takes over the full task of calling the necessary host calls
43640 to perform the @code{system} call. The return value of @code{system} on
43641 the host is simplified before it's returned
43642 to the target. Any termination signal information from the child process
43643 is discarded, and the return value consists
43644 entirely of the exit status of the called command.
43645
43646 Due to security concerns, the @code{system} call is by default refused
43647 by @value{GDBN}. The user has to allow this call explicitly with the
43648 @code{set remote system-call-allowed 1} command.
43649
43650 @table @code
43651 @item set remote system-call-allowed
43652 @kindex set remote system-call-allowed
43653 Control whether to allow the @code{system} calls in the File I/O
43654 protocol for the remote target. The default is zero (disabled).
43655
43656 @item show remote system-call-allowed
43657 @kindex show remote system-call-allowed
43658 Show whether the @code{system} calls are allowed in the File I/O
43659 protocol.
43660 @end table
43661
43662 @node Protocol-specific Representation of Datatypes
43663 @subsection Protocol-specific Representation of Datatypes
43664 @cindex protocol-specific representation of datatypes, in file-i/o protocol
43665
43666 @menu
43667 * Integral Datatypes::
43668 * Pointer Values::
43669 * Memory Transfer::
43670 * struct stat::
43671 * struct timeval::
43672 @end menu
43673
43674 @node Integral Datatypes
43675 @unnumberedsubsubsec Integral Datatypes
43676 @cindex integral datatypes, in file-i/o protocol
43677
43678 The integral datatypes used in the system calls are @code{int},
43679 @code{unsigned int}, @code{long}, @code{unsigned long},
43680 @code{mode_t}, and @code{time_t}.
43681
43682 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
43683 implemented as 32 bit values in this protocol.
43684
43685 @code{long} and @code{unsigned long} are implemented as 64 bit types.
43686
43687 @xref{Limits}, for corresponding MIN and MAX values (similar to those
43688 in @file{limits.h}) to allow range checking on host and target.
43689
43690 @code{time_t} datatypes are defined as seconds since the Epoch.
43691
43692 All integral datatypes transferred as part of a memory read or write of a
43693 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43694 byte order.
43695
43696 @node Pointer Values
43697 @unnumberedsubsubsec Pointer Values
43698 @cindex pointer values, in file-i/o protocol
43699
43700 Pointers to target data are transmitted as they are. An exception
43701 is made for pointers to buffers for which the length isn't
43702 transmitted as part of the function call, namely strings. Strings
43703 are transmitted as a pointer/length pair, both as hex values, e.g.@:
43704
43705 @smallexample
43706 @code{1aaf/12}
43707 @end smallexample
43708
43709 @noindent
43710 which is a pointer to data of length 18 bytes at position 0x1aaf.
43711 The length is defined as the full string length in bytes, including
43712 the trailing null byte. For example, the string @code{"hello world"}
43713 at address 0x123456 is transmitted as
43714
43715 @smallexample
43716 @code{123456/d}
43717 @end smallexample
43718
43719 @node Memory Transfer
43720 @unnumberedsubsubsec Memory Transfer
43721 @cindex memory transfer, in file-i/o protocol
43722
43723 Structured data which is transferred using a memory read or write (for
43724 example, a @code{struct stat}) is expected to be in a protocol-specific format
43725 with all scalar multibyte datatypes being big endian. Translation to
43726 this representation needs to be done both by the target before the @code{F}
43727 packet is sent, and by @value{GDBN} before
43728 it transfers memory to the target. Transferred pointers to structured
43729 data should point to the already-coerced data at any time.
43730
43731
43732 @node struct stat
43733 @unnumberedsubsubsec struct stat
43734 @cindex struct stat, in file-i/o protocol
43735
43736 The buffer of type @code{struct stat} used by the target and @value{GDBN}
43737 is defined as follows:
43738
43739 @smallexample
43740 struct stat @{
43741 unsigned int st_dev; /* device */
43742 unsigned int st_ino; /* inode */
43743 mode_t st_mode; /* protection */
43744 unsigned int st_nlink; /* number of hard links */
43745 unsigned int st_uid; /* user ID of owner */
43746 unsigned int st_gid; /* group ID of owner */
43747 unsigned int st_rdev; /* device type (if inode device) */
43748 unsigned long st_size; /* total size, in bytes */
43749 unsigned long st_blksize; /* blocksize for filesystem I/O */
43750 unsigned long st_blocks; /* number of blocks allocated */
43751 time_t st_atime; /* time of last access */
43752 time_t st_mtime; /* time of last modification */
43753 time_t st_ctime; /* time of last change */
43754 @};
43755 @end smallexample
43756
43757 The integral datatypes conform to the definitions given in the
43758 appropriate section (see @ref{Integral Datatypes}, for details) so this
43759 structure is of size 64 bytes.
43760
43761 The values of several fields have a restricted meaning and/or
43762 range of values.
43763
43764 @table @code
43765
43766 @item st_dev
43767 A value of 0 represents a file, 1 the console.
43768
43769 @item st_ino
43770 No valid meaning for the target. Transmitted unchanged.
43771
43772 @item st_mode
43773 Valid mode bits are described in @ref{Constants}. Any other
43774 bits have currently no meaning for the target.
43775
43776 @item st_uid
43777 @itemx st_gid
43778 @itemx st_rdev
43779 No valid meaning for the target. Transmitted unchanged.
43780
43781 @item st_atime
43782 @itemx st_mtime
43783 @itemx st_ctime
43784 These values have a host and file system dependent
43785 accuracy. Especially on Windows hosts, the file system may not
43786 support exact timing values.
43787 @end table
43788
43789 The target gets a @code{struct stat} of the above representation and is
43790 responsible for coercing it to the target representation before
43791 continuing.
43792
43793 Note that due to size differences between the host, target, and protocol
43794 representations of @code{struct stat} members, these members could eventually
43795 get truncated on the target.
43796
43797 @node struct timeval
43798 @unnumberedsubsubsec struct timeval
43799 @cindex struct timeval, in file-i/o protocol
43800
43801 The buffer of type @code{struct timeval} used by the File-I/O protocol
43802 is defined as follows:
43803
43804 @smallexample
43805 struct timeval @{
43806 time_t tv_sec; /* second */
43807 long tv_usec; /* microsecond */
43808 @};
43809 @end smallexample
43810
43811 The integral datatypes conform to the definitions given in the
43812 appropriate section (see @ref{Integral Datatypes}, for details) so this
43813 structure is of size 8 bytes.
43814
43815 @node Constants
43816 @subsection Constants
43817 @cindex constants, in file-i/o protocol
43818
43819 The following values are used for the constants inside of the
43820 protocol. @value{GDBN} and target are responsible for translating these
43821 values before and after the call as needed.
43822
43823 @menu
43824 * Open Flags::
43825 * mode_t Values::
43826 * Errno Values::
43827 * Lseek Flags::
43828 * Limits::
43829 @end menu
43830
43831 @node Open Flags
43832 @unnumberedsubsubsec Open Flags
43833 @cindex open flags, in file-i/o protocol
43834
43835 All values are given in hexadecimal representation.
43836
43837 @smallexample
43838 O_RDONLY 0x0
43839 O_WRONLY 0x1
43840 O_RDWR 0x2
43841 O_APPEND 0x8
43842 O_CREAT 0x200
43843 O_TRUNC 0x400
43844 O_EXCL 0x800
43845 @end smallexample
43846
43847 @node mode_t Values
43848 @unnumberedsubsubsec mode_t Values
43849 @cindex mode_t values, in file-i/o protocol
43850
43851 All values are given in octal representation.
43852
43853 @smallexample
43854 S_IFREG 0100000
43855 S_IFDIR 040000
43856 S_IRUSR 0400
43857 S_IWUSR 0200
43858 S_IXUSR 0100
43859 S_IRGRP 040
43860 S_IWGRP 020
43861 S_IXGRP 010
43862 S_IROTH 04
43863 S_IWOTH 02
43864 S_IXOTH 01
43865 @end smallexample
43866
43867 @node Errno Values
43868 @unnumberedsubsubsec Errno Values
43869 @cindex errno values, in file-i/o protocol
43870
43871 All values are given in decimal representation.
43872
43873 @smallexample
43874 EPERM 1
43875 ENOENT 2
43876 EINTR 4
43877 EBADF 9
43878 EACCES 13
43879 EFAULT 14
43880 EBUSY 16
43881 EEXIST 17
43882 ENODEV 19
43883 ENOTDIR 20
43884 EISDIR 21
43885 EINVAL 22
43886 ENFILE 23
43887 EMFILE 24
43888 EFBIG 27
43889 ENOSPC 28
43890 ESPIPE 29
43891 EROFS 30
43892 ENAMETOOLONG 91
43893 EUNKNOWN 9999
43894 @end smallexample
43895
43896 @code{EUNKNOWN} is used as a fallback error value if a host system returns
43897 any error value not in the list of supported error numbers.
43898
43899 @node Lseek Flags
43900 @unnumberedsubsubsec Lseek Flags
43901 @cindex lseek flags, in file-i/o protocol
43902
43903 @smallexample
43904 SEEK_SET 0
43905 SEEK_CUR 1
43906 SEEK_END 2
43907 @end smallexample
43908
43909 @node Limits
43910 @unnumberedsubsubsec Limits
43911 @cindex limits, in file-i/o protocol
43912
43913 All values are given in decimal representation.
43914
43915 @smallexample
43916 INT_MIN -2147483648
43917 INT_MAX 2147483647
43918 UINT_MAX 4294967295
43919 LONG_MIN -9223372036854775808
43920 LONG_MAX 9223372036854775807
43921 ULONG_MAX 18446744073709551615
43922 @end smallexample
43923
43924 @node File-I/O Examples
43925 @subsection File-I/O Examples
43926 @cindex file-i/o examples
43927
43928 Example sequence of a write call, file descriptor 3, buffer is at target
43929 address 0x1234, 6 bytes should be written:
43930
43931 @smallexample
43932 <- @code{Fwrite,3,1234,6}
43933 @emph{request memory read from target}
43934 -> @code{m1234,6}
43935 <- XXXXXX
43936 @emph{return "6 bytes written"}
43937 -> @code{F6}
43938 @end smallexample
43939
43940 Example sequence of a read call, file descriptor 3, buffer is at target
43941 address 0x1234, 6 bytes should be read:
43942
43943 @smallexample
43944 <- @code{Fread,3,1234,6}
43945 @emph{request memory write to target}
43946 -> @code{X1234,6:XXXXXX}
43947 @emph{return "6 bytes read"}
43948 -> @code{F6}
43949 @end smallexample
43950
43951 Example sequence of a read call, call fails on the host due to invalid
43952 file descriptor (@code{EBADF}):
43953
43954 @smallexample
43955 <- @code{Fread,3,1234,6}
43956 -> @code{F-1,9}
43957 @end smallexample
43958
43959 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
43960 host is called:
43961
43962 @smallexample
43963 <- @code{Fread,3,1234,6}
43964 -> @code{F-1,4,C}
43965 <- @code{T02}
43966 @end smallexample
43967
43968 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
43969 host is called:
43970
43971 @smallexample
43972 <- @code{Fread,3,1234,6}
43973 -> @code{X1234,6:XXXXXX}
43974 <- @code{T02}
43975 @end smallexample
43976
43977 @node Library List Format
43978 @section Library List Format
43979 @cindex library list format, remote protocol
43980
43981 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
43982 same process as your application to manage libraries. In this case,
43983 @value{GDBN} can use the loader's symbol table and normal memory
43984 operations to maintain a list of shared libraries. On other
43985 platforms, the operating system manages loaded libraries.
43986 @value{GDBN} can not retrieve the list of currently loaded libraries
43987 through memory operations, so it uses the @samp{qXfer:libraries:read}
43988 packet (@pxref{qXfer library list read}) instead. The remote stub
43989 queries the target's operating system and reports which libraries
43990 are loaded.
43991
43992 The @samp{qXfer:libraries:read} packet returns an XML document which
43993 lists loaded libraries and their offsets. Each library has an
43994 associated name and one or more segment or section base addresses,
43995 which report where the library was loaded in memory.
43996
43997 For the common case of libraries that are fully linked binaries, the
43998 library should have a list of segments. If the target supports
43999 dynamic linking of a relocatable object file, its library XML element
44000 should instead include a list of allocated sections. The segment or
44001 section bases are start addresses, not relocation offsets; they do not
44002 depend on the library's link-time base addresses.
44003
44004 @value{GDBN} must be linked with the Expat library to support XML
44005 library lists. @xref{Expat}.
44006
44007 A simple memory map, with one loaded library relocated by a single
44008 offset, looks like this:
44009
44010 @smallexample
44011 <library-list>
44012 <library name="/lib/libc.so.6">
44013 <segment address="0x10000000"/>
44014 </library>
44015 </library-list>
44016 @end smallexample
44017
44018 Another simple memory map, with one loaded library with three
44019 allocated sections (.text, .data, .bss), looks like this:
44020
44021 @smallexample
44022 <library-list>
44023 <library name="sharedlib.o">
44024 <section address="0x10000000"/>
44025 <section address="0x20000000"/>
44026 <section address="0x30000000"/>
44027 </library>
44028 </library-list>
44029 @end smallexample
44030
44031 The format of a library list is described by this DTD:
44032
44033 @smallexample
44034 <!-- library-list: Root element with versioning -->
44035 <!ELEMENT library-list (library)*>
44036 <!ATTLIST library-list version CDATA #FIXED "1.0">
44037 <!ELEMENT library (segment*, section*)>
44038 <!ATTLIST library name CDATA #REQUIRED>
44039 <!ELEMENT segment EMPTY>
44040 <!ATTLIST segment address CDATA #REQUIRED>
44041 <!ELEMENT section EMPTY>
44042 <!ATTLIST section address CDATA #REQUIRED>
44043 @end smallexample
44044
44045 In addition, segments and section descriptors cannot be mixed within a
44046 single library element, and you must supply at least one segment or
44047 section for each library.
44048
44049 @node Library List Format for SVR4 Targets
44050 @section Library List Format for SVR4 Targets
44051 @cindex library list format, remote protocol
44052
44053 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44054 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44055 shared libraries. Still a special library list provided by this packet is
44056 more efficient for the @value{GDBN} remote protocol.
44057
44058 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44059 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44060 target, the following parameters are reported:
44061
44062 @itemize @minus
44063 @item
44064 @code{name}, the absolute file name from the @code{l_name} field of
44065 @code{struct link_map}.
44066 @item
44067 @code{lm} with address of @code{struct link_map} used for TLS
44068 (Thread Local Storage) access.
44069 @item
44070 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44071 @code{struct link_map}. For prelinked libraries this is not an absolute
44072 memory address. It is a displacement of absolute memory address against
44073 address the file was prelinked to during the library load.
44074 @item
44075 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44076 @end itemize
44077
44078 Additionally the single @code{main-lm} attribute specifies address of
44079 @code{struct link_map} used for the main executable. This parameter is used
44080 for TLS access and its presence is optional.
44081
44082 @value{GDBN} must be linked with the Expat library to support XML
44083 SVR4 library lists. @xref{Expat}.
44084
44085 A simple memory map, with two loaded libraries (which do not use prelink),
44086 looks like this:
44087
44088 @smallexample
44089 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44090 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44091 l_ld="0xe4eefc"/>
44092 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
44093 l_ld="0x152350"/>
44094 </library-list-svr>
44095 @end smallexample
44096
44097 The format of an SVR4 library list is described by this DTD:
44098
44099 @smallexample
44100 <!-- library-list-svr4: Root element with versioning -->
44101 <!ELEMENT library-list-svr4 (library)*>
44102 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44103 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
44104 <!ELEMENT library EMPTY>
44105 <!ATTLIST library name CDATA #REQUIRED>
44106 <!ATTLIST library lm CDATA #REQUIRED>
44107 <!ATTLIST library l_addr CDATA #REQUIRED>
44108 <!ATTLIST library l_ld CDATA #REQUIRED>
44109 @end smallexample
44110
44111 @node Memory Map Format
44112 @section Memory Map Format
44113 @cindex memory map format
44114
44115 To be able to write into flash memory, @value{GDBN} needs to obtain a
44116 memory map from the target. This section describes the format of the
44117 memory map.
44118
44119 The memory map is obtained using the @samp{qXfer:memory-map:read}
44120 (@pxref{qXfer memory map read}) packet and is an XML document that
44121 lists memory regions.
44122
44123 @value{GDBN} must be linked with the Expat library to support XML
44124 memory maps. @xref{Expat}.
44125
44126 The top-level structure of the document is shown below:
44127
44128 @smallexample
44129 <?xml version="1.0"?>
44130 <!DOCTYPE memory-map
44131 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44132 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44133 <memory-map>
44134 region...
44135 </memory-map>
44136 @end smallexample
44137
44138 Each region can be either:
44139
44140 @itemize
44141
44142 @item
44143 A region of RAM starting at @var{addr} and extending for @var{length}
44144 bytes from there:
44145
44146 @smallexample
44147 <memory type="ram" start="@var{addr}" length="@var{length}"/>
44148 @end smallexample
44149
44150
44151 @item
44152 A region of read-only memory:
44153
44154 @smallexample
44155 <memory type="rom" start="@var{addr}" length="@var{length}"/>
44156 @end smallexample
44157
44158
44159 @item
44160 A region of flash memory, with erasure blocks @var{blocksize}
44161 bytes in length:
44162
44163 @smallexample
44164 <memory type="flash" start="@var{addr}" length="@var{length}">
44165 <property name="blocksize">@var{blocksize}</property>
44166 </memory>
44167 @end smallexample
44168
44169 @end itemize
44170
44171 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44172 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44173 packets to write to addresses in such ranges.
44174
44175 The formal DTD for memory map format is given below:
44176
44177 @smallexample
44178 <!-- ................................................... -->
44179 <!-- Memory Map XML DTD ................................ -->
44180 <!-- File: memory-map.dtd .............................. -->
44181 <!-- .................................... .............. -->
44182 <!-- memory-map.dtd -->
44183 <!-- memory-map: Root element with versioning -->
44184 <!ELEMENT memory-map (memory)*>
44185 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
44186 <!ELEMENT memory (property)*>
44187 <!-- memory: Specifies a memory region,
44188 and its type, or device. -->
44189 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
44190 start CDATA #REQUIRED
44191 length CDATA #REQUIRED>
44192 <!-- property: Generic attribute tag -->
44193 <!ELEMENT property (#PCDATA | property)*>
44194 <!ATTLIST property name (blocksize) #REQUIRED>
44195 @end smallexample
44196
44197 @node Thread List Format
44198 @section Thread List Format
44199 @cindex thread list format
44200
44201 To efficiently update the list of threads and their attributes,
44202 @value{GDBN} issues the @samp{qXfer:threads:read} packet
44203 (@pxref{qXfer threads read}) and obtains the XML document with
44204 the following structure:
44205
44206 @smallexample
44207 <?xml version="1.0"?>
44208 <threads>
44209 <thread id="id" core="0" name="name">
44210 ... description ...
44211 </thread>
44212 </threads>
44213 @end smallexample
44214
44215 Each @samp{thread} element must have the @samp{id} attribute that
44216 identifies the thread (@pxref{thread-id syntax}). The
44217 @samp{core} attribute, if present, specifies which processor core
44218 the thread was last executing on. The @samp{name} attribute, if
44219 present, specifies the human-readable name of the thread. The content
44220 of the of @samp{thread} element is interpreted as human-readable
44221 auxiliary information. The @samp{handle} attribute, if present,
44222 is a hex encoded representation of the thread handle.
44223
44224
44225 @node Traceframe Info Format
44226 @section Traceframe Info Format
44227 @cindex traceframe info format
44228
44229 To be able to know which objects in the inferior can be examined when
44230 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44231 memory ranges, registers and trace state variables that have been
44232 collected in a traceframe.
44233
44234 This list is obtained using the @samp{qXfer:traceframe-info:read}
44235 (@pxref{qXfer traceframe info read}) packet and is an XML document.
44236
44237 @value{GDBN} must be linked with the Expat library to support XML
44238 traceframe info discovery. @xref{Expat}.
44239
44240 The top-level structure of the document is shown below:
44241
44242 @smallexample
44243 <?xml version="1.0"?>
44244 <!DOCTYPE traceframe-info
44245 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44246 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44247 <traceframe-info>
44248 block...
44249 </traceframe-info>
44250 @end smallexample
44251
44252 Each traceframe block can be either:
44253
44254 @itemize
44255
44256 @item
44257 A region of collected memory starting at @var{addr} and extending for
44258 @var{length} bytes from there:
44259
44260 @smallexample
44261 <memory start="@var{addr}" length="@var{length}"/>
44262 @end smallexample
44263
44264 @item
44265 A block indicating trace state variable numbered @var{number} has been
44266 collected:
44267
44268 @smallexample
44269 <tvar id="@var{number}"/>
44270 @end smallexample
44271
44272 @end itemize
44273
44274 The formal DTD for the traceframe info format is given below:
44275
44276 @smallexample
44277 <!ELEMENT traceframe-info (memory | tvar)* >
44278 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44279
44280 <!ELEMENT memory EMPTY>
44281 <!ATTLIST memory start CDATA #REQUIRED
44282 length CDATA #REQUIRED>
44283 <!ELEMENT tvar>
44284 <!ATTLIST tvar id CDATA #REQUIRED>
44285 @end smallexample
44286
44287 @node Branch Trace Format
44288 @section Branch Trace Format
44289 @cindex branch trace format
44290
44291 In order to display the branch trace of an inferior thread,
44292 @value{GDBN} needs to obtain the list of branches. This list is
44293 represented as list of sequential code blocks that are connected via
44294 branches. The code in each block has been executed sequentially.
44295
44296 This list is obtained using the @samp{qXfer:btrace:read}
44297 (@pxref{qXfer btrace read}) packet and is an XML document.
44298
44299 @value{GDBN} must be linked with the Expat library to support XML
44300 traceframe info discovery. @xref{Expat}.
44301
44302 The top-level structure of the document is shown below:
44303
44304 @smallexample
44305 <?xml version="1.0"?>
44306 <!DOCTYPE btrace
44307 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44308 "http://sourceware.org/gdb/gdb-btrace.dtd">
44309 <btrace>
44310 block...
44311 </btrace>
44312 @end smallexample
44313
44314 @itemize
44315
44316 @item
44317 A block of sequentially executed instructions starting at @var{begin}
44318 and ending at @var{end}:
44319
44320 @smallexample
44321 <block begin="@var{begin}" end="@var{end}"/>
44322 @end smallexample
44323
44324 @end itemize
44325
44326 The formal DTD for the branch trace format is given below:
44327
44328 @smallexample
44329 <!ELEMENT btrace (block* | pt) >
44330 <!ATTLIST btrace version CDATA #FIXED "1.0">
44331
44332 <!ELEMENT block EMPTY>
44333 <!ATTLIST block begin CDATA #REQUIRED
44334 end CDATA #REQUIRED>
44335
44336 <!ELEMENT pt (pt-config?, raw?)>
44337
44338 <!ELEMENT pt-config (cpu?)>
44339
44340 <!ELEMENT cpu EMPTY>
44341 <!ATTLIST cpu vendor CDATA #REQUIRED
44342 family CDATA #REQUIRED
44343 model CDATA #REQUIRED
44344 stepping CDATA #REQUIRED>
44345
44346 <!ELEMENT raw (#PCDATA)>
44347 @end smallexample
44348
44349 @node Branch Trace Configuration Format
44350 @section Branch Trace Configuration Format
44351 @cindex branch trace configuration format
44352
44353 For each inferior thread, @value{GDBN} can obtain the branch trace
44354 configuration using the @samp{qXfer:btrace-conf:read}
44355 (@pxref{qXfer btrace-conf read}) packet.
44356
44357 The configuration describes the branch trace format and configuration
44358 settings for that format. The following information is described:
44359
44360 @table @code
44361 @item bts
44362 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44363 @table @code
44364 @item size
44365 The size of the @acronym{BTS} ring buffer in bytes.
44366 @end table
44367 @item pt
44368 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
44369 PT}) format.
44370 @table @code
44371 @item size
44372 The size of the @acronym{Intel PT} ring buffer in bytes.
44373 @end table
44374 @end table
44375
44376 @value{GDBN} must be linked with the Expat library to support XML
44377 branch trace configuration discovery. @xref{Expat}.
44378
44379 The formal DTD for the branch trace configuration format is given below:
44380
44381 @smallexample
44382 <!ELEMENT btrace-conf (bts?, pt?)>
44383 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44384
44385 <!ELEMENT bts EMPTY>
44386 <!ATTLIST bts size CDATA #IMPLIED>
44387
44388 <!ELEMENT pt EMPTY>
44389 <!ATTLIST pt size CDATA #IMPLIED>
44390 @end smallexample
44391
44392 @include agentexpr.texi
44393
44394 @node Target Descriptions
44395 @appendix Target Descriptions
44396 @cindex target descriptions
44397
44398 One of the challenges of using @value{GDBN} to debug embedded systems
44399 is that there are so many minor variants of each processor
44400 architecture in use. It is common practice for vendors to start with
44401 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
44402 and then make changes to adapt it to a particular market niche. Some
44403 architectures have hundreds of variants, available from dozens of
44404 vendors. This leads to a number of problems:
44405
44406 @itemize @bullet
44407 @item
44408 With so many different customized processors, it is difficult for
44409 the @value{GDBN} maintainers to keep up with the changes.
44410 @item
44411 Since individual variants may have short lifetimes or limited
44412 audiences, it may not be worthwhile to carry information about every
44413 variant in the @value{GDBN} source tree.
44414 @item
44415 When @value{GDBN} does support the architecture of the embedded system
44416 at hand, the task of finding the correct architecture name to give the
44417 @command{set architecture} command can be error-prone.
44418 @end itemize
44419
44420 To address these problems, the @value{GDBN} remote protocol allows a
44421 target system to not only identify itself to @value{GDBN}, but to
44422 actually describe its own features. This lets @value{GDBN} support
44423 processor variants it has never seen before --- to the extent that the
44424 descriptions are accurate, and that @value{GDBN} understands them.
44425
44426 @value{GDBN} must be linked with the Expat library to support XML
44427 target descriptions. @xref{Expat}.
44428
44429 @menu
44430 * Retrieving Descriptions:: How descriptions are fetched from a target.
44431 * Target Description Format:: The contents of a target description.
44432 * Predefined Target Types:: Standard types available for target
44433 descriptions.
44434 * Enum Target Types:: How to define enum target types.
44435 * Standard Target Features:: Features @value{GDBN} knows about.
44436 @end menu
44437
44438 @node Retrieving Descriptions
44439 @section Retrieving Descriptions
44440
44441 Target descriptions can be read from the target automatically, or
44442 specified by the user manually. The default behavior is to read the
44443 description from the target. @value{GDBN} retrieves it via the remote
44444 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44445 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44446 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
44447 XML document, of the form described in @ref{Target Description
44448 Format}.
44449
44450 Alternatively, you can specify a file to read for the target description.
44451 If a file is set, the target will not be queried. The commands to
44452 specify a file are:
44453
44454 @table @code
44455 @cindex set tdesc filename
44456 @item set tdesc filename @var{path}
44457 Read the target description from @var{path}.
44458
44459 @cindex unset tdesc filename
44460 @item unset tdesc filename
44461 Do not read the XML target description from a file. @value{GDBN}
44462 will use the description supplied by the current target.
44463
44464 @cindex show tdesc filename
44465 @item show tdesc filename
44466 Show the filename to read for a target description, if any.
44467 @end table
44468
44469
44470 @node Target Description Format
44471 @section Target Description Format
44472 @cindex target descriptions, XML format
44473
44474 A target description annex is an @uref{http://www.w3.org/XML/, XML}
44475 document which complies with the Document Type Definition provided in
44476 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44477 means you can use generally available tools like @command{xmllint} to
44478 check that your feature descriptions are well-formed and valid.
44479 However, to help people unfamiliar with XML write descriptions for
44480 their targets, we also describe the grammar here.
44481
44482 Target descriptions can identify the architecture of the remote target
44483 and (for some architectures) provide information about custom register
44484 sets. They can also identify the OS ABI of the remote target.
44485 @value{GDBN} can use this information to autoconfigure for your
44486 target, or to warn you if you connect to an unsupported target.
44487
44488 Here is a simple target description:
44489
44490 @smallexample
44491 <target version="1.0">
44492 <architecture>i386:x86-64</architecture>
44493 </target>
44494 @end smallexample
44495
44496 @noindent
44497 This minimal description only says that the target uses
44498 the x86-64 architecture.
44499
44500 A target description has the following overall form, with [ ] marking
44501 optional elements and @dots{} marking repeatable elements. The elements
44502 are explained further below.
44503
44504 @smallexample
44505 <?xml version="1.0"?>
44506 <!DOCTYPE target SYSTEM "gdb-target.dtd">
44507 <target version="1.0">
44508 @r{[}@var{architecture}@r{]}
44509 @r{[}@var{osabi}@r{]}
44510 @r{[}@var{compatible}@r{]}
44511 @r{[}@var{feature}@dots{}@r{]}
44512 </target>
44513 @end smallexample
44514
44515 @noindent
44516 The description is generally insensitive to whitespace and line
44517 breaks, under the usual common-sense rules. The XML version
44518 declaration and document type declaration can generally be omitted
44519 (@value{GDBN} does not require them), but specifying them may be
44520 useful for XML validation tools. The @samp{version} attribute for
44521 @samp{<target>} may also be omitted, but we recommend
44522 including it; if future versions of @value{GDBN} use an incompatible
44523 revision of @file{gdb-target.dtd}, they will detect and report
44524 the version mismatch.
44525
44526 @subsection Inclusion
44527 @cindex target descriptions, inclusion
44528 @cindex XInclude
44529 @ifnotinfo
44530 @cindex <xi:include>
44531 @end ifnotinfo
44532
44533 It can sometimes be valuable to split a target description up into
44534 several different annexes, either for organizational purposes, or to
44535 share files between different possible target descriptions. You can
44536 divide a description into multiple files by replacing any element of
44537 the target description with an inclusion directive of the form:
44538
44539 @smallexample
44540 <xi:include href="@var{document}"/>
44541 @end smallexample
44542
44543 @noindent
44544 When @value{GDBN} encounters an element of this form, it will retrieve
44545 the named XML @var{document}, and replace the inclusion directive with
44546 the contents of that document. If the current description was read
44547 using @samp{qXfer}, then so will be the included document;
44548 @var{document} will be interpreted as the name of an annex. If the
44549 current description was read from a file, @value{GDBN} will look for
44550 @var{document} as a file in the same directory where it found the
44551 original description.
44552
44553 @subsection Architecture
44554 @cindex <architecture>
44555
44556 An @samp{<architecture>} element has this form:
44557
44558 @smallexample
44559 <architecture>@var{arch}</architecture>
44560 @end smallexample
44561
44562 @var{arch} is one of the architectures from the set accepted by
44563 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44564
44565 @subsection OS ABI
44566 @cindex @code{<osabi>}
44567
44568 This optional field was introduced in @value{GDBN} version 7.0.
44569 Previous versions of @value{GDBN} ignore it.
44570
44571 An @samp{<osabi>} element has this form:
44572
44573 @smallexample
44574 <osabi>@var{abi-name}</osabi>
44575 @end smallexample
44576
44577 @var{abi-name} is an OS ABI name from the same selection accepted by
44578 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44579
44580 @subsection Compatible Architecture
44581 @cindex @code{<compatible>}
44582
44583 This optional field was introduced in @value{GDBN} version 7.0.
44584 Previous versions of @value{GDBN} ignore it.
44585
44586 A @samp{<compatible>} element has this form:
44587
44588 @smallexample
44589 <compatible>@var{arch}</compatible>
44590 @end smallexample
44591
44592 @var{arch} is one of the architectures from the set accepted by
44593 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44594
44595 A @samp{<compatible>} element is used to specify that the target
44596 is able to run binaries in some other than the main target architecture
44597 given by the @samp{<architecture>} element. For example, on the
44598 Cell Broadband Engine, the main architecture is @code{powerpc:common}
44599 or @code{powerpc:common64}, but the system is able to run binaries
44600 in the @code{spu} architecture as well. The way to describe this
44601 capability with @samp{<compatible>} is as follows:
44602
44603 @smallexample
44604 <architecture>powerpc:common</architecture>
44605 <compatible>spu</compatible>
44606 @end smallexample
44607
44608 @subsection Features
44609 @cindex <feature>
44610
44611 Each @samp{<feature>} describes some logical portion of the target
44612 system. Features are currently used to describe available CPU
44613 registers and the types of their contents. A @samp{<feature>} element
44614 has this form:
44615
44616 @smallexample
44617 <feature name="@var{name}">
44618 @r{[}@var{type}@dots{}@r{]}
44619 @var{reg}@dots{}
44620 </feature>
44621 @end smallexample
44622
44623 @noindent
44624 Each feature's name should be unique within the description. The name
44625 of a feature does not matter unless @value{GDBN} has some special
44626 knowledge of the contents of that feature; if it does, the feature
44627 should have its standard name. @xref{Standard Target Features}.
44628
44629 @subsection Types
44630
44631 Any register's value is a collection of bits which @value{GDBN} must
44632 interpret. The default interpretation is a two's complement integer,
44633 but other types can be requested by name in the register description.
44634 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
44635 Target Types}), and the description can define additional composite
44636 and enum types.
44637
44638 Each type element must have an @samp{id} attribute, which gives
44639 a unique (within the containing @samp{<feature>}) name to the type.
44640 Types must be defined before they are used.
44641
44642 @cindex <vector>
44643 Some targets offer vector registers, which can be treated as arrays
44644 of scalar elements. These types are written as @samp{<vector>} elements,
44645 specifying the array element type, @var{type}, and the number of elements,
44646 @var{count}:
44647
44648 @smallexample
44649 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44650 @end smallexample
44651
44652 @cindex <union>
44653 If a register's value is usefully viewed in multiple ways, define it
44654 with a union type containing the useful representations. The
44655 @samp{<union>} element contains one or more @samp{<field>} elements,
44656 each of which has a @var{name} and a @var{type}:
44657
44658 @smallexample
44659 <union id="@var{id}">
44660 <field name="@var{name}" type="@var{type}"/>
44661 @dots{}
44662 </union>
44663 @end smallexample
44664
44665 @cindex <struct>
44666 @cindex <flags>
44667 If a register's value is composed from several separate values, define
44668 it with either a structure type or a flags type.
44669 A flags type may only contain bitfields.
44670 A structure type may either contain only bitfields or contain no bitfields.
44671 If the value contains only bitfields, its total size in bytes must be
44672 specified.
44673
44674 Non-bitfield values have a @var{name} and @var{type}.
44675
44676 @smallexample
44677 <struct id="@var{id}">
44678 <field name="@var{name}" type="@var{type}"/>
44679 @dots{}
44680 </struct>
44681 @end smallexample
44682
44683 Both @var{name} and @var{type} values are required.
44684 No implicit padding is added.
44685
44686 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
44687
44688 @smallexample
44689 <struct id="@var{id}" size="@var{size}">
44690 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44691 @dots{}
44692 </struct>
44693 @end smallexample
44694
44695 @smallexample
44696 <flags id="@var{id}" size="@var{size}">
44697 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44698 @dots{}
44699 </flags>
44700 @end smallexample
44701
44702 The @var{name} value is required.
44703 Bitfield values may be named with the empty string, @samp{""},
44704 in which case the field is ``filler'' and its value is not printed.
44705 Not all bits need to be specified, so ``filler'' fields are optional.
44706
44707 The @var{start} and @var{end} values are required, and @var{type}
44708 is optional.
44709 The field's @var{start} must be less than or equal to its @var{end},
44710 and zero represents the least significant bit.
44711
44712 The default value of @var{type} is @code{bool} for single bit fields,
44713 and an unsigned integer otherwise.
44714
44715 Which to choose? Structures or flags?
44716
44717 Registers defined with @samp{flags} have these advantages over
44718 defining them with @samp{struct}:
44719
44720 @itemize @bullet
44721 @item
44722 Arithmetic may be performed on them as if they were integers.
44723 @item
44724 They are printed in a more readable fashion.
44725 @end itemize
44726
44727 Registers defined with @samp{struct} have one advantage over
44728 defining them with @samp{flags}:
44729
44730 @itemize @bullet
44731 @item
44732 One can fetch individual fields like in @samp{C}.
44733
44734 @smallexample
44735 (gdb) print $my_struct_reg.field3
44736 $1 = 42
44737 @end smallexample
44738
44739 @end itemize
44740
44741 @subsection Registers
44742 @cindex <reg>
44743
44744 Each register is represented as an element with this form:
44745
44746 @smallexample
44747 <reg name="@var{name}"
44748 bitsize="@var{size}"
44749 @r{[}regnum="@var{num}"@r{]}
44750 @r{[}save-restore="@var{save-restore}"@r{]}
44751 @r{[}type="@var{type}"@r{]}
44752 @r{[}group="@var{group}"@r{]}/>
44753 @end smallexample
44754
44755 @noindent
44756 The components are as follows:
44757
44758 @table @var
44759
44760 @item name
44761 The register's name; it must be unique within the target description.
44762
44763 @item bitsize
44764 The register's size, in bits.
44765
44766 @item regnum
44767 The register's number. If omitted, a register's number is one greater
44768 than that of the previous register (either in the current feature or in
44769 a preceding feature); the first register in the target description
44770 defaults to zero. This register number is used to read or write
44771 the register; e.g.@: it is used in the remote @code{p} and @code{P}
44772 packets, and registers appear in the @code{g} and @code{G} packets
44773 in order of increasing register number.
44774
44775 @item save-restore
44776 Whether the register should be preserved across inferior function
44777 calls; this must be either @code{yes} or @code{no}. The default is
44778 @code{yes}, which is appropriate for most registers except for
44779 some system control registers; this is not related to the target's
44780 ABI.
44781
44782 @item type
44783 The type of the register. It may be a predefined type, a type
44784 defined in the current feature, or one of the special types @code{int}
44785 and @code{float}. @code{int} is an integer type of the correct size
44786 for @var{bitsize}, and @code{float} is a floating point type (in the
44787 architecture's normal floating point format) of the correct size for
44788 @var{bitsize}. The default is @code{int}.
44789
44790 @item group
44791 The register group to which this register belongs. It can be one of the
44792 standard register groups @code{general}, @code{float}, @code{vector} or an
44793 arbitrary string. Group names should be limited to alphanumeric characters.
44794 If a group name is made up of multiple words the words may be separated by
44795 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
44796 @var{group} is specified, @value{GDBN} will not display the register in
44797 @code{info registers}.
44798
44799 @end table
44800
44801 @node Predefined Target Types
44802 @section Predefined Target Types
44803 @cindex target descriptions, predefined types
44804
44805 Type definitions in the self-description can build up composite types
44806 from basic building blocks, but can not define fundamental types. Instead,
44807 standard identifiers are provided by @value{GDBN} for the fundamental
44808 types. The currently supported types are:
44809
44810 @table @code
44811
44812 @item bool
44813 Boolean type, occupying a single bit.
44814
44815 @item int8
44816 @itemx int16
44817 @itemx int24
44818 @itemx int32
44819 @itemx int64
44820 @itemx int128
44821 Signed integer types holding the specified number of bits.
44822
44823 @item uint8
44824 @itemx uint16
44825 @itemx uint24
44826 @itemx uint32
44827 @itemx uint64
44828 @itemx uint128
44829 Unsigned integer types holding the specified number of bits.
44830
44831 @item code_ptr
44832 @itemx data_ptr
44833 Pointers to unspecified code and data. The program counter and
44834 any dedicated return address register may be marked as code
44835 pointers; printing a code pointer converts it into a symbolic
44836 address. The stack pointer and any dedicated address registers
44837 may be marked as data pointers.
44838
44839 @item ieee_single
44840 Single precision IEEE floating point.
44841
44842 @item ieee_double
44843 Double precision IEEE floating point.
44844
44845 @item arm_fpa_ext
44846 The 12-byte extended precision format used by ARM FPA registers.
44847
44848 @item i387_ext
44849 The 10-byte extended precision format used by x87 registers.
44850
44851 @item i386_eflags
44852 32bit @sc{eflags} register used by x86.
44853
44854 @item i386_mxcsr
44855 32bit @sc{mxcsr} register used by x86.
44856
44857 @end table
44858
44859 @node Enum Target Types
44860 @section Enum Target Types
44861 @cindex target descriptions, enum types
44862
44863 Enum target types are useful in @samp{struct} and @samp{flags}
44864 register descriptions. @xref{Target Description Format}.
44865
44866 Enum types have a name, size and a list of name/value pairs.
44867
44868 @smallexample
44869 <enum id="@var{id}" size="@var{size}">
44870 <evalue name="@var{name}" value="@var{value}"/>
44871 @dots{}
44872 </enum>
44873 @end smallexample
44874
44875 Enums must be defined before they are used.
44876
44877 @smallexample
44878 <enum id="levels_type" size="4">
44879 <evalue name="low" value="0"/>
44880 <evalue name="high" value="1"/>
44881 </enum>
44882 <flags id="flags_type" size="4">
44883 <field name="X" start="0"/>
44884 <field name="LEVEL" start="1" end="1" type="levels_type"/>
44885 </flags>
44886 <reg name="flags" bitsize="32" type="flags_type"/>
44887 @end smallexample
44888
44889 Given that description, a value of 3 for the @samp{flags} register
44890 would be printed as:
44891
44892 @smallexample
44893 (gdb) info register flags
44894 flags 0x3 [ X LEVEL=high ]
44895 @end smallexample
44896
44897 @node Standard Target Features
44898 @section Standard Target Features
44899 @cindex target descriptions, standard features
44900
44901 A target description must contain either no registers or all the
44902 target's registers. If the description contains no registers, then
44903 @value{GDBN} will assume a default register layout, selected based on
44904 the architecture. If the description contains any registers, the
44905 default layout will not be used; the standard registers must be
44906 described in the target description, in such a way that @value{GDBN}
44907 can recognize them.
44908
44909 This is accomplished by giving specific names to feature elements
44910 which contain standard registers. @value{GDBN} will look for features
44911 with those names and verify that they contain the expected registers;
44912 if any known feature is missing required registers, or if any required
44913 feature is missing, @value{GDBN} will reject the target
44914 description. You can add additional registers to any of the
44915 standard features --- @value{GDBN} will display them just as if
44916 they were added to an unrecognized feature.
44917
44918 This section lists the known features and their expected contents.
44919 Sample XML documents for these features are included in the
44920 @value{GDBN} source tree, in the directory @file{gdb/features}.
44921
44922 Names recognized by @value{GDBN} should include the name of the
44923 company or organization which selected the name, and the overall
44924 architecture to which the feature applies; so e.g.@: the feature
44925 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
44926
44927 The names of registers are not case sensitive for the purpose
44928 of recognizing standard features, but @value{GDBN} will only display
44929 registers using the capitalization used in the description.
44930
44931 @menu
44932 * AArch64 Features::
44933 * ARC Features::
44934 * ARM Features::
44935 * i386 Features::
44936 * MicroBlaze Features::
44937 * MIPS Features::
44938 * M68K Features::
44939 * NDS32 Features::
44940 * Nios II Features::
44941 * OpenRISC 1000 Features::
44942 * PowerPC Features::
44943 * RISC-V Features::
44944 * RX Features::
44945 * S/390 and System z Features::
44946 * Sparc Features::
44947 * TIC6x Features::
44948 @end menu
44949
44950
44951 @node AArch64 Features
44952 @subsection AArch64 Features
44953 @cindex target descriptions, AArch64 features
44954
44955 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
44956 targets. It should contain registers @samp{x0} through @samp{x30},
44957 @samp{sp}, @samp{pc}, and @samp{cpsr}.
44958
44959 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
44960 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
44961 and @samp{fpcr}.
44962
44963 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
44964 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
44965 through @samp{p15}, @samp{ffr} and @samp{vg}.
44966
44967 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
44968 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
44969
44970 @node ARC Features
44971 @subsection ARC Features
44972 @cindex target descriptions, ARC Features
44973
44974 ARC processors are highly configurable, so even core registers and their number
44975 are not completely predetermined. In addition flags and PC registers which are
44976 important to @value{GDBN} are not ``core'' registers in ARC. It is required
44977 that one of the core registers features is present.
44978 @samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
44979
44980 The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
44981 targets with a normal register file. It should contain registers @samp{r0}
44982 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
44983 @samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
44984 and any of extension core registers @samp{r32} through @samp{r59/acch}.
44985 @samp{ilink} and extension core registers are not available to read/write, when
44986 debugging GNU/Linux applications, thus @samp{ilink} is made optional.
44987
44988 The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
44989 ARC HS targets with a reduced register file. It should contain registers
44990 @samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
44991 @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
44992 This feature may contain register @samp{ilink} and any of extension core
44993 registers @samp{r32} through @samp{r59/acch}.
44994
44995 The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
44996 targets with a normal register file. It should contain registers @samp{r0}
44997 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
44998 @samp{lp_count} and @samp{pcl}. This feature may contain registers
44999 @samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45000 through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45001 registers are not available when debugging GNU/Linux applications. The only
45002 difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45003 @samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45004 ARC v2, but @samp{ilink2} is optional on ARCompact.
45005
45006 The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45007 targets. It should contain registers @samp{pc} and @samp{status32}.
45008
45009 @node ARM Features
45010 @subsection ARM Features
45011 @cindex target descriptions, ARM features
45012
45013 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45014 ARM targets.
45015 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45016 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45017
45018 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45019 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45020 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45021 and @samp{xpsr}.
45022
45023 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45024 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45025
45026 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45027 it should contain at least registers @samp{wR0} through @samp{wR15} and
45028 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45029 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45030
45031 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45032 should contain at least registers @samp{d0} through @samp{d15}. If
45033 they are present, @samp{d16} through @samp{d31} should also be included.
45034 @value{GDBN} will synthesize the single-precision registers from
45035 halves of the double-precision registers.
45036
45037 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45038 need to contain registers; it instructs @value{GDBN} to display the
45039 VFP double-precision registers as vectors and to synthesize the
45040 quad-precision registers from pairs of double-precision registers.
45041 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45042 be present and include 32 double-precision registers.
45043
45044 @node i386 Features
45045 @subsection i386 Features
45046 @cindex target descriptions, i386 features
45047
45048 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45049 targets. It should describe the following registers:
45050
45051 @itemize @minus
45052 @item
45053 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45054 @item
45055 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45056 @item
45057 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45058 @samp{fs}, @samp{gs}
45059 @item
45060 @samp{st0} through @samp{st7}
45061 @item
45062 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45063 @samp{foseg}, @samp{fooff} and @samp{fop}
45064 @end itemize
45065
45066 The register sets may be different, depending on the target.
45067
45068 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45069 describe registers:
45070
45071 @itemize @minus
45072 @item
45073 @samp{xmm0} through @samp{xmm7} for i386
45074 @item
45075 @samp{xmm0} through @samp{xmm15} for amd64
45076 @item
45077 @samp{mxcsr}
45078 @end itemize
45079
45080 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45081 @samp{org.gnu.gdb.i386.sse} feature. It should
45082 describe the upper 128 bits of @sc{ymm} registers:
45083
45084 @itemize @minus
45085 @item
45086 @samp{ymm0h} through @samp{ymm7h} for i386
45087 @item
45088 @samp{ymm0h} through @samp{ymm15h} for amd64
45089 @end itemize
45090
45091 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
45092 Memory Protection Extension (MPX). It should describe the following registers:
45093
45094 @itemize @minus
45095 @item
45096 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45097 @item
45098 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45099 @end itemize
45100
45101 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45102 describe a single register, @samp{orig_eax}.
45103
45104 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45105 describe two system registers: @samp{fs_base} and @samp{gs_base}.
45106
45107 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45108 @samp{org.gnu.gdb.i386.avx} feature. It should
45109 describe additional @sc{xmm} registers:
45110
45111 @itemize @minus
45112 @item
45113 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45114 @end itemize
45115
45116 It should describe the upper 128 bits of additional @sc{ymm} registers:
45117
45118 @itemize @minus
45119 @item
45120 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45121 @end itemize
45122
45123 It should
45124 describe the upper 256 bits of @sc{zmm} registers:
45125
45126 @itemize @minus
45127 @item
45128 @samp{zmm0h} through @samp{zmm7h} for i386.
45129 @item
45130 @samp{zmm0h} through @samp{zmm15h} for amd64.
45131 @end itemize
45132
45133 It should
45134 describe the additional @sc{zmm} registers:
45135
45136 @itemize @minus
45137 @item
45138 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45139 @end itemize
45140
45141 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45142 describe a single register, @samp{pkru}. It is a 32-bit register
45143 valid for i386 and amd64.
45144
45145 @node MicroBlaze Features
45146 @subsection MicroBlaze Features
45147 @cindex target descriptions, MicroBlaze features
45148
45149 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45150 targets. It should contain registers @samp{r0} through @samp{r31},
45151 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45152 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45153 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45154
45155 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45156 If present, it should contain registers @samp{rshr} and @samp{rslr}
45157
45158 @node MIPS Features
45159 @subsection @acronym{MIPS} Features
45160 @cindex target descriptions, @acronym{MIPS} features
45161
45162 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
45163 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45164 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45165 on the target.
45166
45167 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45168 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45169 registers. They may be 32-bit or 64-bit depending on the target.
45170
45171 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45172 it may be optional in a future version of @value{GDBN}. It should
45173 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45174 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
45175
45176 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45177 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45178 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45179 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45180
45181 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45182 contain a single register, @samp{restart}, which is used by the
45183 Linux kernel to control restartable syscalls.
45184
45185 @node M68K Features
45186 @subsection M68K Features
45187 @cindex target descriptions, M68K features
45188
45189 @table @code
45190 @item @samp{org.gnu.gdb.m68k.core}
45191 @itemx @samp{org.gnu.gdb.coldfire.core}
45192 @itemx @samp{org.gnu.gdb.fido.core}
45193 One of those features must be always present.
45194 The feature that is present determines which flavor of m68k is
45195 used. The feature that is present should contain registers
45196 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45197 @samp{sp}, @samp{ps} and @samp{pc}.
45198
45199 @item @samp{org.gnu.gdb.coldfire.fp}
45200 This feature is optional. If present, it should contain registers
45201 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45202 @samp{fpiaddr}.
45203 @end table
45204
45205 @node NDS32 Features
45206 @subsection NDS32 Features
45207 @cindex target descriptions, NDS32 features
45208
45209 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45210 targets. It should contain at least registers @samp{r0} through
45211 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45212 and @samp{pc}.
45213
45214 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45215 it should contain 64-bit double-precision floating-point registers
45216 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45217 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45218
45219 @emph{Note:} The first sixteen 64-bit double-precision floating-point
45220 registers are overlapped with the thirty-two 32-bit single-precision
45221 floating-point registers. The 32-bit single-precision registers, if
45222 not being listed explicitly, will be synthesized from halves of the
45223 overlapping 64-bit double-precision registers. Listing 32-bit
45224 single-precision registers explicitly is deprecated, and the
45225 support to it could be totally removed some day.
45226
45227 @node Nios II Features
45228 @subsection Nios II Features
45229 @cindex target descriptions, Nios II features
45230
45231 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45232 targets. It should contain the 32 core registers (@samp{zero},
45233 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45234 @samp{pc}, and the 16 control registers (@samp{status} through
45235 @samp{mpuacc}).
45236
45237 @node OpenRISC 1000 Features
45238 @subsection Openrisc 1000 Features
45239 @cindex target descriptions, OpenRISC 1000 features
45240
45241 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45242 targets. It should contain the 32 general purpose registers (@samp{r0}
45243 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45244
45245 @node PowerPC Features
45246 @subsection PowerPC Features
45247 @cindex target descriptions, PowerPC features
45248
45249 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45250 targets. It should contain registers @samp{r0} through @samp{r31},
45251 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45252 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
45253
45254 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45255 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45256
45257 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
45258 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45259 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45260 through @samp{v31} as aliases for the corresponding @samp{vrX}
45261 registers.
45262
45263 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
45264 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45265 combine these registers with the floating point registers (@samp{f0}
45266 through @samp{f31}) and the altivec registers (@samp{vr0} through
45267 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45268 @samp{vs63}, the set of vector-scalar registers for POWER7.
45269 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45270 @samp{org.gnu.gdb.power.altivec}.
45271
45272 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45273 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45274 @samp{spefscr}. SPE targets should provide 32-bit registers in
45275 @samp{org.gnu.gdb.power.core} and provide the upper halves in
45276 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45277 these to present registers @samp{ev0} through @samp{ev31} to the
45278 user.
45279
45280 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45281 contain the 64-bit register @samp{ppr}.
45282
45283 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45284 contain the 64-bit register @samp{dscr}.
45285
45286 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45287 contain the 64-bit register @samp{tar}.
45288
45289 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45290 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
45291 64-bit wide.
45292
45293 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45294 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45295 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45296 server PMU registers provided by @sc{gnu}/Linux.
45297
45298 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45299 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
45300 64-bit wide.
45301
45302 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45303 contain the checkpointed general-purpose registers @samp{cr0} through
45304 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
45305 @samp{cctr}. These registers may all be either 32-bit or 64-bit
45306 depending on the target. It should also contain the checkpointed
45307 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45308 wide.
45309
45310 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45311 contain the checkpointed 64-bit floating-point registers @samp{cf0}
45312 through @samp{cf31}, as well as the checkpointed 64-bit register
45313 @samp{cfpscr}.
45314
45315 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45316 should contain the checkpointed altivec registers @samp{cvr0} through
45317 @samp{cvr31}, all 128-bit wide. It should also contain the
45318 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45319 wide.
45320
45321 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45322 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45323 will combine these registers with the checkpointed floating point
45324 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45325 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45326 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45327 @samp{cvs63}. Therefore, this feature requires both
45328 @samp{org.gnu.gdb.power.htm.altivec} and
45329 @samp{org.gnu.gdb.power.htm.fpu}.
45330
45331 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45332 contain the 64-bit checkpointed register @samp{cppr}.
45333
45334 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45335 contain the 64-bit checkpointed register @samp{cdscr}.
45336
45337 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45338 contain the 64-bit checkpointed register @samp{ctar}.
45339
45340
45341 @node RISC-V Features
45342 @subsection RISC-V Features
45343 @cindex target descriptions, RISC-V Features
45344
45345 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45346 targets. It should contain the registers @samp{x0} through
45347 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45348 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45349 etc).
45350
45351 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45352 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45353 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45354 architectural register names, or the ABI names can be used.
45355
45356 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45357 it should contain registers that are not backed by real registers on
45358 the target, but are instead virtual, where the register value is
45359 derived from other target state. In many ways these are like
45360 @value{GDBN}s pseudo-registers, except implemented by the target.
45361 Currently the only register expected in this set is the one byte
45362 @samp{priv} register that contains the target's privilege level in the
45363 least significant two bits.
45364
45365 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45366 should contain all of the target's standard CSRs. Standard CSRs are
45367 those defined in the RISC-V specification documents. There is some
45368 overlap between this feature and the fpu feature; the @samp{fflags},
45369 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
45370 expectation is that these registers will be in the fpu feature if the
45371 target has floating point hardware, but can be moved into the csr
45372 feature if the target has the floating point control registers, but no
45373 other floating point hardware.
45374
45375 @node RX Features
45376 @subsection RX Features
45377 @cindex target descriptions, RX Features
45378
45379 The @samp{org.gnu.gdb.rx.core} feature is required for RX
45380 targets. It should contain the registers @samp{r0} through
45381 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45382 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45383
45384 @node S/390 and System z Features
45385 @subsection S/390 and System z Features
45386 @cindex target descriptions, S/390 features
45387 @cindex target descriptions, System z features
45388
45389 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45390 System z targets. It should contain the PSW and the 16 general
45391 registers. In particular, System z targets should provide the 64-bit
45392 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45393 S/390 targets should provide the 32-bit versions of these registers.
45394 A System z target that runs in 31-bit addressing mode should provide
45395 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45396 register's upper halves @samp{r0h} through @samp{r15h}, and their
45397 lower halves @samp{r0l} through @samp{r15l}.
45398
45399 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45400 contain the 64-bit registers @samp{f0} through @samp{f15}, and
45401 @samp{fpc}.
45402
45403 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45404 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45405
45406 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45407 contain the register @samp{orig_r2}, which is 64-bit wide on System z
45408 targets and 32-bit otherwise. In addition, the feature may contain
45409 the @samp{last_break} register, whose width depends on the addressing
45410 mode, as well as the @samp{system_call} register, which is always
45411 32-bit wide.
45412
45413 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45414 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45415 @samp{atia}, and @samp{tr0} through @samp{tr15}.
45416
45417 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
45418 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45419 combined by @value{GDBN} with the floating point registers @samp{f0}
45420 through @samp{f15} to present the 128-bit wide vector registers
45421 @samp{v0} through @samp{v15}. In addition, this feature should
45422 contain the 128-bit wide vector registers @samp{v16} through
45423 @samp{v31}.
45424
45425 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45426 the 64-bit wide guarded-storage-control registers @samp{gsd},
45427 @samp{gssm}, and @samp{gsepla}.
45428
45429 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45430 the 64-bit wide guarded-storage broadcast control registers
45431 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45432
45433 @node Sparc Features
45434 @subsection Sparc Features
45435 @cindex target descriptions, sparc32 features
45436 @cindex target descriptions, sparc64 features
45437 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45438 targets. It should describe the following registers:
45439
45440 @itemize @minus
45441 @item
45442 @samp{g0} through @samp{g7}
45443 @item
45444 @samp{o0} through @samp{o7}
45445 @item
45446 @samp{l0} through @samp{l7}
45447 @item
45448 @samp{i0} through @samp{i7}
45449 @end itemize
45450
45451 They may be 32-bit or 64-bit depending on the target.
45452
45453 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45454 targets. It should describe the following registers:
45455
45456 @itemize @minus
45457 @item
45458 @samp{f0} through @samp{f31}
45459 @item
45460 @samp{f32} through @samp{f62} for sparc64
45461 @end itemize
45462
45463 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45464 targets. It should describe the following registers:
45465
45466 @itemize @minus
45467 @item
45468 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45469 @samp{fsr}, and @samp{csr} for sparc32
45470 @item
45471 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45472 for sparc64
45473 @end itemize
45474
45475 @node TIC6x Features
45476 @subsection TMS320C6x Features
45477 @cindex target descriptions, TIC6x features
45478 @cindex target descriptions, TMS320C6x features
45479 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45480 targets. It should contain registers @samp{A0} through @samp{A15},
45481 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45482
45483 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45484 contain registers @samp{A16} through @samp{A31} and @samp{B16}
45485 through @samp{B31}.
45486
45487 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45488 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45489
45490 @node Operating System Information
45491 @appendix Operating System Information
45492 @cindex operating system information
45493
45494 @menu
45495 * Process list::
45496 @end menu
45497
45498 Users of @value{GDBN} often wish to obtain information about the state of
45499 the operating system running on the target---for example the list of
45500 processes, or the list of open files. This section describes the
45501 mechanism that makes it possible. This mechanism is similar to the
45502 target features mechanism (@pxref{Target Descriptions}), but focuses
45503 on a different aspect of target.
45504
45505 Operating system information is retrieved from the target via the
45506 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45507 read}). The object name in the request should be @samp{osdata}, and
45508 the @var{annex} identifies the data to be fetched.
45509
45510 @node Process list
45511 @appendixsection Process list
45512 @cindex operating system information, process list
45513
45514 When requesting the process list, the @var{annex} field in the
45515 @samp{qXfer} request should be @samp{processes}. The returned data is
45516 an XML document. The formal syntax of this document is defined in
45517 @file{gdb/features/osdata.dtd}.
45518
45519 An example document is:
45520
45521 @smallexample
45522 <?xml version="1.0"?>
45523 <!DOCTYPE target SYSTEM "osdata.dtd">
45524 <osdata type="processes">
45525 <item>
45526 <column name="pid">1</column>
45527 <column name="user">root</column>
45528 <column name="command">/sbin/init</column>
45529 <column name="cores">1,2,3</column>
45530 </item>
45531 </osdata>
45532 @end smallexample
45533
45534 Each item should include a column whose name is @samp{pid}. The value
45535 of that column should identify the process on the target. The
45536 @samp{user} and @samp{command} columns are optional, and will be
45537 displayed by @value{GDBN}. The @samp{cores} column, if present,
45538 should contain a comma-separated list of cores that this process
45539 is running on. Target may provide additional columns,
45540 which @value{GDBN} currently ignores.
45541
45542 @node Trace File Format
45543 @appendix Trace File Format
45544 @cindex trace file format
45545
45546 The trace file comes in three parts: a header, a textual description
45547 section, and a trace frame section with binary data.
45548
45549 The header has the form @code{\x7fTRACE0\n}. The first byte is
45550 @code{0x7f} so as to indicate that the file contains binary data,
45551 while the @code{0} is a version number that may have different values
45552 in the future.
45553
45554 The description section consists of multiple lines of @sc{ascii} text
45555 separated by newline characters (@code{0xa}). The lines may include a
45556 variety of optional descriptive or context-setting information, such
45557 as tracepoint definitions or register set size. @value{GDBN} will
45558 ignore any line that it does not recognize. An empty line marks the end
45559 of this section.
45560
45561 @table @code
45562 @item R @var{size}
45563 Specifies the size of a register block in bytes. This is equal to the
45564 size of a @code{g} packet payload in the remote protocol. @var{size}
45565 is an ascii decimal number. There should be only one such line in
45566 a single trace file.
45567
45568 @item status @var{status}
45569 Trace status. @var{status} has the same format as a @code{qTStatus}
45570 remote packet reply. There should be only one such line in a single trace
45571 file.
45572
45573 @item tp @var{payload}
45574 Tracepoint definition. The @var{payload} has the same format as
45575 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45576 may take multiple lines of definition, corresponding to the multiple
45577 reply packets.
45578
45579 @item tsv @var{payload}
45580 Trace state variable definition. The @var{payload} has the same format as
45581 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45582 may take multiple lines of definition, corresponding to the multiple
45583 reply packets.
45584
45585 @item tdesc @var{payload}
45586 Target description in XML format. The @var{payload} is a single line of
45587 the XML file. All such lines should be concatenated together to get
45588 the original XML file. This file is in the same format as @code{qXfer}
45589 @code{features} payload, and corresponds to the main @code{target.xml}
45590 file. Includes are not allowed.
45591
45592 @end table
45593
45594 The trace frame section consists of a number of consecutive frames.
45595 Each frame begins with a two-byte tracepoint number, followed by a
45596 four-byte size giving the amount of data in the frame. The data in
45597 the frame consists of a number of blocks, each introduced by a
45598 character indicating its type (at least register, memory, and trace
45599 state variable). The data in this section is raw binary, not a
45600 hexadecimal or other encoding; its endianness matches the target's
45601 endianness.
45602
45603 @c FIXME bi-arch may require endianness/arch info in description section
45604
45605 @table @code
45606 @item R @var{bytes}
45607 Register block. The number and ordering of bytes matches that of a
45608 @code{g} packet in the remote protocol. Note that these are the
45609 actual bytes, in target order, not a hexadecimal encoding.
45610
45611 @item M @var{address} @var{length} @var{bytes}...
45612 Memory block. This is a contiguous block of memory, at the 8-byte
45613 address @var{address}, with a 2-byte length @var{length}, followed by
45614 @var{length} bytes.
45615
45616 @item V @var{number} @var{value}
45617 Trace state variable block. This records the 8-byte signed value
45618 @var{value} of trace state variable numbered @var{number}.
45619
45620 @end table
45621
45622 Future enhancements of the trace file format may include additional types
45623 of blocks.
45624
45625 @node Index Section Format
45626 @appendix @code{.gdb_index} section format
45627 @cindex .gdb_index section format
45628 @cindex index section format
45629
45630 This section documents the index section that is created by @code{save
45631 gdb-index} (@pxref{Index Files}). The index section is
45632 DWARF-specific; some knowledge of DWARF is assumed in this
45633 description.
45634
45635 The mapped index file format is designed to be directly
45636 @code{mmap}able on any architecture. In most cases, a datum is
45637 represented using a little-endian 32-bit integer value, called an
45638 @code{offset_type}. Big endian machines must byte-swap the values
45639 before using them. Exceptions to this rule are noted. The data is
45640 laid out such that alignment is always respected.
45641
45642 A mapped index consists of several areas, laid out in order.
45643
45644 @enumerate
45645 @item
45646 The file header. This is a sequence of values, of @code{offset_type}
45647 unless otherwise noted:
45648
45649 @enumerate
45650 @item
45651 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
45652 Version 4 uses a different hashing function from versions 5 and 6.
45653 Version 6 includes symbols for inlined functions, whereas versions 4
45654 and 5 do not. Version 7 adds attributes to the CU indices in the
45655 symbol table. Version 8 specifies that symbols from DWARF type units
45656 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45657 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45658
45659 @value{GDBN} will only read version 4, 5, or 6 indices
45660 by specifying @code{set use-deprecated-index-sections on}.
45661 GDB has a workaround for potentially broken version 7 indices so it is
45662 currently not flagged as deprecated.
45663
45664 @item
45665 The offset, from the start of the file, of the CU list.
45666
45667 @item
45668 The offset, from the start of the file, of the types CU list. Note
45669 that this area can be empty, in which case this offset will be equal
45670 to the next offset.
45671
45672 @item
45673 The offset, from the start of the file, of the address area.
45674
45675 @item
45676 The offset, from the start of the file, of the symbol table.
45677
45678 @item
45679 The offset, from the start of the file, of the constant pool.
45680 @end enumerate
45681
45682 @item
45683 The CU list. This is a sequence of pairs of 64-bit little-endian
45684 values, sorted by the CU offset. The first element in each pair is
45685 the offset of a CU in the @code{.debug_info} section. The second
45686 element in each pair is the length of that CU. References to a CU
45687 elsewhere in the map are done using a CU index, which is just the
45688 0-based index into this table. Note that if there are type CUs, then
45689 conceptually CUs and type CUs form a single list for the purposes of
45690 CU indices.
45691
45692 @item
45693 The types CU list. This is a sequence of triplets of 64-bit
45694 little-endian values. In a triplet, the first value is the CU offset,
45695 the second value is the type offset in the CU, and the third value is
45696 the type signature. The types CU list is not sorted.
45697
45698 @item
45699 The address area. The address area consists of a sequence of address
45700 entries. Each address entry has three elements:
45701
45702 @enumerate
45703 @item
45704 The low address. This is a 64-bit little-endian value.
45705
45706 @item
45707 The high address. This is a 64-bit little-endian value. Like
45708 @code{DW_AT_high_pc}, the value is one byte beyond the end.
45709
45710 @item
45711 The CU index. This is an @code{offset_type} value.
45712 @end enumerate
45713
45714 @item
45715 The symbol table. This is an open-addressed hash table. The size of
45716 the hash table is always a power of 2.
45717
45718 Each slot in the hash table consists of a pair of @code{offset_type}
45719 values. The first value is the offset of the symbol's name in the
45720 constant pool. The second value is the offset of the CU vector in the
45721 constant pool.
45722
45723 If both values are 0, then this slot in the hash table is empty. This
45724 is ok because while 0 is a valid constant pool index, it cannot be a
45725 valid index for both a string and a CU vector.
45726
45727 The hash value for a table entry is computed by applying an
45728 iterative hash function to the symbol's name. Starting with an
45729 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
45730 the string is incorporated into the hash using the formula depending on the
45731 index version:
45732
45733 @table @asis
45734 @item Version 4
45735 The formula is @code{r = r * 67 + c - 113}.
45736
45737 @item Versions 5 to 7
45738 The formula is @code{r = r * 67 + tolower (c) - 113}.
45739 @end table
45740
45741 The terminating @samp{\0} is not incorporated into the hash.
45742
45743 The step size used in the hash table is computed via
45744 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45745 value, and @samp{size} is the size of the hash table. The step size
45746 is used to find the next candidate slot when handling a hash
45747 collision.
45748
45749 The names of C@t{++} symbols in the hash table are canonicalized. We
45750 don't currently have a simple description of the canonicalization
45751 algorithm; if you intend to create new index sections, you must read
45752 the code.
45753
45754 @item
45755 The constant pool. This is simply a bunch of bytes. It is organized
45756 so that alignment is correct: CU vectors are stored first, followed by
45757 strings.
45758
45759 A CU vector in the constant pool is a sequence of @code{offset_type}
45760 values. The first value is the number of CU indices in the vector.
45761 Each subsequent value is the index and symbol attributes of a CU in
45762 the CU list. This element in the hash table is used to indicate which
45763 CUs define the symbol and how the symbol is used.
45764 See below for the format of each CU index+attributes entry.
45765
45766 A string in the constant pool is zero-terminated.
45767 @end enumerate
45768
45769 Attributes were added to CU index values in @code{.gdb_index} version 7.
45770 If a symbol has multiple uses within a CU then there is one
45771 CU index+attributes value for each use.
45772
45773 The format of each CU index+attributes entry is as follows
45774 (bit 0 = LSB):
45775
45776 @table @asis
45777
45778 @item Bits 0-23
45779 This is the index of the CU in the CU list.
45780 @item Bits 24-27
45781 These bits are reserved for future purposes and must be zero.
45782 @item Bits 28-30
45783 The kind of the symbol in the CU.
45784
45785 @table @asis
45786 @item 0
45787 This value is reserved and should not be used.
45788 By reserving zero the full @code{offset_type} value is backwards compatible
45789 with previous versions of the index.
45790 @item 1
45791 The symbol is a type.
45792 @item 2
45793 The symbol is a variable or an enum value.
45794 @item 3
45795 The symbol is a function.
45796 @item 4
45797 Any other kind of symbol.
45798 @item 5,6,7
45799 These values are reserved.
45800 @end table
45801
45802 @item Bit 31
45803 This bit is zero if the value is global and one if it is static.
45804
45805 The determination of whether a symbol is global or static is complicated.
45806 The authorative reference is the file @file{dwarf2read.c} in
45807 @value{GDBN} sources.
45808
45809 @end table
45810
45811 This pseudo-code describes the computation of a symbol's kind and
45812 global/static attributes in the index.
45813
45814 @smallexample
45815 is_external = get_attribute (die, DW_AT_external);
45816 language = get_attribute (cu_die, DW_AT_language);
45817 switch (die->tag)
45818 @{
45819 case DW_TAG_typedef:
45820 case DW_TAG_base_type:
45821 case DW_TAG_subrange_type:
45822 kind = TYPE;
45823 is_static = 1;
45824 break;
45825 case DW_TAG_enumerator:
45826 kind = VARIABLE;
45827 is_static = language != CPLUS;
45828 break;
45829 case DW_TAG_subprogram:
45830 kind = FUNCTION;
45831 is_static = ! (is_external || language == ADA);
45832 break;
45833 case DW_TAG_constant:
45834 kind = VARIABLE;
45835 is_static = ! is_external;
45836 break;
45837 case DW_TAG_variable:
45838 kind = VARIABLE;
45839 is_static = ! is_external;
45840 break;
45841 case DW_TAG_namespace:
45842 kind = TYPE;
45843 is_static = 0;
45844 break;
45845 case DW_TAG_class_type:
45846 case DW_TAG_interface_type:
45847 case DW_TAG_structure_type:
45848 case DW_TAG_union_type:
45849 case DW_TAG_enumeration_type:
45850 kind = TYPE;
45851 is_static = language != CPLUS;
45852 break;
45853 default:
45854 assert (0);
45855 @}
45856 @end smallexample
45857
45858 @node Man Pages
45859 @appendix Manual pages
45860 @cindex Man pages
45861
45862 @menu
45863 * gdb man:: The GNU Debugger man page
45864 * gdbserver man:: Remote Server for the GNU Debugger man page
45865 * gcore man:: Generate a core file of a running program
45866 * gdbinit man:: gdbinit scripts
45867 * gdb-add-index man:: Add index files to speed up GDB
45868 @end menu
45869
45870 @node gdb man
45871 @heading gdb man
45872
45873 @c man title gdb The GNU Debugger
45874
45875 @c man begin SYNOPSIS gdb
45876 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
45877 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
45878 [@option{-b}@w{ }@var{bps}]
45879 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
45880 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
45881 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
45882 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
45883 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
45884 @c man end
45885
45886 @c man begin DESCRIPTION gdb
45887 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
45888 going on ``inside'' another program while it executes -- or what another
45889 program was doing at the moment it crashed.
45890
45891 @value{GDBN} can do four main kinds of things (plus other things in support of
45892 these) to help you catch bugs in the act:
45893
45894 @itemize @bullet
45895 @item
45896 Start your program, specifying anything that might affect its behavior.
45897
45898 @item
45899 Make your program stop on specified conditions.
45900
45901 @item
45902 Examine what has happened, when your program has stopped.
45903
45904 @item
45905 Change things in your program, so you can experiment with correcting the
45906 effects of one bug and go on to learn about another.
45907 @end itemize
45908
45909 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
45910 Modula-2.
45911
45912 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
45913 commands from the terminal until you tell it to exit with the @value{GDBN}
45914 command @code{quit}. You can get online help from @value{GDBN} itself
45915 by using the command @code{help}.
45916
45917 You can run @code{gdb} with no arguments or options; but the most
45918 usual way to start @value{GDBN} is with one argument or two, specifying an
45919 executable program as the argument:
45920
45921 @smallexample
45922 gdb program
45923 @end smallexample
45924
45925 You can also start with both an executable program and a core file specified:
45926
45927 @smallexample
45928 gdb program core
45929 @end smallexample
45930
45931 You can, instead, specify a process ID as a second argument or use option
45932 @code{-p}, if you want to debug a running process:
45933
45934 @smallexample
45935 gdb program 1234
45936 gdb -p 1234
45937 @end smallexample
45938
45939 @noindent
45940 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
45941 can omit the @var{program} filename.
45942
45943 Here are some of the most frequently needed @value{GDBN} commands:
45944
45945 @c pod2man highlights the right hand side of the @item lines.
45946 @table @env
45947 @item break [@var{file}:]@var{function}
45948 Set a breakpoint at @var{function} (in @var{file}).
45949
45950 @item run [@var{arglist}]
45951 Start your program (with @var{arglist}, if specified).
45952
45953 @item bt
45954 Backtrace: display the program stack.
45955
45956 @item print @var{expr}
45957 Display the value of an expression.
45958
45959 @item c
45960 Continue running your program (after stopping, e.g. at a breakpoint).
45961
45962 @item next
45963 Execute next program line (after stopping); step @emph{over} any
45964 function calls in the line.
45965
45966 @item edit [@var{file}:]@var{function}
45967 look at the program line where it is presently stopped.
45968
45969 @item list [@var{file}:]@var{function}
45970 type the text of the program in the vicinity of where it is presently stopped.
45971
45972 @item step
45973 Execute next program line (after stopping); step @emph{into} any
45974 function calls in the line.
45975
45976 @item help [@var{name}]
45977 Show information about @value{GDBN} command @var{name}, or general information
45978 about using @value{GDBN}.
45979
45980 @item quit
45981 Exit from @value{GDBN}.
45982 @end table
45983
45984 @ifset man
45985 For full details on @value{GDBN},
45986 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
45987 by Richard M. Stallman and Roland H. Pesch. The same text is available online
45988 as the @code{gdb} entry in the @code{info} program.
45989 @end ifset
45990 @c man end
45991
45992 @c man begin OPTIONS gdb
45993 Any arguments other than options specify an executable
45994 file and core file (or process ID); that is, the first argument
45995 encountered with no
45996 associated option flag is equivalent to a @option{-se} option, and the second,
45997 if any, is equivalent to a @option{-c} option if it's the name of a file.
45998 Many options have
45999 both long and short forms; both are shown here. The long forms are also
46000 recognized if you truncate them, so long as enough of the option is
46001 present to be unambiguous. (If you prefer, you can flag option
46002 arguments with @option{+} rather than @option{-}, though we illustrate the
46003 more usual convention.)
46004
46005 All the options and command line arguments you give are processed
46006 in sequential order. The order makes a difference when the @option{-x}
46007 option is used.
46008
46009 @table @env
46010 @item -help
46011 @itemx -h
46012 List all options, with brief explanations.
46013
46014 @item -symbols=@var{file}
46015 @itemx -s @var{file}
46016 Read symbol table from file @var{file}.
46017
46018 @item -write
46019 Enable writing into executable and core files.
46020
46021 @item -exec=@var{file}
46022 @itemx -e @var{file}
46023 Use file @var{file} as the executable file to execute when
46024 appropriate, and for examining pure data in conjunction with a core
46025 dump.
46026
46027 @item -se=@var{file}
46028 Read symbol table from file @var{file} and use it as the executable
46029 file.
46030
46031 @item -core=@var{file}
46032 @itemx -c @var{file}
46033 Use file @var{file} as a core dump to examine.
46034
46035 @item -command=@var{file}
46036 @itemx -x @var{file}
46037 Execute @value{GDBN} commands from file @var{file}.
46038
46039 @item -ex @var{command}
46040 Execute given @value{GDBN} @var{command}.
46041
46042 @item -directory=@var{directory}
46043 @itemx -d @var{directory}
46044 Add @var{directory} to the path to search for source files.
46045
46046 @item -nh
46047 Do not execute commands from @file{~/.gdbinit}.
46048
46049 @item -nx
46050 @itemx -n
46051 Do not execute commands from any @file{.gdbinit} initialization files.
46052
46053 @item -quiet
46054 @itemx -q
46055 ``Quiet''. Do not print the introductory and copyright messages. These
46056 messages are also suppressed in batch mode.
46057
46058 @item -batch
46059 Run in batch mode. Exit with status @code{0} after processing all the command
46060 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46061 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46062 commands in the command files.
46063
46064 Batch mode may be useful for running @value{GDBN} as a filter, for example to
46065 download and run a program on another computer; in order to make this
46066 more useful, the message
46067
46068 @smallexample
46069 Program exited normally.
46070 @end smallexample
46071
46072 @noindent
46073 (which is ordinarily issued whenever a program running under @value{GDBN} control
46074 terminates) is not issued when running in batch mode.
46075
46076 @item -cd=@var{directory}
46077 Run @value{GDBN} using @var{directory} as its working directory,
46078 instead of the current directory.
46079
46080 @item -fullname
46081 @itemx -f
46082 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46083 @value{GDBN} to output the full file name and line number in a standard,
46084 recognizable fashion each time a stack frame is displayed (which
46085 includes each time the program stops). This recognizable format looks
46086 like two @samp{\032} characters, followed by the file name, line number
46087 and character position separated by colons, and a newline. The
46088 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46089 characters as a signal to display the source code for the frame.
46090
46091 @item -b @var{bps}
46092 Set the line speed (baud rate or bits per second) of any serial
46093 interface used by @value{GDBN} for remote debugging.
46094
46095 @item -tty=@var{device}
46096 Run using @var{device} for your program's standard input and output.
46097 @end table
46098 @c man end
46099
46100 @c man begin SEEALSO gdb
46101 @ifset man
46102 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46103 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46104 documentation are properly installed at your site, the command
46105
46106 @smallexample
46107 info gdb
46108 @end smallexample
46109
46110 @noindent
46111 should give you access to the complete manual.
46112
46113 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46114 Richard M. Stallman and Roland H. Pesch, July 1991.
46115 @end ifset
46116 @c man end
46117
46118 @node gdbserver man
46119 @heading gdbserver man
46120
46121 @c man title gdbserver Remote Server for the GNU Debugger
46122 @format
46123 @c man begin SYNOPSIS gdbserver
46124 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46125
46126 gdbserver --attach @var{comm} @var{pid}
46127
46128 gdbserver --multi @var{comm}
46129 @c man end
46130 @end format
46131
46132 @c man begin DESCRIPTION gdbserver
46133 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46134 than the one which is running the program being debugged.
46135
46136 @ifclear man
46137 @subheading Usage (server (target) side)
46138 @end ifclear
46139 @ifset man
46140 Usage (server (target) side):
46141 @end ifset
46142
46143 First, you need to have a copy of the program you want to debug put onto
46144 the target system. The program can be stripped to save space if needed, as
46145 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46146 the @value{GDBN} running on the host system.
46147
46148 To use the server, you log on to the target system, and run the @command{gdbserver}
46149 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46150 your program, and (c) its arguments. The general syntax is:
46151
46152 @smallexample
46153 target> gdbserver @var{comm} @var{program} [@var{args} ...]
46154 @end smallexample
46155
46156 For example, using a serial port, you might say:
46157
46158 @smallexample
46159 @ifset man
46160 @c @file would wrap it as F</dev/com1>.
46161 target> gdbserver /dev/com1 emacs foo.txt
46162 @end ifset
46163 @ifclear man
46164 target> gdbserver @file{/dev/com1} emacs foo.txt
46165 @end ifclear
46166 @end smallexample
46167
46168 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46169 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46170 waits patiently for the host @value{GDBN} to communicate with it.
46171
46172 To use a TCP connection, you could say:
46173
46174 @smallexample
46175 target> gdbserver host:2345 emacs foo.txt
46176 @end smallexample
46177
46178 This says pretty much the same thing as the last example, except that we are
46179 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46180 that we are expecting to see a TCP connection from @code{host} to local TCP port
46181 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
46182 want for the port number as long as it does not conflict with any existing TCP
46183 ports on the target system. This same port number must be used in the host
46184 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46185 you chose a port number that conflicts with another service, @command{gdbserver} will
46186 print an error message and exit.
46187
46188 @command{gdbserver} can also attach to running programs.
46189 This is accomplished via the @option{--attach} argument. The syntax is:
46190
46191 @smallexample
46192 target> gdbserver --attach @var{comm} @var{pid}
46193 @end smallexample
46194
46195 @var{pid} is the process ID of a currently running process. It isn't
46196 necessary to point @command{gdbserver} at a binary for the running process.
46197
46198 To start @code{gdbserver} without supplying an initial command to run
46199 or process ID to attach, use the @option{--multi} command line option.
46200 In such case you should connect using @kbd{target extended-remote} to start
46201 the program you want to debug.
46202
46203 @smallexample
46204 target> gdbserver --multi @var{comm}
46205 @end smallexample
46206
46207 @ifclear man
46208 @subheading Usage (host side)
46209 @end ifclear
46210 @ifset man
46211 Usage (host side):
46212 @end ifset
46213
46214 You need an unstripped copy of the target program on your host system, since
46215 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
46216 would, with the target program as the first argument. (You may need to use the
46217 @option{--baud} option if the serial line is running at anything except 9600 baud.)
46218 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
46219 new command you need to know about is @code{target remote}
46220 (or @code{target extended-remote}). Its argument is either
46221 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46222 descriptor. For example:
46223
46224 @smallexample
46225 @ifset man
46226 @c @file would wrap it as F</dev/ttyb>.
46227 (gdb) target remote /dev/ttyb
46228 @end ifset
46229 @ifclear man
46230 (gdb) target remote @file{/dev/ttyb}
46231 @end ifclear
46232 @end smallexample
46233
46234 @noindent
46235 communicates with the server via serial line @file{/dev/ttyb}, and:
46236
46237 @smallexample
46238 (gdb) target remote the-target:2345
46239 @end smallexample
46240
46241 @noindent
46242 communicates via a TCP connection to port 2345 on host `the-target', where
46243 you previously started up @command{gdbserver} with the same port number. Note that for
46244 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46245 command, otherwise you may get an error that looks something like
46246 `Connection refused'.
46247
46248 @command{gdbserver} can also debug multiple inferiors at once,
46249 described in
46250 @ifset man
46251 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46252 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
46253 @end ifset
46254 @ifclear man
46255 @ref{Inferiors Connections and Programs}.
46256 @end ifclear
46257 In such case use the @code{extended-remote} @value{GDBN} command variant:
46258
46259 @smallexample
46260 (gdb) target extended-remote the-target:2345
46261 @end smallexample
46262
46263 The @command{gdbserver} option @option{--multi} may or may not be used in such
46264 case.
46265 @c man end
46266
46267 @c man begin OPTIONS gdbserver
46268 There are three different modes for invoking @command{gdbserver}:
46269
46270 @itemize @bullet
46271
46272 @item
46273 Debug a specific program specified by its program name:
46274
46275 @smallexample
46276 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46277 @end smallexample
46278
46279 The @var{comm} parameter specifies how should the server communicate
46280 with @value{GDBN}; it is either a device name (to use a serial line),
46281 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46282 stdin/stdout of @code{gdbserver}. Specify the name of the program to
46283 debug in @var{prog}. Any remaining arguments will be passed to the
46284 program verbatim. When the program exits, @value{GDBN} will close the
46285 connection, and @code{gdbserver} will exit.
46286
46287 @item
46288 Debug a specific program by specifying the process ID of a running
46289 program:
46290
46291 @smallexample
46292 gdbserver --attach @var{comm} @var{pid}
46293 @end smallexample
46294
46295 The @var{comm} parameter is as described above. Supply the process ID
46296 of a running program in @var{pid}; @value{GDBN} will do everything
46297 else. Like with the previous mode, when the process @var{pid} exits,
46298 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
46299
46300 @item
46301 Multi-process mode -- debug more than one program/process:
46302
46303 @smallexample
46304 gdbserver --multi @var{comm}
46305 @end smallexample
46306
46307 In this mode, @value{GDBN} can instruct @command{gdbserver} which
46308 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46309 close the connection when a process being debugged exits, so you can
46310 debug several processes in the same session.
46311 @end itemize
46312
46313 In each of the modes you may specify these options:
46314
46315 @table @env
46316
46317 @item --help
46318 List all options, with brief explanations.
46319
46320 @item --version
46321 This option causes @command{gdbserver} to print its version number and exit.
46322
46323 @item --attach
46324 @command{gdbserver} will attach to a running program. The syntax is:
46325
46326 @smallexample
46327 target> gdbserver --attach @var{comm} @var{pid}
46328 @end smallexample
46329
46330 @var{pid} is the process ID of a currently running process. It isn't
46331 necessary to point @command{gdbserver} at a binary for the running process.
46332
46333 @item --multi
46334 To start @code{gdbserver} without supplying an initial command to run
46335 or process ID to attach, use this command line option.
46336 Then you can connect using @kbd{target extended-remote} and start
46337 the program you want to debug. The syntax is:
46338
46339 @smallexample
46340 target> gdbserver --multi @var{comm}
46341 @end smallexample
46342
46343 @item --debug
46344 Instruct @code{gdbserver} to display extra status information about the debugging
46345 process.
46346 This option is intended for @code{gdbserver} development and for bug reports to
46347 the developers.
46348
46349 @item --remote-debug
46350 Instruct @code{gdbserver} to display remote protocol debug output.
46351 This option is intended for @code{gdbserver} development and for bug reports to
46352 the developers.
46353
46354 @item --debug-file=@var{filename}
46355 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46356 This option is intended for @code{gdbserver} development and for bug reports to
46357 the developers.
46358
46359 @item --debug-format=option1@r{[},option2,...@r{]}
46360 Instruct @code{gdbserver} to include extra information in each line
46361 of debugging output.
46362 @xref{Other Command-Line Arguments for gdbserver}.
46363
46364 @item --wrapper
46365 Specify a wrapper to launch programs
46366 for debugging. The option should be followed by the name of the
46367 wrapper, then any command-line arguments to pass to the wrapper, then
46368 @kbd{--} indicating the end of the wrapper arguments.
46369
46370 @item --once
46371 By default, @command{gdbserver} keeps the listening TCP port open, so that
46372 additional connections are possible. However, if you start @code{gdbserver}
46373 with the @option{--once} option, it will stop listening for any further
46374 connection attempts after connecting to the first @value{GDBN} session.
46375
46376 @c --disable-packet is not documented for users.
46377
46378 @c --disable-randomization and --no-disable-randomization are superseded by
46379 @c QDisableRandomization.
46380
46381 @end table
46382 @c man end
46383
46384 @c man begin SEEALSO gdbserver
46385 @ifset man
46386 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46387 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46388 documentation are properly installed at your site, the command
46389
46390 @smallexample
46391 info gdb
46392 @end smallexample
46393
46394 should give you access to the complete manual.
46395
46396 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46397 Richard M. Stallman and Roland H. Pesch, July 1991.
46398 @end ifset
46399 @c man end
46400
46401 @node gcore man
46402 @heading gcore
46403
46404 @c man title gcore Generate a core file of a running program
46405
46406 @format
46407 @c man begin SYNOPSIS gcore
46408 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
46409 @c man end
46410 @end format
46411
46412 @c man begin DESCRIPTION gcore
46413 Generate core dumps of one or more running programs with process IDs
46414 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46415 is equivalent to one produced by the kernel when the process crashes
46416 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
46417 limit). However, unlike after a crash, after @command{gcore} finishes
46418 its job the program remains running without any change.
46419 @c man end
46420
46421 @c man begin OPTIONS gcore
46422 @table @env
46423 @item -a
46424 Dump all memory mappings. The actual effect of this option depends on
46425 the Operating System. On @sc{gnu}/Linux, it will disable
46426 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46427 enable @code{dump-excluded-mappings} (@pxref{set
46428 dump-excluded-mappings}).
46429
46430 @item -o @var{prefix}
46431 The optional argument @var{prefix} specifies the prefix to be used
46432 when composing the file names of the core dumps. The file name is
46433 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46434 process ID of the running program being analyzed by @command{gcore}.
46435 If not specified, @var{prefix} defaults to @var{gcore}.
46436 @end table
46437 @c man end
46438
46439 @c man begin SEEALSO gcore
46440 @ifset man
46441 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46442 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46443 documentation are properly installed at your site, the command
46444
46445 @smallexample
46446 info gdb
46447 @end smallexample
46448
46449 @noindent
46450 should give you access to the complete manual.
46451
46452 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46453 Richard M. Stallman and Roland H. Pesch, July 1991.
46454 @end ifset
46455 @c man end
46456
46457 @node gdbinit man
46458 @heading gdbinit
46459
46460 @c man title gdbinit GDB initialization scripts
46461
46462 @format
46463 @c man begin SYNOPSIS gdbinit
46464 @ifset SYSTEM_GDBINIT
46465 @value{SYSTEM_GDBINIT}
46466 @end ifset
46467
46468 @ifset SYSTEM_GDBINIT_DIR
46469 @value{SYSTEM_GDBINIT_DIR}/*
46470 @end ifset
46471
46472 ~/.gdbinit
46473
46474 ./.gdbinit
46475 @c man end
46476 @end format
46477
46478 @c man begin DESCRIPTION gdbinit
46479 These files contain @value{GDBN} commands to automatically execute during
46480 @value{GDBN} startup. The lines of contents are canned sequences of commands,
46481 described in
46482 @ifset man
46483 the @value{GDBN} manual in node @code{Sequences}
46484 -- shell command @code{info -f gdb -n Sequences}.
46485 @end ifset
46486 @ifclear man
46487 @ref{Sequences}.
46488 @end ifclear
46489
46490 Please read more in
46491 @ifset man
46492 the @value{GDBN} manual in node @code{Startup}
46493 -- shell command @code{info -f gdb -n Startup}.
46494 @end ifset
46495 @ifclear man
46496 @ref{Startup}.
46497 @end ifclear
46498
46499 @table @env
46500 @ifset SYSTEM_GDBINIT
46501 @item @value{SYSTEM_GDBINIT}
46502 @end ifset
46503 @ifclear SYSTEM_GDBINIT
46504 @item (not enabled with @code{--with-system-gdbinit} during compilation)
46505 @end ifclear
46506 System-wide initialization file. It is executed unless user specified
46507 @value{GDBN} option @code{-nx} or @code{-n}.
46508 See more in
46509 @ifset man
46510 the @value{GDBN} manual in node @code{System-wide configuration}
46511 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46512 @end ifset
46513 @ifset SYSTEM_GDBINIT_DIR
46514 @item @value{SYSTEM_GDBINIT_DIR}
46515 @end ifset
46516 @ifclear SYSTEM_GDBINIT_DIR
46517 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46518 @end ifclear
46519 System-wide initialization directory. All files in this directory are
46520 executed on startup unless user specified @value{GDBN} option @code{-nx} or
46521 @code{-n}, as long as they have a recognized file extension.
46522 See more in
46523 @ifset man
46524 the @value{GDBN} manual in node @code{System-wide configuration}
46525 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46526 @end ifset
46527 @ifclear man
46528 @ref{System-wide configuration}.
46529 @end ifclear
46530
46531 @item ~/.gdbinit
46532 User initialization file. It is executed unless user specified
46533 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46534
46535 @item ./.gdbinit
46536 Initialization file for current directory. It may need to be enabled with
46537 @value{GDBN} security command @code{set auto-load local-gdbinit}.
46538 See more in
46539 @ifset man
46540 the @value{GDBN} manual in node @code{Init File in the Current Directory}
46541 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46542 @end ifset
46543 @ifclear man
46544 @ref{Init File in the Current Directory}.
46545 @end ifclear
46546 @end table
46547 @c man end
46548
46549 @c man begin SEEALSO gdbinit
46550 @ifset man
46551 gdb(1), @code{info -f gdb -n Startup}
46552
46553 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46554 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46555 documentation are properly installed at your site, the command
46556
46557 @smallexample
46558 info gdb
46559 @end smallexample
46560
46561 should give you access to the complete manual.
46562
46563 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46564 Richard M. Stallman and Roland H. Pesch, July 1991.
46565 @end ifset
46566 @c man end
46567
46568 @node gdb-add-index man
46569 @heading gdb-add-index
46570 @pindex gdb-add-index
46571 @anchor{gdb-add-index}
46572
46573 @c man title gdb-add-index Add index files to speed up GDB
46574
46575 @c man begin SYNOPSIS gdb-add-index
46576 gdb-add-index @var{filename}
46577 @c man end
46578
46579 @c man begin DESCRIPTION gdb-add-index
46580 When @value{GDBN} finds a symbol file, it scans the symbols in the
46581 file in order to construct an internal symbol table. This lets most
46582 @value{GDBN} operations work quickly--at the cost of a delay early on.
46583 For large programs, this delay can be quite lengthy, so @value{GDBN}
46584 provides a way to build an index, which speeds up startup.
46585
46586 To determine whether a file contains such an index, use the command
46587 @kbd{readelf -S filename}: the index is stored in a section named
46588 @code{.gdb_index}. The index file can only be produced on systems
46589 which use ELF binaries and DWARF debug information (i.e., sections
46590 named @code{.debug_*}).
46591
46592 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46593 in the @env{PATH} environment variable. If you want to use different
46594 versions of these programs, you can specify them through the
46595 @env{GDB} and @env{OBJDUMP} environment variables.
46596
46597 See more in
46598 @ifset man
46599 the @value{GDBN} manual in node @code{Index Files}
46600 -- shell command @kbd{info -f gdb -n "Index Files"}.
46601 @end ifset
46602 @ifclear man
46603 @ref{Index Files}.
46604 @end ifclear
46605 @c man end
46606
46607 @c man begin SEEALSO gdb-add-index
46608 @ifset man
46609 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46610 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46611 documentation are properly installed at your site, the command
46612
46613 @smallexample
46614 info gdb
46615 @end smallexample
46616
46617 should give you access to the complete manual.
46618
46619 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46620 Richard M. Stallman and Roland H. Pesch, July 1991.
46621 @end ifset
46622 @c man end
46623
46624 @include gpl.texi
46625
46626 @node GNU Free Documentation License
46627 @appendix GNU Free Documentation License
46628 @include fdl.texi
46629
46630 @node Concept Index
46631 @unnumbered Concept Index
46632
46633 @printindex cp
46634
46635 @node Command and Variable Index
46636 @unnumbered Command, Variable, and Function Index
46637
46638 @printindex fn
46639
46640 @tex
46641 % I think something like @@colophon should be in texinfo. In the
46642 % meantime:
46643 \long\def\colophon{\hbox to0pt{}\vfill
46644 \centerline{The body of this manual is set in}
46645 \centerline{\fontname\tenrm,}
46646 \centerline{with headings in {\bf\fontname\tenbf}}
46647 \centerline{and examples in {\tt\fontname\tentt}.}
46648 \centerline{{\it\fontname\tenit\/},}
46649 \centerline{{\bf\fontname\tenbf}, and}
46650 \centerline{{\sl\fontname\tensl\/}}
46651 \centerline{are used for emphasis.}\vfill}
46652 \page\colophon
46653 % Blame: doc@@cygnus.com, 1991.
46654 @end tex
46655
46656 @bye
This page took 1.034833 seconds and 4 git commands to generate.