7f8c77a77f22ea6cce6f4eadae0eeb15edd0128f
[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
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 * Command aliases default args:: Automatically prepend default arguments to user-defined aliases
1581 * Help:: How to ask @value{GDBN} for help
1582 @end menu
1583
1584 @node Command Syntax
1585 @section Command Syntax
1586
1587 A @value{GDBN} command is a single line of input. There is no limit on
1588 how long it can be. It starts with a command name, which is followed by
1589 arguments whose meaning depends on the command name. For example, the
1590 command @code{step} accepts an argument which is the number of times to
1591 step, as in @samp{step 5}. You can also use the @code{step} command
1592 with no arguments. Some commands do not allow any arguments.
1593
1594 @cindex abbreviation
1595 @value{GDBN} command names may always be truncated if that abbreviation is
1596 unambiguous. Other possible command abbreviations are listed in the
1597 documentation for individual commands. In some cases, even ambiguous
1598 abbreviations are allowed; for example, @code{s} is specially defined as
1599 equivalent to @code{step} even though there are other commands whose
1600 names start with @code{s}. You can test abbreviations by using them as
1601 arguments to the @code{help} command.
1602
1603 @cindex repeating commands
1604 @kindex RET @r{(repeat last command)}
1605 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1606 repeat the previous command. Certain commands (for example, @code{run})
1607 will not repeat this way; these are commands whose unintentional
1608 repetition might cause trouble and which you are unlikely to want to
1609 repeat. User-defined commands can disable this feature; see
1610 @ref{Define, dont-repeat}.
1611
1612 The @code{list} and @code{x} commands, when you repeat them with
1613 @key{RET}, construct new arguments rather than repeating
1614 exactly as typed. This permits easy scanning of source or memory.
1615
1616 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1617 output, in a way similar to the common utility @code{more}
1618 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1619 @key{RET} too many in this situation, @value{GDBN} disables command
1620 repetition after any command that generates this sort of display.
1621
1622 @kindex # @r{(a comment)}
1623 @cindex comment
1624 Any text from a @kbd{#} to the end of the line is a comment; it does
1625 nothing. This is useful mainly in command files (@pxref{Command
1626 Files,,Command Files}).
1627
1628 @cindex repeating command sequences
1629 @kindex Ctrl-o @r{(operate-and-get-next)}
1630 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1631 commands. This command accepts the current line, like @key{RET}, and
1632 then fetches the next line relative to the current line from the history
1633 for editing.
1634
1635
1636 @node Command Settings
1637 @section Command Settings
1638 @cindex default behavior of commands, changing
1639 @cindex default settings, changing
1640
1641 Many commands change their behavior according to command-specific
1642 variables or settings. These settings can be changed with the
1643 @code{set} subcommands. For example, the @code{print} command
1644 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1645 settings changeable with the commands @code{set print elements
1646 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1647
1648 You can change these settings to your preference in the gdbinit files
1649 loaded at @value{GDBN} startup. @xref{Startup}.
1650
1651 The settings can also be changed interactively during the debugging
1652 session. For example, to change the limit of array elements to print,
1653 you can do the following:
1654 @smallexample
1655 (@value{GDBN}) set print elements 10
1656 (@value{GDBN}) print some_array
1657 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1658 @end smallexample
1659
1660 The above @code{set print elements 10} command changes the number of
1661 elements to print from the default of 200 to 10. If you only intend
1662 this limit of 10 to be used for printing @code{some_array}, then you
1663 must restore the limit back to 200, with @code{set print elements
1664 200}.
1665
1666 Some commands allow overriding settings with command options. For
1667 example, the @code{print} command supports a number of options that
1668 allow overriding relevant global print settings as set by @code{set
1669 print} subcommands. @xref{print options}. The example above could be
1670 rewritten as:
1671 @smallexample
1672 (@value{GDBN}) print -elements 10 -- some_array
1673 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1674 @end smallexample
1675
1676 Alternatively, you can use the @code{with} command to change a setting
1677 temporarily, for the duration of a command invocation.
1678
1679 @table @code
1680 @kindex with command
1681 @kindex w @r{(@code{with})}
1682 @cindex settings
1683 @cindex temporarily change settings
1684 @item with @var{setting} [@var{value}] [-- @var{command}]
1685 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1686 Temporarily set @var{setting} to @var{value} for the duration of
1687 @var{command}.
1688
1689 @var{setting} is any setting you can change with the @code{set}
1690 subcommands. @var{value} is the value to assign to @code{setting}
1691 while running @code{command}.
1692
1693 If no @var{command} is provided, the last command executed is
1694 repeated.
1695
1696 If a @var{command} is provided, it must be preceded by a double dash
1697 (@code{--}) separator. This is required because some settings accept
1698 free-form arguments, such as expressions or filenames.
1699
1700 For example, the command
1701 @smallexample
1702 (@value{GDBN}) with print array on -- print some_array
1703 @end smallexample
1704 @noindent
1705 is equivalent to the following 3 commands:
1706 @smallexample
1707 (@value{GDBN}) set print array on
1708 (@value{GDBN}) print some_array
1709 (@value{GDBN}) set print array off
1710 @end smallexample
1711
1712 The @code{with} command is particularly useful when you want to
1713 override a setting while running user-defined commands, or commands
1714 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1715
1716 @smallexample
1717 (@value{GDBN}) with print pretty on -- my_complex_command
1718 @end smallexample
1719
1720 To change several settings for the same command, you can nest
1721 @code{with} commands. For example, @code{with language ada -- with
1722 print elements 10} temporarily changes the language to Ada and sets a
1723 limit of 10 elements to print for arrays and strings.
1724
1725 @end table
1726
1727 @node Completion
1728 @section Command Completion
1729
1730 @cindex completion
1731 @cindex word completion
1732 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1733 only one possibility; it can also show you what the valid possibilities
1734 are for the next word in a command, at any time. This works for @value{GDBN}
1735 commands, @value{GDBN} subcommands, command options, and the names of symbols
1736 in your program.
1737
1738 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1739 of a word. If there is only one possibility, @value{GDBN} fills in the
1740 word, and waits for you to finish the command (or press @key{RET} to
1741 enter it). For example, if you type
1742
1743 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1744 @c complete accuracy in these examples; space introduced for clarity.
1745 @c If texinfo enhancements make it unnecessary, it would be nice to
1746 @c replace " @key" by "@key" in the following...
1747 @smallexample
1748 (@value{GDBP}) info bre @key{TAB}
1749 @end smallexample
1750
1751 @noindent
1752 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1753 the only @code{info} subcommand beginning with @samp{bre}:
1754
1755 @smallexample
1756 (@value{GDBP}) info breakpoints
1757 @end smallexample
1758
1759 @noindent
1760 You can either press @key{RET} at this point, to run the @code{info
1761 breakpoints} command, or backspace and enter something else, if
1762 @samp{breakpoints} does not look like the command you expected. (If you
1763 were sure you wanted @code{info breakpoints} in the first place, you
1764 might as well just type @key{RET} immediately after @samp{info bre},
1765 to exploit command abbreviations rather than command completion).
1766
1767 If there is more than one possibility for the next word when you press
1768 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1769 characters and try again, or just press @key{TAB} a second time;
1770 @value{GDBN} displays all the possible completions for that word. For
1771 example, you might want to set a breakpoint on a subroutine whose name
1772 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1773 just sounds the bell. Typing @key{TAB} again displays all the
1774 function names in your program that begin with those characters, for
1775 example:
1776
1777 @smallexample
1778 (@value{GDBP}) b make_ @key{TAB}
1779 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1780 make_a_section_from_file make_environ
1781 make_abs_section make_function_type
1782 make_blockvector make_pointer_type
1783 make_cleanup make_reference_type
1784 make_command make_symbol_completion_list
1785 (@value{GDBP}) b make_
1786 @end smallexample
1787
1788 @noindent
1789 After displaying the available possibilities, @value{GDBN} copies your
1790 partial input (@samp{b make_} in the example) so you can finish the
1791 command.
1792
1793 If you just want to see the list of alternatives in the first place, you
1794 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1795 means @kbd{@key{META} ?}. You can type this either by holding down a
1796 key designated as the @key{META} shift on your keyboard (if there is
1797 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1798
1799 If the number of possible completions is large, @value{GDBN} will
1800 print as much of the list as it has collected, as well as a message
1801 indicating that the list may be truncated.
1802
1803 @smallexample
1804 (@value{GDBP}) b m@key{TAB}@key{TAB}
1805 main
1806 <... the rest of the possible completions ...>
1807 *** List may be truncated, max-completions reached. ***
1808 (@value{GDBP}) b m
1809 @end smallexample
1810
1811 @noindent
1812 This behavior can be controlled with the following commands:
1813
1814 @table @code
1815 @kindex set max-completions
1816 @item set max-completions @var{limit}
1817 @itemx set max-completions unlimited
1818 Set the maximum number of completion candidates. @value{GDBN} will
1819 stop looking for more completions once it collects this many candidates.
1820 This is useful when completing on things like function names as collecting
1821 all the possible candidates can be time consuming.
1822 The default value is 200. A value of zero disables tab-completion.
1823 Note that setting either no limit or a very large limit can make
1824 completion slow.
1825 @kindex show max-completions
1826 @item show max-completions
1827 Show the maximum number of candidates that @value{GDBN} will collect and show
1828 during completion.
1829 @end table
1830
1831 @cindex quotes in commands
1832 @cindex completion of quoted strings
1833 Sometimes the string you need, while logically a ``word'', may contain
1834 parentheses or other characters that @value{GDBN} normally excludes from
1835 its notion of a word. To permit word completion to work in this
1836 situation, you may enclose words in @code{'} (single quote marks) in
1837 @value{GDBN} commands.
1838
1839 A likely situation where you might need this is in typing an
1840 expression that involves a C@t{++} symbol name with template
1841 parameters. This is because when completing expressions, GDB treats
1842 the @samp{<} character as word delimiter, assuming that it's the
1843 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1844 Operators}).
1845
1846 For example, when you want to call a C@t{++} template function
1847 interactively using the @code{print} or @code{call} commands, you may
1848 need to distinguish whether you mean the version of @code{name} that
1849 was specialized for @code{int}, @code{name<int>()}, or the version
1850 that was specialized for @code{float}, @code{name<float>()}. To use
1851 the word-completion facilities in this situation, type a single quote
1852 @code{'} at the beginning of the function name. This alerts
1853 @value{GDBN} that it may need to consider more information than usual
1854 when you press @key{TAB} or @kbd{M-?} to request word completion:
1855
1856 @smallexample
1857 (@value{GDBP}) p 'func< @kbd{M-?}
1858 func<int>() func<float>()
1859 (@value{GDBP}) p 'func<
1860 @end smallexample
1861
1862 When setting breakpoints however (@pxref{Specify Location}), you don't
1863 usually need to type a quote before the function name, because
1864 @value{GDBN} understands that you want to set a breakpoint on a
1865 function:
1866
1867 @smallexample
1868 (@value{GDBP}) b func< @kbd{M-?}
1869 func<int>() func<float>()
1870 (@value{GDBP}) b func<
1871 @end smallexample
1872
1873 This is true even in the case of typing the name of C@t{++} overloaded
1874 functions (multiple definitions of the same function, distinguished by
1875 argument type). For example, when you want to set a breakpoint you
1876 don't need to distinguish whether you mean the version of @code{name}
1877 that takes an @code{int} parameter, @code{name(int)}, or the version
1878 that takes a @code{float} parameter, @code{name(float)}.
1879
1880 @smallexample
1881 (@value{GDBP}) b bubble( @kbd{M-?}
1882 bubble(int) bubble(double)
1883 (@value{GDBP}) b bubble(dou @kbd{M-?}
1884 bubble(double)
1885 @end smallexample
1886
1887 See @ref{quoting names} for a description of other scenarios that
1888 require quoting.
1889
1890 For more information about overloaded functions, see @ref{C Plus Plus
1891 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1892 overload-resolution off} to disable overload resolution;
1893 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1894
1895 @cindex completion of structure field names
1896 @cindex structure field name completion
1897 @cindex completion of union field names
1898 @cindex union field name completion
1899 When completing in an expression which looks up a field in a
1900 structure, @value{GDBN} also tries@footnote{The completer can be
1901 confused by certain kinds of invalid expressions. Also, it only
1902 examines the static type of the expression, not the dynamic type.} to
1903 limit completions to the field names available in the type of the
1904 left-hand-side:
1905
1906 @smallexample
1907 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1908 magic to_fputs to_rewind
1909 to_data to_isatty to_write
1910 to_delete to_put to_write_async_safe
1911 to_flush to_read
1912 @end smallexample
1913
1914 @noindent
1915 This is because the @code{gdb_stdout} is a variable of the type
1916 @code{struct ui_file} that is defined in @value{GDBN} sources as
1917 follows:
1918
1919 @smallexample
1920 struct ui_file
1921 @{
1922 int *magic;
1923 ui_file_flush_ftype *to_flush;
1924 ui_file_write_ftype *to_write;
1925 ui_file_write_async_safe_ftype *to_write_async_safe;
1926 ui_file_fputs_ftype *to_fputs;
1927 ui_file_read_ftype *to_read;
1928 ui_file_delete_ftype *to_delete;
1929 ui_file_isatty_ftype *to_isatty;
1930 ui_file_rewind_ftype *to_rewind;
1931 ui_file_put_ftype *to_put;
1932 void *to_data;
1933 @}
1934 @end smallexample
1935
1936 @node Command Options
1937 @section Command options
1938
1939 @cindex command options
1940 Some commands accept options starting with a leading dash. For
1941 example, @code{print -pretty}. Similarly to command names, you can
1942 abbreviate a @value{GDBN} option to the first few letters of the
1943 option name, if that abbreviation is unambiguous, and you can also use
1944 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1945 in an option (or to show you the alternatives available, if there is
1946 more than one possibility).
1947
1948 @cindex command options, raw input
1949 Some commands take raw input as argument. For example, the print
1950 command processes arbitrary expressions in any of the languages
1951 supported by @value{GDBN}. With such commands, because raw input may
1952 start with a leading dash that would be confused with an option or any
1953 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1954 -pretty} or printing negative @code{p}?), if you specify any command
1955 option, then you must use a double-dash (@code{--}) delimiter to
1956 indicate the end of options.
1957
1958 @cindex command options, boolean
1959
1960 Some options are described as accepting an argument which can be
1961 either @code{on} or @code{off}. These are known as @dfn{boolean
1962 options}. Similarly to boolean settings commands---@code{on} and
1963 @code{off} are the typical values, but any of @code{1}, @code{yes} and
1964 @code{enable} can also be used as ``true'' value, and any of @code{0},
1965 @code{no} and @code{disable} can also be used as ``false'' value. You
1966 can also omit a ``true'' value, as it is implied by default.
1967
1968 For example, these are equivalent:
1969
1970 @smallexample
1971 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1972 (@value{GDBP}) p -o -p 0 -e u -- *myptr
1973 @end smallexample
1974
1975 You can discover the set of options some command accepts by completing
1976 on @code{-} after the command name. For example:
1977
1978 @smallexample
1979 (@value{GDBP}) print -@key{TAB}@key{TAB}
1980 -address -max-depth -raw-values -union
1981 -array -null-stop -repeats -vtbl
1982 -array-indexes -object -static-members
1983 -elements -pretty -symbol
1984 @end smallexample
1985
1986 Completion will in some cases guide you with a suggestion of what kind
1987 of argument an option expects. For example:
1988
1989 @smallexample
1990 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
1991 NUMBER unlimited
1992 @end smallexample
1993
1994 Here, the option expects a number (e.g., @code{100}), not literal
1995 @code{NUMBER}. Such metasyntactical arguments are always presented in
1996 uppercase.
1997
1998 (For more on using the @code{print} command, see @ref{Data, ,Examining
1999 Data}.)
2000
2001 @node Command aliases default args
2002 @section Automatically prepend default arguments to user-defined aliases
2003
2004 You can tell @value{GDBN} to always prepend some default arguments to
2005 the list of arguments provided explicitly by the user when using a
2006 user-defined alias.
2007
2008 If you repeatedly use the same arguments or options for a command, you
2009 can define an alias for this command and tell @value{GDBN} to
2010 automatically prepend these arguments or options to the list of
2011 arguments you type explicitly when using the alias@footnote{@value{GDBN}
2012 could easily accept default arguments for pre-defined commands and aliases,
2013 but it was deemed this would be confusing, and so is not allowed.}.
2014
2015 For example, if you often use the command @code{thread apply all}
2016 specifying to work on the threads in ascending order and to continue in case it
2017 encounters an error, you can tell @value{GDBN} to automatically preprend
2018 the @code{-ascending} and @code{-c} options by using:
2019
2020 @smallexample
2021 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2022 @end smallexample
2023
2024 Once you have defined this alias with its default args, any time you type
2025 the @code{thread apply asc-all} followed by @code{some arguments},
2026 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2027
2028 To have even less to type, you can also define a one word alias:
2029 @smallexample
2030 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2031 @end smallexample
2032
2033 As usual, unambiguous abbreviations can be used for @var{alias}
2034 and @var{default-args}.
2035
2036 The different aliases of a command do not share their default args.
2037 For example, you define a new alias @code{bt_ALL} showing all possible
2038 information and another alias @code{bt_SMALL} showing very limited information
2039 using:
2040 @smallexample
2041 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2042 -past-main -past-entry -full
2043 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2044 -past-main off -past-entry off
2045 @end smallexample
2046
2047 (For more on using the @code{alias} command, see @ref{Aliases}.)
2048
2049 Default args are not limited to the arguments and options of @var{command},
2050 but can specify nested commands if @var{command} accepts such a nested command
2051 as argument.
2052 For example, the below defines @code{faalocalsoftype} that lists the
2053 frames having locals of a certain type, together with the matching
2054 local vars:
2055 @smallexample
2056 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2057 (@value{GDBP}) faalocalsoftype int
2058 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2059 i = 0
2060 ret = 21845
2061 @end smallexample
2062
2063 This is also very useful to define an alias for a set of nested @code{with}
2064 commands to have a particular combination of temporary settings. For example,
2065 the below defines the alias @code{pp10} that pretty prints an expression
2066 argument, with a maximum of 10 elements if the expression is a string or
2067 an array:
2068 @smallexample
2069 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2070 @end smallexample
2071 This defines the alias @code{pp10} as being a sequence of 3 commands.
2072 The first part @code{with print pretty --} temporarily activates the setting
2073 @code{set print pretty}, then launches the command that follows the separator
2074 @code{--}.
2075 The command following the first part is also a @code{with} command that
2076 temporarily changes the setting @code{set print elements} to 10, then
2077 launches the command that follows the second separator @code{--}.
2078 The third part @code{print} is the command the @code{pp10} alias will launch,
2079 using the temporary values of the settings and the arguments explicitly given
2080 by the user.
2081 For more information about the @code{with} command usage,
2082 see @ref{Command Settings}.
2083
2084 @node Help
2085 @section Getting Help
2086 @cindex online documentation
2087 @kindex help
2088
2089 You can always ask @value{GDBN} itself for information on its commands,
2090 using the command @code{help}.
2091
2092 @table @code
2093 @kindex h @r{(@code{help})}
2094 @item help
2095 @itemx h
2096 You can use @code{help} (abbreviated @code{h}) with no arguments to
2097 display a short list of named classes of commands:
2098
2099 @smallexample
2100 (@value{GDBP}) help
2101 List of classes of commands:
2102
2103 aliases -- User-defined aliases of other commands
2104 breakpoints -- Making program stop at certain points
2105 data -- Examining data
2106 files -- Specifying and examining files
2107 internals -- Maintenance commands
2108 obscure -- Obscure features
2109 running -- Running the program
2110 stack -- Examining the stack
2111 status -- Status inquiries
2112 support -- Support facilities
2113 tracepoints -- Tracing of program execution without
2114 stopping the program
2115 user-defined -- User-defined commands
2116
2117 Type "help" followed by a class name for a list of
2118 commands in that class.
2119 Type "help" followed by command name for full
2120 documentation.
2121 Command name abbreviations are allowed if unambiguous.
2122 (@value{GDBP})
2123 @end smallexample
2124 @c the above line break eliminates huge line overfull...
2125
2126 @item help @var{class}
2127 Using one of the general help classes as an argument, you can get a
2128 list of the individual commands in that class. If a command has
2129 aliases, the aliases are given after the command name, separated by
2130 commas. If an alias has default arguments, the full definition of
2131 the alias is given after the first line.
2132 For example, here is the help display for the class @code{status}:
2133
2134 @smallexample
2135 (@value{GDBP}) help status
2136 Status inquiries.
2137
2138 List of commands:
2139
2140 @c Line break in "show" line falsifies real output, but needed
2141 @c to fit in smallbook page size.
2142 info, inf, i -- Generic command for showing things
2143 about the program being debugged
2144 info address, iamain -- Describe where symbol SYM is stored.
2145 alias iamain = info address main
2146 info all-registers -- List of all registers and their contents,
2147 for selected stack frame.
2148 ...
2149 show, info set -- Generic command for showing things
2150 about the debugger
2151
2152 Type "help" followed by command name for full
2153 documentation.
2154 Command name abbreviations are allowed if unambiguous.
2155 (@value{GDBP})
2156 @end smallexample
2157
2158 @item help @var{command}
2159 With a command name as @code{help} argument, @value{GDBN} displays a
2160 short paragraph on how to use that command. If that command has
2161 one or more aliases, @value{GDBN} will display a first line with
2162 the command name and all its aliases separated by commas.
2163 This first line will be followed by the full definition of all aliases
2164 having default arguments.
2165
2166 @kindex apropos
2167 @item apropos [-v] @var{regexp}
2168 The @code{apropos} command searches through all of the @value{GDBN}
2169 commands, and their documentation, for the regular expression specified in
2170 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2171 which stands for @samp{verbose}, indicates to output the full documentation
2172 of the matching commands and highlight the parts of the documentation
2173 matching @var{regexp}. For example:
2174
2175 @smallexample
2176 apropos alias
2177 @end smallexample
2178
2179 @noindent
2180 results in:
2181
2182 @smallexample
2183 @group
2184 alias -- Define a new command that is an alias of an existing command
2185 aliases -- User-defined aliases of other commands
2186 @end group
2187 @end smallexample
2188
2189 @noindent
2190 while
2191
2192 @smallexample
2193 apropos -v cut.*thread apply
2194 @end smallexample
2195
2196 @noindent
2197 results in the below output, where @samp{cut for 'thread apply}
2198 is highlighted if styling is enabled.
2199
2200 @smallexample
2201 @group
2202 taas -- Apply a command to all threads (ignoring errors
2203 and empty output).
2204 Usage: taas COMMAND
2205 shortcut for 'thread apply all -s COMMAND'
2206
2207 tfaas -- Apply a command to all frames of all threads
2208 (ignoring errors and empty output).
2209 Usage: tfaas COMMAND
2210 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2211 @end group
2212 @end smallexample
2213
2214 @kindex complete
2215 @item complete @var{args}
2216 The @code{complete @var{args}} command lists all the possible completions
2217 for the beginning of a command. Use @var{args} to specify the beginning of the
2218 command you want completed. For example:
2219
2220 @smallexample
2221 complete i
2222 @end smallexample
2223
2224 @noindent results in:
2225
2226 @smallexample
2227 @group
2228 if
2229 ignore
2230 info
2231 inspect
2232 @end group
2233 @end smallexample
2234
2235 @noindent This is intended for use by @sc{gnu} Emacs.
2236 @end table
2237
2238 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2239 and @code{show} to inquire about the state of your program, or the state
2240 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2241 manual introduces each of them in the appropriate context. The listings
2242 under @code{info} and under @code{show} in the Command, Variable, and
2243 Function Index point to all the sub-commands. @xref{Command and Variable
2244 Index}.
2245
2246 @c @group
2247 @table @code
2248 @kindex info
2249 @kindex i @r{(@code{info})}
2250 @item info
2251 This command (abbreviated @code{i}) is for describing the state of your
2252 program. For example, you can show the arguments passed to a function
2253 with @code{info args}, list the registers currently in use with @code{info
2254 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2255 You can get a complete list of the @code{info} sub-commands with
2256 @w{@code{help info}}.
2257
2258 @kindex set
2259 @item set
2260 You can assign the result of an expression to an environment variable with
2261 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2262 @code{set prompt $}.
2263
2264 @kindex show
2265 @item show
2266 In contrast to @code{info}, @code{show} is for describing the state of
2267 @value{GDBN} itself.
2268 You can change most of the things you can @code{show}, by using the
2269 related command @code{set}; for example, you can control what number
2270 system is used for displays with @code{set radix}, or simply inquire
2271 which is currently in use with @code{show radix}.
2272
2273 @kindex info set
2274 To display all the settable parameters and their current
2275 values, you can use @code{show} with no arguments; you may also use
2276 @code{info set}. Both commands produce the same display.
2277 @c FIXME: "info set" violates the rule that "info" is for state of
2278 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2279 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2280 @end table
2281 @c @end group
2282
2283 Here are several miscellaneous @code{show} subcommands, all of which are
2284 exceptional in lacking corresponding @code{set} commands:
2285
2286 @table @code
2287 @kindex show version
2288 @cindex @value{GDBN} version number
2289 @item show version
2290 Show what version of @value{GDBN} is running. You should include this
2291 information in @value{GDBN} bug-reports. If multiple versions of
2292 @value{GDBN} are in use at your site, you may need to determine which
2293 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2294 commands are introduced, and old ones may wither away. Also, many
2295 system vendors ship variant versions of @value{GDBN}, and there are
2296 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2297 The version number is the same as the one announced when you start
2298 @value{GDBN}.
2299
2300 @kindex show copying
2301 @kindex info copying
2302 @cindex display @value{GDBN} copyright
2303 @item show copying
2304 @itemx info copying
2305 Display information about permission for copying @value{GDBN}.
2306
2307 @kindex show warranty
2308 @kindex info warranty
2309 @item show warranty
2310 @itemx info warranty
2311 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2312 if your version of @value{GDBN} comes with one.
2313
2314 @kindex show configuration
2315 @item show configuration
2316 Display detailed information about the way @value{GDBN} was configured
2317 when it was built. This displays the optional arguments passed to the
2318 @file{configure} script and also configuration parameters detected
2319 automatically by @command{configure}. When reporting a @value{GDBN}
2320 bug (@pxref{GDB Bugs}), it is important to include this information in
2321 your report.
2322
2323 @end table
2324
2325 @node Running
2326 @chapter Running Programs Under @value{GDBN}
2327
2328 When you run a program under @value{GDBN}, you must first generate
2329 debugging information when you compile it.
2330
2331 You may start @value{GDBN} with its arguments, if any, in an environment
2332 of your choice. If you are doing native debugging, you may redirect
2333 your program's input and output, debug an already running process, or
2334 kill a child process.
2335
2336 @menu
2337 * Compilation:: Compiling for debugging
2338 * Starting:: Starting your program
2339 * Arguments:: Your program's arguments
2340 * Environment:: Your program's environment
2341
2342 * Working Directory:: Your program's working directory
2343 * Input/Output:: Your program's input and output
2344 * Attach:: Debugging an already-running process
2345 * Kill Process:: Killing the child process
2346 * Inferiors Connections and Programs:: Debugging multiple inferiors
2347 connections and programs
2348 * Threads:: Debugging programs with multiple threads
2349 * Forks:: Debugging forks
2350 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2351 @end menu
2352
2353 @node Compilation
2354 @section Compiling for Debugging
2355
2356 In order to debug a program effectively, you need to generate
2357 debugging information when you compile it. This debugging information
2358 is stored in the object file; it describes the data type of each
2359 variable or function and the correspondence between source line numbers
2360 and addresses in the executable code.
2361
2362 To request debugging information, specify the @samp{-g} option when you run
2363 the compiler.
2364
2365 Programs that are to be shipped to your customers are compiled with
2366 optimizations, using the @samp{-O} compiler option. However, some
2367 compilers are unable to handle the @samp{-g} and @samp{-O} options
2368 together. Using those compilers, you cannot generate optimized
2369 executables containing debugging information.
2370
2371 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2372 without @samp{-O}, making it possible to debug optimized code. We
2373 recommend that you @emph{always} use @samp{-g} whenever you compile a
2374 program. You may think your program is correct, but there is no sense
2375 in pushing your luck. For more information, see @ref{Optimized Code}.
2376
2377 Older versions of the @sc{gnu} C compiler permitted a variant option
2378 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2379 format; if your @sc{gnu} C compiler has this option, do not use it.
2380
2381 @value{GDBN} knows about preprocessor macros and can show you their
2382 expansion (@pxref{Macros}). Most compilers do not include information
2383 about preprocessor macros in the debugging information if you specify
2384 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2385 the @sc{gnu} C compiler, provides macro information if you are using
2386 the DWARF debugging format, and specify the option @option{-g3}.
2387
2388 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2389 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2390 information on @value{NGCC} options affecting debug information.
2391
2392 You will have the best debugging experience if you use the latest
2393 version of the DWARF debugging format that your compiler supports.
2394 DWARF is currently the most expressive and best supported debugging
2395 format in @value{GDBN}.
2396
2397 @need 2000
2398 @node Starting
2399 @section Starting your Program
2400 @cindex starting
2401 @cindex running
2402
2403 @table @code
2404 @kindex run
2405 @kindex r @r{(@code{run})}
2406 @item run
2407 @itemx r
2408 Use the @code{run} command to start your program under @value{GDBN}.
2409 You must first specify the program name with an argument to
2410 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2411 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2412 command (@pxref{Files, ,Commands to Specify Files}).
2413
2414 @end table
2415
2416 If you are running your program in an execution environment that
2417 supports processes, @code{run} creates an inferior process and makes
2418 that process run your program. In some environments without processes,
2419 @code{run} jumps to the start of your program. Other targets,
2420 like @samp{remote}, are always running. If you get an error
2421 message like this one:
2422
2423 @smallexample
2424 The "remote" target does not support "run".
2425 Try "help target" or "continue".
2426 @end smallexample
2427
2428 @noindent
2429 then use @code{continue} to run your program. You may need @code{load}
2430 first (@pxref{load}).
2431
2432 The execution of a program is affected by certain information it
2433 receives from its superior. @value{GDBN} provides ways to specify this
2434 information, which you must do @emph{before} starting your program. (You
2435 can change it after starting your program, but such changes only affect
2436 your program the next time you start it.) This information may be
2437 divided into four categories:
2438
2439 @table @asis
2440 @item The @emph{arguments.}
2441 Specify the arguments to give your program as the arguments of the
2442 @code{run} command. If a shell is available on your target, the shell
2443 is used to pass the arguments, so that you may use normal conventions
2444 (such as wildcard expansion or variable substitution) in describing
2445 the arguments.
2446 In Unix systems, you can control which shell is used with the
2447 @code{SHELL} environment variable. If you do not define @code{SHELL},
2448 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2449 use of any shell with the @code{set startup-with-shell} command (see
2450 below for details).
2451
2452 @item The @emph{environment.}
2453 Your program normally inherits its environment from @value{GDBN}, but you can
2454 use the @value{GDBN} commands @code{set environment} and @code{unset
2455 environment} to change parts of the environment that affect
2456 your program. @xref{Environment, ,Your Program's Environment}.
2457
2458 @item The @emph{working directory.}
2459 You can set your program's working directory with the command
2460 @kbd{set cwd}. If you do not set any working directory with this
2461 command, your program will inherit @value{GDBN}'s working directory if
2462 native debugging, or the remote server's working directory if remote
2463 debugging. @xref{Working Directory, ,Your Program's Working
2464 Directory}.
2465
2466 @item The @emph{standard input and output.}
2467 Your program normally uses the same device for standard input and
2468 standard output as @value{GDBN} is using. You can redirect input and output
2469 in the @code{run} command line, or you can use the @code{tty} command to
2470 set a different device for your program.
2471 @xref{Input/Output, ,Your Program's Input and Output}.
2472
2473 @cindex pipes
2474 @emph{Warning:} While input and output redirection work, you cannot use
2475 pipes to pass the output of the program you are debugging to another
2476 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2477 wrong program.
2478 @end table
2479
2480 When you issue the @code{run} command, your program begins to execute
2481 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2482 of how to arrange for your program to stop. Once your program has
2483 stopped, you may call functions in your program, using the @code{print}
2484 or @code{call} commands. @xref{Data, ,Examining Data}.
2485
2486 If the modification time of your symbol file has changed since the last
2487 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2488 table, and reads it again. When it does this, @value{GDBN} tries to retain
2489 your current breakpoints.
2490
2491 @table @code
2492 @kindex start
2493 @item start
2494 @cindex run to main procedure
2495 The name of the main procedure can vary from language to language.
2496 With C or C@t{++}, the main procedure name is always @code{main}, but
2497 other languages such as Ada do not require a specific name for their
2498 main procedure. The debugger provides a convenient way to start the
2499 execution of the program and to stop at the beginning of the main
2500 procedure, depending on the language used.
2501
2502 The @samp{start} command does the equivalent of setting a temporary
2503 breakpoint at the beginning of the main procedure and then invoking
2504 the @samp{run} command.
2505
2506 @cindex elaboration phase
2507 Some programs contain an @dfn{elaboration} phase where some startup code is
2508 executed before the main procedure is called. This depends on the
2509 languages used to write your program. In C@t{++}, for instance,
2510 constructors for static and global objects are executed before
2511 @code{main} is called. It is therefore possible that the debugger stops
2512 before reaching the main procedure. However, the temporary breakpoint
2513 will remain to halt execution.
2514
2515 Specify the arguments to give to your program as arguments to the
2516 @samp{start} command. These arguments will be given verbatim to the
2517 underlying @samp{run} command. Note that the same arguments will be
2518 reused if no argument is provided during subsequent calls to
2519 @samp{start} or @samp{run}.
2520
2521 It is sometimes necessary to debug the program during elaboration. In
2522 these cases, using the @code{start} command would stop the execution
2523 of your program too late, as the program would have already completed
2524 the elaboration phase. Under these circumstances, either insert
2525 breakpoints in your elaboration code before running your program or
2526 use the @code{starti} command.
2527
2528 @kindex starti
2529 @item starti
2530 @cindex run to first instruction
2531 The @samp{starti} command does the equivalent of setting a temporary
2532 breakpoint at the first instruction of a program's execution and then
2533 invoking the @samp{run} command. For programs containing an
2534 elaboration phase, the @code{starti} command will stop execution at
2535 the start of the elaboration phase.
2536
2537 @anchor{set exec-wrapper}
2538 @kindex set exec-wrapper
2539 @item set exec-wrapper @var{wrapper}
2540 @itemx show exec-wrapper
2541 @itemx unset exec-wrapper
2542 When @samp{exec-wrapper} is set, the specified wrapper is used to
2543 launch programs for debugging. @value{GDBN} starts your program
2544 with a shell command of the form @kbd{exec @var{wrapper}
2545 @var{program}}. Quoting is added to @var{program} and its
2546 arguments, but not to @var{wrapper}, so you should add quotes if
2547 appropriate for your shell. The wrapper runs until it executes
2548 your program, and then @value{GDBN} takes control.
2549
2550 You can use any program that eventually calls @code{execve} with
2551 its arguments as a wrapper. Several standard Unix utilities do
2552 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2553 with @code{exec "$@@"} will also work.
2554
2555 For example, you can use @code{env} to pass an environment variable to
2556 the debugged program, without setting the variable in your shell's
2557 environment:
2558
2559 @smallexample
2560 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2561 (@value{GDBP}) run
2562 @end smallexample
2563
2564 This command is available when debugging locally on most targets, excluding
2565 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2566
2567 @kindex set startup-with-shell
2568 @anchor{set startup-with-shell}
2569 @item set startup-with-shell
2570 @itemx set startup-with-shell on
2571 @itemx set startup-with-shell off
2572 @itemx show startup-with-shell
2573 On Unix systems, by default, if a shell is available on your target,
2574 @value{GDBN}) uses it to start your program. Arguments of the
2575 @code{run} command are passed to the shell, which does variable
2576 substitution, expands wildcard characters and performs redirection of
2577 I/O. In some circumstances, it may be useful to disable such use of a
2578 shell, for example, when debugging the shell itself or diagnosing
2579 startup failures such as:
2580
2581 @smallexample
2582 (@value{GDBP}) run
2583 Starting program: ./a.out
2584 During startup program terminated with signal SIGSEGV, Segmentation fault.
2585 @end smallexample
2586
2587 @noindent
2588 which indicates the shell or the wrapper specified with
2589 @samp{exec-wrapper} crashed, not your program. Most often, this is
2590 caused by something odd in your shell's non-interactive mode
2591 initialization file---such as @file{.cshrc} for C-shell,
2592 $@file{.zshenv} for the Z shell, or the file specified in the
2593 @samp{BASH_ENV} environment variable for BASH.
2594
2595 @anchor{set auto-connect-native-target}
2596 @kindex set auto-connect-native-target
2597 @item set auto-connect-native-target
2598 @itemx set auto-connect-native-target on
2599 @itemx set auto-connect-native-target off
2600 @itemx show auto-connect-native-target
2601
2602 By default, if the current inferior is not connected to any target yet
2603 (e.g., with @code{target remote}), the @code{run} command starts your
2604 program as a native process under @value{GDBN}, on your local machine.
2605 If you're sure you don't want to debug programs on your local machine,
2606 you can tell @value{GDBN} to not connect to the native target
2607 automatically with the @code{set auto-connect-native-target off}
2608 command.
2609
2610 If @code{on}, which is the default, and if the current inferior is not
2611 connected to a target already, the @code{run} command automaticaly
2612 connects to the native target, if one is available.
2613
2614 If @code{off}, and if the current inferior is not connected to a
2615 target already, the @code{run} command fails with an error:
2616
2617 @smallexample
2618 (@value{GDBP}) run
2619 Don't know how to run. Try "help target".
2620 @end smallexample
2621
2622 If the current inferior is already connected to a target, @value{GDBN}
2623 always uses it with the @code{run} command.
2624
2625 In any case, you can explicitly connect to the native target with the
2626 @code{target native} command. For example,
2627
2628 @smallexample
2629 (@value{GDBP}) set auto-connect-native-target off
2630 (@value{GDBP}) run
2631 Don't know how to run. Try "help target".
2632 (@value{GDBP}) target native
2633 (@value{GDBP}) run
2634 Starting program: ./a.out
2635 [Inferior 1 (process 10421) exited normally]
2636 @end smallexample
2637
2638 In case you connected explicitly to the @code{native} target,
2639 @value{GDBN} remains connected even if all inferiors exit, ready for
2640 the next @code{run} command. Use the @code{disconnect} command to
2641 disconnect.
2642
2643 Examples of other commands that likewise respect the
2644 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2645 proc}, @code{info os}.
2646
2647 @kindex set disable-randomization
2648 @item set disable-randomization
2649 @itemx set disable-randomization on
2650 This option (enabled by default in @value{GDBN}) will turn off the native
2651 randomization of the virtual address space of the started program. This option
2652 is useful for multiple debugging sessions to make the execution better
2653 reproducible and memory addresses reusable across debugging sessions.
2654
2655 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2656 On @sc{gnu}/Linux you can get the same behavior using
2657
2658 @smallexample
2659 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2660 @end smallexample
2661
2662 @item set disable-randomization off
2663 Leave the behavior of the started executable unchanged. Some bugs rear their
2664 ugly heads only when the program is loaded at certain addresses. If your bug
2665 disappears when you run the program under @value{GDBN}, that might be because
2666 @value{GDBN} by default disables the address randomization on platforms, such
2667 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2668 disable-randomization off} to try to reproduce such elusive bugs.
2669
2670 On targets where it is available, virtual address space randomization
2671 protects the programs against certain kinds of security attacks. In these
2672 cases the attacker needs to know the exact location of a concrete executable
2673 code. Randomizing its location makes it impossible to inject jumps misusing
2674 a code at its expected addresses.
2675
2676 Prelinking shared libraries provides a startup performance advantage but it
2677 makes addresses in these libraries predictable for privileged processes by
2678 having just unprivileged access at the target system. Reading the shared
2679 library binary gives enough information for assembling the malicious code
2680 misusing it. Still even a prelinked shared library can get loaded at a new
2681 random address just requiring the regular relocation process during the
2682 startup. Shared libraries not already prelinked are always loaded at
2683 a randomly chosen address.
2684
2685 Position independent executables (PIE) contain position independent code
2686 similar to the shared libraries and therefore such executables get loaded at
2687 a randomly chosen address upon startup. PIE executables always load even
2688 already prelinked shared libraries at a random address. You can build such
2689 executable using @command{gcc -fPIE -pie}.
2690
2691 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2692 (as long as the randomization is enabled).
2693
2694 @item show disable-randomization
2695 Show the current setting of the explicit disable of the native randomization of
2696 the virtual address space of the started program.
2697
2698 @end table
2699
2700 @node Arguments
2701 @section Your Program's Arguments
2702
2703 @cindex arguments (to your program)
2704 The arguments to your program can be specified by the arguments of the
2705 @code{run} command.
2706 They are passed to a shell, which expands wildcard characters and
2707 performs redirection of I/O, and thence to your program. Your
2708 @code{SHELL} environment variable (if it exists) specifies what shell
2709 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2710 the default shell (@file{/bin/sh} on Unix).
2711
2712 On non-Unix systems, the program is usually invoked directly by
2713 @value{GDBN}, which emulates I/O redirection via the appropriate system
2714 calls, and the wildcard characters are expanded by the startup code of
2715 the program, not by the shell.
2716
2717 @code{run} with no arguments uses the same arguments used by the previous
2718 @code{run}, or those set by the @code{set args} command.
2719
2720 @table @code
2721 @kindex set args
2722 @item set args
2723 Specify the arguments to be used the next time your program is run. If
2724 @code{set args} has no arguments, @code{run} executes your program
2725 with no arguments. Once you have run your program with arguments,
2726 using @code{set args} before the next @code{run} is the only way to run
2727 it again without arguments.
2728
2729 @kindex show args
2730 @item show args
2731 Show the arguments to give your program when it is started.
2732 @end table
2733
2734 @node Environment
2735 @section Your Program's Environment
2736
2737 @cindex environment (of your program)
2738 The @dfn{environment} consists of a set of environment variables and
2739 their values. Environment variables conventionally record such things as
2740 your user name, your home directory, your terminal type, and your search
2741 path for programs to run. Usually you set up environment variables with
2742 the shell and they are inherited by all the other programs you run. When
2743 debugging, it can be useful to try running your program with a modified
2744 environment without having to start @value{GDBN} over again.
2745
2746 @table @code
2747 @kindex path
2748 @item path @var{directory}
2749 Add @var{directory} to the front of the @code{PATH} environment variable
2750 (the search path for executables) that will be passed to your program.
2751 The value of @code{PATH} used by @value{GDBN} does not change.
2752 You may specify several directory names, separated by whitespace or by a
2753 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2754 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2755 is moved to the front, so it is searched sooner.
2756
2757 You can use the string @samp{$cwd} to refer to whatever is the current
2758 working directory at the time @value{GDBN} searches the path. If you
2759 use @samp{.} instead, it refers to the directory where you executed the
2760 @code{path} command. @value{GDBN} replaces @samp{.} in the
2761 @var{directory} argument (with the current path) before adding
2762 @var{directory} to the search path.
2763 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2764 @c document that, since repeating it would be a no-op.
2765
2766 @kindex show paths
2767 @item show paths
2768 Display the list of search paths for executables (the @code{PATH}
2769 environment variable).
2770
2771 @kindex show environment
2772 @item show environment @r{[}@var{varname}@r{]}
2773 Print the value of environment variable @var{varname} to be given to
2774 your program when it starts. If you do not supply @var{varname},
2775 print the names and values of all environment variables to be given to
2776 your program. You can abbreviate @code{environment} as @code{env}.
2777
2778 @kindex set environment
2779 @anchor{set environment}
2780 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2781 Set environment variable @var{varname} to @var{value}. The value
2782 changes for your program (and the shell @value{GDBN} uses to launch
2783 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2784 values of environment variables are just strings, and any
2785 interpretation is supplied by your program itself. The @var{value}
2786 parameter is optional; if it is eliminated, the variable is set to a
2787 null value.
2788 @c "any string" here does not include leading, trailing
2789 @c blanks. Gnu asks: does anyone care?
2790
2791 For example, this command:
2792
2793 @smallexample
2794 set env USER = foo
2795 @end smallexample
2796
2797 @noindent
2798 tells the debugged program, when subsequently run, that its user is named
2799 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2800 are not actually required.)
2801
2802 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2803 which also inherits the environment set with @code{set environment}.
2804 If necessary, you can avoid that by using the @samp{env} program as a
2805 wrapper instead of using @code{set environment}. @xref{set
2806 exec-wrapper}, for an example doing just that.
2807
2808 Environment variables that are set by the user are also transmitted to
2809 @command{gdbserver} to be used when starting the remote inferior.
2810 @pxref{QEnvironmentHexEncoded}.
2811
2812 @kindex unset environment
2813 @anchor{unset environment}
2814 @item unset environment @var{varname}
2815 Remove variable @var{varname} from the environment to be passed to your
2816 program. This is different from @samp{set env @var{varname} =};
2817 @code{unset environment} removes the variable from the environment,
2818 rather than assigning it an empty value.
2819
2820 Environment variables that are unset by the user are also unset on
2821 @command{gdbserver} when starting the remote inferior.
2822 @pxref{QEnvironmentUnset}.
2823 @end table
2824
2825 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2826 the shell indicated by your @code{SHELL} environment variable if it
2827 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2828 names a shell that runs an initialization file when started
2829 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2830 for the Z shell, or the file specified in the @samp{BASH_ENV}
2831 environment variable for BASH---any variables you set in that file
2832 affect your program. You may wish to move setting of environment
2833 variables to files that are only run when you sign on, such as
2834 @file{.login} or @file{.profile}.
2835
2836 @node Working Directory
2837 @section Your Program's Working Directory
2838
2839 @cindex working directory (of your program)
2840 Each time you start your program with @code{run}, the inferior will be
2841 initialized with the current working directory specified by the
2842 @kbd{set cwd} command. If no directory has been specified by this
2843 command, then the inferior will inherit @value{GDBN}'s current working
2844 directory as its working directory if native debugging, or it will
2845 inherit the remote server's current working directory if remote
2846 debugging.
2847
2848 @table @code
2849 @kindex set cwd
2850 @cindex change inferior's working directory
2851 @anchor{set cwd command}
2852 @item set cwd @r{[}@var{directory}@r{]}
2853 Set the inferior's working directory to @var{directory}, which will be
2854 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2855 argument has been specified, the command clears the setting and resets
2856 it to an empty state. This setting has no effect on @value{GDBN}'s
2857 working directory, and it only takes effect the next time you start
2858 the inferior. The @file{~} in @var{directory} is a short for the
2859 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2860 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2861 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2862 fallback.
2863
2864 You can also change @value{GDBN}'s current working directory by using
2865 the @code{cd} command.
2866 @xref{cd command}.
2867
2868 @kindex show cwd
2869 @cindex show inferior's working directory
2870 @item show cwd
2871 Show the inferior's working directory. If no directory has been
2872 specified by @kbd{set cwd}, then the default inferior's working
2873 directory is the same as @value{GDBN}'s working directory.
2874
2875 @kindex cd
2876 @cindex change @value{GDBN}'s working directory
2877 @anchor{cd command}
2878 @item cd @r{[}@var{directory}@r{]}
2879 Set the @value{GDBN} working directory to @var{directory}. If not
2880 given, @var{directory} uses @file{'~'}.
2881
2882 The @value{GDBN} working directory serves as a default for the
2883 commands that specify files for @value{GDBN} to operate on.
2884 @xref{Files, ,Commands to Specify Files}.
2885 @xref{set cwd command}.
2886
2887 @kindex pwd
2888 @item pwd
2889 Print the @value{GDBN} working directory.
2890 @end table
2891
2892 It is generally impossible to find the current working directory of
2893 the process being debugged (since a program can change its directory
2894 during its run). If you work on a system where @value{GDBN} supports
2895 the @code{info proc} command (@pxref{Process Information}), you can
2896 use the @code{info proc} command to find out the
2897 current working directory of the debuggee.
2898
2899 @node Input/Output
2900 @section Your Program's Input and Output
2901
2902 @cindex redirection
2903 @cindex i/o
2904 @cindex terminal
2905 By default, the program you run under @value{GDBN} does input and output to
2906 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2907 to its own terminal modes to interact with you, but it records the terminal
2908 modes your program was using and switches back to them when you continue
2909 running your program.
2910
2911 @table @code
2912 @kindex info terminal
2913 @item info terminal
2914 Displays information recorded by @value{GDBN} about the terminal modes your
2915 program is using.
2916 @end table
2917
2918 You can redirect your program's input and/or output using shell
2919 redirection with the @code{run} command. For example,
2920
2921 @smallexample
2922 run > outfile
2923 @end smallexample
2924
2925 @noindent
2926 starts your program, diverting its output to the file @file{outfile}.
2927
2928 @kindex tty
2929 @cindex controlling terminal
2930 Another way to specify where your program should do input and output is
2931 with the @code{tty} command. This command accepts a file name as
2932 argument, and causes this file to be the default for future @code{run}
2933 commands. It also resets the controlling terminal for the child
2934 process, for future @code{run} commands. For example,
2935
2936 @smallexample
2937 tty /dev/ttyb
2938 @end smallexample
2939
2940 @noindent
2941 directs that processes started with subsequent @code{run} commands
2942 default to do input and output on the terminal @file{/dev/ttyb} and have
2943 that as their controlling terminal.
2944
2945 An explicit redirection in @code{run} overrides the @code{tty} command's
2946 effect on the input/output device, but not its effect on the controlling
2947 terminal.
2948
2949 When you use the @code{tty} command or redirect input in the @code{run}
2950 command, only the input @emph{for your program} is affected. The input
2951 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2952 for @code{set inferior-tty}.
2953
2954 @cindex inferior tty
2955 @cindex set inferior controlling terminal
2956 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2957 display the name of the terminal that will be used for future runs of your
2958 program.
2959
2960 @table @code
2961 @item set inferior-tty [ @var{tty} ]
2962 @kindex set inferior-tty
2963 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2964 restores the default behavior, which is to use the same terminal as
2965 @value{GDBN}.
2966
2967 @item show inferior-tty
2968 @kindex show inferior-tty
2969 Show the current tty for the program being debugged.
2970 @end table
2971
2972 @node Attach
2973 @section Debugging an Already-running Process
2974 @kindex attach
2975 @cindex attach
2976
2977 @table @code
2978 @item attach @var{process-id}
2979 This command attaches to a running process---one that was started
2980 outside @value{GDBN}. (@code{info files} shows your active
2981 targets.) The command takes as argument a process ID. The usual way to
2982 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2983 or with the @samp{jobs -l} shell command.
2984
2985 @code{attach} does not repeat if you press @key{RET} a second time after
2986 executing the command.
2987 @end table
2988
2989 To use @code{attach}, your program must be running in an environment
2990 which supports processes; for example, @code{attach} does not work for
2991 programs on bare-board targets that lack an operating system. You must
2992 also have permission to send the process a signal.
2993
2994 When you use @code{attach}, the debugger finds the program running in
2995 the process first by looking in the current working directory, then (if
2996 the program is not found) by using the source file search path
2997 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2998 the @code{file} command to load the program. @xref{Files, ,Commands to
2999 Specify Files}.
3000
3001 @anchor{set exec-file-mismatch}
3002 If the debugger can determine that the executable file running in the
3003 process it is attaching to does not match the current exec-file loaded
3004 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3005 handle the mismatch. @value{GDBN} tries to compare the files by
3006 comparing their build IDs (@pxref{build ID}), if available.
3007
3008 @table @code
3009 @kindex exec-file-mismatch
3010 @cindex set exec-file-mismatch
3011 @item set exec-file-mismatch @samp{ask|warn|off}
3012
3013 Whether to detect mismatch between the current executable file loaded
3014 by @value{GDBN} and the executable file used to start the process. If
3015 @samp{ask}, the default, display a warning and ask the user whether to
3016 load the process executable file; if @samp{warn}, just display a
3017 warning; if @samp{off}, don't attempt to detect a mismatch.
3018
3019 @cindex show exec-file-mismatch
3020 @item show exec-file-mismatch
3021 Show the current value of @code{exec-file-mismatch}.
3022
3023 @end table
3024
3025 The first thing @value{GDBN} does after arranging to debug the specified
3026 process is to stop it. You can examine and modify an attached process
3027 with all the @value{GDBN} commands that are ordinarily available when
3028 you start processes with @code{run}. You can insert breakpoints; you
3029 can step and continue; you can modify storage. If you would rather the
3030 process continue running, you may use the @code{continue} command after
3031 attaching @value{GDBN} to the process.
3032
3033 @table @code
3034 @kindex detach
3035 @item detach
3036 When you have finished debugging the attached process, you can use the
3037 @code{detach} command to release it from @value{GDBN} control. Detaching
3038 the process continues its execution. After the @code{detach} command,
3039 that process and @value{GDBN} become completely independent once more, and you
3040 are ready to @code{attach} another process or start one with @code{run}.
3041 @code{detach} does not repeat if you press @key{RET} again after
3042 executing the command.
3043 @end table
3044
3045 If you exit @value{GDBN} while you have an attached process, you detach
3046 that process. If you use the @code{run} command, you kill that process.
3047 By default, @value{GDBN} asks for confirmation if you try to do either of these
3048 things; you can control whether or not you need to confirm by using the
3049 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3050 Messages}).
3051
3052 @node Kill Process
3053 @section Killing the Child Process
3054
3055 @table @code
3056 @kindex kill
3057 @item kill
3058 Kill the child process in which your program is running under @value{GDBN}.
3059 @end table
3060
3061 This command is useful if you wish to debug a core dump instead of a
3062 running process. @value{GDBN} ignores any core dump file while your program
3063 is running.
3064
3065 On some operating systems, a program cannot be executed outside @value{GDBN}
3066 while you have breakpoints set on it inside @value{GDBN}. You can use the
3067 @code{kill} command in this situation to permit running your program
3068 outside the debugger.
3069
3070 The @code{kill} command is also useful if you wish to recompile and
3071 relink your program, since on many systems it is impossible to modify an
3072 executable file while it is running in a process. In this case, when you
3073 next type @code{run}, @value{GDBN} notices that the file has changed, and
3074 reads the symbol table again (while trying to preserve your current
3075 breakpoint settings).
3076
3077 @node Inferiors Connections and Programs
3078 @section Debugging Multiple Inferiors Connections and Programs
3079
3080 @value{GDBN} lets you run and debug multiple programs in a single
3081 session. In addition, @value{GDBN} on some systems may let you run
3082 several programs simultaneously (otherwise you have to exit from one
3083 before starting another). On some systems @value{GDBN} may even let
3084 you debug several programs simultaneously on different remote systems.
3085 In the most general case, you can have multiple threads of execution
3086 in each of multiple processes, launched from multiple executables,
3087 running on different machines.
3088
3089 @cindex inferior
3090 @value{GDBN} represents the state of each program execution with an
3091 object called an @dfn{inferior}. An inferior typically corresponds to
3092 a process, but is more general and applies also to targets that do not
3093 have processes. Inferiors may be created before a process runs, and
3094 may be retained after a process exits. Inferiors have unique
3095 identifiers that are different from process ids. Usually each
3096 inferior will also have its own distinct address space, although some
3097 embedded targets may have several inferiors running in different parts
3098 of a single address space. Each inferior may in turn have multiple
3099 threads running in it.
3100
3101 To find out what inferiors exist at any moment, use @w{@code{info
3102 inferiors}}:
3103
3104 @table @code
3105 @kindex info inferiors [ @var{id}@dots{} ]
3106 @item info inferiors
3107 Print a list of all inferiors currently being managed by @value{GDBN}.
3108 By default all inferiors are printed, but the argument @var{id}@dots{}
3109 -- a space separated list of inferior numbers -- can be used to limit
3110 the display to just the requested inferiors.
3111
3112 @value{GDBN} displays for each inferior (in this order):
3113
3114 @enumerate
3115 @item
3116 the inferior number assigned by @value{GDBN}
3117
3118 @item
3119 the target system's inferior identifier
3120
3121 @item
3122 the target connection the inferior is bound to, including the unique
3123 connection number assigned by @value{GDBN}, and the protocol used by
3124 the connection.
3125
3126 @item
3127 the name of the executable the inferior is running.
3128
3129 @end enumerate
3130
3131 @noindent
3132 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3133 indicates the current inferior.
3134
3135 For example,
3136 @end table
3137 @c end table here to get a little more width for example
3138
3139 @smallexample
3140 (@value{GDBP}) info inferiors
3141 Num Description Connection Executable
3142 * 1 process 3401 1 (native) goodbye
3143 2 process 2307 2 (extended-remote host:10000) hello
3144 @end smallexample
3145
3146 To find out what open target connections exist at any moment, use
3147 @w{@code{info connections}}:
3148
3149 @table @code
3150 @kindex info connections [ @var{id}@dots{} ]
3151 @item info connections
3152 Print a list of all open target connections currently being managed by
3153 @value{GDBN}. By default all connections are printed, but the
3154 argument @var{id}@dots{} -- a space separated list of connections
3155 numbers -- can be used to limit the display to just the requested
3156 connections.
3157
3158 @value{GDBN} displays for each connection (in this order):
3159
3160 @enumerate
3161 @item
3162 the connection number assigned by @value{GDBN}.
3163
3164 @item
3165 the protocol used by the connection.
3166
3167 @item
3168 a textual description of the protocol used by the connection.
3169
3170 @end enumerate
3171
3172 @noindent
3173 An asterisk @samp{*} preceding the connection number indicates the
3174 connection of the current inferior.
3175
3176 For example,
3177 @end table
3178 @c end table here to get a little more width for example
3179
3180 @smallexample
3181 (@value{GDBP}) info connections
3182 Num What Description
3183 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3184 2 native Native process
3185 3 core Local core dump file
3186 @end smallexample
3187
3188 To switch focus between inferiors, use the @code{inferior} command:
3189
3190 @table @code
3191 @kindex inferior @var{infno}
3192 @item inferior @var{infno}
3193 Make inferior number @var{infno} the current inferior. The argument
3194 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3195 in the first field of the @samp{info inferiors} display.
3196 @end table
3197
3198 @vindex $_inferior@r{, convenience variable}
3199 The debugger convenience variable @samp{$_inferior} contains the
3200 number of the current inferior. You may find this useful in writing
3201 breakpoint conditional expressions, command scripts, and so forth.
3202 @xref{Convenience Vars,, Convenience Variables}, for general
3203 information on convenience variables.
3204
3205 You can get multiple executables into a debugging session via the
3206 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3207 systems @value{GDBN} can add inferiors to the debug session
3208 automatically by following calls to @code{fork} and @code{exec}. To
3209 remove inferiors from the debugging session use the
3210 @w{@code{remove-inferiors}} command.
3211
3212 @table @code
3213 @kindex add-inferior
3214 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3215 Adds @var{n} inferiors to be run using @var{executable} as the
3216 executable; @var{n} defaults to 1. If no executable is specified,
3217 the inferiors begins empty, with no program. You can still assign or
3218 change the program assigned to the inferior at any time by using the
3219 @code{file} command with the executable name as its argument.
3220
3221 By default, the new inferior begins connected to the same target
3222 connection as the current inferior. For example, if the current
3223 inferior was connected to @code{gdbserver} with @code{target remote},
3224 then the new inferior will be connected to the same @code{gdbserver}
3225 instance. The @samp{-no-connection} option starts the new inferior
3226 with no connection yet. You can then for example use the @code{target
3227 remote} command to connect to some other @code{gdbserver} instance,
3228 use @code{run} to spawn a local program, etc.
3229
3230 @kindex clone-inferior
3231 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3232 Adds @var{n} inferiors ready to execute the same program as inferior
3233 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3234 number of the current inferior. This is a convenient command when you
3235 want to run another instance of the inferior you are debugging.
3236
3237 @smallexample
3238 (@value{GDBP}) info inferiors
3239 Num Description Connection Executable
3240 * 1 process 29964 1 (native) helloworld
3241 (@value{GDBP}) clone-inferior
3242 Added inferior 2.
3243 1 inferiors added.
3244 (@value{GDBP}) info inferiors
3245 Num Description Connection Executable
3246 * 1 process 29964 1 (native) helloworld
3247 2 <null> 1 (native) helloworld
3248 @end smallexample
3249
3250 You can now simply switch focus to inferior 2 and run it.
3251
3252 @kindex remove-inferiors
3253 @item remove-inferiors @var{infno}@dots{}
3254 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3255 possible to remove an inferior that is running with this command. For
3256 those, use the @code{kill} or @code{detach} command first.
3257
3258 @end table
3259
3260 To quit debugging one of the running inferiors that is not the current
3261 inferior, you can either detach from it by using the @w{@code{detach
3262 inferior}} command (allowing it to run independently), or kill it
3263 using the @w{@code{kill inferiors}} command:
3264
3265 @table @code
3266 @kindex detach inferiors @var{infno}@dots{}
3267 @item detach inferior @var{infno}@dots{}
3268 Detach from the inferior or inferiors identified by @value{GDBN}
3269 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3270 still stays on the list of inferiors shown by @code{info inferiors},
3271 but its Description will show @samp{<null>}.
3272
3273 @kindex kill inferiors @var{infno}@dots{}
3274 @item kill inferiors @var{infno}@dots{}
3275 Kill the inferior or inferiors identified by @value{GDBN} inferior
3276 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3277 stays on the list of inferiors shown by @code{info inferiors}, but its
3278 Description will show @samp{<null>}.
3279 @end table
3280
3281 After the successful completion of a command such as @code{detach},
3282 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3283 a normal process exit, the inferior is still valid and listed with
3284 @code{info inferiors}, ready to be restarted.
3285
3286
3287 To be notified when inferiors are started or exit under @value{GDBN}'s
3288 control use @w{@code{set print inferior-events}}:
3289
3290 @table @code
3291 @kindex set print inferior-events
3292 @cindex print messages on inferior start and exit
3293 @item set print inferior-events
3294 @itemx set print inferior-events on
3295 @itemx set print inferior-events off
3296 The @code{set print inferior-events} command allows you to enable or
3297 disable printing of messages when @value{GDBN} notices that new
3298 inferiors have started or that inferiors have exited or have been
3299 detached. By default, these messages will not be printed.
3300
3301 @kindex show print inferior-events
3302 @item show print inferior-events
3303 Show whether messages will be printed when @value{GDBN} detects that
3304 inferiors have started, exited or have been detached.
3305 @end table
3306
3307 Many commands will work the same with multiple programs as with a
3308 single program: e.g., @code{print myglobal} will simply display the
3309 value of @code{myglobal} in the current inferior.
3310
3311
3312 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3313 get more info about the relationship of inferiors, programs, address
3314 spaces in a debug session. You can do that with the @w{@code{maint
3315 info program-spaces}} command.
3316
3317 @table @code
3318 @kindex maint info program-spaces
3319 @item maint info program-spaces
3320 Print a list of all program spaces currently being managed by
3321 @value{GDBN}.
3322
3323 @value{GDBN} displays for each program space (in this order):
3324
3325 @enumerate
3326 @item
3327 the program space number assigned by @value{GDBN}
3328
3329 @item
3330 the name of the executable loaded into the program space, with e.g.,
3331 the @code{file} command.
3332
3333 @end enumerate
3334
3335 @noindent
3336 An asterisk @samp{*} preceding the @value{GDBN} program space number
3337 indicates the current program space.
3338
3339 In addition, below each program space line, @value{GDBN} prints extra
3340 information that isn't suitable to display in tabular form. For
3341 example, the list of inferiors bound to the program space.
3342
3343 @smallexample
3344 (@value{GDBP}) maint info program-spaces
3345 Id Executable
3346 * 1 hello
3347 2 goodbye
3348 Bound inferiors: ID 1 (process 21561)
3349 @end smallexample
3350
3351 Here we can see that no inferior is running the program @code{hello},
3352 while @code{process 21561} is running the program @code{goodbye}. On
3353 some targets, it is possible that multiple inferiors are bound to the
3354 same program space. The most common example is that of debugging both
3355 the parent and child processes of a @code{vfork} call. For example,
3356
3357 @smallexample
3358 (@value{GDBP}) maint info program-spaces
3359 Id Executable
3360 * 1 vfork-test
3361 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3362 @end smallexample
3363
3364 Here, both inferior 2 and inferior 1 are running in the same program
3365 space as a result of inferior 1 having executed a @code{vfork} call.
3366 @end table
3367
3368 @node Threads
3369 @section Debugging Programs with Multiple Threads
3370
3371 @cindex threads of execution
3372 @cindex multiple threads
3373 @cindex switching threads
3374 In some operating systems, such as GNU/Linux and Solaris, a single program
3375 may have more than one @dfn{thread} of execution. The precise semantics
3376 of threads differ from one operating system to another, but in general
3377 the threads of a single program are akin to multiple processes---except
3378 that they share one address space (that is, they can all examine and
3379 modify the same variables). On the other hand, each thread has its own
3380 registers and execution stack, and perhaps private memory.
3381
3382 @value{GDBN} provides these facilities for debugging multi-thread
3383 programs:
3384
3385 @itemize @bullet
3386 @item automatic notification of new threads
3387 @item @samp{thread @var{thread-id}}, a command to switch among threads
3388 @item @samp{info threads}, a command to inquire about existing threads
3389 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3390 a command to apply a command to a list of threads
3391 @item thread-specific breakpoints
3392 @item @samp{set print thread-events}, which controls printing of
3393 messages on thread start and exit.
3394 @item @samp{set libthread-db-search-path @var{path}}, which lets
3395 the user specify which @code{libthread_db} to use if the default choice
3396 isn't compatible with the program.
3397 @end itemize
3398
3399 @cindex focus of debugging
3400 @cindex current thread
3401 The @value{GDBN} thread debugging facility allows you to observe all
3402 threads while your program runs---but whenever @value{GDBN} takes
3403 control, one thread in particular is always the focus of debugging.
3404 This thread is called the @dfn{current thread}. Debugging commands show
3405 program information from the perspective of the current thread.
3406
3407 @cindex @code{New} @var{systag} message
3408 @cindex thread identifier (system)
3409 @c FIXME-implementors!! It would be more helpful if the [New...] message
3410 @c included GDB's numeric thread handle, so you could just go to that
3411 @c thread without first checking `info threads'.
3412 Whenever @value{GDBN} detects a new thread in your program, it displays
3413 the target system's identification for the thread with a message in the
3414 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3415 whose form varies depending on the particular system. For example, on
3416 @sc{gnu}/Linux, you might see
3417
3418 @smallexample
3419 [New Thread 0x41e02940 (LWP 25582)]
3420 @end smallexample
3421
3422 @noindent
3423 when @value{GDBN} notices a new thread. In contrast, on other systems,
3424 the @var{systag} is simply something like @samp{process 368}, with no
3425 further qualifier.
3426
3427 @c FIXME!! (1) Does the [New...] message appear even for the very first
3428 @c thread of a program, or does it only appear for the
3429 @c second---i.e.@: when it becomes obvious we have a multithread
3430 @c program?
3431 @c (2) *Is* there necessarily a first thread always? Or do some
3432 @c multithread systems permit starting a program with multiple
3433 @c threads ab initio?
3434
3435 @anchor{thread numbers}
3436 @cindex thread number, per inferior
3437 @cindex thread identifier (GDB)
3438 For debugging purposes, @value{GDBN} associates its own thread number
3439 ---always a single integer---with each thread of an inferior. This
3440 number is unique between all threads of an inferior, but not unique
3441 between threads of different inferiors.
3442
3443 @cindex qualified thread ID
3444 You can refer to a given thread in an inferior using the qualified
3445 @var{inferior-num}.@var{thread-num} syntax, also known as
3446 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3447 number and @var{thread-num} being the thread number of the given
3448 inferior. For example, thread @code{2.3} refers to thread number 3 of
3449 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3450 then @value{GDBN} infers you're referring to a thread of the current
3451 inferior.
3452
3453 Until you create a second inferior, @value{GDBN} does not show the
3454 @var{inferior-num} part of thread IDs, even though you can always use
3455 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3456 of inferior 1, the initial inferior.
3457
3458 @anchor{thread ID lists}
3459 @cindex thread ID lists
3460 Some commands accept a space-separated @dfn{thread ID list} as
3461 argument. A list element can be:
3462
3463 @enumerate
3464 @item
3465 A thread ID as shown in the first field of the @samp{info threads}
3466 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3467 @samp{1}.
3468
3469 @item
3470 A range of thread numbers, again with or without an inferior
3471 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3472 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3473
3474 @item
3475 All threads of an inferior, specified with a star wildcard, with or
3476 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3477 @samp{1.*}) or @code{*}. The former refers to all threads of the
3478 given inferior, and the latter form without an inferior qualifier
3479 refers to all threads of the current inferior.
3480
3481 @end enumerate
3482
3483 For example, if the current inferior is 1, and inferior 7 has one
3484 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3485 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3486 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3487 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3488 7.1}.
3489
3490
3491 @anchor{global thread numbers}
3492 @cindex global thread number
3493 @cindex global thread identifier (GDB)
3494 In addition to a @emph{per-inferior} number, each thread is also
3495 assigned a unique @emph{global} number, also known as @dfn{global
3496 thread ID}, a single integer. Unlike the thread number component of
3497 the thread ID, no two threads have the same global ID, even when
3498 you're debugging multiple inferiors.
3499
3500 From @value{GDBN}'s perspective, a process always has at least one
3501 thread. In other words, @value{GDBN} assigns a thread number to the
3502 program's ``main thread'' even if the program is not multi-threaded.
3503
3504 @vindex $_thread@r{, convenience variable}
3505 @vindex $_gthread@r{, convenience variable}
3506 The debugger convenience variables @samp{$_thread} and
3507 @samp{$_gthread} contain, respectively, the per-inferior thread number
3508 and the global thread number of the current thread. You may find this
3509 useful in writing breakpoint conditional expressions, command scripts,
3510 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3511 general information on convenience variables.
3512
3513 If @value{GDBN} detects the program is multi-threaded, it augments the
3514 usual message about stopping at a breakpoint with the ID and name of
3515 the thread that hit the breakpoint.
3516
3517 @smallexample
3518 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3519 @end smallexample
3520
3521 Likewise when the program receives a signal:
3522
3523 @smallexample
3524 Thread 1 "main" received signal SIGINT, Interrupt.
3525 @end smallexample
3526
3527 @table @code
3528 @kindex info threads
3529 @item info threads @r{[}@var{thread-id-list}@r{]}
3530
3531 Display information about one or more threads. With no arguments
3532 displays information about all threads. You can specify the list of
3533 threads that you want to display using the thread ID list syntax
3534 (@pxref{thread ID lists}).
3535
3536 @value{GDBN} displays for each thread (in this order):
3537
3538 @enumerate
3539 @item
3540 the per-inferior thread number assigned by @value{GDBN}
3541
3542 @item
3543 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3544 option was specified
3545
3546 @item
3547 the target system's thread identifier (@var{systag})
3548
3549 @item
3550 the thread's name, if one is known. A thread can either be named by
3551 the user (see @code{thread name}, below), or, in some cases, by the
3552 program itself.
3553
3554 @item
3555 the current stack frame summary for that thread
3556 @end enumerate
3557
3558 @noindent
3559 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3560 indicates the current thread.
3561
3562 For example,
3563 @end table
3564 @c end table here to get a little more width for example
3565
3566 @smallexample
3567 (@value{GDBP}) info threads
3568 Id Target Id Frame
3569 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3570 2 process 35 thread 23 0x34e5 in sigpause ()
3571 3 process 35 thread 27 0x34e5 in sigpause ()
3572 at threadtest.c:68
3573 @end smallexample
3574
3575 If you're debugging multiple inferiors, @value{GDBN} displays thread
3576 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3577 Otherwise, only @var{thread-num} is shown.
3578
3579 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3580 indicating each thread's global thread ID:
3581
3582 @smallexample
3583 (@value{GDBP}) info threads
3584 Id GId Target Id Frame
3585 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3586 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3587 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3588 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3589 @end smallexample
3590
3591 On Solaris, you can display more information about user threads with a
3592 Solaris-specific command:
3593
3594 @table @code
3595 @item maint info sol-threads
3596 @kindex maint info sol-threads
3597 @cindex thread info (Solaris)
3598 Display info on Solaris user threads.
3599 @end table
3600
3601 @table @code
3602 @kindex thread @var{thread-id}
3603 @item thread @var{thread-id}
3604 Make thread ID @var{thread-id} the current thread. The command
3605 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3606 the first field of the @samp{info threads} display, with or without an
3607 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3608
3609 @value{GDBN} responds by displaying the system identifier of the
3610 thread you selected, and its current stack frame summary:
3611
3612 @smallexample
3613 (@value{GDBP}) thread 2
3614 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3615 #0 some_function (ignore=0x0) at example.c:8
3616 8 printf ("hello\n");
3617 @end smallexample
3618
3619 @noindent
3620 As with the @samp{[New @dots{}]} message, the form of the text after
3621 @samp{Switching to} depends on your system's conventions for identifying
3622 threads.
3623
3624 @anchor{thread apply all}
3625 @kindex thread apply
3626 @cindex apply command to several threads
3627 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3628 The @code{thread apply} command allows you to apply the named
3629 @var{command} to one or more threads. Specify the threads that you
3630 want affected using the thread ID list syntax (@pxref{thread ID
3631 lists}), or specify @code{all} to apply to all threads. To apply a
3632 command to all threads in descending order, type @kbd{thread apply all
3633 @var{command}}. To apply a command to all threads in ascending order,
3634 type @kbd{thread apply all -ascending @var{command}}.
3635
3636 The @var{flag} arguments control what output to produce and how to handle
3637 errors raised when applying @var{command} to a thread. @var{flag}
3638 must start with a @code{-} directly followed by one letter in
3639 @code{qcs}. If several flags are provided, they must be given
3640 individually, such as @code{-c -q}.
3641
3642 By default, @value{GDBN} displays some thread information before the
3643 output produced by @var{command}, and an error raised during the
3644 execution of a @var{command} will abort @code{thread apply}. The
3645 following flags can be used to fine-tune this behavior:
3646
3647 @table @code
3648 @item -c
3649 The flag @code{-c}, which stands for @samp{continue}, causes any
3650 errors in @var{command} to be displayed, and the execution of
3651 @code{thread apply} then continues.
3652 @item -s
3653 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3654 or empty output produced by a @var{command} to be silently ignored.
3655 That is, the execution continues, but the thread information and errors
3656 are not printed.
3657 @item -q
3658 The flag @code{-q} (@samp{quiet}) disables printing the thread
3659 information.
3660 @end table
3661
3662 Flags @code{-c} and @code{-s} cannot be used together.
3663
3664 @kindex taas
3665 @cindex apply command to all threads (ignoring errors and empty output)
3666 @item taas [@var{option}]@dots{} @var{command}
3667 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3668 Applies @var{command} on all threads, ignoring errors and empty output.
3669
3670 The @code{taas} command accepts the same options as the @code{thread
3671 apply all} command. @xref{thread apply all}.
3672
3673 @kindex tfaas
3674 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3675 @item tfaas [@var{option}]@dots{} @var{command}
3676 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3677 Applies @var{command} on all frames of all threads, ignoring errors
3678 and empty output. Note that the flag @code{-s} is specified twice:
3679 The first @code{-s} ensures that @code{thread apply} only shows the thread
3680 information of the threads for which @code{frame apply} produces
3681 some output. The second @code{-s} is needed to ensure that @code{frame
3682 apply} shows the frame information of a frame only if the
3683 @var{command} successfully produced some output.
3684
3685 It can for example be used to print a local variable or a function
3686 argument without knowing the thread or frame where this variable or argument
3687 is, using:
3688 @smallexample
3689 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3690 @end smallexample
3691
3692 The @code{tfaas} command accepts the same options as the @code{frame
3693 apply} command. @xref{frame apply}.
3694
3695 @kindex thread name
3696 @cindex name a thread
3697 @item thread name [@var{name}]
3698 This command assigns a name to the current thread. If no argument is
3699 given, any existing user-specified name is removed. The thread name
3700 appears in the @samp{info threads} display.
3701
3702 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3703 determine the name of the thread as given by the OS. On these
3704 systems, a name specified with @samp{thread name} will override the
3705 system-give name, and removing the user-specified name will cause
3706 @value{GDBN} to once again display the system-specified name.
3707
3708 @kindex thread find
3709 @cindex search for a thread
3710 @item thread find [@var{regexp}]
3711 Search for and display thread ids whose name or @var{systag}
3712 matches the supplied regular expression.
3713
3714 As well as being the complement to the @samp{thread name} command,
3715 this command also allows you to identify a thread by its target
3716 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3717 is the LWP id.
3718
3719 @smallexample
3720 (@value{GDBN}) thread find 26688
3721 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3722 (@value{GDBN}) info thread 4
3723 Id Target Id Frame
3724 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3725 @end smallexample
3726
3727 @kindex set print thread-events
3728 @cindex print messages on thread start and exit
3729 @item set print thread-events
3730 @itemx set print thread-events on
3731 @itemx set print thread-events off
3732 The @code{set print thread-events} command allows you to enable or
3733 disable printing of messages when @value{GDBN} notices that new threads have
3734 started or that threads have exited. By default, these messages will
3735 be printed if detection of these events is supported by the target.
3736 Note that these messages cannot be disabled on all targets.
3737
3738 @kindex show print thread-events
3739 @item show print thread-events
3740 Show whether messages will be printed when @value{GDBN} detects that threads
3741 have started and exited.
3742 @end table
3743
3744 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3745 more information about how @value{GDBN} behaves when you stop and start
3746 programs with multiple threads.
3747
3748 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3749 watchpoints in programs with multiple threads.
3750
3751 @anchor{set libthread-db-search-path}
3752 @table @code
3753 @kindex set libthread-db-search-path
3754 @cindex search path for @code{libthread_db}
3755 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3756 If this variable is set, @var{path} is a colon-separated list of
3757 directories @value{GDBN} will use to search for @code{libthread_db}.
3758 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3759 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3760 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3761 macro.
3762
3763 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3764 @code{libthread_db} library to obtain information about threads in the
3765 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3766 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3767 specific thread debugging library loading is enabled
3768 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3769
3770 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3771 refers to the default system directories that are
3772 normally searched for loading shared libraries. The @samp{$sdir} entry
3773 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3774 (@pxref{libthread_db.so.1 file}).
3775
3776 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3777 refers to the directory from which @code{libpthread}
3778 was loaded in the inferior process.
3779
3780 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3781 @value{GDBN} attempts to initialize it with the current inferior process.
3782 If this initialization fails (which could happen because of a version
3783 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3784 will unload @code{libthread_db}, and continue with the next directory.
3785 If none of @code{libthread_db} libraries initialize successfully,
3786 @value{GDBN} will issue a warning and thread debugging will be disabled.
3787
3788 Setting @code{libthread-db-search-path} is currently implemented
3789 only on some platforms.
3790
3791 @kindex show libthread-db-search-path
3792 @item show libthread-db-search-path
3793 Display current libthread_db search path.
3794
3795 @kindex set debug libthread-db
3796 @kindex show debug libthread-db
3797 @cindex debugging @code{libthread_db}
3798 @item set debug libthread-db
3799 @itemx show debug libthread-db
3800 Turns on or off display of @code{libthread_db}-related events.
3801 Use @code{1} to enable, @code{0} to disable.
3802 @end table
3803
3804 @node Forks
3805 @section Debugging Forks
3806
3807 @cindex fork, debugging programs which call
3808 @cindex multiple processes
3809 @cindex processes, multiple
3810 On most systems, @value{GDBN} has no special support for debugging
3811 programs which create additional processes using the @code{fork}
3812 function. When a program forks, @value{GDBN} will continue to debug the
3813 parent process and the child process will run unimpeded. If you have
3814 set a breakpoint in any code which the child then executes, the child
3815 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3816 will cause it to terminate.
3817
3818 However, if you want to debug the child process there is a workaround
3819 which isn't too painful. Put a call to @code{sleep} in the code which
3820 the child process executes after the fork. It may be useful to sleep
3821 only if a certain environment variable is set, or a certain file exists,
3822 so that the delay need not occur when you don't want to run @value{GDBN}
3823 on the child. While the child is sleeping, use the @code{ps} program to
3824 get its process ID. Then tell @value{GDBN} (a new invocation of
3825 @value{GDBN} if you are also debugging the parent process) to attach to
3826 the child process (@pxref{Attach}). From that point on you can debug
3827 the child process just like any other process which you attached to.
3828
3829 On some systems, @value{GDBN} provides support for debugging programs
3830 that create additional processes using the @code{fork} or @code{vfork}
3831 functions. On @sc{gnu}/Linux platforms, this feature is supported
3832 with kernel version 2.5.46 and later.
3833
3834 The fork debugging commands are supported in native mode and when
3835 connected to @code{gdbserver} in either @code{target remote} mode or
3836 @code{target extended-remote} mode.
3837
3838 By default, when a program forks, @value{GDBN} will continue to debug
3839 the parent process and the child process will run unimpeded.
3840
3841 If you want to follow the child process instead of the parent process,
3842 use the command @w{@code{set follow-fork-mode}}.
3843
3844 @table @code
3845 @kindex set follow-fork-mode
3846 @item set follow-fork-mode @var{mode}
3847 Set the debugger response to a program call of @code{fork} or
3848 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3849 process. The @var{mode} argument can be:
3850
3851 @table @code
3852 @item parent
3853 The original process is debugged after a fork. The child process runs
3854 unimpeded. This is the default.
3855
3856 @item child
3857 The new process is debugged after a fork. The parent process runs
3858 unimpeded.
3859
3860 @end table
3861
3862 @kindex show follow-fork-mode
3863 @item show follow-fork-mode
3864 Display the current debugger response to a @code{fork} or @code{vfork} call.
3865 @end table
3866
3867 @cindex debugging multiple processes
3868 On Linux, if you want to debug both the parent and child processes, use the
3869 command @w{@code{set detach-on-fork}}.
3870
3871 @table @code
3872 @kindex set detach-on-fork
3873 @item set detach-on-fork @var{mode}
3874 Tells gdb whether to detach one of the processes after a fork, or
3875 retain debugger control over them both.
3876
3877 @table @code
3878 @item on
3879 The child process (or parent process, depending on the value of
3880 @code{follow-fork-mode}) will be detached and allowed to run
3881 independently. This is the default.
3882
3883 @item off
3884 Both processes will be held under the control of @value{GDBN}.
3885 One process (child or parent, depending on the value of
3886 @code{follow-fork-mode}) is debugged as usual, while the other
3887 is held suspended.
3888
3889 @end table
3890
3891 @kindex show detach-on-fork
3892 @item show detach-on-fork
3893 Show whether detach-on-fork mode is on/off.
3894 @end table
3895
3896 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3897 will retain control of all forked processes (including nested forks).
3898 You can list the forked processes under the control of @value{GDBN} by
3899 using the @w{@code{info inferiors}} command, and switch from one fork
3900 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3901 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3902
3903 To quit debugging one of the forked processes, you can either detach
3904 from it by using the @w{@code{detach inferiors}} command (allowing it
3905 to run independently), or kill it using the @w{@code{kill inferiors}}
3906 command. @xref{Inferiors Connections and Programs, ,Debugging
3907 Multiple Inferiors Connections and Programs}.
3908
3909 If you ask to debug a child process and a @code{vfork} is followed by an
3910 @code{exec}, @value{GDBN} executes the new target up to the first
3911 breakpoint in the new target. If you have a breakpoint set on
3912 @code{main} in your original program, the breakpoint will also be set on
3913 the child process's @code{main}.
3914
3915 On some systems, when a child process is spawned by @code{vfork}, you
3916 cannot debug the child or parent until an @code{exec} call completes.
3917
3918 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3919 call executes, the new target restarts. To restart the parent
3920 process, use the @code{file} command with the parent executable name
3921 as its argument. By default, after an @code{exec} call executes,
3922 @value{GDBN} discards the symbols of the previous executable image.
3923 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3924 command.
3925
3926 @table @code
3927 @kindex set follow-exec-mode
3928 @item set follow-exec-mode @var{mode}
3929
3930 Set debugger response to a program call of @code{exec}. An
3931 @code{exec} call replaces the program image of a process.
3932
3933 @code{follow-exec-mode} can be:
3934
3935 @table @code
3936 @item new
3937 @value{GDBN} creates a new inferior and rebinds the process to this
3938 new inferior. The program the process was running before the
3939 @code{exec} call can be restarted afterwards by restarting the
3940 original inferior.
3941
3942 For example:
3943
3944 @smallexample
3945 (@value{GDBP}) info inferiors
3946 (gdb) info inferior
3947 Id Description Executable
3948 * 1 <null> prog1
3949 (@value{GDBP}) run
3950 process 12020 is executing new program: prog2
3951 Program exited normally.
3952 (@value{GDBP}) info inferiors
3953 Id Description Executable
3954 1 <null> prog1
3955 * 2 <null> prog2
3956 @end smallexample
3957
3958 @item same
3959 @value{GDBN} keeps the process bound to the same inferior. The new
3960 executable image replaces the previous executable loaded in the
3961 inferior. Restarting the inferior after the @code{exec} call, with
3962 e.g., the @code{run} command, restarts the executable the process was
3963 running after the @code{exec} call. This is the default mode.
3964
3965 For example:
3966
3967 @smallexample
3968 (@value{GDBP}) info inferiors
3969 Id Description Executable
3970 * 1 <null> prog1
3971 (@value{GDBP}) run
3972 process 12020 is executing new program: prog2
3973 Program exited normally.
3974 (@value{GDBP}) info inferiors
3975 Id Description Executable
3976 * 1 <null> prog2
3977 @end smallexample
3978
3979 @end table
3980 @end table
3981
3982 @code{follow-exec-mode} is supported in native mode and
3983 @code{target extended-remote} mode.
3984
3985 You can use the @code{catch} command to make @value{GDBN} stop whenever
3986 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3987 Catchpoints, ,Setting Catchpoints}.
3988
3989 @node Checkpoint/Restart
3990 @section Setting a @emph{Bookmark} to Return to Later
3991
3992 @cindex checkpoint
3993 @cindex restart
3994 @cindex bookmark
3995 @cindex snapshot of a process
3996 @cindex rewind program state
3997
3998 On certain operating systems@footnote{Currently, only
3999 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4000 program's state, called a @dfn{checkpoint}, and come back to it
4001 later.
4002
4003 Returning to a checkpoint effectively undoes everything that has
4004 happened in the program since the @code{checkpoint} was saved. This
4005 includes changes in memory, registers, and even (within some limits)
4006 system state. Effectively, it is like going back in time to the
4007 moment when the checkpoint was saved.
4008
4009 Thus, if you're stepping thru a program and you think you're
4010 getting close to the point where things go wrong, you can save
4011 a checkpoint. Then, if you accidentally go too far and miss
4012 the critical statement, instead of having to restart your program
4013 from the beginning, you can just go back to the checkpoint and
4014 start again from there.
4015
4016 This can be especially useful if it takes a lot of time or
4017 steps to reach the point where you think the bug occurs.
4018
4019 To use the @code{checkpoint}/@code{restart} method of debugging:
4020
4021 @table @code
4022 @kindex checkpoint
4023 @item checkpoint
4024 Save a snapshot of the debugged program's current execution state.
4025 The @code{checkpoint} command takes no arguments, but each checkpoint
4026 is assigned a small integer id, similar to a breakpoint id.
4027
4028 @kindex info checkpoints
4029 @item info checkpoints
4030 List the checkpoints that have been saved in the current debugging
4031 session. For each checkpoint, the following information will be
4032 listed:
4033
4034 @table @code
4035 @item Checkpoint ID
4036 @item Process ID
4037 @item Code Address
4038 @item Source line, or label
4039 @end table
4040
4041 @kindex restart @var{checkpoint-id}
4042 @item restart @var{checkpoint-id}
4043 Restore the program state that was saved as checkpoint number
4044 @var{checkpoint-id}. All program variables, registers, stack frames
4045 etc.@: will be returned to the values that they had when the checkpoint
4046 was saved. In essence, gdb will ``wind back the clock'' to the point
4047 in time when the checkpoint was saved.
4048
4049 Note that breakpoints, @value{GDBN} variables, command history etc.
4050 are not affected by restoring a checkpoint. In general, a checkpoint
4051 only restores things that reside in the program being debugged, not in
4052 the debugger.
4053
4054 @kindex delete checkpoint @var{checkpoint-id}
4055 @item delete checkpoint @var{checkpoint-id}
4056 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4057
4058 @end table
4059
4060 Returning to a previously saved checkpoint will restore the user state
4061 of the program being debugged, plus a significant subset of the system
4062 (OS) state, including file pointers. It won't ``un-write'' data from
4063 a file, but it will rewind the file pointer to the previous location,
4064 so that the previously written data can be overwritten. For files
4065 opened in read mode, the pointer will also be restored so that the
4066 previously read data can be read again.
4067
4068 Of course, characters that have been sent to a printer (or other
4069 external device) cannot be ``snatched back'', and characters received
4070 from eg.@: a serial device can be removed from internal program buffers,
4071 but they cannot be ``pushed back'' into the serial pipeline, ready to
4072 be received again. Similarly, the actual contents of files that have
4073 been changed cannot be restored (at this time).
4074
4075 However, within those constraints, you actually can ``rewind'' your
4076 program to a previously saved point in time, and begin debugging it
4077 again --- and you can change the course of events so as to debug a
4078 different execution path this time.
4079
4080 @cindex checkpoints and process id
4081 Finally, there is one bit of internal program state that will be
4082 different when you return to a checkpoint --- the program's process
4083 id. Each checkpoint will have a unique process id (or @var{pid}),
4084 and each will be different from the program's original @var{pid}.
4085 If your program has saved a local copy of its process id, this could
4086 potentially pose a problem.
4087
4088 @subsection A Non-obvious Benefit of Using Checkpoints
4089
4090 On some systems such as @sc{gnu}/Linux, address space randomization
4091 is performed on new processes for security reasons. This makes it
4092 difficult or impossible to set a breakpoint, or watchpoint, on an
4093 absolute address if you have to restart the program, since the
4094 absolute location of a symbol will change from one execution to the
4095 next.
4096
4097 A checkpoint, however, is an @emph{identical} copy of a process.
4098 Therefore if you create a checkpoint at (eg.@:) the start of main,
4099 and simply return to that checkpoint instead of restarting the
4100 process, you can avoid the effects of address randomization and
4101 your symbols will all stay in the same place.
4102
4103 @node Stopping
4104 @chapter Stopping and Continuing
4105
4106 The principal purposes of using a debugger are so that you can stop your
4107 program before it terminates; or so that, if your program runs into
4108 trouble, you can investigate and find out why.
4109
4110 Inside @value{GDBN}, your program may stop for any of several reasons,
4111 such as a signal, a breakpoint, or reaching a new line after a
4112 @value{GDBN} command such as @code{step}. You may then examine and
4113 change variables, set new breakpoints or remove old ones, and then
4114 continue execution. Usually, the messages shown by @value{GDBN} provide
4115 ample explanation of the status of your program---but you can also
4116 explicitly request this information at any time.
4117
4118 @table @code
4119 @kindex info program
4120 @item info program
4121 Display information about the status of your program: whether it is
4122 running or not, what process it is, and why it stopped.
4123 @end table
4124
4125 @menu
4126 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4127 * Continuing and Stepping:: Resuming execution
4128 * Skipping Over Functions and Files::
4129 Skipping over functions and files
4130 * Signals:: Signals
4131 * Thread Stops:: Stopping and starting multi-thread programs
4132 @end menu
4133
4134 @node Breakpoints
4135 @section Breakpoints, Watchpoints, and Catchpoints
4136
4137 @cindex breakpoints
4138 A @dfn{breakpoint} makes your program stop whenever a certain point in
4139 the program is reached. For each breakpoint, you can add conditions to
4140 control in finer detail whether your program stops. You can set
4141 breakpoints with the @code{break} command and its variants (@pxref{Set
4142 Breaks, ,Setting Breakpoints}), to specify the place where your program
4143 should stop by line number, function name or exact address in the
4144 program.
4145
4146 On some systems, you can set breakpoints in shared libraries before
4147 the executable is run.
4148
4149 @cindex watchpoints
4150 @cindex data breakpoints
4151 @cindex memory tracing
4152 @cindex breakpoint on memory address
4153 @cindex breakpoint on variable modification
4154 A @dfn{watchpoint} is a special breakpoint that stops your program
4155 when the value of an expression changes. The expression may be a value
4156 of a variable, or it could involve values of one or more variables
4157 combined by operators, such as @samp{a + b}. This is sometimes called
4158 @dfn{data breakpoints}. You must use a different command to set
4159 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4160 from that, you can manage a watchpoint like any other breakpoint: you
4161 enable, disable, and delete both breakpoints and watchpoints using the
4162 same commands.
4163
4164 You can arrange to have values from your program displayed automatically
4165 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4166 Automatic Display}.
4167
4168 @cindex catchpoints
4169 @cindex breakpoint on events
4170 A @dfn{catchpoint} is another special breakpoint that stops your program
4171 when a certain kind of event occurs, such as the throwing of a C@t{++}
4172 exception or the loading of a library. As with watchpoints, you use a
4173 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4174 Catchpoints}), but aside from that, you can manage a catchpoint like any
4175 other breakpoint. (To stop when your program receives a signal, use the
4176 @code{handle} command; see @ref{Signals, ,Signals}.)
4177
4178 @cindex breakpoint numbers
4179 @cindex numbers for breakpoints
4180 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4181 catchpoint when you create it; these numbers are successive integers
4182 starting with one. In many of the commands for controlling various
4183 features of breakpoints you use the breakpoint number to say which
4184 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4185 @dfn{disabled}; if disabled, it has no effect on your program until you
4186 enable it again.
4187
4188 @cindex breakpoint ranges
4189 @cindex breakpoint lists
4190 @cindex ranges of breakpoints
4191 @cindex lists of breakpoints
4192 Some @value{GDBN} commands accept a space-separated list of breakpoints
4193 on which to operate. A list element can be either a single breakpoint number,
4194 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4195 When a breakpoint list is given to a command, all breakpoints in that list
4196 are operated on.
4197
4198 @menu
4199 * Set Breaks:: Setting breakpoints
4200 * Set Watchpoints:: Setting watchpoints
4201 * Set Catchpoints:: Setting catchpoints
4202 * Delete Breaks:: Deleting breakpoints
4203 * Disabling:: Disabling breakpoints
4204 * Conditions:: Break conditions
4205 * Break Commands:: Breakpoint command lists
4206 * Dynamic Printf:: Dynamic printf
4207 * Save Breakpoints:: How to save breakpoints in a file
4208 * Static Probe Points:: Listing static probe points
4209 * Error in Breakpoints:: ``Cannot insert breakpoints''
4210 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4211 @end menu
4212
4213 @node Set Breaks
4214 @subsection Setting Breakpoints
4215
4216 @c FIXME LMB what does GDB do if no code on line of breakpt?
4217 @c consider in particular declaration with/without initialization.
4218 @c
4219 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4220
4221 @kindex break
4222 @kindex b @r{(@code{break})}
4223 @vindex $bpnum@r{, convenience variable}
4224 @cindex latest breakpoint
4225 Breakpoints are set with the @code{break} command (abbreviated
4226 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4227 number of the breakpoint you've set most recently; see @ref{Convenience
4228 Vars,, Convenience Variables}, for a discussion of what you can do with
4229 convenience variables.
4230
4231 @table @code
4232 @item break @var{location}
4233 Set a breakpoint at the given @var{location}, which can specify a
4234 function name, a line number, or an address of an instruction.
4235 (@xref{Specify Location}, for a list of all the possible ways to
4236 specify a @var{location}.) The breakpoint will stop your program just
4237 before it executes any of the code in the specified @var{location}.
4238
4239 When using source languages that permit overloading of symbols, such as
4240 C@t{++}, a function name may refer to more than one possible place to break.
4241 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4242 that situation.
4243
4244 It is also possible to insert a breakpoint that will stop the program
4245 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4246 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4247
4248 @item break
4249 When called without any arguments, @code{break} sets a breakpoint at
4250 the next instruction to be executed in the selected stack frame
4251 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4252 innermost, this makes your program stop as soon as control
4253 returns to that frame. This is similar to the effect of a
4254 @code{finish} command in the frame inside the selected frame---except
4255 that @code{finish} does not leave an active breakpoint. If you use
4256 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4257 the next time it reaches the current location; this may be useful
4258 inside loops.
4259
4260 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4261 least one instruction has been executed. If it did not do this, you
4262 would be unable to proceed past a breakpoint without first disabling the
4263 breakpoint. This rule applies whether or not the breakpoint already
4264 existed when your program stopped.
4265
4266 @item break @dots{} if @var{cond}
4267 Set a breakpoint with condition @var{cond}; evaluate the expression
4268 @var{cond} each time the breakpoint is reached, and stop only if the
4269 value is nonzero---that is, if @var{cond} evaluates as true.
4270 @samp{@dots{}} stands for one of the possible arguments described
4271 above (or no argument) specifying where to break. @xref{Conditions,
4272 ,Break Conditions}, for more information on breakpoint conditions.
4273
4274 @kindex tbreak
4275 @item tbreak @var{args}
4276 Set a breakpoint enabled only for one stop. The @var{args} are the
4277 same as for the @code{break} command, and the breakpoint is set in the same
4278 way, but the breakpoint is automatically deleted after the first time your
4279 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4280
4281 @kindex hbreak
4282 @cindex hardware breakpoints
4283 @item hbreak @var{args}
4284 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4285 @code{break} command and the breakpoint is set in the same way, but the
4286 breakpoint requires hardware support and some target hardware may not
4287 have this support. The main purpose of this is EPROM/ROM code
4288 debugging, so you can set a breakpoint at an instruction without
4289 changing the instruction. This can be used with the new trap-generation
4290 provided by SPARClite DSU and most x86-based targets. These targets
4291 will generate traps when a program accesses some data or instruction
4292 address that is assigned to the debug registers. However the hardware
4293 breakpoint registers can take a limited number of breakpoints. For
4294 example, on the DSU, only two data breakpoints can be set at a time, and
4295 @value{GDBN} will reject this command if more than two are used. Delete
4296 or disable unused hardware breakpoints before setting new ones
4297 (@pxref{Disabling, ,Disabling Breakpoints}).
4298 @xref{Conditions, ,Break Conditions}.
4299 For remote targets, you can restrict the number of hardware
4300 breakpoints @value{GDBN} will use, see @ref{set remote
4301 hardware-breakpoint-limit}.
4302
4303 @kindex thbreak
4304 @item thbreak @var{args}
4305 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4306 are the same as for the @code{hbreak} command and the breakpoint is set in
4307 the same way. However, like the @code{tbreak} command,
4308 the breakpoint is automatically deleted after the
4309 first time your program stops there. Also, like the @code{hbreak}
4310 command, the breakpoint requires hardware support and some target hardware
4311 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4312 See also @ref{Conditions, ,Break Conditions}.
4313
4314 @kindex rbreak
4315 @cindex regular expression
4316 @cindex breakpoints at functions matching a regexp
4317 @cindex set breakpoints in many functions
4318 @item rbreak @var{regex}
4319 Set breakpoints on all functions matching the regular expression
4320 @var{regex}. This command sets an unconditional breakpoint on all
4321 matches, printing a list of all breakpoints it set. Once these
4322 breakpoints are set, they are treated just like the breakpoints set with
4323 the @code{break} command. You can delete them, disable them, or make
4324 them conditional the same way as any other breakpoint.
4325
4326 In programs using different languages, @value{GDBN} chooses the syntax
4327 to print the list of all breakpoints it sets according to the
4328 @samp{set language} value: using @samp{set language auto}
4329 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4330 language of the breakpoint's function, other values mean to use
4331 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4332
4333 The syntax of the regular expression is the standard one used with tools
4334 like @file{grep}. Note that this is different from the syntax used by
4335 shells, so for instance @code{foo*} matches all functions that include
4336 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4337 @code{.*} leading and trailing the regular expression you supply, so to
4338 match only functions that begin with @code{foo}, use @code{^foo}.
4339
4340 @cindex non-member C@t{++} functions, set breakpoint in
4341 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4342 breakpoints on overloaded functions that are not members of any special
4343 classes.
4344
4345 @cindex set breakpoints on all functions
4346 The @code{rbreak} command can be used to set breakpoints in
4347 @strong{all} the functions in a program, like this:
4348
4349 @smallexample
4350 (@value{GDBP}) rbreak .
4351 @end smallexample
4352
4353 @item rbreak @var{file}:@var{regex}
4354 If @code{rbreak} is called with a filename qualification, it limits
4355 the search for functions matching the given regular expression to the
4356 specified @var{file}. This can be used, for example, to set breakpoints on
4357 every function in a given file:
4358
4359 @smallexample
4360 (@value{GDBP}) rbreak file.c:.
4361 @end smallexample
4362
4363 The colon separating the filename qualifier from the regex may
4364 optionally be surrounded by spaces.
4365
4366 @kindex info breakpoints
4367 @cindex @code{$_} and @code{info breakpoints}
4368 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4369 @itemx info break @r{[}@var{list}@dots{}@r{]}
4370 Print a table of all breakpoints, watchpoints, and catchpoints set and
4371 not deleted. Optional argument @var{n} means print information only
4372 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4373 For each breakpoint, following columns are printed:
4374
4375 @table @emph
4376 @item Breakpoint Numbers
4377 @item Type
4378 Breakpoint, watchpoint, or catchpoint.
4379 @item Disposition
4380 Whether the breakpoint is marked to be disabled or deleted when hit.
4381 @item Enabled or Disabled
4382 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4383 that are not enabled.
4384 @item Address
4385 Where the breakpoint is in your program, as a memory address. For a
4386 pending breakpoint whose address is not yet known, this field will
4387 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4388 library that has the symbol or line referred by breakpoint is loaded.
4389 See below for details. A breakpoint with several locations will
4390 have @samp{<MULTIPLE>} in this field---see below for details.
4391 @item What
4392 Where the breakpoint is in the source for your program, as a file and
4393 line number. For a pending breakpoint, the original string passed to
4394 the breakpoint command will be listed as it cannot be resolved until
4395 the appropriate shared library is loaded in the future.
4396 @end table
4397
4398 @noindent
4399 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4400 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4401 @value{GDBN} on the host's side. If it is ``target'', then the condition
4402 is evaluated by the target. The @code{info break} command shows
4403 the condition on the line following the affected breakpoint, together with
4404 its condition evaluation mode in between parentheses.
4405
4406 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4407 allowed to have a condition specified for it. The condition is not parsed for
4408 validity until a shared library is loaded that allows the pending
4409 breakpoint to resolve to a valid location.
4410
4411 @noindent
4412 @code{info break} with a breakpoint
4413 number @var{n} as argument lists only that breakpoint. The
4414 convenience variable @code{$_} and the default examining-address for
4415 the @code{x} command are set to the address of the last breakpoint
4416 listed (@pxref{Memory, ,Examining Memory}).
4417
4418 @noindent
4419 @code{info break} displays a count of the number of times the breakpoint
4420 has been hit. This is especially useful in conjunction with the
4421 @code{ignore} command. You can ignore a large number of breakpoint
4422 hits, look at the breakpoint info to see how many times the breakpoint
4423 was hit, and then run again, ignoring one less than that number. This
4424 will get you quickly to the last hit of that breakpoint.
4425
4426 @noindent
4427 For a breakpoints with an enable count (xref) greater than 1,
4428 @code{info break} also displays that count.
4429
4430 @end table
4431
4432 @value{GDBN} allows you to set any number of breakpoints at the same place in
4433 your program. There is nothing silly or meaningless about this. When
4434 the breakpoints are conditional, this is even useful
4435 (@pxref{Conditions, ,Break Conditions}).
4436
4437 @cindex multiple locations, breakpoints
4438 @cindex breakpoints, multiple locations
4439 It is possible that a breakpoint corresponds to several locations
4440 in your program. Examples of this situation are:
4441
4442 @itemize @bullet
4443 @item
4444 Multiple functions in the program may have the same name.
4445
4446 @item
4447 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4448 instances of the function body, used in different cases.
4449
4450 @item
4451 For a C@t{++} template function, a given line in the function can
4452 correspond to any number of instantiations.
4453
4454 @item
4455 For an inlined function, a given source line can correspond to
4456 several places where that function is inlined.
4457 @end itemize
4458
4459 In all those cases, @value{GDBN} will insert a breakpoint at all
4460 the relevant locations.
4461
4462 A breakpoint with multiple locations is displayed in the breakpoint
4463 table using several rows---one header row, followed by one row for
4464 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4465 address column. The rows for individual locations contain the actual
4466 addresses for locations, and show the functions to which those
4467 locations belong. The number column for a location is of the form
4468 @var{breakpoint-number}.@var{location-number}.
4469
4470 For example:
4471
4472 @smallexample
4473 Num Type Disp Enb Address What
4474 1 breakpoint keep y <MULTIPLE>
4475 stop only if i==1
4476 breakpoint already hit 1 time
4477 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4478 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4479 @end smallexample
4480
4481 You cannot delete the individual locations from a breakpoint. However,
4482 each location can be individually enabled or disabled by passing
4483 @var{breakpoint-number}.@var{location-number} as argument to the
4484 @code{enable} and @code{disable} commands. It's also possible to
4485 @code{enable} and @code{disable} a range of @var{location-number}
4486 locations using a @var{breakpoint-number} and two @var{location-number}s,
4487 in increasing order, separated by a hyphen, like
4488 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4489 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4490 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4491 all of the locations that belong to that breakpoint.
4492
4493 @cindex pending breakpoints
4494 It's quite common to have a breakpoint inside a shared library.
4495 Shared libraries can be loaded and unloaded explicitly,
4496 and possibly repeatedly, as the program is executed. To support
4497 this use case, @value{GDBN} updates breakpoint locations whenever
4498 any shared library is loaded or unloaded. Typically, you would
4499 set a breakpoint in a shared library at the beginning of your
4500 debugging session, when the library is not loaded, and when the
4501 symbols from the library are not available. When you try to set
4502 breakpoint, @value{GDBN} will ask you if you want to set
4503 a so called @dfn{pending breakpoint}---breakpoint whose address
4504 is not yet resolved.
4505
4506 After the program is run, whenever a new shared library is loaded,
4507 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4508 shared library contains the symbol or line referred to by some
4509 pending breakpoint, that breakpoint is resolved and becomes an
4510 ordinary breakpoint. When a library is unloaded, all breakpoints
4511 that refer to its symbols or source lines become pending again.
4512
4513 This logic works for breakpoints with multiple locations, too. For
4514 example, if you have a breakpoint in a C@t{++} template function, and
4515 a newly loaded shared library has an instantiation of that template,
4516 a new location is added to the list of locations for the breakpoint.
4517
4518 Except for having unresolved address, pending breakpoints do not
4519 differ from regular breakpoints. You can set conditions or commands,
4520 enable and disable them and perform other breakpoint operations.
4521
4522 @value{GDBN} provides some additional commands for controlling what
4523 happens when the @samp{break} command cannot resolve breakpoint
4524 address specification to an address:
4525
4526 @kindex set breakpoint pending
4527 @kindex show breakpoint pending
4528 @table @code
4529 @item set breakpoint pending auto
4530 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4531 location, it queries you whether a pending breakpoint should be created.
4532
4533 @item set breakpoint pending on
4534 This indicates that an unrecognized breakpoint location should automatically
4535 result in a pending breakpoint being created.
4536
4537 @item set breakpoint pending off
4538 This indicates that pending breakpoints are not to be created. Any
4539 unrecognized breakpoint location results in an error. This setting does
4540 not affect any pending breakpoints previously created.
4541
4542 @item show breakpoint pending
4543 Show the current behavior setting for creating pending breakpoints.
4544 @end table
4545
4546 The settings above only affect the @code{break} command and its
4547 variants. Once breakpoint is set, it will be automatically updated
4548 as shared libraries are loaded and unloaded.
4549
4550 @cindex automatic hardware breakpoints
4551 For some targets, @value{GDBN} can automatically decide if hardware or
4552 software breakpoints should be used, depending on whether the
4553 breakpoint address is read-only or read-write. This applies to
4554 breakpoints set with the @code{break} command as well as to internal
4555 breakpoints set by commands like @code{next} and @code{finish}. For
4556 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4557 breakpoints.
4558
4559 You can control this automatic behaviour with the following commands:
4560
4561 @kindex set breakpoint auto-hw
4562 @kindex show breakpoint auto-hw
4563 @table @code
4564 @item set breakpoint auto-hw on
4565 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4566 will try to use the target memory map to decide if software or hardware
4567 breakpoint must be used.
4568
4569 @item set breakpoint auto-hw off
4570 This indicates @value{GDBN} should not automatically select breakpoint
4571 type. If the target provides a memory map, @value{GDBN} will warn when
4572 trying to set software breakpoint at a read-only address.
4573 @end table
4574
4575 @value{GDBN} normally implements breakpoints by replacing the program code
4576 at the breakpoint address with a special instruction, which, when
4577 executed, given control to the debugger. By default, the program
4578 code is so modified only when the program is resumed. As soon as
4579 the program stops, @value{GDBN} restores the original instructions. This
4580 behaviour guards against leaving breakpoints inserted in the
4581 target should gdb abrubptly disconnect. However, with slow remote
4582 targets, inserting and removing breakpoint can reduce the performance.
4583 This behavior can be controlled with the following commands::
4584
4585 @kindex set breakpoint always-inserted
4586 @kindex show breakpoint always-inserted
4587 @table @code
4588 @item set breakpoint always-inserted off
4589 All breakpoints, including newly added by the user, are inserted in
4590 the target only when the target is resumed. All breakpoints are
4591 removed from the target when it stops. This is the default mode.
4592
4593 @item set breakpoint always-inserted on
4594 Causes all breakpoints to be inserted in the target at all times. If
4595 the user adds a new breakpoint, or changes an existing breakpoint, the
4596 breakpoints in the target are updated immediately. A breakpoint is
4597 removed from the target only when breakpoint itself is deleted.
4598 @end table
4599
4600 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4601 when a breakpoint breaks. If the condition is true, then the process being
4602 debugged stops, otherwise the process is resumed.
4603
4604 If the target supports evaluating conditions on its end, @value{GDBN} may
4605 download the breakpoint, together with its conditions, to it.
4606
4607 This feature can be controlled via the following commands:
4608
4609 @kindex set breakpoint condition-evaluation
4610 @kindex show breakpoint condition-evaluation
4611 @table @code
4612 @item set breakpoint condition-evaluation host
4613 This option commands @value{GDBN} to evaluate the breakpoint
4614 conditions on the host's side. Unconditional breakpoints are sent to
4615 the target which in turn receives the triggers and reports them back to GDB
4616 for condition evaluation. This is the standard evaluation mode.
4617
4618 @item set breakpoint condition-evaluation target
4619 This option commands @value{GDBN} to download breakpoint conditions
4620 to the target at the moment of their insertion. The target
4621 is responsible for evaluating the conditional expression and reporting
4622 breakpoint stop events back to @value{GDBN} whenever the condition
4623 is true. Due to limitations of target-side evaluation, some conditions
4624 cannot be evaluated there, e.g., conditions that depend on local data
4625 that is only known to the host. Examples include
4626 conditional expressions involving convenience variables, complex types
4627 that cannot be handled by the agent expression parser and expressions
4628 that are too long to be sent over to the target, specially when the
4629 target is a remote system. In these cases, the conditions will be
4630 evaluated by @value{GDBN}.
4631
4632 @item set breakpoint condition-evaluation auto
4633 This is the default mode. If the target supports evaluating breakpoint
4634 conditions on its end, @value{GDBN} will download breakpoint conditions to
4635 the target (limitations mentioned previously apply). If the target does
4636 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4637 to evaluating all these conditions on the host's side.
4638 @end table
4639
4640
4641 @cindex negative breakpoint numbers
4642 @cindex internal @value{GDBN} breakpoints
4643 @value{GDBN} itself sometimes sets breakpoints in your program for
4644 special purposes, such as proper handling of @code{longjmp} (in C
4645 programs). These internal breakpoints are assigned negative numbers,
4646 starting with @code{-1}; @samp{info breakpoints} does not display them.
4647 You can see these breakpoints with the @value{GDBN} maintenance command
4648 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4649
4650
4651 @node Set Watchpoints
4652 @subsection Setting Watchpoints
4653
4654 @cindex setting watchpoints
4655 You can use a watchpoint to stop execution whenever the value of an
4656 expression changes, without having to predict a particular place where
4657 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4658 The expression may be as simple as the value of a single variable, or
4659 as complex as many variables combined by operators. Examples include:
4660
4661 @itemize @bullet
4662 @item
4663 A reference to the value of a single variable.
4664
4665 @item
4666 An address cast to an appropriate data type. For example,
4667 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4668 address (assuming an @code{int} occupies 4 bytes).
4669
4670 @item
4671 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4672 expression can use any operators valid in the program's native
4673 language (@pxref{Languages}).
4674 @end itemize
4675
4676 You can set a watchpoint on an expression even if the expression can
4677 not be evaluated yet. For instance, you can set a watchpoint on
4678 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4679 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4680 the expression produces a valid value. If the expression becomes
4681 valid in some other way than changing a variable (e.g.@: if the memory
4682 pointed to by @samp{*global_ptr} becomes readable as the result of a
4683 @code{malloc} call), @value{GDBN} may not stop until the next time
4684 the expression changes.
4685
4686 @cindex software watchpoints
4687 @cindex hardware watchpoints
4688 Depending on your system, watchpoints may be implemented in software or
4689 hardware. @value{GDBN} does software watchpointing by single-stepping your
4690 program and testing the variable's value each time, which is hundreds of
4691 times slower than normal execution. (But this may still be worth it, to
4692 catch errors where you have no clue what part of your program is the
4693 culprit.)
4694
4695 On some systems, such as most PowerPC or x86-based targets,
4696 @value{GDBN} includes support for hardware watchpoints, which do not
4697 slow down the running of your program.
4698
4699 @table @code
4700 @kindex watch
4701 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4702 Set a watchpoint for an expression. @value{GDBN} will break when the
4703 expression @var{expr} is written into by the program and its value
4704 changes. The simplest (and the most popular) use of this command is
4705 to watch the value of a single variable:
4706
4707 @smallexample
4708 (@value{GDBP}) watch foo
4709 @end smallexample
4710
4711 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4712 argument, @value{GDBN} breaks only when the thread identified by
4713 @var{thread-id} changes the value of @var{expr}. If any other threads
4714 change the value of @var{expr}, @value{GDBN} will not break. Note
4715 that watchpoints restricted to a single thread in this way only work
4716 with Hardware Watchpoints.
4717
4718 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4719 (see below). The @code{-location} argument tells @value{GDBN} to
4720 instead watch the memory referred to by @var{expr}. In this case,
4721 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4722 and watch the memory at that address. The type of the result is used
4723 to determine the size of the watched memory. If the expression's
4724 result does not have an address, then @value{GDBN} will print an
4725 error.
4726
4727 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4728 of masked watchpoints, if the current architecture supports this
4729 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4730 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4731 to an address to watch. The mask specifies that some bits of an address
4732 (the bits which are reset in the mask) should be ignored when matching
4733 the address accessed by the inferior against the watchpoint address.
4734 Thus, a masked watchpoint watches many addresses simultaneously---those
4735 addresses whose unmasked bits are identical to the unmasked bits in the
4736 watchpoint address. The @code{mask} argument implies @code{-location}.
4737 Examples:
4738
4739 @smallexample
4740 (@value{GDBP}) watch foo mask 0xffff00ff
4741 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4742 @end smallexample
4743
4744 @kindex rwatch
4745 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4746 Set a watchpoint that will break when the value of @var{expr} is read
4747 by the program.
4748
4749 @kindex awatch
4750 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4751 Set a watchpoint that will break when @var{expr} is either read from
4752 or written into by the program.
4753
4754 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4755 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4756 This command prints a list of watchpoints, using the same format as
4757 @code{info break} (@pxref{Set Breaks}).
4758 @end table
4759
4760 If you watch for a change in a numerically entered address you need to
4761 dereference it, as the address itself is just a constant number which will
4762 never change. @value{GDBN} refuses to create a watchpoint that watches
4763 a never-changing value:
4764
4765 @smallexample
4766 (@value{GDBP}) watch 0x600850
4767 Cannot watch constant value 0x600850.
4768 (@value{GDBP}) watch *(int *) 0x600850
4769 Watchpoint 1: *(int *) 6293584
4770 @end smallexample
4771
4772 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4773 watchpoints execute very quickly, and the debugger reports a change in
4774 value at the exact instruction where the change occurs. If @value{GDBN}
4775 cannot set a hardware watchpoint, it sets a software watchpoint, which
4776 executes more slowly and reports the change in value at the next
4777 @emph{statement}, not the instruction, after the change occurs.
4778
4779 @cindex use only software watchpoints
4780 You can force @value{GDBN} to use only software watchpoints with the
4781 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4782 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4783 the underlying system supports them. (Note that hardware-assisted
4784 watchpoints that were set @emph{before} setting
4785 @code{can-use-hw-watchpoints} to zero will still use the hardware
4786 mechanism of watching expression values.)
4787
4788 @table @code
4789 @item set can-use-hw-watchpoints
4790 @kindex set can-use-hw-watchpoints
4791 Set whether or not to use hardware watchpoints.
4792
4793 @item show can-use-hw-watchpoints
4794 @kindex show can-use-hw-watchpoints
4795 Show the current mode of using hardware watchpoints.
4796 @end table
4797
4798 For remote targets, you can restrict the number of hardware
4799 watchpoints @value{GDBN} will use, see @ref{set remote
4800 hardware-breakpoint-limit}.
4801
4802 When you issue the @code{watch} command, @value{GDBN} reports
4803
4804 @smallexample
4805 Hardware watchpoint @var{num}: @var{expr}
4806 @end smallexample
4807
4808 @noindent
4809 if it was able to set a hardware watchpoint.
4810
4811 Currently, the @code{awatch} and @code{rwatch} commands can only set
4812 hardware watchpoints, because accesses to data that don't change the
4813 value of the watched expression cannot be detected without examining
4814 every instruction as it is being executed, and @value{GDBN} does not do
4815 that currently. If @value{GDBN} finds that it is unable to set a
4816 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4817 will print a message like this:
4818
4819 @smallexample
4820 Expression cannot be implemented with read/access watchpoint.
4821 @end smallexample
4822
4823 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4824 data type of the watched expression is wider than what a hardware
4825 watchpoint on the target machine can handle. For example, some systems
4826 can only watch regions that are up to 4 bytes wide; on such systems you
4827 cannot set hardware watchpoints for an expression that yields a
4828 double-precision floating-point number (which is typically 8 bytes
4829 wide). As a work-around, it might be possible to break the large region
4830 into a series of smaller ones and watch them with separate watchpoints.
4831
4832 If you set too many hardware watchpoints, @value{GDBN} might be unable
4833 to insert all of them when you resume the execution of your program.
4834 Since the precise number of active watchpoints is unknown until such
4835 time as the program is about to be resumed, @value{GDBN} might not be
4836 able to warn you about this when you set the watchpoints, and the
4837 warning will be printed only when the program is resumed:
4838
4839 @smallexample
4840 Hardware watchpoint @var{num}: Could not insert watchpoint
4841 @end smallexample
4842
4843 @noindent
4844 If this happens, delete or disable some of the watchpoints.
4845
4846 Watching complex expressions that reference many variables can also
4847 exhaust the resources available for hardware-assisted watchpoints.
4848 That's because @value{GDBN} needs to watch every variable in the
4849 expression with separately allocated resources.
4850
4851 If you call a function interactively using @code{print} or @code{call},
4852 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4853 kind of breakpoint or the call completes.
4854
4855 @value{GDBN} automatically deletes watchpoints that watch local
4856 (automatic) variables, or expressions that involve such variables, when
4857 they go out of scope, that is, when the execution leaves the block in
4858 which these variables were defined. In particular, when the program
4859 being debugged terminates, @emph{all} local variables go out of scope,
4860 and so only watchpoints that watch global variables remain set. If you
4861 rerun the program, you will need to set all such watchpoints again. One
4862 way of doing that would be to set a code breakpoint at the entry to the
4863 @code{main} function and when it breaks, set all the watchpoints.
4864
4865 @cindex watchpoints and threads
4866 @cindex threads and watchpoints
4867 In multi-threaded programs, watchpoints will detect changes to the
4868 watched expression from every thread.
4869
4870 @quotation
4871 @emph{Warning:} In multi-threaded programs, software watchpoints
4872 have only limited usefulness. If @value{GDBN} creates a software
4873 watchpoint, it can only watch the value of an expression @emph{in a
4874 single thread}. If you are confident that the expression can only
4875 change due to the current thread's activity (and if you are also
4876 confident that no other thread can become current), then you can use
4877 software watchpoints as usual. However, @value{GDBN} may not notice
4878 when a non-current thread's activity changes the expression. (Hardware
4879 watchpoints, in contrast, watch an expression in all threads.)
4880 @end quotation
4881
4882 @xref{set remote hardware-watchpoint-limit}.
4883
4884 @node Set Catchpoints
4885 @subsection Setting Catchpoints
4886 @cindex catchpoints, setting
4887 @cindex exception handlers
4888 @cindex event handling
4889
4890 You can use @dfn{catchpoints} to cause the debugger to stop for certain
4891 kinds of program events, such as C@t{++} exceptions or the loading of a
4892 shared library. Use the @code{catch} command to set a catchpoint.
4893
4894 @table @code
4895 @kindex catch
4896 @item catch @var{event}
4897 Stop when @var{event} occurs. The @var{event} can be any of the following:
4898
4899 @table @code
4900 @item throw @r{[}@var{regexp}@r{]}
4901 @itemx rethrow @r{[}@var{regexp}@r{]}
4902 @itemx catch @r{[}@var{regexp}@r{]}
4903 @kindex catch throw
4904 @kindex catch rethrow
4905 @kindex catch catch
4906 @cindex stop on C@t{++} exceptions
4907 The throwing, re-throwing, or catching of a C@t{++} exception.
4908
4909 If @var{regexp} is given, then only exceptions whose type matches the
4910 regular expression will be caught.
4911
4912 @vindex $_exception@r{, convenience variable}
4913 The convenience variable @code{$_exception} is available at an
4914 exception-related catchpoint, on some systems. This holds the
4915 exception being thrown.
4916
4917 There are currently some limitations to C@t{++} exception handling in
4918 @value{GDBN}:
4919
4920 @itemize @bullet
4921 @item
4922 The support for these commands is system-dependent. Currently, only
4923 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4924 supported.
4925
4926 @item
4927 The regular expression feature and the @code{$_exception} convenience
4928 variable rely on the presence of some SDT probes in @code{libstdc++}.
4929 If these probes are not present, then these features cannot be used.
4930 These probes were first available in the GCC 4.8 release, but whether
4931 or not they are available in your GCC also depends on how it was
4932 built.
4933
4934 @item
4935 The @code{$_exception} convenience variable is only valid at the
4936 instruction at which an exception-related catchpoint is set.
4937
4938 @item
4939 When an exception-related catchpoint is hit, @value{GDBN} stops at a
4940 location in the system library which implements runtime exception
4941 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4942 (@pxref{Selection}) to get to your code.
4943
4944 @item
4945 If you call a function interactively, @value{GDBN} normally returns
4946 control to you when the function has finished executing. If the call
4947 raises an exception, however, the call may bypass the mechanism that
4948 returns control to you and cause your program either to abort or to
4949 simply continue running until it hits a breakpoint, catches a signal
4950 that @value{GDBN} is listening for, or exits. This is the case even if
4951 you set a catchpoint for the exception; catchpoints on exceptions are
4952 disabled within interactive calls. @xref{Calling}, for information on
4953 controlling this with @code{set unwind-on-terminating-exception}.
4954
4955 @item
4956 You cannot raise an exception interactively.
4957
4958 @item
4959 You cannot install an exception handler interactively.
4960 @end itemize
4961
4962 @item exception @r{[}@var{name}@r{]}
4963 @kindex catch exception
4964 @cindex Ada exception catching
4965 @cindex catch Ada exceptions
4966 An Ada exception being raised. If an exception name is specified
4967 at the end of the command (eg @code{catch exception Program_Error}),
4968 the debugger will stop only when this specific exception is raised.
4969 Otherwise, the debugger stops execution when any Ada exception is raised.
4970
4971 When inserting an exception catchpoint on a user-defined exception whose
4972 name is identical to one of the exceptions defined by the language, the
4973 fully qualified name must be used as the exception name. Otherwise,
4974 @value{GDBN} will assume that it should stop on the pre-defined exception
4975 rather than the user-defined one. For instance, assuming an exception
4976 called @code{Constraint_Error} is defined in package @code{Pck}, then
4977 the command to use to catch such exceptions is @kbd{catch exception
4978 Pck.Constraint_Error}.
4979
4980 @vindex $_ada_exception@r{, convenience variable}
4981 The convenience variable @code{$_ada_exception} holds the address of
4982 the exception being thrown. This can be useful when setting a
4983 condition for such a catchpoint.
4984
4985 @item exception unhandled
4986 @kindex catch exception unhandled
4987 An exception that was raised but is not handled by the program. The
4988 convenience variable @code{$_ada_exception} is set as for @code{catch
4989 exception}.
4990
4991 @item handlers @r{[}@var{name}@r{]}
4992 @kindex catch handlers
4993 @cindex Ada exception handlers catching
4994 @cindex catch Ada exceptions when handled
4995 An Ada exception being handled. If an exception name is
4996 specified at the end of the command
4997 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4998 only when this specific exception is handled.
4999 Otherwise, the debugger stops execution when any Ada exception is handled.
5000
5001 When inserting a handlers catchpoint on a user-defined
5002 exception whose name is identical to one of the exceptions
5003 defined by the language, the fully qualified name must be used
5004 as the exception name. Otherwise, @value{GDBN} will assume that it
5005 should stop on the pre-defined exception rather than the
5006 user-defined one. For instance, assuming an exception called
5007 @code{Constraint_Error} is defined in package @code{Pck}, then the
5008 command to use to catch such exceptions handling is
5009 @kbd{catch handlers Pck.Constraint_Error}.
5010
5011 The convenience variable @code{$_ada_exception} is set as for
5012 @code{catch exception}.
5013
5014 @item assert
5015 @kindex catch assert
5016 A failed Ada assertion. Note that the convenience variable
5017 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5018
5019 @item exec
5020 @kindex catch exec
5021 @cindex break on fork/exec
5022 A call to @code{exec}.
5023
5024 @anchor{catch syscall}
5025 @item syscall
5026 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5027 @kindex catch syscall
5028 @cindex break on a system call.
5029 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5030 syscall is a mechanism for application programs to request a service
5031 from the operating system (OS) or one of the OS system services.
5032 @value{GDBN} can catch some or all of the syscalls issued by the
5033 debuggee, and show the related information for each syscall. If no
5034 argument is specified, calls to and returns from all system calls
5035 will be caught.
5036
5037 @var{name} can be any system call name that is valid for the
5038 underlying OS. Just what syscalls are valid depends on the OS. On
5039 GNU and Unix systems, you can find the full list of valid syscall
5040 names on @file{/usr/include/asm/unistd.h}.
5041
5042 @c For MS-Windows, the syscall names and the corresponding numbers
5043 @c can be found, e.g., on this URL:
5044 @c http://www.metasploit.com/users/opcode/syscalls.html
5045 @c but we don't support Windows syscalls yet.
5046
5047 Normally, @value{GDBN} knows in advance which syscalls are valid for
5048 each OS, so you can use the @value{GDBN} command-line completion
5049 facilities (@pxref{Completion,, command completion}) to list the
5050 available choices.
5051
5052 You may also specify the system call numerically. A syscall's
5053 number is the value passed to the OS's syscall dispatcher to
5054 identify the requested service. When you specify the syscall by its
5055 name, @value{GDBN} uses its database of syscalls to convert the name
5056 into the corresponding numeric code, but using the number directly
5057 may be useful if @value{GDBN}'s database does not have the complete
5058 list of syscalls on your system (e.g., because @value{GDBN} lags
5059 behind the OS upgrades).
5060
5061 You may specify a group of related syscalls to be caught at once using
5062 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5063 instance, on some platforms @value{GDBN} allows you to catch all
5064 network related syscalls, by passing the argument @code{group:network}
5065 to @code{catch syscall}. Note that not all syscall groups are
5066 available in every system. You can use the command completion
5067 facilities (@pxref{Completion,, command completion}) to list the
5068 syscall groups available on your environment.
5069
5070 The example below illustrates how this command works if you don't provide
5071 arguments to it:
5072
5073 @smallexample
5074 (@value{GDBP}) catch syscall
5075 Catchpoint 1 (syscall)
5076 (@value{GDBP}) r
5077 Starting program: /tmp/catch-syscall
5078
5079 Catchpoint 1 (call to syscall 'close'), \
5080 0xffffe424 in __kernel_vsyscall ()
5081 (@value{GDBP}) c
5082 Continuing.
5083
5084 Catchpoint 1 (returned from syscall 'close'), \
5085 0xffffe424 in __kernel_vsyscall ()
5086 (@value{GDBP})
5087 @end smallexample
5088
5089 Here is an example of catching a system call by name:
5090
5091 @smallexample
5092 (@value{GDBP}) catch syscall chroot
5093 Catchpoint 1 (syscall 'chroot' [61])
5094 (@value{GDBP}) r
5095 Starting program: /tmp/catch-syscall
5096
5097 Catchpoint 1 (call to syscall 'chroot'), \
5098 0xffffe424 in __kernel_vsyscall ()
5099 (@value{GDBP}) c
5100 Continuing.
5101
5102 Catchpoint 1 (returned from syscall 'chroot'), \
5103 0xffffe424 in __kernel_vsyscall ()
5104 (@value{GDBP})
5105 @end smallexample
5106
5107 An example of specifying a system call numerically. In the case
5108 below, the syscall number has a corresponding entry in the XML
5109 file, so @value{GDBN} finds its name and prints it:
5110
5111 @smallexample
5112 (@value{GDBP}) catch syscall 252
5113 Catchpoint 1 (syscall(s) 'exit_group')
5114 (@value{GDBP}) r
5115 Starting program: /tmp/catch-syscall
5116
5117 Catchpoint 1 (call to syscall 'exit_group'), \
5118 0xffffe424 in __kernel_vsyscall ()
5119 (@value{GDBP}) c
5120 Continuing.
5121
5122 Program exited normally.
5123 (@value{GDBP})
5124 @end smallexample
5125
5126 Here is an example of catching a syscall group:
5127
5128 @smallexample
5129 (@value{GDBP}) catch syscall group:process
5130 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5131 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5132 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5133 (@value{GDBP}) r
5134 Starting program: /tmp/catch-syscall
5135
5136 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5137 from /lib64/ld-linux-x86-64.so.2
5138
5139 (@value{GDBP}) c
5140 Continuing.
5141 @end smallexample
5142
5143 However, there can be situations when there is no corresponding name
5144 in XML file for that syscall number. In this case, @value{GDBN} prints
5145 a warning message saying that it was not able to find the syscall name,
5146 but the catchpoint will be set anyway. See the example below:
5147
5148 @smallexample
5149 (@value{GDBP}) catch syscall 764
5150 warning: The number '764' does not represent a known syscall.
5151 Catchpoint 2 (syscall 764)
5152 (@value{GDBP})
5153 @end smallexample
5154
5155 If you configure @value{GDBN} using the @samp{--without-expat} option,
5156 it will not be able to display syscall names. Also, if your
5157 architecture does not have an XML file describing its system calls,
5158 you will not be able to see the syscall names. It is important to
5159 notice that these two features are used for accessing the syscall
5160 name database. In either case, you will see a warning like this:
5161
5162 @smallexample
5163 (@value{GDBP}) catch syscall
5164 warning: Could not open "syscalls/i386-linux.xml"
5165 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5166 GDB will not be able to display syscall names.
5167 Catchpoint 1 (syscall)
5168 (@value{GDBP})
5169 @end smallexample
5170
5171 Of course, the file name will change depending on your architecture and system.
5172
5173 Still using the example above, you can also try to catch a syscall by its
5174 number. In this case, you would see something like:
5175
5176 @smallexample
5177 (@value{GDBP}) catch syscall 252
5178 Catchpoint 1 (syscall(s) 252)
5179 @end smallexample
5180
5181 Again, in this case @value{GDBN} would not be able to display syscall's names.
5182
5183 @item fork
5184 @kindex catch fork
5185 A call to @code{fork}.
5186
5187 @item vfork
5188 @kindex catch vfork
5189 A call to @code{vfork}.
5190
5191 @item load @r{[}@var{regexp}@r{]}
5192 @itemx unload @r{[}@var{regexp}@r{]}
5193 @kindex catch load
5194 @kindex catch unload
5195 The loading or unloading of a shared library. If @var{regexp} is
5196 given, then the catchpoint will stop only if the regular expression
5197 matches one of the affected libraries.
5198
5199 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5200 @kindex catch signal
5201 The delivery of a signal.
5202
5203 With no arguments, this catchpoint will catch any signal that is not
5204 used internally by @value{GDBN}, specifically, all signals except
5205 @samp{SIGTRAP} and @samp{SIGINT}.
5206
5207 With the argument @samp{all}, all signals, including those used by
5208 @value{GDBN}, will be caught. This argument cannot be used with other
5209 signal names.
5210
5211 Otherwise, the arguments are a list of signal names as given to
5212 @code{handle} (@pxref{Signals}). Only signals specified in this list
5213 will be caught.
5214
5215 One reason that @code{catch signal} can be more useful than
5216 @code{handle} is that you can attach commands and conditions to the
5217 catchpoint.
5218
5219 When a signal is caught by a catchpoint, the signal's @code{stop} and
5220 @code{print} settings, as specified by @code{handle}, are ignored.
5221 However, whether the signal is still delivered to the inferior depends
5222 on the @code{pass} setting; this can be changed in the catchpoint's
5223 commands.
5224
5225 @end table
5226
5227 @item tcatch @var{event}
5228 @kindex tcatch
5229 Set a catchpoint that is enabled only for one stop. The catchpoint is
5230 automatically deleted after the first time the event is caught.
5231
5232 @end table
5233
5234 Use the @code{info break} command to list the current catchpoints.
5235
5236
5237 @node Delete Breaks
5238 @subsection Deleting Breakpoints
5239
5240 @cindex clearing breakpoints, watchpoints, catchpoints
5241 @cindex deleting breakpoints, watchpoints, catchpoints
5242 It is often necessary to eliminate a breakpoint, watchpoint, or
5243 catchpoint once it has done its job and you no longer want your program
5244 to stop there. This is called @dfn{deleting} the breakpoint. A
5245 breakpoint that has been deleted no longer exists; it is forgotten.
5246
5247 With the @code{clear} command you can delete breakpoints according to
5248 where they are in your program. With the @code{delete} command you can
5249 delete individual breakpoints, watchpoints, or catchpoints by specifying
5250 their breakpoint numbers.
5251
5252 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5253 automatically ignores breakpoints on the first instruction to be executed
5254 when you continue execution without changing the execution address.
5255
5256 @table @code
5257 @kindex clear
5258 @item clear
5259 Delete any breakpoints at the next instruction to be executed in the
5260 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5261 the innermost frame is selected, this is a good way to delete a
5262 breakpoint where your program just stopped.
5263
5264 @item clear @var{location}
5265 Delete any breakpoints set at the specified @var{location}.
5266 @xref{Specify Location}, for the various forms of @var{location}; the
5267 most useful ones are listed below:
5268
5269 @table @code
5270 @item clear @var{function}
5271 @itemx clear @var{filename}:@var{function}
5272 Delete any breakpoints set at entry to the named @var{function}.
5273
5274 @item clear @var{linenum}
5275 @itemx clear @var{filename}:@var{linenum}
5276 Delete any breakpoints set at or within the code of the specified
5277 @var{linenum} of the specified @var{filename}.
5278 @end table
5279
5280 @cindex delete breakpoints
5281 @kindex delete
5282 @kindex d @r{(@code{delete})}
5283 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5284 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5285 list specified as argument. If no argument is specified, delete all
5286 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5287 confirm off}). You can abbreviate this command as @code{d}.
5288 @end table
5289
5290 @node Disabling
5291 @subsection Disabling Breakpoints
5292
5293 @cindex enable/disable a breakpoint
5294 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5295 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5296 it had been deleted, but remembers the information on the breakpoint so
5297 that you can @dfn{enable} it again later.
5298
5299 You disable and enable breakpoints, watchpoints, and catchpoints with
5300 the @code{enable} and @code{disable} commands, optionally specifying
5301 one or more breakpoint numbers as arguments. Use @code{info break} to
5302 print a list of all breakpoints, watchpoints, and catchpoints if you
5303 do not know which numbers to use.
5304
5305 Disabling and enabling a breakpoint that has multiple locations
5306 affects all of its locations.
5307
5308 A breakpoint, watchpoint, or catchpoint can have any of several
5309 different states of enablement:
5310
5311 @itemize @bullet
5312 @item
5313 Enabled. The breakpoint stops your program. A breakpoint set
5314 with the @code{break} command starts out in this state.
5315 @item
5316 Disabled. The breakpoint has no effect on your program.
5317 @item
5318 Enabled once. The breakpoint stops your program, but then becomes
5319 disabled.
5320 @item
5321 Enabled for a count. The breakpoint stops your program for the next
5322 N times, then becomes disabled.
5323 @item
5324 Enabled for deletion. The breakpoint stops your program, but
5325 immediately after it does so it is deleted permanently. A breakpoint
5326 set with the @code{tbreak} command starts out in this state.
5327 @end itemize
5328
5329 You can use the following commands to enable or disable breakpoints,
5330 watchpoints, and catchpoints:
5331
5332 @table @code
5333 @kindex disable
5334 @kindex dis @r{(@code{disable})}
5335 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5336 Disable the specified breakpoints---or all breakpoints, if none are
5337 listed. A disabled breakpoint has no effect but is not forgotten. All
5338 options such as ignore-counts, conditions and commands are remembered in
5339 case the breakpoint is enabled again later. You may abbreviate
5340 @code{disable} as @code{dis}.
5341
5342 @kindex enable
5343 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5344 Enable the specified breakpoints (or all defined breakpoints). They
5345 become effective once again in stopping your program.
5346
5347 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5348 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5349 of these breakpoints immediately after stopping your program.
5350
5351 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5352 Enable the specified breakpoints temporarily. @value{GDBN} records
5353 @var{count} with each of the specified breakpoints, and decrements a
5354 breakpoint's count when it is hit. When any count reaches 0,
5355 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5356 count (@pxref{Conditions, ,Break Conditions}), that will be
5357 decremented to 0 before @var{count} is affected.
5358
5359 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5360 Enable the specified breakpoints to work once, then die. @value{GDBN}
5361 deletes any of these breakpoints as soon as your program stops there.
5362 Breakpoints set by the @code{tbreak} command start out in this state.
5363 @end table
5364
5365 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5366 @c confusing: tbreak is also initially enabled.
5367 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5368 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5369 subsequently, they become disabled or enabled only when you use one of
5370 the commands above. (The command @code{until} can set and delete a
5371 breakpoint of its own, but it does not change the state of your other
5372 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5373 Stepping}.)
5374
5375 @node Conditions
5376 @subsection Break Conditions
5377 @cindex conditional breakpoints
5378 @cindex breakpoint conditions
5379
5380 @c FIXME what is scope of break condition expr? Context where wanted?
5381 @c in particular for a watchpoint?
5382 The simplest sort of breakpoint breaks every time your program reaches a
5383 specified place. You can also specify a @dfn{condition} for a
5384 breakpoint. A condition is just a Boolean expression in your
5385 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5386 a condition evaluates the expression each time your program reaches it,
5387 and your program stops only if the condition is @emph{true}.
5388
5389 This is the converse of using assertions for program validation; in that
5390 situation, you want to stop when the assertion is violated---that is,
5391 when the condition is false. In C, if you want to test an assertion expressed
5392 by the condition @var{assert}, you should set the condition
5393 @samp{! @var{assert}} on the appropriate breakpoint.
5394
5395 Conditions are also accepted for watchpoints; you may not need them,
5396 since a watchpoint is inspecting the value of an expression anyhow---but
5397 it might be simpler, say, to just set a watchpoint on a variable name,
5398 and specify a condition that tests whether the new value is an interesting
5399 one.
5400
5401 Break conditions can have side effects, and may even call functions in
5402 your program. This can be useful, for example, to activate functions
5403 that log program progress, or to use your own print functions to
5404 format special data structures. The effects are completely predictable
5405 unless there is another enabled breakpoint at the same address. (In
5406 that case, @value{GDBN} might see the other breakpoint first and stop your
5407 program without checking the condition of this one.) Note that
5408 breakpoint commands are usually more convenient and flexible than break
5409 conditions for the
5410 purpose of performing side effects when a breakpoint is reached
5411 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5412
5413 Breakpoint conditions can also be evaluated on the target's side if
5414 the target supports it. Instead of evaluating the conditions locally,
5415 @value{GDBN} encodes the expression into an agent expression
5416 (@pxref{Agent Expressions}) suitable for execution on the target,
5417 independently of @value{GDBN}. Global variables become raw memory
5418 locations, locals become stack accesses, and so forth.
5419
5420 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5421 when its condition evaluates to true. This mechanism may provide faster
5422 response times depending on the performance characteristics of the target
5423 since it does not need to keep @value{GDBN} informed about
5424 every breakpoint trigger, even those with false conditions.
5425
5426 Break conditions can be specified when a breakpoint is set, by using
5427 @samp{if} in the arguments to the @code{break} command. @xref{Set
5428 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5429 with the @code{condition} command.
5430
5431 You can also use the @code{if} keyword with the @code{watch} command.
5432 The @code{catch} command does not recognize the @code{if} keyword;
5433 @code{condition} is the only way to impose a further condition on a
5434 catchpoint.
5435
5436 @table @code
5437 @kindex condition
5438 @item condition @var{bnum} @var{expression}
5439 Specify @var{expression} as the break condition for breakpoint,
5440 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5441 breakpoint @var{bnum} stops your program only if the value of
5442 @var{expression} is true (nonzero, in C). When you use
5443 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5444 syntactic correctness, and to determine whether symbols in it have
5445 referents in the context of your breakpoint. If @var{expression} uses
5446 symbols not referenced in the context of the breakpoint, @value{GDBN}
5447 prints an error message:
5448
5449 @smallexample
5450 No symbol "foo" in current context.
5451 @end smallexample
5452
5453 @noindent
5454 @value{GDBN} does
5455 not actually evaluate @var{expression} at the time the @code{condition}
5456 command (or a command that sets a breakpoint with a condition, like
5457 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5458
5459 @item condition @var{bnum}
5460 Remove the condition from breakpoint number @var{bnum}. It becomes
5461 an ordinary unconditional breakpoint.
5462 @end table
5463
5464 @cindex ignore count (of breakpoint)
5465 A special case of a breakpoint condition is to stop only when the
5466 breakpoint has been reached a certain number of times. This is so
5467 useful that there is a special way to do it, using the @dfn{ignore
5468 count} of the breakpoint. Every breakpoint has an ignore count, which
5469 is an integer. Most of the time, the ignore count is zero, and
5470 therefore has no effect. But if your program reaches a breakpoint whose
5471 ignore count is positive, then instead of stopping, it just decrements
5472 the ignore count by one and continues. As a result, if the ignore count
5473 value is @var{n}, the breakpoint does not stop the next @var{n} times
5474 your program reaches it.
5475
5476 @table @code
5477 @kindex ignore
5478 @item ignore @var{bnum} @var{count}
5479 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5480 The next @var{count} times the breakpoint is reached, your program's
5481 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5482 takes no action.
5483
5484 To make the breakpoint stop the next time it is reached, specify
5485 a count of zero.
5486
5487 When you use @code{continue} to resume execution of your program from a
5488 breakpoint, you can specify an ignore count directly as an argument to
5489 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5490 Stepping,,Continuing and Stepping}.
5491
5492 If a breakpoint has a positive ignore count and a condition, the
5493 condition is not checked. Once the ignore count reaches zero,
5494 @value{GDBN} resumes checking the condition.
5495
5496 You could achieve the effect of the ignore count with a condition such
5497 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5498 is decremented each time. @xref{Convenience Vars, ,Convenience
5499 Variables}.
5500 @end table
5501
5502 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5503
5504
5505 @node Break Commands
5506 @subsection Breakpoint Command Lists
5507
5508 @cindex breakpoint commands
5509 You can give any breakpoint (or watchpoint or catchpoint) a series of
5510 commands to execute when your program stops due to that breakpoint. For
5511 example, you might want to print the values of certain expressions, or
5512 enable other breakpoints.
5513
5514 @table @code
5515 @kindex commands
5516 @kindex end@r{ (breakpoint commands)}
5517 @item commands @r{[}@var{list}@dots{}@r{]}
5518 @itemx @dots{} @var{command-list} @dots{}
5519 @itemx end
5520 Specify a list of commands for the given breakpoints. The commands
5521 themselves appear on the following lines. Type a line containing just
5522 @code{end} to terminate the commands.
5523
5524 To remove all commands from a breakpoint, type @code{commands} and
5525 follow it immediately with @code{end}; that is, give no commands.
5526
5527 With no argument, @code{commands} refers to the last breakpoint,
5528 watchpoint, or catchpoint set (not to the breakpoint most recently
5529 encountered). If the most recent breakpoints were set with a single
5530 command, then the @code{commands} will apply to all the breakpoints
5531 set by that command. This applies to breakpoints set by
5532 @code{rbreak}, and also applies when a single @code{break} command
5533 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5534 Expressions}).
5535 @end table
5536
5537 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5538 disabled within a @var{command-list}.
5539
5540 You can use breakpoint commands to start your program up again. Simply
5541 use the @code{continue} command, or @code{step}, or any other command
5542 that resumes execution.
5543
5544 Any other commands in the command list, after a command that resumes
5545 execution, are ignored. This is because any time you resume execution
5546 (even with a simple @code{next} or @code{step}), you may encounter
5547 another breakpoint---which could have its own command list, leading to
5548 ambiguities about which list to execute.
5549
5550 @kindex silent
5551 If the first command you specify in a command list is @code{silent}, the
5552 usual message about stopping at a breakpoint is not printed. This may
5553 be desirable for breakpoints that are to print a specific message and
5554 then continue. If none of the remaining commands print anything, you
5555 see no sign that the breakpoint was reached. @code{silent} is
5556 meaningful only at the beginning of a breakpoint command list.
5557
5558 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5559 print precisely controlled output, and are often useful in silent
5560 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5561
5562 For example, here is how you could use breakpoint commands to print the
5563 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5564
5565 @smallexample
5566 break foo if x>0
5567 commands
5568 silent
5569 printf "x is %d\n",x
5570 cont
5571 end
5572 @end smallexample
5573
5574 One application for breakpoint commands is to compensate for one bug so
5575 you can test for another. Put a breakpoint just after the erroneous line
5576 of code, give it a condition to detect the case in which something
5577 erroneous has been done, and give it commands to assign correct values
5578 to any variables that need them. End with the @code{continue} command
5579 so that your program does not stop, and start with the @code{silent}
5580 command so that no output is produced. Here is an example:
5581
5582 @smallexample
5583 break 403
5584 commands
5585 silent
5586 set x = y + 4
5587 cont
5588 end
5589 @end smallexample
5590
5591 @node Dynamic Printf
5592 @subsection Dynamic Printf
5593
5594 @cindex dynamic printf
5595 @cindex dprintf
5596 The dynamic printf command @code{dprintf} combines a breakpoint with
5597 formatted printing of your program's data to give you the effect of
5598 inserting @code{printf} calls into your program on-the-fly, without
5599 having to recompile it.
5600
5601 In its most basic form, the output goes to the GDB console. However,
5602 you can set the variable @code{dprintf-style} for alternate handling.
5603 For instance, you can ask to format the output by calling your
5604 program's @code{printf} function. This has the advantage that the
5605 characters go to the program's output device, so they can recorded in
5606 redirects to files and so forth.
5607
5608 If you are doing remote debugging with a stub or agent, you can also
5609 ask to have the printf handled by the remote agent. In addition to
5610 ensuring that the output goes to the remote program's device along
5611 with any other output the program might produce, you can also ask that
5612 the dprintf remain active even after disconnecting from the remote
5613 target. Using the stub/agent is also more efficient, as it can do
5614 everything without needing to communicate with @value{GDBN}.
5615
5616 @table @code
5617 @kindex dprintf
5618 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5619 Whenever execution reaches @var{location}, print the values of one or
5620 more @var{expressions} under the control of the string @var{template}.
5621 To print several values, separate them with commas.
5622
5623 @item set dprintf-style @var{style}
5624 Set the dprintf output to be handled in one of several different
5625 styles enumerated below. A change of style affects all existing
5626 dynamic printfs immediately. (If you need individual control over the
5627 print commands, simply define normal breakpoints with
5628 explicitly-supplied command lists.)
5629
5630 @table @code
5631 @item gdb
5632 @kindex dprintf-style gdb
5633 Handle the output using the @value{GDBN} @code{printf} command.
5634
5635 @item call
5636 @kindex dprintf-style call
5637 Handle the output by calling a function in your program (normally
5638 @code{printf}).
5639
5640 @item agent
5641 @kindex dprintf-style agent
5642 Have the remote debugging agent (such as @code{gdbserver}) handle
5643 the output itself. This style is only available for agents that
5644 support running commands on the target.
5645 @end table
5646
5647 @item set dprintf-function @var{function}
5648 Set the function to call if the dprintf style is @code{call}. By
5649 default its value is @code{printf}. You may set it to any expression.
5650 that @value{GDBN} can evaluate to a function, as per the @code{call}
5651 command.
5652
5653 @item set dprintf-channel @var{channel}
5654 Set a ``channel'' for dprintf. If set to a non-empty value,
5655 @value{GDBN} will evaluate it as an expression and pass the result as
5656 a first argument to the @code{dprintf-function}, in the manner of
5657 @code{fprintf} and similar functions. Otherwise, the dprintf format
5658 string will be the first argument, in the manner of @code{printf}.
5659
5660 As an example, if you wanted @code{dprintf} output to go to a logfile
5661 that is a standard I/O stream assigned to the variable @code{mylog},
5662 you could do the following:
5663
5664 @example
5665 (gdb) set dprintf-style call
5666 (gdb) set dprintf-function fprintf
5667 (gdb) set dprintf-channel mylog
5668 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5669 Dprintf 1 at 0x123456: file main.c, line 25.
5670 (gdb) info break
5671 1 dprintf keep y 0x00123456 in main at main.c:25
5672 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5673 continue
5674 (gdb)
5675 @end example
5676
5677 Note that the @code{info break} displays the dynamic printf commands
5678 as normal breakpoint commands; you can thus easily see the effect of
5679 the variable settings.
5680
5681 @item set disconnected-dprintf on
5682 @itemx set disconnected-dprintf off
5683 @kindex set disconnected-dprintf
5684 Choose whether @code{dprintf} commands should continue to run if
5685 @value{GDBN} has disconnected from the target. This only applies
5686 if the @code{dprintf-style} is @code{agent}.
5687
5688 @item show disconnected-dprintf off
5689 @kindex show disconnected-dprintf
5690 Show the current choice for disconnected @code{dprintf}.
5691
5692 @end table
5693
5694 @value{GDBN} does not check the validity of function and channel,
5695 relying on you to supply values that are meaningful for the contexts
5696 in which they are being used. For instance, the function and channel
5697 may be the values of local variables, but if that is the case, then
5698 all enabled dynamic prints must be at locations within the scope of
5699 those locals. If evaluation fails, @value{GDBN} will report an error.
5700
5701 @node Save Breakpoints
5702 @subsection How to save breakpoints to a file
5703
5704 To save breakpoint definitions to a file use the @w{@code{save
5705 breakpoints}} command.
5706
5707 @table @code
5708 @kindex save breakpoints
5709 @cindex save breakpoints to a file for future sessions
5710 @item save breakpoints [@var{filename}]
5711 This command saves all current breakpoint definitions together with
5712 their commands and ignore counts, into a file @file{@var{filename}}
5713 suitable for use in a later debugging session. This includes all
5714 types of breakpoints (breakpoints, watchpoints, catchpoints,
5715 tracepoints). To read the saved breakpoint definitions, use the
5716 @code{source} command (@pxref{Command Files}). Note that watchpoints
5717 with expressions involving local variables may fail to be recreated
5718 because it may not be possible to access the context where the
5719 watchpoint is valid anymore. Because the saved breakpoint definitions
5720 are simply a sequence of @value{GDBN} commands that recreate the
5721 breakpoints, you can edit the file in your favorite editing program,
5722 and remove the breakpoint definitions you're not interested in, or
5723 that can no longer be recreated.
5724 @end table
5725
5726 @node Static Probe Points
5727 @subsection Static Probe Points
5728
5729 @cindex static probe point, SystemTap
5730 @cindex static probe point, DTrace
5731 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5732 for Statically Defined Tracing, and the probes are designed to have a tiny
5733 runtime code and data footprint, and no dynamic relocations.
5734
5735 Currently, the following types of probes are supported on
5736 ELF-compatible systems:
5737
5738 @itemize @bullet
5739
5740 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5741 @acronym{SDT} probes@footnote{See
5742 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5743 for more information on how to add @code{SystemTap} @acronym{SDT}
5744 probes in your applications.}. @code{SystemTap} probes are usable
5745 from assembly, C and C@t{++} languages@footnote{See
5746 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5747 for a good reference on how the @acronym{SDT} probes are implemented.}.
5748
5749 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5750 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5751 C@t{++} languages.
5752 @end itemize
5753
5754 @cindex semaphores on static probe points
5755 Some @code{SystemTap} probes have an associated semaphore variable;
5756 for instance, this happens automatically if you defined your probe
5757 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5758 @value{GDBN} will automatically enable it when you specify a
5759 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5760 breakpoint at a probe's location by some other method (e.g.,
5761 @code{break file:line}), then @value{GDBN} will not automatically set
5762 the semaphore. @code{DTrace} probes do not support semaphores.
5763
5764 You can examine the available static static probes using @code{info
5765 probes}, with optional arguments:
5766
5767 @table @code
5768 @kindex info probes
5769 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5770 If given, @var{type} is either @code{stap} for listing
5771 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5772 probes. If omitted all probes are listed regardless of their types.
5773
5774 If given, @var{provider} is a regular expression used to match against provider
5775 names when selecting which probes to list. If omitted, probes by all
5776 probes from all providers are listed.
5777
5778 If given, @var{name} is a regular expression to match against probe names
5779 when selecting which probes to list. If omitted, probe names are not
5780 considered when deciding whether to display them.
5781
5782 If given, @var{objfile} is a regular expression used to select which
5783 object files (executable or shared libraries) to examine. If not
5784 given, all object files are considered.
5785
5786 @item info probes all
5787 List the available static probes, from all types.
5788 @end table
5789
5790 @cindex enabling and disabling probes
5791 Some probe points can be enabled and/or disabled. The effect of
5792 enabling or disabling a probe depends on the type of probe being
5793 handled. Some @code{DTrace} probes can be enabled or
5794 disabled, but @code{SystemTap} probes cannot be disabled.
5795
5796 You can enable (or disable) one or more probes using the following
5797 commands, with optional arguments:
5798
5799 @table @code
5800 @kindex enable probes
5801 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5802 If given, @var{provider} is a regular expression used to match against
5803 provider names when selecting which probes to enable. If omitted,
5804 all probes from all providers are enabled.
5805
5806 If given, @var{name} is a regular expression to match against probe
5807 names when selecting which probes to enable. If omitted, probe names
5808 are not considered when deciding whether to enable them.
5809
5810 If given, @var{objfile} is a regular expression used to select which
5811 object files (executable or shared libraries) to examine. If not
5812 given, all object files are considered.
5813
5814 @kindex disable probes
5815 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5816 See the @code{enable probes} command above for a description of the
5817 optional arguments accepted by this command.
5818 @end table
5819
5820 @vindex $_probe_arg@r{, convenience variable}
5821 A probe may specify up to twelve arguments. These are available at the
5822 point at which the probe is defined---that is, when the current PC is
5823 at the probe's location. The arguments are available using the
5824 convenience variables (@pxref{Convenience Vars})
5825 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5826 probes each probe argument is an integer of the appropriate size;
5827 types are not preserved. In @code{DTrace} probes types are preserved
5828 provided that they are recognized as such by @value{GDBN}; otherwise
5829 the value of the probe argument will be a long integer. The
5830 convenience variable @code{$_probe_argc} holds the number of arguments
5831 at the current probe point.
5832
5833 These variables are always available, but attempts to access them at
5834 any location other than a probe point will cause @value{GDBN} to give
5835 an error message.
5836
5837
5838 @c @ifclear BARETARGET
5839 @node Error in Breakpoints
5840 @subsection ``Cannot insert breakpoints''
5841
5842 If you request too many active hardware-assisted breakpoints and
5843 watchpoints, you will see this error message:
5844
5845 @c FIXME: the precise wording of this message may change; the relevant
5846 @c source change is not committed yet (Sep 3, 1999).
5847 @smallexample
5848 Stopped; cannot insert breakpoints.
5849 You may have requested too many hardware breakpoints and watchpoints.
5850 @end smallexample
5851
5852 @noindent
5853 This message is printed when you attempt to resume the program, since
5854 only then @value{GDBN} knows exactly how many hardware breakpoints and
5855 watchpoints it needs to insert.
5856
5857 When this message is printed, you need to disable or remove some of the
5858 hardware-assisted breakpoints and watchpoints, and then continue.
5859
5860 @node Breakpoint-related Warnings
5861 @subsection ``Breakpoint address adjusted...''
5862 @cindex breakpoint address adjusted
5863
5864 Some processor architectures place constraints on the addresses at
5865 which breakpoints may be placed. For architectures thus constrained,
5866 @value{GDBN} will attempt to adjust the breakpoint's address to comply
5867 with the constraints dictated by the architecture.
5868
5869 One example of such an architecture is the Fujitsu FR-V. The FR-V is
5870 a VLIW architecture in which a number of RISC-like instructions may be
5871 bundled together for parallel execution. The FR-V architecture
5872 constrains the location of a breakpoint instruction within such a
5873 bundle to the instruction with the lowest address. @value{GDBN}
5874 honors this constraint by adjusting a breakpoint's address to the
5875 first in the bundle.
5876
5877 It is not uncommon for optimized code to have bundles which contain
5878 instructions from different source statements, thus it may happen that
5879 a breakpoint's address will be adjusted from one source statement to
5880 another. Since this adjustment may significantly alter @value{GDBN}'s
5881 breakpoint related behavior from what the user expects, a warning is
5882 printed when the breakpoint is first set and also when the breakpoint
5883 is hit.
5884
5885 A warning like the one below is printed when setting a breakpoint
5886 that's been subject to address adjustment:
5887
5888 @smallexample
5889 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5890 @end smallexample
5891
5892 Such warnings are printed both for user settable and @value{GDBN}'s
5893 internal breakpoints. If you see one of these warnings, you should
5894 verify that a breakpoint set at the adjusted address will have the
5895 desired affect. If not, the breakpoint in question may be removed and
5896 other breakpoints may be set which will have the desired behavior.
5897 E.g., it may be sufficient to place the breakpoint at a later
5898 instruction. A conditional breakpoint may also be useful in some
5899 cases to prevent the breakpoint from triggering too often.
5900
5901 @value{GDBN} will also issue a warning when stopping at one of these
5902 adjusted breakpoints:
5903
5904 @smallexample
5905 warning: Breakpoint 1 address previously adjusted from 0x00010414
5906 to 0x00010410.
5907 @end smallexample
5908
5909 When this warning is encountered, it may be too late to take remedial
5910 action except in cases where the breakpoint is hit earlier or more
5911 frequently than expected.
5912
5913 @node Continuing and Stepping
5914 @section Continuing and Stepping
5915
5916 @cindex stepping
5917 @cindex continuing
5918 @cindex resuming execution
5919 @dfn{Continuing} means resuming program execution until your program
5920 completes normally. In contrast, @dfn{stepping} means executing just
5921 one more ``step'' of your program, where ``step'' may mean either one
5922 line of source code, or one machine instruction (depending on what
5923 particular command you use). Either when continuing or when stepping,
5924 your program may stop even sooner, due to a breakpoint or a signal. (If
5925 it stops due to a signal, you may want to use @code{handle}, or use
5926 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5927 or you may step into the signal's handler (@pxref{stepping and signal
5928 handlers}).)
5929
5930 @table @code
5931 @kindex continue
5932 @kindex c @r{(@code{continue})}
5933 @kindex fg @r{(resume foreground execution)}
5934 @item continue @r{[}@var{ignore-count}@r{]}
5935 @itemx c @r{[}@var{ignore-count}@r{]}
5936 @itemx fg @r{[}@var{ignore-count}@r{]}
5937 Resume program execution, at the address where your program last stopped;
5938 any breakpoints set at that address are bypassed. The optional argument
5939 @var{ignore-count} allows you to specify a further number of times to
5940 ignore a breakpoint at this location; its effect is like that of
5941 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
5942
5943 The argument @var{ignore-count} is meaningful only when your program
5944 stopped due to a breakpoint. At other times, the argument to
5945 @code{continue} is ignored.
5946
5947 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5948 debugged program is deemed to be the foreground program) are provided
5949 purely for convenience, and have exactly the same behavior as
5950 @code{continue}.
5951 @end table
5952
5953 To resume execution at a different place, you can use @code{return}
5954 (@pxref{Returning, ,Returning from a Function}) to go back to the
5955 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
5956 Different Address}) to go to an arbitrary location in your program.
5957
5958 A typical technique for using stepping is to set a breakpoint
5959 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
5960 beginning of the function or the section of your program where a problem
5961 is believed to lie, run your program until it stops at that breakpoint,
5962 and then step through the suspect area, examining the variables that are
5963 interesting, until you see the problem happen.
5964
5965 @table @code
5966 @kindex step
5967 @kindex s @r{(@code{step})}
5968 @item step
5969 Continue running your program until control reaches a different source
5970 line, then stop it and return control to @value{GDBN}. This command is
5971 abbreviated @code{s}.
5972
5973 @quotation
5974 @c "without debugging information" is imprecise; actually "without line
5975 @c numbers in the debugging information". (gcc -g1 has debugging info but
5976 @c not line numbers). But it seems complex to try to make that
5977 @c distinction here.
5978 @emph{Warning:} If you use the @code{step} command while control is
5979 within a function that was compiled without debugging information,
5980 execution proceeds until control reaches a function that does have
5981 debugging information. Likewise, it will not step into a function which
5982 is compiled without debugging information. To step through functions
5983 without debugging information, use the @code{stepi} command, described
5984 below.
5985 @end quotation
5986
5987 The @code{step} command only stops at the first instruction of a source
5988 line. This prevents the multiple stops that could otherwise occur in
5989 @code{switch} statements, @code{for} loops, etc. @code{step} continues
5990 to stop if a function that has debugging information is called within
5991 the line. In other words, @code{step} @emph{steps inside} any functions
5992 called within the line.
5993
5994 Also, the @code{step} command only enters a function if there is line
5995 number information for the function. Otherwise it acts like the
5996 @code{next} command. This avoids problems when using @code{cc -gl}
5997 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5998 was any debugging information about the routine.
5999
6000 @item step @var{count}
6001 Continue running as in @code{step}, but do so @var{count} times. If a
6002 breakpoint is reached, or a signal not related to stepping occurs before
6003 @var{count} steps, stepping stops right away.
6004
6005 @kindex next
6006 @kindex n @r{(@code{next})}
6007 @item next @r{[}@var{count}@r{]}
6008 Continue to the next source line in the current (innermost) stack frame.
6009 This is similar to @code{step}, but function calls that appear within
6010 the line of code are executed without stopping. Execution stops when
6011 control reaches a different line of code at the original stack level
6012 that was executing when you gave the @code{next} command. This command
6013 is abbreviated @code{n}.
6014
6015 An argument @var{count} is a repeat count, as for @code{step}.
6016
6017
6018 @c FIX ME!! Do we delete this, or is there a way it fits in with
6019 @c the following paragraph? --- Vctoria
6020 @c
6021 @c @code{next} within a function that lacks debugging information acts like
6022 @c @code{step}, but any function calls appearing within the code of the
6023 @c function are executed without stopping.
6024
6025 The @code{next} command only stops at the first instruction of a
6026 source line. This prevents multiple stops that could otherwise occur in
6027 @code{switch} statements, @code{for} loops, etc.
6028
6029 @kindex set step-mode
6030 @item set step-mode
6031 @cindex functions without line info, and stepping
6032 @cindex stepping into functions with no line info
6033 @itemx set step-mode on
6034 The @code{set step-mode on} command causes the @code{step} command to
6035 stop at the first instruction of a function which contains no debug line
6036 information rather than stepping over it.
6037
6038 This is useful in cases where you may be interested in inspecting the
6039 machine instructions of a function which has no symbolic info and do not
6040 want @value{GDBN} to automatically skip over this function.
6041
6042 @item set step-mode off
6043 Causes the @code{step} command to step over any functions which contains no
6044 debug information. This is the default.
6045
6046 @item show step-mode
6047 Show whether @value{GDBN} will stop in or step over functions without
6048 source line debug information.
6049
6050 @kindex finish
6051 @kindex fin @r{(@code{finish})}
6052 @item finish
6053 Continue running until just after function in the selected stack frame
6054 returns. Print the returned value (if any). This command can be
6055 abbreviated as @code{fin}.
6056
6057 Contrast this with the @code{return} command (@pxref{Returning,
6058 ,Returning from a Function}).
6059
6060 @kindex set print finish
6061 @kindex show print finish
6062 @item set print finish @r{[}on|off@r{]}
6063 @itemx show print finish
6064 By default the @code{finish} command will show the value that is
6065 returned by the function. This can be disabled using @code{set print
6066 finish off}. When disabled, the value is still entered into the value
6067 history (@pxref{Value History}), but not displayed.
6068
6069 @kindex until
6070 @kindex u @r{(@code{until})}
6071 @cindex run until specified location
6072 @item until
6073 @itemx u
6074 Continue running until a source line past the current line, in the
6075 current stack frame, is reached. This command is used to avoid single
6076 stepping through a loop more than once. It is like the @code{next}
6077 command, except that when @code{until} encounters a jump, it
6078 automatically continues execution until the program counter is greater
6079 than the address of the jump.
6080
6081 This means that when you reach the end of a loop after single stepping
6082 though it, @code{until} makes your program continue execution until it
6083 exits the loop. In contrast, a @code{next} command at the end of a loop
6084 simply steps back to the beginning of the loop, which forces you to step
6085 through the next iteration.
6086
6087 @code{until} always stops your program if it attempts to exit the current
6088 stack frame.
6089
6090 @code{until} may produce somewhat counterintuitive results if the order
6091 of machine code does not match the order of the source lines. For
6092 example, in the following excerpt from a debugging session, the @code{f}
6093 (@code{frame}) command shows that execution is stopped at line
6094 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6095
6096 @smallexample
6097 (@value{GDBP}) f
6098 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6099 206 expand_input();
6100 (@value{GDBP}) until
6101 195 for ( ; argc > 0; NEXTARG) @{
6102 @end smallexample
6103
6104 This happened because, for execution efficiency, the compiler had
6105 generated code for the loop closure test at the end, rather than the
6106 start, of the loop---even though the test in a C @code{for}-loop is
6107 written before the body of the loop. The @code{until} command appeared
6108 to step back to the beginning of the loop when it advanced to this
6109 expression; however, it has not really gone to an earlier
6110 statement---not in terms of the actual machine code.
6111
6112 @code{until} with no argument works by means of single
6113 instruction stepping, and hence is slower than @code{until} with an
6114 argument.
6115
6116 @item until @var{location}
6117 @itemx u @var{location}
6118 Continue running your program until either the specified @var{location} is
6119 reached, or the current stack frame returns. The location is any of
6120 the forms described in @ref{Specify Location}.
6121 This form of the command uses temporary breakpoints, and
6122 hence is quicker than @code{until} without an argument. The specified
6123 location is actually reached only if it is in the current frame. This
6124 implies that @code{until} can be used to skip over recursive function
6125 invocations. For instance in the code below, if the current location is
6126 line @code{96}, issuing @code{until 99} will execute the program up to
6127 line @code{99} in the same invocation of factorial, i.e., after the inner
6128 invocations have returned.
6129
6130 @smallexample
6131 94 int factorial (int value)
6132 95 @{
6133 96 if (value > 1) @{
6134 97 value *= factorial (value - 1);
6135 98 @}
6136 99 return (value);
6137 100 @}
6138 @end smallexample
6139
6140
6141 @kindex advance @var{location}
6142 @item advance @var{location}
6143 Continue running the program up to the given @var{location}. An argument is
6144 required, which should be of one of the forms described in
6145 @ref{Specify Location}.
6146 Execution will also stop upon exit from the current stack
6147 frame. This command is similar to @code{until}, but @code{advance} will
6148 not skip over recursive function calls, and the target location doesn't
6149 have to be in the same frame as the current one.
6150
6151
6152 @kindex stepi
6153 @kindex si @r{(@code{stepi})}
6154 @item stepi
6155 @itemx stepi @var{arg}
6156 @itemx si
6157 Execute one machine instruction, then stop and return to the debugger.
6158
6159 It is often useful to do @samp{display/i $pc} when stepping by machine
6160 instructions. This makes @value{GDBN} automatically display the next
6161 instruction to be executed, each time your program stops. @xref{Auto
6162 Display,, Automatic Display}.
6163
6164 An argument is a repeat count, as in @code{step}.
6165
6166 @need 750
6167 @kindex nexti
6168 @kindex ni @r{(@code{nexti})}
6169 @item nexti
6170 @itemx nexti @var{arg}
6171 @itemx ni
6172 Execute one machine instruction, but if it is a function call,
6173 proceed until the function returns.
6174
6175 An argument is a repeat count, as in @code{next}.
6176
6177 @end table
6178
6179 @anchor{range stepping}
6180 @cindex range stepping
6181 @cindex target-assisted range stepping
6182 By default, and if available, @value{GDBN} makes use of
6183 target-assisted @dfn{range stepping}. In other words, whenever you
6184 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6185 tells the target to step the corresponding range of instruction
6186 addresses instead of issuing multiple single-steps. This speeds up
6187 line stepping, particularly for remote targets. Ideally, there should
6188 be no reason you would want to turn range stepping off. However, it's
6189 possible that a bug in the debug info, a bug in the remote stub (for
6190 remote targets), or even a bug in @value{GDBN} could make line
6191 stepping behave incorrectly when target-assisted range stepping is
6192 enabled. You can use the following command to turn off range stepping
6193 if necessary:
6194
6195 @table @code
6196 @kindex set range-stepping
6197 @kindex show range-stepping
6198 @item set range-stepping
6199 @itemx show range-stepping
6200 Control whether range stepping is enabled.
6201
6202 If @code{on}, and the target supports it, @value{GDBN} tells the
6203 target to step a range of addresses itself, instead of issuing
6204 multiple single-steps. If @code{off}, @value{GDBN} always issues
6205 single-steps, even if range stepping is supported by the target. The
6206 default is @code{on}.
6207
6208 @end table
6209
6210 @node Skipping Over Functions and Files
6211 @section Skipping Over Functions and Files
6212 @cindex skipping over functions and files
6213
6214 The program you are debugging may contain some functions which are
6215 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6216 skip a function, all functions in a file or a particular function in
6217 a particular file when stepping.
6218
6219 For example, consider the following C function:
6220
6221 @smallexample
6222 101 int func()
6223 102 @{
6224 103 foo(boring());
6225 104 bar(boring());
6226 105 @}
6227 @end smallexample
6228
6229 @noindent
6230 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6231 are not interested in stepping through @code{boring}. If you run @code{step}
6232 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6233 step over both @code{foo} and @code{boring}!
6234
6235 One solution is to @code{step} into @code{boring} and use the @code{finish}
6236 command to immediately exit it. But this can become tedious if @code{boring}
6237 is called from many places.
6238
6239 A more flexible solution is to execute @kbd{skip boring}. This instructs
6240 @value{GDBN} never to step into @code{boring}. Now when you execute
6241 @code{step} at line 103, you'll step over @code{boring} and directly into
6242 @code{foo}.
6243
6244 Functions may be skipped by providing either a function name, linespec
6245 (@pxref{Specify Location}), regular expression that matches the function's
6246 name, file name or a @code{glob}-style pattern that matches the file name.
6247
6248 On Posix systems the form of the regular expression is
6249 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6250 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6251 expression is whatever is provided by the @code{regcomp} function of
6252 the underlying system.
6253 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6254 description of @code{glob}-style patterns.
6255
6256 @table @code
6257 @kindex skip
6258 @item skip @r{[}@var{options}@r{]}
6259 The basic form of the @code{skip} command takes zero or more options
6260 that specify what to skip.
6261 The @var{options} argument is any useful combination of the following:
6262
6263 @table @code
6264 @item -file @var{file}
6265 @itemx -fi @var{file}
6266 Functions in @var{file} will be skipped over when stepping.
6267
6268 @item -gfile @var{file-glob-pattern}
6269 @itemx -gfi @var{file-glob-pattern}
6270 @cindex skipping over files via glob-style patterns
6271 Functions in files matching @var{file-glob-pattern} will be skipped
6272 over when stepping.
6273
6274 @smallexample
6275 (gdb) skip -gfi utils/*.c
6276 @end smallexample
6277
6278 @item -function @var{linespec}
6279 @itemx -fu @var{linespec}
6280 Functions named by @var{linespec} or the function containing the line
6281 named by @var{linespec} will be skipped over when stepping.
6282 @xref{Specify Location}.
6283
6284 @item -rfunction @var{regexp}
6285 @itemx -rfu @var{regexp}
6286 @cindex skipping over functions via regular expressions
6287 Functions whose name matches @var{regexp} will be skipped over when stepping.
6288
6289 This form is useful for complex function names.
6290 For example, there is generally no need to step into C@t{++} @code{std::string}
6291 constructors or destructors. Plus with C@t{++} templates it can be hard to
6292 write out the full name of the function, and often it doesn't matter what
6293 the template arguments are. Specifying the function to be skipped as a
6294 regular expression makes this easier.
6295
6296 @smallexample
6297 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6298 @end smallexample
6299
6300 If you want to skip every templated C@t{++} constructor and destructor
6301 in the @code{std} namespace you can do:
6302
6303 @smallexample
6304 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6305 @end smallexample
6306 @end table
6307
6308 If no options are specified, the function you're currently debugging
6309 will be skipped.
6310
6311 @kindex skip function
6312 @item skip function @r{[}@var{linespec}@r{]}
6313 After running this command, the function named by @var{linespec} or the
6314 function containing the line named by @var{linespec} will be skipped over when
6315 stepping. @xref{Specify Location}.
6316
6317 If you do not specify @var{linespec}, the function you're currently debugging
6318 will be skipped.
6319
6320 (If you have a function called @code{file} that you want to skip, use
6321 @kbd{skip function file}.)
6322
6323 @kindex skip file
6324 @item skip file @r{[}@var{filename}@r{]}
6325 After running this command, any function whose source lives in @var{filename}
6326 will be skipped over when stepping.
6327
6328 @smallexample
6329 (gdb) skip file boring.c
6330 File boring.c will be skipped when stepping.
6331 @end smallexample
6332
6333 If you do not specify @var{filename}, functions whose source lives in the file
6334 you're currently debugging will be skipped.
6335 @end table
6336
6337 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6338 These are the commands for managing your list of skips:
6339
6340 @table @code
6341 @kindex info skip
6342 @item info skip @r{[}@var{range}@r{]}
6343 Print details about the specified skip(s). If @var{range} is not specified,
6344 print a table with details about all functions and files marked for skipping.
6345 @code{info skip} prints the following information about each skip:
6346
6347 @table @emph
6348 @item Identifier
6349 A number identifying this skip.
6350 @item Enabled or Disabled
6351 Enabled skips are marked with @samp{y}.
6352 Disabled skips are marked with @samp{n}.
6353 @item Glob
6354 If the file name is a @samp{glob} pattern this is @samp{y}.
6355 Otherwise it is @samp{n}.
6356 @item File
6357 The name or @samp{glob} pattern of the file to be skipped.
6358 If no file is specified this is @samp{<none>}.
6359 @item RE
6360 If the function name is a @samp{regular expression} this is @samp{y}.
6361 Otherwise it is @samp{n}.
6362 @item Function
6363 The name or regular expression of the function to skip.
6364 If no function is specified this is @samp{<none>}.
6365 @end table
6366
6367 @kindex skip delete
6368 @item skip delete @r{[}@var{range}@r{]}
6369 Delete the specified skip(s). If @var{range} is not specified, delete all
6370 skips.
6371
6372 @kindex skip enable
6373 @item skip enable @r{[}@var{range}@r{]}
6374 Enable the specified skip(s). If @var{range} is not specified, enable all
6375 skips.
6376
6377 @kindex skip disable
6378 @item skip disable @r{[}@var{range}@r{]}
6379 Disable the specified skip(s). If @var{range} is not specified, disable all
6380 skips.
6381
6382 @kindex set debug skip
6383 @item set debug skip @r{[}on|off@r{]}
6384 Set whether to print the debug output about skipping files and functions.
6385
6386 @kindex show debug skip
6387 @item show debug skip
6388 Show whether the debug output about skipping files and functions is printed.
6389
6390 @end table
6391
6392 @node Signals
6393 @section Signals
6394 @cindex signals
6395
6396 A signal is an asynchronous event that can happen in a program. The
6397 operating system defines the possible kinds of signals, and gives each
6398 kind a name and a number. For example, in Unix @code{SIGINT} is the
6399 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6400 @code{SIGSEGV} is the signal a program gets from referencing a place in
6401 memory far away from all the areas in use; @code{SIGALRM} occurs when
6402 the alarm clock timer goes off (which happens only if your program has
6403 requested an alarm).
6404
6405 @cindex fatal signals
6406 Some signals, including @code{SIGALRM}, are a normal part of the
6407 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6408 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6409 program has not specified in advance some other way to handle the signal.
6410 @code{SIGINT} does not indicate an error in your program, but it is normally
6411 fatal so it can carry out the purpose of the interrupt: to kill the program.
6412
6413 @value{GDBN} has the ability to detect any occurrence of a signal in your
6414 program. You can tell @value{GDBN} in advance what to do for each kind of
6415 signal.
6416
6417 @cindex handling signals
6418 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6419 @code{SIGALRM} be silently passed to your program
6420 (so as not to interfere with their role in the program's functioning)
6421 but to stop your program immediately whenever an error signal happens.
6422 You can change these settings with the @code{handle} command.
6423
6424 @table @code
6425 @kindex info signals
6426 @kindex info handle
6427 @item info signals
6428 @itemx info handle
6429 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6430 handle each one. You can use this to see the signal numbers of all
6431 the defined types of signals.
6432
6433 @item info signals @var{sig}
6434 Similar, but print information only about the specified signal number.
6435
6436 @code{info handle} is an alias for @code{info signals}.
6437
6438 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6439 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6440 for details about this command.
6441
6442 @kindex handle
6443 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6444 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6445 can be the number of a signal or its name (with or without the
6446 @samp{SIG} at the beginning); a list of signal numbers of the form
6447 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6448 known signals. Optional arguments @var{keywords}, described below,
6449 say what change to make.
6450 @end table
6451
6452 @c @group
6453 The keywords allowed by the @code{handle} command can be abbreviated.
6454 Their full names are:
6455
6456 @table @code
6457 @item nostop
6458 @value{GDBN} should not stop your program when this signal happens. It may
6459 still print a message telling you that the signal has come in.
6460
6461 @item stop
6462 @value{GDBN} should stop your program when this signal happens. This implies
6463 the @code{print} keyword as well.
6464
6465 @item print
6466 @value{GDBN} should print a message when this signal happens.
6467
6468 @item noprint
6469 @value{GDBN} should not mention the occurrence of the signal at all. This
6470 implies the @code{nostop} keyword as well.
6471
6472 @item pass
6473 @itemx noignore
6474 @value{GDBN} should allow your program to see this signal; your program
6475 can handle the signal, or else it may terminate if the signal is fatal
6476 and not handled. @code{pass} and @code{noignore} are synonyms.
6477
6478 @item nopass
6479 @itemx ignore
6480 @value{GDBN} should not allow your program to see this signal.
6481 @code{nopass} and @code{ignore} are synonyms.
6482 @end table
6483 @c @end group
6484
6485 When a signal stops your program, the signal is not visible to the
6486 program until you
6487 continue. Your program sees the signal then, if @code{pass} is in
6488 effect for the signal in question @emph{at that time}. In other words,
6489 after @value{GDBN} reports a signal, you can use the @code{handle}
6490 command with @code{pass} or @code{nopass} to control whether your
6491 program sees that signal when you continue.
6492
6493 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6494 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6495 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6496 erroneous signals.
6497
6498 You can also use the @code{signal} command to prevent your program from
6499 seeing a signal, or cause it to see a signal it normally would not see,
6500 or to give it any signal at any time. For example, if your program stopped
6501 due to some sort of memory reference error, you might store correct
6502 values into the erroneous variables and continue, hoping to see more
6503 execution; but your program would probably terminate immediately as
6504 a result of the fatal signal once it saw the signal. To prevent this,
6505 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6506 Program a Signal}.
6507
6508 @cindex stepping and signal handlers
6509 @anchor{stepping and signal handlers}
6510
6511 @value{GDBN} optimizes for stepping the mainline code. If a signal
6512 that has @code{handle nostop} and @code{handle pass} set arrives while
6513 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6514 in progress, @value{GDBN} lets the signal handler run and then resumes
6515 stepping the mainline code once the signal handler returns. In other
6516 words, @value{GDBN} steps over the signal handler. This prevents
6517 signals that you've specified as not interesting (with @code{handle
6518 nostop}) from changing the focus of debugging unexpectedly. Note that
6519 the signal handler itself may still hit a breakpoint, stop for another
6520 signal that has @code{handle stop} in effect, or for any other event
6521 that normally results in stopping the stepping command sooner. Also
6522 note that @value{GDBN} still informs you that the program received a
6523 signal if @code{handle print} is set.
6524
6525 @anchor{stepping into signal handlers}
6526
6527 If you set @code{handle pass} for a signal, and your program sets up a
6528 handler for it, then issuing a stepping command, such as @code{step}
6529 or @code{stepi}, when your program is stopped due to the signal will
6530 step @emph{into} the signal handler (if the target supports that).
6531
6532 Likewise, if you use the @code{queue-signal} command to queue a signal
6533 to be delivered to the current thread when execution of the thread
6534 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6535 stepping command will step into the signal handler.
6536
6537 Here's an example, using @code{stepi} to step to the first instruction
6538 of @code{SIGUSR1}'s handler:
6539
6540 @smallexample
6541 (@value{GDBP}) handle SIGUSR1
6542 Signal Stop Print Pass to program Description
6543 SIGUSR1 Yes Yes Yes User defined signal 1
6544 (@value{GDBP}) c
6545 Continuing.
6546
6547 Program received signal SIGUSR1, User defined signal 1.
6548 main () sigusr1.c:28
6549 28 p = 0;
6550 (@value{GDBP}) si
6551 sigusr1_handler () at sigusr1.c:9
6552 9 @{
6553 @end smallexample
6554
6555 The same, but using @code{queue-signal} instead of waiting for the
6556 program to receive the signal first:
6557
6558 @smallexample
6559 (@value{GDBP}) n
6560 28 p = 0;
6561 (@value{GDBP}) queue-signal SIGUSR1
6562 (@value{GDBP}) si
6563 sigusr1_handler () at sigusr1.c:9
6564 9 @{
6565 (@value{GDBP})
6566 @end smallexample
6567
6568 @cindex extra signal information
6569 @anchor{extra signal information}
6570
6571 On some targets, @value{GDBN} can inspect extra signal information
6572 associated with the intercepted signal, before it is actually
6573 delivered to the program being debugged. This information is exported
6574 by the convenience variable @code{$_siginfo}, and consists of data
6575 that is passed by the kernel to the signal handler at the time of the
6576 receipt of a signal. The data type of the information itself is
6577 target dependent. You can see the data type using the @code{ptype
6578 $_siginfo} command. On Unix systems, it typically corresponds to the
6579 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6580 system header.
6581
6582 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6583 referenced address that raised a segmentation fault.
6584
6585 @smallexample
6586 @group
6587 (@value{GDBP}) continue
6588 Program received signal SIGSEGV, Segmentation fault.
6589 0x0000000000400766 in main ()
6590 69 *(int *)p = 0;
6591 (@value{GDBP}) ptype $_siginfo
6592 type = struct @{
6593 int si_signo;
6594 int si_errno;
6595 int si_code;
6596 union @{
6597 int _pad[28];
6598 struct @{...@} _kill;
6599 struct @{...@} _timer;
6600 struct @{...@} _rt;
6601 struct @{...@} _sigchld;
6602 struct @{...@} _sigfault;
6603 struct @{...@} _sigpoll;
6604 @} _sifields;
6605 @}
6606 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6607 type = struct @{
6608 void *si_addr;
6609 @}
6610 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6611 $1 = (void *) 0x7ffff7ff7000
6612 @end group
6613 @end smallexample
6614
6615 Depending on target support, @code{$_siginfo} may also be writable.
6616
6617 @cindex Intel MPX boundary violations
6618 @cindex boundary violations, Intel MPX
6619 On some targets, a @code{SIGSEGV} can be caused by a boundary
6620 violation, i.e., accessing an address outside of the allowed range.
6621 In those cases @value{GDBN} may displays additional information,
6622 depending on how @value{GDBN} has been told to handle the signal.
6623 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6624 kind: "Upper" or "Lower", the memory address accessed and the
6625 bounds, while with @code{handle nostop SIGSEGV} no additional
6626 information is displayed.
6627
6628 The usual output of a segfault is:
6629 @smallexample
6630 Program received signal SIGSEGV, Segmentation fault
6631 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6632 68 value = *(p + len);
6633 @end smallexample
6634
6635 While a bound violation is presented as:
6636 @smallexample
6637 Program received signal SIGSEGV, Segmentation fault
6638 Upper bound violation while accessing address 0x7fffffffc3b3
6639 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6640 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6641 68 value = *(p + len);
6642 @end smallexample
6643
6644 @node Thread Stops
6645 @section Stopping and Starting Multi-thread Programs
6646
6647 @cindex stopped threads
6648 @cindex threads, stopped
6649
6650 @cindex continuing threads
6651 @cindex threads, continuing
6652
6653 @value{GDBN} supports debugging programs with multiple threads
6654 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6655 are two modes of controlling execution of your program within the
6656 debugger. In the default mode, referred to as @dfn{all-stop mode},
6657 when any thread in your program stops (for example, at a breakpoint
6658 or while being stepped), all other threads in the program are also stopped by
6659 @value{GDBN}. On some targets, @value{GDBN} also supports
6660 @dfn{non-stop mode}, in which other threads can continue to run freely while
6661 you examine the stopped thread in the debugger.
6662
6663 @menu
6664 * All-Stop Mode:: All threads stop when GDB takes control
6665 * Non-Stop Mode:: Other threads continue to execute
6666 * Background Execution:: Running your program asynchronously
6667 * Thread-Specific Breakpoints:: Controlling breakpoints
6668 * Interrupted System Calls:: GDB may interfere with system calls
6669 * Observer Mode:: GDB does not alter program behavior
6670 @end menu
6671
6672 @node All-Stop Mode
6673 @subsection All-Stop Mode
6674
6675 @cindex all-stop mode
6676
6677 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6678 @emph{all} threads of execution stop, not just the current thread. This
6679 allows you to examine the overall state of the program, including
6680 switching between threads, without worrying that things may change
6681 underfoot.
6682
6683 Conversely, whenever you restart the program, @emph{all} threads start
6684 executing. @emph{This is true even when single-stepping} with commands
6685 like @code{step} or @code{next}.
6686
6687 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6688 Since thread scheduling is up to your debugging target's operating
6689 system (not controlled by @value{GDBN}), other threads may
6690 execute more than one statement while the current thread completes a
6691 single step. Moreover, in general other threads stop in the middle of a
6692 statement, rather than at a clean statement boundary, when the program
6693 stops.
6694
6695 You might even find your program stopped in another thread after
6696 continuing or even single-stepping. This happens whenever some other
6697 thread runs into a breakpoint, a signal, or an exception before the
6698 first thread completes whatever you requested.
6699
6700 @cindex automatic thread selection
6701 @cindex switching threads automatically
6702 @cindex threads, automatic switching
6703 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6704 signal, it automatically selects the thread where that breakpoint or
6705 signal happened. @value{GDBN} alerts you to the context switch with a
6706 message such as @samp{[Switching to Thread @var{n}]} to identify the
6707 thread.
6708
6709 On some OSes, you can modify @value{GDBN}'s default behavior by
6710 locking the OS scheduler to allow only a single thread to run.
6711
6712 @table @code
6713 @item set scheduler-locking @var{mode}
6714 @cindex scheduler locking mode
6715 @cindex lock scheduler
6716 Set the scheduler locking mode. It applies to normal execution,
6717 record mode, and replay mode. If it is @code{off}, then there is no
6718 locking and any thread may run at any time. If @code{on}, then only
6719 the current thread may run when the inferior is resumed. The
6720 @code{step} mode optimizes for single-stepping; it prevents other
6721 threads from preempting the current thread while you are stepping, so
6722 that the focus of debugging does not change unexpectedly. Other
6723 threads never get a chance to run when you step, and they are
6724 completely free to run when you use commands like @samp{continue},
6725 @samp{until}, or @samp{finish}. However, unless another thread hits a
6726 breakpoint during its timeslice, @value{GDBN} does not change the
6727 current thread away from the thread that you are debugging. The
6728 @code{replay} mode behaves like @code{off} in record mode and like
6729 @code{on} in replay mode.
6730
6731 @item show scheduler-locking
6732 Display the current scheduler locking mode.
6733 @end table
6734
6735 @cindex resume threads of multiple processes simultaneously
6736 By default, when you issue one of the execution commands such as
6737 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6738 threads of the current inferior to run. For example, if @value{GDBN}
6739 is attached to two inferiors, each with two threads, the
6740 @code{continue} command resumes only the two threads of the current
6741 inferior. This is useful, for example, when you debug a program that
6742 forks and you want to hold the parent stopped (so that, for instance,
6743 it doesn't run to exit), while you debug the child. In other
6744 situations, you may not be interested in inspecting the current state
6745 of any of the processes @value{GDBN} is attached to, and you may want
6746 to resume them all until some breakpoint is hit. In the latter case,
6747 you can instruct @value{GDBN} to allow all threads of all the
6748 inferiors to run with the @w{@code{set schedule-multiple}} command.
6749
6750 @table @code
6751 @kindex set schedule-multiple
6752 @item set schedule-multiple
6753 Set the mode for allowing threads of multiple processes to be resumed
6754 when an execution command is issued. When @code{on}, all threads of
6755 all processes are allowed to run. When @code{off}, only the threads
6756 of the current process are resumed. The default is @code{off}. The
6757 @code{scheduler-locking} mode takes precedence when set to @code{on},
6758 or while you are stepping and set to @code{step}.
6759
6760 @item show schedule-multiple
6761 Display the current mode for resuming the execution of threads of
6762 multiple processes.
6763 @end table
6764
6765 @node Non-Stop Mode
6766 @subsection Non-Stop Mode
6767
6768 @cindex non-stop mode
6769
6770 @c This section is really only a place-holder, and needs to be expanded
6771 @c with more details.
6772
6773 For some multi-threaded targets, @value{GDBN} supports an optional
6774 mode of operation in which you can examine stopped program threads in
6775 the debugger while other threads continue to execute freely. This
6776 minimizes intrusion when debugging live systems, such as programs
6777 where some threads have real-time constraints or must continue to
6778 respond to external events. This is referred to as @dfn{non-stop} mode.
6779
6780 In non-stop mode, when a thread stops to report a debugging event,
6781 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6782 threads as well, in contrast to the all-stop mode behavior. Additionally,
6783 execution commands such as @code{continue} and @code{step} apply by default
6784 only to the current thread in non-stop mode, rather than all threads as
6785 in all-stop mode. This allows you to control threads explicitly in
6786 ways that are not possible in all-stop mode --- for example, stepping
6787 one thread while allowing others to run freely, stepping
6788 one thread while holding all others stopped, or stepping several threads
6789 independently and simultaneously.
6790
6791 To enter non-stop mode, use this sequence of commands before you run
6792 or attach to your program:
6793
6794 @smallexample
6795 # If using the CLI, pagination breaks non-stop.
6796 set pagination off
6797
6798 # Finally, turn it on!
6799 set non-stop on
6800 @end smallexample
6801
6802 You can use these commands to manipulate the non-stop mode setting:
6803
6804 @table @code
6805 @kindex set non-stop
6806 @item set non-stop on
6807 Enable selection of non-stop mode.
6808 @item set non-stop off
6809 Disable selection of non-stop mode.
6810 @kindex show non-stop
6811 @item show non-stop
6812 Show the current non-stop enablement setting.
6813 @end table
6814
6815 Note these commands only reflect whether non-stop mode is enabled,
6816 not whether the currently-executing program is being run in non-stop mode.
6817 In particular, the @code{set non-stop} preference is only consulted when
6818 @value{GDBN} starts or connects to the target program, and it is generally
6819 not possible to switch modes once debugging has started. Furthermore,
6820 since not all targets support non-stop mode, even when you have enabled
6821 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6822 default.
6823
6824 In non-stop mode, all execution commands apply only to the current thread
6825 by default. That is, @code{continue} only continues one thread.
6826 To continue all threads, issue @code{continue -a} or @code{c -a}.
6827
6828 You can use @value{GDBN}'s background execution commands
6829 (@pxref{Background Execution}) to run some threads in the background
6830 while you continue to examine or step others from @value{GDBN}.
6831 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6832 always executed asynchronously in non-stop mode.
6833
6834 Suspending execution is done with the @code{interrupt} command when
6835 running in the background, or @kbd{Ctrl-c} during foreground execution.
6836 In all-stop mode, this stops the whole process;
6837 but in non-stop mode the interrupt applies only to the current thread.
6838 To stop the whole program, use @code{interrupt -a}.
6839
6840 Other execution commands do not currently support the @code{-a} option.
6841
6842 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6843 that thread current, as it does in all-stop mode. This is because the
6844 thread stop notifications are asynchronous with respect to @value{GDBN}'s
6845 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6846 changed to a different thread just as you entered a command to operate on the
6847 previously current thread.
6848
6849 @node Background Execution
6850 @subsection Background Execution
6851
6852 @cindex foreground execution
6853 @cindex background execution
6854 @cindex asynchronous execution
6855 @cindex execution, foreground, background and asynchronous
6856
6857 @value{GDBN}'s execution commands have two variants: the normal
6858 foreground (synchronous) behavior, and a background
6859 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
6860 the program to report that some thread has stopped before prompting for
6861 another command. In background execution, @value{GDBN} immediately gives
6862 a command prompt so that you can issue other commands while your program runs.
6863
6864 If the target doesn't support async mode, @value{GDBN} issues an error
6865 message if you attempt to use the background execution commands.
6866
6867 @cindex @code{&}, background execution of commands
6868 To specify background execution, add a @code{&} to the command. For example,
6869 the background form of the @code{continue} command is @code{continue&}, or
6870 just @code{c&}. The execution commands that accept background execution
6871 are:
6872
6873 @table @code
6874 @kindex run&
6875 @item run
6876 @xref{Starting, , Starting your Program}.
6877
6878 @item attach
6879 @kindex attach&
6880 @xref{Attach, , Debugging an Already-running Process}.
6881
6882 @item step
6883 @kindex step&
6884 @xref{Continuing and Stepping, step}.
6885
6886 @item stepi
6887 @kindex stepi&
6888 @xref{Continuing and Stepping, stepi}.
6889
6890 @item next
6891 @kindex next&
6892 @xref{Continuing and Stepping, next}.
6893
6894 @item nexti
6895 @kindex nexti&
6896 @xref{Continuing and Stepping, nexti}.
6897
6898 @item continue
6899 @kindex continue&
6900 @xref{Continuing and Stepping, continue}.
6901
6902 @item finish
6903 @kindex finish&
6904 @xref{Continuing and Stepping, finish}.
6905
6906 @item until
6907 @kindex until&
6908 @xref{Continuing and Stepping, until}.
6909
6910 @end table
6911
6912 Background execution is especially useful in conjunction with non-stop
6913 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6914 However, you can also use these commands in the normal all-stop mode with
6915 the restriction that you cannot issue another execution command until the
6916 previous one finishes. Examples of commands that are valid in all-stop
6917 mode while the program is running include @code{help} and @code{info break}.
6918
6919 You can interrupt your program while it is running in the background by
6920 using the @code{interrupt} command.
6921
6922 @table @code
6923 @kindex interrupt
6924 @item interrupt
6925 @itemx interrupt -a
6926
6927 Suspend execution of the running program. In all-stop mode,
6928 @code{interrupt} stops the whole process, but in non-stop mode, it stops
6929 only the current thread. To stop the whole program in non-stop mode,
6930 use @code{interrupt -a}.
6931 @end table
6932
6933 @node Thread-Specific Breakpoints
6934 @subsection Thread-Specific Breakpoints
6935
6936 When your program has multiple threads (@pxref{Threads,, Debugging
6937 Programs with Multiple Threads}), you can choose whether to set
6938 breakpoints on all threads, or on a particular thread.
6939
6940 @table @code
6941 @cindex breakpoints and threads
6942 @cindex thread breakpoints
6943 @kindex break @dots{} thread @var{thread-id}
6944 @item break @var{location} thread @var{thread-id}
6945 @itemx break @var{location} thread @var{thread-id} if @dots{}
6946 @var{location} specifies source lines; there are several ways of
6947 writing them (@pxref{Specify Location}), but the effect is always to
6948 specify some source line.
6949
6950 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
6951 to specify that you only want @value{GDBN} to stop the program when a
6952 particular thread reaches this breakpoint. The @var{thread-id} specifier
6953 is one of the thread identifiers assigned by @value{GDBN}, shown
6954 in the first column of the @samp{info threads} display.
6955
6956 If you do not specify @samp{thread @var{thread-id}} when you set a
6957 breakpoint, the breakpoint applies to @emph{all} threads of your
6958 program.
6959
6960 You can use the @code{thread} qualifier on conditional breakpoints as
6961 well; in this case, place @samp{thread @var{thread-id}} before or
6962 after the breakpoint condition, like this:
6963
6964 @smallexample
6965 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
6966 @end smallexample
6967
6968 @end table
6969
6970 Thread-specific breakpoints are automatically deleted when
6971 @value{GDBN} detects the corresponding thread is no longer in the
6972 thread list. For example:
6973
6974 @smallexample
6975 (@value{GDBP}) c
6976 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6977 @end smallexample
6978
6979 There are several ways for a thread to disappear, such as a regular
6980 thread exit, but also when you detach from the process with the
6981 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
6982 Process}), or if @value{GDBN} loses the remote connection
6983 (@pxref{Remote Debugging}), etc. Note that with some targets,
6984 @value{GDBN} is only able to detect a thread has exited when the user
6985 explictly asks for the thread list with the @code{info threads}
6986 command.
6987
6988 @node Interrupted System Calls
6989 @subsection Interrupted System Calls
6990
6991 @cindex thread breakpoints and system calls
6992 @cindex system calls and thread breakpoints
6993 @cindex premature return from system calls
6994 There is an unfortunate side effect when using @value{GDBN} to debug
6995 multi-threaded programs. If one thread stops for a
6996 breakpoint, or for some other reason, and another thread is blocked in a
6997 system call, then the system call may return prematurely. This is a
6998 consequence of the interaction between multiple threads and the signals
6999 that @value{GDBN} uses to implement breakpoints and other events that
7000 stop execution.
7001
7002 To handle this problem, your program should check the return value of
7003 each system call and react appropriately. This is good programming
7004 style anyways.
7005
7006 For example, do not write code like this:
7007
7008 @smallexample
7009 sleep (10);
7010 @end smallexample
7011
7012 The call to @code{sleep} will return early if a different thread stops
7013 at a breakpoint or for some other reason.
7014
7015 Instead, write this:
7016
7017 @smallexample
7018 int unslept = 10;
7019 while (unslept > 0)
7020 unslept = sleep (unslept);
7021 @end smallexample
7022
7023 A system call is allowed to return early, so the system is still
7024 conforming to its specification. But @value{GDBN} does cause your
7025 multi-threaded program to behave differently than it would without
7026 @value{GDBN}.
7027
7028 Also, @value{GDBN} uses internal breakpoints in the thread library to
7029 monitor certain events such as thread creation and thread destruction.
7030 When such an event happens, a system call in another thread may return
7031 prematurely, even though your program does not appear to stop.
7032
7033 @node Observer Mode
7034 @subsection Observer Mode
7035
7036 If you want to build on non-stop mode and observe program behavior
7037 without any chance of disruption by @value{GDBN}, you can set
7038 variables to disable all of the debugger's attempts to modify state,
7039 whether by writing memory, inserting breakpoints, etc. These operate
7040 at a low level, intercepting operations from all commands.
7041
7042 When all of these are set to @code{off}, then @value{GDBN} is said to
7043 be @dfn{observer mode}. As a convenience, the variable
7044 @code{observer} can be set to disable these, plus enable non-stop
7045 mode.
7046
7047 Note that @value{GDBN} will not prevent you from making nonsensical
7048 combinations of these settings. For instance, if you have enabled
7049 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7050 then breakpoints that work by writing trap instructions into the code
7051 stream will still not be able to be placed.
7052
7053 @table @code
7054
7055 @kindex observer
7056 @item set observer on
7057 @itemx set observer off
7058 When set to @code{on}, this disables all the permission variables
7059 below (except for @code{insert-fast-tracepoints}), plus enables
7060 non-stop debugging. Setting this to @code{off} switches back to
7061 normal debugging, though remaining in non-stop mode.
7062
7063 @item show observer
7064 Show whether observer mode is on or off.
7065
7066 @kindex may-write-registers
7067 @item set may-write-registers on
7068 @itemx set may-write-registers off
7069 This controls whether @value{GDBN} will attempt to alter the values of
7070 registers, such as with assignment expressions in @code{print}, or the
7071 @code{jump} command. It defaults to @code{on}.
7072
7073 @item show may-write-registers
7074 Show the current permission to write registers.
7075
7076 @kindex may-write-memory
7077 @item set may-write-memory on
7078 @itemx set may-write-memory off
7079 This controls whether @value{GDBN} will attempt to alter the contents
7080 of memory, such as with assignment expressions in @code{print}. It
7081 defaults to @code{on}.
7082
7083 @item show may-write-memory
7084 Show the current permission to write memory.
7085
7086 @kindex may-insert-breakpoints
7087 @item set may-insert-breakpoints on
7088 @itemx set may-insert-breakpoints off
7089 This controls whether @value{GDBN} will attempt to insert breakpoints.
7090 This affects all breakpoints, including internal breakpoints defined
7091 by @value{GDBN}. It defaults to @code{on}.
7092
7093 @item show may-insert-breakpoints
7094 Show the current permission to insert breakpoints.
7095
7096 @kindex may-insert-tracepoints
7097 @item set may-insert-tracepoints on
7098 @itemx set may-insert-tracepoints off
7099 This controls whether @value{GDBN} will attempt to insert (regular)
7100 tracepoints at the beginning of a tracing experiment. It affects only
7101 non-fast tracepoints, fast tracepoints being under the control of
7102 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7103
7104 @item show may-insert-tracepoints
7105 Show the current permission to insert tracepoints.
7106
7107 @kindex may-insert-fast-tracepoints
7108 @item set may-insert-fast-tracepoints on
7109 @itemx set may-insert-fast-tracepoints off
7110 This controls whether @value{GDBN} will attempt to insert fast
7111 tracepoints at the beginning of a tracing experiment. It affects only
7112 fast tracepoints, regular (non-fast) tracepoints being under the
7113 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7114
7115 @item show may-insert-fast-tracepoints
7116 Show the current permission to insert fast tracepoints.
7117
7118 @kindex may-interrupt
7119 @item set may-interrupt on
7120 @itemx set may-interrupt off
7121 This controls whether @value{GDBN} will attempt to interrupt or stop
7122 program execution. When this variable is @code{off}, the
7123 @code{interrupt} command will have no effect, nor will
7124 @kbd{Ctrl-c}. It defaults to @code{on}.
7125
7126 @item show may-interrupt
7127 Show the current permission to interrupt or stop the program.
7128
7129 @end table
7130
7131 @node Reverse Execution
7132 @chapter Running programs backward
7133 @cindex reverse execution
7134 @cindex running programs backward
7135
7136 When you are debugging a program, it is not unusual to realize that
7137 you have gone too far, and some event of interest has already happened.
7138 If the target environment supports it, @value{GDBN} can allow you to
7139 ``rewind'' the program by running it backward.
7140
7141 A target environment that supports reverse execution should be able
7142 to ``undo'' the changes in machine state that have taken place as the
7143 program was executing normally. Variables, registers etc.@: should
7144 revert to their previous values. Obviously this requires a great
7145 deal of sophistication on the part of the target environment; not
7146 all target environments can support reverse execution.
7147
7148 When a program is executed in reverse, the instructions that
7149 have most recently been executed are ``un-executed'', in reverse
7150 order. The program counter runs backward, following the previous
7151 thread of execution in reverse. As each instruction is ``un-executed'',
7152 the values of memory and/or registers that were changed by that
7153 instruction are reverted to their previous states. After executing
7154 a piece of source code in reverse, all side effects of that code
7155 should be ``undone'', and all variables should be returned to their
7156 prior values@footnote{
7157 Note that some side effects are easier to undo than others. For instance,
7158 memory and registers are relatively easy, but device I/O is hard. Some
7159 targets may be able undo things like device I/O, and some may not.
7160
7161 The contract between @value{GDBN} and the reverse executing target
7162 requires only that the target do something reasonable when
7163 @value{GDBN} tells it to execute backwards, and then report the
7164 results back to @value{GDBN}. Whatever the target reports back to
7165 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7166 assumes that the memory and registers that the target reports are in a
7167 consistent state, but @value{GDBN} accepts whatever it is given.
7168 }.
7169
7170 On some platforms, @value{GDBN} has built-in support for reverse
7171 execution, activated with the @code{record} or @code{record btrace}
7172 commands. @xref{Process Record and Replay}. Some remote targets,
7173 typically full system emulators, support reverse execution directly
7174 without requiring any special command.
7175
7176 If you are debugging in a target environment that supports
7177 reverse execution, @value{GDBN} provides the following commands.
7178
7179 @table @code
7180 @kindex reverse-continue
7181 @kindex rc @r{(@code{reverse-continue})}
7182 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7183 @itemx rc @r{[}@var{ignore-count}@r{]}
7184 Beginning at the point where your program last stopped, start executing
7185 in reverse. Reverse execution will stop for breakpoints and synchronous
7186 exceptions (signals), just like normal execution. Behavior of
7187 asynchronous signals depends on the target environment.
7188
7189 @kindex reverse-step
7190 @kindex rs @r{(@code{step})}
7191 @item reverse-step @r{[}@var{count}@r{]}
7192 Run the program backward until control reaches the start of a
7193 different source line; then stop it, and return control to @value{GDBN}.
7194
7195 Like the @code{step} command, @code{reverse-step} will only stop
7196 at the beginning of a source line. It ``un-executes'' the previously
7197 executed source line. If the previous source line included calls to
7198 debuggable functions, @code{reverse-step} will step (backward) into
7199 the called function, stopping at the beginning of the @emph{last}
7200 statement in the called function (typically a return statement).
7201
7202 Also, as with the @code{step} command, if non-debuggable functions are
7203 called, @code{reverse-step} will run thru them backward without stopping.
7204
7205 @kindex reverse-stepi
7206 @kindex rsi @r{(@code{reverse-stepi})}
7207 @item reverse-stepi @r{[}@var{count}@r{]}
7208 Reverse-execute one machine instruction. Note that the instruction
7209 to be reverse-executed is @emph{not} the one pointed to by the program
7210 counter, but the instruction executed prior to that one. For instance,
7211 if the last instruction was a jump, @code{reverse-stepi} will take you
7212 back from the destination of the jump to the jump instruction itself.
7213
7214 @kindex reverse-next
7215 @kindex rn @r{(@code{reverse-next})}
7216 @item reverse-next @r{[}@var{count}@r{]}
7217 Run backward to the beginning of the previous line executed in
7218 the current (innermost) stack frame. If the line contains function
7219 calls, they will be ``un-executed'' without stopping. Starting from
7220 the first line of a function, @code{reverse-next} will take you back
7221 to the caller of that function, @emph{before} the function was called,
7222 just as the normal @code{next} command would take you from the last
7223 line of a function back to its return to its caller
7224 @footnote{Unless the code is too heavily optimized.}.
7225
7226 @kindex reverse-nexti
7227 @kindex rni @r{(@code{reverse-nexti})}
7228 @item reverse-nexti @r{[}@var{count}@r{]}
7229 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7230 in reverse, except that called functions are ``un-executed'' atomically.
7231 That is, if the previously executed instruction was a return from
7232 another function, @code{reverse-nexti} will continue to execute
7233 in reverse until the call to that function (from the current stack
7234 frame) is reached.
7235
7236 @kindex reverse-finish
7237 @item reverse-finish
7238 Just as the @code{finish} command takes you to the point where the
7239 current function returns, @code{reverse-finish} takes you to the point
7240 where it was called. Instead of ending up at the end of the current
7241 function invocation, you end up at the beginning.
7242
7243 @kindex set exec-direction
7244 @item set exec-direction
7245 Set the direction of target execution.
7246 @item set exec-direction reverse
7247 @cindex execute forward or backward in time
7248 @value{GDBN} will perform all execution commands in reverse, until the
7249 exec-direction mode is changed to ``forward''. Affected commands include
7250 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7251 command cannot be used in reverse mode.
7252 @item set exec-direction forward
7253 @value{GDBN} will perform all execution commands in the normal fashion.
7254 This is the default.
7255 @end table
7256
7257
7258 @node Process Record and Replay
7259 @chapter Recording Inferior's Execution and Replaying It
7260 @cindex process record and replay
7261 @cindex recording inferior's execution and replaying it
7262
7263 On some platforms, @value{GDBN} provides a special @dfn{process record
7264 and replay} target that can record a log of the process execution, and
7265 replay it later with both forward and reverse execution commands.
7266
7267 @cindex replay mode
7268 When this target is in use, if the execution log includes the record
7269 for the next instruction, @value{GDBN} will debug in @dfn{replay
7270 mode}. In the replay mode, the inferior does not really execute code
7271 instructions. Instead, all the events that normally happen during
7272 code execution are taken from the execution log. While code is not
7273 really executed in replay mode, the values of registers (including the
7274 program counter register) and the memory of the inferior are still
7275 changed as they normally would. Their contents are taken from the
7276 execution log.
7277
7278 @cindex record mode
7279 If the record for the next instruction is not in the execution log,
7280 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7281 inferior executes normally, and @value{GDBN} records the execution log
7282 for future replay.
7283
7284 The process record and replay target supports reverse execution
7285 (@pxref{Reverse Execution}), even if the platform on which the
7286 inferior runs does not. However, the reverse execution is limited in
7287 this case by the range of the instructions recorded in the execution
7288 log. In other words, reverse execution on platforms that don't
7289 support it directly can only be done in the replay mode.
7290
7291 When debugging in the reverse direction, @value{GDBN} will work in
7292 replay mode as long as the execution log includes the record for the
7293 previous instruction; otherwise, it will work in record mode, if the
7294 platform supports reverse execution, or stop if not.
7295
7296 Currently, process record and replay is supported on ARM, Aarch64,
7297 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7298 GNU/Linux. Process record and replay can be used both when native
7299 debugging, and when remote debugging via @code{gdbserver}.
7300
7301 For architecture environments that support process record and replay,
7302 @value{GDBN} provides the following commands:
7303
7304 @table @code
7305 @kindex target record
7306 @kindex target record-full
7307 @kindex target record-btrace
7308 @kindex record
7309 @kindex record full
7310 @kindex record btrace
7311 @kindex record btrace bts
7312 @kindex record btrace pt
7313 @kindex record bts
7314 @kindex record pt
7315 @kindex rec
7316 @kindex rec full
7317 @kindex rec btrace
7318 @kindex rec btrace bts
7319 @kindex rec btrace pt
7320 @kindex rec bts
7321 @kindex rec pt
7322 @item record @var{method}
7323 This command starts the process record and replay target. The
7324 recording method can be specified as parameter. Without a parameter
7325 the command uses the @code{full} recording method. The following
7326 recording methods are available:
7327
7328 @table @code
7329 @item full
7330 Full record/replay recording using @value{GDBN}'s software record and
7331 replay implementation. This method allows replaying and reverse
7332 execution.
7333
7334 @item btrace @var{format}
7335 Hardware-supported instruction recording, supported on Intel
7336 processors. This method does not record data. Further, the data is
7337 collected in a ring buffer so old data will be overwritten when the
7338 buffer is full. It allows limited reverse execution. Variables and
7339 registers are not available during reverse execution. In remote
7340 debugging, recording continues on disconnect. Recorded data can be
7341 inspected after reconnecting. The recording may be stopped using
7342 @code{record stop}.
7343
7344 The recording format can be specified as parameter. Without a parameter
7345 the command chooses the recording format. The following recording
7346 formats are available:
7347
7348 @table @code
7349 @item bts
7350 @cindex branch trace store
7351 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7352 this format, the processor stores a from/to record for each executed
7353 branch in the btrace ring buffer.
7354
7355 @item pt
7356 @cindex Intel Processor Trace
7357 Use the @dfn{Intel Processor Trace} recording format. In this
7358 format, the processor stores the execution trace in a compressed form
7359 that is afterwards decoded by @value{GDBN}.
7360
7361 The trace can be recorded with very low overhead. The compressed
7362 trace format also allows small trace buffers to already contain a big
7363 number of instructions compared to @acronym{BTS}.
7364
7365 Decoding the recorded execution trace, on the other hand, is more
7366 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7367 increased number of instructions to process. You should increase the
7368 buffer-size with care.
7369 @end table
7370
7371 Not all recording formats may be available on all processors.
7372 @end table
7373
7374 The process record and replay target can only debug a process that is
7375 already running. Therefore, you need first to start the process with
7376 the @kbd{run} or @kbd{start} commands, and then start the recording
7377 with the @kbd{record @var{method}} command.
7378
7379 @cindex displaced stepping, and process record and replay
7380 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7381 will be automatically disabled when process record and replay target
7382 is started. That's because the process record and replay target
7383 doesn't support displaced stepping.
7384
7385 @cindex non-stop mode, and process record and replay
7386 @cindex asynchronous execution, and process record and replay
7387 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7388 the asynchronous execution mode (@pxref{Background Execution}), not
7389 all recording methods are available. The @code{full} recording method
7390 does not support these two modes.
7391
7392 @kindex record stop
7393 @kindex rec s
7394 @item record stop
7395 Stop the process record and replay target. When process record and
7396 replay target stops, the entire execution log will be deleted and the
7397 inferior will either be terminated, or will remain in its final state.
7398
7399 When you stop the process record and replay target in record mode (at
7400 the end of the execution log), the inferior will be stopped at the
7401 next instruction that would have been recorded. In other words, if
7402 you record for a while and then stop recording, the inferior process
7403 will be left in the same state as if the recording never happened.
7404
7405 On the other hand, if the process record and replay target is stopped
7406 while in replay mode (that is, not at the end of the execution log,
7407 but at some earlier point), the inferior process will become ``live''
7408 at that earlier state, and it will then be possible to continue the
7409 usual ``live'' debugging of the process from that state.
7410
7411 When the inferior process exits, or @value{GDBN} detaches from it,
7412 process record and replay target will automatically stop itself.
7413
7414 @kindex record goto
7415 @item record goto
7416 Go to a specific location in the execution log. There are several
7417 ways to specify the location to go to:
7418
7419 @table @code
7420 @item record goto begin
7421 @itemx record goto start
7422 Go to the beginning of the execution log.
7423
7424 @item record goto end
7425 Go to the end of the execution log.
7426
7427 @item record goto @var{n}
7428 Go to instruction number @var{n} in the execution log.
7429 @end table
7430
7431 @kindex record save
7432 @item record save @var{filename}
7433 Save the execution log to a file @file{@var{filename}}.
7434 Default filename is @file{gdb_record.@var{process_id}}, where
7435 @var{process_id} is the process ID of the inferior.
7436
7437 This command may not be available for all recording methods.
7438
7439 @kindex record restore
7440 @item record restore @var{filename}
7441 Restore the execution log from a file @file{@var{filename}}.
7442 File must have been created with @code{record save}.
7443
7444 @kindex set record full
7445 @item set record full insn-number-max @var{limit}
7446 @itemx set record full insn-number-max unlimited
7447 Set the limit of instructions to be recorded for the @code{full}
7448 recording method. Default value is 200000.
7449
7450 If @var{limit} is a positive number, then @value{GDBN} will start
7451 deleting instructions from the log once the number of the record
7452 instructions becomes greater than @var{limit}. For every new recorded
7453 instruction, @value{GDBN} will delete the earliest recorded
7454 instruction to keep the number of recorded instructions at the limit.
7455 (Since deleting recorded instructions loses information, @value{GDBN}
7456 lets you control what happens when the limit is reached, by means of
7457 the @code{stop-at-limit} option, described below.)
7458
7459 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7460 delete recorded instructions from the execution log. The number of
7461 recorded instructions is limited only by the available memory.
7462
7463 @kindex show record full
7464 @item show record full insn-number-max
7465 Show the limit of instructions to be recorded with the @code{full}
7466 recording method.
7467
7468 @item set record full stop-at-limit
7469 Control the behavior of the @code{full} recording method when the
7470 number of recorded instructions reaches the limit. If ON (the
7471 default), @value{GDBN} will stop when the limit is reached for the
7472 first time and ask you whether you want to stop the inferior or
7473 continue running it and recording the execution log. If you decide
7474 to continue recording, each new recorded instruction will cause the
7475 oldest one to be deleted.
7476
7477 If this option is OFF, @value{GDBN} will automatically delete the
7478 oldest record to make room for each new one, without asking.
7479
7480 @item show record full stop-at-limit
7481 Show the current setting of @code{stop-at-limit}.
7482
7483 @item set record full memory-query
7484 Control the behavior when @value{GDBN} is unable to record memory
7485 changes caused by an instruction for the @code{full} recording method.
7486 If ON, @value{GDBN} will query whether to stop the inferior in that
7487 case.
7488
7489 If this option is OFF (the default), @value{GDBN} will automatically
7490 ignore the effect of such instructions on memory. Later, when
7491 @value{GDBN} replays this execution log, it will mark the log of this
7492 instruction as not accessible, and it will not affect the replay
7493 results.
7494
7495 @item show record full memory-query
7496 Show the current setting of @code{memory-query}.
7497
7498 @kindex set record btrace
7499 The @code{btrace} record target does not trace data. As a
7500 convenience, when replaying, @value{GDBN} reads read-only memory off
7501 the live program directly, assuming that the addresses of the
7502 read-only areas don't change. This for example makes it possible to
7503 disassemble code while replaying, but not to print variables.
7504 In some cases, being able to inspect variables might be useful.
7505 You can use the following command for that:
7506
7507 @item set record btrace replay-memory-access
7508 Control the behavior of the @code{btrace} recording method when
7509 accessing memory during replay. If @code{read-only} (the default),
7510 @value{GDBN} will only allow accesses to read-only memory.
7511 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7512 and to read-write memory. Beware that the accessed memory corresponds
7513 to the live target and not necessarily to the current replay
7514 position.
7515
7516 @item set record btrace cpu @var{identifier}
7517 Set the processor to be used for enabling workarounds for processor
7518 errata when decoding the trace.
7519
7520 Processor errata are defects in processor operation, caused by its
7521 design or manufacture. They can cause a trace not to match the
7522 specification. This, in turn, may cause trace decode to fail.
7523 @value{GDBN} can detect erroneous trace packets and correct them, thus
7524 avoiding the decoding failures. These corrections are known as
7525 @dfn{errata workarounds}, and are enabled based on the processor on
7526 which the trace was recorded.
7527
7528 By default, @value{GDBN} attempts to detect the processor
7529 automatically, and apply the necessary workarounds for it. However,
7530 you may need to specify the processor if @value{GDBN} does not yet
7531 support it. This command allows you to do that, and also allows to
7532 disable the workarounds.
7533
7534 The argument @var{identifier} identifies the @sc{cpu} and is of the
7535 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7536 there are two special identifiers, @code{none} and @code{auto}
7537 (default).
7538
7539 The following vendor identifiers and corresponding processor
7540 identifiers are currently supported:
7541
7542 @multitable @columnfractions .1 .9
7543
7544 @item @code{intel}
7545 @tab @var{family}/@var{model}[/@var{stepping}]
7546
7547 @end multitable
7548
7549 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7550 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7551
7552 If @var{identifier} is @code{auto}, enable errata workarounds for the
7553 processor on which the trace was recorded. If @var{identifier} is
7554 @code{none}, errata workarounds are disabled.
7555
7556 For example, when using an old @value{GDBN} on a new system, decode
7557 may fail because @value{GDBN} does not support the new processor. It
7558 often suffices to specify an older processor that @value{GDBN}
7559 supports.
7560
7561 @smallexample
7562 (gdb) info record
7563 Active record target: record-btrace
7564 Recording format: Intel Processor Trace.
7565 Buffer size: 16kB.
7566 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7567 (gdb) set record btrace cpu intel:6/158
7568 (gdb) info record
7569 Active record target: record-btrace
7570 Recording format: Intel Processor Trace.
7571 Buffer size: 16kB.
7572 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7573 @end smallexample
7574
7575 @kindex show record btrace
7576 @item show record btrace replay-memory-access
7577 Show the current setting of @code{replay-memory-access}.
7578
7579 @item show record btrace cpu
7580 Show the processor to be used for enabling trace decode errata
7581 workarounds.
7582
7583 @kindex set record btrace bts
7584 @item set record btrace bts buffer-size @var{size}
7585 @itemx set record btrace bts buffer-size unlimited
7586 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7587 format. Default is 64KB.
7588
7589 If @var{size} is a positive number, then @value{GDBN} will try to
7590 allocate a buffer of at least @var{size} bytes for each new thread
7591 that uses the btrace recording method and the @acronym{BTS} format.
7592 The actually obtained buffer size may differ from the requested
7593 @var{size}. Use the @code{info record} command to see the actual
7594 buffer size for each thread that uses the btrace recording method and
7595 the @acronym{BTS} format.
7596
7597 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7598 allocate a buffer of 4MB.
7599
7600 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7601 also need longer to process the branch trace data before it can be used.
7602
7603 @item show record btrace bts buffer-size @var{size}
7604 Show the current setting of the requested ring buffer size for branch
7605 tracing in @acronym{BTS} format.
7606
7607 @kindex set record btrace pt
7608 @item set record btrace pt buffer-size @var{size}
7609 @itemx set record btrace pt buffer-size unlimited
7610 Set the requested ring buffer size for branch tracing in Intel
7611 Processor Trace format. Default is 16KB.
7612
7613 If @var{size} is a positive number, then @value{GDBN} will try to
7614 allocate a buffer of at least @var{size} bytes for each new thread
7615 that uses the btrace recording method and the Intel Processor Trace
7616 format. The actually obtained buffer size may differ from the
7617 requested @var{size}. Use the @code{info record} command to see the
7618 actual buffer size for each thread.
7619
7620 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7621 allocate a buffer of 4MB.
7622
7623 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7624 also need longer to process the branch trace data before it can be used.
7625
7626 @item show record btrace pt buffer-size @var{size}
7627 Show the current setting of the requested ring buffer size for branch
7628 tracing in Intel Processor Trace format.
7629
7630 @kindex info record
7631 @item info record
7632 Show various statistics about the recording depending on the recording
7633 method:
7634
7635 @table @code
7636 @item full
7637 For the @code{full} recording method, it shows the state of process
7638 record and its in-memory execution log buffer, including:
7639
7640 @itemize @bullet
7641 @item
7642 Whether in record mode or replay mode.
7643 @item
7644 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7645 @item
7646 Highest recorded instruction number.
7647 @item
7648 Current instruction about to be replayed (if in replay mode).
7649 @item
7650 Number of instructions contained in the execution log.
7651 @item
7652 Maximum number of instructions that may be contained in the execution log.
7653 @end itemize
7654
7655 @item btrace
7656 For the @code{btrace} recording method, it shows:
7657
7658 @itemize @bullet
7659 @item
7660 Recording format.
7661 @item
7662 Number of instructions that have been recorded.
7663 @item
7664 Number of blocks of sequential control-flow formed by the recorded
7665 instructions.
7666 @item
7667 Whether in record mode or replay mode.
7668 @end itemize
7669
7670 For the @code{bts} recording format, it also shows:
7671 @itemize @bullet
7672 @item
7673 Size of the perf ring buffer.
7674 @end itemize
7675
7676 For the @code{pt} recording format, it also shows:
7677 @itemize @bullet
7678 @item
7679 Size of the perf ring buffer.
7680 @end itemize
7681 @end table
7682
7683 @kindex record delete
7684 @kindex rec del
7685 @item record delete
7686 When record target runs in replay mode (``in the past''), delete the
7687 subsequent execution log and begin to record a new execution log starting
7688 from the current address. This means you will abandon the previously
7689 recorded ``future'' and begin recording a new ``future''.
7690
7691 @kindex record instruction-history
7692 @kindex rec instruction-history
7693 @item record instruction-history
7694 Disassembles instructions from the recorded execution log. By
7695 default, ten instructions are disassembled. This can be changed using
7696 the @code{set record instruction-history-size} command. Instructions
7697 are printed in execution order.
7698
7699 It can also print mixed source+disassembly if you specify the the
7700 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7701 as well as in symbolic form by specifying the @code{/r} modifier.
7702
7703 The current position marker is printed for the instruction at the
7704 current program counter value. This instruction can appear multiple
7705 times in the trace and the current position marker will be printed
7706 every time. To omit the current position marker, specify the
7707 @code{/p} modifier.
7708
7709 To better align the printed instructions when the trace contains
7710 instructions from more than one function, the function name may be
7711 omitted by specifying the @code{/f} modifier.
7712
7713 Speculatively executed instructions are prefixed with @samp{?}. This
7714 feature is not available for all recording formats.
7715
7716 There are several ways to specify what part of the execution log to
7717 disassemble:
7718
7719 @table @code
7720 @item record instruction-history @var{insn}
7721 Disassembles ten instructions starting from instruction number
7722 @var{insn}.
7723
7724 @item record instruction-history @var{insn}, +/-@var{n}
7725 Disassembles @var{n} instructions around instruction number
7726 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7727 @var{n} instructions after instruction number @var{insn}. If
7728 @var{n} is preceded with @code{-}, disassembles @var{n}
7729 instructions before instruction number @var{insn}.
7730
7731 @item record instruction-history
7732 Disassembles ten more instructions after the last disassembly.
7733
7734 @item record instruction-history -
7735 Disassembles ten more instructions before the last disassembly.
7736
7737 @item record instruction-history @var{begin}, @var{end}
7738 Disassembles instructions beginning with instruction number
7739 @var{begin} until instruction number @var{end}. The instruction
7740 number @var{end} is included.
7741 @end table
7742
7743 This command may not be available for all recording methods.
7744
7745 @kindex set record
7746 @item set record instruction-history-size @var{size}
7747 @itemx set record instruction-history-size unlimited
7748 Define how many instructions to disassemble in the @code{record
7749 instruction-history} command. The default value is 10.
7750 A @var{size} of @code{unlimited} means unlimited instructions.
7751
7752 @kindex show record
7753 @item show record instruction-history-size
7754 Show how many instructions to disassemble in the @code{record
7755 instruction-history} command.
7756
7757 @kindex record function-call-history
7758 @kindex rec function-call-history
7759 @item record function-call-history
7760 Prints the execution history at function granularity. It prints one
7761 line for each sequence of instructions that belong to the same
7762 function giving the name of that function, the source lines
7763 for this instruction sequence (if the @code{/l} modifier is
7764 specified), and the instructions numbers that form the sequence (if
7765 the @code{/i} modifier is specified). The function names are indented
7766 to reflect the call stack depth if the @code{/c} modifier is
7767 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7768 given together.
7769
7770 @smallexample
7771 (@value{GDBP}) @b{list 1, 10}
7772 1 void foo (void)
7773 2 @{
7774 3 @}
7775 4
7776 5 void bar (void)
7777 6 @{
7778 7 ...
7779 8 foo ();
7780 9 ...
7781 10 @}
7782 (@value{GDBP}) @b{record function-call-history /ilc}
7783 1 bar inst 1,4 at foo.c:6,8
7784 2 foo inst 5,10 at foo.c:2,3
7785 3 bar inst 11,13 at foo.c:9,10
7786 @end smallexample
7787
7788 By default, ten lines are printed. This can be changed using the
7789 @code{set record function-call-history-size} command. Functions are
7790 printed in execution order. There are several ways to specify what
7791 to print:
7792
7793 @table @code
7794 @item record function-call-history @var{func}
7795 Prints ten functions starting from function number @var{func}.
7796
7797 @item record function-call-history @var{func}, +/-@var{n}
7798 Prints @var{n} functions around function number @var{func}. If
7799 @var{n} is preceded with @code{+}, prints @var{n} functions after
7800 function number @var{func}. If @var{n} is preceded with @code{-},
7801 prints @var{n} functions before function number @var{func}.
7802
7803 @item record function-call-history
7804 Prints ten more functions after the last ten-line print.
7805
7806 @item record function-call-history -
7807 Prints ten more functions before the last ten-line print.
7808
7809 @item record function-call-history @var{begin}, @var{end}
7810 Prints functions beginning with function number @var{begin} until
7811 function number @var{end}. The function number @var{end} is included.
7812 @end table
7813
7814 This command may not be available for all recording methods.
7815
7816 @item set record function-call-history-size @var{size}
7817 @itemx set record function-call-history-size unlimited
7818 Define how many lines to print in the
7819 @code{record function-call-history} command. The default value is 10.
7820 A size of @code{unlimited} means unlimited lines.
7821
7822 @item show record function-call-history-size
7823 Show how many lines to print in the
7824 @code{record function-call-history} command.
7825 @end table
7826
7827
7828 @node Stack
7829 @chapter Examining the Stack
7830
7831 When your program has stopped, the first thing you need to know is where it
7832 stopped and how it got there.
7833
7834 @cindex call stack
7835 Each time your program performs a function call, information about the call
7836 is generated.
7837 That information includes the location of the call in your program,
7838 the arguments of the call,
7839 and the local variables of the function being called.
7840 The information is saved in a block of data called a @dfn{stack frame}.
7841 The stack frames are allocated in a region of memory called the @dfn{call
7842 stack}.
7843
7844 When your program stops, the @value{GDBN} commands for examining the
7845 stack allow you to see all of this information.
7846
7847 @cindex selected frame
7848 One of the stack frames is @dfn{selected} by @value{GDBN} and many
7849 @value{GDBN} commands refer implicitly to the selected frame. In
7850 particular, whenever you ask @value{GDBN} for the value of a variable in
7851 your program, the value is found in the selected frame. There are
7852 special @value{GDBN} commands to select whichever frame you are
7853 interested in. @xref{Selection, ,Selecting a Frame}.
7854
7855 When your program stops, @value{GDBN} automatically selects the
7856 currently executing frame and describes it briefly, similar to the
7857 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
7858
7859 @menu
7860 * Frames:: Stack frames
7861 * Backtrace:: Backtraces
7862 * Selection:: Selecting a frame
7863 * Frame Info:: Information on a frame
7864 * Frame Apply:: Applying a command to several frames
7865 * Frame Filter Management:: Managing frame filters
7866
7867 @end menu
7868
7869 @node Frames
7870 @section Stack Frames
7871
7872 @cindex frame, definition
7873 @cindex stack frame
7874 The call stack is divided up into contiguous pieces called @dfn{stack
7875 frames}, or @dfn{frames} for short; each frame is the data associated
7876 with one call to one function. The frame contains the arguments given
7877 to the function, the function's local variables, and the address at
7878 which the function is executing.
7879
7880 @cindex initial frame
7881 @cindex outermost frame
7882 @cindex innermost frame
7883 When your program is started, the stack has only one frame, that of the
7884 function @code{main}. This is called the @dfn{initial} frame or the
7885 @dfn{outermost} frame. Each time a function is called, a new frame is
7886 made. Each time a function returns, the frame for that function invocation
7887 is eliminated. If a function is recursive, there can be many frames for
7888 the same function. The frame for the function in which execution is
7889 actually occurring is called the @dfn{innermost} frame. This is the most
7890 recently created of all the stack frames that still exist.
7891
7892 @cindex frame pointer
7893 Inside your program, stack frames are identified by their addresses. A
7894 stack frame consists of many bytes, each of which has its own address; each
7895 kind of computer has a convention for choosing one byte whose
7896 address serves as the address of the frame. Usually this address is kept
7897 in a register called the @dfn{frame pointer register}
7898 (@pxref{Registers, $fp}) while execution is going on in that frame.
7899
7900 @cindex frame level
7901 @cindex frame number
7902 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
7903 number that is zero for the innermost frame, one for the frame that
7904 called it, and so on upward. These level numbers give you a way of
7905 designating stack frames in @value{GDBN} commands. The terms
7906 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
7907 describe this number.
7908
7909 @c The -fomit-frame-pointer below perennially causes hbox overflow
7910 @c underflow problems.
7911 @cindex frameless execution
7912 Some compilers provide a way to compile functions so that they operate
7913 without stack frames. (For example, the @value{NGCC} option
7914 @smallexample
7915 @samp{-fomit-frame-pointer}
7916 @end smallexample
7917 generates functions without a frame.)
7918 This is occasionally done with heavily used library functions to save
7919 the frame setup time. @value{GDBN} has limited facilities for dealing
7920 with these function invocations. If the innermost function invocation
7921 has no stack frame, @value{GDBN} nevertheless regards it as though
7922 it had a separate frame, which is numbered zero as usual, allowing
7923 correct tracing of the function call chain. However, @value{GDBN} has
7924 no provision for frameless functions elsewhere in the stack.
7925
7926 @node Backtrace
7927 @section Backtraces
7928
7929 @cindex traceback
7930 @cindex call stack traces
7931 A backtrace is a summary of how your program got where it is. It shows one
7932 line per frame, for many frames, starting with the currently executing
7933 frame (frame zero), followed by its caller (frame one), and on up the
7934 stack.
7935
7936 @anchor{backtrace-command}
7937 @kindex backtrace
7938 @kindex bt @r{(@code{backtrace})}
7939 To print a backtrace of the entire stack, use the @code{backtrace}
7940 command, or its alias @code{bt}. This command will print one line per
7941 frame for frames in the stack. By default, all stack frames are
7942 printed. You can stop the backtrace at any time by typing the system
7943 interrupt character, normally @kbd{Ctrl-c}.
7944
7945 @table @code
7946 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7947 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7948 Print the backtrace of the entire stack.
7949
7950 The optional @var{count} can be one of the following:
7951
7952 @table @code
7953 @item @var{n}
7954 @itemx @var{n}
7955 Print only the innermost @var{n} frames, where @var{n} is a positive
7956 number.
7957
7958 @item -@var{n}
7959 @itemx -@var{n}
7960 Print only the outermost @var{n} frames, where @var{n} is a positive
7961 number.
7962 @end table
7963
7964 Options:
7965
7966 @table @code
7967 @item -full
7968 Print the values of the local variables also. This can be combined
7969 with the optional @var{count} to limit the number of frames shown.
7970
7971 @item -no-filters
7972 Do not run Python frame filters on this backtrace. @xref{Frame
7973 Filter API}, for more information. Additionally use @ref{disable
7974 frame-filter all} to turn off all frame filters. This is only
7975 relevant when @value{GDBN} has been configured with @code{Python}
7976 support.
7977
7978 @item -hide
7979 A Python frame filter might decide to ``elide'' some frames. Normally
7980 such elided frames are still printed, but they are indented relative
7981 to the filtered frames that cause them to be elided. The @code{-hide}
7982 option causes elided frames to not be printed at all.
7983 @end table
7984
7985 The @code{backtrace} command also supports a number of options that
7986 allow overriding relevant global print settings as set by @code{set
7987 backtrace} and @code{set print} subcommands:
7988
7989 @table @code
7990 @item -past-main [@code{on}|@code{off}]
7991 Set whether backtraces should continue past @code{main}. Related setting:
7992 @ref{set backtrace past-main}.
7993
7994 @item -past-entry [@code{on}|@code{off}]
7995 Set whether backtraces should continue past the entry point of a program.
7996 Related setting: @ref{set backtrace past-entry}.
7997
7998 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
7999 Set printing of function arguments at function entry.
8000 Related setting: @ref{set print entry-values}.
8001
8002 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8003 Set printing of non-scalar frame arguments.
8004 Related setting: @ref{set print frame-arguments}.
8005
8006 @item -raw-frame-arguments [@code{on}|@code{off}]
8007 Set whether to print frame arguments in raw form.
8008 Related setting: @ref{set print raw-frame-arguments}.
8009
8010 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8011 Set printing of frame information.
8012 Related setting: @ref{set print frame-info}.
8013 @end table
8014
8015 The optional @var{qualifier} is maintained for backward compatibility.
8016 It can be one of the following:
8017
8018 @table @code
8019 @item full
8020 Equivalent to the @code{-full} option.
8021
8022 @item no-filters
8023 Equivalent to the @code{-no-filters} option.
8024
8025 @item hide
8026 Equivalent to the @code{-hide} option.
8027 @end table
8028
8029 @end table
8030
8031 @kindex where
8032 @kindex info stack
8033 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8034 are additional aliases for @code{backtrace}.
8035
8036 @cindex multiple threads, backtrace
8037 In a multi-threaded program, @value{GDBN} by default shows the
8038 backtrace only for the current thread. To display the backtrace for
8039 several or all of the threads, use the command @code{thread apply}
8040 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8041 apply all backtrace}, @value{GDBN} will display the backtrace for all
8042 the threads; this is handy when you debug a core dump of a
8043 multi-threaded program.
8044
8045 Each line in the backtrace shows the frame number and the function name.
8046 The program counter value is also shown---unless you use @code{set
8047 print address off}. The backtrace also shows the source file name and
8048 line number, as well as the arguments to the function. The program
8049 counter value is omitted if it is at the beginning of the code for that
8050 line number.
8051
8052 Here is an example of a backtrace. It was made with the command
8053 @samp{bt 3}, so it shows the innermost three frames.
8054
8055 @smallexample
8056 @group
8057 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8058 at builtin.c:993
8059 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8060 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8061 at macro.c:71
8062 (More stack frames follow...)
8063 @end group
8064 @end smallexample
8065
8066 @noindent
8067 The display for frame zero does not begin with a program counter
8068 value, indicating that your program has stopped at the beginning of the
8069 code for line @code{993} of @code{builtin.c}.
8070
8071 @noindent
8072 The value of parameter @code{data} in frame 1 has been replaced by
8073 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8074 only if it is a scalar (integer, pointer, enumeration, etc). See command
8075 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8076 on how to configure the way function parameter values are printed.
8077 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8078 what frame information is printed.
8079
8080 @cindex optimized out, in backtrace
8081 @cindex function call arguments, optimized out
8082 If your program was compiled with optimizations, some compilers will
8083 optimize away arguments passed to functions if those arguments are
8084 never used after the call. Such optimizations generate code that
8085 passes arguments through registers, but doesn't store those arguments
8086 in the stack frame. @value{GDBN} has no way of displaying such
8087 arguments in stack frames other than the innermost one. Here's what
8088 such a backtrace might look like:
8089
8090 @smallexample
8091 @group
8092 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8093 at builtin.c:993
8094 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8095 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8096 at macro.c:71
8097 (More stack frames follow...)
8098 @end group
8099 @end smallexample
8100
8101 @noindent
8102 The values of arguments that were not saved in their stack frames are
8103 shown as @samp{<optimized out>}.
8104
8105 If you need to display the values of such optimized-out arguments,
8106 either deduce that from other variables whose values depend on the one
8107 you are interested in, or recompile without optimizations.
8108
8109 @cindex backtrace beyond @code{main} function
8110 @cindex program entry point
8111 @cindex startup code, and backtrace
8112 Most programs have a standard user entry point---a place where system
8113 libraries and startup code transition into user code. For C this is
8114 @code{main}@footnote{
8115 Note that embedded programs (the so-called ``free-standing''
8116 environment) are not required to have a @code{main} function as the
8117 entry point. They could even have multiple entry points.}.
8118 When @value{GDBN} finds the entry function in a backtrace
8119 it will terminate the backtrace, to avoid tracing into highly
8120 system-specific (and generally uninteresting) code.
8121
8122 If you need to examine the startup code, or limit the number of levels
8123 in a backtrace, you can change this behavior:
8124
8125 @table @code
8126 @item set backtrace past-main
8127 @itemx set backtrace past-main on
8128 @anchor{set backtrace past-main}
8129 @kindex set backtrace
8130 Backtraces will continue past the user entry point.
8131
8132 @item set backtrace past-main off
8133 Backtraces will stop when they encounter the user entry point. This is the
8134 default.
8135
8136 @item show backtrace past-main
8137 @kindex show backtrace
8138 Display the current user entry point backtrace policy.
8139
8140 @item set backtrace past-entry
8141 @itemx set backtrace past-entry on
8142 @anchor{set backtrace past-entry}
8143 Backtraces will continue past the internal entry point of an application.
8144 This entry point is encoded by the linker when the application is built,
8145 and is likely before the user entry point @code{main} (or equivalent) is called.
8146
8147 @item set backtrace past-entry off
8148 Backtraces will stop when they encounter the internal entry point of an
8149 application. This is the default.
8150
8151 @item show backtrace past-entry
8152 Display the current internal entry point backtrace policy.
8153
8154 @item set backtrace limit @var{n}
8155 @itemx set backtrace limit 0
8156 @itemx set backtrace limit unlimited
8157 @anchor{set backtrace limit}
8158 @cindex backtrace limit
8159 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8160 or zero means unlimited levels.
8161
8162 @item show backtrace limit
8163 Display the current limit on backtrace levels.
8164 @end table
8165
8166 You can control how file names are displayed.
8167
8168 @table @code
8169 @item set filename-display
8170 @itemx set filename-display relative
8171 @cindex filename-display
8172 Display file names relative to the compilation directory. This is the default.
8173
8174 @item set filename-display basename
8175 Display only basename of a filename.
8176
8177 @item set filename-display absolute
8178 Display an absolute filename.
8179
8180 @item show filename-display
8181 Show the current way to display filenames.
8182 @end table
8183
8184 @node Selection
8185 @section Selecting a Frame
8186
8187 Most commands for examining the stack and other data in your program work on
8188 whichever stack frame is selected at the moment. Here are the commands for
8189 selecting a stack frame; all of them finish by printing a brief description
8190 of the stack frame just selected.
8191
8192 @table @code
8193 @kindex frame@r{, selecting}
8194 @kindex f @r{(@code{frame})}
8195 @item frame @r{[} @var{frame-selection-spec} @r{]}
8196 @item f @r{[} @var{frame-selection-spec} @r{]}
8197 The @command{frame} command allows different stack frames to be
8198 selected. The @var{frame-selection-spec} can be any of the following:
8199
8200 @table @code
8201 @kindex frame level
8202 @item @var{num}
8203 @item level @var{num}
8204 Select frame level @var{num}. Recall that frame zero is the innermost
8205 (currently executing) frame, frame one is the frame that called the
8206 innermost one, and so on. The highest level frame is usually the one
8207 for @code{main}.
8208
8209 As this is the most common method of navigating the frame stack, the
8210 string @command{level} can be omitted. For example, the following two
8211 commands are equivalent:
8212
8213 @smallexample
8214 (@value{GDBP}) frame 3
8215 (@value{GDBP}) frame level 3
8216 @end smallexample
8217
8218 @kindex frame address
8219 @item address @var{stack-address}
8220 Select the frame with stack address @var{stack-address}. The
8221 @var{stack-address} for a frame can be seen in the output of
8222 @command{info frame}, for example:
8223
8224 @smallexample
8225 (gdb) info frame
8226 Stack level 1, frame at 0x7fffffffda30:
8227 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8228 tail call frame, caller of frame at 0x7fffffffda30
8229 source language c++.
8230 Arglist at unknown address.
8231 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8232 @end smallexample
8233
8234 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8235 indicated by the line:
8236
8237 @smallexample
8238 Stack level 1, frame at 0x7fffffffda30:
8239 @end smallexample
8240
8241 @kindex frame function
8242 @item function @var{function-name}
8243 Select the stack frame for function @var{function-name}. If there are
8244 multiple stack frames for function @var{function-name} then the inner
8245 most stack frame is selected.
8246
8247 @kindex frame view
8248 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8249 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8250 viewed has stack address @var{stack-addr}, and optionally, a program
8251 counter address of @var{pc-addr}.
8252
8253 This is useful mainly if the chaining of stack frames has been
8254 damaged by a bug, making it impossible for @value{GDBN} to assign
8255 numbers properly to all frames. In addition, this can be useful
8256 when your program has multiple stacks and switches between them.
8257
8258 When viewing a frame outside the current backtrace using
8259 @command{frame view} then you can always return to the original
8260 stack using one of the previous stack frame selection instructions,
8261 for example @command{frame level 0}.
8262
8263 @end table
8264
8265 @kindex up
8266 @item up @var{n}
8267 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8268 numbers @var{n}, this advances toward the outermost frame, to higher
8269 frame numbers, to frames that have existed longer.
8270
8271 @kindex down
8272 @kindex do @r{(@code{down})}
8273 @item down @var{n}
8274 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8275 positive numbers @var{n}, this advances toward the innermost frame, to
8276 lower frame numbers, to frames that were created more recently.
8277 You may abbreviate @code{down} as @code{do}.
8278 @end table
8279
8280 All of these commands end by printing two lines of output describing the
8281 frame. The first line shows the frame number, the function name, the
8282 arguments, and the source file and line number of execution in that
8283 frame. The second line shows the text of that source line.
8284
8285 @need 1000
8286 For example:
8287
8288 @smallexample
8289 @group
8290 (@value{GDBP}) up
8291 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8292 at env.c:10
8293 10 read_input_file (argv[i]);
8294 @end group
8295 @end smallexample
8296
8297 After such a printout, the @code{list} command with no arguments
8298 prints ten lines centered on the point of execution in the frame.
8299 You can also edit the program at the point of execution with your favorite
8300 editing program by typing @code{edit}.
8301 @xref{List, ,Printing Source Lines},
8302 for details.
8303
8304 @table @code
8305 @kindex select-frame
8306 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8307 The @code{select-frame} command is a variant of @code{frame} that does
8308 not display the new frame after selecting it. This command is
8309 intended primarily for use in @value{GDBN} command scripts, where the
8310 output might be unnecessary and distracting. The
8311 @var{frame-selection-spec} is as for the @command{frame} command
8312 described in @ref{Selection, ,Selecting a Frame}.
8313
8314 @kindex down-silently
8315 @kindex up-silently
8316 @item up-silently @var{n}
8317 @itemx down-silently @var{n}
8318 These two commands are variants of @code{up} and @code{down},
8319 respectively; they differ in that they do their work silently, without
8320 causing display of the new frame. They are intended primarily for use
8321 in @value{GDBN} command scripts, where the output might be unnecessary and
8322 distracting.
8323 @end table
8324
8325 @node Frame Info
8326 @section Information About a Frame
8327
8328 There are several other commands to print information about the selected
8329 stack frame.
8330
8331 @table @code
8332 @item frame
8333 @itemx f
8334 When used without any argument, this command does not change which
8335 frame is selected, but prints a brief description of the currently
8336 selected stack frame. It can be abbreviated @code{f}. With an
8337 argument, this command is used to select a stack frame.
8338 @xref{Selection, ,Selecting a Frame}.
8339
8340 @kindex info frame
8341 @kindex info f @r{(@code{info frame})}
8342 @item info frame
8343 @itemx info f
8344 This command prints a verbose description of the selected stack frame,
8345 including:
8346
8347 @itemize @bullet
8348 @item
8349 the address of the frame
8350 @item
8351 the address of the next frame down (called by this frame)
8352 @item
8353 the address of the next frame up (caller of this frame)
8354 @item
8355 the language in which the source code corresponding to this frame is written
8356 @item
8357 the address of the frame's arguments
8358 @item
8359 the address of the frame's local variables
8360 @item
8361 the program counter saved in it (the address of execution in the caller frame)
8362 @item
8363 which registers were saved in the frame
8364 @end itemize
8365
8366 @noindent The verbose description is useful when
8367 something has gone wrong that has made the stack format fail to fit
8368 the usual conventions.
8369
8370 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8371 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8372 Print a verbose description of the frame selected by
8373 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8374 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8375 a Frame}). The selected frame remains unchanged by this command.
8376
8377 @kindex info args
8378 @item info args [-q]
8379 Print the arguments of the selected frame, each on a separate line.
8380
8381 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8382 printing header information and messages explaining why no argument
8383 have been printed.
8384
8385 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8386 Like @kbd{info args}, but only print the arguments selected
8387 with the provided regexp(s).
8388
8389 If @var{regexp} is provided, print only the arguments whose names
8390 match the regular expression @var{regexp}.
8391
8392 If @var{type_regexp} is provided, print only the arguments whose
8393 types, as printed by the @code{whatis} command, match
8394 the regular expression @var{type_regexp}.
8395 If @var{type_regexp} contains space(s), it should be enclosed in
8396 quote characters. If needed, use backslash to escape the meaning
8397 of special characters or quotes.
8398
8399 If both @var{regexp} and @var{type_regexp} are provided, an argument
8400 is printed only if its name matches @var{regexp} and its type matches
8401 @var{type_regexp}.
8402
8403 @item info locals [-q]
8404 @kindex info locals
8405 Print the local variables of the selected frame, each on a separate
8406 line. These are all variables (declared either static or automatic)
8407 accessible at the point of execution of the selected frame.
8408
8409 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8410 printing header information and messages explaining why no local variables
8411 have been printed.
8412
8413 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8414 Like @kbd{info locals}, but only print the local variables selected
8415 with the provided regexp(s).
8416
8417 If @var{regexp} is provided, print only the local variables whose names
8418 match the regular expression @var{regexp}.
8419
8420 If @var{type_regexp} is provided, print only the local variables whose
8421 types, as printed by the @code{whatis} command, match
8422 the regular expression @var{type_regexp}.
8423 If @var{type_regexp} contains space(s), it should be enclosed in
8424 quote characters. If needed, use backslash to escape the meaning
8425 of special characters or quotes.
8426
8427 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8428 is printed only if its name matches @var{regexp} and its type matches
8429 @var{type_regexp}.
8430
8431 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8432 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8433 For example, your program might use Resource Acquisition Is
8434 Initialization types (RAII) such as @code{lock_something_t}: each
8435 local variable of type @code{lock_something_t} automatically places a
8436 lock that is destroyed when the variable goes out of scope. You can
8437 then list all acquired locks in your program by doing
8438 @smallexample
8439 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8440 @end smallexample
8441 @noindent
8442 or the equivalent shorter form
8443 @smallexample
8444 tfaas i lo -q -t lock_something_t
8445 @end smallexample
8446
8447 @end table
8448
8449 @node Frame Apply
8450 @section Applying a Command to Several Frames.
8451 @anchor{frame apply}
8452 @kindex frame apply
8453 @cindex apply command to several frames
8454 @table @code
8455 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8456 The @code{frame apply} command allows you to apply the named
8457 @var{command} to one or more frames.
8458
8459 @table @code
8460 @item @code{all}
8461 Specify @code{all} to apply @var{command} to all frames.
8462
8463 @item @var{count}
8464 Use @var{count} to apply @var{command} to the innermost @var{count}
8465 frames, where @var{count} is a positive number.
8466
8467 @item @var{-count}
8468 Use @var{-count} to apply @var{command} to the outermost @var{count}
8469 frames, where @var{count} is a positive number.
8470
8471 @item @code{level}
8472 Use @code{level} to apply @var{command} to the set of frames identified
8473 by the @var{level} list. @var{level} is a frame level or a range of frame
8474 levels as @var{level1}-@var{level2}. The frame level is the number shown
8475 in the first field of the @samp{backtrace} command output.
8476 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8477 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8478
8479 @end table
8480
8481 Note that the frames on which @code{frame apply} applies a command are
8482 also influenced by the @code{set backtrace} settings such as @code{set
8483 backtrace past-main} and @code{set backtrace limit N}.
8484 @xref{Backtrace,,Backtraces}.
8485
8486 The @code{frame apply} command also supports a number of options that
8487 allow overriding relevant @code{set backtrace} settings:
8488
8489 @table @code
8490 @item -past-main [@code{on}|@code{off}]
8491 Whether backtraces should continue past @code{main}.
8492 Related setting: @ref{set backtrace past-main}.
8493
8494 @item -past-entry [@code{on}|@code{off}]
8495 Whether backtraces should continue past the entry point of a program.
8496 Related setting: @ref{set backtrace past-entry}.
8497 @end table
8498
8499 By default, @value{GDBN} displays some frame information before the
8500 output produced by @var{command}, and an error raised during the
8501 execution of a @var{command} will abort @code{frame apply}. The
8502 following options can be used to fine-tune these behaviors:
8503
8504 @table @code
8505 @item -c
8506 The flag @code{-c}, which stands for @samp{continue}, causes any
8507 errors in @var{command} to be displayed, and the execution of
8508 @code{frame apply} then continues.
8509 @item -s
8510 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8511 or empty output produced by a @var{command} to be silently ignored.
8512 That is, the execution continues, but the frame information and errors
8513 are not printed.
8514 @item -q
8515 The flag @code{-q} (@samp{quiet}) disables printing the frame
8516 information.
8517 @end table
8518
8519 The following example shows how the flags @code{-c} and @code{-s} are
8520 working when applying the command @code{p j} to all frames, where
8521 variable @code{j} can only be successfully printed in the outermost
8522 @code{#1 main} frame.
8523
8524 @smallexample
8525 @group
8526 (gdb) frame apply all p j
8527 #0 some_function (i=5) at fun.c:4
8528 No symbol "j" in current context.
8529 (gdb) frame apply all -c p j
8530 #0 some_function (i=5) at fun.c:4
8531 No symbol "j" in current context.
8532 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8533 $1 = 5
8534 (gdb) frame apply all -s p j
8535 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8536 $2 = 5
8537 (gdb)
8538 @end group
8539 @end smallexample
8540
8541 By default, @samp{frame apply}, prints the frame location
8542 information before the command output:
8543
8544 @smallexample
8545 @group
8546 (gdb) frame apply all p $sp
8547 #0 some_function (i=5) at fun.c:4
8548 $4 = (void *) 0xffffd1e0
8549 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8550 $5 = (void *) 0xffffd1f0
8551 (gdb)
8552 @end group
8553 @end smallexample
8554
8555 If the flag @code{-q} is given, no frame information is printed:
8556 @smallexample
8557 @group
8558 (gdb) frame apply all -q p $sp
8559 $12 = (void *) 0xffffd1e0
8560 $13 = (void *) 0xffffd1f0
8561 (gdb)
8562 @end group
8563 @end smallexample
8564
8565 @end table
8566
8567 @table @code
8568
8569 @kindex faas
8570 @cindex apply a command to all frames (ignoring errors and empty output)
8571 @item faas @var{command}
8572 Shortcut for @code{frame apply all -s @var{command}}.
8573 Applies @var{command} on all frames, ignoring errors and empty output.
8574
8575 It can for example be used to print a local variable or a function
8576 argument without knowing the frame where this variable or argument
8577 is, using:
8578 @smallexample
8579 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8580 @end smallexample
8581
8582 The @code{faas} command accepts the same options as the @code{frame
8583 apply} command. @xref{frame apply}.
8584
8585 Note that the command @code{tfaas @var{command}} applies @var{command}
8586 on all frames of all threads. See @xref{Threads,,Threads}.
8587 @end table
8588
8589
8590 @node Frame Filter Management
8591 @section Management of Frame Filters.
8592 @cindex managing frame filters
8593
8594 Frame filters are Python based utilities to manage and decorate the
8595 output of frames. @xref{Frame Filter API}, for further information.
8596
8597 Managing frame filters is performed by several commands available
8598 within @value{GDBN}, detailed here.
8599
8600 @table @code
8601 @kindex info frame-filter
8602 @item info frame-filter
8603 Print a list of installed frame filters from all dictionaries, showing
8604 their name, priority and enabled status.
8605
8606 @kindex disable frame-filter
8607 @anchor{disable frame-filter all}
8608 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8609 Disable a frame filter in the dictionary matching
8610 @var{filter-dictionary} and @var{filter-name}. The
8611 @var{filter-dictionary} may be @code{all}, @code{global},
8612 @code{progspace}, or the name of the object file where the frame filter
8613 dictionary resides. When @code{all} is specified, all frame filters
8614 across all dictionaries are disabled. The @var{filter-name} is the name
8615 of the frame filter and is used when @code{all} is not the option for
8616 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8617 may be enabled again later.
8618
8619 @kindex enable frame-filter
8620 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8621 Enable a frame filter in the dictionary matching
8622 @var{filter-dictionary} and @var{filter-name}. The
8623 @var{filter-dictionary} may be @code{all}, @code{global},
8624 @code{progspace} or the name of the object file where the frame filter
8625 dictionary resides. When @code{all} is specified, all frame filters across
8626 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8627 filter and is used when @code{all} is not the option for
8628 @var{filter-dictionary}.
8629
8630 Example:
8631
8632 @smallexample
8633 (gdb) info frame-filter
8634
8635 global frame-filters:
8636 Priority Enabled Name
8637 1000 No PrimaryFunctionFilter
8638 100 Yes Reverse
8639
8640 progspace /build/test frame-filters:
8641 Priority Enabled Name
8642 100 Yes ProgspaceFilter
8643
8644 objfile /build/test frame-filters:
8645 Priority Enabled Name
8646 999 Yes BuildProgramFilter
8647
8648 (gdb) disable frame-filter /build/test BuildProgramFilter
8649 (gdb) info frame-filter
8650
8651 global frame-filters:
8652 Priority Enabled Name
8653 1000 No PrimaryFunctionFilter
8654 100 Yes Reverse
8655
8656 progspace /build/test frame-filters:
8657 Priority Enabled Name
8658 100 Yes ProgspaceFilter
8659
8660 objfile /build/test frame-filters:
8661 Priority Enabled Name
8662 999 No BuildProgramFilter
8663
8664 (gdb) enable frame-filter global PrimaryFunctionFilter
8665 (gdb) info frame-filter
8666
8667 global frame-filters:
8668 Priority Enabled Name
8669 1000 Yes PrimaryFunctionFilter
8670 100 Yes Reverse
8671
8672 progspace /build/test frame-filters:
8673 Priority Enabled Name
8674 100 Yes ProgspaceFilter
8675
8676 objfile /build/test frame-filters:
8677 Priority Enabled Name
8678 999 No BuildProgramFilter
8679 @end smallexample
8680
8681 @kindex set frame-filter priority
8682 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8683 Set the @var{priority} of a frame filter in the dictionary matching
8684 @var{filter-dictionary}, and the frame filter name matching
8685 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8686 @code{progspace} or the name of the object file where the frame filter
8687 dictionary resides. The @var{priority} is an integer.
8688
8689 @kindex show frame-filter priority
8690 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8691 Show the @var{priority} of a frame filter in the dictionary matching
8692 @var{filter-dictionary}, and the frame filter name matching
8693 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8694 @code{progspace} or the name of the object file where the frame filter
8695 dictionary resides.
8696
8697 Example:
8698
8699 @smallexample
8700 (gdb) info frame-filter
8701
8702 global frame-filters:
8703 Priority Enabled Name
8704 1000 Yes PrimaryFunctionFilter
8705 100 Yes Reverse
8706
8707 progspace /build/test frame-filters:
8708 Priority Enabled Name
8709 100 Yes ProgspaceFilter
8710
8711 objfile /build/test frame-filters:
8712 Priority Enabled Name
8713 999 No BuildProgramFilter
8714
8715 (gdb) set frame-filter priority global Reverse 50
8716 (gdb) info frame-filter
8717
8718 global frame-filters:
8719 Priority Enabled Name
8720 1000 Yes PrimaryFunctionFilter
8721 50 Yes Reverse
8722
8723 progspace /build/test frame-filters:
8724 Priority Enabled Name
8725 100 Yes ProgspaceFilter
8726
8727 objfile /build/test frame-filters:
8728 Priority Enabled Name
8729 999 No BuildProgramFilter
8730 @end smallexample
8731 @end table
8732
8733 @node Source
8734 @chapter Examining Source Files
8735
8736 @value{GDBN} can print parts of your program's source, since the debugging
8737 information recorded in the program tells @value{GDBN} what source files were
8738 used to build it. When your program stops, @value{GDBN} spontaneously prints
8739 the line where it stopped. Likewise, when you select a stack frame
8740 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8741 execution in that frame has stopped. You can print other portions of
8742 source files by explicit command.
8743
8744 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8745 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8746 @value{GDBN} under @sc{gnu} Emacs}.
8747
8748 @menu
8749 * List:: Printing source lines
8750 * Specify Location:: How to specify code locations
8751 * Edit:: Editing source files
8752 * Search:: Searching source files
8753 * Source Path:: Specifying source directories
8754 * Machine Code:: Source and machine code
8755 @end menu
8756
8757 @node List
8758 @section Printing Source Lines
8759
8760 @kindex list
8761 @kindex l @r{(@code{list})}
8762 To print lines from a source file, use the @code{list} command
8763 (abbreviated @code{l}). By default, ten lines are printed.
8764 There are several ways to specify what part of the file you want to
8765 print; see @ref{Specify Location}, for the full list.
8766
8767 Here are the forms of the @code{list} command most commonly used:
8768
8769 @table @code
8770 @item list @var{linenum}
8771 Print lines centered around line number @var{linenum} in the
8772 current source file.
8773
8774 @item list @var{function}
8775 Print lines centered around the beginning of function
8776 @var{function}.
8777
8778 @item list
8779 Print more lines. If the last lines printed were printed with a
8780 @code{list} command, this prints lines following the last lines
8781 printed; however, if the last line printed was a solitary line printed
8782 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8783 Stack}), this prints lines centered around that line.
8784
8785 @item list -
8786 Print lines just before the lines last printed.
8787 @end table
8788
8789 @cindex @code{list}, how many lines to display
8790 By default, @value{GDBN} prints ten source lines with any of these forms of
8791 the @code{list} command. You can change this using @code{set listsize}:
8792
8793 @table @code
8794 @kindex set listsize
8795 @item set listsize @var{count}
8796 @itemx set listsize unlimited
8797 Make the @code{list} command display @var{count} source lines (unless
8798 the @code{list} argument explicitly specifies some other number).
8799 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8800
8801 @kindex show listsize
8802 @item show listsize
8803 Display the number of lines that @code{list} prints.
8804 @end table
8805
8806 Repeating a @code{list} command with @key{RET} discards the argument,
8807 so it is equivalent to typing just @code{list}. This is more useful
8808 than listing the same lines again. An exception is made for an
8809 argument of @samp{-}; that argument is preserved in repetition so that
8810 each repetition moves up in the source file.
8811
8812 In general, the @code{list} command expects you to supply zero, one or two
8813 @dfn{locations}. Locations specify source lines; there are several ways
8814 of writing them (@pxref{Specify Location}), but the effect is always
8815 to specify some source line.
8816
8817 Here is a complete description of the possible arguments for @code{list}:
8818
8819 @table @code
8820 @item list @var{location}
8821 Print lines centered around the line specified by @var{location}.
8822
8823 @item list @var{first},@var{last}
8824 Print lines from @var{first} to @var{last}. Both arguments are
8825 locations. When a @code{list} command has two locations, and the
8826 source file of the second location is omitted, this refers to
8827 the same source file as the first location.
8828
8829 @item list ,@var{last}
8830 Print lines ending with @var{last}.
8831
8832 @item list @var{first},
8833 Print lines starting with @var{first}.
8834
8835 @item list +
8836 Print lines just after the lines last printed.
8837
8838 @item list -
8839 Print lines just before the lines last printed.
8840
8841 @item list
8842 As described in the preceding table.
8843 @end table
8844
8845 @node Specify Location
8846 @section Specifying a Location
8847 @cindex specifying location
8848 @cindex location
8849 @cindex source location
8850
8851 @menu
8852 * Linespec Locations:: Linespec locations
8853 * Explicit Locations:: Explicit locations
8854 * Address Locations:: Address locations
8855 @end menu
8856
8857 Several @value{GDBN} commands accept arguments that specify a location
8858 of your program's code. Since @value{GDBN} is a source-level
8859 debugger, a location usually specifies some line in the source code.
8860 Locations may be specified using three different formats:
8861 linespec locations, explicit locations, or address locations.
8862
8863 @node Linespec Locations
8864 @subsection Linespec Locations
8865 @cindex linespec locations
8866
8867 A @dfn{linespec} is a colon-separated list of source location parameters such
8868 as file name, function name, etc. Here are all the different ways of
8869 specifying a linespec:
8870
8871 @table @code
8872 @item @var{linenum}
8873 Specifies the line number @var{linenum} of the current source file.
8874
8875 @item -@var{offset}
8876 @itemx +@var{offset}
8877 Specifies the line @var{offset} lines before or after the @dfn{current
8878 line}. For the @code{list} command, the current line is the last one
8879 printed; for the breakpoint commands, this is the line at which
8880 execution stopped in the currently selected @dfn{stack frame}
8881 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
8882 used as the second of the two linespecs in a @code{list} command,
8883 this specifies the line @var{offset} lines up or down from the first
8884 linespec.
8885
8886 @item @var{filename}:@var{linenum}
8887 Specifies the line @var{linenum} in the source file @var{filename}.
8888 If @var{filename} is a relative file name, then it will match any
8889 source file name with the same trailing components. For example, if
8890 @var{filename} is @samp{gcc/expr.c}, then it will match source file
8891 name of @file{/build/trunk/gcc/expr.c}, but not
8892 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
8893
8894 @item @var{function}
8895 Specifies the line that begins the body of the function @var{function}.
8896 For example, in C, this is the line with the open brace.
8897
8898 By default, in C@t{++} and Ada, @var{function} is interpreted as
8899 specifying all functions named @var{function} in all scopes. For
8900 C@t{++}, this means in all namespaces and classes. For Ada, this
8901 means in all packages.
8902
8903 For example, assuming a program with C@t{++} symbols named
8904 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8905 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8906
8907 Commands that accept a linespec let you override this with the
8908 @code{-qualified} option. For example, @w{@kbd{break -qualified
8909 func}} sets a breakpoint on a free-function named @code{func} ignoring
8910 any C@t{++} class methods and namespace functions called @code{func}.
8911
8912 @xref{Explicit Locations}.
8913
8914 @item @var{function}:@var{label}
8915 Specifies the line where @var{label} appears in @var{function}.
8916
8917 @item @var{filename}:@var{function}
8918 Specifies the line that begins the body of the function @var{function}
8919 in the file @var{filename}. You only need the file name with a
8920 function name to avoid ambiguity when there are identically named
8921 functions in different source files.
8922
8923 @item @var{label}
8924 Specifies the line at which the label named @var{label} appears
8925 in the function corresponding to the currently selected stack frame.
8926 If there is no current selected stack frame (for instance, if the inferior
8927 is not running), then @value{GDBN} will not search for a label.
8928
8929 @cindex breakpoint at static probe point
8930 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8931 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8932 applications to embed static probes. @xref{Static Probe Points}, for more
8933 information on finding and using static probes. This form of linespec
8934 specifies the location of such a static probe.
8935
8936 If @var{objfile} is given, only probes coming from that shared library
8937 or executable matching @var{objfile} as a regular expression are considered.
8938 If @var{provider} is given, then only probes from that provider are considered.
8939 If several probes match the spec, @value{GDBN} will insert a breakpoint at
8940 each one of those probes.
8941 @end table
8942
8943 @node Explicit Locations
8944 @subsection Explicit Locations
8945 @cindex explicit locations
8946
8947 @dfn{Explicit locations} allow the user to directly specify the source
8948 location's parameters using option-value pairs.
8949
8950 Explicit locations are useful when several functions, labels, or
8951 file names have the same name (base name for files) in the program's
8952 sources. In these cases, explicit locations point to the source
8953 line you meant more accurately and unambiguously. Also, using
8954 explicit locations might be faster in large programs.
8955
8956 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8957 defined in the file named @file{foo} or the label @code{bar} in a function
8958 named @code{foo}. @value{GDBN} must search either the file system or
8959 the symbol table to know.
8960
8961 The list of valid explicit location options is summarized in the
8962 following table:
8963
8964 @table @code
8965 @item -source @var{filename}
8966 The value specifies the source file name. To differentiate between
8967 files with the same base name, prepend as many directories as is necessary
8968 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8969 @value{GDBN} will use the first file it finds with the given base
8970 name. This option requires the use of either @code{-function} or @code{-line}.
8971
8972 @item -function @var{function}
8973 The value specifies the name of a function. Operations
8974 on function locations unmodified by other options (such as @code{-label}
8975 or @code{-line}) refer to the line that begins the body of the function.
8976 In C, for example, this is the line with the open brace.
8977
8978 By default, in C@t{++} and Ada, @var{function} is interpreted as
8979 specifying all functions named @var{function} in all scopes. For
8980 C@t{++}, this means in all namespaces and classes. For Ada, this
8981 means in all packages.
8982
8983 For example, assuming a program with C@t{++} symbols named
8984 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8985 -function func}} and @w{@kbd{break -function B::func}} set a
8986 breakpoint on both symbols.
8987
8988 You can use the @kbd{-qualified} flag to override this (see below).
8989
8990 @item -qualified
8991
8992 This flag makes @value{GDBN} interpret a function name specified with
8993 @kbd{-function} as a complete fully-qualified name.
8994
8995 For example, assuming a C@t{++} program with symbols named
8996 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8997 -function B::func}} command sets a breakpoint on @code{B::func}, only.
8998
8999 (Note: the @kbd{-qualified} option can precede a linespec as well
9000 (@pxref{Linespec Locations}), so the particular example above could be
9001 simplified as @w{@kbd{break -qualified B::func}}.)
9002
9003 @item -label @var{label}
9004 The value specifies the name of a label. When the function
9005 name is not specified, the label is searched in the function of the currently
9006 selected stack frame.
9007
9008 @item -line @var{number}
9009 The value specifies a line offset for the location. The offset may either
9010 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9011 the command. When specified without any other options, the line offset is
9012 relative to the current line.
9013 @end table
9014
9015 Explicit location options may be abbreviated by omitting any non-unique
9016 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9017
9018 @node Address Locations
9019 @subsection Address Locations
9020 @cindex address locations
9021
9022 @dfn{Address locations} indicate a specific program address. They have
9023 the generalized form *@var{address}.
9024
9025 For line-oriented commands, such as @code{list} and @code{edit}, this
9026 specifies a source line that contains @var{address}. For @code{break} and
9027 other breakpoint-oriented commands, this can be used to set breakpoints in
9028 parts of your program which do not have debugging information or
9029 source files.
9030
9031 Here @var{address} may be any expression valid in the current working
9032 language (@pxref{Languages, working language}) that specifies a code
9033 address. In addition, as a convenience, @value{GDBN} extends the
9034 semantics of expressions used in locations to cover several situations
9035 that frequently occur during debugging. Here are the various forms
9036 of @var{address}:
9037
9038 @table @code
9039 @item @var{expression}
9040 Any expression valid in the current working language.
9041
9042 @item @var{funcaddr}
9043 An address of a function or procedure derived from its name. In C,
9044 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9045 simply the function's name @var{function} (and actually a special case
9046 of a valid expression). In Pascal and Modula-2, this is
9047 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9048 (although the Pascal form also works).
9049
9050 This form specifies the address of the function's first instruction,
9051 before the stack frame and arguments have been set up.
9052
9053 @item '@var{filename}':@var{funcaddr}
9054 Like @var{funcaddr} above, but also specifies the name of the source
9055 file explicitly. This is useful if the name of the function does not
9056 specify the function unambiguously, e.g., if there are several
9057 functions with identical names in different source files.
9058 @end table
9059
9060 @node Edit
9061 @section Editing Source Files
9062 @cindex editing source files
9063
9064 @kindex edit
9065 @kindex e @r{(@code{edit})}
9066 To edit the lines in a source file, use the @code{edit} command.
9067 The editing program of your choice
9068 is invoked with the current line set to
9069 the active line in the program.
9070 Alternatively, there are several ways to specify what part of the file you
9071 want to print if you want to see other parts of the program:
9072
9073 @table @code
9074 @item edit @var{location}
9075 Edit the source file specified by @code{location}. Editing starts at
9076 that @var{location}, e.g., at the specified source line of the
9077 specified file. @xref{Specify Location}, for all the possible forms
9078 of the @var{location} argument; here are the forms of the @code{edit}
9079 command most commonly used:
9080
9081 @table @code
9082 @item edit @var{number}
9083 Edit the current source file with @var{number} as the active line number.
9084
9085 @item edit @var{function}
9086 Edit the file containing @var{function} at the beginning of its definition.
9087 @end table
9088
9089 @end table
9090
9091 @subsection Choosing your Editor
9092 You can customize @value{GDBN} to use any editor you want
9093 @footnote{
9094 The only restriction is that your editor (say @code{ex}), recognizes the
9095 following command-line syntax:
9096 @smallexample
9097 ex +@var{number} file
9098 @end smallexample
9099 The optional numeric value +@var{number} specifies the number of the line in
9100 the file where to start editing.}.
9101 By default, it is @file{@value{EDITOR}}, but you can change this
9102 by setting the environment variable @code{EDITOR} before using
9103 @value{GDBN}. For example, to configure @value{GDBN} to use the
9104 @code{vi} editor, you could use these commands with the @code{sh} shell:
9105 @smallexample
9106 EDITOR=/usr/bin/vi
9107 export EDITOR
9108 gdb @dots{}
9109 @end smallexample
9110 or in the @code{csh} shell,
9111 @smallexample
9112 setenv EDITOR /usr/bin/vi
9113 gdb @dots{}
9114 @end smallexample
9115
9116 @node Search
9117 @section Searching Source Files
9118 @cindex searching source files
9119
9120 There are two commands for searching through the current source file for a
9121 regular expression.
9122
9123 @table @code
9124 @kindex search
9125 @kindex forward-search
9126 @kindex fo @r{(@code{forward-search})}
9127 @item forward-search @var{regexp}
9128 @itemx search @var{regexp}
9129 The command @samp{forward-search @var{regexp}} checks each line,
9130 starting with the one following the last line listed, for a match for
9131 @var{regexp}. It lists the line that is found. You can use the
9132 synonym @samp{search @var{regexp}} or abbreviate the command name as
9133 @code{fo}.
9134
9135 @kindex reverse-search
9136 @item reverse-search @var{regexp}
9137 The command @samp{reverse-search @var{regexp}} checks each line, starting
9138 with the one before the last line listed and going backward, for a match
9139 for @var{regexp}. It lists the line that is found. You can abbreviate
9140 this command as @code{rev}.
9141 @end table
9142
9143 @node Source Path
9144 @section Specifying Source Directories
9145
9146 @cindex source path
9147 @cindex directories for source files
9148 Executable programs sometimes do not record the directories of the source
9149 files from which they were compiled, just the names. Even when they do,
9150 the directories could be moved between the compilation and your debugging
9151 session. @value{GDBN} has a list of directories to search for source files;
9152 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9153 it tries all the directories in the list, in the order they are present
9154 in the list, until it finds a file with the desired name.
9155
9156 For example, suppose an executable references the file
9157 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9158 directory, and the @dfn{source path} is @file{/mnt/cross}.
9159 @value{GDBN} would look for the source file in the following
9160 locations:
9161
9162 @enumerate
9163
9164 @item @file{/usr/src/foo-1.0/lib/foo.c}
9165 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9166 @item @file{/mnt/cross/foo.c}
9167
9168 @end enumerate
9169
9170 If the source file is not present at any of the above locations then
9171 an error is printed. @value{GDBN} does not look up the parts of the
9172 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9173 Likewise, the subdirectories of the source path are not searched: if
9174 the source path is @file{/mnt/cross}, and the binary refers to
9175 @file{foo.c}, @value{GDBN} would not find it under
9176 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9177
9178 Plain file names, relative file names with leading directories, file
9179 names containing dots, etc.@: are all treated as described above,
9180 except that non-absolute file names are not looked up literally. If
9181 the @dfn{source path} is @file{/mnt/cross}, the source file is
9182 recorded as @file{../lib/foo.c}, and no compilation directory is
9183 recorded, then @value{GDBN} will search in the following locations:
9184
9185 @enumerate
9186
9187 @item @file{/mnt/cross/../lib/foo.c}
9188 @item @file{/mnt/cross/foo.c}
9189
9190 @end enumerate
9191
9192 @kindex cdir
9193 @kindex cwd
9194 @vindex $cdir@r{, convenience variable}
9195 @vindex $cwd@r{, convenience variable}
9196 @cindex compilation directory
9197 @cindex current directory
9198 @cindex working directory
9199 @cindex directory, current
9200 @cindex directory, compilation
9201 The @dfn{source path} will always include two special entries
9202 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9203 (if one is recorded) and the current working directory respectively.
9204
9205 @samp{$cdir} causes @value{GDBN} to search within the compilation
9206 directory, if one is recorded in the debug information. If no
9207 compilation directory is recorded in the debug information then
9208 @samp{$cdir} is ignored.
9209
9210 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9211 current working directory as it changes during your @value{GDBN}
9212 session, while the latter is immediately expanded to the current
9213 directory at the time you add an entry to the source path.
9214
9215 If a compilation directory is recorded in the debug information, and
9216 @value{GDBN} has not found the source file after the first search
9217 using @dfn{source path}, then @value{GDBN} will combine the
9218 compilation directory and the filename, and then search for the source
9219 file again using the @dfn{source path}.
9220
9221 For example, if the executable records the source file as
9222 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9223 recorded as @file{/project/build}, and the @dfn{source path} is
9224 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9225 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9226 search for the source file in the following locations:
9227
9228 @enumerate
9229
9230 @item @file{/usr/src/foo-1.0/lib/foo.c}
9231 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9232 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9233 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9234 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9235 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9236 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9237 @item @file{/mnt/cross/foo.c}
9238 @item @file{/project/build/foo.c}
9239 @item @file{/home/user/foo.c}
9240
9241 @end enumerate
9242
9243 If the file name in the previous example had been recorded in the
9244 executable as a relative path rather than an absolute path, then the
9245 first look up would not have occurred, but all of the remaining steps
9246 would be similar.
9247
9248 When searching for source files on MS-DOS and MS-Windows, where
9249 absolute paths start with a drive letter (e.g.
9250 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9251 from the file name before appending it to a search directory from
9252 @dfn{source path}; for instance if the executable references the
9253 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9254 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9255 locations for the source file:
9256
9257 @enumerate
9258
9259 @item @file{C:/project/foo.c}
9260 @item @file{D:/mnt/cross/project/foo.c}
9261 @item @file{D:/mnt/cross/foo.c}
9262
9263 @end enumerate
9264
9265 Note that the executable search path is @emph{not} used to locate the
9266 source files.
9267
9268 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9269 any information it has cached about where source files are found and where
9270 each line is in the file.
9271
9272 @kindex directory
9273 @kindex dir
9274 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9275 and @samp{$cwd}, in that order.
9276 To add other directories, use the @code{directory} command.
9277
9278 The search path is used to find both program source files and @value{GDBN}
9279 script files (read using the @samp{-command} option and @samp{source} command).
9280
9281 In addition to the source path, @value{GDBN} provides a set of commands
9282 that manage a list of source path substitution rules. A @dfn{substitution
9283 rule} specifies how to rewrite source directories stored in the program's
9284 debug information in case the sources were moved to a different
9285 directory between compilation and debugging. A rule is made of
9286 two strings, the first specifying what needs to be rewritten in
9287 the path, and the second specifying how it should be rewritten.
9288 In @ref{set substitute-path}, we name these two parts @var{from} and
9289 @var{to} respectively. @value{GDBN} does a simple string replacement
9290 of @var{from} with @var{to} at the start of the directory part of the
9291 source file name, and uses that result instead of the original file
9292 name to look up the sources.
9293
9294 Using the previous example, suppose the @file{foo-1.0} tree has been
9295 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9296 @value{GDBN} to replace @file{/usr/src} in all source path names with
9297 @file{/mnt/cross}. The first lookup will then be
9298 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9299 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9300 substitution rule, use the @code{set substitute-path} command
9301 (@pxref{set substitute-path}).
9302
9303 To avoid unexpected substitution results, a rule is applied only if the
9304 @var{from} part of the directory name ends at a directory separator.
9305 For instance, a rule substituting @file{/usr/source} into
9306 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9307 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9308 is applied only at the beginning of the directory name, this rule will
9309 not be applied to @file{/root/usr/source/baz.c} either.
9310
9311 In many cases, you can achieve the same result using the @code{directory}
9312 command. However, @code{set substitute-path} can be more efficient in
9313 the case where the sources are organized in a complex tree with multiple
9314 subdirectories. With the @code{directory} command, you need to add each
9315 subdirectory of your project. If you moved the entire tree while
9316 preserving its internal organization, then @code{set substitute-path}
9317 allows you to direct the debugger to all the sources with one single
9318 command.
9319
9320 @code{set substitute-path} is also more than just a shortcut command.
9321 The source path is only used if the file at the original location no
9322 longer exists. On the other hand, @code{set substitute-path} modifies
9323 the debugger behavior to look at the rewritten location instead. So, if
9324 for any reason a source file that is not relevant to your executable is
9325 located at the original location, a substitution rule is the only
9326 method available to point @value{GDBN} at the new location.
9327
9328 @cindex @samp{--with-relocated-sources}
9329 @cindex default source path substitution
9330 You can configure a default source path substitution rule by
9331 configuring @value{GDBN} with the
9332 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9333 should be the name of a directory under @value{GDBN}'s configured
9334 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9335 directory names in debug information under @var{dir} will be adjusted
9336 automatically if the installed @value{GDBN} is moved to a new
9337 location. This is useful if @value{GDBN}, libraries or executables
9338 with debug information and corresponding source code are being moved
9339 together.
9340
9341 @table @code
9342 @item directory @var{dirname} @dots{}
9343 @item dir @var{dirname} @dots{}
9344 Add directory @var{dirname} to the front of the source path. Several
9345 directory names may be given to this command, separated by @samp{:}
9346 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9347 part of absolute file names) or
9348 whitespace. You may specify a directory that is already in the source
9349 path; this moves it forward, so @value{GDBN} searches it sooner.
9350
9351 The special strings @samp{$cdir} (to refer to the compilation
9352 directory, if one is recorded), and @samp{$cwd} (to refer to the
9353 current working directory) can also be included in the list of
9354 directories @var{dirname}. Though these will already be in the source
9355 path they will be moved forward in the list so @value{GDBN} searches
9356 them sooner.
9357
9358 @item directory
9359 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9360
9361 @c RET-repeat for @code{directory} is explicitly disabled, but since
9362 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9363
9364 @item set directories @var{path-list}
9365 @kindex set directories
9366 Set the source path to @var{path-list}.
9367 @samp{$cdir:$cwd} are added if missing.
9368
9369 @item show directories
9370 @kindex show directories
9371 Print the source path: show which directories it contains.
9372
9373 @anchor{set substitute-path}
9374 @item set substitute-path @var{from} @var{to}
9375 @kindex set substitute-path
9376 Define a source path substitution rule, and add it at the end of the
9377 current list of existing substitution rules. If a rule with the same
9378 @var{from} was already defined, then the old rule is also deleted.
9379
9380 For example, if the file @file{/foo/bar/baz.c} was moved to
9381 @file{/mnt/cross/baz.c}, then the command
9382
9383 @smallexample
9384 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9385 @end smallexample
9386
9387 @noindent
9388 will tell @value{GDBN} to replace @samp{/foo/bar} with
9389 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9390 @file{baz.c} even though it was moved.
9391
9392 In the case when more than one substitution rule have been defined,
9393 the rules are evaluated one by one in the order where they have been
9394 defined. The first one matching, if any, is selected to perform
9395 the substitution.
9396
9397 For instance, if we had entered the following commands:
9398
9399 @smallexample
9400 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9401 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9402 @end smallexample
9403
9404 @noindent
9405 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9406 @file{/mnt/include/defs.h} by using the first rule. However, it would
9407 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9408 @file{/mnt/src/lib/foo.c}.
9409
9410
9411 @item unset substitute-path [path]
9412 @kindex unset substitute-path
9413 If a path is specified, search the current list of substitution rules
9414 for a rule that would rewrite that path. Delete that rule if found.
9415 A warning is emitted by the debugger if no rule could be found.
9416
9417 If no path is specified, then all substitution rules are deleted.
9418
9419 @item show substitute-path [path]
9420 @kindex show substitute-path
9421 If a path is specified, then print the source path substitution rule
9422 which would rewrite that path, if any.
9423
9424 If no path is specified, then print all existing source path substitution
9425 rules.
9426
9427 @end table
9428
9429 If your source path is cluttered with directories that are no longer of
9430 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9431 versions of source. You can correct the situation as follows:
9432
9433 @enumerate
9434 @item
9435 Use @code{directory} with no argument to reset the source path to its default value.
9436
9437 @item
9438 Use @code{directory} with suitable arguments to reinstall the
9439 directories you want in the source path. You can add all the
9440 directories in one command.
9441 @end enumerate
9442
9443 @node Machine Code
9444 @section Source and Machine Code
9445 @cindex source line and its code address
9446
9447 You can use the command @code{info line} to map source lines to program
9448 addresses (and vice versa), and the command @code{disassemble} to display
9449 a range of addresses as machine instructions. You can use the command
9450 @code{set disassemble-next-line} to set whether to disassemble next
9451 source line when execution stops. When run under @sc{gnu} Emacs
9452 mode, the @code{info line} command causes the arrow to point to the
9453 line specified. Also, @code{info line} prints addresses in symbolic form as
9454 well as hex.
9455
9456 @table @code
9457 @kindex info line
9458 @item info line
9459 @itemx info line @var{location}
9460 Print the starting and ending addresses of the compiled code for
9461 source line @var{location}. You can specify source lines in any of
9462 the ways documented in @ref{Specify Location}. With no @var{location}
9463 information about the current source line is printed.
9464 @end table
9465
9466 For example, we can use @code{info line} to discover the location of
9467 the object code for the first line of function
9468 @code{m4_changequote}:
9469
9470 @smallexample
9471 (@value{GDBP}) info line m4_changequote
9472 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9473 ends at 0x6350 <m4_changequote+4>.
9474 @end smallexample
9475
9476 @noindent
9477 @cindex code address and its source line
9478 We can also inquire (using @code{*@var{addr}} as the form for
9479 @var{location}) what source line covers a particular address:
9480 @smallexample
9481 (@value{GDBP}) info line *0x63ff
9482 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9483 ends at 0x6404 <m4_changequote+184>.
9484 @end smallexample
9485
9486 @cindex @code{$_} and @code{info line}
9487 @cindex @code{x} command, default address
9488 @kindex x@r{(examine), and} info line
9489 After @code{info line}, the default address for the @code{x} command
9490 is changed to the starting address of the line, so that @samp{x/i} is
9491 sufficient to begin examining the machine code (@pxref{Memory,
9492 ,Examining Memory}). Also, this address is saved as the value of the
9493 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9494 Variables}).
9495
9496 @cindex info line, repeated calls
9497 After @code{info line}, using @code{info line} again without
9498 specifying a location will display information about the next source
9499 line.
9500
9501 @table @code
9502 @kindex disassemble
9503 @cindex assembly instructions
9504 @cindex instructions, assembly
9505 @cindex machine instructions
9506 @cindex listing machine instructions
9507 @item disassemble
9508 @itemx disassemble /m
9509 @itemx disassemble /s
9510 @itemx disassemble /r
9511 This specialized command dumps a range of memory as machine
9512 instructions. It can also print mixed source+disassembly by specifying
9513 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9514 as well as in symbolic form by specifying the @code{/r} modifier.
9515 The default memory range is the function surrounding the
9516 program counter of the selected frame. A single argument to this
9517 command is a program counter value; @value{GDBN} dumps the function
9518 surrounding this value. When two arguments are given, they should
9519 be separated by a comma, possibly surrounded by whitespace. The
9520 arguments specify a range of addresses to dump, in one of two forms:
9521
9522 @table @code
9523 @item @var{start},@var{end}
9524 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9525 @item @var{start},+@var{length}
9526 the addresses from @var{start} (inclusive) to
9527 @code{@var{start}+@var{length}} (exclusive).
9528 @end table
9529
9530 @noindent
9531 When 2 arguments are specified, the name of the function is also
9532 printed (since there could be several functions in the given range).
9533
9534 The argument(s) can be any expression yielding a numeric value, such as
9535 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9536
9537 If the range of memory being disassembled contains current program counter,
9538 the instruction at that location is shown with a @code{=>} marker.
9539 @end table
9540
9541 The following example shows the disassembly of a range of addresses of
9542 HP PA-RISC 2.0 code:
9543
9544 @smallexample
9545 (@value{GDBP}) disas 0x32c4, 0x32e4
9546 Dump of assembler code from 0x32c4 to 0x32e4:
9547 0x32c4 <main+204>: addil 0,dp
9548 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9549 0x32cc <main+212>: ldil 0x3000,r31
9550 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9551 0x32d4 <main+220>: ldo 0(r31),rp
9552 0x32d8 <main+224>: addil -0x800,dp
9553 0x32dc <main+228>: ldo 0x588(r1),r26
9554 0x32e0 <main+232>: ldil 0x3000,r31
9555 End of assembler dump.
9556 @end smallexample
9557
9558 Here is an example showing mixed source+assembly for Intel x86
9559 with @code{/m} or @code{/s}, when the program is stopped just after
9560 function prologue in a non-optimized function with no inline code.
9561
9562 @smallexample
9563 (@value{GDBP}) disas /m main
9564 Dump of assembler code for function main:
9565 5 @{
9566 0x08048330 <+0>: push %ebp
9567 0x08048331 <+1>: mov %esp,%ebp
9568 0x08048333 <+3>: sub $0x8,%esp
9569 0x08048336 <+6>: and $0xfffffff0,%esp
9570 0x08048339 <+9>: sub $0x10,%esp
9571
9572 6 printf ("Hello.\n");
9573 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9574 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9575
9576 7 return 0;
9577 8 @}
9578 0x08048348 <+24>: mov $0x0,%eax
9579 0x0804834d <+29>: leave
9580 0x0804834e <+30>: ret
9581
9582 End of assembler dump.
9583 @end smallexample
9584
9585 The @code{/m} option is deprecated as its output is not useful when
9586 there is either inlined code or re-ordered code.
9587 The @code{/s} option is the preferred choice.
9588 Here is an example for AMD x86-64 showing the difference between
9589 @code{/m} output and @code{/s} output.
9590 This example has one inline function defined in a header file,
9591 and the code is compiled with @samp{-O2} optimization.
9592 Note how the @code{/m} output is missing the disassembly of
9593 several instructions that are present in the @code{/s} output.
9594
9595 @file{foo.h}:
9596
9597 @smallexample
9598 int
9599 foo (int a)
9600 @{
9601 if (a < 0)
9602 return a * 2;
9603 if (a == 0)
9604 return 1;
9605 return a + 10;
9606 @}
9607 @end smallexample
9608
9609 @file{foo.c}:
9610
9611 @smallexample
9612 #include "foo.h"
9613 volatile int x, y;
9614 int
9615 main ()
9616 @{
9617 x = foo (y);
9618 return 0;
9619 @}
9620 @end smallexample
9621
9622 @smallexample
9623 (@value{GDBP}) disas /m main
9624 Dump of assembler code for function main:
9625 5 @{
9626
9627 6 x = foo (y);
9628 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9629 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9630
9631 7 return 0;
9632 8 @}
9633 0x000000000040041d <+29>: xor %eax,%eax
9634 0x000000000040041f <+31>: retq
9635 0x0000000000400420 <+32>: add %eax,%eax
9636 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9637
9638 End of assembler dump.
9639 (@value{GDBP}) disas /s main
9640 Dump of assembler code for function main:
9641 foo.c:
9642 5 @{
9643 6 x = foo (y);
9644 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9645
9646 foo.h:
9647 4 if (a < 0)
9648 0x0000000000400406 <+6>: test %eax,%eax
9649 0x0000000000400408 <+8>: js 0x400420 <main+32>
9650
9651 6 if (a == 0)
9652 7 return 1;
9653 8 return a + 10;
9654 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9655 0x000000000040040d <+13>: test %eax,%eax
9656 0x000000000040040f <+15>: mov $0x1,%eax
9657 0x0000000000400414 <+20>: cmovne %edx,%eax
9658
9659 foo.c:
9660 6 x = foo (y);
9661 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9662
9663 7 return 0;
9664 8 @}
9665 0x000000000040041d <+29>: xor %eax,%eax
9666 0x000000000040041f <+31>: retq
9667
9668 foo.h:
9669 5 return a * 2;
9670 0x0000000000400420 <+32>: add %eax,%eax
9671 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9672 End of assembler dump.
9673 @end smallexample
9674
9675 Here is another example showing raw instructions in hex for AMD x86-64,
9676
9677 @smallexample
9678 (gdb) disas /r 0x400281,+10
9679 Dump of assembler code from 0x400281 to 0x40028b:
9680 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9681 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9682 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9683 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9684 End of assembler dump.
9685 @end smallexample
9686
9687 Addresses cannot be specified as a location (@pxref{Specify Location}).
9688 So, for example, if you want to disassemble function @code{bar}
9689 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9690 and not @samp{disassemble foo.c:bar}.
9691
9692 Some architectures have more than one commonly-used set of instruction
9693 mnemonics or other syntax.
9694
9695 For programs that were dynamically linked and use shared libraries,
9696 instructions that call functions or branch to locations in the shared
9697 libraries might show a seemingly bogus location---it's actually a
9698 location of the relocation table. On some architectures, @value{GDBN}
9699 might be able to resolve these to actual function names.
9700
9701 @table @code
9702 @kindex set disassembler-options
9703 @cindex disassembler options
9704 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9705 This command controls the passing of target specific information to
9706 the disassembler. For a list of valid options, please refer to the
9707 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9708 manual and/or the output of @kbd{objdump --help}
9709 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9710 The default value is the empty string.
9711
9712 If it is necessary to specify more than one disassembler option, then
9713 multiple options can be placed together into a comma separated list.
9714 Currently this command is only supported on targets ARM, MIPS, PowerPC
9715 and S/390.
9716
9717 @kindex show disassembler-options
9718 @item show disassembler-options
9719 Show the current setting of the disassembler options.
9720 @end table
9721
9722 @table @code
9723 @kindex set disassembly-flavor
9724 @cindex Intel disassembly flavor
9725 @cindex AT&T disassembly flavor
9726 @item set disassembly-flavor @var{instruction-set}
9727 Select the instruction set to use when disassembling the
9728 program via the @code{disassemble} or @code{x/i} commands.
9729
9730 Currently this command is only defined for the Intel x86 family. You
9731 can set @var{instruction-set} to either @code{intel} or @code{att}.
9732 The default is @code{att}, the AT&T flavor used by default by Unix
9733 assemblers for x86-based targets.
9734
9735 @kindex show disassembly-flavor
9736 @item show disassembly-flavor
9737 Show the current setting of the disassembly flavor.
9738 @end table
9739
9740 @table @code
9741 @kindex set disassemble-next-line
9742 @kindex show disassemble-next-line
9743 @item set disassemble-next-line
9744 @itemx show disassemble-next-line
9745 Control whether or not @value{GDBN} will disassemble the next source
9746 line or instruction when execution stops. If ON, @value{GDBN} will
9747 display disassembly of the next source line when execution of the
9748 program being debugged stops. This is @emph{in addition} to
9749 displaying the source line itself, which @value{GDBN} always does if
9750 possible. If the next source line cannot be displayed for some reason
9751 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9752 info in the debug info), @value{GDBN} will display disassembly of the
9753 next @emph{instruction} instead of showing the next source line. If
9754 AUTO, @value{GDBN} will display disassembly of next instruction only
9755 if the source line cannot be displayed. This setting causes
9756 @value{GDBN} to display some feedback when you step through a function
9757 with no line info or whose source file is unavailable. The default is
9758 OFF, which means never display the disassembly of the next line or
9759 instruction.
9760 @end table
9761
9762
9763 @node Data
9764 @chapter Examining Data
9765
9766 @cindex printing data
9767 @cindex examining data
9768 @kindex print
9769 @kindex inspect
9770 The usual way to examine data in your program is with the @code{print}
9771 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9772 evaluates and prints the value of an expression of the language your
9773 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9774 Different Languages}). It may also print the expression using a
9775 Python-based pretty-printer (@pxref{Pretty Printing}).
9776
9777 @table @code
9778 @item print [[@var{options}] --] @var{expr}
9779 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9780 @var{expr} is an expression (in the source language). By default the
9781 value of @var{expr} is printed in a format appropriate to its data type;
9782 you can choose a different format by specifying @samp{/@var{f}}, where
9783 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9784 Formats}.
9785
9786 @anchor{print options}
9787 The @code{print} command supports a number of options that allow
9788 overriding relevant global print settings as set by @code{set print}
9789 subcommands:
9790
9791 @table @code
9792 @item -address [@code{on}|@code{off}]
9793 Set printing of addresses.
9794 Related setting: @ref{set print address}.
9795
9796 @item -array [@code{on}|@code{off}]
9797 Pretty formatting of arrays.
9798 Related setting: @ref{set print array}.
9799
9800 @item -array-indexes [@code{on}|@code{off}]
9801 Set printing of array indexes.
9802 Related setting: @ref{set print array-indexes}.
9803
9804 @item -elements @var{number-of-elements}|@code{unlimited}
9805 Set limit on string chars or array elements to print. The value
9806 @code{unlimited} causes there to be no limit. Related setting:
9807 @ref{set print elements}.
9808
9809 @item -max-depth @var{depth}|@code{unlimited}
9810 Set the threshold after which nested structures are replaced with
9811 ellipsis. Related setting: @ref{set print max-depth}.
9812
9813 @item -null-stop [@code{on}|@code{off}]
9814 Set printing of char arrays to stop at first null char. Related
9815 setting: @ref{set print null-stop}.
9816
9817 @item -object [@code{on}|@code{off}]
9818 Set printing C@t{++} virtual function tables. Related setting:
9819 @ref{set print object}.
9820
9821 @item -pretty [@code{on}|@code{off}]
9822 Set pretty formatting of structures. Related setting: @ref{set print
9823 pretty}.
9824
9825 @item -raw-values [@code{on}|@code{off}]
9826 Set whether to print values in raw form, bypassing any
9827 pretty-printers for that value. Related setting: @ref{set print
9828 raw-values}.
9829
9830 @item -repeats @var{number-of-repeats}|@code{unlimited}
9831 Set threshold for repeated print elements. @code{unlimited} causes
9832 all elements to be individually printed. Related setting: @ref{set
9833 print repeats}.
9834
9835 @item -static-members [@code{on}|@code{off}]
9836 Set printing C@t{++} static members. Related setting: @ref{set print
9837 static-members}.
9838
9839 @item -symbol [@code{on}|@code{off}]
9840 Set printing of symbol names when printing pointers. Related setting:
9841 @ref{set print symbol}.
9842
9843 @item -union [@code{on}|@code{off}]
9844 Set printing of unions interior to structures. Related setting:
9845 @ref{set print union}.
9846
9847 @item -vtbl [@code{on}|@code{off}]
9848 Set printing of C++ virtual function tables. Related setting:
9849 @ref{set print vtbl}.
9850 @end table
9851
9852 Because the @code{print} command accepts arbitrary expressions which
9853 may look like options (including abbreviations), if you specify any
9854 command option, then you must use a double dash (@code{--}) to mark
9855 the end of option processing.
9856
9857 For example, this prints the value of the @code{-p} expression:
9858
9859 @smallexample
9860 (@value{GDBP}) print -p
9861 @end smallexample
9862
9863 While this repeats the last value in the value history (see below)
9864 with the @code{-pretty} option in effect:
9865
9866 @smallexample
9867 (@value{GDBP}) print -p --
9868 @end smallexample
9869
9870 Here is an example including both on option and an expression:
9871
9872 @smallexample
9873 @group
9874 (@value{GDBP}) print -pretty -- *myptr
9875 $1 = @{
9876 next = 0x0,
9877 flags = @{
9878 sweet = 1,
9879 sour = 1
9880 @},
9881 meat = 0x54 "Pork"
9882 @}
9883 @end group
9884 @end smallexample
9885
9886 @item print [@var{options}]
9887 @itemx print [@var{options}] /@var{f}
9888 @cindex reprint the last value
9889 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
9890 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
9891 conveniently inspect the same value in an alternative format.
9892 @end table
9893
9894 A more low-level way of examining data is with the @code{x} command.
9895 It examines data in memory at a specified address and prints it in a
9896 specified format. @xref{Memory, ,Examining Memory}.
9897
9898 If you are interested in information about types, or about how the
9899 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9900 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
9901 Table}.
9902
9903 @cindex exploring hierarchical data structures
9904 @kindex explore
9905 Another way of examining values of expressions and type information is
9906 through the Python extension command @code{explore} (available only if
9907 the @value{GDBN} build is configured with @code{--with-python}). It
9908 offers an interactive way to start at the highest level (or, the most
9909 abstract level) of the data type of an expression (or, the data type
9910 itself) and explore all the way down to leaf scalar values/fields
9911 embedded in the higher level data types.
9912
9913 @table @code
9914 @item explore @var{arg}
9915 @var{arg} is either an expression (in the source language), or a type
9916 visible in the current context of the program being debugged.
9917 @end table
9918
9919 The working of the @code{explore} command can be illustrated with an
9920 example. If a data type @code{struct ComplexStruct} is defined in your
9921 C program as
9922
9923 @smallexample
9924 struct SimpleStruct
9925 @{
9926 int i;
9927 double d;
9928 @};
9929
9930 struct ComplexStruct
9931 @{
9932 struct SimpleStruct *ss_p;
9933 int arr[10];
9934 @};
9935 @end smallexample
9936
9937 @noindent
9938 followed by variable declarations as
9939
9940 @smallexample
9941 struct SimpleStruct ss = @{ 10, 1.11 @};
9942 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9943 @end smallexample
9944
9945 @noindent
9946 then, the value of the variable @code{cs} can be explored using the
9947 @code{explore} command as follows.
9948
9949 @smallexample
9950 (gdb) explore cs
9951 The value of `cs' is a struct/class of type `struct ComplexStruct' with
9952 the following fields:
9953
9954 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9955 arr = <Enter 1 to explore this field of type `int [10]'>
9956
9957 Enter the field number of choice:
9958 @end smallexample
9959
9960 @noindent
9961 Since the fields of @code{cs} are not scalar values, you are being
9962 prompted to chose the field you want to explore. Let's say you choose
9963 the field @code{ss_p} by entering @code{0}. Then, since this field is a
9964 pointer, you will be asked if it is pointing to a single value. From
9965 the declaration of @code{cs} above, it is indeed pointing to a single
9966 value, hence you enter @code{y}. If you enter @code{n}, then you will
9967 be asked if it were pointing to an array of values, in which case this
9968 field will be explored as if it were an array.
9969
9970 @smallexample
9971 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9972 Continue exploring it as a pointer to a single value [y/n]: y
9973 The value of `*(cs.ss_p)' is a struct/class of type `struct
9974 SimpleStruct' with the following fields:
9975
9976 i = 10 .. (Value of type `int')
9977 d = 1.1100000000000001 .. (Value of type `double')
9978
9979 Press enter to return to parent value:
9980 @end smallexample
9981
9982 @noindent
9983 If the field @code{arr} of @code{cs} was chosen for exploration by
9984 entering @code{1} earlier, then since it is as array, you will be
9985 prompted to enter the index of the element in the array that you want
9986 to explore.
9987
9988 @smallexample
9989 `cs.arr' is an array of `int'.
9990 Enter the index of the element you want to explore in `cs.arr': 5
9991
9992 `(cs.arr)[5]' is a scalar value of type `int'.
9993
9994 (cs.arr)[5] = 4
9995
9996 Press enter to return to parent value:
9997 @end smallexample
9998
9999 In general, at any stage of exploration, you can go deeper towards the
10000 leaf values by responding to the prompts appropriately, or hit the
10001 return key to return to the enclosing data structure (the @i{higher}
10002 level data structure).
10003
10004 Similar to exploring values, you can use the @code{explore} command to
10005 explore types. Instead of specifying a value (which is typically a
10006 variable name or an expression valid in the current context of the
10007 program being debugged), you specify a type name. If you consider the
10008 same example as above, your can explore the type
10009 @code{struct ComplexStruct} by passing the argument
10010 @code{struct ComplexStruct} to the @code{explore} command.
10011
10012 @smallexample
10013 (gdb) explore struct ComplexStruct
10014 @end smallexample
10015
10016 @noindent
10017 By responding to the prompts appropriately in the subsequent interactive
10018 session, you can explore the type @code{struct ComplexStruct} in a
10019 manner similar to how the value @code{cs} was explored in the above
10020 example.
10021
10022 The @code{explore} command also has two sub-commands,
10023 @code{explore value} and @code{explore type}. The former sub-command is
10024 a way to explicitly specify that value exploration of the argument is
10025 being invoked, while the latter is a way to explicitly specify that type
10026 exploration of the argument is being invoked.
10027
10028 @table @code
10029 @item explore value @var{expr}
10030 @cindex explore value
10031 This sub-command of @code{explore} explores the value of the
10032 expression @var{expr} (if @var{expr} is an expression valid in the
10033 current context of the program being debugged). The behavior of this
10034 command is identical to that of the behavior of the @code{explore}
10035 command being passed the argument @var{expr}.
10036
10037 @item explore type @var{arg}
10038 @cindex explore type
10039 This sub-command of @code{explore} explores the type of @var{arg} (if
10040 @var{arg} is a type visible in the current context of program being
10041 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10042 is an expression valid in the current context of the program being
10043 debugged). If @var{arg} is a type, then the behavior of this command is
10044 identical to that of the @code{explore} command being passed the
10045 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10046 this command will be identical to that of the @code{explore} command
10047 being passed the type of @var{arg} as the argument.
10048 @end table
10049
10050 @menu
10051 * Expressions:: Expressions
10052 * Ambiguous Expressions:: Ambiguous Expressions
10053 * Variables:: Program variables
10054 * Arrays:: Artificial arrays
10055 * Output Formats:: Output formats
10056 * Memory:: Examining memory
10057 * Auto Display:: Automatic display
10058 * Print Settings:: Print settings
10059 * Pretty Printing:: Python pretty printing
10060 * Value History:: Value history
10061 * Convenience Vars:: Convenience variables
10062 * Convenience Funs:: Convenience functions
10063 * Registers:: Registers
10064 * Floating Point Hardware:: Floating point hardware
10065 * Vector Unit:: Vector Unit
10066 * OS Information:: Auxiliary data provided by operating system
10067 * Memory Region Attributes:: Memory region attributes
10068 * Dump/Restore Files:: Copy between memory and a file
10069 * Core File Generation:: Cause a program dump its core
10070 * Character Sets:: Debugging programs that use a different
10071 character set than GDB does
10072 * Caching Target Data:: Data caching for targets
10073 * Searching Memory:: Searching memory for a sequence of bytes
10074 * Value Sizes:: Managing memory allocated for values
10075 @end menu
10076
10077 @node Expressions
10078 @section Expressions
10079
10080 @cindex expressions
10081 @code{print} and many other @value{GDBN} commands accept an expression and
10082 compute its value. Any kind of constant, variable or operator defined
10083 by the programming language you are using is valid in an expression in
10084 @value{GDBN}. This includes conditional expressions, function calls,
10085 casts, and string constants. It also includes preprocessor macros, if
10086 you compiled your program to include this information; see
10087 @ref{Compilation}.
10088
10089 @cindex arrays in expressions
10090 @value{GDBN} supports array constants in expressions input by
10091 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10092 you can use the command @code{print @{1, 2, 3@}} to create an array
10093 of three integers. If you pass an array to a function or assign it
10094 to a program variable, @value{GDBN} copies the array to memory that
10095 is @code{malloc}ed in the target program.
10096
10097 Because C is so widespread, most of the expressions shown in examples in
10098 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10099 Languages}, for information on how to use expressions in other
10100 languages.
10101
10102 In this section, we discuss operators that you can use in @value{GDBN}
10103 expressions regardless of your programming language.
10104
10105 @cindex casts, in expressions
10106 Casts are supported in all languages, not just in C, because it is so
10107 useful to cast a number into a pointer in order to examine a structure
10108 at that address in memory.
10109 @c FIXME: casts supported---Mod2 true?
10110
10111 @value{GDBN} supports these operators, in addition to those common
10112 to programming languages:
10113
10114 @table @code
10115 @item @@
10116 @samp{@@} is a binary operator for treating parts of memory as arrays.
10117 @xref{Arrays, ,Artificial Arrays}, for more information.
10118
10119 @item ::
10120 @samp{::} allows you to specify a variable in terms of the file or
10121 function where it is defined. @xref{Variables, ,Program Variables}.
10122
10123 @cindex @{@var{type}@}
10124 @cindex type casting memory
10125 @cindex memory, viewing as typed object
10126 @cindex casts, to view memory
10127 @item @{@var{type}@} @var{addr}
10128 Refers to an object of type @var{type} stored at address @var{addr} in
10129 memory. The address @var{addr} may be any expression whose value is
10130 an integer or pointer (but parentheses are required around binary
10131 operators, just as in a cast). This construct is allowed regardless
10132 of what kind of data is normally supposed to reside at @var{addr}.
10133 @end table
10134
10135 @node Ambiguous Expressions
10136 @section Ambiguous Expressions
10137 @cindex ambiguous expressions
10138
10139 Expressions can sometimes contain some ambiguous elements. For instance,
10140 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10141 a single function name to be defined several times, for application in
10142 different contexts. This is called @dfn{overloading}. Another example
10143 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10144 templates and is typically instantiated several times, resulting in
10145 the same function name being defined in different contexts.
10146
10147 In some cases and depending on the language, it is possible to adjust
10148 the expression to remove the ambiguity. For instance in C@t{++}, you
10149 can specify the signature of the function you want to break on, as in
10150 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10151 qualified name of your function often makes the expression unambiguous
10152 as well.
10153
10154 When an ambiguity that needs to be resolved is detected, the debugger
10155 has the capability to display a menu of numbered choices for each
10156 possibility, and then waits for the selection with the prompt @samp{>}.
10157 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10158 aborts the current command. If the command in which the expression was
10159 used allows more than one choice to be selected, the next option in the
10160 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10161 choices.
10162
10163 For example, the following session excerpt shows an attempt to set a
10164 breakpoint at the overloaded symbol @code{String::after}.
10165 We choose three particular definitions of that function name:
10166
10167 @c FIXME! This is likely to change to show arg type lists, at least
10168 @smallexample
10169 @group
10170 (@value{GDBP}) b String::after
10171 [0] cancel
10172 [1] all
10173 [2] file:String.cc; line number:867
10174 [3] file:String.cc; line number:860
10175 [4] file:String.cc; line number:875
10176 [5] file:String.cc; line number:853
10177 [6] file:String.cc; line number:846
10178 [7] file:String.cc; line number:735
10179 > 2 4 6
10180 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10181 Breakpoint 2 at 0xb344: file String.cc, line 875.
10182 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10183 Multiple breakpoints were set.
10184 Use the "delete" command to delete unwanted
10185 breakpoints.
10186 (@value{GDBP})
10187 @end group
10188 @end smallexample
10189
10190 @table @code
10191 @kindex set multiple-symbols
10192 @item set multiple-symbols @var{mode}
10193 @cindex multiple-symbols menu
10194
10195 This option allows you to adjust the debugger behavior when an expression
10196 is ambiguous.
10197
10198 By default, @var{mode} is set to @code{all}. If the command with which
10199 the expression is used allows more than one choice, then @value{GDBN}
10200 automatically selects all possible choices. For instance, inserting
10201 a breakpoint on a function using an ambiguous name results in a breakpoint
10202 inserted on each possible match. However, if a unique choice must be made,
10203 then @value{GDBN} uses the menu to help you disambiguate the expression.
10204 For instance, printing the address of an overloaded function will result
10205 in the use of the menu.
10206
10207 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10208 when an ambiguity is detected.
10209
10210 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10211 an error due to the ambiguity and the command is aborted.
10212
10213 @kindex show multiple-symbols
10214 @item show multiple-symbols
10215 Show the current value of the @code{multiple-symbols} setting.
10216 @end table
10217
10218 @node Variables
10219 @section Program Variables
10220
10221 The most common kind of expression to use is the name of a variable
10222 in your program.
10223
10224 Variables in expressions are understood in the selected stack frame
10225 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10226
10227 @itemize @bullet
10228 @item
10229 global (or file-static)
10230 @end itemize
10231
10232 @noindent or
10233
10234 @itemize @bullet
10235 @item
10236 visible according to the scope rules of the
10237 programming language from the point of execution in that frame
10238 @end itemize
10239
10240 @noindent This means that in the function
10241
10242 @smallexample
10243 foo (a)
10244 int a;
10245 @{
10246 bar (a);
10247 @{
10248 int b = test ();
10249 bar (b);
10250 @}
10251 @}
10252 @end smallexample
10253
10254 @noindent
10255 you can examine and use the variable @code{a} whenever your program is
10256 executing within the function @code{foo}, but you can only use or
10257 examine the variable @code{b} while your program is executing inside
10258 the block where @code{b} is declared.
10259
10260 @cindex variable name conflict
10261 There is an exception: you can refer to a variable or function whose
10262 scope is a single source file even if the current execution point is not
10263 in this file. But it is possible to have more than one such variable or
10264 function with the same name (in different source files). If that
10265 happens, referring to that name has unpredictable effects. If you wish,
10266 you can specify a static variable in a particular function or file by
10267 using the colon-colon (@code{::}) notation:
10268
10269 @cindex colon-colon, context for variables/functions
10270 @ifnotinfo
10271 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10272 @cindex @code{::}, context for variables/functions
10273 @end ifnotinfo
10274 @smallexample
10275 @var{file}::@var{variable}
10276 @var{function}::@var{variable}
10277 @end smallexample
10278
10279 @noindent
10280 Here @var{file} or @var{function} is the name of the context for the
10281 static @var{variable}. In the case of file names, you can use quotes to
10282 make sure @value{GDBN} parses the file name as a single word---for example,
10283 to print a global value of @code{x} defined in @file{f2.c}:
10284
10285 @smallexample
10286 (@value{GDBP}) p 'f2.c'::x
10287 @end smallexample
10288
10289 The @code{::} notation is normally used for referring to
10290 static variables, since you typically disambiguate uses of local variables
10291 in functions by selecting the appropriate frame and using the
10292 simple name of the variable. However, you may also use this notation
10293 to refer to local variables in frames enclosing the selected frame:
10294
10295 @smallexample
10296 void
10297 foo (int a)
10298 @{
10299 if (a < 10)
10300 bar (a);
10301 else
10302 process (a); /* Stop here */
10303 @}
10304
10305 int
10306 bar (int a)
10307 @{
10308 foo (a + 5);
10309 @}
10310 @end smallexample
10311
10312 @noindent
10313 For example, if there is a breakpoint at the commented line,
10314 here is what you might see
10315 when the program stops after executing the call @code{bar(0)}:
10316
10317 @smallexample
10318 (@value{GDBP}) p a
10319 $1 = 10
10320 (@value{GDBP}) p bar::a
10321 $2 = 5
10322 (@value{GDBP}) up 2
10323 #2 0x080483d0 in foo (a=5) at foobar.c:12
10324 (@value{GDBP}) p a
10325 $3 = 5
10326 (@value{GDBP}) p bar::a
10327 $4 = 0
10328 @end smallexample
10329
10330 @cindex C@t{++} scope resolution
10331 These uses of @samp{::} are very rarely in conflict with the very
10332 similar use of the same notation in C@t{++}. When they are in
10333 conflict, the C@t{++} meaning takes precedence; however, this can be
10334 overridden by quoting the file or function name with single quotes.
10335
10336 For example, suppose the program is stopped in a method of a class
10337 that has a field named @code{includefile}, and there is also an
10338 include file named @file{includefile} that defines a variable,
10339 @code{some_global}.
10340
10341 @smallexample
10342 (@value{GDBP}) p includefile
10343 $1 = 23
10344 (@value{GDBP}) p includefile::some_global
10345 A syntax error in expression, near `'.
10346 (@value{GDBP}) p 'includefile'::some_global
10347 $2 = 27
10348 @end smallexample
10349
10350 @cindex wrong values
10351 @cindex variable values, wrong
10352 @cindex function entry/exit, wrong values of variables
10353 @cindex optimized code, wrong values of variables
10354 @quotation
10355 @emph{Warning:} Occasionally, a local variable may appear to have the
10356 wrong value at certain points in a function---just after entry to a new
10357 scope, and just before exit.
10358 @end quotation
10359 You may see this problem when you are stepping by machine instructions.
10360 This is because, on most machines, it takes more than one instruction to
10361 set up a stack frame (including local variable definitions); if you are
10362 stepping by machine instructions, variables may appear to have the wrong
10363 values until the stack frame is completely built. On exit, it usually
10364 also takes more than one machine instruction to destroy a stack frame;
10365 after you begin stepping through that group of instructions, local
10366 variable definitions may be gone.
10367
10368 This may also happen when the compiler does significant optimizations.
10369 To be sure of always seeing accurate values, turn off all optimization
10370 when compiling.
10371
10372 @cindex ``No symbol "foo" in current context''
10373 Another possible effect of compiler optimizations is to optimize
10374 unused variables out of existence, or assign variables to registers (as
10375 opposed to memory addresses). Depending on the support for such cases
10376 offered by the debug info format used by the compiler, @value{GDBN}
10377 might not be able to display values for such local variables. If that
10378 happens, @value{GDBN} will print a message like this:
10379
10380 @smallexample
10381 No symbol "foo" in current context.
10382 @end smallexample
10383
10384 To solve such problems, either recompile without optimizations, or use a
10385 different debug info format, if the compiler supports several such
10386 formats. @xref{Compilation}, for more information on choosing compiler
10387 options. @xref{C, ,C and C@t{++}}, for more information about debug
10388 info formats that are best suited to C@t{++} programs.
10389
10390 If you ask to print an object whose contents are unknown to
10391 @value{GDBN}, e.g., because its data type is not completely specified
10392 by the debug information, @value{GDBN} will say @samp{<incomplete
10393 type>}. @xref{Symbols, incomplete type}, for more about this.
10394
10395 @cindex no debug info variables
10396 If you try to examine or use the value of a (global) variable for
10397 which @value{GDBN} has no type information, e.g., because the program
10398 includes no debug information, @value{GDBN} displays an error message.
10399 @xref{Symbols, unknown type}, for more about unknown types. If you
10400 cast the variable to its declared type, @value{GDBN} gets the
10401 variable's value using the cast-to type as the variable's type. For
10402 example, in a C program:
10403
10404 @smallexample
10405 (@value{GDBP}) p var
10406 'var' has unknown type; cast it to its declared type
10407 (@value{GDBP}) p (float) var
10408 $1 = 3.14
10409 @end smallexample
10410
10411 If you append @kbd{@@entry} string to a function parameter name you get its
10412 value at the time the function got called. If the value is not available an
10413 error message is printed. Entry values are available only with some compilers.
10414 Entry values are normally also printed at the function parameter list according
10415 to @ref{set print entry-values}.
10416
10417 @smallexample
10418 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10419 29 i++;
10420 (gdb) next
10421 30 e (i);
10422 (gdb) print i
10423 $1 = 31
10424 (gdb) print i@@entry
10425 $2 = 30
10426 @end smallexample
10427
10428 Strings are identified as arrays of @code{char} values without specified
10429 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10430 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10431 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10432 defines literal string type @code{"char"} as @code{char} without a sign.
10433 For program code
10434
10435 @smallexample
10436 char var0[] = "A";
10437 signed char var1[] = "A";
10438 @end smallexample
10439
10440 You get during debugging
10441 @smallexample
10442 (gdb) print var0
10443 $1 = "A"
10444 (gdb) print var1
10445 $2 = @{65 'A', 0 '\0'@}
10446 @end smallexample
10447
10448 @node Arrays
10449 @section Artificial Arrays
10450
10451 @cindex artificial array
10452 @cindex arrays
10453 @kindex @@@r{, referencing memory as an array}
10454 It is often useful to print out several successive objects of the
10455 same type in memory; a section of an array, or an array of
10456 dynamically determined size for which only a pointer exists in the
10457 program.
10458
10459 You can do this by referring to a contiguous span of memory as an
10460 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10461 operand of @samp{@@} should be the first element of the desired array
10462 and be an individual object. The right operand should be the desired length
10463 of the array. The result is an array value whose elements are all of
10464 the type of the left argument. The first element is actually the left
10465 argument; the second element comes from bytes of memory immediately
10466 following those that hold the first element, and so on. Here is an
10467 example. If a program says
10468
10469 @smallexample
10470 int *array = (int *) malloc (len * sizeof (int));
10471 @end smallexample
10472
10473 @noindent
10474 you can print the contents of @code{array} with
10475
10476 @smallexample
10477 p *array@@len
10478 @end smallexample
10479
10480 The left operand of @samp{@@} must reside in memory. Array values made
10481 with @samp{@@} in this way behave just like other arrays in terms of
10482 subscripting, and are coerced to pointers when used in expressions.
10483 Artificial arrays most often appear in expressions via the value history
10484 (@pxref{Value History, ,Value History}), after printing one out.
10485
10486 Another way to create an artificial array is to use a cast.
10487 This re-interprets a value as if it were an array.
10488 The value need not be in memory:
10489 @smallexample
10490 (@value{GDBP}) p/x (short[2])0x12345678
10491 $1 = @{0x1234, 0x5678@}
10492 @end smallexample
10493
10494 As a convenience, if you leave the array length out (as in
10495 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10496 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10497 @smallexample
10498 (@value{GDBP}) p/x (short[])0x12345678
10499 $2 = @{0x1234, 0x5678@}
10500 @end smallexample
10501
10502 Sometimes the artificial array mechanism is not quite enough; in
10503 moderately complex data structures, the elements of interest may not
10504 actually be adjacent---for example, if you are interested in the values
10505 of pointers in an array. One useful work-around in this situation is
10506 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10507 Variables}) as a counter in an expression that prints the first
10508 interesting value, and then repeat that expression via @key{RET}. For
10509 instance, suppose you have an array @code{dtab} of pointers to
10510 structures, and you are interested in the values of a field @code{fv}
10511 in each structure. Here is an example of what you might type:
10512
10513 @smallexample
10514 set $i = 0
10515 p dtab[$i++]->fv
10516 @key{RET}
10517 @key{RET}
10518 @dots{}
10519 @end smallexample
10520
10521 @node Output Formats
10522 @section Output Formats
10523
10524 @cindex formatted output
10525 @cindex output formats
10526 By default, @value{GDBN} prints a value according to its data type. Sometimes
10527 this is not what you want. For example, you might want to print a number
10528 in hex, or a pointer in decimal. Or you might want to view data in memory
10529 at a certain address as a character string or as an instruction. To do
10530 these things, specify an @dfn{output format} when you print a value.
10531
10532 The simplest use of output formats is to say how to print a value
10533 already computed. This is done by starting the arguments of the
10534 @code{print} command with a slash and a format letter. The format
10535 letters supported are:
10536
10537 @table @code
10538 @item x
10539 Regard the bits of the value as an integer, and print the integer in
10540 hexadecimal.
10541
10542 @item d
10543 Print as integer in signed decimal.
10544
10545 @item u
10546 Print as integer in unsigned decimal.
10547
10548 @item o
10549 Print as integer in octal.
10550
10551 @item t
10552 Print as integer in binary. The letter @samp{t} stands for ``two''.
10553 @footnote{@samp{b} cannot be used because these format letters are also
10554 used with the @code{x} command, where @samp{b} stands for ``byte'';
10555 see @ref{Memory,,Examining Memory}.}
10556
10557 @item a
10558 @cindex unknown address, locating
10559 @cindex locate address
10560 Print as an address, both absolute in hexadecimal and as an offset from
10561 the nearest preceding symbol. You can use this format used to discover
10562 where (in what function) an unknown address is located:
10563
10564 @smallexample
10565 (@value{GDBP}) p/a 0x54320
10566 $3 = 0x54320 <_initialize_vx+396>
10567 @end smallexample
10568
10569 @noindent
10570 The command @code{info symbol 0x54320} yields similar results.
10571 @xref{Symbols, info symbol}.
10572
10573 @item c
10574 Regard as an integer and print it as a character constant. This
10575 prints both the numerical value and its character representation. The
10576 character representation is replaced with the octal escape @samp{\nnn}
10577 for characters outside the 7-bit @sc{ascii} range.
10578
10579 Without this format, @value{GDBN} displays @code{char},
10580 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10581 constants. Single-byte members of vectors are displayed as integer
10582 data.
10583
10584 @item f
10585 Regard the bits of the value as a floating point number and print
10586 using typical floating point syntax.
10587
10588 @item s
10589 @cindex printing strings
10590 @cindex printing byte arrays
10591 Regard as a string, if possible. With this format, pointers to single-byte
10592 data are displayed as null-terminated strings and arrays of single-byte data
10593 are displayed as fixed-length strings. Other values are displayed in their
10594 natural types.
10595
10596 Without this format, @value{GDBN} displays pointers to and arrays of
10597 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10598 strings. Single-byte members of a vector are displayed as an integer
10599 array.
10600
10601 @item z
10602 Like @samp{x} formatting, the value is treated as an integer and
10603 printed as hexadecimal, but leading zeros are printed to pad the value
10604 to the size of the integer type.
10605
10606 @item r
10607 @cindex raw printing
10608 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10609 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10610 Printing}). This typically results in a higher-level display of the
10611 value's contents. The @samp{r} format bypasses any Python
10612 pretty-printer which might exist.
10613 @end table
10614
10615 For example, to print the program counter in hex (@pxref{Registers}), type
10616
10617 @smallexample
10618 p/x $pc
10619 @end smallexample
10620
10621 @noindent
10622 Note that no space is required before the slash; this is because command
10623 names in @value{GDBN} cannot contain a slash.
10624
10625 To reprint the last value in the value history with a different format,
10626 you can use the @code{print} command with just a format and no
10627 expression. For example, @samp{p/x} reprints the last value in hex.
10628
10629 @node Memory
10630 @section Examining Memory
10631
10632 You can use the command @code{x} (for ``examine'') to examine memory in
10633 any of several formats, independently of your program's data types.
10634
10635 @cindex examining memory
10636 @table @code
10637 @kindex x @r{(examine memory)}
10638 @item x/@var{nfu} @var{addr}
10639 @itemx x @var{addr}
10640 @itemx x
10641 Use the @code{x} command to examine memory.
10642 @end table
10643
10644 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10645 much memory to display and how to format it; @var{addr} is an
10646 expression giving the address where you want to start displaying memory.
10647 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10648 Several commands set convenient defaults for @var{addr}.
10649
10650 @table @r
10651 @item @var{n}, the repeat count
10652 The repeat count is a decimal integer; the default is 1. It specifies
10653 how much memory (counting by units @var{u}) to display. If a negative
10654 number is specified, memory is examined backward from @var{addr}.
10655 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10656 @c 4.1.2.
10657
10658 @item @var{f}, the display format
10659 The display format is one of the formats used by @code{print}
10660 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10661 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10662 The default is @samp{x} (hexadecimal) initially. The default changes
10663 each time you use either @code{x} or @code{print}.
10664
10665 @item @var{u}, the unit size
10666 The unit size is any of
10667
10668 @table @code
10669 @item b
10670 Bytes.
10671 @item h
10672 Halfwords (two bytes).
10673 @item w
10674 Words (four bytes). This is the initial default.
10675 @item g
10676 Giant words (eight bytes).
10677 @end table
10678
10679 Each time you specify a unit size with @code{x}, that size becomes the
10680 default unit the next time you use @code{x}. For the @samp{i} format,
10681 the unit size is ignored and is normally not written. For the @samp{s} format,
10682 the unit size defaults to @samp{b}, unless it is explicitly given.
10683 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10684 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10685 Note that the results depend on the programming language of the
10686 current compilation unit. If the language is C, the @samp{s}
10687 modifier will use the UTF-16 encoding while @samp{w} will use
10688 UTF-32. The encoding is set by the programming language and cannot
10689 be altered.
10690
10691 @item @var{addr}, starting display address
10692 @var{addr} is the address where you want @value{GDBN} to begin displaying
10693 memory. The expression need not have a pointer value (though it may);
10694 it is always interpreted as an integer address of a byte of memory.
10695 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10696 @var{addr} is usually just after the last address examined---but several
10697 other commands also set the default address: @code{info breakpoints} (to
10698 the address of the last breakpoint listed), @code{info line} (to the
10699 starting address of a line), and @code{print} (if you use it to display
10700 a value from memory).
10701 @end table
10702
10703 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10704 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10705 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10706 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10707 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10708
10709 You can also specify a negative repeat count to examine memory backward
10710 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10711 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10712
10713 Since the letters indicating unit sizes are all distinct from the
10714 letters specifying output formats, you do not have to remember whether
10715 unit size or format comes first; either order works. The output
10716 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10717 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10718
10719 Even though the unit size @var{u} is ignored for the formats @samp{s}
10720 and @samp{i}, you might still want to use a count @var{n}; for example,
10721 @samp{3i} specifies that you want to see three machine instructions,
10722 including any operands. For convenience, especially when used with
10723 the @code{display} command, the @samp{i} format also prints branch delay
10724 slot instructions, if any, beyond the count specified, which immediately
10725 follow the last instruction that is within the count. The command
10726 @code{disassemble} gives an alternative way of inspecting machine
10727 instructions; see @ref{Machine Code,,Source and Machine Code}.
10728
10729 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10730 the command displays null-terminated strings or instructions before the given
10731 address as many as the absolute value of the given number. For the @samp{i}
10732 format, we use line number information in the debug info to accurately locate
10733 instruction boundaries while disassembling backward. If line info is not
10734 available, the command stops examining memory with an error message.
10735
10736 All the defaults for the arguments to @code{x} are designed to make it
10737 easy to continue scanning memory with minimal specifications each time
10738 you use @code{x}. For example, after you have inspected three machine
10739 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10740 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10741 the repeat count @var{n} is used again; the other arguments default as
10742 for successive uses of @code{x}.
10743
10744 When examining machine instructions, the instruction at current program
10745 counter is shown with a @code{=>} marker. For example:
10746
10747 @smallexample
10748 (@value{GDBP}) x/5i $pc-6
10749 0x804837f <main+11>: mov %esp,%ebp
10750 0x8048381 <main+13>: push %ecx
10751 0x8048382 <main+14>: sub $0x4,%esp
10752 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10753 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10754 @end smallexample
10755
10756 @cindex @code{$_}, @code{$__}, and value history
10757 The addresses and contents printed by the @code{x} command are not saved
10758 in the value history because there is often too much of them and they
10759 would get in the way. Instead, @value{GDBN} makes these values available for
10760 subsequent use in expressions as values of the convenience variables
10761 @code{$_} and @code{$__}. After an @code{x} command, the last address
10762 examined is available for use in expressions in the convenience variable
10763 @code{$_}. The contents of that address, as examined, are available in
10764 the convenience variable @code{$__}.
10765
10766 If the @code{x} command has a repeat count, the address and contents saved
10767 are from the last memory unit printed; this is not the same as the last
10768 address printed if several units were printed on the last line of output.
10769
10770 @anchor{addressable memory unit}
10771 @cindex addressable memory unit
10772 Most targets have an addressable memory unit size of 8 bits. This means
10773 that to each memory address are associated 8 bits of data. Some
10774 targets, however, have other addressable memory unit sizes.
10775 Within @value{GDBN} and this document, the term
10776 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10777 when explicitly referring to a chunk of data of that size. The word
10778 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10779 the addressable memory unit size of the target. For most systems,
10780 addressable memory unit is a synonym of byte.
10781
10782 @cindex remote memory comparison
10783 @cindex target memory comparison
10784 @cindex verify remote memory image
10785 @cindex verify target memory image
10786 When you are debugging a program running on a remote target machine
10787 (@pxref{Remote Debugging}), you may wish to verify the program's image
10788 in the remote machine's memory against the executable file you
10789 downloaded to the target. Or, on any target, you may want to check
10790 whether the program has corrupted its own read-only sections. The
10791 @code{compare-sections} command is provided for such situations.
10792
10793 @table @code
10794 @kindex compare-sections
10795 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10796 Compare the data of a loadable section @var{section-name} in the
10797 executable file of the program being debugged with the same section in
10798 the target machine's memory, and report any mismatches. With no
10799 arguments, compares all loadable sections. With an argument of
10800 @code{-r}, compares all loadable read-only sections.
10801
10802 Note: for remote targets, this command can be accelerated if the
10803 target supports computing the CRC checksum of a block of memory
10804 (@pxref{qCRC packet}).
10805 @end table
10806
10807 @node Auto Display
10808 @section Automatic Display
10809 @cindex automatic display
10810 @cindex display of expressions
10811
10812 If you find that you want to print the value of an expression frequently
10813 (to see how it changes), you might want to add it to the @dfn{automatic
10814 display list} so that @value{GDBN} prints its value each time your program stops.
10815 Each expression added to the list is given a number to identify it;
10816 to remove an expression from the list, you specify that number.
10817 The automatic display looks like this:
10818
10819 @smallexample
10820 2: foo = 38
10821 3: bar[5] = (struct hack *) 0x3804
10822 @end smallexample
10823
10824 @noindent
10825 This display shows item numbers, expressions and their current values. As with
10826 displays you request manually using @code{x} or @code{print}, you can
10827 specify the output format you prefer; in fact, @code{display} decides
10828 whether to use @code{print} or @code{x} depending your format
10829 specification---it uses @code{x} if you specify either the @samp{i}
10830 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
10831
10832 @table @code
10833 @kindex display
10834 @item display @var{expr}
10835 Add the expression @var{expr} to the list of expressions to display
10836 each time your program stops. @xref{Expressions, ,Expressions}.
10837
10838 @code{display} does not repeat if you press @key{RET} again after using it.
10839
10840 @item display/@var{fmt} @var{expr}
10841 For @var{fmt} specifying only a display format and not a size or
10842 count, add the expression @var{expr} to the auto-display list but
10843 arrange to display it each time in the specified format @var{fmt}.
10844 @xref{Output Formats,,Output Formats}.
10845
10846 @item display/@var{fmt} @var{addr}
10847 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10848 number of units, add the expression @var{addr} as a memory address to
10849 be examined each time your program stops. Examining means in effect
10850 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
10851 @end table
10852
10853 For example, @samp{display/i $pc} can be helpful, to see the machine
10854 instruction about to be executed each time execution stops (@samp{$pc}
10855 is a common name for the program counter; @pxref{Registers, ,Registers}).
10856
10857 @table @code
10858 @kindex delete display
10859 @kindex undisplay
10860 @item undisplay @var{dnums}@dots{}
10861 @itemx delete display @var{dnums}@dots{}
10862 Remove items from the list of expressions to display. Specify the
10863 numbers of the displays that you want affected with the command
10864 argument @var{dnums}. It can be a single display number, one of the
10865 numbers shown in the first field of the @samp{info display} display;
10866 or it could be a range of display numbers, as in @code{2-4}.
10867
10868 @code{undisplay} does not repeat if you press @key{RET} after using it.
10869 (Otherwise you would just get the error @samp{No display number @dots{}}.)
10870
10871 @kindex disable display
10872 @item disable display @var{dnums}@dots{}
10873 Disable the display of item numbers @var{dnums}. A disabled display
10874 item is not printed automatically, but is not forgotten. It may be
10875 enabled again later. Specify the numbers of the displays that you
10876 want affected with the command argument @var{dnums}. It can be a
10877 single display number, one of the numbers shown in the first field of
10878 the @samp{info display} display; or it could be a range of display
10879 numbers, as in @code{2-4}.
10880
10881 @kindex enable display
10882 @item enable display @var{dnums}@dots{}
10883 Enable display of item numbers @var{dnums}. It becomes effective once
10884 again in auto display of its expression, until you specify otherwise.
10885 Specify the numbers of the displays that you want affected with the
10886 command argument @var{dnums}. It can be a single display number, one
10887 of the numbers shown in the first field of the @samp{info display}
10888 display; or it could be a range of display numbers, as in @code{2-4}.
10889
10890 @item display
10891 Display the current values of the expressions on the list, just as is
10892 done when your program stops.
10893
10894 @kindex info display
10895 @item info display
10896 Print the list of expressions previously set up to display
10897 automatically, each one with its item number, but without showing the
10898 values. This includes disabled expressions, which are marked as such.
10899 It also includes expressions which would not be displayed right now
10900 because they refer to automatic variables not currently available.
10901 @end table
10902
10903 @cindex display disabled out of scope
10904 If a display expression refers to local variables, then it does not make
10905 sense outside the lexical context for which it was set up. Such an
10906 expression is disabled when execution enters a context where one of its
10907 variables is not defined. For example, if you give the command
10908 @code{display last_char} while inside a function with an argument
10909 @code{last_char}, @value{GDBN} displays this argument while your program
10910 continues to stop inside that function. When it stops elsewhere---where
10911 there is no variable @code{last_char}---the display is disabled
10912 automatically. The next time your program stops where @code{last_char}
10913 is meaningful, you can enable the display expression once again.
10914
10915 @node Print Settings
10916 @section Print Settings
10917
10918 @cindex format options
10919 @cindex print settings
10920 @value{GDBN} provides the following ways to control how arrays, structures,
10921 and symbols are printed.
10922
10923 @noindent
10924 These settings are useful for debugging programs in any language:
10925
10926 @table @code
10927 @kindex set print
10928 @anchor{set print address}
10929 @item set print address
10930 @itemx set print address on
10931 @cindex print/don't print memory addresses
10932 @value{GDBN} prints memory addresses showing the location of stack
10933 traces, structure values, pointer values, breakpoints, and so forth,
10934 even when it also displays the contents of those addresses. The default
10935 is @code{on}. For example, this is what a stack frame display looks like with
10936 @code{set print address on}:
10937
10938 @smallexample
10939 @group
10940 (@value{GDBP}) f
10941 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10942 at input.c:530
10943 530 if (lquote != def_lquote)
10944 @end group
10945 @end smallexample
10946
10947 @item set print address off
10948 Do not print addresses when displaying their contents. For example,
10949 this is the same stack frame displayed with @code{set print address off}:
10950
10951 @smallexample
10952 @group
10953 (@value{GDBP}) set print addr off
10954 (@value{GDBP}) f
10955 #0 set_quotes (lq="<<", rq=">>") at input.c:530
10956 530 if (lquote != def_lquote)
10957 @end group
10958 @end smallexample
10959
10960 You can use @samp{set print address off} to eliminate all machine
10961 dependent displays from the @value{GDBN} interface. For example, with
10962 @code{print address off}, you should get the same text for backtraces on
10963 all machines---whether or not they involve pointer arguments.
10964
10965 @kindex show print
10966 @item show print address
10967 Show whether or not addresses are to be printed.
10968 @end table
10969
10970 When @value{GDBN} prints a symbolic address, it normally prints the
10971 closest earlier symbol plus an offset. If that symbol does not uniquely
10972 identify the address (for example, it is a name whose scope is a single
10973 source file), you may need to clarify. One way to do this is with
10974 @code{info line}, for example @samp{info line *0x4537}. Alternately,
10975 you can set @value{GDBN} to print the source file and line number when
10976 it prints a symbolic address:
10977
10978 @table @code
10979 @item set print symbol-filename on
10980 @cindex source file and line of a symbol
10981 @cindex symbol, source file and line
10982 Tell @value{GDBN} to print the source file name and line number of a
10983 symbol in the symbolic form of an address.
10984
10985 @item set print symbol-filename off
10986 Do not print source file name and line number of a symbol. This is the
10987 default.
10988
10989 @item show print symbol-filename
10990 Show whether or not @value{GDBN} will print the source file name and
10991 line number of a symbol in the symbolic form of an address.
10992 @end table
10993
10994 Another situation where it is helpful to show symbol filenames and line
10995 numbers is when disassembling code; @value{GDBN} shows you the line
10996 number and source file that corresponds to each instruction.
10997
10998 Also, you may wish to see the symbolic form only if the address being
10999 printed is reasonably close to the closest earlier symbol:
11000
11001 @table @code
11002 @item set print max-symbolic-offset @var{max-offset}
11003 @itemx set print max-symbolic-offset unlimited
11004 @cindex maximum value for offset of closest symbol
11005 Tell @value{GDBN} to only display the symbolic form of an address if the
11006 offset between the closest earlier symbol and the address is less than
11007 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11008 to always print the symbolic form of an address if any symbol precedes
11009 it. Zero is equivalent to @code{unlimited}.
11010
11011 @item show print max-symbolic-offset
11012 Ask how large the maximum offset is that @value{GDBN} prints in a
11013 symbolic address.
11014 @end table
11015
11016 @cindex wild pointer, interpreting
11017 @cindex pointer, finding referent
11018 If you have a pointer and you are not sure where it points, try
11019 @samp{set print symbol-filename on}. Then you can determine the name
11020 and source file location of the variable where it points, using
11021 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11022 For example, here @value{GDBN} shows that a variable @code{ptt} points
11023 at another variable @code{t}, defined in @file{hi2.c}:
11024
11025 @smallexample
11026 (@value{GDBP}) set print symbol-filename on
11027 (@value{GDBP}) p/a ptt
11028 $4 = 0xe008 <t in hi2.c>
11029 @end smallexample
11030
11031 @quotation
11032 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11033 does not show the symbol name and filename of the referent, even with
11034 the appropriate @code{set print} options turned on.
11035 @end quotation
11036
11037 You can also enable @samp{/a}-like formatting all the time using
11038 @samp{set print symbol on}:
11039
11040 @anchor{set print symbol}
11041 @table @code
11042 @item set print symbol on
11043 Tell @value{GDBN} to print the symbol corresponding to an address, if
11044 one exists.
11045
11046 @item set print symbol off
11047 Tell @value{GDBN} not to print the symbol corresponding to an
11048 address. In this mode, @value{GDBN} will still print the symbol
11049 corresponding to pointers to functions. This is the default.
11050
11051 @item show print symbol
11052 Show whether @value{GDBN} will display the symbol corresponding to an
11053 address.
11054 @end table
11055
11056 Other settings control how different kinds of objects are printed:
11057
11058 @table @code
11059 @anchor{set print array}
11060 @item set print array
11061 @itemx set print array on
11062 @cindex pretty print arrays
11063 Pretty print arrays. This format is more convenient to read,
11064 but uses more space. The default is off.
11065
11066 @item set print array off
11067 Return to compressed format for arrays.
11068
11069 @item show print array
11070 Show whether compressed or pretty format is selected for displaying
11071 arrays.
11072
11073 @cindex print array indexes
11074 @anchor{set print array-indexes}
11075 @item set print array-indexes
11076 @itemx set print array-indexes on
11077 Print the index of each element when displaying arrays. May be more
11078 convenient to locate a given element in the array or quickly find the
11079 index of a given element in that printed array. The default is off.
11080
11081 @item set print array-indexes off
11082 Stop printing element indexes when displaying arrays.
11083
11084 @item show print array-indexes
11085 Show whether the index of each element is printed when displaying
11086 arrays.
11087
11088 @anchor{set print elements}
11089 @item set print elements @var{number-of-elements}
11090 @itemx set print elements unlimited
11091 @cindex number of array elements to print
11092 @cindex limit on number of printed array elements
11093 Set a limit on how many elements of an array @value{GDBN} will print.
11094 If @value{GDBN} is printing a large array, it stops printing after it has
11095 printed the number of elements set by the @code{set print elements} command.
11096 This limit also applies to the display of strings.
11097 When @value{GDBN} starts, this limit is set to 200.
11098 Setting @var{number-of-elements} to @code{unlimited} or zero means
11099 that the number of elements to print is unlimited.
11100
11101 @item show print elements
11102 Display the number of elements of a large array that @value{GDBN} will print.
11103 If the number is 0, then the printing is unlimited.
11104
11105 @anchor{set print frame-arguments}
11106 @item set print frame-arguments @var{value}
11107 @kindex set print frame-arguments
11108 @cindex printing frame argument values
11109 @cindex print all frame argument values
11110 @cindex print frame argument values for scalars only
11111 @cindex do not print frame arguments
11112 This command allows to control how the values of arguments are printed
11113 when the debugger prints a frame (@pxref{Frames}). The possible
11114 values are:
11115
11116 @table @code
11117 @item all
11118 The values of all arguments are printed.
11119
11120 @item scalars
11121 Print the value of an argument only if it is a scalar. The value of more
11122 complex arguments such as arrays, structures, unions, etc, is replaced
11123 by @code{@dots{}}. This is the default. Here is an example where
11124 only scalar arguments are shown:
11125
11126 @smallexample
11127 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11128 at frame-args.c:23
11129 @end smallexample
11130
11131 @item none
11132 None of the argument values are printed. Instead, the value of each argument
11133 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11134
11135 @smallexample
11136 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11137 at frame-args.c:23
11138 @end smallexample
11139
11140 @item presence
11141 Only the presence of arguments is indicated by @code{@dots{}}.
11142 The @code{@dots{}} are not printed for function without any arguments.
11143 None of the argument names and values are printed.
11144 In this case, the example above now becomes:
11145
11146 @smallexample
11147 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11148 @end smallexample
11149
11150 @end table
11151
11152 By default, only scalar arguments are printed. This command can be used
11153 to configure the debugger to print the value of all arguments, regardless
11154 of their type. However, it is often advantageous to not print the value
11155 of more complex parameters. For instance, it reduces the amount of
11156 information printed in each frame, making the backtrace more readable.
11157 Also, it improves performance when displaying Ada frames, because
11158 the computation of large arguments can sometimes be CPU-intensive,
11159 especially in large applications. Setting @code{print frame-arguments}
11160 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11161 this computation, thus speeding up the display of each Ada frame.
11162
11163 @item show print frame-arguments
11164 Show how the value of arguments should be displayed when printing a frame.
11165
11166 @anchor{set print raw-frame-arguments}
11167 @item set print raw-frame-arguments on
11168 Print frame arguments in raw, non pretty-printed, form.
11169
11170 @item set print raw-frame-arguments off
11171 Print frame arguments in pretty-printed form, if there is a pretty-printer
11172 for the value (@pxref{Pretty Printing}),
11173 otherwise print the value in raw form.
11174 This is the default.
11175
11176 @item show print raw-frame-arguments
11177 Show whether to print frame arguments in raw form.
11178
11179 @anchor{set print entry-values}
11180 @item set print entry-values @var{value}
11181 @kindex set print entry-values
11182 Set printing of frame argument values at function entry. In some cases
11183 @value{GDBN} can determine the value of function argument which was passed by
11184 the function caller, even if the value was modified inside the called function
11185 and therefore is different. With optimized code, the current value could be
11186 unavailable, but the entry value may still be known.
11187
11188 The default value is @code{default} (see below for its description). Older
11189 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11190 this feature will behave in the @code{default} setting the same way as with the
11191 @code{no} setting.
11192
11193 This functionality is currently supported only by DWARF 2 debugging format and
11194 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11195 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11196 this information.
11197
11198 The @var{value} parameter can be one of the following:
11199
11200 @table @code
11201 @item no
11202 Print only actual parameter values, never print values from function entry
11203 point.
11204 @smallexample
11205 #0 equal (val=5)
11206 #0 different (val=6)
11207 #0 lost (val=<optimized out>)
11208 #0 born (val=10)
11209 #0 invalid (val=<optimized out>)
11210 @end smallexample
11211
11212 @item only
11213 Print only parameter values from function entry point. The actual parameter
11214 values are never printed.
11215 @smallexample
11216 #0 equal (val@@entry=5)
11217 #0 different (val@@entry=5)
11218 #0 lost (val@@entry=5)
11219 #0 born (val@@entry=<optimized out>)
11220 #0 invalid (val@@entry=<optimized out>)
11221 @end smallexample
11222
11223 @item preferred
11224 Print only parameter values from function entry point. If value from function
11225 entry point is not known while the actual value is known, print the actual
11226 value for such parameter.
11227 @smallexample
11228 #0 equal (val@@entry=5)
11229 #0 different (val@@entry=5)
11230 #0 lost (val@@entry=5)
11231 #0 born (val=10)
11232 #0 invalid (val@@entry=<optimized out>)
11233 @end smallexample
11234
11235 @item if-needed
11236 Print actual parameter values. If actual parameter value is not known while
11237 value from function entry point is known, print the entry point value for such
11238 parameter.
11239 @smallexample
11240 #0 equal (val=5)
11241 #0 different (val=6)
11242 #0 lost (val@@entry=5)
11243 #0 born (val=10)
11244 #0 invalid (val=<optimized out>)
11245 @end smallexample
11246
11247 @item both
11248 Always print both the actual parameter value and its value from function entry
11249 point, even if values of one or both are not available due to compiler
11250 optimizations.
11251 @smallexample
11252 #0 equal (val=5, val@@entry=5)
11253 #0 different (val=6, val@@entry=5)
11254 #0 lost (val=<optimized out>, val@@entry=5)
11255 #0 born (val=10, val@@entry=<optimized out>)
11256 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11257 @end smallexample
11258
11259 @item compact
11260 Print the actual parameter value if it is known and also its value from
11261 function entry point if it is known. If neither is known, print for the actual
11262 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11263 values are known and identical, print the shortened
11264 @code{param=param@@entry=VALUE} notation.
11265 @smallexample
11266 #0 equal (val=val@@entry=5)
11267 #0 different (val=6, val@@entry=5)
11268 #0 lost (val@@entry=5)
11269 #0 born (val=10)
11270 #0 invalid (val=<optimized out>)
11271 @end smallexample
11272
11273 @item default
11274 Always print the actual parameter value. Print also its value from function
11275 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11276 if both values are known and identical, print the shortened
11277 @code{param=param@@entry=VALUE} notation.
11278 @smallexample
11279 #0 equal (val=val@@entry=5)
11280 #0 different (val=6, val@@entry=5)
11281 #0 lost (val=<optimized out>, val@@entry=5)
11282 #0 born (val=10)
11283 #0 invalid (val=<optimized out>)
11284 @end smallexample
11285 @end table
11286
11287 For analysis messages on possible failures of frame argument values at function
11288 entry resolution see @ref{set debug entry-values}.
11289
11290 @item show print entry-values
11291 Show the method being used for printing of frame argument values at function
11292 entry.
11293
11294 @anchor{set print frame-info}
11295 @item set print frame-info @var{value}
11296 @kindex set print frame-info
11297 @cindex printing frame information
11298 @cindex frame information, printing
11299 This command allows to control the information printed when
11300 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11301 for a general explanation about frames and frame information.
11302 Note that some other settings (such as @code{set print frame-arguments}
11303 and @code{set print address}) are also influencing if and how some frame
11304 information is displayed. In particular, the frame program counter is never
11305 printed if @code{set print address} is off.
11306
11307 The possible values for @code{set print frame-info} are:
11308 @table @code
11309 @item short-location
11310 Print the frame level, the program counter (if not at the
11311 beginning of the location source line), the function, the function
11312 arguments.
11313 @item location
11314 Same as @code{short-location} but also print the source file and source line
11315 number.
11316 @item location-and-address
11317 Same as @code{location} but print the program counter even if located at the
11318 beginning of the location source line.
11319 @item source-line
11320 Print the program counter (if not at the beginning of the location
11321 source line), the line number and the source line.
11322 @item source-and-location
11323 Print what @code{location} and @code{source-line} are printing.
11324 @item auto
11325 The information printed for a frame is decided automatically
11326 by the @value{GDBN} command that prints a frame.
11327 For example, @code{frame} prints the information printed by
11328 @code{source-and-location} while @code{stepi} will switch between
11329 @code{source-line} and @code{source-and-location} depending on the program
11330 counter.
11331 The default value is @code{auto}.
11332 @end table
11333
11334 @anchor{set print repeats}
11335 @item set print repeats @var{number-of-repeats}
11336 @itemx set print repeats unlimited
11337 @cindex repeated array elements
11338 Set the threshold for suppressing display of repeated array
11339 elements. When the number of consecutive identical elements of an
11340 array exceeds the threshold, @value{GDBN} prints the string
11341 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11342 identical repetitions, instead of displaying the identical elements
11343 themselves. Setting the threshold to @code{unlimited} or zero will
11344 cause all elements to be individually printed. The default threshold
11345 is 10.
11346
11347 @item show print repeats
11348 Display the current threshold for printing repeated identical
11349 elements.
11350
11351 @anchor{set print max-depth}
11352 @item set print max-depth @var{depth}
11353 @item set print max-depth unlimited
11354 @cindex printing nested structures
11355 Set the threshold after which nested structures are replaced with
11356 ellipsis, this can make visualising deeply nested structures easier.
11357
11358 For example, given this C code
11359
11360 @smallexample
11361 typedef struct s1 @{ int a; @} s1;
11362 typedef struct s2 @{ s1 b; @} s2;
11363 typedef struct s3 @{ s2 c; @} s3;
11364 typedef struct s4 @{ s3 d; @} s4;
11365
11366 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11367 @end smallexample
11368
11369 The following table shows how different values of @var{depth} will
11370 effect how @code{var} is printed by @value{GDBN}:
11371
11372 @multitable @columnfractions .3 .7
11373 @headitem @var{depth} setting @tab Result of @samp{p var}
11374 @item unlimited
11375 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11376 @item @code{0}
11377 @tab @code{$1 = @{...@}}
11378 @item @code{1}
11379 @tab @code{$1 = @{d = @{...@}@}}
11380 @item @code{2}
11381 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11382 @item @code{3}
11383 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11384 @item @code{4}
11385 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11386 @end multitable
11387
11388 To see the contents of structures that have been hidden the user can
11389 either increase the print max-depth, or they can print the elements of
11390 the structure that are visible, for example
11391
11392 @smallexample
11393 (gdb) set print max-depth 2
11394 (gdb) p var
11395 $1 = @{d = @{c = @{...@}@}@}
11396 (gdb) p var.d
11397 $2 = @{c = @{b = @{...@}@}@}
11398 (gdb) p var.d.c
11399 $3 = @{b = @{a = 3@}@}
11400 @end smallexample
11401
11402 The pattern used to replace nested structures varies based on
11403 language, for most languages @code{@{...@}} is used, but Fortran uses
11404 @code{(...)}.
11405
11406 @item show print max-depth
11407 Display the current threshold after which nested structures are
11408 replaces with ellipsis.
11409
11410 @anchor{set print null-stop}
11411 @item set print null-stop
11412 @cindex @sc{null} elements in arrays
11413 Cause @value{GDBN} to stop printing the characters of an array when the first
11414 @sc{null} is encountered. This is useful when large arrays actually
11415 contain only short strings.
11416 The default is off.
11417
11418 @item show print null-stop
11419 Show whether @value{GDBN} stops printing an array on the first
11420 @sc{null} character.
11421
11422 @anchor{set print pretty}
11423 @item set print pretty on
11424 @cindex print structures in indented form
11425 @cindex indentation in structure display
11426 Cause @value{GDBN} to print structures in an indented format with one member
11427 per line, like this:
11428
11429 @smallexample
11430 @group
11431 $1 = @{
11432 next = 0x0,
11433 flags = @{
11434 sweet = 1,
11435 sour = 1
11436 @},
11437 meat = 0x54 "Pork"
11438 @}
11439 @end group
11440 @end smallexample
11441
11442 @item set print pretty off
11443 Cause @value{GDBN} to print structures in a compact format, like this:
11444
11445 @smallexample
11446 @group
11447 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11448 meat = 0x54 "Pork"@}
11449 @end group
11450 @end smallexample
11451
11452 @noindent
11453 This is the default format.
11454
11455 @item show print pretty
11456 Show which format @value{GDBN} is using to print structures.
11457
11458 @anchor{set print raw-values}
11459 @item set print raw-values on
11460 Print values in raw form, without applying the pretty
11461 printers for the value.
11462
11463 @item set print raw-values off
11464 Print values in pretty-printed form, if there is a pretty-printer
11465 for the value (@pxref{Pretty Printing}),
11466 otherwise print the value in raw form.
11467
11468 The default setting is ``off''.
11469
11470 @item show print raw-values
11471 Show whether to print values in raw form.
11472
11473 @item set print sevenbit-strings on
11474 @cindex eight-bit characters in strings
11475 @cindex octal escapes in strings
11476 Print using only seven-bit characters; if this option is set,
11477 @value{GDBN} displays any eight-bit characters (in strings or
11478 character values) using the notation @code{\}@var{nnn}. This setting is
11479 best if you are working in English (@sc{ascii}) and you use the
11480 high-order bit of characters as a marker or ``meta'' bit.
11481
11482 @item set print sevenbit-strings off
11483 Print full eight-bit characters. This allows the use of more
11484 international character sets, and is the default.
11485
11486 @item show print sevenbit-strings
11487 Show whether or not @value{GDBN} is printing only seven-bit characters.
11488
11489 @anchor{set print union}
11490 @item set print union on
11491 @cindex unions in structures, printing
11492 Tell @value{GDBN} to print unions which are contained in structures
11493 and other unions. This is the default setting.
11494
11495 @item set print union off
11496 Tell @value{GDBN} not to print unions which are contained in
11497 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11498 instead.
11499
11500 @item show print union
11501 Ask @value{GDBN} whether or not it will print unions which are contained in
11502 structures and other unions.
11503
11504 For example, given the declarations
11505
11506 @smallexample
11507 typedef enum @{Tree, Bug@} Species;
11508 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11509 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11510 Bug_forms;
11511
11512 struct thing @{
11513 Species it;
11514 union @{
11515 Tree_forms tree;
11516 Bug_forms bug;
11517 @} form;
11518 @};
11519
11520 struct thing foo = @{Tree, @{Acorn@}@};
11521 @end smallexample
11522
11523 @noindent
11524 with @code{set print union on} in effect @samp{p foo} would print
11525
11526 @smallexample
11527 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11528 @end smallexample
11529
11530 @noindent
11531 and with @code{set print union off} in effect it would print
11532
11533 @smallexample
11534 $1 = @{it = Tree, form = @{...@}@}
11535 @end smallexample
11536
11537 @noindent
11538 @code{set print union} affects programs written in C-like languages
11539 and in Pascal.
11540 @end table
11541
11542 @need 1000
11543 @noindent
11544 These settings are of interest when debugging C@t{++} programs:
11545
11546 @table @code
11547 @cindex demangling C@t{++} names
11548 @item set print demangle
11549 @itemx set print demangle on
11550 Print C@t{++} names in their source form rather than in the encoded
11551 (``mangled'') form passed to the assembler and linker for type-safe
11552 linkage. The default is on.
11553
11554 @item show print demangle
11555 Show whether C@t{++} names are printed in mangled or demangled form.
11556
11557 @item set print asm-demangle
11558 @itemx set print asm-demangle on
11559 Print C@t{++} names in their source form rather than their mangled form, even
11560 in assembler code printouts such as instruction disassemblies.
11561 The default is off.
11562
11563 @item show print asm-demangle
11564 Show whether C@t{++} names in assembly listings are printed in mangled
11565 or demangled form.
11566
11567 @cindex C@t{++} symbol decoding style
11568 @cindex symbol decoding style, C@t{++}
11569 @kindex set demangle-style
11570 @item set demangle-style @var{style}
11571 Choose among several encoding schemes used by different compilers to represent
11572 C@t{++} names. If you omit @var{style}, you will see a list of possible
11573 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11574 decoding style by inspecting your program.
11575
11576 @item show demangle-style
11577 Display the encoding style currently in use for decoding C@t{++} symbols.
11578
11579 @anchor{set print object}
11580 @item set print object
11581 @itemx set print object on
11582 @cindex derived type of an object, printing
11583 @cindex display derived types
11584 When displaying a pointer to an object, identify the @emph{actual}
11585 (derived) type of the object rather than the @emph{declared} type, using
11586 the virtual function table. Note that the virtual function table is
11587 required---this feature can only work for objects that have run-time
11588 type identification; a single virtual method in the object's declared
11589 type is sufficient. Note that this setting is also taken into account when
11590 working with variable objects via MI (@pxref{GDB/MI}).
11591
11592 @item set print object off
11593 Display only the declared type of objects, without reference to the
11594 virtual function table. This is the default setting.
11595
11596 @item show print object
11597 Show whether actual, or declared, object types are displayed.
11598
11599 @anchor{set print static-members}
11600 @item set print static-members
11601 @itemx set print static-members on
11602 @cindex static members of C@t{++} objects
11603 Print static members when displaying a C@t{++} object. The default is on.
11604
11605 @item set print static-members off
11606 Do not print static members when displaying a C@t{++} object.
11607
11608 @item show print static-members
11609 Show whether C@t{++} static members are printed or not.
11610
11611 @item set print pascal_static-members
11612 @itemx set print pascal_static-members on
11613 @cindex static members of Pascal objects
11614 @cindex Pascal objects, static members display
11615 Print static members when displaying a Pascal object. The default is on.
11616
11617 @item set print pascal_static-members off
11618 Do not print static members when displaying a Pascal object.
11619
11620 @item show print pascal_static-members
11621 Show whether Pascal static members are printed or not.
11622
11623 @c These don't work with HP ANSI C++ yet.
11624 @anchor{set print vtbl}
11625 @item set print vtbl
11626 @itemx set print vtbl on
11627 @cindex pretty print C@t{++} virtual function tables
11628 @cindex virtual functions (C@t{++}) display
11629 @cindex VTBL display
11630 Pretty print C@t{++} virtual function tables. The default is off.
11631 (The @code{vtbl} commands do not work on programs compiled with the HP
11632 ANSI C@t{++} compiler (@code{aCC}).)
11633
11634 @item set print vtbl off
11635 Do not pretty print C@t{++} virtual function tables.
11636
11637 @item show print vtbl
11638 Show whether C@t{++} virtual function tables are pretty printed, or not.
11639 @end table
11640
11641 @node Pretty Printing
11642 @section Pretty Printing
11643
11644 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11645 Python code. It greatly simplifies the display of complex objects. This
11646 mechanism works for both MI and the CLI.
11647
11648 @menu
11649 * Pretty-Printer Introduction:: Introduction to pretty-printers
11650 * Pretty-Printer Example:: An example pretty-printer
11651 * Pretty-Printer Commands:: Pretty-printer commands
11652 @end menu
11653
11654 @node Pretty-Printer Introduction
11655 @subsection Pretty-Printer Introduction
11656
11657 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11658 registered for the value. If there is then @value{GDBN} invokes the
11659 pretty-printer to print the value. Otherwise the value is printed normally.
11660
11661 Pretty-printers are normally named. This makes them easy to manage.
11662 The @samp{info pretty-printer} command will list all the installed
11663 pretty-printers with their names.
11664 If a pretty-printer can handle multiple data types, then its
11665 @dfn{subprinters} are the printers for the individual data types.
11666 Each such subprinter has its own name.
11667 The format of the name is @var{printer-name};@var{subprinter-name}.
11668
11669 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11670 Typically they are automatically loaded and registered when the corresponding
11671 debug information is loaded, thus making them available without having to
11672 do anything special.
11673
11674 There are three places where a pretty-printer can be registered.
11675
11676 @itemize @bullet
11677 @item
11678 Pretty-printers registered globally are available when debugging
11679 all inferiors.
11680
11681 @item
11682 Pretty-printers registered with a program space are available only
11683 when debugging that program.
11684 @xref{Progspaces In Python}, for more details on program spaces in Python.
11685
11686 @item
11687 Pretty-printers registered with an objfile are loaded and unloaded
11688 with the corresponding objfile (e.g., shared library).
11689 @xref{Objfiles In Python}, for more details on objfiles in Python.
11690 @end itemize
11691
11692 @xref{Selecting Pretty-Printers}, for further information on how
11693 pretty-printers are selected,
11694
11695 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11696 for new types.
11697
11698 @node Pretty-Printer Example
11699 @subsection Pretty-Printer Example
11700
11701 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11702
11703 @smallexample
11704 (@value{GDBP}) print s
11705 $1 = @{
11706 static npos = 4294967295,
11707 _M_dataplus = @{
11708 <std::allocator<char>> = @{
11709 <__gnu_cxx::new_allocator<char>> = @{
11710 <No data fields>@}, <No data fields>
11711 @},
11712 members of std::basic_string<char, std::char_traits<char>,
11713 std::allocator<char> >::_Alloc_hider:
11714 _M_p = 0x804a014 "abcd"
11715 @}
11716 @}
11717 @end smallexample
11718
11719 With a pretty-printer for @code{std::string} only the contents are printed:
11720
11721 @smallexample
11722 (@value{GDBP}) print s
11723 $2 = "abcd"
11724 @end smallexample
11725
11726 @node Pretty-Printer Commands
11727 @subsection Pretty-Printer Commands
11728 @cindex pretty-printer commands
11729
11730 @table @code
11731 @kindex info pretty-printer
11732 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11733 Print the list of installed pretty-printers.
11734 This includes disabled pretty-printers, which are marked as such.
11735
11736 @var{object-regexp} is a regular expression matching the objects
11737 whose pretty-printers to list.
11738 Objects can be @code{global}, the program space's file
11739 (@pxref{Progspaces In Python}),
11740 and the object files within that program space (@pxref{Objfiles In Python}).
11741 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11742 looks up a printer from these three objects.
11743
11744 @var{name-regexp} is a regular expression matching the name of the printers
11745 to list.
11746
11747 @kindex disable pretty-printer
11748 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11749 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11750 A disabled pretty-printer is not forgotten, it may be enabled again later.
11751
11752 @kindex enable pretty-printer
11753 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11754 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11755 @end table
11756
11757 Example:
11758
11759 Suppose we have three pretty-printers installed: one from library1.so
11760 named @code{foo} that prints objects of type @code{foo}, and
11761 another from library2.so named @code{bar} that prints two types of objects,
11762 @code{bar1} and @code{bar2}.
11763
11764 @smallexample
11765 (gdb) info pretty-printer
11766 library1.so:
11767 foo
11768 library2.so:
11769 bar
11770 bar1
11771 bar2
11772 (gdb) info pretty-printer library2
11773 library2.so:
11774 bar
11775 bar1
11776 bar2
11777 (gdb) disable pretty-printer library1
11778 1 printer disabled
11779 2 of 3 printers enabled
11780 (gdb) info pretty-printer
11781 library1.so:
11782 foo [disabled]
11783 library2.so:
11784 bar
11785 bar1
11786 bar2
11787 (gdb) disable pretty-printer library2 bar;bar1
11788 1 printer disabled
11789 1 of 3 printers enabled
11790 (gdb) info pretty-printer library2
11791 library1.so:
11792 foo [disabled]
11793 library2.so:
11794 bar
11795 bar1 [disabled]
11796 bar2
11797 (gdb) disable pretty-printer library2 bar
11798 1 printer disabled
11799 0 of 3 printers enabled
11800 (gdb) info pretty-printer library2
11801 library1.so:
11802 foo [disabled]
11803 library2.so:
11804 bar [disabled]
11805 bar1 [disabled]
11806 bar2
11807 @end smallexample
11808
11809 Note that for @code{bar} the entire printer can be disabled,
11810 as can each individual subprinter.
11811
11812 Printing values and frame arguments is done by default using
11813 the enabled pretty printers.
11814
11815 The print option @code{-raw-values} and @value{GDBN} setting
11816 @code{set print raw-values} (@pxref{set print raw-values}) can be
11817 used to print values without applying the enabled pretty printers.
11818
11819 Similarly, the backtrace option @code{-raw-frame-arguments} and
11820 @value{GDBN} setting @code{set print raw-frame-arguments}
11821 (@pxref{set print raw-frame-arguments}) can be used to ignore the
11822 enabled pretty printers when printing frame argument values.
11823
11824 @node Value History
11825 @section Value History
11826
11827 @cindex value history
11828 @cindex history of values printed by @value{GDBN}
11829 Values printed by the @code{print} command are saved in the @value{GDBN}
11830 @dfn{value history}. This allows you to refer to them in other expressions.
11831 Values are kept until the symbol table is re-read or discarded
11832 (for example with the @code{file} or @code{symbol-file} commands).
11833 When the symbol table changes, the value history is discarded,
11834 since the values may contain pointers back to the types defined in the
11835 symbol table.
11836
11837 @cindex @code{$}
11838 @cindex @code{$$}
11839 @cindex history number
11840 The values printed are given @dfn{history numbers} by which you can
11841 refer to them. These are successive integers starting with one.
11842 @code{print} shows you the history number assigned to a value by
11843 printing @samp{$@var{num} = } before the value; here @var{num} is the
11844 history number.
11845
11846 To refer to any previous value, use @samp{$} followed by the value's
11847 history number. The way @code{print} labels its output is designed to
11848 remind you of this. Just @code{$} refers to the most recent value in
11849 the history, and @code{$$} refers to the value before that.
11850 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11851 is the value just prior to @code{$$}, @code{$$1} is equivalent to
11852 @code{$$}, and @code{$$0} is equivalent to @code{$}.
11853
11854 For example, suppose you have just printed a pointer to a structure and
11855 want to see the contents of the structure. It suffices to type
11856
11857 @smallexample
11858 p *$
11859 @end smallexample
11860
11861 If you have a chain of structures where the component @code{next} points
11862 to the next one, you can print the contents of the next one with this:
11863
11864 @smallexample
11865 p *$.next
11866 @end smallexample
11867
11868 @noindent
11869 You can print successive links in the chain by repeating this
11870 command---which you can do by just typing @key{RET}.
11871
11872 Note that the history records values, not expressions. If the value of
11873 @code{x} is 4 and you type these commands:
11874
11875 @smallexample
11876 print x
11877 set x=5
11878 @end smallexample
11879
11880 @noindent
11881 then the value recorded in the value history by the @code{print} command
11882 remains 4 even though the value of @code{x} has changed.
11883
11884 @table @code
11885 @kindex show values
11886 @item show values
11887 Print the last ten values in the value history, with their item numbers.
11888 This is like @samp{p@ $$9} repeated ten times, except that @code{show
11889 values} does not change the history.
11890
11891 @item show values @var{n}
11892 Print ten history values centered on history item number @var{n}.
11893
11894 @item show values +
11895 Print ten history values just after the values last printed. If no more
11896 values are available, @code{show values +} produces no display.
11897 @end table
11898
11899 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11900 same effect as @samp{show values +}.
11901
11902 @node Convenience Vars
11903 @section Convenience Variables
11904
11905 @cindex convenience variables
11906 @cindex user-defined variables
11907 @value{GDBN} provides @dfn{convenience variables} that you can use within
11908 @value{GDBN} to hold on to a value and refer to it later. These variables
11909 exist entirely within @value{GDBN}; they are not part of your program, and
11910 setting a convenience variable has no direct effect on further execution
11911 of your program. That is why you can use them freely.
11912
11913 Convenience variables are prefixed with @samp{$}. Any name preceded by
11914 @samp{$} can be used for a convenience variable, unless it is one of
11915 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
11916 (Value history references, in contrast, are @emph{numbers} preceded
11917 by @samp{$}. @xref{Value History, ,Value History}.)
11918
11919 You can save a value in a convenience variable with an assignment
11920 expression, just as you would set a variable in your program.
11921 For example:
11922
11923 @smallexample
11924 set $foo = *object_ptr
11925 @end smallexample
11926
11927 @noindent
11928 would save in @code{$foo} the value contained in the object pointed to by
11929 @code{object_ptr}.
11930
11931 Using a convenience variable for the first time creates it, but its
11932 value is @code{void} until you assign a new value. You can alter the
11933 value with another assignment at any time.
11934
11935 Convenience variables have no fixed types. You can assign a convenience
11936 variable any type of value, including structures and arrays, even if
11937 that variable already has a value of a different type. The convenience
11938 variable, when used as an expression, has the type of its current value.
11939
11940 @table @code
11941 @kindex show convenience
11942 @cindex show all user variables and functions
11943 @item show convenience
11944 Print a list of convenience variables used so far, and their values,
11945 as well as a list of the convenience functions.
11946 Abbreviated @code{show conv}.
11947
11948 @kindex init-if-undefined
11949 @cindex convenience variables, initializing
11950 @item init-if-undefined $@var{variable} = @var{expression}
11951 Set a convenience variable if it has not already been set. This is useful
11952 for user-defined commands that keep some state. It is similar, in concept,
11953 to using local static variables with initializers in C (except that
11954 convenience variables are global). It can also be used to allow users to
11955 override default values used in a command script.
11956
11957 If the variable is already defined then the expression is not evaluated so
11958 any side-effects do not occur.
11959 @end table
11960
11961 One of the ways to use a convenience variable is as a counter to be
11962 incremented or a pointer to be advanced. For example, to print
11963 a field from successive elements of an array of structures:
11964
11965 @smallexample
11966 set $i = 0
11967 print bar[$i++]->contents
11968 @end smallexample
11969
11970 @noindent
11971 Repeat that command by typing @key{RET}.
11972
11973 Some convenience variables are created automatically by @value{GDBN} and given
11974 values likely to be useful.
11975
11976 @table @code
11977 @vindex $_@r{, convenience variable}
11978 @item $_
11979 The variable @code{$_} is automatically set by the @code{x} command to
11980 the last address examined (@pxref{Memory, ,Examining Memory}). Other
11981 commands which provide a default address for @code{x} to examine also
11982 set @code{$_} to that address; these commands include @code{info line}
11983 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11984 except when set by the @code{x} command, in which case it is a pointer
11985 to the type of @code{$__}.
11986
11987 @vindex $__@r{, convenience variable}
11988 @item $__
11989 The variable @code{$__} is automatically set by the @code{x} command
11990 to the value found in the last address examined. Its type is chosen
11991 to match the format in which the data was printed.
11992
11993 @item $_exitcode
11994 @vindex $_exitcode@r{, convenience variable}
11995 When the program being debugged terminates normally, @value{GDBN}
11996 automatically sets this variable to the exit code of the program, and
11997 resets @code{$_exitsignal} to @code{void}.
11998
11999 @item $_exitsignal
12000 @vindex $_exitsignal@r{, convenience variable}
12001 When the program being debugged dies due to an uncaught signal,
12002 @value{GDBN} automatically sets this variable to that signal's number,
12003 and resets @code{$_exitcode} to @code{void}.
12004
12005 To distinguish between whether the program being debugged has exited
12006 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12007 @code{$_exitsignal} is not @code{void}), the convenience function
12008 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12009 Functions}). For example, considering the following source code:
12010
12011 @smallexample
12012 #include <signal.h>
12013
12014 int
12015 main (int argc, char *argv[])
12016 @{
12017 raise (SIGALRM);
12018 return 0;
12019 @}
12020 @end smallexample
12021
12022 A valid way of telling whether the program being debugged has exited
12023 or signalled would be:
12024
12025 @smallexample
12026 (@value{GDBP}) define has_exited_or_signalled
12027 Type commands for definition of ``has_exited_or_signalled''.
12028 End with a line saying just ``end''.
12029 >if $_isvoid ($_exitsignal)
12030 >echo The program has exited\n
12031 >else
12032 >echo The program has signalled\n
12033 >end
12034 >end
12035 (@value{GDBP}) run
12036 Starting program:
12037
12038 Program terminated with signal SIGALRM, Alarm clock.
12039 The program no longer exists.
12040 (@value{GDBP}) has_exited_or_signalled
12041 The program has signalled
12042 @end smallexample
12043
12044 As can be seen, @value{GDBN} correctly informs that the program being
12045 debugged has signalled, since it calls @code{raise} and raises a
12046 @code{SIGALRM} signal. If the program being debugged had not called
12047 @code{raise}, then @value{GDBN} would report a normal exit:
12048
12049 @smallexample
12050 (@value{GDBP}) has_exited_or_signalled
12051 The program has exited
12052 @end smallexample
12053
12054 @item $_exception
12055 The variable @code{$_exception} is set to the exception object being
12056 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12057
12058 @item $_ada_exception
12059 The variable @code{$_ada_exception} is set to the address of the
12060 exception being caught or thrown at an Ada exception-related
12061 catchpoint. @xref{Set Catchpoints}.
12062
12063 @item $_probe_argc
12064 @itemx $_probe_arg0@dots{}$_probe_arg11
12065 Arguments to a static probe. @xref{Static Probe Points}.
12066
12067 @item $_sdata
12068 @vindex $_sdata@r{, inspect, convenience variable}
12069 The variable @code{$_sdata} contains extra collected static tracepoint
12070 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12071 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12072 if extra static tracepoint data has not been collected.
12073
12074 @item $_siginfo
12075 @vindex $_siginfo@r{, convenience variable}
12076 The variable @code{$_siginfo} contains extra signal information
12077 (@pxref{extra signal information}). Note that @code{$_siginfo}
12078 could be empty, if the application has not yet received any signals.
12079 For example, it will be empty before you execute the @code{run} command.
12080
12081 @item $_tlb
12082 @vindex $_tlb@r{, convenience variable}
12083 The variable @code{$_tlb} is automatically set when debugging
12084 applications running on MS-Windows in native mode or connected to
12085 gdbserver that supports the @code{qGetTIBAddr} request.
12086 @xref{General Query Packets}.
12087 This variable contains the address of the thread information block.
12088
12089 @item $_inferior
12090 The number of the current inferior. @xref{Inferiors Connections and
12091 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12092
12093 @item $_thread
12094 The thread number of the current thread. @xref{thread numbers}.
12095
12096 @item $_gthread
12097 The global number of the current thread. @xref{global thread numbers}.
12098
12099 @item $_gdb_major
12100 @itemx $_gdb_minor
12101 @vindex $_gdb_major@r{, convenience variable}
12102 @vindex $_gdb_minor@r{, convenience variable}
12103 The major and minor version numbers of the running @value{GDBN}.
12104 Development snapshots and pretest versions have their minor version
12105 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12106 the value 12 for @code{$_gdb_minor}. These variables allow you to
12107 write scripts that work with different versions of @value{GDBN}
12108 without errors caused by features unavailable in some of those
12109 versions.
12110
12111 @item $_shell_exitcode
12112 @itemx $_shell_exitsignal
12113 @vindex $_shell_exitcode@r{, convenience variable}
12114 @vindex $_shell_exitsignal@r{, convenience variable}
12115 @cindex shell command, exit code
12116 @cindex shell command, exit signal
12117 @cindex exit status of shell commands
12118 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12119 shell commands. When a launched command terminates, @value{GDBN}
12120 automatically maintains the variables @code{$_shell_exitcode}
12121 and @code{$_shell_exitsignal} according to the exit status of the last
12122 launched command. These variables are set and used similarly to
12123 the variables @code{$_exitcode} and @code{$_exitsignal}.
12124
12125 @end table
12126
12127 @node Convenience Funs
12128 @section Convenience Functions
12129
12130 @cindex convenience functions
12131 @value{GDBN} also supplies some @dfn{convenience functions}. These
12132 have a syntax similar to convenience variables. A convenience
12133 function can be used in an expression just like an ordinary function;
12134 however, a convenience function is implemented internally to
12135 @value{GDBN}.
12136
12137 These functions do not require @value{GDBN} to be configured with
12138 @code{Python} support, which means that they are always available.
12139
12140 @table @code
12141
12142 @item $_isvoid (@var{expr})
12143 @findex $_isvoid@r{, convenience function}
12144 Return one if the expression @var{expr} is @code{void}. Otherwise it
12145 returns zero.
12146
12147 A @code{void} expression is an expression where the type of the result
12148 is @code{void}. For example, you can examine a convenience variable
12149 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12150 it is @code{void}:
12151
12152 @smallexample
12153 (@value{GDBP}) print $_exitcode
12154 $1 = void
12155 (@value{GDBP}) print $_isvoid ($_exitcode)
12156 $2 = 1
12157 (@value{GDBP}) run
12158 Starting program: ./a.out
12159 [Inferior 1 (process 29572) exited normally]
12160 (@value{GDBP}) print $_exitcode
12161 $3 = 0
12162 (@value{GDBP}) print $_isvoid ($_exitcode)
12163 $4 = 0
12164 @end smallexample
12165
12166 In the example above, we used @code{$_isvoid} to check whether
12167 @code{$_exitcode} is @code{void} before and after the execution of the
12168 program being debugged. Before the execution there is no exit code to
12169 be examined, therefore @code{$_exitcode} is @code{void}. After the
12170 execution the program being debugged returned zero, therefore
12171 @code{$_exitcode} is zero, which means that it is not @code{void}
12172 anymore.
12173
12174 The @code{void} expression can also be a call of a function from the
12175 program being debugged. For example, given the following function:
12176
12177 @smallexample
12178 void
12179 foo (void)
12180 @{
12181 @}
12182 @end smallexample
12183
12184 The result of calling it inside @value{GDBN} is @code{void}:
12185
12186 @smallexample
12187 (@value{GDBP}) print foo ()
12188 $1 = void
12189 (@value{GDBP}) print $_isvoid (foo ())
12190 $2 = 1
12191 (@value{GDBP}) set $v = foo ()
12192 (@value{GDBP}) print $v
12193 $3 = void
12194 (@value{GDBP}) print $_isvoid ($v)
12195 $4 = 1
12196 @end smallexample
12197
12198 @item $_gdb_setting_str (@var{setting})
12199 @findex $_gdb_setting_str@r{, convenience function}
12200 Return the value of the @value{GDBN} @var{setting} as a string.
12201 @var{setting} is any setting that can be used in a @code{set} or
12202 @code{show} command (@pxref{Controlling GDB}).
12203
12204 @smallexample
12205 (@value{GDBP}) show print frame-arguments
12206 Printing of non-scalar frame arguments is "scalars".
12207 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12208 $1 = "scalars"
12209 (@value{GDBP}) p $_gdb_setting_str("height")
12210 $2 = "30"
12211 (@value{GDBP})
12212 @end smallexample
12213
12214 @item $_gdb_setting (@var{setting})
12215 @findex $_gdb_setting@r{, convenience function}
12216 Return the value of the @value{GDBN} @var{setting}.
12217 The type of the returned value depends on the setting.
12218
12219 The value type for boolean and auto boolean settings is @code{int}.
12220 The boolean values @code{off} and @code{on} are converted to
12221 the integer values @code{0} and @code{1}. The value @code{auto} is
12222 converted to the value @code{-1}.
12223
12224 The value type for integer settings is either @code{unsigned int}
12225 or @code{int}, depending on the setting.
12226
12227 Some integer settings accept an @code{unlimited} value.
12228 Depending on the setting, the @code{set} command also accepts
12229 the value @code{0} or the value @code{@minus{}1} as a synonym for
12230 @code{unlimited}.
12231 For example, @code{set height unlimited} is equivalent to
12232 @code{set height 0}.
12233
12234 Some other settings that accept the @code{unlimited} value
12235 use the value @code{0} to literally mean zero.
12236 For example, @code{set history size 0} indicates to not
12237 record any @value{GDBN} commands in the command history.
12238 For such settings, @code{@minus{}1} is the synonym
12239 for @code{unlimited}.
12240
12241 See the documentation of the corresponding @code{set} command for
12242 the numerical value equivalent to @code{unlimited}.
12243
12244 The @code{$_gdb_setting} function converts the unlimited value
12245 to a @code{0} or a @code{@minus{}1} value according to what the
12246 @code{set} command uses.
12247
12248 @smallexample
12249 @group
12250 (@value{GDBP}) p $_gdb_setting_str("height")
12251 $1 = "30"
12252 (@value{GDBP}) p $_gdb_setting("height")
12253 $2 = 30
12254 (@value{GDBP}) set height unlimited
12255 (@value{GDBP}) p $_gdb_setting_str("height")
12256 $3 = "unlimited"
12257 (@value{GDBP}) p $_gdb_setting("height")
12258 $4 = 0
12259 @end group
12260 @group
12261 (@value{GDBP}) p $_gdb_setting_str("history size")
12262 $5 = "unlimited"
12263 (@value{GDBP}) p $_gdb_setting("history size")
12264 $6 = -1
12265 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12266 $7 = "auto"
12267 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12268 $8 = -1
12269 (@value{GDBP})
12270 @end group
12271 @end smallexample
12272
12273 Other setting types (enum, filename, optional filename, string, string noescape)
12274 are returned as string values.
12275
12276
12277 @item $_gdb_maint_setting_str (@var{setting})
12278 @findex $_gdb_maint_setting_str@r{, convenience function}
12279 Like the @code{$_gdb_setting_str} function, but works with
12280 @code{maintenance set} variables.
12281
12282 @item $_gdb_maint_setting (@var{setting})
12283 @findex $_gdb_maint_setting@r{, convenience function}
12284 Like the @code{$_gdb_setting} function, but works with
12285 @code{maintenance set} variables.
12286
12287 @end table
12288
12289 The following functions require @value{GDBN} to be configured with
12290 @code{Python} support.
12291
12292 @table @code
12293
12294 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12295 @findex $_memeq@r{, convenience function}
12296 Returns one if the @var{length} bytes at the addresses given by
12297 @var{buf1} and @var{buf2} are equal.
12298 Otherwise it returns zero.
12299
12300 @item $_regex(@var{str}, @var{regex})
12301 @findex $_regex@r{, convenience function}
12302 Returns one if the string @var{str} matches the regular expression
12303 @var{regex}. Otherwise it returns zero.
12304 The syntax of the regular expression is that specified by @code{Python}'s
12305 regular expression support.
12306
12307 @item $_streq(@var{str1}, @var{str2})
12308 @findex $_streq@r{, convenience function}
12309 Returns one if the strings @var{str1} and @var{str2} are equal.
12310 Otherwise it returns zero.
12311
12312 @item $_strlen(@var{str})
12313 @findex $_strlen@r{, convenience function}
12314 Returns the length of string @var{str}.
12315
12316 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12317 @findex $_caller_is@r{, convenience function}
12318 Returns one if the calling function's name is equal to @var{name}.
12319 Otherwise it returns zero.
12320
12321 If the optional argument @var{number_of_frames} is provided,
12322 it is the number of frames up in the stack to look.
12323 The default is 1.
12324
12325 Example:
12326
12327 @smallexample
12328 (gdb) backtrace
12329 #0 bottom_func ()
12330 at testsuite/gdb.python/py-caller-is.c:21
12331 #1 0x00000000004005a0 in middle_func ()
12332 at testsuite/gdb.python/py-caller-is.c:27
12333 #2 0x00000000004005ab in top_func ()
12334 at testsuite/gdb.python/py-caller-is.c:33
12335 #3 0x00000000004005b6 in main ()
12336 at testsuite/gdb.python/py-caller-is.c:39
12337 (gdb) print $_caller_is ("middle_func")
12338 $1 = 1
12339 (gdb) print $_caller_is ("top_func", 2)
12340 $1 = 1
12341 @end smallexample
12342
12343 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12344 @findex $_caller_matches@r{, convenience function}
12345 Returns one if the calling function's name matches the regular expression
12346 @var{regexp}. Otherwise it returns zero.
12347
12348 If the optional argument @var{number_of_frames} is provided,
12349 it is the number of frames up in the stack to look.
12350 The default is 1.
12351
12352 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12353 @findex $_any_caller_is@r{, convenience function}
12354 Returns one if any calling function's name is equal to @var{name}.
12355 Otherwise it returns zero.
12356
12357 If the optional argument @var{number_of_frames} is provided,
12358 it is the number of frames up in the stack to look.
12359 The default is 1.
12360
12361 This function differs from @code{$_caller_is} in that this function
12362 checks all stack frames from the immediate caller to the frame specified
12363 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12364 frame specified by @var{number_of_frames}.
12365
12366 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12367 @findex $_any_caller_matches@r{, convenience function}
12368 Returns one if any calling function's name matches the regular expression
12369 @var{regexp}. Otherwise it returns zero.
12370
12371 If the optional argument @var{number_of_frames} is provided,
12372 it is the number of frames up in the stack to look.
12373 The default is 1.
12374
12375 This function differs from @code{$_caller_matches} in that this function
12376 checks all stack frames from the immediate caller to the frame specified
12377 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12378 frame specified by @var{number_of_frames}.
12379
12380 @item $_as_string(@var{value})
12381 @findex $_as_string@r{, convenience function}
12382 Return the string representation of @var{value}.
12383
12384 This function is useful to obtain the textual label (enumerator) of an
12385 enumeration value. For example, assuming the variable @var{node} is of
12386 an enumerated type:
12387
12388 @smallexample
12389 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12390 Visiting node of type NODE_INTEGER
12391 @end smallexample
12392
12393 @item $_cimag(@var{value})
12394 @itemx $_creal(@var{value})
12395 @findex $_cimag@r{, convenience function}
12396 @findex $_creal@r{, convenience function}
12397 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12398 the complex number @var{value}.
12399
12400 The type of the imaginary or real part depends on the type of the
12401 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12402 will return an imaginary part of type @code{float}.
12403
12404 @end table
12405
12406 @value{GDBN} provides the ability to list and get help on
12407 convenience functions.
12408
12409 @table @code
12410 @item help function
12411 @kindex help function
12412 @cindex show all convenience functions
12413 Print a list of all convenience functions.
12414 @end table
12415
12416 @node Registers
12417 @section Registers
12418
12419 @cindex registers
12420 You can refer to machine register contents, in expressions, as variables
12421 with names starting with @samp{$}. The names of registers are different
12422 for each machine; use @code{info registers} to see the names used on
12423 your machine.
12424
12425 @table @code
12426 @kindex info registers
12427 @item info registers
12428 Print the names and values of all registers except floating-point
12429 and vector registers (in the selected stack frame).
12430
12431 @kindex info all-registers
12432 @cindex floating point registers
12433 @item info all-registers
12434 Print the names and values of all registers, including floating-point
12435 and vector registers (in the selected stack frame).
12436
12437 @item info registers @var{reggroup} @dots{}
12438 Print the name and value of the registers in each of the specified
12439 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12440 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12441
12442 @item info registers @var{regname} @dots{}
12443 Print the @dfn{relativized} value of each specified register @var{regname}.
12444 As discussed in detail below, register values are normally relative to
12445 the selected stack frame. The @var{regname} may be any register name valid on
12446 the machine you are using, with or without the initial @samp{$}.
12447 @end table
12448
12449 @anchor{standard registers}
12450 @cindex stack pointer register
12451 @cindex program counter register
12452 @cindex process status register
12453 @cindex frame pointer register
12454 @cindex standard registers
12455 @value{GDBN} has four ``standard'' register names that are available (in
12456 expressions) on most machines---whenever they do not conflict with an
12457 architecture's canonical mnemonics for registers. The register names
12458 @code{$pc} and @code{$sp} are used for the program counter register and
12459 the stack pointer. @code{$fp} is used for a register that contains a
12460 pointer to the current stack frame, and @code{$ps} is used for a
12461 register that contains the processor status. For example,
12462 you could print the program counter in hex with
12463
12464 @smallexample
12465 p/x $pc
12466 @end smallexample
12467
12468 @noindent
12469 or print the instruction to be executed next with
12470
12471 @smallexample
12472 x/i $pc
12473 @end smallexample
12474
12475 @noindent
12476 or add four to the stack pointer@footnote{This is a way of removing
12477 one word from the stack, on machines where stacks grow downward in
12478 memory (most machines, nowadays). This assumes that the innermost
12479 stack frame is selected; setting @code{$sp} is not allowed when other
12480 stack frames are selected. To pop entire frames off the stack,
12481 regardless of machine architecture, use @code{return};
12482 see @ref{Returning, ,Returning from a Function}.} with
12483
12484 @smallexample
12485 set $sp += 4
12486 @end smallexample
12487
12488 Whenever possible, these four standard register names are available on
12489 your machine even though the machine has different canonical mnemonics,
12490 so long as there is no conflict. The @code{info registers} command
12491 shows the canonical names. For example, on the SPARC, @code{info
12492 registers} displays the processor status register as @code{$psr} but you
12493 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12494 is an alias for the @sc{eflags} register.
12495
12496 @value{GDBN} always considers the contents of an ordinary register as an
12497 integer when the register is examined in this way. Some machines have
12498 special registers which can hold nothing but floating point; these
12499 registers are considered to have floating point values. There is no way
12500 to refer to the contents of an ordinary register as floating point value
12501 (although you can @emph{print} it as a floating point value with
12502 @samp{print/f $@var{regname}}).
12503
12504 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12505 means that the data format in which the register contents are saved by
12506 the operating system is not the same one that your program normally
12507 sees. For example, the registers of the 68881 floating point
12508 coprocessor are always saved in ``extended'' (raw) format, but all C
12509 programs expect to work with ``double'' (virtual) format. In such
12510 cases, @value{GDBN} normally works with the virtual format only (the format
12511 that makes sense for your program), but the @code{info registers} command
12512 prints the data in both formats.
12513
12514 @cindex SSE registers (x86)
12515 @cindex MMX registers (x86)
12516 Some machines have special registers whose contents can be interpreted
12517 in several different ways. For example, modern x86-based machines
12518 have SSE and MMX registers that can hold several values packed
12519 together in several different formats. @value{GDBN} refers to such
12520 registers in @code{struct} notation:
12521
12522 @smallexample
12523 (@value{GDBP}) print $xmm1
12524 $1 = @{
12525 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12526 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12527 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12528 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12529 v4_int32 = @{0, 20657912, 11, 13@},
12530 v2_int64 = @{88725056443645952, 55834574859@},
12531 uint128 = 0x0000000d0000000b013b36f800000000
12532 @}
12533 @end smallexample
12534
12535 @noindent
12536 To set values of such registers, you need to tell @value{GDBN} which
12537 view of the register you wish to change, as if you were assigning
12538 value to a @code{struct} member:
12539
12540 @smallexample
12541 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12542 @end smallexample
12543
12544 Normally, register values are relative to the selected stack frame
12545 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12546 value that the register would contain if all stack frames farther in
12547 were exited and their saved registers restored. In order to see the
12548 true contents of hardware registers, you must select the innermost
12549 frame (with @samp{frame 0}).
12550
12551 @cindex caller-saved registers
12552 @cindex call-clobbered registers
12553 @cindex volatile registers
12554 @cindex <not saved> values
12555 Usually ABIs reserve some registers as not needed to be saved by the
12556 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12557 registers). It may therefore not be possible for @value{GDBN} to know
12558 the value a register had before the call (in other words, in the outer
12559 frame), if the register value has since been changed by the callee.
12560 @value{GDBN} tries to deduce where the inner frame saved
12561 (``callee-saved'') registers, from the debug info, unwind info, or the
12562 machine code generated by your compiler. If some register is not
12563 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12564 its own knowledge of the ABI, or because the debug/unwind info
12565 explicitly says the register's value is undefined), @value{GDBN}
12566 displays @w{@samp{<not saved>}} as the register's value. With targets
12567 that @value{GDBN} has no knowledge of the register saving convention,
12568 if a register was not saved by the callee, then its value and location
12569 in the outer frame are assumed to be the same of the inner frame.
12570 This is usually harmless, because if the register is call-clobbered,
12571 the caller either does not care what is in the register after the
12572 call, or has code to restore the value that it does care about. Note,
12573 however, that if you change such a register in the outer frame, you
12574 may also be affecting the inner frame. Also, the more ``outer'' the
12575 frame is you're looking at, the more likely a call-clobbered
12576 register's value is to be wrong, in the sense that it doesn't actually
12577 represent the value the register had just before the call.
12578
12579 @node Floating Point Hardware
12580 @section Floating Point Hardware
12581 @cindex floating point
12582
12583 Depending on the configuration, @value{GDBN} may be able to give
12584 you more information about the status of the floating point hardware.
12585
12586 @table @code
12587 @kindex info float
12588 @item info float
12589 Display hardware-dependent information about the floating
12590 point unit. The exact contents and layout vary depending on the
12591 floating point chip. Currently, @samp{info float} is supported on
12592 the ARM and x86 machines.
12593 @end table
12594
12595 @node Vector Unit
12596 @section Vector Unit
12597 @cindex vector unit
12598
12599 Depending on the configuration, @value{GDBN} may be able to give you
12600 more information about the status of the vector unit.
12601
12602 @table @code
12603 @kindex info vector
12604 @item info vector
12605 Display information about the vector unit. The exact contents and
12606 layout vary depending on the hardware.
12607 @end table
12608
12609 @node OS Information
12610 @section Operating System Auxiliary Information
12611 @cindex OS information
12612
12613 @value{GDBN} provides interfaces to useful OS facilities that can help
12614 you debug your program.
12615
12616 @cindex auxiliary vector
12617 @cindex vector, auxiliary
12618 Some operating systems supply an @dfn{auxiliary vector} to programs at
12619 startup. This is akin to the arguments and environment that you
12620 specify for a program, but contains a system-dependent variety of
12621 binary values that tell system libraries important details about the
12622 hardware, operating system, and process. Each value's purpose is
12623 identified by an integer tag; the meanings are well-known but system-specific.
12624 Depending on the configuration and operating system facilities,
12625 @value{GDBN} may be able to show you this information. For remote
12626 targets, this functionality may further depend on the remote stub's
12627 support of the @samp{qXfer:auxv:read} packet, see
12628 @ref{qXfer auxiliary vector read}.
12629
12630 @table @code
12631 @kindex info auxv
12632 @item info auxv
12633 Display the auxiliary vector of the inferior, which can be either a
12634 live process or a core dump file. @value{GDBN} prints each tag value
12635 numerically, and also shows names and text descriptions for recognized
12636 tags. Some values in the vector are numbers, some bit masks, and some
12637 pointers to strings or other data. @value{GDBN} displays each value in the
12638 most appropriate form for a recognized tag, and in hexadecimal for
12639 an unrecognized tag.
12640 @end table
12641
12642 On some targets, @value{GDBN} can access operating system-specific
12643 information and show it to you. The types of information available
12644 will differ depending on the type of operating system running on the
12645 target. The mechanism used to fetch the data is described in
12646 @ref{Operating System Information}. For remote targets, this
12647 functionality depends on the remote stub's support of the
12648 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12649
12650 @table @code
12651 @kindex info os
12652 @item info os @var{infotype}
12653
12654 Display OS information of the requested type.
12655
12656 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12657
12658 @anchor{linux info os infotypes}
12659 @table @code
12660 @kindex info os cpus
12661 @item cpus
12662 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12663 the available fields from /proc/cpuinfo. For each supported architecture
12664 different fields are available. Two common entries are processor which gives
12665 CPU number and bogomips; a system constant that is calculated during
12666 kernel initialization.
12667
12668 @kindex info os files
12669 @item files
12670 Display the list of open file descriptors on the target. For each
12671 file descriptor, @value{GDBN} prints the identifier of the process
12672 owning the descriptor, the command of the owning process, the value
12673 of the descriptor, and the target of the descriptor.
12674
12675 @kindex info os modules
12676 @item modules
12677 Display the list of all loaded kernel modules on the target. For each
12678 module, @value{GDBN} prints the module name, the size of the module in
12679 bytes, the number of times the module is used, the dependencies of the
12680 module, the status of the module, and the address of the loaded module
12681 in memory.
12682
12683 @kindex info os msg
12684 @item msg
12685 Display the list of all System V message queues on the target. For each
12686 message queue, @value{GDBN} prints the message queue key, the message
12687 queue identifier, the access permissions, the current number of bytes
12688 on the queue, the current number of messages on the queue, the processes
12689 that last sent and received a message on the queue, the user and group
12690 of the owner and creator of the message queue, the times at which a
12691 message was last sent and received on the queue, and the time at which
12692 the message queue was last changed.
12693
12694 @kindex info os processes
12695 @item processes
12696 Display the list of processes on the target. For each process,
12697 @value{GDBN} prints the process identifier, the name of the user, the
12698 command corresponding to the process, and the list of processor cores
12699 that the process is currently running on. (To understand what these
12700 properties mean, for this and the following info types, please consult
12701 the general @sc{gnu}/Linux documentation.)
12702
12703 @kindex info os procgroups
12704 @item procgroups
12705 Display the list of process groups on the target. For each process,
12706 @value{GDBN} prints the identifier of the process group that it belongs
12707 to, the command corresponding to the process group leader, the process
12708 identifier, and the command line of the process. The list is sorted
12709 first by the process group identifier, then by the process identifier,
12710 so that processes belonging to the same process group are grouped together
12711 and the process group leader is listed first.
12712
12713 @kindex info os semaphores
12714 @item semaphores
12715 Display the list of all System V semaphore sets on the target. For each
12716 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12717 set identifier, the access permissions, the number of semaphores in the
12718 set, the user and group of the owner and creator of the semaphore set,
12719 and the times at which the semaphore set was operated upon and changed.
12720
12721 @kindex info os shm
12722 @item shm
12723 Display the list of all System V shared-memory regions on the target.
12724 For each shared-memory region, @value{GDBN} prints the region key,
12725 the shared-memory identifier, the access permissions, the size of the
12726 region, the process that created the region, the process that last
12727 attached to or detached from the region, the current number of live
12728 attaches to the region, and the times at which the region was last
12729 attached to, detach from, and changed.
12730
12731 @kindex info os sockets
12732 @item sockets
12733 Display the list of Internet-domain sockets on the target. For each
12734 socket, @value{GDBN} prints the address and port of the local and
12735 remote endpoints, the current state of the connection, the creator of
12736 the socket, the IP address family of the socket, and the type of the
12737 connection.
12738
12739 @kindex info os threads
12740 @item threads
12741 Display the list of threads running on the target. For each thread,
12742 @value{GDBN} prints the identifier of the process that the thread
12743 belongs to, the command of the process, the thread identifier, and the
12744 processor core that it is currently running on. The main thread of a
12745 process is not listed.
12746 @end table
12747
12748 @item info os
12749 If @var{infotype} is omitted, then list the possible values for
12750 @var{infotype} and the kind of OS information available for each
12751 @var{infotype}. If the target does not return a list of possible
12752 types, this command will report an error.
12753 @end table
12754
12755 @node Memory Region Attributes
12756 @section Memory Region Attributes
12757 @cindex memory region attributes
12758
12759 @dfn{Memory region attributes} allow you to describe special handling
12760 required by regions of your target's memory. @value{GDBN} uses
12761 attributes to determine whether to allow certain types of memory
12762 accesses; whether to use specific width accesses; and whether to cache
12763 target memory. By default the description of memory regions is
12764 fetched from the target (if the current target supports this), but the
12765 user can override the fetched regions.
12766
12767 Defined memory regions can be individually enabled and disabled. When a
12768 memory region is disabled, @value{GDBN} uses the default attributes when
12769 accessing memory in that region. Similarly, if no memory regions have
12770 been defined, @value{GDBN} uses the default attributes when accessing
12771 all memory.
12772
12773 When a memory region is defined, it is given a number to identify it;
12774 to enable, disable, or remove a memory region, you specify that number.
12775
12776 @table @code
12777 @kindex mem
12778 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
12779 Define a memory region bounded by @var{lower} and @var{upper} with
12780 attributes @var{attributes}@dots{}, and add it to the list of regions
12781 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
12782 case: it is treated as the target's maximum memory address.
12783 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
12784
12785 @item mem auto
12786 Discard any user changes to the memory regions and use target-supplied
12787 regions, if available, or no regions if the target does not support.
12788
12789 @kindex delete mem
12790 @item delete mem @var{nums}@dots{}
12791 Remove memory regions @var{nums}@dots{} from the list of regions
12792 monitored by @value{GDBN}.
12793
12794 @kindex disable mem
12795 @item disable mem @var{nums}@dots{}
12796 Disable monitoring of memory regions @var{nums}@dots{}.
12797 A disabled memory region is not forgotten.
12798 It may be enabled again later.
12799
12800 @kindex enable mem
12801 @item enable mem @var{nums}@dots{}
12802 Enable monitoring of memory regions @var{nums}@dots{}.
12803
12804 @kindex info mem
12805 @item info mem
12806 Print a table of all defined memory regions, with the following columns
12807 for each region:
12808
12809 @table @emph
12810 @item Memory Region Number
12811 @item Enabled or Disabled.
12812 Enabled memory regions are marked with @samp{y}.
12813 Disabled memory regions are marked with @samp{n}.
12814
12815 @item Lo Address
12816 The address defining the inclusive lower bound of the memory region.
12817
12818 @item Hi Address
12819 The address defining the exclusive upper bound of the memory region.
12820
12821 @item Attributes
12822 The list of attributes set for this memory region.
12823 @end table
12824 @end table
12825
12826
12827 @subsection Attributes
12828
12829 @subsubsection Memory Access Mode
12830 The access mode attributes set whether @value{GDBN} may make read or
12831 write accesses to a memory region.
12832
12833 While these attributes prevent @value{GDBN} from performing invalid
12834 memory accesses, they do nothing to prevent the target system, I/O DMA,
12835 etc.@: from accessing memory.
12836
12837 @table @code
12838 @item ro
12839 Memory is read only.
12840 @item wo
12841 Memory is write only.
12842 @item rw
12843 Memory is read/write. This is the default.
12844 @end table
12845
12846 @subsubsection Memory Access Size
12847 The access size attribute tells @value{GDBN} to use specific sized
12848 accesses in the memory region. Often memory mapped device registers
12849 require specific sized accesses. If no access size attribute is
12850 specified, @value{GDBN} may use accesses of any size.
12851
12852 @table @code
12853 @item 8
12854 Use 8 bit memory accesses.
12855 @item 16
12856 Use 16 bit memory accesses.
12857 @item 32
12858 Use 32 bit memory accesses.
12859 @item 64
12860 Use 64 bit memory accesses.
12861 @end table
12862
12863 @c @subsubsection Hardware/Software Breakpoints
12864 @c The hardware/software breakpoint attributes set whether @value{GDBN}
12865 @c will use hardware or software breakpoints for the internal breakpoints
12866 @c used by the step, next, finish, until, etc. commands.
12867 @c
12868 @c @table @code
12869 @c @item hwbreak
12870 @c Always use hardware breakpoints
12871 @c @item swbreak (default)
12872 @c @end table
12873
12874 @subsubsection Data Cache
12875 The data cache attributes set whether @value{GDBN} will cache target
12876 memory. While this generally improves performance by reducing debug
12877 protocol overhead, it can lead to incorrect results because @value{GDBN}
12878 does not know about volatile variables or memory mapped device
12879 registers.
12880
12881 @table @code
12882 @item cache
12883 Enable @value{GDBN} to cache target memory.
12884 @item nocache
12885 Disable @value{GDBN} from caching target memory. This is the default.
12886 @end table
12887
12888 @subsection Memory Access Checking
12889 @value{GDBN} can be instructed to refuse accesses to memory that is
12890 not explicitly described. This can be useful if accessing such
12891 regions has undesired effects for a specific target, or to provide
12892 better error checking. The following commands control this behaviour.
12893
12894 @table @code
12895 @kindex set mem inaccessible-by-default
12896 @item set mem inaccessible-by-default [on|off]
12897 If @code{on} is specified, make @value{GDBN} treat memory not
12898 explicitly described by the memory ranges as non-existent and refuse accesses
12899 to such memory. The checks are only performed if there's at least one
12900 memory range defined. If @code{off} is specified, make @value{GDBN}
12901 treat the memory not explicitly described by the memory ranges as RAM.
12902 The default value is @code{on}.
12903 @kindex show mem inaccessible-by-default
12904 @item show mem inaccessible-by-default
12905 Show the current handling of accesses to unknown memory.
12906 @end table
12907
12908
12909 @c @subsubsection Memory Write Verification
12910 @c The memory write verification attributes set whether @value{GDBN}
12911 @c will re-reads data after each write to verify the write was successful.
12912 @c
12913 @c @table @code
12914 @c @item verify
12915 @c @item noverify (default)
12916 @c @end table
12917
12918 @node Dump/Restore Files
12919 @section Copy Between Memory and a File
12920 @cindex dump/restore files
12921 @cindex append data to a file
12922 @cindex dump data to a file
12923 @cindex restore data from a file
12924
12925 You can use the commands @code{dump}, @code{append}, and
12926 @code{restore} to copy data between target memory and a file. The
12927 @code{dump} and @code{append} commands write data to a file, and the
12928 @code{restore} command reads data from a file back into the inferior's
12929 memory. Files may be in binary, Motorola S-record, Intel hex,
12930 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12931 append to binary files, and cannot read from Verilog Hex files.
12932
12933 @table @code
12934
12935 @kindex dump
12936 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12937 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12938 Dump the contents of memory from @var{start_addr} to @var{end_addr},
12939 or the value of @var{expr}, to @var{filename} in the given format.
12940
12941 The @var{format} parameter may be any one of:
12942 @table @code
12943 @item binary
12944 Raw binary form.
12945 @item ihex
12946 Intel hex format.
12947 @item srec
12948 Motorola S-record format.
12949 @item tekhex
12950 Tektronix Hex format.
12951 @item verilog
12952 Verilog Hex format.
12953 @end table
12954
12955 @value{GDBN} uses the same definitions of these formats as the
12956 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12957 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
12958 form.
12959
12960 @kindex append
12961 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12962 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12963 Append the contents of memory from @var{start_addr} to @var{end_addr},
12964 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
12965 (@value{GDBN} can only append data to files in raw binary form.)
12966
12967 @kindex restore
12968 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12969 Restore the contents of file @var{filename} into memory. The
12970 @code{restore} command can automatically recognize any known @sc{bfd}
12971 file format, except for raw binary. To restore a raw binary file you
12972 must specify the optional keyword @code{binary} after the filename.
12973
12974 If @var{bias} is non-zero, its value will be added to the addresses
12975 contained in the file. Binary files always start at address zero, so
12976 they will be restored at address @var{bias}. Other bfd files have
12977 a built-in location; they will be restored at offset @var{bias}
12978 from that location.
12979
12980 If @var{start} and/or @var{end} are non-zero, then only data between
12981 file offset @var{start} and file offset @var{end} will be restored.
12982 These offsets are relative to the addresses in the file, before
12983 the @var{bias} argument is applied.
12984
12985 @end table
12986
12987 @node Core File Generation
12988 @section How to Produce a Core File from Your Program
12989 @cindex dump core from inferior
12990
12991 A @dfn{core file} or @dfn{core dump} is a file that records the memory
12992 image of a running process and its process status (register values
12993 etc.). Its primary use is post-mortem debugging of a program that
12994 crashed while it ran outside a debugger. A program that crashes
12995 automatically produces a core file, unless this feature is disabled by
12996 the user. @xref{Files}, for information on invoking @value{GDBN} in
12997 the post-mortem debugging mode.
12998
12999 Occasionally, you may wish to produce a core file of the program you
13000 are debugging in order to preserve a snapshot of its state.
13001 @value{GDBN} has a special command for that.
13002
13003 @table @code
13004 @kindex gcore
13005 @kindex generate-core-file
13006 @item generate-core-file [@var{file}]
13007 @itemx gcore [@var{file}]
13008 Produce a core dump of the inferior process. The optional argument
13009 @var{file} specifies the file name where to put the core dump. If not
13010 specified, the file name defaults to @file{core.@var{pid}}, where
13011 @var{pid} is the inferior process ID.
13012
13013 Note that this command is implemented only for some systems (as of
13014 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13015
13016 On @sc{gnu}/Linux, this command can take into account the value of the
13017 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13018 dump (@pxref{set use-coredump-filter}), and by default honors the
13019 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13020 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13021
13022 @kindex set use-coredump-filter
13023 @anchor{set use-coredump-filter}
13024 @item set use-coredump-filter on
13025 @itemx set use-coredump-filter off
13026 Enable or disable the use of the file
13027 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13028 files. This file is used by the Linux kernel to decide what types of
13029 memory mappings will be dumped or ignored when generating a core dump
13030 file. @var{pid} is the process ID of a currently running process.
13031
13032 To make use of this feature, you have to write in the
13033 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13034 which is a bit mask representing the memory mapping types. If a bit
13035 is set in the bit mask, then the memory mappings of the corresponding
13036 types will be dumped; otherwise, they will be ignored. This
13037 configuration is inherited by child processes. For more information
13038 about the bits that can be set in the
13039 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13040 manpage of @code{core(5)}.
13041
13042 By default, this option is @code{on}. If this option is turned
13043 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13044 and instead uses the same default value as the Linux kernel in order
13045 to decide which pages will be dumped in the core dump file. This
13046 value is currently @code{0x33}, which means that bits @code{0}
13047 (anonymous private mappings), @code{1} (anonymous shared mappings),
13048 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13049 This will cause these memory mappings to be dumped automatically.
13050
13051 @kindex set dump-excluded-mappings
13052 @anchor{set dump-excluded-mappings}
13053 @item set dump-excluded-mappings on
13054 @itemx set dump-excluded-mappings off
13055 If @code{on} is specified, @value{GDBN} will dump memory mappings
13056 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13057 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13058
13059 The default value is @code{off}.
13060 @end table
13061
13062 @node Character Sets
13063 @section Character Sets
13064 @cindex character sets
13065 @cindex charset
13066 @cindex translating between character sets
13067 @cindex host character set
13068 @cindex target character set
13069
13070 If the program you are debugging uses a different character set to
13071 represent characters and strings than the one @value{GDBN} uses itself,
13072 @value{GDBN} can automatically translate between the character sets for
13073 you. The character set @value{GDBN} uses we call the @dfn{host
13074 character set}; the one the inferior program uses we call the
13075 @dfn{target character set}.
13076
13077 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13078 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13079 remote protocol (@pxref{Remote Debugging}) to debug a program
13080 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13081 then the host character set is Latin-1, and the target character set is
13082 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13083 target-charset EBCDIC-US}, then @value{GDBN} translates between
13084 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13085 character and string literals in expressions.
13086
13087 @value{GDBN} has no way to automatically recognize which character set
13088 the inferior program uses; you must tell it, using the @code{set
13089 target-charset} command, described below.
13090
13091 Here are the commands for controlling @value{GDBN}'s character set
13092 support:
13093
13094 @table @code
13095 @item set target-charset @var{charset}
13096 @kindex set target-charset
13097 Set the current target character set to @var{charset}. To display the
13098 list of supported target character sets, type
13099 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13100
13101 @item set host-charset @var{charset}
13102 @kindex set host-charset
13103 Set the current host character set to @var{charset}.
13104
13105 By default, @value{GDBN} uses a host character set appropriate to the
13106 system it is running on; you can override that default using the
13107 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13108 automatically determine the appropriate host character set. In this
13109 case, @value{GDBN} uses @samp{UTF-8}.
13110
13111 @value{GDBN} can only use certain character sets as its host character
13112 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13113 @value{GDBN} will list the host character sets it supports.
13114
13115 @item set charset @var{charset}
13116 @kindex set charset
13117 Set the current host and target character sets to @var{charset}. As
13118 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13119 @value{GDBN} will list the names of the character sets that can be used
13120 for both host and target.
13121
13122 @item show charset
13123 @kindex show charset
13124 Show the names of the current host and target character sets.
13125
13126 @item show host-charset
13127 @kindex show host-charset
13128 Show the name of the current host character set.
13129
13130 @item show target-charset
13131 @kindex show target-charset
13132 Show the name of the current target character set.
13133
13134 @item set target-wide-charset @var{charset}
13135 @kindex set target-wide-charset
13136 Set the current target's wide character set to @var{charset}. This is
13137 the character set used by the target's @code{wchar_t} type. To
13138 display the list of supported wide character sets, type
13139 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13140
13141 @item show target-wide-charset
13142 @kindex show target-wide-charset
13143 Show the name of the current target's wide character set.
13144 @end table
13145
13146 Here is an example of @value{GDBN}'s character set support in action.
13147 Assume that the following source code has been placed in the file
13148 @file{charset-test.c}:
13149
13150 @smallexample
13151 #include <stdio.h>
13152
13153 char ascii_hello[]
13154 = @{72, 101, 108, 108, 111, 44, 32, 119,
13155 111, 114, 108, 100, 33, 10, 0@};
13156 char ibm1047_hello[]
13157 = @{200, 133, 147, 147, 150, 107, 64, 166,
13158 150, 153, 147, 132, 90, 37, 0@};
13159
13160 main ()
13161 @{
13162 printf ("Hello, world!\n");
13163 @}
13164 @end smallexample
13165
13166 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13167 containing the string @samp{Hello, world!} followed by a newline,
13168 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13169
13170 We compile the program, and invoke the debugger on it:
13171
13172 @smallexample
13173 $ gcc -g charset-test.c -o charset-test
13174 $ gdb -nw charset-test
13175 GNU gdb 2001-12-19-cvs
13176 Copyright 2001 Free Software Foundation, Inc.
13177 @dots{}
13178 (@value{GDBP})
13179 @end smallexample
13180
13181 We can use the @code{show charset} command to see what character sets
13182 @value{GDBN} is currently using to interpret and display characters and
13183 strings:
13184
13185 @smallexample
13186 (@value{GDBP}) show charset
13187 The current host and target character set is `ISO-8859-1'.
13188 (@value{GDBP})
13189 @end smallexample
13190
13191 For the sake of printing this manual, let's use @sc{ascii} as our
13192 initial character set:
13193 @smallexample
13194 (@value{GDBP}) set charset ASCII
13195 (@value{GDBP}) show charset
13196 The current host and target character set is `ASCII'.
13197 (@value{GDBP})
13198 @end smallexample
13199
13200 Let's assume that @sc{ascii} is indeed the correct character set for our
13201 host system --- in other words, let's assume that if @value{GDBN} prints
13202 characters using the @sc{ascii} character set, our terminal will display
13203 them properly. Since our current target character set is also
13204 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13205
13206 @smallexample
13207 (@value{GDBP}) print ascii_hello
13208 $1 = 0x401698 "Hello, world!\n"
13209 (@value{GDBP}) print ascii_hello[0]
13210 $2 = 72 'H'
13211 (@value{GDBP})
13212 @end smallexample
13213
13214 @value{GDBN} uses the target character set for character and string
13215 literals you use in expressions:
13216
13217 @smallexample
13218 (@value{GDBP}) print '+'
13219 $3 = 43 '+'
13220 (@value{GDBP})
13221 @end smallexample
13222
13223 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13224 character.
13225
13226 @value{GDBN} relies on the user to tell it which character set the
13227 target program uses. If we print @code{ibm1047_hello} while our target
13228 character set is still @sc{ascii}, we get jibberish:
13229
13230 @smallexample
13231 (@value{GDBP}) print ibm1047_hello
13232 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13233 (@value{GDBP}) print ibm1047_hello[0]
13234 $5 = 200 '\310'
13235 (@value{GDBP})
13236 @end smallexample
13237
13238 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13239 @value{GDBN} tells us the character sets it supports:
13240
13241 @smallexample
13242 (@value{GDBP}) set target-charset
13243 ASCII EBCDIC-US IBM1047 ISO-8859-1
13244 (@value{GDBP}) set target-charset
13245 @end smallexample
13246
13247 We can select @sc{ibm1047} as our target character set, and examine the
13248 program's strings again. Now the @sc{ascii} string is wrong, but
13249 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13250 target character set, @sc{ibm1047}, to the host character set,
13251 @sc{ascii}, and they display correctly:
13252
13253 @smallexample
13254 (@value{GDBP}) set target-charset IBM1047
13255 (@value{GDBP}) show charset
13256 The current host character set is `ASCII'.
13257 The current target character set is `IBM1047'.
13258 (@value{GDBP}) print ascii_hello
13259 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13260 (@value{GDBP}) print ascii_hello[0]
13261 $7 = 72 '\110'
13262 (@value{GDBP}) print ibm1047_hello
13263 $8 = 0x4016a8 "Hello, world!\n"
13264 (@value{GDBP}) print ibm1047_hello[0]
13265 $9 = 200 'H'
13266 (@value{GDBP})
13267 @end smallexample
13268
13269 As above, @value{GDBN} uses the target character set for character and
13270 string literals you use in expressions:
13271
13272 @smallexample
13273 (@value{GDBP}) print '+'
13274 $10 = 78 '+'
13275 (@value{GDBP})
13276 @end smallexample
13277
13278 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13279 character.
13280
13281 @node Caching Target Data
13282 @section Caching Data of Targets
13283 @cindex caching data of targets
13284
13285 @value{GDBN} caches data exchanged between the debugger and a target.
13286 Each cache is associated with the address space of the inferior.
13287 @xref{Inferiors Connections and Programs}, about inferior and address space.
13288 Such caching generally improves performance in remote debugging
13289 (@pxref{Remote Debugging}), because it reduces the overhead of the
13290 remote protocol by bundling memory reads and writes into large chunks.
13291 Unfortunately, simply caching everything would lead to incorrect results,
13292 since @value{GDBN} does not necessarily know anything about volatile
13293 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13294 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13295 is executing.
13296 Therefore, by default, @value{GDBN} only caches data
13297 known to be on the stack@footnote{In non-stop mode, it is moderately
13298 rare for a running thread to modify the stack of a stopped thread
13299 in a way that would interfere with a backtrace, and caching of
13300 stack reads provides a significant speed up of remote backtraces.} or
13301 in the code segment.
13302 Other regions of memory can be explicitly marked as
13303 cacheable; @pxref{Memory Region Attributes}.
13304
13305 @table @code
13306 @kindex set remotecache
13307 @item set remotecache on
13308 @itemx set remotecache off
13309 This option no longer does anything; it exists for compatibility
13310 with old scripts.
13311
13312 @kindex show remotecache
13313 @item show remotecache
13314 Show the current state of the obsolete remotecache flag.
13315
13316 @kindex set stack-cache
13317 @item set stack-cache on
13318 @itemx set stack-cache off
13319 Enable or disable caching of stack accesses. When @code{on}, use
13320 caching. By default, this option is @code{on}.
13321
13322 @kindex show stack-cache
13323 @item show stack-cache
13324 Show the current state of data caching for memory accesses.
13325
13326 @kindex set code-cache
13327 @item set code-cache on
13328 @itemx set code-cache off
13329 Enable or disable caching of code segment accesses. When @code{on},
13330 use caching. By default, this option is @code{on}. This improves
13331 performance of disassembly in remote debugging.
13332
13333 @kindex show code-cache
13334 @item show code-cache
13335 Show the current state of target memory cache for code segment
13336 accesses.
13337
13338 @kindex info dcache
13339 @item info dcache @r{[}line@r{]}
13340 Print the information about the performance of data cache of the
13341 current inferior's address space. The information displayed
13342 includes the dcache width and depth, and for each cache line, its
13343 number, address, and how many times it was referenced. This
13344 command is useful for debugging the data cache operation.
13345
13346 If a line number is specified, the contents of that line will be
13347 printed in hex.
13348
13349 @item set dcache size @var{size}
13350 @cindex dcache size
13351 @kindex set dcache size
13352 Set maximum number of entries in dcache (dcache depth above).
13353
13354 @item set dcache line-size @var{line-size}
13355 @cindex dcache line-size
13356 @kindex set dcache line-size
13357 Set number of bytes each dcache entry caches (dcache width above).
13358 Must be a power of 2.
13359
13360 @item show dcache size
13361 @kindex show dcache size
13362 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13363
13364 @item show dcache line-size
13365 @kindex show dcache line-size
13366 Show default size of dcache lines.
13367
13368 @end table
13369
13370 @node Searching Memory
13371 @section Search Memory
13372 @cindex searching memory
13373
13374 Memory can be searched for a particular sequence of bytes with the
13375 @code{find} command.
13376
13377 @table @code
13378 @kindex find
13379 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13380 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13381 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13382 etc. The search begins at address @var{start_addr} and continues for either
13383 @var{len} bytes or through to @var{end_addr} inclusive.
13384 @end table
13385
13386 @var{s} and @var{n} are optional parameters.
13387 They may be specified in either order, apart or together.
13388
13389 @table @r
13390 @item @var{s}, search query size
13391 The size of each search query value.
13392
13393 @table @code
13394 @item b
13395 bytes
13396 @item h
13397 halfwords (two bytes)
13398 @item w
13399 words (four bytes)
13400 @item g
13401 giant words (eight bytes)
13402 @end table
13403
13404 All values are interpreted in the current language.
13405 This means, for example, that if the current source language is C/C@t{++}
13406 then searching for the string ``hello'' includes the trailing '\0'.
13407 The null terminator can be removed from searching by using casts,
13408 e.g.: @samp{@{char[5]@}"hello"}.
13409
13410 If the value size is not specified, it is taken from the
13411 value's type in the current language.
13412 This is useful when one wants to specify the search
13413 pattern as a mixture of types.
13414 Note that this means, for example, that in the case of C-like languages
13415 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13416 which is typically four bytes.
13417
13418 @item @var{n}, maximum number of finds
13419 The maximum number of matches to print. The default is to print all finds.
13420 @end table
13421
13422 You can use strings as search values. Quote them with double-quotes
13423 (@code{"}).
13424 The string value is copied into the search pattern byte by byte,
13425 regardless of the endianness of the target and the size specification.
13426
13427 The address of each match found is printed as well as a count of the
13428 number of matches found.
13429
13430 The address of the last value found is stored in convenience variable
13431 @samp{$_}.
13432 A count of the number of matches is stored in @samp{$numfound}.
13433
13434 For example, if stopped at the @code{printf} in this function:
13435
13436 @smallexample
13437 void
13438 hello ()
13439 @{
13440 static char hello[] = "hello-hello";
13441 static struct @{ char c; short s; int i; @}
13442 __attribute__ ((packed)) mixed
13443 = @{ 'c', 0x1234, 0x87654321 @};
13444 printf ("%s\n", hello);
13445 @}
13446 @end smallexample
13447
13448 @noindent
13449 you get during debugging:
13450
13451 @smallexample
13452 (gdb) find &hello[0], +sizeof(hello), "hello"
13453 0x804956d <hello.1620+6>
13454 1 pattern found
13455 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13456 0x8049567 <hello.1620>
13457 0x804956d <hello.1620+6>
13458 2 patterns found.
13459 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13460 0x8049567 <hello.1620>
13461 0x804956d <hello.1620+6>
13462 2 patterns found.
13463 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13464 0x8049567 <hello.1620>
13465 1 pattern found
13466 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13467 0x8049560 <mixed.1625>
13468 1 pattern found
13469 (gdb) print $numfound
13470 $1 = 1
13471 (gdb) print $_
13472 $2 = (void *) 0x8049560
13473 @end smallexample
13474
13475 @node Value Sizes
13476 @section Value Sizes
13477
13478 Whenever @value{GDBN} prints a value memory will be allocated within
13479 @value{GDBN} to hold the contents of the value. It is possible in
13480 some languages with dynamic typing systems, that an invalid program
13481 may indicate a value that is incorrectly large, this in turn may cause
13482 @value{GDBN} to try and allocate an overly large amount of memory.
13483
13484 @table @code
13485 @kindex set max-value-size
13486 @item set max-value-size @var{bytes}
13487 @itemx set max-value-size unlimited
13488 Set the maximum size of memory that @value{GDBN} will allocate for the
13489 contents of a value to @var{bytes}, trying to display a value that
13490 requires more memory than that will result in an error.
13491
13492 Setting this variable does not effect values that have already been
13493 allocated within @value{GDBN}, only future allocations.
13494
13495 There's a minimum size that @code{max-value-size} can be set to in
13496 order that @value{GDBN} can still operate correctly, this minimum is
13497 currently 16 bytes.
13498
13499 The limit applies to the results of some subexpressions as well as to
13500 complete expressions. For example, an expression denoting a simple
13501 integer component, such as @code{x.y.z}, may fail if the size of
13502 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13503 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13504 @var{A} is an array variable with non-constant size, will generally
13505 succeed regardless of the bounds on @var{A}, as long as the component
13506 size is less than @var{bytes}.
13507
13508 The default value of @code{max-value-size} is currently 64k.
13509
13510 @kindex show max-value-size
13511 @item show max-value-size
13512 Show the maximum size of memory, in bytes, that @value{GDBN} will
13513 allocate for the contents of a value.
13514 @end table
13515
13516 @node Optimized Code
13517 @chapter Debugging Optimized Code
13518 @cindex optimized code, debugging
13519 @cindex debugging optimized code
13520
13521 Almost all compilers support optimization. With optimization
13522 disabled, the compiler generates assembly code that corresponds
13523 directly to your source code, in a simplistic way. As the compiler
13524 applies more powerful optimizations, the generated assembly code
13525 diverges from your original source code. With help from debugging
13526 information generated by the compiler, @value{GDBN} can map from
13527 the running program back to constructs from your original source.
13528
13529 @value{GDBN} is more accurate with optimization disabled. If you
13530 can recompile without optimization, it is easier to follow the
13531 progress of your program during debugging. But, there are many cases
13532 where you may need to debug an optimized version.
13533
13534 When you debug a program compiled with @samp{-g -O}, remember that the
13535 optimizer has rearranged your code; the debugger shows you what is
13536 really there. Do not be too surprised when the execution path does not
13537 exactly match your source file! An extreme example: if you define a
13538 variable, but never use it, @value{GDBN} never sees that
13539 variable---because the compiler optimizes it out of existence.
13540
13541 Some things do not work as well with @samp{-g -O} as with just
13542 @samp{-g}, particularly on machines with instruction scheduling. If in
13543 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13544 please report it to us as a bug (including a test case!).
13545 @xref{Variables}, for more information about debugging optimized code.
13546
13547 @menu
13548 * Inline Functions:: How @value{GDBN} presents inlining
13549 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13550 @end menu
13551
13552 @node Inline Functions
13553 @section Inline Functions
13554 @cindex inline functions, debugging
13555
13556 @dfn{Inlining} is an optimization that inserts a copy of the function
13557 body directly at each call site, instead of jumping to a shared
13558 routine. @value{GDBN} displays inlined functions just like
13559 non-inlined functions. They appear in backtraces. You can view their
13560 arguments and local variables, step into them with @code{step}, skip
13561 them with @code{next}, and escape from them with @code{finish}.
13562 You can check whether a function was inlined by using the
13563 @code{info frame} command.
13564
13565 For @value{GDBN} to support inlined functions, the compiler must
13566 record information about inlining in the debug information ---
13567 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13568 other compilers do also. @value{GDBN} only supports inlined functions
13569 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13570 do not emit two required attributes (@samp{DW_AT_call_file} and
13571 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13572 function calls with earlier versions of @value{NGCC}. It instead
13573 displays the arguments and local variables of inlined functions as
13574 local variables in the caller.
13575
13576 The body of an inlined function is directly included at its call site;
13577 unlike a non-inlined function, there are no instructions devoted to
13578 the call. @value{GDBN} still pretends that the call site and the
13579 start of the inlined function are different instructions. Stepping to
13580 the call site shows the call site, and then stepping again shows
13581 the first line of the inlined function, even though no additional
13582 instructions are executed.
13583
13584 This makes source-level debugging much clearer; you can see both the
13585 context of the call and then the effect of the call. Only stepping by
13586 a single instruction using @code{stepi} or @code{nexti} does not do
13587 this; single instruction steps always show the inlined body.
13588
13589 There are some ways that @value{GDBN} does not pretend that inlined
13590 function calls are the same as normal calls:
13591
13592 @itemize @bullet
13593 @item
13594 Setting breakpoints at the call site of an inlined function may not
13595 work, because the call site does not contain any code. @value{GDBN}
13596 may incorrectly move the breakpoint to the next line of the enclosing
13597 function, after the call. This limitation will be removed in a future
13598 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13599 or inside the inlined function instead.
13600
13601 @item
13602 @value{GDBN} cannot locate the return value of inlined calls after
13603 using the @code{finish} command. This is a limitation of compiler-generated
13604 debugging information; after @code{finish}, you can step to the next line
13605 and print a variable where your program stored the return value.
13606
13607 @end itemize
13608
13609 @node Tail Call Frames
13610 @section Tail Call Frames
13611 @cindex tail call frames, debugging
13612
13613 Function @code{B} can call function @code{C} in its very last statement. In
13614 unoptimized compilation the call of @code{C} is immediately followed by return
13615 instruction at the end of @code{B} code. Optimizing compiler may replace the
13616 call and return in function @code{B} into one jump to function @code{C}
13617 instead. Such use of a jump instruction is called @dfn{tail call}.
13618
13619 During execution of function @code{C}, there will be no indication in the
13620 function call stack frames that it was tail-called from @code{B}. If function
13621 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13622 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13623 some cases @value{GDBN} can determine that @code{C} was tail-called from
13624 @code{B}, and it will then create fictitious call frame for that, with the
13625 return address set up as if @code{B} called @code{C} normally.
13626
13627 This functionality is currently supported only by DWARF 2 debugging format and
13628 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13629 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13630 this information.
13631
13632 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13633 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13634
13635 @smallexample
13636 (gdb) x/i $pc - 2
13637 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13638 (gdb) info frame
13639 Stack level 1, frame at 0x7fffffffda30:
13640 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13641 tail call frame, caller of frame at 0x7fffffffda30
13642 source language c++.
13643 Arglist at unknown address.
13644 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13645 @end smallexample
13646
13647 The detection of all the possible code path executions can find them ambiguous.
13648 There is no execution history stored (possible @ref{Reverse Execution} is never
13649 used for this purpose) and the last known caller could have reached the known
13650 callee by multiple different jump sequences. In such case @value{GDBN} still
13651 tries to show at least all the unambiguous top tail callers and all the
13652 unambiguous bottom tail calees, if any.
13653
13654 @table @code
13655 @anchor{set debug entry-values}
13656 @item set debug entry-values
13657 @kindex set debug entry-values
13658 When set to on, enables printing of analysis messages for both frame argument
13659 values at function entry and tail calls. It will show all the possible valid
13660 tail calls code paths it has considered. It will also print the intersection
13661 of them with the final unambiguous (possibly partial or even empty) code path
13662 result.
13663
13664 @item show debug entry-values
13665 @kindex show debug entry-values
13666 Show the current state of analysis messages printing for both frame argument
13667 values at function entry and tail calls.
13668 @end table
13669
13670 The analysis messages for tail calls can for example show why the virtual tail
13671 call frame for function @code{c} has not been recognized (due to the indirect
13672 reference by variable @code{x}):
13673
13674 @smallexample
13675 static void __attribute__((noinline, noclone)) c (void);
13676 void (*x) (void) = c;
13677 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13678 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13679 int main (void) @{ x (); return 0; @}
13680
13681 Breakpoint 1, DW_OP_entry_value resolving cannot find
13682 DW_TAG_call_site 0x40039a in main
13683 a () at t.c:3
13684 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13685 (gdb) bt
13686 #0 a () at t.c:3
13687 #1 0x000000000040039a in main () at t.c:5
13688 @end smallexample
13689
13690 Another possibility is an ambiguous virtual tail call frames resolution:
13691
13692 @smallexample
13693 int i;
13694 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13695 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13696 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13697 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13698 static void __attribute__((noinline, noclone)) b (void)
13699 @{ if (i) c (); else e (); @}
13700 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13701 int main (void) @{ a (); return 0; @}
13702
13703 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13704 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13705 tailcall: reduced: 0x4004d2(a) |
13706 (gdb) bt
13707 #0 f () at t.c:2
13708 #1 0x00000000004004d2 in a () at t.c:8
13709 #2 0x0000000000400395 in main () at t.c:9
13710 @end smallexample
13711
13712 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13713 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13714
13715 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13716 @ifset HAVE_MAKEINFO_CLICK
13717 @set ARROW @click{}
13718 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13719 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13720 @end ifset
13721 @ifclear HAVE_MAKEINFO_CLICK
13722 @set ARROW ->
13723 @set CALLSEQ1B @value{CALLSEQ1A}
13724 @set CALLSEQ2B @value{CALLSEQ2A}
13725 @end ifclear
13726
13727 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13728 The code can have possible execution paths @value{CALLSEQ1B} or
13729 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13730
13731 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13732 has found. It then finds another possible calling sequence - that one is
13733 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13734 printed as the @code{reduced:} calling sequence. That one could have many
13735 further @code{compare:} and @code{reduced:} statements as long as there remain
13736 any non-ambiguous sequence entries.
13737
13738 For the frame of function @code{b} in both cases there are different possible
13739 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
13740 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
13741 therefore this one is displayed to the user while the ambiguous frames are
13742 omitted.
13743
13744 There can be also reasons why printing of frame argument values at function
13745 entry may fail:
13746
13747 @smallexample
13748 int v;
13749 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13750 static void __attribute__((noinline, noclone)) a (int i);
13751 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13752 static void __attribute__((noinline, noclone)) a (int i)
13753 @{ if (i) b (i - 1); else c (0); @}
13754 int main (void) @{ a (5); return 0; @}
13755
13756 (gdb) bt
13757 #0 c (i=i@@entry=0) at t.c:2
13758 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
13759 function "a" at 0x400420 can call itself via tail calls
13760 i=<optimized out>) at t.c:6
13761 #2 0x000000000040036e in main () at t.c:7
13762 @end smallexample
13763
13764 @value{GDBN} cannot find out from the inferior state if and how many times did
13765 function @code{a} call itself (via function @code{b}) as these calls would be
13766 tail calls. Such tail calls would modify the @code{i} variable, therefore
13767 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13768 prints @code{<optimized out>} instead.
13769
13770 @node Macros
13771 @chapter C Preprocessor Macros
13772
13773 Some languages, such as C and C@t{++}, provide a way to define and invoke
13774 ``preprocessor macros'' which expand into strings of tokens.
13775 @value{GDBN} can evaluate expressions containing macro invocations, show
13776 the result of macro expansion, and show a macro's definition, including
13777 where it was defined.
13778
13779 You may need to compile your program specially to provide @value{GDBN}
13780 with information about preprocessor macros. Most compilers do not
13781 include macros in their debugging information, even when you compile
13782 with the @option{-g} flag. @xref{Compilation}.
13783
13784 A program may define a macro at one point, remove that definition later,
13785 and then provide a different definition after that. Thus, at different
13786 points in the program, a macro may have different definitions, or have
13787 no definition at all. If there is a current stack frame, @value{GDBN}
13788 uses the macros in scope at that frame's source code line. Otherwise,
13789 @value{GDBN} uses the macros in scope at the current listing location;
13790 see @ref{List}.
13791
13792 Whenever @value{GDBN} evaluates an expression, it always expands any
13793 macro invocations present in the expression. @value{GDBN} also provides
13794 the following commands for working with macros explicitly.
13795
13796 @table @code
13797
13798 @kindex macro expand
13799 @cindex macro expansion, showing the results of preprocessor
13800 @cindex preprocessor macro expansion, showing the results of
13801 @cindex expanding preprocessor macros
13802 @item macro expand @var{expression}
13803 @itemx macro exp @var{expression}
13804 Show the results of expanding all preprocessor macro invocations in
13805 @var{expression}. Since @value{GDBN} simply expands macros, but does
13806 not parse the result, @var{expression} need not be a valid expression;
13807 it can be any string of tokens.
13808
13809 @kindex macro exp1
13810 @item macro expand-once @var{expression}
13811 @itemx macro exp1 @var{expression}
13812 @cindex expand macro once
13813 @i{(This command is not yet implemented.)} Show the results of
13814 expanding those preprocessor macro invocations that appear explicitly in
13815 @var{expression}. Macro invocations appearing in that expansion are
13816 left unchanged. This command allows you to see the effect of a
13817 particular macro more clearly, without being confused by further
13818 expansions. Since @value{GDBN} simply expands macros, but does not
13819 parse the result, @var{expression} need not be a valid expression; it
13820 can be any string of tokens.
13821
13822 @kindex info macro
13823 @cindex macro definition, showing
13824 @cindex definition of a macro, showing
13825 @cindex macros, from debug info
13826 @item info macro [-a|-all] [--] @var{macro}
13827 Show the current definition or all definitions of the named @var{macro},
13828 and describe the source location or compiler command-line where that
13829 definition was established. The optional double dash is to signify the end of
13830 argument processing and the beginning of @var{macro} for non C-like macros where
13831 the macro may begin with a hyphen.
13832
13833 @kindex info macros
13834 @item info macros @var{location}
13835 Show all macro definitions that are in effect at the location specified
13836 by @var{location}, and describe the source location or compiler
13837 command-line where those definitions were established.
13838
13839 @kindex macro define
13840 @cindex user-defined macros
13841 @cindex defining macros interactively
13842 @cindex macros, user-defined
13843 @item macro define @var{macro} @var{replacement-list}
13844 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
13845 Introduce a definition for a preprocessor macro named @var{macro},
13846 invocations of which are replaced by the tokens given in
13847 @var{replacement-list}. The first form of this command defines an
13848 ``object-like'' macro, which takes no arguments; the second form
13849 defines a ``function-like'' macro, which takes the arguments given in
13850 @var{arglist}.
13851
13852 A definition introduced by this command is in scope in every
13853 expression evaluated in @value{GDBN}, until it is removed with the
13854 @code{macro undef} command, described below. The definition overrides
13855 all definitions for @var{macro} present in the program being debugged,
13856 as well as any previous user-supplied definition.
13857
13858 @kindex macro undef
13859 @item macro undef @var{macro}
13860 Remove any user-supplied definition for the macro named @var{macro}.
13861 This command only affects definitions provided with the @code{macro
13862 define} command, described above; it cannot remove definitions present
13863 in the program being debugged.
13864
13865 @kindex macro list
13866 @item macro list
13867 List all the macros defined using the @code{macro define} command.
13868 @end table
13869
13870 @cindex macros, example of debugging with
13871 Here is a transcript showing the above commands in action. First, we
13872 show our source files:
13873
13874 @smallexample
13875 $ cat sample.c
13876 #include <stdio.h>
13877 #include "sample.h"
13878
13879 #define M 42
13880 #define ADD(x) (M + x)
13881
13882 main ()
13883 @{
13884 #define N 28
13885 printf ("Hello, world!\n");
13886 #undef N
13887 printf ("We're so creative.\n");
13888 #define N 1729
13889 printf ("Goodbye, world!\n");
13890 @}
13891 $ cat sample.h
13892 #define Q <
13893 $
13894 @end smallexample
13895
13896 Now, we compile the program using the @sc{gnu} C compiler,
13897 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13898 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13899 and @option{-gdwarf-4}; we recommend always choosing the most recent
13900 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13901 includes information about preprocessor macros in the debugging
13902 information.
13903
13904 @smallexample
13905 $ gcc -gdwarf-2 -g3 sample.c -o sample
13906 $
13907 @end smallexample
13908
13909 Now, we start @value{GDBN} on our sample program:
13910
13911 @smallexample
13912 $ gdb -nw sample
13913 GNU gdb 2002-05-06-cvs
13914 Copyright 2002 Free Software Foundation, Inc.
13915 GDB is free software, @dots{}
13916 (@value{GDBP})
13917 @end smallexample
13918
13919 We can expand macros and examine their definitions, even when the
13920 program is not running. @value{GDBN} uses the current listing position
13921 to decide which macro definitions are in scope:
13922
13923 @smallexample
13924 (@value{GDBP}) list main
13925 3
13926 4 #define M 42
13927 5 #define ADD(x) (M + x)
13928 6
13929 7 main ()
13930 8 @{
13931 9 #define N 28
13932 10 printf ("Hello, world!\n");
13933 11 #undef N
13934 12 printf ("We're so creative.\n");
13935 (@value{GDBP}) info macro ADD
13936 Defined at /home/jimb/gdb/macros/play/sample.c:5
13937 #define ADD(x) (M + x)
13938 (@value{GDBP}) info macro Q
13939 Defined at /home/jimb/gdb/macros/play/sample.h:1
13940 included at /home/jimb/gdb/macros/play/sample.c:2
13941 #define Q <
13942 (@value{GDBP}) macro expand ADD(1)
13943 expands to: (42 + 1)
13944 (@value{GDBP}) macro expand-once ADD(1)
13945 expands to: once (M + 1)
13946 (@value{GDBP})
13947 @end smallexample
13948
13949 In the example above, note that @code{macro expand-once} expands only
13950 the macro invocation explicit in the original text --- the invocation of
13951 @code{ADD} --- but does not expand the invocation of the macro @code{M},
13952 which was introduced by @code{ADD}.
13953
13954 Once the program is running, @value{GDBN} uses the macro definitions in
13955 force at the source line of the current stack frame:
13956
13957 @smallexample
13958 (@value{GDBP}) break main
13959 Breakpoint 1 at 0x8048370: file sample.c, line 10.
13960 (@value{GDBP}) run
13961 Starting program: /home/jimb/gdb/macros/play/sample
13962
13963 Breakpoint 1, main () at sample.c:10
13964 10 printf ("Hello, world!\n");
13965 (@value{GDBP})
13966 @end smallexample
13967
13968 At line 10, the definition of the macro @code{N} at line 9 is in force:
13969
13970 @smallexample
13971 (@value{GDBP}) info macro N
13972 Defined at /home/jimb/gdb/macros/play/sample.c:9
13973 #define N 28
13974 (@value{GDBP}) macro expand N Q M
13975 expands to: 28 < 42
13976 (@value{GDBP}) print N Q M
13977 $1 = 1
13978 (@value{GDBP})
13979 @end smallexample
13980
13981 As we step over directives that remove @code{N}'s definition, and then
13982 give it a new definition, @value{GDBN} finds the definition (or lack
13983 thereof) in force at each point:
13984
13985 @smallexample
13986 (@value{GDBP}) next
13987 Hello, world!
13988 12 printf ("We're so creative.\n");
13989 (@value{GDBP}) info macro N
13990 The symbol `N' has no definition as a C/C++ preprocessor macro
13991 at /home/jimb/gdb/macros/play/sample.c:12
13992 (@value{GDBP}) next
13993 We're so creative.
13994 14 printf ("Goodbye, world!\n");
13995 (@value{GDBP}) info macro N
13996 Defined at /home/jimb/gdb/macros/play/sample.c:13
13997 #define N 1729
13998 (@value{GDBP}) macro expand N Q M
13999 expands to: 1729 < 42
14000 (@value{GDBP}) print N Q M
14001 $2 = 0
14002 (@value{GDBP})
14003 @end smallexample
14004
14005 In addition to source files, macros can be defined on the compilation command
14006 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14007 such a way, @value{GDBN} displays the location of their definition as line zero
14008 of the source file submitted to the compiler.
14009
14010 @smallexample
14011 (@value{GDBP}) info macro __STDC__
14012 Defined at /home/jimb/gdb/macros/play/sample.c:0
14013 -D__STDC__=1
14014 (@value{GDBP})
14015 @end smallexample
14016
14017
14018 @node Tracepoints
14019 @chapter Tracepoints
14020 @c This chapter is based on the documentation written by Michael
14021 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14022
14023 @cindex tracepoints
14024 In some applications, it is not feasible for the debugger to interrupt
14025 the program's execution long enough for the developer to learn
14026 anything helpful about its behavior. If the program's correctness
14027 depends on its real-time behavior, delays introduced by a debugger
14028 might cause the program to change its behavior drastically, or perhaps
14029 fail, even when the code itself is correct. It is useful to be able
14030 to observe the program's behavior without interrupting it.
14031
14032 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14033 specify locations in the program, called @dfn{tracepoints}, and
14034 arbitrary expressions to evaluate when those tracepoints are reached.
14035 Later, using the @code{tfind} command, you can examine the values
14036 those expressions had when the program hit the tracepoints. The
14037 expressions may also denote objects in memory---structures or arrays,
14038 for example---whose values @value{GDBN} should record; while visiting
14039 a particular tracepoint, you may inspect those objects as if they were
14040 in memory at that moment. However, because @value{GDBN} records these
14041 values without interacting with you, it can do so quickly and
14042 unobtrusively, hopefully not disturbing the program's behavior.
14043
14044 The tracepoint facility is currently available only for remote
14045 targets. @xref{Targets}. In addition, your remote target must know
14046 how to collect trace data. This functionality is implemented in the
14047 remote stub; however, none of the stubs distributed with @value{GDBN}
14048 support tracepoints as of this writing. The format of the remote
14049 packets used to implement tracepoints are described in @ref{Tracepoint
14050 Packets}.
14051
14052 It is also possible to get trace data from a file, in a manner reminiscent
14053 of corefiles; you specify the filename, and use @code{tfind} to search
14054 through the file. @xref{Trace Files}, for more details.
14055
14056 This chapter describes the tracepoint commands and features.
14057
14058 @menu
14059 * Set Tracepoints::
14060 * Analyze Collected Data::
14061 * Tracepoint Variables::
14062 * Trace Files::
14063 @end menu
14064
14065 @node Set Tracepoints
14066 @section Commands to Set Tracepoints
14067
14068 Before running such a @dfn{trace experiment}, an arbitrary number of
14069 tracepoints can be set. A tracepoint is actually a special type of
14070 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14071 standard breakpoint commands. For instance, as with breakpoints,
14072 tracepoint numbers are successive integers starting from one, and many
14073 of the commands associated with tracepoints take the tracepoint number
14074 as their argument, to identify which tracepoint to work on.
14075
14076 For each tracepoint, you can specify, in advance, some arbitrary set
14077 of data that you want the target to collect in the trace buffer when
14078 it hits that tracepoint. The collected data can include registers,
14079 local variables, or global data. Later, you can use @value{GDBN}
14080 commands to examine the values these data had at the time the
14081 tracepoint was hit.
14082
14083 Tracepoints do not support every breakpoint feature. Ignore counts on
14084 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14085 commands when they are hit. Tracepoints may not be thread-specific
14086 either.
14087
14088 @cindex fast tracepoints
14089 Some targets may support @dfn{fast tracepoints}, which are inserted in
14090 a different way (such as with a jump instead of a trap), that is
14091 faster but possibly restricted in where they may be installed.
14092
14093 @cindex static tracepoints
14094 @cindex markers, static tracepoints
14095 @cindex probing markers, static tracepoints
14096 Regular and fast tracepoints are dynamic tracing facilities, meaning
14097 that they can be used to insert tracepoints at (almost) any location
14098 in the target. Some targets may also support controlling @dfn{static
14099 tracepoints} from @value{GDBN}. With static tracing, a set of
14100 instrumentation points, also known as @dfn{markers}, are embedded in
14101 the target program, and can be activated or deactivated by name or
14102 address. These are usually placed at locations which facilitate
14103 investigating what the target is actually doing. @value{GDBN}'s
14104 support for static tracing includes being able to list instrumentation
14105 points, and attach them with @value{GDBN} defined high level
14106 tracepoints that expose the whole range of convenience of
14107 @value{GDBN}'s tracepoints support. Namely, support for collecting
14108 registers values and values of global or local (to the instrumentation
14109 point) variables; tracepoint conditions and trace state variables.
14110 The act of installing a @value{GDBN} static tracepoint on an
14111 instrumentation point, or marker, is referred to as @dfn{probing} a
14112 static tracepoint marker.
14113
14114 @code{gdbserver} supports tracepoints on some target systems.
14115 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14116
14117 This section describes commands to set tracepoints and associated
14118 conditions and actions.
14119
14120 @menu
14121 * Create and Delete Tracepoints::
14122 * Enable and Disable Tracepoints::
14123 * Tracepoint Passcounts::
14124 * Tracepoint Conditions::
14125 * Trace State Variables::
14126 * Tracepoint Actions::
14127 * Listing Tracepoints::
14128 * Listing Static Tracepoint Markers::
14129 * Starting and Stopping Trace Experiments::
14130 * Tracepoint Restrictions::
14131 @end menu
14132
14133 @node Create and Delete Tracepoints
14134 @subsection Create and Delete Tracepoints
14135
14136 @table @code
14137 @cindex set tracepoint
14138 @kindex trace
14139 @item trace @var{location}
14140 The @code{trace} command is very similar to the @code{break} command.
14141 Its argument @var{location} can be any valid location.
14142 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14143 which is a point in the target program where the debugger will briefly stop,
14144 collect some data, and then allow the program to continue. Setting a tracepoint
14145 or changing its actions takes effect immediately if the remote stub
14146 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14147 in tracing}).
14148 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14149 these changes don't take effect until the next @code{tstart}
14150 command, and once a trace experiment is running, further changes will
14151 not have any effect until the next trace experiment starts. In addition,
14152 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14153 address is not yet resolved. (This is similar to pending breakpoints.)
14154 Pending tracepoints are not downloaded to the target and not installed
14155 until they are resolved. The resolution of pending tracepoints requires
14156 @value{GDBN} support---when debugging with the remote target, and
14157 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14158 tracing}), pending tracepoints can not be resolved (and downloaded to
14159 the remote stub) while @value{GDBN} is disconnected.
14160
14161 Here are some examples of using the @code{trace} command:
14162
14163 @smallexample
14164 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14165
14166 (@value{GDBP}) @b{trace +2} // 2 lines forward
14167
14168 (@value{GDBP}) @b{trace my_function} // first source line of function
14169
14170 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14171
14172 (@value{GDBP}) @b{trace *0x2117c4} // an address
14173 @end smallexample
14174
14175 @noindent
14176 You can abbreviate @code{trace} as @code{tr}.
14177
14178 @item trace @var{location} if @var{cond}
14179 Set a tracepoint with condition @var{cond}; evaluate the expression
14180 @var{cond} each time the tracepoint is reached, and collect data only
14181 if the value is nonzero---that is, if @var{cond} evaluates as true.
14182 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14183 information on tracepoint conditions.
14184
14185 @item ftrace @var{location} [ if @var{cond} ]
14186 @cindex set fast tracepoint
14187 @cindex fast tracepoints, setting
14188 @kindex ftrace
14189 The @code{ftrace} command sets a fast tracepoint. For targets that
14190 support them, fast tracepoints will use a more efficient but possibly
14191 less general technique to trigger data collection, such as a jump
14192 instruction instead of a trap, or some sort of hardware support. It
14193 may not be possible to create a fast tracepoint at the desired
14194 location, in which case the command will exit with an explanatory
14195 message.
14196
14197 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14198 @code{trace}.
14199
14200 On 32-bit x86-architecture systems, fast tracepoints normally need to
14201 be placed at an instruction that is 5 bytes or longer, but can be
14202 placed at 4-byte instructions if the low 64K of memory of the target
14203 program is available to install trampolines. Some Unix-type systems,
14204 such as @sc{gnu}/Linux, exclude low addresses from the program's
14205 address space; but for instance with the Linux kernel it is possible
14206 to let @value{GDBN} use this area by doing a @command{sysctl} command
14207 to set the @code{mmap_min_addr} kernel parameter, as in
14208
14209 @example
14210 sudo sysctl -w vm.mmap_min_addr=32768
14211 @end example
14212
14213 @noindent
14214 which sets the low address to 32K, which leaves plenty of room for
14215 trampolines. The minimum address should be set to a page boundary.
14216
14217 @item strace @var{location} [ if @var{cond} ]
14218 @cindex set static tracepoint
14219 @cindex static tracepoints, setting
14220 @cindex probe static tracepoint marker
14221 @kindex strace
14222 The @code{strace} command sets a static tracepoint. For targets that
14223 support it, setting a static tracepoint probes a static
14224 instrumentation point, or marker, found at @var{location}. It may not
14225 be possible to set a static tracepoint at the desired location, in
14226 which case the command will exit with an explanatory message.
14227
14228 @value{GDBN} handles arguments to @code{strace} exactly as for
14229 @code{trace}, with the addition that the user can also specify
14230 @code{-m @var{marker}} as @var{location}. This probes the marker
14231 identified by the @var{marker} string identifier. This identifier
14232 depends on the static tracepoint backend library your program is
14233 using. You can find all the marker identifiers in the @samp{ID} field
14234 of the @code{info static-tracepoint-markers} command output.
14235 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14236 Markers}. For example, in the following small program using the UST
14237 tracing engine:
14238
14239 @smallexample
14240 main ()
14241 @{
14242 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14243 @}
14244 @end smallexample
14245
14246 @noindent
14247 the marker id is composed of joining the first two arguments to the
14248 @code{trace_mark} call with a slash, which translates to:
14249
14250 @smallexample
14251 (@value{GDBP}) info static-tracepoint-markers
14252 Cnt Enb ID Address What
14253 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14254 Data: "str %s"
14255 [etc...]
14256 @end smallexample
14257
14258 @noindent
14259 so you may probe the marker above with:
14260
14261 @smallexample
14262 (@value{GDBP}) strace -m ust/bar33
14263 @end smallexample
14264
14265 Static tracepoints accept an extra collect action --- @code{collect
14266 $_sdata}. This collects arbitrary user data passed in the probe point
14267 call to the tracing library. In the UST example above, you'll see
14268 that the third argument to @code{trace_mark} is a printf-like format
14269 string. The user data is then the result of running that formatting
14270 string against the following arguments. Note that @code{info
14271 static-tracepoint-markers} command output lists that format string in
14272 the @samp{Data:} field.
14273
14274 You can inspect this data when analyzing the trace buffer, by printing
14275 the $_sdata variable like any other variable available to
14276 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14277
14278 @vindex $tpnum
14279 @cindex last tracepoint number
14280 @cindex recent tracepoint number
14281 @cindex tracepoint number
14282 The convenience variable @code{$tpnum} records the tracepoint number
14283 of the most recently set tracepoint.
14284
14285 @kindex delete tracepoint
14286 @cindex tracepoint deletion
14287 @item delete tracepoint @r{[}@var{num}@r{]}
14288 Permanently delete one or more tracepoints. With no argument, the
14289 default is to delete all tracepoints. Note that the regular
14290 @code{delete} command can remove tracepoints also.
14291
14292 Examples:
14293
14294 @smallexample
14295 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14296
14297 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14298 @end smallexample
14299
14300 @noindent
14301 You can abbreviate this command as @code{del tr}.
14302 @end table
14303
14304 @node Enable and Disable Tracepoints
14305 @subsection Enable and Disable Tracepoints
14306
14307 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14308
14309 @table @code
14310 @kindex disable tracepoint
14311 @item disable tracepoint @r{[}@var{num}@r{]}
14312 Disable tracepoint @var{num}, or all tracepoints if no argument
14313 @var{num} is given. A disabled tracepoint will have no effect during
14314 a trace experiment, but it is not forgotten. You can re-enable
14315 a disabled tracepoint using the @code{enable tracepoint} command.
14316 If the command is issued during a trace experiment and the debug target
14317 has support for disabling tracepoints during a trace experiment, then the
14318 change will be effective immediately. Otherwise, it will be applied to the
14319 next trace experiment.
14320
14321 @kindex enable tracepoint
14322 @item enable tracepoint @r{[}@var{num}@r{]}
14323 Enable tracepoint @var{num}, or all tracepoints. If this command is
14324 issued during a trace experiment and the debug target supports enabling
14325 tracepoints during a trace experiment, then the enabled tracepoints will
14326 become effective immediately. Otherwise, they will become effective the
14327 next time a trace experiment is run.
14328 @end table
14329
14330 @node Tracepoint Passcounts
14331 @subsection Tracepoint Passcounts
14332
14333 @table @code
14334 @kindex passcount
14335 @cindex tracepoint pass count
14336 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14337 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14338 automatically stop a trace experiment. If a tracepoint's passcount is
14339 @var{n}, then the trace experiment will be automatically stopped on
14340 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14341 @var{num} is not specified, the @code{passcount} command sets the
14342 passcount of the most recently defined tracepoint. If no passcount is
14343 given, the trace experiment will run until stopped explicitly by the
14344 user.
14345
14346 Examples:
14347
14348 @smallexample
14349 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14350 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14351
14352 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14353 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14354 (@value{GDBP}) @b{trace foo}
14355 (@value{GDBP}) @b{pass 3}
14356 (@value{GDBP}) @b{trace bar}
14357 (@value{GDBP}) @b{pass 2}
14358 (@value{GDBP}) @b{trace baz}
14359 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14360 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14361 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14362 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14363 @end smallexample
14364 @end table
14365
14366 @node Tracepoint Conditions
14367 @subsection Tracepoint Conditions
14368 @cindex conditional tracepoints
14369 @cindex tracepoint conditions
14370
14371 The simplest sort of tracepoint collects data every time your program
14372 reaches a specified place. You can also specify a @dfn{condition} for
14373 a tracepoint. A condition is just a Boolean expression in your
14374 programming language (@pxref{Expressions, ,Expressions}). A
14375 tracepoint with a condition evaluates the expression each time your
14376 program reaches it, and data collection happens only if the condition
14377 is true.
14378
14379 Tracepoint conditions can be specified when a tracepoint is set, by
14380 using @samp{if} in the arguments to the @code{trace} command.
14381 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14382 also be set or changed at any time with the @code{condition} command,
14383 just as with breakpoints.
14384
14385 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14386 the conditional expression itself. Instead, @value{GDBN} encodes the
14387 expression into an agent expression (@pxref{Agent Expressions})
14388 suitable for execution on the target, independently of @value{GDBN}.
14389 Global variables become raw memory locations, locals become stack
14390 accesses, and so forth.
14391
14392 For instance, suppose you have a function that is usually called
14393 frequently, but should not be called after an error has occurred. You
14394 could use the following tracepoint command to collect data about calls
14395 of that function that happen while the error code is propagating
14396 through the program; an unconditional tracepoint could end up
14397 collecting thousands of useless trace frames that you would have to
14398 search through.
14399
14400 @smallexample
14401 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14402 @end smallexample
14403
14404 @node Trace State Variables
14405 @subsection Trace State Variables
14406 @cindex trace state variables
14407
14408 A @dfn{trace state variable} is a special type of variable that is
14409 created and managed by target-side code. The syntax is the same as
14410 that for GDB's convenience variables (a string prefixed with ``$''),
14411 but they are stored on the target. They must be created explicitly,
14412 using a @code{tvariable} command. They are always 64-bit signed
14413 integers.
14414
14415 Trace state variables are remembered by @value{GDBN}, and downloaded
14416 to the target along with tracepoint information when the trace
14417 experiment starts. There are no intrinsic limits on the number of
14418 trace state variables, beyond memory limitations of the target.
14419
14420 @cindex convenience variables, and trace state variables
14421 Although trace state variables are managed by the target, you can use
14422 them in print commands and expressions as if they were convenience
14423 variables; @value{GDBN} will get the current value from the target
14424 while the trace experiment is running. Trace state variables share
14425 the same namespace as other ``$'' variables, which means that you
14426 cannot have trace state variables with names like @code{$23} or
14427 @code{$pc}, nor can you have a trace state variable and a convenience
14428 variable with the same name.
14429
14430 @table @code
14431
14432 @item tvariable $@var{name} [ = @var{expression} ]
14433 @kindex tvariable
14434 The @code{tvariable} command creates a new trace state variable named
14435 @code{$@var{name}}, and optionally gives it an initial value of
14436 @var{expression}. The @var{expression} is evaluated when this command is
14437 entered; the result will be converted to an integer if possible,
14438 otherwise @value{GDBN} will report an error. A subsequent
14439 @code{tvariable} command specifying the same name does not create a
14440 variable, but instead assigns the supplied initial value to the
14441 existing variable of that name, overwriting any previous initial
14442 value. The default initial value is 0.
14443
14444 @item info tvariables
14445 @kindex info tvariables
14446 List all the trace state variables along with their initial values.
14447 Their current values may also be displayed, if the trace experiment is
14448 currently running.
14449
14450 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14451 @kindex delete tvariable
14452 Delete the given trace state variables, or all of them if no arguments
14453 are specified.
14454
14455 @end table
14456
14457 @node Tracepoint Actions
14458 @subsection Tracepoint Action Lists
14459
14460 @table @code
14461 @kindex actions
14462 @cindex tracepoint actions
14463 @item actions @r{[}@var{num}@r{]}
14464 This command will prompt for a list of actions to be taken when the
14465 tracepoint is hit. If the tracepoint number @var{num} is not
14466 specified, this command sets the actions for the one that was most
14467 recently defined (so that you can define a tracepoint and then say
14468 @code{actions} without bothering about its number). You specify the
14469 actions themselves on the following lines, one action at a time, and
14470 terminate the actions list with a line containing just @code{end}. So
14471 far, the only defined actions are @code{collect}, @code{teval}, and
14472 @code{while-stepping}.
14473
14474 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14475 Commands, ,Breakpoint Command Lists}), except that only the defined
14476 actions are allowed; any other @value{GDBN} command is rejected.
14477
14478 @cindex remove actions from a tracepoint
14479 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14480 and follow it immediately with @samp{end}.
14481
14482 @smallexample
14483 (@value{GDBP}) @b{collect @var{data}} // collect some data
14484
14485 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14486
14487 (@value{GDBP}) @b{end} // signals the end of actions.
14488 @end smallexample
14489
14490 In the following example, the action list begins with @code{collect}
14491 commands indicating the things to be collected when the tracepoint is
14492 hit. Then, in order to single-step and collect additional data
14493 following the tracepoint, a @code{while-stepping} command is used,
14494 followed by the list of things to be collected after each step in a
14495 sequence of single steps. The @code{while-stepping} command is
14496 terminated by its own separate @code{end} command. Lastly, the action
14497 list is terminated by an @code{end} command.
14498
14499 @smallexample
14500 (@value{GDBP}) @b{trace foo}
14501 (@value{GDBP}) @b{actions}
14502 Enter actions for tracepoint 1, one per line:
14503 > collect bar,baz
14504 > collect $regs
14505 > while-stepping 12
14506 > collect $pc, arr[i]
14507 > end
14508 end
14509 @end smallexample
14510
14511 @kindex collect @r{(tracepoints)}
14512 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14513 Collect values of the given expressions when the tracepoint is hit.
14514 This command accepts a comma-separated list of any valid expressions.
14515 In addition to global, static, or local variables, the following
14516 special arguments are supported:
14517
14518 @table @code
14519 @item $regs
14520 Collect all registers.
14521
14522 @item $args
14523 Collect all function arguments.
14524
14525 @item $locals
14526 Collect all local variables.
14527
14528 @item $_ret
14529 Collect the return address. This is helpful if you want to see more
14530 of a backtrace.
14531
14532 @emph{Note:} The return address location can not always be reliably
14533 determined up front, and the wrong address / registers may end up
14534 collected instead. On some architectures the reliability is higher
14535 for tracepoints at function entry, while on others it's the opposite.
14536 When this happens, backtracing will stop because the return address is
14537 found unavailable (unless another collect rule happened to match it).
14538
14539 @item $_probe_argc
14540 Collects the number of arguments from the static probe at which the
14541 tracepoint is located.
14542 @xref{Static Probe Points}.
14543
14544 @item $_probe_arg@var{n}
14545 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14546 from the static probe at which the tracepoint is located.
14547 @xref{Static Probe Points}.
14548
14549 @item $_sdata
14550 @vindex $_sdata@r{, collect}
14551 Collect static tracepoint marker specific data. Only available for
14552 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14553 Lists}. On the UST static tracepoints library backend, an
14554 instrumentation point resembles a @code{printf} function call. The
14555 tracing library is able to collect user specified data formatted to a
14556 character string using the format provided by the programmer that
14557 instrumented the program. Other backends have similar mechanisms.
14558 Here's an example of a UST marker call:
14559
14560 @smallexample
14561 const char master_name[] = "$your_name";
14562 trace_mark(channel1, marker1, "hello %s", master_name)
14563 @end smallexample
14564
14565 In this case, collecting @code{$_sdata} collects the string
14566 @samp{hello $yourname}. When analyzing the trace buffer, you can
14567 inspect @samp{$_sdata} like any other variable available to
14568 @value{GDBN}.
14569 @end table
14570
14571 You can give several consecutive @code{collect} commands, each one
14572 with a single argument, or one @code{collect} command with several
14573 arguments separated by commas; the effect is the same.
14574
14575 The optional @var{mods} changes the usual handling of the arguments.
14576 @code{s} requests that pointers to chars be handled as strings, in
14577 particular collecting the contents of the memory being pointed at, up
14578 to the first zero. The upper bound is by default the value of the
14579 @code{print elements} variable; if @code{s} is followed by a decimal
14580 number, that is the upper bound instead. So for instance
14581 @samp{collect/s25 mystr} collects as many as 25 characters at
14582 @samp{mystr}.
14583
14584 The command @code{info scope} (@pxref{Symbols, info scope}) is
14585 particularly useful for figuring out what data to collect.
14586
14587 @kindex teval @r{(tracepoints)}
14588 @item teval @var{expr1}, @var{expr2}, @dots{}
14589 Evaluate the given expressions when the tracepoint is hit. This
14590 command accepts a comma-separated list of expressions. The results
14591 are discarded, so this is mainly useful for assigning values to trace
14592 state variables (@pxref{Trace State Variables}) without adding those
14593 values to the trace buffer, as would be the case if the @code{collect}
14594 action were used.
14595
14596 @kindex while-stepping @r{(tracepoints)}
14597 @item while-stepping @var{n}
14598 Perform @var{n} single-step instruction traces after the tracepoint,
14599 collecting new data after each step. The @code{while-stepping}
14600 command is followed by the list of what to collect while stepping
14601 (followed by its own @code{end} command):
14602
14603 @smallexample
14604 > while-stepping 12
14605 > collect $regs, myglobal
14606 > end
14607 >
14608 @end smallexample
14609
14610 @noindent
14611 Note that @code{$pc} is not automatically collected by
14612 @code{while-stepping}; you need to explicitly collect that register if
14613 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14614 @code{stepping}.
14615
14616 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14617 @kindex set default-collect
14618 @cindex default collection action
14619 This variable is a list of expressions to collect at each tracepoint
14620 hit. It is effectively an additional @code{collect} action prepended
14621 to every tracepoint action list. The expressions are parsed
14622 individually for each tracepoint, so for instance a variable named
14623 @code{xyz} may be interpreted as a global for one tracepoint, and a
14624 local for another, as appropriate to the tracepoint's location.
14625
14626 @item show default-collect
14627 @kindex show default-collect
14628 Show the list of expressions that are collected by default at each
14629 tracepoint hit.
14630
14631 @end table
14632
14633 @node Listing Tracepoints
14634 @subsection Listing Tracepoints
14635
14636 @table @code
14637 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14638 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14639 @cindex information about tracepoints
14640 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14641 Display information about the tracepoint @var{num}. If you don't
14642 specify a tracepoint number, displays information about all the
14643 tracepoints defined so far. The format is similar to that used for
14644 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14645 command, simply restricting itself to tracepoints.
14646
14647 A tracepoint's listing may include additional information specific to
14648 tracing:
14649
14650 @itemize @bullet
14651 @item
14652 its passcount as given by the @code{passcount @var{n}} command
14653
14654 @item
14655 the state about installed on target of each location
14656 @end itemize
14657
14658 @smallexample
14659 (@value{GDBP}) @b{info trace}
14660 Num Type Disp Enb Address What
14661 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14662 while-stepping 20
14663 collect globfoo, $regs
14664 end
14665 collect globfoo2
14666 end
14667 pass count 1200
14668 2 tracepoint keep y <MULTIPLE>
14669 collect $eip
14670 2.1 y 0x0804859c in func4 at change-loc.h:35
14671 installed on target
14672 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14673 installed on target
14674 2.3 y <PENDING> set_tracepoint
14675 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14676 not installed on target
14677 (@value{GDBP})
14678 @end smallexample
14679
14680 @noindent
14681 This command can be abbreviated @code{info tp}.
14682 @end table
14683
14684 @node Listing Static Tracepoint Markers
14685 @subsection Listing Static Tracepoint Markers
14686
14687 @table @code
14688 @kindex info static-tracepoint-markers
14689 @cindex information about static tracepoint markers
14690 @item info static-tracepoint-markers
14691 Display information about all static tracepoint markers defined in the
14692 program.
14693
14694 For each marker, the following columns are printed:
14695
14696 @table @emph
14697 @item Count
14698 An incrementing counter, output to help readability. This is not a
14699 stable identifier.
14700 @item ID
14701 The marker ID, as reported by the target.
14702 @item Enabled or Disabled
14703 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14704 that are not enabled.
14705 @item Address
14706 Where the marker is in your program, as a memory address.
14707 @item What
14708 Where the marker is in the source for your program, as a file and line
14709 number. If the debug information included in the program does not
14710 allow @value{GDBN} to locate the source of the marker, this column
14711 will be left blank.
14712 @end table
14713
14714 @noindent
14715 In addition, the following information may be printed for each marker:
14716
14717 @table @emph
14718 @item Data
14719 User data passed to the tracing library by the marker call. In the
14720 UST backend, this is the format string passed as argument to the
14721 marker call.
14722 @item Static tracepoints probing the marker
14723 The list of static tracepoints attached to the marker.
14724 @end table
14725
14726 @smallexample
14727 (@value{GDBP}) info static-tracepoint-markers
14728 Cnt ID Enb Address What
14729 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14730 Data: number1 %d number2 %d
14731 Probed by static tracepoints: #2
14732 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14733 Data: str %s
14734 (@value{GDBP})
14735 @end smallexample
14736 @end table
14737
14738 @node Starting and Stopping Trace Experiments
14739 @subsection Starting and Stopping Trace Experiments
14740
14741 @table @code
14742 @kindex tstart [ @var{notes} ]
14743 @cindex start a new trace experiment
14744 @cindex collected data discarded
14745 @item tstart
14746 This command starts the trace experiment, and begins collecting data.
14747 It has the side effect of discarding all the data collected in the
14748 trace buffer during the previous trace experiment. If any arguments
14749 are supplied, they are taken as a note and stored with the trace
14750 experiment's state. The notes may be arbitrary text, and are
14751 especially useful with disconnected tracing in a multi-user context;
14752 the notes can explain what the trace is doing, supply user contact
14753 information, and so forth.
14754
14755 @kindex tstop [ @var{notes} ]
14756 @cindex stop a running trace experiment
14757 @item tstop
14758 This command stops the trace experiment. If any arguments are
14759 supplied, they are recorded with the experiment as a note. This is
14760 useful if you are stopping a trace started by someone else, for
14761 instance if the trace is interfering with the system's behavior and
14762 needs to be stopped quickly.
14763
14764 @strong{Note}: a trace experiment and data collection may stop
14765 automatically if any tracepoint's passcount is reached
14766 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14767
14768 @kindex tstatus
14769 @cindex status of trace data collection
14770 @cindex trace experiment, status of
14771 @item tstatus
14772 This command displays the status of the current trace data
14773 collection.
14774 @end table
14775
14776 Here is an example of the commands we described so far:
14777
14778 @smallexample
14779 (@value{GDBP}) @b{trace gdb_c_test}
14780 (@value{GDBP}) @b{actions}
14781 Enter actions for tracepoint #1, one per line.
14782 > collect $regs,$locals,$args
14783 > while-stepping 11
14784 > collect $regs
14785 > end
14786 > end
14787 (@value{GDBP}) @b{tstart}
14788 [time passes @dots{}]
14789 (@value{GDBP}) @b{tstop}
14790 @end smallexample
14791
14792 @anchor{disconnected tracing}
14793 @cindex disconnected tracing
14794 You can choose to continue running the trace experiment even if
14795 @value{GDBN} disconnects from the target, voluntarily or
14796 involuntarily. For commands such as @code{detach}, the debugger will
14797 ask what you want to do with the trace. But for unexpected
14798 terminations (@value{GDBN} crash, network outage), it would be
14799 unfortunate to lose hard-won trace data, so the variable
14800 @code{disconnected-tracing} lets you decide whether the trace should
14801 continue running without @value{GDBN}.
14802
14803 @table @code
14804 @item set disconnected-tracing on
14805 @itemx set disconnected-tracing off
14806 @kindex set disconnected-tracing
14807 Choose whether a tracing run should continue to run if @value{GDBN}
14808 has disconnected from the target. Note that @code{detach} or
14809 @code{quit} will ask you directly what to do about a running trace no
14810 matter what this variable's setting, so the variable is mainly useful
14811 for handling unexpected situations, such as loss of the network.
14812
14813 @item show disconnected-tracing
14814 @kindex show disconnected-tracing
14815 Show the current choice for disconnected tracing.
14816
14817 @end table
14818
14819 When you reconnect to the target, the trace experiment may or may not
14820 still be running; it might have filled the trace buffer in the
14821 meantime, or stopped for one of the other reasons. If it is running,
14822 it will continue after reconnection.
14823
14824 Upon reconnection, the target will upload information about the
14825 tracepoints in effect. @value{GDBN} will then compare that
14826 information to the set of tracepoints currently defined, and attempt
14827 to match them up, allowing for the possibility that the numbers may
14828 have changed due to creation and deletion in the meantime. If one of
14829 the target's tracepoints does not match any in @value{GDBN}, the
14830 debugger will create a new tracepoint, so that you have a number with
14831 which to specify that tracepoint. This matching-up process is
14832 necessarily heuristic, and it may result in useless tracepoints being
14833 created; you may simply delete them if they are of no use.
14834
14835 @cindex circular trace buffer
14836 If your target agent supports a @dfn{circular trace buffer}, then you
14837 can run a trace experiment indefinitely without filling the trace
14838 buffer; when space runs out, the agent deletes already-collected trace
14839 frames, oldest first, until there is enough room to continue
14840 collecting. This is especially useful if your tracepoints are being
14841 hit too often, and your trace gets terminated prematurely because the
14842 buffer is full. To ask for a circular trace buffer, simply set
14843 @samp{circular-trace-buffer} to on. You can set this at any time,
14844 including during tracing; if the agent can do it, it will change
14845 buffer handling on the fly, otherwise it will not take effect until
14846 the next run.
14847
14848 @table @code
14849 @item set circular-trace-buffer on
14850 @itemx set circular-trace-buffer off
14851 @kindex set circular-trace-buffer
14852 Choose whether a tracing run should use a linear or circular buffer
14853 for trace data. A linear buffer will not lose any trace data, but may
14854 fill up prematurely, while a circular buffer will discard old trace
14855 data, but it will have always room for the latest tracepoint hits.
14856
14857 @item show circular-trace-buffer
14858 @kindex show circular-trace-buffer
14859 Show the current choice for the trace buffer. Note that this may not
14860 match the agent's current buffer handling, nor is it guaranteed to
14861 match the setting that might have been in effect during a past run,
14862 for instance if you are looking at frames from a trace file.
14863
14864 @end table
14865
14866 @table @code
14867 @item set trace-buffer-size @var{n}
14868 @itemx set trace-buffer-size unlimited
14869 @kindex set trace-buffer-size
14870 Request that the target use a trace buffer of @var{n} bytes. Not all
14871 targets will honor the request; they may have a compiled-in size for
14872 the trace buffer, or some other limitation. Set to a value of
14873 @code{unlimited} or @code{-1} to let the target use whatever size it
14874 likes. This is also the default.
14875
14876 @item show trace-buffer-size
14877 @kindex show trace-buffer-size
14878 Show the current requested size for the trace buffer. Note that this
14879 will only match the actual size if the target supports size-setting,
14880 and was able to handle the requested size. For instance, if the
14881 target can only change buffer size between runs, this variable will
14882 not reflect the change until the next run starts. Use @code{tstatus}
14883 to get a report of the actual buffer size.
14884 @end table
14885
14886 @table @code
14887 @item set trace-user @var{text}
14888 @kindex set trace-user
14889
14890 @item show trace-user
14891 @kindex show trace-user
14892
14893 @item set trace-notes @var{text}
14894 @kindex set trace-notes
14895 Set the trace run's notes.
14896
14897 @item show trace-notes
14898 @kindex show trace-notes
14899 Show the trace run's notes.
14900
14901 @item set trace-stop-notes @var{text}
14902 @kindex set trace-stop-notes
14903 Set the trace run's stop notes. The handling of the note is as for
14904 @code{tstop} arguments; the set command is convenient way to fix a
14905 stop note that is mistaken or incomplete.
14906
14907 @item show trace-stop-notes
14908 @kindex show trace-stop-notes
14909 Show the trace run's stop notes.
14910
14911 @end table
14912
14913 @node Tracepoint Restrictions
14914 @subsection Tracepoint Restrictions
14915
14916 @cindex tracepoint restrictions
14917 There are a number of restrictions on the use of tracepoints. As
14918 described above, tracepoint data gathering occurs on the target
14919 without interaction from @value{GDBN}. Thus the full capabilities of
14920 the debugger are not available during data gathering, and then at data
14921 examination time, you will be limited by only having what was
14922 collected. The following items describe some common problems, but it
14923 is not exhaustive, and you may run into additional difficulties not
14924 mentioned here.
14925
14926 @itemize @bullet
14927
14928 @item
14929 Tracepoint expressions are intended to gather objects (lvalues). Thus
14930 the full flexibility of GDB's expression evaluator is not available.
14931 You cannot call functions, cast objects to aggregate types, access
14932 convenience variables or modify values (except by assignment to trace
14933 state variables). Some language features may implicitly call
14934 functions (for instance Objective-C fields with accessors), and therefore
14935 cannot be collected either.
14936
14937 @item
14938 Collection of local variables, either individually or in bulk with
14939 @code{$locals} or @code{$args}, during @code{while-stepping} may
14940 behave erratically. The stepping action may enter a new scope (for
14941 instance by stepping into a function), or the location of the variable
14942 may change (for instance it is loaded into a register). The
14943 tracepoint data recorded uses the location information for the
14944 variables that is correct for the tracepoint location. When the
14945 tracepoint is created, it is not possible, in general, to determine
14946 where the steps of a @code{while-stepping} sequence will advance the
14947 program---particularly if a conditional branch is stepped.
14948
14949 @item
14950 Collection of an incompletely-initialized or partially-destroyed object
14951 may result in something that @value{GDBN} cannot display, or displays
14952 in a misleading way.
14953
14954 @item
14955 When @value{GDBN} displays a pointer to character it automatically
14956 dereferences the pointer to also display characters of the string
14957 being pointed to. However, collecting the pointer during tracing does
14958 not automatically collect the string. You need to explicitly
14959 dereference the pointer and provide size information if you want to
14960 collect not only the pointer, but the memory pointed to. For example,
14961 @code{*ptr@@50} can be used to collect the 50 element array pointed to
14962 by @code{ptr}.
14963
14964 @item
14965 It is not possible to collect a complete stack backtrace at a
14966 tracepoint. Instead, you may collect the registers and a few hundred
14967 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
14968 (adjust to use the name of the actual stack pointer register on your
14969 target architecture, and the amount of stack you wish to capture).
14970 Then the @code{backtrace} command will show a partial backtrace when
14971 using a trace frame. The number of stack frames that can be examined
14972 depends on the sizes of the frames in the collected stack. Note that
14973 if you ask for a block so large that it goes past the bottom of the
14974 stack, the target agent may report an error trying to read from an
14975 invalid address.
14976
14977 @item
14978 If you do not collect registers at a tracepoint, @value{GDBN} can
14979 infer that the value of @code{$pc} must be the same as the address of
14980 the tracepoint and use that when you are looking at a trace frame
14981 for that tracepoint. However, this cannot work if the tracepoint has
14982 multiple locations (for instance if it was set in a function that was
14983 inlined), or if it has a @code{while-stepping} loop. In those cases
14984 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
14985 it to zero.
14986
14987 @end itemize
14988
14989 @node Analyze Collected Data
14990 @section Using the Collected Data
14991
14992 After the tracepoint experiment ends, you use @value{GDBN} commands
14993 for examining the trace data. The basic idea is that each tracepoint
14994 collects a trace @dfn{snapshot} every time it is hit and another
14995 snapshot every time it single-steps. All these snapshots are
14996 consecutively numbered from zero and go into a buffer, and you can
14997 examine them later. The way you examine them is to @dfn{focus} on a
14998 specific trace snapshot. When the remote stub is focused on a trace
14999 snapshot, it will respond to all @value{GDBN} requests for memory and
15000 registers by reading from the buffer which belongs to that snapshot,
15001 rather than from @emph{real} memory or registers of the program being
15002 debugged. This means that @strong{all} @value{GDBN} commands
15003 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15004 behave as if we were currently debugging the program state as it was
15005 when the tracepoint occurred. Any requests for data that are not in
15006 the buffer will fail.
15007
15008 @menu
15009 * tfind:: How to select a trace snapshot
15010 * tdump:: How to display all data for a snapshot
15011 * save tracepoints:: How to save tracepoints for a future run
15012 @end menu
15013
15014 @node tfind
15015 @subsection @code{tfind @var{n}}
15016
15017 @kindex tfind
15018 @cindex select trace snapshot
15019 @cindex find trace snapshot
15020 The basic command for selecting a trace snapshot from the buffer is
15021 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15022 counting from zero. If no argument @var{n} is given, the next
15023 snapshot is selected.
15024
15025 Here are the various forms of using the @code{tfind} command.
15026
15027 @table @code
15028 @item tfind start
15029 Find the first snapshot in the buffer. This is a synonym for
15030 @code{tfind 0} (since 0 is the number of the first snapshot).
15031
15032 @item tfind none
15033 Stop debugging trace snapshots, resume @emph{live} debugging.
15034
15035 @item tfind end
15036 Same as @samp{tfind none}.
15037
15038 @item tfind
15039 No argument means find the next trace snapshot or find the first
15040 one if no trace snapshot is selected.
15041
15042 @item tfind -
15043 Find the previous trace snapshot before the current one. This permits
15044 retracing earlier steps.
15045
15046 @item tfind tracepoint @var{num}
15047 Find the next snapshot associated with tracepoint @var{num}. Search
15048 proceeds forward from the last examined trace snapshot. If no
15049 argument @var{num} is given, it means find the next snapshot collected
15050 for the same tracepoint as the current snapshot.
15051
15052 @item tfind pc @var{addr}
15053 Find the next snapshot associated with the value @var{addr} of the
15054 program counter. Search proceeds forward from the last examined trace
15055 snapshot. If no argument @var{addr} is given, it means find the next
15056 snapshot with the same value of PC as the current snapshot.
15057
15058 @item tfind outside @var{addr1}, @var{addr2}
15059 Find the next snapshot whose PC is outside the given range of
15060 addresses (exclusive).
15061
15062 @item tfind range @var{addr1}, @var{addr2}
15063 Find the next snapshot whose PC is between @var{addr1} and
15064 @var{addr2} (inclusive).
15065
15066 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15067 Find the next snapshot associated with the source line @var{n}. If
15068 the optional argument @var{file} is given, refer to line @var{n} in
15069 that source file. Search proceeds forward from the last examined
15070 trace snapshot. If no argument @var{n} is given, it means find the
15071 next line other than the one currently being examined; thus saying
15072 @code{tfind line} repeatedly can appear to have the same effect as
15073 stepping from line to line in a @emph{live} debugging session.
15074 @end table
15075
15076 The default arguments for the @code{tfind} commands are specifically
15077 designed to make it easy to scan through the trace buffer. For
15078 instance, @code{tfind} with no argument selects the next trace
15079 snapshot, and @code{tfind -} with no argument selects the previous
15080 trace snapshot. So, by giving one @code{tfind} command, and then
15081 simply hitting @key{RET} repeatedly you can examine all the trace
15082 snapshots in order. Or, by saying @code{tfind -} and then hitting
15083 @key{RET} repeatedly you can examine the snapshots in reverse order.
15084 The @code{tfind line} command with no argument selects the snapshot
15085 for the next source line executed. The @code{tfind pc} command with
15086 no argument selects the next snapshot with the same program counter
15087 (PC) as the current frame. The @code{tfind tracepoint} command with
15088 no argument selects the next trace snapshot collected by the same
15089 tracepoint as the current one.
15090
15091 In addition to letting you scan through the trace buffer manually,
15092 these commands make it easy to construct @value{GDBN} scripts that
15093 scan through the trace buffer and print out whatever collected data
15094 you are interested in. Thus, if we want to examine the PC, FP, and SP
15095 registers from each trace frame in the buffer, we can say this:
15096
15097 @smallexample
15098 (@value{GDBP}) @b{tfind start}
15099 (@value{GDBP}) @b{while ($trace_frame != -1)}
15100 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15101 $trace_frame, $pc, $sp, $fp
15102 > tfind
15103 > end
15104
15105 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15106 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15107 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15108 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15109 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15110 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15111 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15112 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15113 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15114 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15115 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15116 @end smallexample
15117
15118 Or, if we want to examine the variable @code{X} at each source line in
15119 the buffer:
15120
15121 @smallexample
15122 (@value{GDBP}) @b{tfind start}
15123 (@value{GDBP}) @b{while ($trace_frame != -1)}
15124 > printf "Frame %d, X == %d\n", $trace_frame, X
15125 > tfind line
15126 > end
15127
15128 Frame 0, X = 1
15129 Frame 7, X = 2
15130 Frame 13, X = 255
15131 @end smallexample
15132
15133 @node tdump
15134 @subsection @code{tdump}
15135 @kindex tdump
15136 @cindex dump all data collected at tracepoint
15137 @cindex tracepoint data, display
15138
15139 This command takes no arguments. It prints all the data collected at
15140 the current trace snapshot.
15141
15142 @smallexample
15143 (@value{GDBP}) @b{trace 444}
15144 (@value{GDBP}) @b{actions}
15145 Enter actions for tracepoint #2, one per line:
15146 > collect $regs, $locals, $args, gdb_long_test
15147 > end
15148
15149 (@value{GDBP}) @b{tstart}
15150
15151 (@value{GDBP}) @b{tfind line 444}
15152 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15153 at gdb_test.c:444
15154 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15155
15156 (@value{GDBP}) @b{tdump}
15157 Data collected at tracepoint 2, trace frame 1:
15158 d0 0xc4aa0085 -995491707
15159 d1 0x18 24
15160 d2 0x80 128
15161 d3 0x33 51
15162 d4 0x71aea3d 119204413
15163 d5 0x22 34
15164 d6 0xe0 224
15165 d7 0x380035 3670069
15166 a0 0x19e24a 1696330
15167 a1 0x3000668 50333288
15168 a2 0x100 256
15169 a3 0x322000 3284992
15170 a4 0x3000698 50333336
15171 a5 0x1ad3cc 1758156
15172 fp 0x30bf3c 0x30bf3c
15173 sp 0x30bf34 0x30bf34
15174 ps 0x0 0
15175 pc 0x20b2c8 0x20b2c8
15176 fpcontrol 0x0 0
15177 fpstatus 0x0 0
15178 fpiaddr 0x0 0
15179 p = 0x20e5b4 "gdb-test"
15180 p1 = (void *) 0x11
15181 p2 = (void *) 0x22
15182 p3 = (void *) 0x33
15183 p4 = (void *) 0x44
15184 p5 = (void *) 0x55
15185 p6 = (void *) 0x66
15186 gdb_long_test = 17 '\021'
15187
15188 (@value{GDBP})
15189 @end smallexample
15190
15191 @code{tdump} works by scanning the tracepoint's current collection
15192 actions and printing the value of each expression listed. So
15193 @code{tdump} can fail, if after a run, you change the tracepoint's
15194 actions to mention variables that were not collected during the run.
15195
15196 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15197 uses the collected value of @code{$pc} to distinguish between trace
15198 frames that were collected at the tracepoint hit, and frames that were
15199 collected while stepping. This allows it to correctly choose whether
15200 to display the basic list of collections, or the collections from the
15201 body of the while-stepping loop. However, if @code{$pc} was not collected,
15202 then @code{tdump} will always attempt to dump using the basic collection
15203 list, and may fail if a while-stepping frame does not include all the
15204 same data that is collected at the tracepoint hit.
15205 @c This is getting pretty arcane, example would be good.
15206
15207 @node save tracepoints
15208 @subsection @code{save tracepoints @var{filename}}
15209 @kindex save tracepoints
15210 @kindex save-tracepoints
15211 @cindex save tracepoints for future sessions
15212
15213 This command saves all current tracepoint definitions together with
15214 their actions and passcounts, into a file @file{@var{filename}}
15215 suitable for use in a later debugging session. To read the saved
15216 tracepoint definitions, use the @code{source} command (@pxref{Command
15217 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15218 alias for @w{@code{save tracepoints}}
15219
15220 @node Tracepoint Variables
15221 @section Convenience Variables for Tracepoints
15222 @cindex tracepoint variables
15223 @cindex convenience variables for tracepoints
15224
15225 @table @code
15226 @vindex $trace_frame
15227 @item (int) $trace_frame
15228 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15229 snapshot is selected.
15230
15231 @vindex $tracepoint
15232 @item (int) $tracepoint
15233 The tracepoint for the current trace snapshot.
15234
15235 @vindex $trace_line
15236 @item (int) $trace_line
15237 The line number for the current trace snapshot.
15238
15239 @vindex $trace_file
15240 @item (char []) $trace_file
15241 The source file for the current trace snapshot.
15242
15243 @vindex $trace_func
15244 @item (char []) $trace_func
15245 The name of the function containing @code{$tracepoint}.
15246 @end table
15247
15248 Note: @code{$trace_file} is not suitable for use in @code{printf},
15249 use @code{output} instead.
15250
15251 Here's a simple example of using these convenience variables for
15252 stepping through all the trace snapshots and printing some of their
15253 data. Note that these are not the same as trace state variables,
15254 which are managed by the target.
15255
15256 @smallexample
15257 (@value{GDBP}) @b{tfind start}
15258
15259 (@value{GDBP}) @b{while $trace_frame != -1}
15260 > output $trace_file
15261 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15262 > tfind
15263 > end
15264 @end smallexample
15265
15266 @node Trace Files
15267 @section Using Trace Files
15268 @cindex trace files
15269
15270 In some situations, the target running a trace experiment may no
15271 longer be available; perhaps it crashed, or the hardware was needed
15272 for a different activity. To handle these cases, you can arrange to
15273 dump the trace data into a file, and later use that file as a source
15274 of trace data, via the @code{target tfile} command.
15275
15276 @table @code
15277
15278 @kindex tsave
15279 @item tsave [ -r ] @var{filename}
15280 @itemx tsave [-ctf] @var{dirname}
15281 Save the trace data to @var{filename}. By default, this command
15282 assumes that @var{filename} refers to the host filesystem, so if
15283 necessary @value{GDBN} will copy raw trace data up from the target and
15284 then save it. If the target supports it, you can also supply the
15285 optional argument @code{-r} (``remote'') to direct the target to save
15286 the data directly into @var{filename} in its own filesystem, which may be
15287 more efficient if the trace buffer is very large. (Note, however, that
15288 @code{target tfile} can only read from files accessible to the host.)
15289 By default, this command will save trace frame in tfile format.
15290 You can supply the optional argument @code{-ctf} to save data in CTF
15291 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15292 that can be shared by multiple debugging and tracing tools. Please go to
15293 @indicateurl{http://www.efficios.com/ctf} to get more information.
15294
15295 @kindex target tfile
15296 @kindex tfile
15297 @kindex target ctf
15298 @kindex ctf
15299 @item target tfile @var{filename}
15300 @itemx target ctf @var{dirname}
15301 Use the file named @var{filename} or directory named @var{dirname} as
15302 a source of trace data. Commands that examine data work as they do with
15303 a live target, but it is not possible to run any new trace experiments.
15304 @code{tstatus} will report the state of the trace run at the moment
15305 the data was saved, as well as the current trace frame you are examining.
15306 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15307 the host.
15308
15309 @smallexample
15310 (@value{GDBP}) target ctf ctf.ctf
15311 (@value{GDBP}) tfind
15312 Found trace frame 0, tracepoint 2
15313 39 ++a; /* set tracepoint 1 here */
15314 (@value{GDBP}) tdump
15315 Data collected at tracepoint 2, trace frame 0:
15316 i = 0
15317 a = 0
15318 b = 1 '\001'
15319 c = @{"123", "456", "789", "123", "456", "789"@}
15320 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15321 (@value{GDBP}) p b
15322 $1 = 1
15323 @end smallexample
15324
15325 @end table
15326
15327 @node Overlays
15328 @chapter Debugging Programs That Use Overlays
15329 @cindex overlays
15330
15331 If your program is too large to fit completely in your target system's
15332 memory, you can sometimes use @dfn{overlays} to work around this
15333 problem. @value{GDBN} provides some support for debugging programs that
15334 use overlays.
15335
15336 @menu
15337 * How Overlays Work:: A general explanation of overlays.
15338 * Overlay Commands:: Managing overlays in @value{GDBN}.
15339 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15340 mapped by asking the inferior.
15341 * Overlay Sample Program:: A sample program using overlays.
15342 @end menu
15343
15344 @node How Overlays Work
15345 @section How Overlays Work
15346 @cindex mapped overlays
15347 @cindex unmapped overlays
15348 @cindex load address, overlay's
15349 @cindex mapped address
15350 @cindex overlay area
15351
15352 Suppose you have a computer whose instruction address space is only 64
15353 kilobytes long, but which has much more memory which can be accessed by
15354 other means: special instructions, segment registers, or memory
15355 management hardware, for example. Suppose further that you want to
15356 adapt a program which is larger than 64 kilobytes to run on this system.
15357
15358 One solution is to identify modules of your program which are relatively
15359 independent, and need not call each other directly; call these modules
15360 @dfn{overlays}. Separate the overlays from the main program, and place
15361 their machine code in the larger memory. Place your main program in
15362 instruction memory, but leave at least enough space there to hold the
15363 largest overlay as well.
15364
15365 Now, to call a function located in an overlay, you must first copy that
15366 overlay's machine code from the large memory into the space set aside
15367 for it in the instruction memory, and then jump to its entry point
15368 there.
15369
15370 @c NB: In the below the mapped area's size is greater or equal to the
15371 @c size of all overlays. This is intentional to remind the developer
15372 @c that overlays don't necessarily need to be the same size.
15373
15374 @smallexample
15375 @group
15376 Data Instruction Larger
15377 Address Space Address Space Address Space
15378 +-----------+ +-----------+ +-----------+
15379 | | | | | |
15380 +-----------+ +-----------+ +-----------+<-- overlay 1
15381 | program | | main | .----| overlay 1 | load address
15382 | variables | | program | | +-----------+
15383 | and heap | | | | | |
15384 +-----------+ | | | +-----------+<-- overlay 2
15385 | | +-----------+ | | | load address
15386 +-----------+ | | | .-| overlay 2 |
15387 | | | | | |
15388 mapped --->+-----------+ | | +-----------+
15389 address | | | | | |
15390 | overlay | <-' | | |
15391 | area | <---' +-----------+<-- overlay 3
15392 | | <---. | | load address
15393 +-----------+ `--| overlay 3 |
15394 | | | |
15395 +-----------+ | |
15396 +-----------+
15397 | |
15398 +-----------+
15399
15400 @anchor{A code overlay}A code overlay
15401 @end group
15402 @end smallexample
15403
15404 The diagram (@pxref{A code overlay}) shows a system with separate data
15405 and instruction address spaces. To map an overlay, the program copies
15406 its code from the larger address space to the instruction address space.
15407 Since the overlays shown here all use the same mapped address, only one
15408 may be mapped at a time. For a system with a single address space for
15409 data and instructions, the diagram would be similar, except that the
15410 program variables and heap would share an address space with the main
15411 program and the overlay area.
15412
15413 An overlay loaded into instruction memory and ready for use is called a
15414 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15415 instruction memory. An overlay not present (or only partially present)
15416 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15417 is its address in the larger memory. The mapped address is also called
15418 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15419 called the @dfn{load memory address}, or @dfn{LMA}.
15420
15421 Unfortunately, overlays are not a completely transparent way to adapt a
15422 program to limited instruction memory. They introduce a new set of
15423 global constraints you must keep in mind as you design your program:
15424
15425 @itemize @bullet
15426
15427 @item
15428 Before calling or returning to a function in an overlay, your program
15429 must make sure that overlay is actually mapped. Otherwise, the call or
15430 return will transfer control to the right address, but in the wrong
15431 overlay, and your program will probably crash.
15432
15433 @item
15434 If the process of mapping an overlay is expensive on your system, you
15435 will need to choose your overlays carefully to minimize their effect on
15436 your program's performance.
15437
15438 @item
15439 The executable file you load onto your system must contain each
15440 overlay's instructions, appearing at the overlay's load address, not its
15441 mapped address. However, each overlay's instructions must be relocated
15442 and its symbols defined as if the overlay were at its mapped address.
15443 You can use GNU linker scripts to specify different load and relocation
15444 addresses for pieces of your program; see @ref{Overlay Description,,,
15445 ld.info, Using ld: the GNU linker}.
15446
15447 @item
15448 The procedure for loading executable files onto your system must be able
15449 to load their contents into the larger address space as well as the
15450 instruction and data spaces.
15451
15452 @end itemize
15453
15454 The overlay system described above is rather simple, and could be
15455 improved in many ways:
15456
15457 @itemize @bullet
15458
15459 @item
15460 If your system has suitable bank switch registers or memory management
15461 hardware, you could use those facilities to make an overlay's load area
15462 contents simply appear at their mapped address in instruction space.
15463 This would probably be faster than copying the overlay to its mapped
15464 area in the usual way.
15465
15466 @item
15467 If your overlays are small enough, you could set aside more than one
15468 overlay area, and have more than one overlay mapped at a time.
15469
15470 @item
15471 You can use overlays to manage data, as well as instructions. In
15472 general, data overlays are even less transparent to your design than
15473 code overlays: whereas code overlays only require care when you call or
15474 return to functions, data overlays require care every time you access
15475 the data. Also, if you change the contents of a data overlay, you
15476 must copy its contents back out to its load address before you can copy a
15477 different data overlay into the same mapped area.
15478
15479 @end itemize
15480
15481
15482 @node Overlay Commands
15483 @section Overlay Commands
15484
15485 To use @value{GDBN}'s overlay support, each overlay in your program must
15486 correspond to a separate section of the executable file. The section's
15487 virtual memory address and load memory address must be the overlay's
15488 mapped and load addresses. Identifying overlays with sections allows
15489 @value{GDBN} to determine the appropriate address of a function or
15490 variable, depending on whether the overlay is mapped or not.
15491
15492 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15493 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15494
15495 @table @code
15496 @item overlay off
15497 @kindex overlay
15498 Disable @value{GDBN}'s overlay support. When overlay support is
15499 disabled, @value{GDBN} assumes that all functions and variables are
15500 always present at their mapped addresses. By default, @value{GDBN}'s
15501 overlay support is disabled.
15502
15503 @item overlay manual
15504 @cindex manual overlay debugging
15505 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15506 relies on you to tell it which overlays are mapped, and which are not,
15507 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15508 commands described below.
15509
15510 @item overlay map-overlay @var{overlay}
15511 @itemx overlay map @var{overlay}
15512 @cindex map an overlay
15513 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15514 be the name of the object file section containing the overlay. When an
15515 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15516 functions and variables at their mapped addresses. @value{GDBN} assumes
15517 that any other overlays whose mapped ranges overlap that of
15518 @var{overlay} are now unmapped.
15519
15520 @item overlay unmap-overlay @var{overlay}
15521 @itemx overlay unmap @var{overlay}
15522 @cindex unmap an overlay
15523 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15524 must be the name of the object file section containing the overlay.
15525 When an overlay is unmapped, @value{GDBN} assumes it can find the
15526 overlay's functions and variables at their load addresses.
15527
15528 @item overlay auto
15529 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15530 consults a data structure the overlay manager maintains in the inferior
15531 to see which overlays are mapped. For details, see @ref{Automatic
15532 Overlay Debugging}.
15533
15534 @item overlay load-target
15535 @itemx overlay load
15536 @cindex reloading the overlay table
15537 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15538 re-reads the table @value{GDBN} automatically each time the inferior
15539 stops, so this command should only be necessary if you have changed the
15540 overlay mapping yourself using @value{GDBN}. This command is only
15541 useful when using automatic overlay debugging.
15542
15543 @item overlay list-overlays
15544 @itemx overlay list
15545 @cindex listing mapped overlays
15546 Display a list of the overlays currently mapped, along with their mapped
15547 addresses, load addresses, and sizes.
15548
15549 @end table
15550
15551 Normally, when @value{GDBN} prints a code address, it includes the name
15552 of the function the address falls in:
15553
15554 @smallexample
15555 (@value{GDBP}) print main
15556 $3 = @{int ()@} 0x11a0 <main>
15557 @end smallexample
15558 @noindent
15559 When overlay debugging is enabled, @value{GDBN} recognizes code in
15560 unmapped overlays, and prints the names of unmapped functions with
15561 asterisks around them. For example, if @code{foo} is a function in an
15562 unmapped overlay, @value{GDBN} prints it this way:
15563
15564 @smallexample
15565 (@value{GDBP}) overlay list
15566 No sections are mapped.
15567 (@value{GDBP}) print foo
15568 $5 = @{int (int)@} 0x100000 <*foo*>
15569 @end smallexample
15570 @noindent
15571 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15572 name normally:
15573
15574 @smallexample
15575 (@value{GDBP}) overlay list
15576 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15577 mapped at 0x1016 - 0x104a
15578 (@value{GDBP}) print foo
15579 $6 = @{int (int)@} 0x1016 <foo>
15580 @end smallexample
15581
15582 When overlay debugging is enabled, @value{GDBN} can find the correct
15583 address for functions and variables in an overlay, whether or not the
15584 overlay is mapped. This allows most @value{GDBN} commands, like
15585 @code{break} and @code{disassemble}, to work normally, even on unmapped
15586 code. However, @value{GDBN}'s breakpoint support has some limitations:
15587
15588 @itemize @bullet
15589 @item
15590 @cindex breakpoints in overlays
15591 @cindex overlays, setting breakpoints in
15592 You can set breakpoints in functions in unmapped overlays, as long as
15593 @value{GDBN} can write to the overlay at its load address.
15594 @item
15595 @value{GDBN} can not set hardware or simulator-based breakpoints in
15596 unmapped overlays. However, if you set a breakpoint at the end of your
15597 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15598 you are using manual overlay management), @value{GDBN} will re-set its
15599 breakpoints properly.
15600 @end itemize
15601
15602
15603 @node Automatic Overlay Debugging
15604 @section Automatic Overlay Debugging
15605 @cindex automatic overlay debugging
15606
15607 @value{GDBN} can automatically track which overlays are mapped and which
15608 are not, given some simple co-operation from the overlay manager in the
15609 inferior. If you enable automatic overlay debugging with the
15610 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15611 looks in the inferior's memory for certain variables describing the
15612 current state of the overlays.
15613
15614 Here are the variables your overlay manager must define to support
15615 @value{GDBN}'s automatic overlay debugging:
15616
15617 @table @asis
15618
15619 @item @code{_ovly_table}:
15620 This variable must be an array of the following structures:
15621
15622 @smallexample
15623 struct
15624 @{
15625 /* The overlay's mapped address. */
15626 unsigned long vma;
15627
15628 /* The size of the overlay, in bytes. */
15629 unsigned long size;
15630
15631 /* The overlay's load address. */
15632 unsigned long lma;
15633
15634 /* Non-zero if the overlay is currently mapped;
15635 zero otherwise. */
15636 unsigned long mapped;
15637 @}
15638 @end smallexample
15639
15640 @item @code{_novlys}:
15641 This variable must be a four-byte signed integer, holding the total
15642 number of elements in @code{_ovly_table}.
15643
15644 @end table
15645
15646 To decide whether a particular overlay is mapped or not, @value{GDBN}
15647 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15648 @code{lma} members equal the VMA and LMA of the overlay's section in the
15649 executable file. When @value{GDBN} finds a matching entry, it consults
15650 the entry's @code{mapped} member to determine whether the overlay is
15651 currently mapped.
15652
15653 In addition, your overlay manager may define a function called
15654 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15655 will silently set a breakpoint there. If the overlay manager then
15656 calls this function whenever it has changed the overlay table, this
15657 will enable @value{GDBN} to accurately keep track of which overlays
15658 are in program memory, and update any breakpoints that may be set
15659 in overlays. This will allow breakpoints to work even if the
15660 overlays are kept in ROM or other non-writable memory while they
15661 are not being executed.
15662
15663 @node Overlay Sample Program
15664 @section Overlay Sample Program
15665 @cindex overlay example program
15666
15667 When linking a program which uses overlays, you must place the overlays
15668 at their load addresses, while relocating them to run at their mapped
15669 addresses. To do this, you must write a linker script (@pxref{Overlay
15670 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15671 since linker scripts are specific to a particular host system, target
15672 architecture, and target memory layout, this manual cannot provide
15673 portable sample code demonstrating @value{GDBN}'s overlay support.
15674
15675 However, the @value{GDBN} source distribution does contain an overlaid
15676 program, with linker scripts for a few systems, as part of its test
15677 suite. The program consists of the following files from
15678 @file{gdb/testsuite/gdb.base}:
15679
15680 @table @file
15681 @item overlays.c
15682 The main program file.
15683 @item ovlymgr.c
15684 A simple overlay manager, used by @file{overlays.c}.
15685 @item foo.c
15686 @itemx bar.c
15687 @itemx baz.c
15688 @itemx grbx.c
15689 Overlay modules, loaded and used by @file{overlays.c}.
15690 @item d10v.ld
15691 @itemx m32r.ld
15692 Linker scripts for linking the test program on the @code{d10v-elf}
15693 and @code{m32r-elf} targets.
15694 @end table
15695
15696 You can build the test program using the @code{d10v-elf} GCC
15697 cross-compiler like this:
15698
15699 @smallexample
15700 $ d10v-elf-gcc -g -c overlays.c
15701 $ d10v-elf-gcc -g -c ovlymgr.c
15702 $ d10v-elf-gcc -g -c foo.c
15703 $ d10v-elf-gcc -g -c bar.c
15704 $ d10v-elf-gcc -g -c baz.c
15705 $ d10v-elf-gcc -g -c grbx.c
15706 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15707 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15708 @end smallexample
15709
15710 The build process is identical for any other architecture, except that
15711 you must substitute the appropriate compiler and linker script for the
15712 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15713
15714
15715 @node Languages
15716 @chapter Using @value{GDBN} with Different Languages
15717 @cindex languages
15718
15719 Although programming languages generally have common aspects, they are
15720 rarely expressed in the same manner. For instance, in ANSI C,
15721 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15722 Modula-2, it is accomplished by @code{p^}. Values can also be
15723 represented (and displayed) differently. Hex numbers in C appear as
15724 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15725
15726 @cindex working language
15727 Language-specific information is built into @value{GDBN} for some languages,
15728 allowing you to express operations like the above in your program's
15729 native language, and allowing @value{GDBN} to output values in a manner
15730 consistent with the syntax of your program's native language. The
15731 language you use to build expressions is called the @dfn{working
15732 language}.
15733
15734 @menu
15735 * Setting:: Switching between source languages
15736 * Show:: Displaying the language
15737 * Checks:: Type and range checks
15738 * Supported Languages:: Supported languages
15739 * Unsupported Languages:: Unsupported languages
15740 @end menu
15741
15742 @node Setting
15743 @section Switching Between Source Languages
15744
15745 There are two ways to control the working language---either have @value{GDBN}
15746 set it automatically, or select it manually yourself. You can use the
15747 @code{set language} command for either purpose. On startup, @value{GDBN}
15748 defaults to setting the language automatically. The working language is
15749 used to determine how expressions you type are interpreted, how values
15750 are printed, etc.
15751
15752 In addition to the working language, every source file that
15753 @value{GDBN} knows about has its own working language. For some object
15754 file formats, the compiler might indicate which language a particular
15755 source file is in. However, most of the time @value{GDBN} infers the
15756 language from the name of the file. The language of a source file
15757 controls whether C@t{++} names are demangled---this way @code{backtrace} can
15758 show each frame appropriately for its own language. There is no way to
15759 set the language of a source file from within @value{GDBN}, but you can
15760 set the language associated with a filename extension. @xref{Show, ,
15761 Displaying the Language}.
15762
15763 This is most commonly a problem when you use a program, such
15764 as @code{cfront} or @code{f2c}, that generates C but is written in
15765 another language. In that case, make the
15766 program use @code{#line} directives in its C output; that way
15767 @value{GDBN} will know the correct language of the source code of the original
15768 program, and will display that source code, not the generated C code.
15769
15770 @menu
15771 * Filenames:: Filename extensions and languages.
15772 * Manually:: Setting the working language manually
15773 * Automatically:: Having @value{GDBN} infer the source language
15774 @end menu
15775
15776 @node Filenames
15777 @subsection List of Filename Extensions and Languages
15778
15779 If a source file name ends in one of the following extensions, then
15780 @value{GDBN} infers that its language is the one indicated.
15781
15782 @table @file
15783 @item .ada
15784 @itemx .ads
15785 @itemx .adb
15786 @itemx .a
15787 Ada source file.
15788
15789 @item .c
15790 C source file
15791
15792 @item .C
15793 @itemx .cc
15794 @itemx .cp
15795 @itemx .cpp
15796 @itemx .cxx
15797 @itemx .c++
15798 C@t{++} source file
15799
15800 @item .d
15801 D source file
15802
15803 @item .m
15804 Objective-C source file
15805
15806 @item .f
15807 @itemx .F
15808 Fortran source file
15809
15810 @item .mod
15811 Modula-2 source file
15812
15813 @item .s
15814 @itemx .S
15815 Assembler source file. This actually behaves almost like C, but
15816 @value{GDBN} does not skip over function prologues when stepping.
15817 @end table
15818
15819 In addition, you may set the language associated with a filename
15820 extension. @xref{Show, , Displaying the Language}.
15821
15822 @node Manually
15823 @subsection Setting the Working Language
15824
15825 If you allow @value{GDBN} to set the language automatically,
15826 expressions are interpreted the same way in your debugging session and
15827 your program.
15828
15829 @kindex set language
15830 If you wish, you may set the language manually. To do this, issue the
15831 command @samp{set language @var{lang}}, where @var{lang} is the name of
15832 a language, such as
15833 @code{c} or @code{modula-2}.
15834 For a list of the supported languages, type @samp{set language}.
15835
15836 Setting the language manually prevents @value{GDBN} from updating the working
15837 language automatically. This can lead to confusion if you try
15838 to debug a program when the working language is not the same as the
15839 source language, when an expression is acceptable to both
15840 languages---but means different things. For instance, if the current
15841 source file were written in C, and @value{GDBN} was parsing Modula-2, a
15842 command such as:
15843
15844 @smallexample
15845 print a = b + c
15846 @end smallexample
15847
15848 @noindent
15849 might not have the effect you intended. In C, this means to add
15850 @code{b} and @code{c} and place the result in @code{a}. The result
15851 printed would be the value of @code{a}. In Modula-2, this means to compare
15852 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
15853
15854 @node Automatically
15855 @subsection Having @value{GDBN} Infer the Source Language
15856
15857 To have @value{GDBN} set the working language automatically, use
15858 @samp{set language local} or @samp{set language auto}. @value{GDBN}
15859 then infers the working language. That is, when your program stops in a
15860 frame (usually by encountering a breakpoint), @value{GDBN} sets the
15861 working language to the language recorded for the function in that
15862 frame. If the language for a frame is unknown (that is, if the function
15863 or block corresponding to the frame was defined in a source file that
15864 does not have a recognized extension), the current working language is
15865 not changed, and @value{GDBN} issues a warning.
15866
15867 This may not seem necessary for most programs, which are written
15868 entirely in one source language. However, program modules and libraries
15869 written in one source language can be used by a main program written in
15870 a different source language. Using @samp{set language auto} in this
15871 case frees you from having to set the working language manually.
15872
15873 @node Show
15874 @section Displaying the Language
15875
15876 The following commands help you find out which language is the
15877 working language, and also what language source files were written in.
15878
15879 @table @code
15880 @item show language
15881 @anchor{show language}
15882 @kindex show language
15883 Display the current working language. This is the
15884 language you can use with commands such as @code{print} to
15885 build and compute expressions that may involve variables in your program.
15886
15887 @item info frame
15888 @kindex info frame@r{, show the source language}
15889 Display the source language for this frame. This language becomes the
15890 working language if you use an identifier from this frame.
15891 @xref{Frame Info, ,Information about a Frame}, to identify the other
15892 information listed here.
15893
15894 @item info source
15895 @kindex info source@r{, show the source language}
15896 Display the source language of this source file.
15897 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
15898 information listed here.
15899 @end table
15900
15901 In unusual circumstances, you may have source files with extensions
15902 not in the standard list. You can then set the extension associated
15903 with a language explicitly:
15904
15905 @table @code
15906 @item set extension-language @var{ext} @var{language}
15907 @kindex set extension-language
15908 Tell @value{GDBN} that source files with extension @var{ext} are to be
15909 assumed as written in the source language @var{language}.
15910
15911 @item info extensions
15912 @kindex info extensions
15913 List all the filename extensions and the associated languages.
15914 @end table
15915
15916 @node Checks
15917 @section Type and Range Checking
15918
15919 Some languages are designed to guard you against making seemingly common
15920 errors through a series of compile- and run-time checks. These include
15921 checking the type of arguments to functions and operators and making
15922 sure mathematical overflows are caught at run time. Checks such as
15923 these help to ensure a program's correctness once it has been compiled
15924 by eliminating type mismatches and providing active checks for range
15925 errors when your program is running.
15926
15927 By default @value{GDBN} checks for these errors according to the
15928 rules of the current source language. Although @value{GDBN} does not check
15929 the statements in your program, it can check expressions entered directly
15930 into @value{GDBN} for evaluation via the @code{print} command, for example.
15931
15932 @menu
15933 * Type Checking:: An overview of type checking
15934 * Range Checking:: An overview of range checking
15935 @end menu
15936
15937 @cindex type checking
15938 @cindex checks, type
15939 @node Type Checking
15940 @subsection An Overview of Type Checking
15941
15942 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
15943 arguments to operators and functions have to be of the correct type,
15944 otherwise an error occurs. These checks prevent type mismatch
15945 errors from ever causing any run-time problems. For example,
15946
15947 @smallexample
15948 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15949
15950 (@value{GDBP}) print obj.my_method (0)
15951 $1 = 2
15952 @exdent but
15953 (@value{GDBP}) print obj.my_method (0x1234)
15954 Cannot resolve method klass::my_method to any overloaded instance
15955 @end smallexample
15956
15957 The second example fails because in C@t{++} the integer constant
15958 @samp{0x1234} is not type-compatible with the pointer parameter type.
15959
15960 For the expressions you use in @value{GDBN} commands, you can tell
15961 @value{GDBN} to not enforce strict type checking or
15962 to treat any mismatches as errors and abandon the expression;
15963 When type checking is disabled, @value{GDBN} successfully evaluates
15964 expressions like the second example above.
15965
15966 Even if type checking is off, there may be other reasons
15967 related to type that prevent @value{GDBN} from evaluating an expression.
15968 For instance, @value{GDBN} does not know how to add an @code{int} and
15969 a @code{struct foo}. These particular type errors have nothing to do
15970 with the language in use and usually arise from expressions which make
15971 little sense to evaluate anyway.
15972
15973 @value{GDBN} provides some additional commands for controlling type checking:
15974
15975 @kindex set check type
15976 @kindex show check type
15977 @table @code
15978 @item set check type on
15979 @itemx set check type off
15980 Set strict type checking on or off. If any type mismatches occur in
15981 evaluating an expression while type checking is on, @value{GDBN} prints a
15982 message and aborts evaluation of the expression.
15983
15984 @item show check type
15985 Show the current setting of type checking and whether @value{GDBN}
15986 is enforcing strict type checking rules.
15987 @end table
15988
15989 @cindex range checking
15990 @cindex checks, range
15991 @node Range Checking
15992 @subsection An Overview of Range Checking
15993
15994 In some languages (such as Modula-2), it is an error to exceed the
15995 bounds of a type; this is enforced with run-time checks. Such range
15996 checking is meant to ensure program correctness by making sure
15997 computations do not overflow, or indices on an array element access do
15998 not exceed the bounds of the array.
15999
16000 For expressions you use in @value{GDBN} commands, you can tell
16001 @value{GDBN} to treat range errors in one of three ways: ignore them,
16002 always treat them as errors and abandon the expression, or issue
16003 warnings but evaluate the expression anyway.
16004
16005 A range error can result from numerical overflow, from exceeding an
16006 array index bound, or when you type a constant that is not a member
16007 of any type. Some languages, however, do not treat overflows as an
16008 error. In many implementations of C, mathematical overflow causes the
16009 result to ``wrap around'' to lower values---for example, if @var{m} is
16010 the largest integer value, and @var{s} is the smallest, then
16011
16012 @smallexample
16013 @var{m} + 1 @result{} @var{s}
16014 @end smallexample
16015
16016 This, too, is specific to individual languages, and in some cases
16017 specific to individual compilers or machines. @xref{Supported Languages, ,
16018 Supported Languages}, for further details on specific languages.
16019
16020 @value{GDBN} provides some additional commands for controlling the range checker:
16021
16022 @kindex set check range
16023 @kindex show check range
16024 @table @code
16025 @item set check range auto
16026 Set range checking on or off based on the current working language.
16027 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16028 each language.
16029
16030 @item set check range on
16031 @itemx set check range off
16032 Set range checking on or off, overriding the default setting for the
16033 current working language. A warning is issued if the setting does not
16034 match the language default. If a range error occurs and range checking is on,
16035 then a message is printed and evaluation of the expression is aborted.
16036
16037 @item set check range warn
16038 Output messages when the @value{GDBN} range checker detects a range error,
16039 but attempt to evaluate the expression anyway. Evaluating the
16040 expression may still be impossible for other reasons, such as accessing
16041 memory that the process does not own (a typical example from many Unix
16042 systems).
16043
16044 @item show range
16045 Show the current setting of the range checker, and whether or not it is
16046 being set automatically by @value{GDBN}.
16047 @end table
16048
16049 @node Supported Languages
16050 @section Supported Languages
16051
16052 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16053 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16054 @c This is false ...
16055 Some @value{GDBN} features may be used in expressions regardless of the
16056 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16057 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16058 ,Expressions}) can be used with the constructs of any supported
16059 language.
16060
16061 The following sections detail to what degree each source language is
16062 supported by @value{GDBN}. These sections are not meant to be language
16063 tutorials or references, but serve only as a reference guide to what the
16064 @value{GDBN} expression parser accepts, and what input and output
16065 formats should look like for different languages. There are many good
16066 books written on each of these languages; please look to these for a
16067 language reference or tutorial.
16068
16069 @menu
16070 * C:: C and C@t{++}
16071 * D:: D
16072 * Go:: Go
16073 * Objective-C:: Objective-C
16074 * OpenCL C:: OpenCL C
16075 * Fortran:: Fortran
16076 * Pascal:: Pascal
16077 * Rust:: Rust
16078 * Modula-2:: Modula-2
16079 * Ada:: Ada
16080 @end menu
16081
16082 @node C
16083 @subsection C and C@t{++}
16084
16085 @cindex C and C@t{++}
16086 @cindex expressions in C or C@t{++}
16087
16088 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16089 to both languages. Whenever this is the case, we discuss those languages
16090 together.
16091
16092 @cindex C@t{++}
16093 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16094 @cindex @sc{gnu} C@t{++}
16095 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16096 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16097 effectively, you must compile your C@t{++} programs with a supported
16098 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16099 compiler (@code{aCC}).
16100
16101 @menu
16102 * C Operators:: C and C@t{++} operators
16103 * C Constants:: C and C@t{++} constants
16104 * C Plus Plus Expressions:: C@t{++} expressions
16105 * C Defaults:: Default settings for C and C@t{++}
16106 * C Checks:: C and C@t{++} type and range checks
16107 * Debugging C:: @value{GDBN} and C
16108 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16109 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16110 @end menu
16111
16112 @node C Operators
16113 @subsubsection C and C@t{++} Operators
16114
16115 @cindex C and C@t{++} operators
16116
16117 Operators must be defined on values of specific types. For instance,
16118 @code{+} is defined on numbers, but not on structures. Operators are
16119 often defined on groups of types.
16120
16121 For the purposes of C and C@t{++}, the following definitions hold:
16122
16123 @itemize @bullet
16124
16125 @item
16126 @emph{Integral types} include @code{int} with any of its storage-class
16127 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16128
16129 @item
16130 @emph{Floating-point types} include @code{float}, @code{double}, and
16131 @code{long double} (if supported by the target platform).
16132
16133 @item
16134 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16135
16136 @item
16137 @emph{Scalar types} include all of the above.
16138
16139 @end itemize
16140
16141 @noindent
16142 The following operators are supported. They are listed here
16143 in order of increasing precedence:
16144
16145 @table @code
16146 @item ,
16147 The comma or sequencing operator. Expressions in a comma-separated list
16148 are evaluated from left to right, with the result of the entire
16149 expression being the last expression evaluated.
16150
16151 @item =
16152 Assignment. The value of an assignment expression is the value
16153 assigned. Defined on scalar types.
16154
16155 @item @var{op}=
16156 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16157 and translated to @w{@code{@var{a} = @var{a op b}}}.
16158 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16159 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16160 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16161
16162 @item ?:
16163 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16164 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16165 should be of an integral type.
16166
16167 @item ||
16168 Logical @sc{or}. Defined on integral types.
16169
16170 @item &&
16171 Logical @sc{and}. Defined on integral types.
16172
16173 @item |
16174 Bitwise @sc{or}. Defined on integral types.
16175
16176 @item ^
16177 Bitwise exclusive-@sc{or}. Defined on integral types.
16178
16179 @item &
16180 Bitwise @sc{and}. Defined on integral types.
16181
16182 @item ==@r{, }!=
16183 Equality and inequality. Defined on scalar types. The value of these
16184 expressions is 0 for false and non-zero for true.
16185
16186 @item <@r{, }>@r{, }<=@r{, }>=
16187 Less than, greater than, less than or equal, greater than or equal.
16188 Defined on scalar types. The value of these expressions is 0 for false
16189 and non-zero for true.
16190
16191 @item <<@r{, }>>
16192 left shift, and right shift. Defined on integral types.
16193
16194 @item @@
16195 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16196
16197 @item +@r{, }-
16198 Addition and subtraction. Defined on integral types, floating-point types and
16199 pointer types.
16200
16201 @item *@r{, }/@r{, }%
16202 Multiplication, division, and modulus. Multiplication and division are
16203 defined on integral and floating-point types. Modulus is defined on
16204 integral types.
16205
16206 @item ++@r{, }--
16207 Increment and decrement. When appearing before a variable, the
16208 operation is performed before the variable is used in an expression;
16209 when appearing after it, the variable's value is used before the
16210 operation takes place.
16211
16212 @item *
16213 Pointer dereferencing. Defined on pointer types. Same precedence as
16214 @code{++}.
16215
16216 @item &
16217 Address operator. Defined on variables. Same precedence as @code{++}.
16218
16219 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16220 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16221 to examine the address
16222 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16223 stored.
16224
16225 @item -
16226 Negative. Defined on integral and floating-point types. Same
16227 precedence as @code{++}.
16228
16229 @item !
16230 Logical negation. Defined on integral types. Same precedence as
16231 @code{++}.
16232
16233 @item ~
16234 Bitwise complement operator. Defined on integral types. Same precedence as
16235 @code{++}.
16236
16237
16238 @item .@r{, }->
16239 Structure member, and pointer-to-structure member. For convenience,
16240 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16241 pointer based on the stored type information.
16242 Defined on @code{struct} and @code{union} data.
16243
16244 @item .*@r{, }->*
16245 Dereferences of pointers to members.
16246
16247 @item []
16248 Array indexing. @code{@var{a}[@var{i}]} is defined as
16249 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16250
16251 @item ()
16252 Function parameter list. Same precedence as @code{->}.
16253
16254 @item ::
16255 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16256 and @code{class} types.
16257
16258 @item ::
16259 Doubled colons also represent the @value{GDBN} scope operator
16260 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16261 above.
16262 @end table
16263
16264 If an operator is redefined in the user code, @value{GDBN} usually
16265 attempts to invoke the redefined version instead of using the operator's
16266 predefined meaning.
16267
16268 @node C Constants
16269 @subsubsection C and C@t{++} Constants
16270
16271 @cindex C and C@t{++} constants
16272
16273 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16274 following ways:
16275
16276 @itemize @bullet
16277 @item
16278 Integer constants are a sequence of digits. Octal constants are
16279 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16280 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16281 @samp{l}, specifying that the constant should be treated as a
16282 @code{long} value.
16283
16284 @item
16285 Floating point constants are a sequence of digits, followed by a decimal
16286 point, followed by a sequence of digits, and optionally followed by an
16287 exponent. An exponent is of the form:
16288 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16289 sequence of digits. The @samp{+} is optional for positive exponents.
16290 A floating-point constant may also end with a letter @samp{f} or
16291 @samp{F}, specifying that the constant should be treated as being of
16292 the @code{float} (as opposed to the default @code{double}) type; or with
16293 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16294 constant.
16295
16296 @item
16297 Enumerated constants consist of enumerated identifiers, or their
16298 integral equivalents.
16299
16300 @item
16301 Character constants are a single character surrounded by single quotes
16302 (@code{'}), or a number---the ordinal value of the corresponding character
16303 (usually its @sc{ascii} value). Within quotes, the single character may
16304 be represented by a letter or by @dfn{escape sequences}, which are of
16305 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16306 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16307 @samp{@var{x}} is a predefined special character---for example,
16308 @samp{\n} for newline.
16309
16310 Wide character constants can be written by prefixing a character
16311 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16312 form of @samp{x}. The target wide character set is used when
16313 computing the value of this constant (@pxref{Character Sets}).
16314
16315 @item
16316 String constants are a sequence of character constants surrounded by
16317 double quotes (@code{"}). Any valid character constant (as described
16318 above) may appear. Double quotes within the string must be preceded by
16319 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16320 characters.
16321
16322 Wide string constants can be written by prefixing a string constant
16323 with @samp{L}, as in C. The target wide character set is used when
16324 computing the value of this constant (@pxref{Character Sets}).
16325
16326 @item
16327 Pointer constants are an integral value. You can also write pointers
16328 to constants using the C operator @samp{&}.
16329
16330 @item
16331 Array constants are comma-separated lists surrounded by braces @samp{@{}
16332 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16333 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16334 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16335 @end itemize
16336
16337 @node C Plus Plus Expressions
16338 @subsubsection C@t{++} Expressions
16339
16340 @cindex expressions in C@t{++}
16341 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16342
16343 @cindex debugging C@t{++} programs
16344 @cindex C@t{++} compilers
16345 @cindex debug formats and C@t{++}
16346 @cindex @value{NGCC} and C@t{++}
16347 @quotation
16348 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16349 the proper compiler and the proper debug format. Currently,
16350 @value{GDBN} works best when debugging C@t{++} code that is compiled
16351 with the most recent version of @value{NGCC} possible. The DWARF
16352 debugging format is preferred; @value{NGCC} defaults to this on most
16353 popular platforms. Other compilers and/or debug formats are likely to
16354 work badly or not at all when using @value{GDBN} to debug C@t{++}
16355 code. @xref{Compilation}.
16356 @end quotation
16357
16358 @enumerate
16359
16360 @cindex member functions
16361 @item
16362 Member function calls are allowed; you can use expressions like
16363
16364 @smallexample
16365 count = aml->GetOriginal(x, y)
16366 @end smallexample
16367
16368 @vindex this@r{, inside C@t{++} member functions}
16369 @cindex namespace in C@t{++}
16370 @item
16371 While a member function is active (in the selected stack frame), your
16372 expressions have the same namespace available as the member function;
16373 that is, @value{GDBN} allows implicit references to the class instance
16374 pointer @code{this} following the same rules as C@t{++}. @code{using}
16375 declarations in the current scope are also respected by @value{GDBN}.
16376
16377 @cindex call overloaded functions
16378 @cindex overloaded functions, calling
16379 @cindex type conversions in C@t{++}
16380 @item
16381 You can call overloaded functions; @value{GDBN} resolves the function
16382 call to the right definition, with some restrictions. @value{GDBN} does not
16383 perform overload resolution involving user-defined type conversions,
16384 calls to constructors, or instantiations of templates that do not exist
16385 in the program. It also cannot handle ellipsis argument lists or
16386 default arguments.
16387
16388 It does perform integral conversions and promotions, floating-point
16389 promotions, arithmetic conversions, pointer conversions, conversions of
16390 class objects to base classes, and standard conversions such as those of
16391 functions or arrays to pointers; it requires an exact match on the
16392 number of function arguments.
16393
16394 Overload resolution is always performed, unless you have specified
16395 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16396 ,@value{GDBN} Features for C@t{++}}.
16397
16398 You must specify @code{set overload-resolution off} in order to use an
16399 explicit function signature to call an overloaded function, as in
16400 @smallexample
16401 p 'foo(char,int)'('x', 13)
16402 @end smallexample
16403
16404 The @value{GDBN} command-completion facility can simplify this;
16405 see @ref{Completion, ,Command Completion}.
16406
16407 @cindex reference declarations
16408 @item
16409 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16410 references; you can use them in expressions just as you do in C@t{++}
16411 source---they are automatically dereferenced.
16412
16413 In the parameter list shown when @value{GDBN} displays a frame, the values of
16414 reference variables are not displayed (unlike other variables); this
16415 avoids clutter, since references are often used for large structures.
16416 The @emph{address} of a reference variable is always shown, unless
16417 you have specified @samp{set print address off}.
16418
16419 @item
16420 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16421 expressions can use it just as expressions in your program do. Since
16422 one scope may be defined in another, you can use @code{::} repeatedly if
16423 necessary, for example in an expression like
16424 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16425 resolving name scope by reference to source files, in both C and C@t{++}
16426 debugging (@pxref{Variables, ,Program Variables}).
16427
16428 @item
16429 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16430 specification.
16431 @end enumerate
16432
16433 @node C Defaults
16434 @subsubsection C and C@t{++} Defaults
16435
16436 @cindex C and C@t{++} defaults
16437
16438 If you allow @value{GDBN} to set range checking automatically, it
16439 defaults to @code{off} whenever the working language changes to
16440 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16441 selects the working language.
16442
16443 If you allow @value{GDBN} to set the language automatically, it
16444 recognizes source files whose names end with @file{.c}, @file{.C}, or
16445 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16446 these files, it sets the working language to C or C@t{++}.
16447 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16448 for further details.
16449
16450 @node C Checks
16451 @subsubsection C and C@t{++} Type and Range Checks
16452
16453 @cindex C and C@t{++} checks
16454
16455 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16456 checking is used. However, if you turn type checking off, @value{GDBN}
16457 will allow certain non-standard conversions, such as promoting integer
16458 constants to pointers.
16459
16460 Range checking, if turned on, is done on mathematical operations. Array
16461 indices are not checked, since they are often used to index a pointer
16462 that is not itself an array.
16463
16464 @node Debugging C
16465 @subsubsection @value{GDBN} and C
16466
16467 The @code{set print union} and @code{show print union} commands apply to
16468 the @code{union} type. When set to @samp{on}, any @code{union} that is
16469 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16470 appears as @samp{@{...@}}.
16471
16472 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16473 with pointers and a memory allocation function. @xref{Expressions,
16474 ,Expressions}.
16475
16476 @node Debugging C Plus Plus
16477 @subsubsection @value{GDBN} Features for C@t{++}
16478
16479 @cindex commands for C@t{++}
16480
16481 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16482 designed specifically for use with C@t{++}. Here is a summary:
16483
16484 @table @code
16485 @cindex break in overloaded functions
16486 @item @r{breakpoint menus}
16487 When you want a breakpoint in a function whose name is overloaded,
16488 @value{GDBN} has the capability to display a menu of possible breakpoint
16489 locations to help you specify which function definition you want.
16490 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16491
16492 @cindex overloading in C@t{++}
16493 @item rbreak @var{regex}
16494 Setting breakpoints using regular expressions is helpful for setting
16495 breakpoints on overloaded functions that are not members of any special
16496 classes.
16497 @xref{Set Breaks, ,Setting Breakpoints}.
16498
16499 @cindex C@t{++} exception handling
16500 @item catch throw
16501 @itemx catch rethrow
16502 @itemx catch catch
16503 Debug C@t{++} exception handling using these commands. @xref{Set
16504 Catchpoints, , Setting Catchpoints}.
16505
16506 @cindex inheritance
16507 @item ptype @var{typename}
16508 Print inheritance relationships as well as other information for type
16509 @var{typename}.
16510 @xref{Symbols, ,Examining the Symbol Table}.
16511
16512 @item info vtbl @var{expression}.
16513 The @code{info vtbl} command can be used to display the virtual
16514 method tables of the object computed by @var{expression}. This shows
16515 one entry per virtual table; there may be multiple virtual tables when
16516 multiple inheritance is in use.
16517
16518 @cindex C@t{++} demangling
16519 @item demangle @var{name}
16520 Demangle @var{name}.
16521 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16522
16523 @cindex C@t{++} symbol display
16524 @item set print demangle
16525 @itemx show print demangle
16526 @itemx set print asm-demangle
16527 @itemx show print asm-demangle
16528 Control whether C@t{++} symbols display in their source form, both when
16529 displaying code as C@t{++} source and when displaying disassemblies.
16530 @xref{Print Settings, ,Print Settings}.
16531
16532 @item set print object
16533 @itemx show print object
16534 Choose whether to print derived (actual) or declared types of objects.
16535 @xref{Print Settings, ,Print Settings}.
16536
16537 @item set print vtbl
16538 @itemx show print vtbl
16539 Control the format for printing virtual function tables.
16540 @xref{Print Settings, ,Print Settings}.
16541 (The @code{vtbl} commands do not work on programs compiled with the HP
16542 ANSI C@t{++} compiler (@code{aCC}).)
16543
16544 @kindex set overload-resolution
16545 @cindex overloaded functions, overload resolution
16546 @item set overload-resolution on
16547 Enable overload resolution for C@t{++} expression evaluation. The default
16548 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16549 and searches for a function whose signature matches the argument types,
16550 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16551 Expressions, ,C@t{++} Expressions}, for details).
16552 If it cannot find a match, it emits a message.
16553
16554 @item set overload-resolution off
16555 Disable overload resolution for C@t{++} expression evaluation. For
16556 overloaded functions that are not class member functions, @value{GDBN}
16557 chooses the first function of the specified name that it finds in the
16558 symbol table, whether or not its arguments are of the correct type. For
16559 overloaded functions that are class member functions, @value{GDBN}
16560 searches for a function whose signature @emph{exactly} matches the
16561 argument types.
16562
16563 @kindex show overload-resolution
16564 @item show overload-resolution
16565 Show the current setting of overload resolution.
16566
16567 @item @r{Overloaded symbol names}
16568 You can specify a particular definition of an overloaded symbol, using
16569 the same notation that is used to declare such symbols in C@t{++}: type
16570 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16571 also use the @value{GDBN} command-line word completion facilities to list the
16572 available choices, or to finish the type list for you.
16573 @xref{Completion,, Command Completion}, for details on how to do this.
16574
16575 @item @r{Breakpoints in functions with ABI tags}
16576
16577 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16578 correspond to changes in the ABI of a type, function, or variable that
16579 would not otherwise be reflected in a mangled name. See
16580 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16581 for more detail.
16582
16583 The ABI tags are visible in C@t{++} demangled names. For example, a
16584 function that returns a std::string:
16585
16586 @smallexample
16587 std::string function(int);
16588 @end smallexample
16589
16590 @noindent
16591 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16592 tag, and @value{GDBN} displays the symbol like this:
16593
16594 @smallexample
16595 function[abi:cxx11](int)
16596 @end smallexample
16597
16598 You can set a breakpoint on such functions simply as if they had no
16599 tag. For example:
16600
16601 @smallexample
16602 (gdb) b function(int)
16603 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16604 (gdb) info breakpoints
16605 Num Type Disp Enb Address What
16606 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16607 at main.cc:10
16608 @end smallexample
16609
16610 On the rare occasion you need to disambiguate between different ABI
16611 tags, you can do so by simply including the ABI tag in the function
16612 name, like:
16613
16614 @smallexample
16615 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16616 @end smallexample
16617 @end table
16618
16619 @node Decimal Floating Point
16620 @subsubsection Decimal Floating Point format
16621 @cindex decimal floating point format
16622
16623 @value{GDBN} can examine, set and perform computations with numbers in
16624 decimal floating point format, which in the C language correspond to the
16625 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16626 specified by the extension to support decimal floating-point arithmetic.
16627
16628 There are two encodings in use, depending on the architecture: BID (Binary
16629 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16630 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16631 configured target.
16632
16633 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16634 to manipulate decimal floating point numbers, it is not possible to convert
16635 (using a cast, for example) integers wider than 32-bit to decimal float.
16636
16637 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16638 point computations, error checking in decimal float operations ignores
16639 underflow, overflow and divide by zero exceptions.
16640
16641 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16642 to inspect @code{_Decimal128} values stored in floating point registers.
16643 See @ref{PowerPC,,PowerPC} for more details.
16644
16645 @node D
16646 @subsection D
16647
16648 @cindex D
16649 @value{GDBN} can be used to debug programs written in D and compiled with
16650 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16651 specific feature --- dynamic arrays.
16652
16653 @node Go
16654 @subsection Go
16655
16656 @cindex Go (programming language)
16657 @value{GDBN} can be used to debug programs written in Go and compiled with
16658 @file{gccgo} or @file{6g} compilers.
16659
16660 Here is a summary of the Go-specific features and restrictions:
16661
16662 @table @code
16663 @cindex current Go package
16664 @item The current Go package
16665 The name of the current package does not need to be specified when
16666 specifying global variables and functions.
16667
16668 For example, given the program:
16669
16670 @example
16671 package main
16672 var myglob = "Shall we?"
16673 func main () @{
16674 // ...
16675 @}
16676 @end example
16677
16678 When stopped inside @code{main} either of these work:
16679
16680 @example
16681 (gdb) p myglob
16682 (gdb) p main.myglob
16683 @end example
16684
16685 @cindex builtin Go types
16686 @item Builtin Go types
16687 The @code{string} type is recognized by @value{GDBN} and is printed
16688 as a string.
16689
16690 @cindex builtin Go functions
16691 @item Builtin Go functions
16692 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16693 function and handles it internally.
16694
16695 @cindex restrictions on Go expressions
16696 @item Restrictions on Go expressions
16697 All Go operators are supported except @code{&^}.
16698 The Go @code{_} ``blank identifier'' is not supported.
16699 Automatic dereferencing of pointers is not supported.
16700 @end table
16701
16702 @node Objective-C
16703 @subsection Objective-C
16704
16705 @cindex Objective-C
16706 This section provides information about some commands and command
16707 options that are useful for debugging Objective-C code. See also
16708 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16709 few more commands specific to Objective-C support.
16710
16711 @menu
16712 * Method Names in Commands::
16713 * The Print Command with Objective-C::
16714 @end menu
16715
16716 @node Method Names in Commands
16717 @subsubsection Method Names in Commands
16718
16719 The following commands have been extended to accept Objective-C method
16720 names as line specifications:
16721
16722 @kindex clear@r{, and Objective-C}
16723 @kindex break@r{, and Objective-C}
16724 @kindex info line@r{, and Objective-C}
16725 @kindex jump@r{, and Objective-C}
16726 @kindex list@r{, and Objective-C}
16727 @itemize
16728 @item @code{clear}
16729 @item @code{break}
16730 @item @code{info line}
16731 @item @code{jump}
16732 @item @code{list}
16733 @end itemize
16734
16735 A fully qualified Objective-C method name is specified as
16736
16737 @smallexample
16738 -[@var{Class} @var{methodName}]
16739 @end smallexample
16740
16741 where the minus sign is used to indicate an instance method and a
16742 plus sign (not shown) is used to indicate a class method. The class
16743 name @var{Class} and method name @var{methodName} are enclosed in
16744 brackets, similar to the way messages are specified in Objective-C
16745 source code. For example, to set a breakpoint at the @code{create}
16746 instance method of class @code{Fruit} in the program currently being
16747 debugged, enter:
16748
16749 @smallexample
16750 break -[Fruit create]
16751 @end smallexample
16752
16753 To list ten program lines around the @code{initialize} class method,
16754 enter:
16755
16756 @smallexample
16757 list +[NSText initialize]
16758 @end smallexample
16759
16760 In the current version of @value{GDBN}, the plus or minus sign is
16761 required. In future versions of @value{GDBN}, the plus or minus
16762 sign will be optional, but you can use it to narrow the search. It
16763 is also possible to specify just a method name:
16764
16765 @smallexample
16766 break create
16767 @end smallexample
16768
16769 You must specify the complete method name, including any colons. If
16770 your program's source files contain more than one @code{create} method,
16771 you'll be presented with a numbered list of classes that implement that
16772 method. Indicate your choice by number, or type @samp{0} to exit if
16773 none apply.
16774
16775 As another example, to clear a breakpoint established at the
16776 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16777
16778 @smallexample
16779 clear -[NSWindow makeKeyAndOrderFront:]
16780 @end smallexample
16781
16782 @node The Print Command with Objective-C
16783 @subsubsection The Print Command With Objective-C
16784 @cindex Objective-C, print objects
16785 @kindex print-object
16786 @kindex po @r{(@code{print-object})}
16787
16788 The print command has also been extended to accept methods. For example:
16789
16790 @smallexample
16791 print -[@var{object} hash]
16792 @end smallexample
16793
16794 @cindex print an Objective-C object description
16795 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16796 @noindent
16797 will tell @value{GDBN} to send the @code{hash} message to @var{object}
16798 and print the result. Also, an additional command has been added,
16799 @code{print-object} or @code{po} for short, which is meant to print
16800 the description of an object. However, this command may only work
16801 with certain Objective-C libraries that have a particular hook
16802 function, @code{_NSPrintForDebugger}, defined.
16803
16804 @node OpenCL C
16805 @subsection OpenCL C
16806
16807 @cindex OpenCL C
16808 This section provides information about @value{GDBN}s OpenCL C support.
16809
16810 @menu
16811 * OpenCL C Datatypes::
16812 * OpenCL C Expressions::
16813 * OpenCL C Operators::
16814 @end menu
16815
16816 @node OpenCL C Datatypes
16817 @subsubsection OpenCL C Datatypes
16818
16819 @cindex OpenCL C Datatypes
16820 @value{GDBN} supports the builtin scalar and vector datatypes specified
16821 by OpenCL 1.1. In addition the half- and double-precision floating point
16822 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16823 extensions are also known to @value{GDBN}.
16824
16825 @node OpenCL C Expressions
16826 @subsubsection OpenCL C Expressions
16827
16828 @cindex OpenCL C Expressions
16829 @value{GDBN} supports accesses to vector components including the access as
16830 lvalue where possible. Since OpenCL C is based on C99 most C expressions
16831 supported by @value{GDBN} can be used as well.
16832
16833 @node OpenCL C Operators
16834 @subsubsection OpenCL C Operators
16835
16836 @cindex OpenCL C Operators
16837 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16838 vector data types.
16839
16840 @node Fortran
16841 @subsection Fortran
16842 @cindex Fortran-specific support in @value{GDBN}
16843
16844 @value{GDBN} can be used to debug programs written in Fortran, but it
16845 currently supports only the features of Fortran 77 language.
16846
16847 @cindex trailing underscore, in Fortran symbols
16848 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16849 among them) append an underscore to the names of variables and
16850 functions. When you debug programs compiled by those compilers, you
16851 will need to refer to variables and functions with a trailing
16852 underscore.
16853
16854 @menu
16855 * Fortran Operators:: Fortran operators and expressions
16856 * Fortran Defaults:: Default settings for Fortran
16857 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
16858 @end menu
16859
16860 @node Fortran Operators
16861 @subsubsection Fortran Operators and Expressions
16862
16863 @cindex Fortran operators and expressions
16864
16865 Operators must be defined on values of specific types. For instance,
16866 @code{+} is defined on numbers, but not on characters or other non-
16867 arithmetic types. Operators are often defined on groups of types.
16868
16869 @table @code
16870 @item **
16871 The exponentiation operator. It raises the first operand to the power
16872 of the second one.
16873
16874 @item :
16875 The range operator. Normally used in the form of array(low:high) to
16876 represent a section of array.
16877
16878 @item %
16879 The access component operator. Normally used to access elements in derived
16880 types. Also suitable for unions. As unions aren't part of regular Fortran,
16881 this can only happen when accessing a register that uses a gdbarch-defined
16882 union type.
16883 @item ::
16884 The scope operator. Normally used to access variables in modules or
16885 to set breakpoints on subroutines nested in modules or in other
16886 subroutines (internal subroutines).
16887 @end table
16888
16889 @node Fortran Defaults
16890 @subsubsection Fortran Defaults
16891
16892 @cindex Fortran Defaults
16893
16894 Fortran symbols are usually case-insensitive, so @value{GDBN} by
16895 default uses case-insensitive matches for Fortran symbols. You can
16896 change that with the @samp{set case-insensitive} command, see
16897 @ref{Symbols}, for the details.
16898
16899 @node Special Fortran Commands
16900 @subsubsection Special Fortran Commands
16901
16902 @cindex Special Fortran commands
16903
16904 @value{GDBN} has some commands to support Fortran-specific features,
16905 such as displaying common blocks.
16906
16907 @table @code
16908 @cindex @code{COMMON} blocks, Fortran
16909 @kindex info common
16910 @item info common @r{[}@var{common-name}@r{]}
16911 This command prints the values contained in the Fortran @code{COMMON}
16912 block whose name is @var{common-name}. With no argument, the names of
16913 all @code{COMMON} blocks visible at the current program location are
16914 printed.
16915 @end table
16916
16917 @node Pascal
16918 @subsection Pascal
16919
16920 @cindex Pascal support in @value{GDBN}, limitations
16921 Debugging Pascal programs which use sets, subranges, file variables, or
16922 nested functions does not currently work. @value{GDBN} does not support
16923 entering expressions, printing values, or similar features using Pascal
16924 syntax.
16925
16926 The Pascal-specific command @code{set print pascal_static-members}
16927 controls whether static members of Pascal objects are displayed.
16928 @xref{Print Settings, pascal_static-members}.
16929
16930 @node Rust
16931 @subsection Rust
16932
16933 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16934 Programming Language}. Type- and value-printing, and expression
16935 parsing, are reasonably complete. However, there are a few
16936 peculiarities and holes to be aware of.
16937
16938 @itemize @bullet
16939 @item
16940 Linespecs (@pxref{Specify Location}) are never relative to the current
16941 crate. Instead, they act as if there were a global namespace of
16942 crates, somewhat similar to the way @code{extern crate} behaves.
16943
16944 That is, if @value{GDBN} is stopped at a breakpoint in a function in
16945 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16946 to set a breakpoint in a function named @samp{f} in a crate named
16947 @samp{B}.
16948
16949 As a consequence of this approach, linespecs also cannot refer to
16950 items using @samp{self::} or @samp{super::}.
16951
16952 @item
16953 Because @value{GDBN} implements Rust name-lookup semantics in
16954 expressions, it will sometimes prepend the current crate to a name.
16955 For example, if @value{GDBN} is stopped at a breakpoint in the crate
16956 @samp{K}, then @code{print ::x::y} will try to find the symbol
16957 @samp{K::x::y}.
16958
16959 However, since it is useful to be able to refer to other crates when
16960 debugging, @value{GDBN} provides the @code{extern} extension to
16961 circumvent this. To use the extension, just put @code{extern} before
16962 a path expression to refer to the otherwise unavailable ``global''
16963 scope.
16964
16965 In the above example, if you wanted to refer to the symbol @samp{y} in
16966 the crate @samp{x}, you would use @code{print extern x::y}.
16967
16968 @item
16969 The Rust expression evaluator does not support ``statement-like''
16970 expressions such as @code{if} or @code{match}, or lambda expressions.
16971
16972 @item
16973 Tuple expressions are not implemented.
16974
16975 @item
16976 The Rust expression evaluator does not currently implement the
16977 @code{Drop} trait. Objects that may be created by the evaluator will
16978 never be destroyed.
16979
16980 @item
16981 @value{GDBN} does not implement type inference for generics. In order
16982 to call generic functions or otherwise refer to generic items, you
16983 will have to specify the type parameters manually.
16984
16985 @item
16986 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16987 cases this does not cause any problems. However, in an expression
16988 context, completing a generic function name will give syntactically
16989 invalid results. This happens because Rust requires the @samp{::}
16990 operator between the function name and its generic arguments. For
16991 example, @value{GDBN} might provide a completion like
16992 @code{crate::f<u32>}, where the parser would require
16993 @code{crate::f::<u32>}.
16994
16995 @item
16996 As of this writing, the Rust compiler (version 1.8) has a few holes in
16997 the debugging information it generates. These holes prevent certain
16998 features from being implemented by @value{GDBN}:
16999 @itemize @bullet
17000
17001 @item
17002 Method calls cannot be made via traits.
17003
17004 @item
17005 Operator overloading is not implemented.
17006
17007 @item
17008 When debugging in a monomorphized function, you cannot use the generic
17009 type names.
17010
17011 @item
17012 The type @code{Self} is not available.
17013
17014 @item
17015 @code{use} statements are not available, so some names may not be
17016 available in the crate.
17017 @end itemize
17018 @end itemize
17019
17020 @node Modula-2
17021 @subsection Modula-2
17022
17023 @cindex Modula-2, @value{GDBN} support
17024
17025 The extensions made to @value{GDBN} to support Modula-2 only support
17026 output from the @sc{gnu} Modula-2 compiler (which is currently being
17027 developed). Other Modula-2 compilers are not currently supported, and
17028 attempting to debug executables produced by them is most likely
17029 to give an error as @value{GDBN} reads in the executable's symbol
17030 table.
17031
17032 @cindex expressions in Modula-2
17033 @menu
17034 * M2 Operators:: Built-in operators
17035 * Built-In Func/Proc:: Built-in functions and procedures
17036 * M2 Constants:: Modula-2 constants
17037 * M2 Types:: Modula-2 types
17038 * M2 Defaults:: Default settings for Modula-2
17039 * Deviations:: Deviations from standard Modula-2
17040 * M2 Checks:: Modula-2 type and range checks
17041 * M2 Scope:: The scope operators @code{::} and @code{.}
17042 * GDB/M2:: @value{GDBN} and Modula-2
17043 @end menu
17044
17045 @node M2 Operators
17046 @subsubsection Operators
17047 @cindex Modula-2 operators
17048
17049 Operators must be defined on values of specific types. For instance,
17050 @code{+} is defined on numbers, but not on structures. Operators are
17051 often defined on groups of types. For the purposes of Modula-2, the
17052 following definitions hold:
17053
17054 @itemize @bullet
17055
17056 @item
17057 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17058 their subranges.
17059
17060 @item
17061 @emph{Character types} consist of @code{CHAR} and its subranges.
17062
17063 @item
17064 @emph{Floating-point types} consist of @code{REAL}.
17065
17066 @item
17067 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17068 @var{type}}.
17069
17070 @item
17071 @emph{Scalar types} consist of all of the above.
17072
17073 @item
17074 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17075
17076 @item
17077 @emph{Boolean types} consist of @code{BOOLEAN}.
17078 @end itemize
17079
17080 @noindent
17081 The following operators are supported, and appear in order of
17082 increasing precedence:
17083
17084 @table @code
17085 @item ,
17086 Function argument or array index separator.
17087
17088 @item :=
17089 Assignment. The value of @var{var} @code{:=} @var{value} is
17090 @var{value}.
17091
17092 @item <@r{, }>
17093 Less than, greater than on integral, floating-point, or enumerated
17094 types.
17095
17096 @item <=@r{, }>=
17097 Less than or equal to, greater than or equal to
17098 on integral, floating-point and enumerated types, or set inclusion on
17099 set types. Same precedence as @code{<}.
17100
17101 @item =@r{, }<>@r{, }#
17102 Equality and two ways of expressing inequality, valid on scalar types.
17103 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17104 available for inequality, since @code{#} conflicts with the script
17105 comment character.
17106
17107 @item IN
17108 Set membership. Defined on set types and the types of their members.
17109 Same precedence as @code{<}.
17110
17111 @item OR
17112 Boolean disjunction. Defined on boolean types.
17113
17114 @item AND@r{, }&
17115 Boolean conjunction. Defined on boolean types.
17116
17117 @item @@
17118 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17119
17120 @item +@r{, }-
17121 Addition and subtraction on integral and floating-point types, or union
17122 and difference on set types.
17123
17124 @item *
17125 Multiplication on integral and floating-point types, or set intersection
17126 on set types.
17127
17128 @item /
17129 Division on floating-point types, or symmetric set difference on set
17130 types. Same precedence as @code{*}.
17131
17132 @item DIV@r{, }MOD
17133 Integer division and remainder. Defined on integral types. Same
17134 precedence as @code{*}.
17135
17136 @item -
17137 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17138
17139 @item ^
17140 Pointer dereferencing. Defined on pointer types.
17141
17142 @item NOT
17143 Boolean negation. Defined on boolean types. Same precedence as
17144 @code{^}.
17145
17146 @item .
17147 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17148 precedence as @code{^}.
17149
17150 @item []
17151 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17152
17153 @item ()
17154 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17155 as @code{^}.
17156
17157 @item ::@r{, }.
17158 @value{GDBN} and Modula-2 scope operators.
17159 @end table
17160
17161 @quotation
17162 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17163 treats the use of the operator @code{IN}, or the use of operators
17164 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17165 @code{<=}, and @code{>=} on sets as an error.
17166 @end quotation
17167
17168
17169 @node Built-In Func/Proc
17170 @subsubsection Built-in Functions and Procedures
17171 @cindex Modula-2 built-ins
17172
17173 Modula-2 also makes available several built-in procedures and functions.
17174 In describing these, the following metavariables are used:
17175
17176 @table @var
17177
17178 @item a
17179 represents an @code{ARRAY} variable.
17180
17181 @item c
17182 represents a @code{CHAR} constant or variable.
17183
17184 @item i
17185 represents a variable or constant of integral type.
17186
17187 @item m
17188 represents an identifier that belongs to a set. Generally used in the
17189 same function with the metavariable @var{s}. The type of @var{s} should
17190 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17191
17192 @item n
17193 represents a variable or constant of integral or floating-point type.
17194
17195 @item r
17196 represents a variable or constant of floating-point type.
17197
17198 @item t
17199 represents a type.
17200
17201 @item v
17202 represents a variable.
17203
17204 @item x
17205 represents a variable or constant of one of many types. See the
17206 explanation of the function for details.
17207 @end table
17208
17209 All Modula-2 built-in procedures also return a result, described below.
17210
17211 @table @code
17212 @item ABS(@var{n})
17213 Returns the absolute value of @var{n}.
17214
17215 @item CAP(@var{c})
17216 If @var{c} is a lower case letter, it returns its upper case
17217 equivalent, otherwise it returns its argument.
17218
17219 @item CHR(@var{i})
17220 Returns the character whose ordinal value is @var{i}.
17221
17222 @item DEC(@var{v})
17223 Decrements the value in the variable @var{v} by one. Returns the new value.
17224
17225 @item DEC(@var{v},@var{i})
17226 Decrements the value in the variable @var{v} by @var{i}. Returns the
17227 new value.
17228
17229 @item EXCL(@var{m},@var{s})
17230 Removes the element @var{m} from the set @var{s}. Returns the new
17231 set.
17232
17233 @item FLOAT(@var{i})
17234 Returns the floating point equivalent of the integer @var{i}.
17235
17236 @item HIGH(@var{a})
17237 Returns the index of the last member of @var{a}.
17238
17239 @item INC(@var{v})
17240 Increments the value in the variable @var{v} by one. Returns the new value.
17241
17242 @item INC(@var{v},@var{i})
17243 Increments the value in the variable @var{v} by @var{i}. Returns the
17244 new value.
17245
17246 @item INCL(@var{m},@var{s})
17247 Adds the element @var{m} to the set @var{s} if it is not already
17248 there. Returns the new set.
17249
17250 @item MAX(@var{t})
17251 Returns the maximum value of the type @var{t}.
17252
17253 @item MIN(@var{t})
17254 Returns the minimum value of the type @var{t}.
17255
17256 @item ODD(@var{i})
17257 Returns boolean TRUE if @var{i} is an odd number.
17258
17259 @item ORD(@var{x})
17260 Returns the ordinal value of its argument. For example, the ordinal
17261 value of a character is its @sc{ascii} value (on machines supporting
17262 the @sc{ascii} character set). The argument @var{x} must be of an
17263 ordered type, which include integral, character and enumerated types.
17264
17265 @item SIZE(@var{x})
17266 Returns the size of its argument. The argument @var{x} can be a
17267 variable or a type.
17268
17269 @item TRUNC(@var{r})
17270 Returns the integral part of @var{r}.
17271
17272 @item TSIZE(@var{x})
17273 Returns the size of its argument. The argument @var{x} can be a
17274 variable or a type.
17275
17276 @item VAL(@var{t},@var{i})
17277 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17278 @end table
17279
17280 @quotation
17281 @emph{Warning:} Sets and their operations are not yet supported, so
17282 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17283 an error.
17284 @end quotation
17285
17286 @cindex Modula-2 constants
17287 @node M2 Constants
17288 @subsubsection Constants
17289
17290 @value{GDBN} allows you to express the constants of Modula-2 in the following
17291 ways:
17292
17293 @itemize @bullet
17294
17295 @item
17296 Integer constants are simply a sequence of digits. When used in an
17297 expression, a constant is interpreted to be type-compatible with the
17298 rest of the expression. Hexadecimal integers are specified by a
17299 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17300
17301 @item
17302 Floating point constants appear as a sequence of digits, followed by a
17303 decimal point and another sequence of digits. An optional exponent can
17304 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17305 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17306 digits of the floating point constant must be valid decimal (base 10)
17307 digits.
17308
17309 @item
17310 Character constants consist of a single character enclosed by a pair of
17311 like quotes, either single (@code{'}) or double (@code{"}). They may
17312 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17313 followed by a @samp{C}.
17314
17315 @item
17316 String constants consist of a sequence of characters enclosed by a
17317 pair of like quotes, either single (@code{'}) or double (@code{"}).
17318 Escape sequences in the style of C are also allowed. @xref{C
17319 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17320 sequences.
17321
17322 @item
17323 Enumerated constants consist of an enumerated identifier.
17324
17325 @item
17326 Boolean constants consist of the identifiers @code{TRUE} and
17327 @code{FALSE}.
17328
17329 @item
17330 Pointer constants consist of integral values only.
17331
17332 @item
17333 Set constants are not yet supported.
17334 @end itemize
17335
17336 @node M2 Types
17337 @subsubsection Modula-2 Types
17338 @cindex Modula-2 types
17339
17340 Currently @value{GDBN} can print the following data types in Modula-2
17341 syntax: array types, record types, set types, pointer types, procedure
17342 types, enumerated types, subrange types and base types. You can also
17343 print the contents of variables declared using these type.
17344 This section gives a number of simple source code examples together with
17345 sample @value{GDBN} sessions.
17346
17347 The first example contains the following section of code:
17348
17349 @smallexample
17350 VAR
17351 s: SET OF CHAR ;
17352 r: [20..40] ;
17353 @end smallexample
17354
17355 @noindent
17356 and you can request @value{GDBN} to interrogate the type and value of
17357 @code{r} and @code{s}.
17358
17359 @smallexample
17360 (@value{GDBP}) print s
17361 @{'A'..'C', 'Z'@}
17362 (@value{GDBP}) ptype s
17363 SET OF CHAR
17364 (@value{GDBP}) print r
17365 21
17366 (@value{GDBP}) ptype r
17367 [20..40]
17368 @end smallexample
17369
17370 @noindent
17371 Likewise if your source code declares @code{s} as:
17372
17373 @smallexample
17374 VAR
17375 s: SET ['A'..'Z'] ;
17376 @end smallexample
17377
17378 @noindent
17379 then you may query the type of @code{s} by:
17380
17381 @smallexample
17382 (@value{GDBP}) ptype s
17383 type = SET ['A'..'Z']
17384 @end smallexample
17385
17386 @noindent
17387 Note that at present you cannot interactively manipulate set
17388 expressions using the debugger.
17389
17390 The following example shows how you might declare an array in Modula-2
17391 and how you can interact with @value{GDBN} to print its type and contents:
17392
17393 @smallexample
17394 VAR
17395 s: ARRAY [-10..10] OF CHAR ;
17396 @end smallexample
17397
17398 @smallexample
17399 (@value{GDBP}) ptype s
17400 ARRAY [-10..10] OF CHAR
17401 @end smallexample
17402
17403 Note that the array handling is not yet complete and although the type
17404 is printed correctly, expression handling still assumes that all
17405 arrays have a lower bound of zero and not @code{-10} as in the example
17406 above.
17407
17408 Here are some more type related Modula-2 examples:
17409
17410 @smallexample
17411 TYPE
17412 colour = (blue, red, yellow, green) ;
17413 t = [blue..yellow] ;
17414 VAR
17415 s: t ;
17416 BEGIN
17417 s := blue ;
17418 @end smallexample
17419
17420 @noindent
17421 The @value{GDBN} interaction shows how you can query the data type
17422 and value of a variable.
17423
17424 @smallexample
17425 (@value{GDBP}) print s
17426 $1 = blue
17427 (@value{GDBP}) ptype t
17428 type = [blue..yellow]
17429 @end smallexample
17430
17431 @noindent
17432 In this example a Modula-2 array is declared and its contents
17433 displayed. Observe that the contents are written in the same way as
17434 their @code{C} counterparts.
17435
17436 @smallexample
17437 VAR
17438 s: ARRAY [1..5] OF CARDINAL ;
17439 BEGIN
17440 s[1] := 1 ;
17441 @end smallexample
17442
17443 @smallexample
17444 (@value{GDBP}) print s
17445 $1 = @{1, 0, 0, 0, 0@}
17446 (@value{GDBP}) ptype s
17447 type = ARRAY [1..5] OF CARDINAL
17448 @end smallexample
17449
17450 The Modula-2 language interface to @value{GDBN} also understands
17451 pointer types as shown in this example:
17452
17453 @smallexample
17454 VAR
17455 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17456 BEGIN
17457 NEW(s) ;
17458 s^[1] := 1 ;
17459 @end smallexample
17460
17461 @noindent
17462 and you can request that @value{GDBN} describes the type of @code{s}.
17463
17464 @smallexample
17465 (@value{GDBP}) ptype s
17466 type = POINTER TO ARRAY [1..5] OF CARDINAL
17467 @end smallexample
17468
17469 @value{GDBN} handles compound types as we can see in this example.
17470 Here we combine array types, record types, pointer types and subrange
17471 types:
17472
17473 @smallexample
17474 TYPE
17475 foo = RECORD
17476 f1: CARDINAL ;
17477 f2: CHAR ;
17478 f3: myarray ;
17479 END ;
17480
17481 myarray = ARRAY myrange OF CARDINAL ;
17482 myrange = [-2..2] ;
17483 VAR
17484 s: POINTER TO ARRAY myrange OF foo ;
17485 @end smallexample
17486
17487 @noindent
17488 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17489 below.
17490
17491 @smallexample
17492 (@value{GDBP}) ptype s
17493 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17494 f1 : CARDINAL;
17495 f2 : CHAR;
17496 f3 : ARRAY [-2..2] OF CARDINAL;
17497 END
17498 @end smallexample
17499
17500 @node M2 Defaults
17501 @subsubsection Modula-2 Defaults
17502 @cindex Modula-2 defaults
17503
17504 If type and range checking are set automatically by @value{GDBN}, they
17505 both default to @code{on} whenever the working language changes to
17506 Modula-2. This happens regardless of whether you or @value{GDBN}
17507 selected the working language.
17508
17509 If you allow @value{GDBN} to set the language automatically, then entering
17510 code compiled from a file whose name ends with @file{.mod} sets the
17511 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17512 Infer the Source Language}, for further details.
17513
17514 @node Deviations
17515 @subsubsection Deviations from Standard Modula-2
17516 @cindex Modula-2, deviations from
17517
17518 A few changes have been made to make Modula-2 programs easier to debug.
17519 This is done primarily via loosening its type strictness:
17520
17521 @itemize @bullet
17522 @item
17523 Unlike in standard Modula-2, pointer constants can be formed by
17524 integers. This allows you to modify pointer variables during
17525 debugging. (In standard Modula-2, the actual address contained in a
17526 pointer variable is hidden from you; it can only be modified
17527 through direct assignment to another pointer variable or expression that
17528 returned a pointer.)
17529
17530 @item
17531 C escape sequences can be used in strings and characters to represent
17532 non-printable characters. @value{GDBN} prints out strings with these
17533 escape sequences embedded. Single non-printable characters are
17534 printed using the @samp{CHR(@var{nnn})} format.
17535
17536 @item
17537 The assignment operator (@code{:=}) returns the value of its right-hand
17538 argument.
17539
17540 @item
17541 All built-in procedures both modify @emph{and} return their argument.
17542 @end itemize
17543
17544 @node M2 Checks
17545 @subsubsection Modula-2 Type and Range Checks
17546 @cindex Modula-2 checks
17547
17548 @quotation
17549 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17550 range checking.
17551 @end quotation
17552 @c FIXME remove warning when type/range checks added
17553
17554 @value{GDBN} considers two Modula-2 variables type equivalent if:
17555
17556 @itemize @bullet
17557 @item
17558 They are of types that have been declared equivalent via a @code{TYPE
17559 @var{t1} = @var{t2}} statement
17560
17561 @item
17562 They have been declared on the same line. (Note: This is true of the
17563 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17564 @end itemize
17565
17566 As long as type checking is enabled, any attempt to combine variables
17567 whose types are not equivalent is an error.
17568
17569 Range checking is done on all mathematical operations, assignment, array
17570 index bounds, and all built-in functions and procedures.
17571
17572 @node M2 Scope
17573 @subsubsection The Scope Operators @code{::} and @code{.}
17574 @cindex scope
17575 @cindex @code{.}, Modula-2 scope operator
17576 @cindex colon, doubled as scope operator
17577 @ifinfo
17578 @vindex colon-colon@r{, in Modula-2}
17579 @c Info cannot handle :: but TeX can.
17580 @end ifinfo
17581 @ifnotinfo
17582 @vindex ::@r{, in Modula-2}
17583 @end ifnotinfo
17584
17585 There are a few subtle differences between the Modula-2 scope operator
17586 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17587 similar syntax:
17588
17589 @smallexample
17590
17591 @var{module} . @var{id}
17592 @var{scope} :: @var{id}
17593 @end smallexample
17594
17595 @noindent
17596 where @var{scope} is the name of a module or a procedure,
17597 @var{module} the name of a module, and @var{id} is any declared
17598 identifier within your program, except another module.
17599
17600 Using the @code{::} operator makes @value{GDBN} search the scope
17601 specified by @var{scope} for the identifier @var{id}. If it is not
17602 found in the specified scope, then @value{GDBN} searches all scopes
17603 enclosing the one specified by @var{scope}.
17604
17605 Using the @code{.} operator makes @value{GDBN} search the current scope for
17606 the identifier specified by @var{id} that was imported from the
17607 definition module specified by @var{module}. With this operator, it is
17608 an error if the identifier @var{id} was not imported from definition
17609 module @var{module}, or if @var{id} is not an identifier in
17610 @var{module}.
17611
17612 @node GDB/M2
17613 @subsubsection @value{GDBN} and Modula-2
17614
17615 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17616 Five subcommands of @code{set print} and @code{show print} apply
17617 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17618 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17619 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17620 analogue in Modula-2.
17621
17622 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17623 with any language, is not useful with Modula-2. Its
17624 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17625 created in Modula-2 as they can in C or C@t{++}. However, because an
17626 address can be specified by an integral constant, the construct
17627 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17628
17629 @cindex @code{#} in Modula-2
17630 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17631 interpreted as the beginning of a comment. Use @code{<>} instead.
17632
17633 @node Ada
17634 @subsection Ada
17635 @cindex Ada
17636
17637 The extensions made to @value{GDBN} for Ada only support
17638 output from the @sc{gnu} Ada (GNAT) compiler.
17639 Other Ada compilers are not currently supported, and
17640 attempting to debug executables produced by them is most likely
17641 to be difficult.
17642
17643
17644 @cindex expressions in Ada
17645 @menu
17646 * Ada Mode Intro:: General remarks on the Ada syntax
17647 and semantics supported by Ada mode
17648 in @value{GDBN}.
17649 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17650 * Additions to Ada:: Extensions of the Ada expression syntax.
17651 * Overloading support for Ada:: Support for expressions involving overloaded
17652 subprograms.
17653 * Stopping Before Main Program:: Debugging the program during elaboration.
17654 * Ada Exceptions:: Ada Exceptions
17655 * Ada Tasks:: Listing and setting breakpoints in tasks.
17656 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17657 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17658 Profile
17659 * Ada Settings:: New settable GDB parameters for Ada.
17660 * Ada Glitches:: Known peculiarities of Ada mode.
17661 @end menu
17662
17663 @node Ada Mode Intro
17664 @subsubsection Introduction
17665 @cindex Ada mode, general
17666
17667 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17668 syntax, with some extensions.
17669 The philosophy behind the design of this subset is
17670
17671 @itemize @bullet
17672 @item
17673 That @value{GDBN} should provide basic literals and access to operations for
17674 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17675 leaving more sophisticated computations to subprograms written into the
17676 program (which therefore may be called from @value{GDBN}).
17677
17678 @item
17679 That type safety and strict adherence to Ada language restrictions
17680 are not particularly important to the @value{GDBN} user.
17681
17682 @item
17683 That brevity is important to the @value{GDBN} user.
17684 @end itemize
17685
17686 Thus, for brevity, the debugger acts as if all names declared in
17687 user-written packages are directly visible, even if they are not visible
17688 according to Ada rules, thus making it unnecessary to fully qualify most
17689 names with their packages, regardless of context. Where this causes
17690 ambiguity, @value{GDBN} asks the user's intent.
17691
17692 The debugger will start in Ada mode if it detects an Ada main program.
17693 As for other languages, it will enter Ada mode when stopped in a program that
17694 was translated from an Ada source file.
17695
17696 While in Ada mode, you may use `@t{--}' for comments. This is useful
17697 mostly for documenting command files. The standard @value{GDBN} comment
17698 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17699 middle (to allow based literals).
17700
17701 @node Omissions from Ada
17702 @subsubsection Omissions from Ada
17703 @cindex Ada, omissions from
17704
17705 Here are the notable omissions from the subset:
17706
17707 @itemize @bullet
17708 @item
17709 Only a subset of the attributes are supported:
17710
17711 @itemize @minus
17712 @item
17713 @t{'First}, @t{'Last}, and @t{'Length}
17714 on array objects (not on types and subtypes).
17715
17716 @item
17717 @t{'Min} and @t{'Max}.
17718
17719 @item
17720 @t{'Pos} and @t{'Val}.
17721
17722 @item
17723 @t{'Tag}.
17724
17725 @item
17726 @t{'Range} on array objects (not subtypes), but only as the right
17727 operand of the membership (@code{in}) operator.
17728
17729 @item
17730 @t{'Access}, @t{'Unchecked_Access}, and
17731 @t{'Unrestricted_Access} (a GNAT extension).
17732
17733 @item
17734 @t{'Address}.
17735 @end itemize
17736
17737 @item
17738 The names in
17739 @code{Characters.Latin_1} are not available and
17740 concatenation is not implemented. Thus, escape characters in strings are
17741 not currently available.
17742
17743 @item
17744 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17745 equality of representations. They will generally work correctly
17746 for strings and arrays whose elements have integer or enumeration types.
17747 They may not work correctly for arrays whose element
17748 types have user-defined equality, for arrays of real values
17749 (in particular, IEEE-conformant floating point, because of negative
17750 zeroes and NaNs), and for arrays whose elements contain unused bits with
17751 indeterminate values.
17752
17753 @item
17754 The other component-by-component array operations (@code{and}, @code{or},
17755 @code{xor}, @code{not}, and relational tests other than equality)
17756 are not implemented.
17757
17758 @item
17759 @cindex array aggregates (Ada)
17760 @cindex record aggregates (Ada)
17761 @cindex aggregates (Ada)
17762 There is limited support for array and record aggregates. They are
17763 permitted only on the right sides of assignments, as in these examples:
17764
17765 @smallexample
17766 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17767 (@value{GDBP}) set An_Array := (1, others => 0)
17768 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17769 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17770 (@value{GDBP}) set A_Record := (1, "Peter", True);
17771 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
17772 @end smallexample
17773
17774 Changing a
17775 discriminant's value by assigning an aggregate has an
17776 undefined effect if that discriminant is used within the record.
17777 However, you can first modify discriminants by directly assigning to
17778 them (which normally would not be allowed in Ada), and then performing an
17779 aggregate assignment. For example, given a variable @code{A_Rec}
17780 declared to have a type such as:
17781
17782 @smallexample
17783 type Rec (Len : Small_Integer := 0) is record
17784 Id : Integer;
17785 Vals : IntArray (1 .. Len);
17786 end record;
17787 @end smallexample
17788
17789 you can assign a value with a different size of @code{Vals} with two
17790 assignments:
17791
17792 @smallexample
17793 (@value{GDBP}) set A_Rec.Len := 4
17794 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
17795 @end smallexample
17796
17797 As this example also illustrates, @value{GDBN} is very loose about the usual
17798 rules concerning aggregates. You may leave out some of the
17799 components of an array or record aggregate (such as the @code{Len}
17800 component in the assignment to @code{A_Rec} above); they will retain their
17801 original values upon assignment. You may freely use dynamic values as
17802 indices in component associations. You may even use overlapping or
17803 redundant component associations, although which component values are
17804 assigned in such cases is not defined.
17805
17806 @item
17807 Calls to dispatching subprograms are not implemented.
17808
17809 @item
17810 The overloading algorithm is much more limited (i.e., less selective)
17811 than that of real Ada. It makes only limited use of the context in
17812 which a subexpression appears to resolve its meaning, and it is much
17813 looser in its rules for allowing type matches. As a result, some
17814 function calls will be ambiguous, and the user will be asked to choose
17815 the proper resolution.
17816
17817 @item
17818 The @code{new} operator is not implemented.
17819
17820 @item
17821 Entry calls are not implemented.
17822
17823 @item
17824 Aside from printing, arithmetic operations on the native VAX floating-point
17825 formats are not supported.
17826
17827 @item
17828 It is not possible to slice a packed array.
17829
17830 @item
17831 The names @code{True} and @code{False}, when not part of a qualified name,
17832 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17833 context.
17834 Should your program
17835 redefine these names in a package or procedure (at best a dubious practice),
17836 you will have to use fully qualified names to access their new definitions.
17837 @end itemize
17838
17839 @node Additions to Ada
17840 @subsubsection Additions to Ada
17841 @cindex Ada, deviations from
17842
17843 As it does for other languages, @value{GDBN} makes certain generic
17844 extensions to Ada (@pxref{Expressions}):
17845
17846 @itemize @bullet
17847 @item
17848 If the expression @var{E} is a variable residing in memory (typically
17849 a local variable or array element) and @var{N} is a positive integer,
17850 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17851 @var{N}-1 adjacent variables following it in memory as an array. In
17852 Ada, this operator is generally not necessary, since its prime use is
17853 in displaying parts of an array, and slicing will usually do this in
17854 Ada. However, there are occasional uses when debugging programs in
17855 which certain debugging information has been optimized away.
17856
17857 @item
17858 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
17859 appears in function or file @var{B}.'' When @var{B} is a file name,
17860 you must typically surround it in single quotes.
17861
17862 @item
17863 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17864 @var{type} that appears at address @var{addr}.''
17865
17866 @item
17867 A name starting with @samp{$} is a convenience variable
17868 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17869 @end itemize
17870
17871 In addition, @value{GDBN} provides a few other shortcuts and outright
17872 additions specific to Ada:
17873
17874 @itemize @bullet
17875 @item
17876 The assignment statement is allowed as an expression, returning
17877 its right-hand operand as its value. Thus, you may enter
17878
17879 @smallexample
17880 (@value{GDBP}) set x := y + 3
17881 (@value{GDBP}) print A(tmp := y + 1)
17882 @end smallexample
17883
17884 @item
17885 The semicolon is allowed as an ``operator,'' returning as its value
17886 the value of its right-hand operand.
17887 This allows, for example,
17888 complex conditional breaks:
17889
17890 @smallexample
17891 (@value{GDBP}) break f
17892 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
17893 @end smallexample
17894
17895 @item
17896 Rather than use catenation and symbolic character names to introduce special
17897 characters into strings, one may instead use a special bracket notation,
17898 which is also used to print strings. A sequence of characters of the form
17899 @samp{["@var{XX}"]} within a string or character literal denotes the
17900 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
17901 sequence of characters @samp{["""]} also denotes a single quotation mark
17902 in strings. For example,
17903 @smallexample
17904 "One line.["0a"]Next line.["0a"]"
17905 @end smallexample
17906 @noindent
17907 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17908 after each period.
17909
17910 @item
17911 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17912 @t{'Max} is optional (and is ignored in any case). For example, it is valid
17913 to write
17914
17915 @smallexample
17916 (@value{GDBP}) print 'max(x, y)
17917 @end smallexample
17918
17919 @item
17920 When printing arrays, @value{GDBN} uses positional notation when the
17921 array has a lower bound of 1, and uses a modified named notation otherwise.
17922 For example, a one-dimensional array of three integers with a lower bound
17923 of 3 might print as
17924
17925 @smallexample
17926 (3 => 10, 17, 1)
17927 @end smallexample
17928
17929 @noindent
17930 That is, in contrast to valid Ada, only the first component has a @code{=>}
17931 clause.
17932
17933 @item
17934 You may abbreviate attributes in expressions with any unique,
17935 multi-character subsequence of
17936 their names (an exact match gets preference).
17937 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17938 in place of @t{a'length}.
17939
17940 @item
17941 @cindex quoting Ada internal identifiers
17942 Since Ada is case-insensitive, the debugger normally maps identifiers you type
17943 to lower case. The GNAT compiler uses upper-case characters for
17944 some of its internal identifiers, which are normally of no interest to users.
17945 For the rare occasions when you actually have to look at them,
17946 enclose them in angle brackets to avoid the lower-case mapping.
17947 For example,
17948 @smallexample
17949 (@value{GDBP}) print <JMPBUF_SAVE>[0]
17950 @end smallexample
17951
17952 @item
17953 Printing an object of class-wide type or dereferencing an
17954 access-to-class-wide value will display all the components of the object's
17955 specific type (as indicated by its run-time tag). Likewise, component
17956 selection on such a value will operate on the specific type of the
17957 object.
17958
17959 @end itemize
17960
17961 @node Overloading support for Ada
17962 @subsubsection Overloading support for Ada
17963 @cindex overloading, Ada
17964
17965 The debugger supports limited overloading. Given a subprogram call in which
17966 the function symbol has multiple definitions, it will use the number of
17967 actual parameters and some information about their types to attempt to narrow
17968 the set of definitions. It also makes very limited use of context, preferring
17969 procedures to functions in the context of the @code{call} command, and
17970 functions to procedures elsewhere.
17971
17972 If, after narrowing, the set of matching definitions still contains more than
17973 one definition, @value{GDBN} will display a menu to query which one it should
17974 use, for instance:
17975
17976 @smallexample
17977 (@value{GDBP}) print f(1)
17978 Multiple matches for f
17979 [0] cancel
17980 [1] foo.f (integer) return boolean at foo.adb:23
17981 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
17982 >
17983 @end smallexample
17984
17985 In this case, just select one menu entry either to cancel expression evaluation
17986 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17987 instance (type the corresponding number and press @key{RET}).
17988
17989 Here are a couple of commands to customize @value{GDBN}'s behavior in this
17990 case:
17991
17992 @table @code
17993
17994 @kindex set ada print-signatures
17995 @item set ada print-signatures
17996 Control whether parameter types and return types are displayed in overloads
17997 selection menus. It is @code{on} by default.
17998 @xref{Overloading support for Ada}.
17999
18000 @kindex show ada print-signatures
18001 @item show ada print-signatures
18002 Show the current setting for displaying parameter types and return types in
18003 overloads selection menu.
18004 @xref{Overloading support for Ada}.
18005
18006 @end table
18007
18008 @node Stopping Before Main Program
18009 @subsubsection Stopping at the Very Beginning
18010
18011 @cindex breakpointing Ada elaboration code
18012 It is sometimes necessary to debug the program during elaboration, and
18013 before reaching the main procedure.
18014 As defined in the Ada Reference
18015 Manual, the elaboration code is invoked from a procedure called
18016 @code{adainit}. To run your program up to the beginning of
18017 elaboration, simply use the following two commands:
18018 @code{tbreak adainit} and @code{run}.
18019
18020 @node Ada Exceptions
18021 @subsubsection Ada Exceptions
18022
18023 A command is provided to list all Ada exceptions:
18024
18025 @table @code
18026 @kindex info exceptions
18027 @item info exceptions
18028 @itemx info exceptions @var{regexp}
18029 The @code{info exceptions} command allows you to list all Ada exceptions
18030 defined within the program being debugged, as well as their addresses.
18031 With a regular expression, @var{regexp}, as argument, only those exceptions
18032 whose names match @var{regexp} are listed.
18033 @end table
18034
18035 Below is a small example, showing how the command can be used, first
18036 without argument, and next with a regular expression passed as an
18037 argument.
18038
18039 @smallexample
18040 (@value{GDBP}) info exceptions
18041 All defined Ada exceptions:
18042 constraint_error: 0x613da0
18043 program_error: 0x613d20
18044 storage_error: 0x613ce0
18045 tasking_error: 0x613ca0
18046 const.aint_global_e: 0x613b00
18047 (@value{GDBP}) info exceptions const.aint
18048 All Ada exceptions matching regular expression "const.aint":
18049 constraint_error: 0x613da0
18050 const.aint_global_e: 0x613b00
18051 @end smallexample
18052
18053 It is also possible to ask @value{GDBN} to stop your program's execution
18054 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18055
18056 @node Ada Tasks
18057 @subsubsection Extensions for Ada Tasks
18058 @cindex Ada, tasking
18059
18060 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18061 @value{GDBN} provides the following task-related commands:
18062
18063 @table @code
18064 @kindex info tasks
18065 @item info tasks
18066 This command shows a list of current Ada tasks, as in the following example:
18067
18068
18069 @smallexample
18070 @iftex
18071 @leftskip=0.5cm
18072 @end iftex
18073 (@value{GDBP}) info tasks
18074 ID TID P-ID Pri State Name
18075 1 8088000 0 15 Child Activation Wait main_task
18076 2 80a4000 1 15 Accept Statement b
18077 3 809a800 1 15 Child Activation Wait a
18078 * 4 80ae800 3 15 Runnable c
18079
18080 @end smallexample
18081
18082 @noindent
18083 In this listing, the asterisk before the last task indicates it to be the
18084 task currently being inspected.
18085
18086 @table @asis
18087 @item ID
18088 Represents @value{GDBN}'s internal task number.
18089
18090 @item TID
18091 The Ada task ID.
18092
18093 @item P-ID
18094 The parent's task ID (@value{GDBN}'s internal task number).
18095
18096 @item Pri
18097 The base priority of the task.
18098
18099 @item State
18100 Current state of the task.
18101
18102 @table @code
18103 @item Unactivated
18104 The task has been created but has not been activated. It cannot be
18105 executing.
18106
18107 @item Runnable
18108 The task is not blocked for any reason known to Ada. (It may be waiting
18109 for a mutex, though.) It is conceptually "executing" in normal mode.
18110
18111 @item Terminated
18112 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18113 that were waiting on terminate alternatives have been awakened and have
18114 terminated themselves.
18115
18116 @item Child Activation Wait
18117 The task is waiting for created tasks to complete activation.
18118
18119 @item Accept Statement
18120 The task is waiting on an accept or selective wait statement.
18121
18122 @item Waiting on entry call
18123 The task is waiting on an entry call.
18124
18125 @item Async Select Wait
18126 The task is waiting to start the abortable part of an asynchronous
18127 select statement.
18128
18129 @item Delay Sleep
18130 The task is waiting on a select statement with only a delay
18131 alternative open.
18132
18133 @item Child Termination Wait
18134 The task is sleeping having completed a master within itself, and is
18135 waiting for the tasks dependent on that master to become terminated or
18136 waiting on a terminate Phase.
18137
18138 @item Wait Child in Term Alt
18139 The task is sleeping waiting for tasks on terminate alternatives to
18140 finish terminating.
18141
18142 @item Accepting RV with @var{taskno}
18143 The task is accepting a rendez-vous with the task @var{taskno}.
18144 @end table
18145
18146 @item Name
18147 Name of the task in the program.
18148
18149 @end table
18150
18151 @kindex info task @var{taskno}
18152 @item info task @var{taskno}
18153 This command shows detailed informations on the specified task, as in
18154 the following example:
18155 @smallexample
18156 @iftex
18157 @leftskip=0.5cm
18158 @end iftex
18159 (@value{GDBP}) info tasks
18160 ID TID P-ID Pri State Name
18161 1 8077880 0 15 Child Activation Wait main_task
18162 * 2 807c468 1 15 Runnable task_1
18163 (@value{GDBP}) info task 2
18164 Ada Task: 0x807c468
18165 Name: "task_1"
18166 Thread: 0
18167 LWP: 0x1fac
18168 Parent: 1 ("main_task")
18169 Base Priority: 15
18170 State: Runnable
18171 @end smallexample
18172
18173 @item task
18174 @kindex task@r{ (Ada)}
18175 @cindex current Ada task ID
18176 This command prints the ID and name of the current task.
18177
18178 @smallexample
18179 @iftex
18180 @leftskip=0.5cm
18181 @end iftex
18182 (@value{GDBP}) info tasks
18183 ID TID P-ID Pri State Name
18184 1 8077870 0 15 Child Activation Wait main_task
18185 * 2 807c458 1 15 Runnable some_task
18186 (@value{GDBP}) task
18187 [Current task is 2 "some_task"]
18188 @end smallexample
18189
18190 @item task @var{taskno}
18191 @cindex Ada task switching
18192 This command is like the @code{thread @var{thread-id}}
18193 command (@pxref{Threads}). It switches the context of debugging
18194 from the current task to the given task.
18195
18196 @smallexample
18197 @iftex
18198 @leftskip=0.5cm
18199 @end iftex
18200 (@value{GDBP}) info tasks
18201 ID TID P-ID Pri State Name
18202 1 8077870 0 15 Child Activation Wait main_task
18203 * 2 807c458 1 15 Runnable some_task
18204 (@value{GDBP}) task 1
18205 [Switching to task 1 "main_task"]
18206 #0 0x8067726 in pthread_cond_wait ()
18207 (@value{GDBP}) bt
18208 #0 0x8067726 in pthread_cond_wait ()
18209 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18210 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18211 #3 0x806153e in system.tasking.stages.activate_tasks ()
18212 #4 0x804aacc in un () at un.adb:5
18213 @end smallexample
18214
18215 @item break @var{location} task @var{taskno}
18216 @itemx break @var{location} task @var{taskno} if @dots{}
18217 @cindex breakpoints and tasks, in Ada
18218 @cindex task breakpoints, in Ada
18219 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18220 These commands are like the @code{break @dots{} thread @dots{}}
18221 command (@pxref{Thread Stops}). The
18222 @var{location} argument specifies source lines, as described
18223 in @ref{Specify Location}.
18224
18225 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18226 to specify that you only want @value{GDBN} to stop the program when a
18227 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18228 numeric task identifiers assigned by @value{GDBN}, shown in the first
18229 column of the @samp{info tasks} display.
18230
18231 If you do not specify @samp{task @var{taskno}} when you set a
18232 breakpoint, the breakpoint applies to @emph{all} tasks of your
18233 program.
18234
18235 You can use the @code{task} qualifier on conditional breakpoints as
18236 well; in this case, place @samp{task @var{taskno}} before the
18237 breakpoint condition (before the @code{if}).
18238
18239 For example,
18240
18241 @smallexample
18242 @iftex
18243 @leftskip=0.5cm
18244 @end iftex
18245 (@value{GDBP}) info tasks
18246 ID TID P-ID Pri State Name
18247 1 140022020 0 15 Child Activation Wait main_task
18248 2 140045060 1 15 Accept/Select Wait t2
18249 3 140044840 1 15 Runnable t1
18250 * 4 140056040 1 15 Runnable t3
18251 (@value{GDBP}) b 15 task 2
18252 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18253 (@value{GDBP}) cont
18254 Continuing.
18255 task # 1 running
18256 task # 2 running
18257
18258 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18259 15 flush;
18260 (@value{GDBP}) info tasks
18261 ID TID P-ID Pri State Name
18262 1 140022020 0 15 Child Activation Wait main_task
18263 * 2 140045060 1 15 Runnable t2
18264 3 140044840 1 15 Runnable t1
18265 4 140056040 1 15 Delay Sleep t3
18266 @end smallexample
18267 @end table
18268
18269 @node Ada Tasks and Core Files
18270 @subsubsection Tasking Support when Debugging Core Files
18271 @cindex Ada tasking and core file debugging
18272
18273 When inspecting a core file, as opposed to debugging a live program,
18274 tasking support may be limited or even unavailable, depending on
18275 the platform being used.
18276 For instance, on x86-linux, the list of tasks is available, but task
18277 switching is not supported.
18278
18279 On certain platforms, the debugger needs to perform some
18280 memory writes in order to provide Ada tasking support. When inspecting
18281 a core file, this means that the core file must be opened with read-write
18282 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18283 Under these circumstances, you should make a backup copy of the core
18284 file before inspecting it with @value{GDBN}.
18285
18286 @node Ravenscar Profile
18287 @subsubsection Tasking Support when using the Ravenscar Profile
18288 @cindex Ravenscar Profile
18289
18290 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18291 specifically designed for systems with safety-critical real-time
18292 requirements.
18293
18294 @table @code
18295 @kindex set ravenscar task-switching on
18296 @cindex task switching with program using Ravenscar Profile
18297 @item set ravenscar task-switching on
18298 Allows task switching when debugging a program that uses the Ravenscar
18299 Profile. This is the default.
18300
18301 @kindex set ravenscar task-switching off
18302 @item set ravenscar task-switching off
18303 Turn off task switching when debugging a program that uses the Ravenscar
18304 Profile. This is mostly intended to disable the code that adds support
18305 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18306 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18307 To be effective, this command should be run before the program is started.
18308
18309 @kindex show ravenscar task-switching
18310 @item show ravenscar task-switching
18311 Show whether it is possible to switch from task to task in a program
18312 using the Ravenscar Profile.
18313
18314 @end table
18315
18316 @node Ada Settings
18317 @subsubsection Ada Settings
18318 @cindex Ada settings
18319
18320 @table @code
18321 @kindex set varsize-limit
18322 @item set varsize-limit @var{size}
18323 Prevent @value{GDBN} from attempting to evaluate objects whose size
18324 is above the given limit (@var{size}) when those sizes are computed
18325 from run-time quantities. This is typically the case when the object
18326 has a variable size, such as an array whose bounds are not known at
18327 compile time for example. Setting @var{size} to @code{unlimited}
18328 removes the size limitation. By default, the limit is about 65KB.
18329
18330 The purpose of having such a limit is to prevent @value{GDBN} from
18331 trying to grab enormous chunks of virtual memory when asked to evaluate
18332 a quantity whose bounds have been corrupted or have not yet been fully
18333 initialized. The limit applies to the results of some subexpressions
18334 as well as to complete expressions. For example, an expression denoting
18335 a simple integer component, such as @code{x.y.z}, may fail if the size of
18336 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18337 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18338 @code{A} is an array variable with non-constant size, will generally
18339 succeed regardless of the bounds on @code{A}, as long as the component
18340 size is less than @var{size}.
18341
18342 @kindex show varsize-limit
18343 @item show varsize-limit
18344 Show the limit on types whose size is determined by run-time quantities.
18345 @end table
18346
18347 @node Ada Glitches
18348 @subsubsection Known Peculiarities of Ada Mode
18349 @cindex Ada, problems
18350
18351 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18352 we know of several problems with and limitations of Ada mode in
18353 @value{GDBN},
18354 some of which will be fixed with planned future releases of the debugger
18355 and the GNU Ada compiler.
18356
18357 @itemize @bullet
18358 @item
18359 Static constants that the compiler chooses not to materialize as objects in
18360 storage are invisible to the debugger.
18361
18362 @item
18363 Named parameter associations in function argument lists are ignored (the
18364 argument lists are treated as positional).
18365
18366 @item
18367 Many useful library packages are currently invisible to the debugger.
18368
18369 @item
18370 Fixed-point arithmetic, conversions, input, and output is carried out using
18371 floating-point arithmetic, and may give results that only approximate those on
18372 the host machine.
18373
18374 @item
18375 The GNAT compiler never generates the prefix @code{Standard} for any of
18376 the standard symbols defined by the Ada language. @value{GDBN} knows about
18377 this: it will strip the prefix from names when you use it, and will never
18378 look for a name you have so qualified among local symbols, nor match against
18379 symbols in other packages or subprograms. If you have
18380 defined entities anywhere in your program other than parameters and
18381 local variables whose simple names match names in @code{Standard},
18382 GNAT's lack of qualification here can cause confusion. When this happens,
18383 you can usually resolve the confusion
18384 by qualifying the problematic names with package
18385 @code{Standard} explicitly.
18386 @end itemize
18387
18388 Older versions of the compiler sometimes generate erroneous debugging
18389 information, resulting in the debugger incorrectly printing the value
18390 of affected entities. In some cases, the debugger is able to work
18391 around an issue automatically. In other cases, the debugger is able
18392 to work around the issue, but the work-around has to be specifically
18393 enabled.
18394
18395 @kindex set ada trust-PAD-over-XVS
18396 @kindex show ada trust-PAD-over-XVS
18397 @table @code
18398
18399 @item set ada trust-PAD-over-XVS on
18400 Configure GDB to strictly follow the GNAT encoding when computing the
18401 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18402 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18403 a complete description of the encoding used by the GNAT compiler).
18404 This is the default.
18405
18406 @item set ada trust-PAD-over-XVS off
18407 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18408 sometimes prints the wrong value for certain entities, changing @code{ada
18409 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18410 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18411 @code{off}, but this incurs a slight performance penalty, so it is
18412 recommended to leave this setting to @code{on} unless necessary.
18413
18414 @end table
18415
18416 @cindex GNAT descriptive types
18417 @cindex GNAT encoding
18418 Internally, the debugger also relies on the compiler following a number
18419 of conventions known as the @samp{GNAT Encoding}, all documented in
18420 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18421 how the debugging information should be generated for certain types.
18422 In particular, this convention makes use of @dfn{descriptive types},
18423 which are artificial types generated purely to help the debugger.
18424
18425 These encodings were defined at a time when the debugging information
18426 format used was not powerful enough to describe some of the more complex
18427 types available in Ada. Since DWARF allows us to express nearly all
18428 Ada features, the long-term goal is to slowly replace these descriptive
18429 types by their pure DWARF equivalent. To facilitate that transition,
18430 a new maintenance option is available to force the debugger to ignore
18431 those descriptive types. It allows the user to quickly evaluate how
18432 well @value{GDBN} works without them.
18433
18434 @table @code
18435
18436 @kindex maint ada set ignore-descriptive-types
18437 @item maintenance ada set ignore-descriptive-types [on|off]
18438 Control whether the debugger should ignore descriptive types.
18439 The default is not to ignore descriptives types (@code{off}).
18440
18441 @kindex maint ada show ignore-descriptive-types
18442 @item maintenance ada show ignore-descriptive-types
18443 Show if descriptive types are ignored by @value{GDBN}.
18444
18445 @end table
18446
18447 @node Unsupported Languages
18448 @section Unsupported Languages
18449
18450 @cindex unsupported languages
18451 @cindex minimal language
18452 In addition to the other fully-supported programming languages,
18453 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18454 It does not represent a real programming language, but provides a set
18455 of capabilities close to what the C or assembly languages provide.
18456 This should allow most simple operations to be performed while debugging
18457 an application that uses a language currently not supported by @value{GDBN}.
18458
18459 If the language is set to @code{auto}, @value{GDBN} will automatically
18460 select this language if the current frame corresponds to an unsupported
18461 language.
18462
18463 @node Symbols
18464 @chapter Examining the Symbol Table
18465
18466 The commands described in this chapter allow you to inquire about the
18467 symbols (names of variables, functions and types) defined in your
18468 program. This information is inherent in the text of your program and
18469 does not change as your program executes. @value{GDBN} finds it in your
18470 program's symbol table, in the file indicated when you started @value{GDBN}
18471 (@pxref{File Options, ,Choosing Files}), or by one of the
18472 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18473
18474 @cindex symbol names
18475 @cindex names of symbols
18476 @cindex quoting names
18477 @anchor{quoting names}
18478 Occasionally, you may need to refer to symbols that contain unusual
18479 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18480 most frequent case is in referring to static variables in other
18481 source files (@pxref{Variables,,Program Variables}). File names
18482 are recorded in object files as debugging symbols, but @value{GDBN} would
18483 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18484 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18485 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18486
18487 @smallexample
18488 p 'foo.c'::x
18489 @end smallexample
18490
18491 @noindent
18492 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18493
18494 @table @code
18495 @cindex case-insensitive symbol names
18496 @cindex case sensitivity in symbol names
18497 @kindex set case-sensitive
18498 @item set case-sensitive on
18499 @itemx set case-sensitive off
18500 @itemx set case-sensitive auto
18501 Normally, when @value{GDBN} looks up symbols, it matches their names
18502 with case sensitivity determined by the current source language.
18503 Occasionally, you may wish to control that. The command @code{set
18504 case-sensitive} lets you do that by specifying @code{on} for
18505 case-sensitive matches or @code{off} for case-insensitive ones. If
18506 you specify @code{auto}, case sensitivity is reset to the default
18507 suitable for the source language. The default is case-sensitive
18508 matches for all languages except for Fortran, for which the default is
18509 case-insensitive matches.
18510
18511 @kindex show case-sensitive
18512 @item show case-sensitive
18513 This command shows the current setting of case sensitivity for symbols
18514 lookups.
18515
18516 @kindex set print type methods
18517 @item set print type methods
18518 @itemx set print type methods on
18519 @itemx set print type methods off
18520 Normally, when @value{GDBN} prints a class, it displays any methods
18521 declared in that class. You can control this behavior either by
18522 passing the appropriate flag to @code{ptype}, or using @command{set
18523 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18524 display the methods; this is the default. Specifying @code{off} will
18525 cause @value{GDBN} to omit the methods.
18526
18527 @kindex show print type methods
18528 @item show print type methods
18529 This command shows the current setting of method display when printing
18530 classes.
18531
18532 @kindex set print type nested-type-limit
18533 @item set print type nested-type-limit @var{limit}
18534 @itemx set print type nested-type-limit unlimited
18535 Set the limit of displayed nested types that the type printer will
18536 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18537 nested definitions. By default, the type printer will not show any nested
18538 types defined in classes.
18539
18540 @kindex show print type nested-type-limit
18541 @item show print type nested-type-limit
18542 This command shows the current display limit of nested types when
18543 printing classes.
18544
18545 @kindex set print type typedefs
18546 @item set print type typedefs
18547 @itemx set print type typedefs on
18548 @itemx set print type typedefs off
18549
18550 Normally, when @value{GDBN} prints a class, it displays any typedefs
18551 defined in that class. You can control this behavior either by
18552 passing the appropriate flag to @code{ptype}, or using @command{set
18553 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18554 display the typedef definitions; this is the default. Specifying
18555 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18556 Note that this controls whether the typedef definition itself is
18557 printed, not whether typedef names are substituted when printing other
18558 types.
18559
18560 @kindex show print type typedefs
18561 @item show print type typedefs
18562 This command shows the current setting of typedef display when
18563 printing classes.
18564
18565 @kindex info address
18566 @cindex address of a symbol
18567 @item info address @var{symbol}
18568 Describe where the data for @var{symbol} is stored. For a register
18569 variable, this says which register it is kept in. For a non-register
18570 local variable, this prints the stack-frame offset at which the variable
18571 is always stored.
18572
18573 Note the contrast with @samp{print &@var{symbol}}, which does not work
18574 at all for a register variable, and for a stack local variable prints
18575 the exact address of the current instantiation of the variable.
18576
18577 @kindex info symbol
18578 @cindex symbol from address
18579 @cindex closest symbol and offset for an address
18580 @item info symbol @var{addr}
18581 Print the name of a symbol which is stored at the address @var{addr}.
18582 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18583 nearest symbol and an offset from it:
18584
18585 @smallexample
18586 (@value{GDBP}) info symbol 0x54320
18587 _initialize_vx + 396 in section .text
18588 @end smallexample
18589
18590 @noindent
18591 This is the opposite of the @code{info address} command. You can use
18592 it to find out the name of a variable or a function given its address.
18593
18594 For dynamically linked executables, the name of executable or shared
18595 library containing the symbol is also printed:
18596
18597 @smallexample
18598 (@value{GDBP}) info symbol 0x400225
18599 _start + 5 in section .text of /tmp/a.out
18600 (@value{GDBP}) info symbol 0x2aaaac2811cf
18601 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18602 @end smallexample
18603
18604 @kindex demangle
18605 @cindex demangle
18606 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18607 Demangle @var{name}.
18608 If @var{language} is provided it is the name of the language to demangle
18609 @var{name} in. Otherwise @var{name} is demangled in the current language.
18610
18611 The @samp{--} option specifies the end of options,
18612 and is useful when @var{name} begins with a dash.
18613
18614 The parameter @code{demangle-style} specifies how to interpret the kind
18615 of mangling used. @xref{Print Settings}.
18616
18617 @kindex whatis
18618 @item whatis[/@var{flags}] [@var{arg}]
18619 Print the data type of @var{arg}, which can be either an expression
18620 or a name of a data type. With no argument, print the data type of
18621 @code{$}, the last value in the value history.
18622
18623 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18624 is not actually evaluated, and any side-effecting operations (such as
18625 assignments or function calls) inside it do not take place.
18626
18627 If @var{arg} is a variable or an expression, @code{whatis} prints its
18628 literal type as it is used in the source code. If the type was
18629 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18630 the data type underlying the @code{typedef}. If the type of the
18631 variable or the expression is a compound data type, such as
18632 @code{struct} or @code{class}, @code{whatis} never prints their
18633 fields or methods. It just prints the @code{struct}/@code{class}
18634 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18635 such a compound data type, use @code{ptype}.
18636
18637 If @var{arg} is a type name that was defined using @code{typedef},
18638 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18639 Unrolling means that @code{whatis} will show the underlying type used
18640 in the @code{typedef} declaration of @var{arg}. However, if that
18641 underlying type is also a @code{typedef}, @code{whatis} will not
18642 unroll it.
18643
18644 For C code, the type names may also have the form @samp{class
18645 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18646 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18647
18648 @var{flags} can be used to modify how the type is displayed.
18649 Available flags are:
18650
18651 @table @code
18652 @item r
18653 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18654 parameters and typedefs defined in a class when printing the class'
18655 members. The @code{/r} flag disables this.
18656
18657 @item m
18658 Do not print methods defined in the class.
18659
18660 @item M
18661 Print methods defined in the class. This is the default, but the flag
18662 exists in case you change the default with @command{set print type methods}.
18663
18664 @item t
18665 Do not print typedefs defined in the class. Note that this controls
18666 whether the typedef definition itself is printed, not whether typedef
18667 names are substituted when printing other types.
18668
18669 @item T
18670 Print typedefs defined in the class. This is the default, but the flag
18671 exists in case you change the default with @command{set print type typedefs}.
18672
18673 @item o
18674 Print the offsets and sizes of fields in a struct, similar to what the
18675 @command{pahole} tool does. This option implies the @code{/tm} flags.
18676
18677 For example, given the following declarations:
18678
18679 @smallexample
18680 struct tuv
18681 @{
18682 int a1;
18683 char *a2;
18684 int a3;
18685 @};
18686
18687 struct xyz
18688 @{
18689 int f1;
18690 char f2;
18691 void *f3;
18692 struct tuv f4;
18693 @};
18694
18695 union qwe
18696 @{
18697 struct tuv fff1;
18698 struct xyz fff2;
18699 @};
18700
18701 struct tyu
18702 @{
18703 int a1 : 1;
18704 int a2 : 3;
18705 int a3 : 23;
18706 char a4 : 2;
18707 int64_t a5;
18708 int a6 : 5;
18709 int64_t a7 : 3;
18710 @};
18711 @end smallexample
18712
18713 Issuing a @kbd{ptype /o struct tuv} command would print:
18714
18715 @smallexample
18716 (@value{GDBP}) ptype /o struct tuv
18717 /* offset | size */ type = struct tuv @{
18718 /* 0 | 4 */ int a1;
18719 /* XXX 4-byte hole */
18720 /* 8 | 8 */ char *a2;
18721 /* 16 | 4 */ int a3;
18722
18723 /* total size (bytes): 24 */
18724 @}
18725 @end smallexample
18726
18727 Notice the format of the first column of comments. There, you can
18728 find two parts separated by the @samp{|} character: the @emph{offset},
18729 which indicates where the field is located inside the struct, in
18730 bytes, and the @emph{size} of the field. Another interesting line is
18731 the marker of a @emph{hole} in the struct, indicating that it may be
18732 possible to pack the struct and make it use less space by reorganizing
18733 its fields.
18734
18735 It is also possible to print offsets inside an union:
18736
18737 @smallexample
18738 (@value{GDBP}) ptype /o union qwe
18739 /* offset | size */ type = union qwe @{
18740 /* 24 */ struct tuv @{
18741 /* 0 | 4 */ int a1;
18742 /* XXX 4-byte hole */
18743 /* 8 | 8 */ char *a2;
18744 /* 16 | 4 */ int a3;
18745
18746 /* total size (bytes): 24 */
18747 @} fff1;
18748 /* 40 */ struct xyz @{
18749 /* 0 | 4 */ int f1;
18750 /* 4 | 1 */ char f2;
18751 /* XXX 3-byte hole */
18752 /* 8 | 8 */ void *f3;
18753 /* 16 | 24 */ struct tuv @{
18754 /* 16 | 4 */ int a1;
18755 /* XXX 4-byte hole */
18756 /* 24 | 8 */ char *a2;
18757 /* 32 | 4 */ int a3;
18758
18759 /* total size (bytes): 24 */
18760 @} f4;
18761
18762 /* total size (bytes): 40 */
18763 @} fff2;
18764
18765 /* total size (bytes): 40 */
18766 @}
18767 @end smallexample
18768
18769 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18770 same space (because we are dealing with an union), the offset is not
18771 printed for them. However, you can still examine the offset of each
18772 of these structures' fields.
18773
18774 Another useful scenario is printing the offsets of a struct containing
18775 bitfields:
18776
18777 @smallexample
18778 (@value{GDBP}) ptype /o struct tyu
18779 /* offset | size */ type = struct tyu @{
18780 /* 0:31 | 4 */ int a1 : 1;
18781 /* 0:28 | 4 */ int a2 : 3;
18782 /* 0: 5 | 4 */ int a3 : 23;
18783 /* 3: 3 | 1 */ signed char a4 : 2;
18784 /* XXX 3-bit hole */
18785 /* XXX 4-byte hole */
18786 /* 8 | 8 */ int64_t a5;
18787 /* 16: 0 | 4 */ int a6 : 5;
18788 /* 16: 5 | 8 */ int64_t a7 : 3;
18789 "/* XXX 7-byte padding */
18790
18791 /* total size (bytes): 24 */
18792 @}
18793 @end smallexample
18794
18795 Note how the offset information is now extended to also include the
18796 first bit of the bitfield.
18797 @end table
18798
18799 @kindex ptype
18800 @item ptype[/@var{flags}] [@var{arg}]
18801 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
18802 detailed description of the type, instead of just the name of the type.
18803 @xref{Expressions, ,Expressions}.
18804
18805 Contrary to @code{whatis}, @code{ptype} always unrolls any
18806 @code{typedef}s in its argument declaration, whether the argument is
18807 a variable, expression, or a data type. This means that @code{ptype}
18808 of a variable or an expression will not print literally its type as
18809 present in the source code---use @code{whatis} for that. @code{typedef}s at
18810 the pointer or reference targets are also unrolled. Only @code{typedef}s of
18811 fields, methods and inner @code{class typedef}s of @code{struct}s,
18812 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18813
18814 For example, for this variable declaration:
18815
18816 @smallexample
18817 typedef double real_t;
18818 struct complex @{ real_t real; double imag; @};
18819 typedef struct complex complex_t;
18820 complex_t var;
18821 real_t *real_pointer_var;
18822 @end smallexample
18823
18824 @noindent
18825 the two commands give this output:
18826
18827 @smallexample
18828 @group
18829 (@value{GDBP}) whatis var
18830 type = complex_t
18831 (@value{GDBP}) ptype var
18832 type = struct complex @{
18833 real_t real;
18834 double imag;
18835 @}
18836 (@value{GDBP}) whatis complex_t
18837 type = struct complex
18838 (@value{GDBP}) whatis struct complex
18839 type = struct complex
18840 (@value{GDBP}) ptype struct complex
18841 type = struct complex @{
18842 real_t real;
18843 double imag;
18844 @}
18845 (@value{GDBP}) whatis real_pointer_var
18846 type = real_t *
18847 (@value{GDBP}) ptype real_pointer_var
18848 type = double *
18849 @end group
18850 @end smallexample
18851
18852 @noindent
18853 As with @code{whatis}, using @code{ptype} without an argument refers to
18854 the type of @code{$}, the last value in the value history.
18855
18856 @cindex incomplete type
18857 Sometimes, programs use opaque data types or incomplete specifications
18858 of complex data structure. If the debug information included in the
18859 program does not allow @value{GDBN} to display a full declaration of
18860 the data type, it will say @samp{<incomplete type>}. For example,
18861 given these declarations:
18862
18863 @smallexample
18864 struct foo;
18865 struct foo *fooptr;
18866 @end smallexample
18867
18868 @noindent
18869 but no definition for @code{struct foo} itself, @value{GDBN} will say:
18870
18871 @smallexample
18872 (@value{GDBP}) ptype foo
18873 $1 = <incomplete type>
18874 @end smallexample
18875
18876 @noindent
18877 ``Incomplete type'' is C terminology for data types that are not
18878 completely specified.
18879
18880 @cindex unknown type
18881 Othertimes, information about a variable's type is completely absent
18882 from the debug information included in the program. This most often
18883 happens when the program or library where the variable is defined
18884 includes no debug information at all. @value{GDBN} knows the variable
18885 exists from inspecting the linker/loader symbol table (e.g., the ELF
18886 dynamic symbol table), but such symbols do not contain type
18887 information. Inspecting the type of a (global) variable for which
18888 @value{GDBN} has no type information shows:
18889
18890 @smallexample
18891 (@value{GDBP}) ptype var
18892 type = <data variable, no debug info>
18893 @end smallexample
18894
18895 @xref{Variables, no debug info variables}, for how to print the values
18896 of such variables.
18897
18898 @kindex info types
18899 @item info types [-q] [@var{regexp}]
18900 Print a brief description of all types whose names match the regular
18901 expression @var{regexp} (or all types in your program, if you supply
18902 no argument). Each complete typename is matched as though it were a
18903 complete line; thus, @samp{i type value} gives information on all
18904 types in your program whose names include the string @code{value}, but
18905 @samp{i type ^value$} gives information only on types whose complete
18906 name is @code{value}.
18907
18908 In programs using different languages, @value{GDBN} chooses the syntax
18909 to print the type description according to the
18910 @samp{set language} value: using @samp{set language auto}
18911 (see @ref{Automatically, ,Set Language Automatically}) means to use the
18912 language of the type, other values mean to use
18913 the manually specified language (see @ref{Manually, ,Set Language Manually}).
18914
18915 This command differs from @code{ptype} in two ways: first, like
18916 @code{whatis}, it does not print a detailed description; second, it
18917 lists all source files and line numbers where a type is defined.
18918
18919 The output from @samp{into types} is proceeded with a header line
18920 describing what types are being listed. The optional flag @samp{-q},
18921 which stands for @samp{quiet}, disables printing this header
18922 information.
18923
18924 @kindex info type-printers
18925 @item info type-printers
18926 Versions of @value{GDBN} that ship with Python scripting enabled may
18927 have ``type printers'' available. When using @command{ptype} or
18928 @command{whatis}, these printers are consulted when the name of a type
18929 is needed. @xref{Type Printing API}, for more information on writing
18930 type printers.
18931
18932 @code{info type-printers} displays all the available type printers.
18933
18934 @kindex enable type-printer
18935 @kindex disable type-printer
18936 @item enable type-printer @var{name}@dots{}
18937 @item disable type-printer @var{name}@dots{}
18938 These commands can be used to enable or disable type printers.
18939
18940 @kindex info scope
18941 @cindex local variables
18942 @item info scope @var{location}
18943 List all the variables local to a particular scope. This command
18944 accepts a @var{location} argument---a function name, a source line, or
18945 an address preceded by a @samp{*}, and prints all the variables local
18946 to the scope defined by that location. (@xref{Specify Location}, for
18947 details about supported forms of @var{location}.) For example:
18948
18949 @smallexample
18950 (@value{GDBP}) @b{info scope command_line_handler}
18951 Scope for command_line_handler:
18952 Symbol rl is an argument at stack/frame offset 8, length 4.
18953 Symbol linebuffer is in static storage at address 0x150a18, length 4.
18954 Symbol linelength is in static storage at address 0x150a1c, length 4.
18955 Symbol p is a local variable in register $esi, length 4.
18956 Symbol p1 is a local variable in register $ebx, length 4.
18957 Symbol nline is a local variable in register $edx, length 4.
18958 Symbol repeat is a local variable at frame offset -8, length 4.
18959 @end smallexample
18960
18961 @noindent
18962 This command is especially useful for determining what data to collect
18963 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18964 collect}.
18965
18966 @kindex info source
18967 @item info source
18968 Show information about the current source file---that is, the source file for
18969 the function containing the current point of execution:
18970 @itemize @bullet
18971 @item
18972 the name of the source file, and the directory containing it,
18973 @item
18974 the directory it was compiled in,
18975 @item
18976 its length, in lines,
18977 @item
18978 which programming language it is written in,
18979 @item
18980 if the debug information provides it, the program that compiled the file
18981 (which may include, e.g., the compiler version and command line arguments),
18982 @item
18983 whether the executable includes debugging information for that file, and
18984 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18985 @item
18986 whether the debugging information includes information about
18987 preprocessor macros.
18988 @end itemize
18989
18990
18991 @kindex info sources
18992 @item info sources
18993 Print the names of all source files in your program for which there is
18994 debugging information, organized into two lists: files whose symbols
18995 have already been read, and files whose symbols will be read when needed.
18996
18997 @item info sources [-dirname | -basename] [--] [@var{regexp}]
18998 Like @samp{info sources}, but only print the names of the files
18999 matching the provided @var{regexp}.
19000 By default, the @var{regexp} is used to match anywhere in the filename.
19001 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19002 If @code{-basename}, only files having a basename matching @var{regexp}
19003 are shown.
19004 The matching is case-sensitive, except on operating systems that
19005 have case-insensitive filesystem (e.g., MS-Windows).
19006
19007 @kindex info functions
19008 @item info functions [-q] [-n]
19009 Print the names and data types of all defined functions.
19010 Similarly to @samp{info types}, this command groups its output by source
19011 files and annotates each function definition with its source line
19012 number.
19013
19014 In programs using different languages, @value{GDBN} chooses the syntax
19015 to print the function name and type according to the
19016 @samp{set language} value: using @samp{set language auto}
19017 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19018 language of the function, other values mean to use
19019 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19020
19021 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19022 results. A non-debugging symbol is a symbol that comes from the
19023 executable's symbol table, not from the debug information (for
19024 example, DWARF) associated with the executable.
19025
19026 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19027 printing header information and messages explaining why no functions
19028 have been printed.
19029
19030 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19031 Like @samp{info functions}, but only print the names and data types
19032 of the functions selected with the provided regexp(s).
19033
19034 If @var{regexp} is provided, print only the functions whose names
19035 match the regular expression @var{regexp}.
19036 Thus, @samp{info fun step} finds all functions whose
19037 names include @code{step}; @samp{info fun ^step} finds those whose names
19038 start with @code{step}. If a function name contains characters that
19039 conflict with the regular expression language (e.g.@:
19040 @samp{operator*()}), they may be quoted with a backslash.
19041
19042 If @var{type_regexp} is provided, print only the functions whose
19043 types, as printed by the @code{whatis} command, match
19044 the regular expression @var{type_regexp}.
19045 If @var{type_regexp} contains space(s), it should be enclosed in
19046 quote characters. If needed, use backslash to escape the meaning
19047 of special characters or quotes.
19048 Thus, @samp{info fun -t '^int ('} finds the functions that return
19049 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19050 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19051 finds the functions whose names start with @code{step} and that return
19052 int.
19053
19054 If both @var{regexp} and @var{type_regexp} are provided, a function
19055 is printed only if its name matches @var{regexp} and its type matches
19056 @var{type_regexp}.
19057
19058
19059 @kindex info variables
19060 @item info variables [-q] [-n]
19061 Print the names and data types of all variables that are defined
19062 outside of functions (i.e.@: excluding local variables).
19063 The printed variables are grouped by source files and annotated with
19064 their respective source line numbers.
19065
19066 In programs using different languages, @value{GDBN} chooses the syntax
19067 to print the variable name and type according to the
19068 @samp{set language} value: using @samp{set language auto}
19069 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19070 language of the variable, other values mean to use
19071 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19072
19073 The @samp{-n} flag excludes non-debugging symbols from the results.
19074
19075 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19076 printing header information and messages explaining why no variables
19077 have been printed.
19078
19079 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19080 Like @kbd{info variables}, but only print the variables selected
19081 with the provided regexp(s).
19082
19083 If @var{regexp} is provided, print only the variables whose names
19084 match the regular expression @var{regexp}.
19085
19086 If @var{type_regexp} is provided, print only the variables whose
19087 types, as printed by the @code{whatis} command, match
19088 the regular expression @var{type_regexp}.
19089 If @var{type_regexp} contains space(s), it should be enclosed in
19090 quote characters. If needed, use backslash to escape the meaning
19091 of special characters or quotes.
19092
19093 If both @var{regexp} and @var{type_regexp} are provided, an argument
19094 is printed only if its name matches @var{regexp} and its type matches
19095 @var{type_regexp}.
19096
19097 @kindex info modules
19098 @cindex modules
19099 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19100 List all Fortran modules in the program, or all modules matching the
19101 optional regular expression @var{regexp}.
19102
19103 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19104 printing header information and messages explaining why no modules
19105 have been printed.
19106
19107 @kindex info module
19108 @cindex Fortran modules, information about
19109 @cindex functions and variables by Fortran module
19110 @cindex module functions and variables
19111 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19112 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19113 List all functions or variables within all Fortran modules. The set
19114 of functions or variables listed can be limited by providing some or
19115 all of the optional regular expressions. If @var{module-regexp} is
19116 provided, then only Fortran modules matching @var{module-regexp} will
19117 be searched. Only functions or variables whose type matches the
19118 optional regular expression @var{type-regexp} will be listed. And
19119 only functions or variables whose name matches the optional regular
19120 expression @var{regexp} will be listed.
19121
19122 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19123 printing header information and messages explaining why no functions
19124 or variables have been printed.
19125
19126 @kindex info classes
19127 @cindex Objective-C, classes and selectors
19128 @item info classes
19129 @itemx info classes @var{regexp}
19130 Display all Objective-C classes in your program, or
19131 (with the @var{regexp} argument) all those matching a particular regular
19132 expression.
19133
19134 @kindex info selectors
19135 @item info selectors
19136 @itemx info selectors @var{regexp}
19137 Display all Objective-C selectors in your program, or
19138 (with the @var{regexp} argument) all those matching a particular regular
19139 expression.
19140
19141 @ignore
19142 This was never implemented.
19143 @kindex info methods
19144 @item info methods
19145 @itemx info methods @var{regexp}
19146 The @code{info methods} command permits the user to examine all defined
19147 methods within C@t{++} program, or (with the @var{regexp} argument) a
19148 specific set of methods found in the various C@t{++} classes. Many
19149 C@t{++} classes provide a large number of methods. Thus, the output
19150 from the @code{ptype} command can be overwhelming and hard to use. The
19151 @code{info-methods} command filters the methods, printing only those
19152 which match the regular-expression @var{regexp}.
19153 @end ignore
19154
19155 @cindex opaque data types
19156 @kindex set opaque-type-resolution
19157 @item set opaque-type-resolution on
19158 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19159 declared as a pointer to a @code{struct}, @code{class}, or
19160 @code{union}---for example, @code{struct MyType *}---that is used in one
19161 source file although the full declaration of @code{struct MyType} is in
19162 another source file. The default is on.
19163
19164 A change in the setting of this subcommand will not take effect until
19165 the next time symbols for a file are loaded.
19166
19167 @item set opaque-type-resolution off
19168 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19169 is printed as follows:
19170 @smallexample
19171 @{<no data fields>@}
19172 @end smallexample
19173
19174 @kindex show opaque-type-resolution
19175 @item show opaque-type-resolution
19176 Show whether opaque types are resolved or not.
19177
19178 @kindex set print symbol-loading
19179 @cindex print messages when symbols are loaded
19180 @item set print symbol-loading
19181 @itemx set print symbol-loading full
19182 @itemx set print symbol-loading brief
19183 @itemx set print symbol-loading off
19184 The @code{set print symbol-loading} command allows you to control the
19185 printing of messages when @value{GDBN} loads symbol information.
19186 By default a message is printed for the executable and one for each
19187 shared library, and normally this is what you want. However, when
19188 debugging apps with large numbers of shared libraries these messages
19189 can be annoying.
19190 When set to @code{brief} a message is printed for each executable,
19191 and when @value{GDBN} loads a collection of shared libraries at once
19192 it will only print one message regardless of the number of shared
19193 libraries. When set to @code{off} no messages are printed.
19194
19195 @kindex show print symbol-loading
19196 @item show print symbol-loading
19197 Show whether messages will be printed when a @value{GDBN} command
19198 entered from the keyboard causes symbol information to be loaded.
19199
19200 @kindex maint print symbols
19201 @cindex symbol dump
19202 @kindex maint print psymbols
19203 @cindex partial symbol dump
19204 @kindex maint print msymbols
19205 @cindex minimal symbol dump
19206 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19207 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19208 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19209 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19210 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19211 Write a dump of debugging symbol data into the file @var{filename} or
19212 the terminal if @var{filename} is unspecified.
19213 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19214 that objfile.
19215 If @code{-pc @var{address}} is specified, only dump symbols for the file
19216 with code at that address. Note that @var{address} may be a symbol like
19217 @code{main}.
19218 If @code{-source @var{source}} is specified, only dump symbols for that
19219 source file.
19220
19221 These commands are used to debug the @value{GDBN} symbol-reading code.
19222 These commands do not modify internal @value{GDBN} state, therefore
19223 @samp{maint print symbols} will only print symbols for already expanded symbol
19224 tables.
19225 You can use the command @code{info sources} to find out which files these are.
19226 If you use @samp{maint print psymbols} instead, the dump shows information
19227 about symbols that @value{GDBN} only knows partially---that is, symbols
19228 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19229 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19230 ``ELF symbols''.
19231
19232 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19233 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19234
19235 @kindex maint info symtabs
19236 @kindex maint info psymtabs
19237 @cindex listing @value{GDBN}'s internal symbol tables
19238 @cindex symbol tables, listing @value{GDBN}'s internal
19239 @cindex full symbol tables, listing @value{GDBN}'s internal
19240 @cindex partial symbol tables, listing @value{GDBN}'s internal
19241 @item maint info symtabs @r{[} @var{regexp} @r{]}
19242 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19243
19244 List the @code{struct symtab} or @code{struct partial_symtab}
19245 structures whose names match @var{regexp}. If @var{regexp} is not
19246 given, list them all. The output includes expressions which you can
19247 copy into a @value{GDBN} debugging this one to examine a particular
19248 structure in more detail. For example:
19249
19250 @smallexample
19251 (@value{GDBP}) maint info psymtabs dwarf2read
19252 @{ objfile /home/gnu/build/gdb/gdb
19253 ((struct objfile *) 0x82e69d0)
19254 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19255 ((struct partial_symtab *) 0x8474b10)
19256 readin no
19257 fullname (null)
19258 text addresses 0x814d3c8 -- 0x8158074
19259 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19260 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19261 dependencies (none)
19262 @}
19263 @}
19264 (@value{GDBP}) maint info symtabs
19265 (@value{GDBP})
19266 @end smallexample
19267 @noindent
19268 We see that there is one partial symbol table whose filename contains
19269 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19270 and we see that @value{GDBN} has not read in any symtabs yet at all.
19271 If we set a breakpoint on a function, that will cause @value{GDBN} to
19272 read the symtab for the compilation unit containing that function:
19273
19274 @smallexample
19275 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19276 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19277 line 1574.
19278 (@value{GDBP}) maint info symtabs
19279 @{ objfile /home/gnu/build/gdb/gdb
19280 ((struct objfile *) 0x82e69d0)
19281 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19282 ((struct symtab *) 0x86c1f38)
19283 dirname (null)
19284 fullname (null)
19285 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19286 linetable ((struct linetable *) 0x8370fa0)
19287 debugformat DWARF 2
19288 @}
19289 @}
19290 (@value{GDBP})
19291 @end smallexample
19292
19293 @kindex maint info line-table
19294 @cindex listing @value{GDBN}'s internal line tables
19295 @cindex line tables, listing @value{GDBN}'s internal
19296 @item maint info line-table @r{[} @var{regexp} @r{]}
19297
19298 List the @code{struct linetable} from all @code{struct symtab}
19299 instances whose name matches @var{regexp}. If @var{regexp} is not
19300 given, list the @code{struct linetable} from all @code{struct symtab}.
19301
19302 @kindex maint set symbol-cache-size
19303 @cindex symbol cache size
19304 @item maint set symbol-cache-size @var{size}
19305 Set the size of the symbol cache to @var{size}.
19306 The default size is intended to be good enough for debugging
19307 most applications. This option exists to allow for experimenting
19308 with different sizes.
19309
19310 @kindex maint show symbol-cache-size
19311 @item maint show symbol-cache-size
19312 Show the size of the symbol cache.
19313
19314 @kindex maint print symbol-cache
19315 @cindex symbol cache, printing its contents
19316 @item maint print symbol-cache
19317 Print the contents of the symbol cache.
19318 This is useful when debugging symbol cache issues.
19319
19320 @kindex maint print symbol-cache-statistics
19321 @cindex symbol cache, printing usage statistics
19322 @item maint print symbol-cache-statistics
19323 Print symbol cache usage statistics.
19324 This helps determine how well the cache is being utilized.
19325
19326 @kindex maint flush-symbol-cache
19327 @cindex symbol cache, flushing
19328 @item maint flush-symbol-cache
19329 Flush the contents of the symbol cache, all entries are removed.
19330 This command is useful when debugging the symbol cache.
19331 It is also useful when collecting performance data.
19332
19333 @end table
19334
19335 @node Altering
19336 @chapter Altering Execution
19337
19338 Once you think you have found an error in your program, you might want to
19339 find out for certain whether correcting the apparent error would lead to
19340 correct results in the rest of the run. You can find the answer by
19341 experiment, using the @value{GDBN} features for altering execution of the
19342 program.
19343
19344 For example, you can store new values into variables or memory
19345 locations, give your program a signal, restart it at a different
19346 address, or even return prematurely from a function.
19347
19348 @menu
19349 * Assignment:: Assignment to variables
19350 * Jumping:: Continuing at a different address
19351 * Signaling:: Giving your program a signal
19352 * Returning:: Returning from a function
19353 * Calling:: Calling your program's functions
19354 * Patching:: Patching your program
19355 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19356 @end menu
19357
19358 @node Assignment
19359 @section Assignment to Variables
19360
19361 @cindex assignment
19362 @cindex setting variables
19363 To alter the value of a variable, evaluate an assignment expression.
19364 @xref{Expressions, ,Expressions}. For example,
19365
19366 @smallexample
19367 print x=4
19368 @end smallexample
19369
19370 @noindent
19371 stores the value 4 into the variable @code{x}, and then prints the
19372 value of the assignment expression (which is 4).
19373 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19374 information on operators in supported languages.
19375
19376 @kindex set variable
19377 @cindex variables, setting
19378 If you are not interested in seeing the value of the assignment, use the
19379 @code{set} command instead of the @code{print} command. @code{set} is
19380 really the same as @code{print} except that the expression's value is
19381 not printed and is not put in the value history (@pxref{Value History,
19382 ,Value History}). The expression is evaluated only for its effects.
19383
19384 If the beginning of the argument string of the @code{set} command
19385 appears identical to a @code{set} subcommand, use the @code{set
19386 variable} command instead of just @code{set}. This command is identical
19387 to @code{set} except for its lack of subcommands. For example, if your
19388 program has a variable @code{width}, you get an error if you try to set
19389 a new value with just @samp{set width=13}, because @value{GDBN} has the
19390 command @code{set width}:
19391
19392 @smallexample
19393 (@value{GDBP}) whatis width
19394 type = double
19395 (@value{GDBP}) p width
19396 $4 = 13
19397 (@value{GDBP}) set width=47
19398 Invalid syntax in expression.
19399 @end smallexample
19400
19401 @noindent
19402 The invalid expression, of course, is @samp{=47}. In
19403 order to actually set the program's variable @code{width}, use
19404
19405 @smallexample
19406 (@value{GDBP}) set var width=47
19407 @end smallexample
19408
19409 Because the @code{set} command has many subcommands that can conflict
19410 with the names of program variables, it is a good idea to use the
19411 @code{set variable} command instead of just @code{set}. For example, if
19412 your program has a variable @code{g}, you run into problems if you try
19413 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19414 the command @code{set gnutarget}, abbreviated @code{set g}:
19415
19416 @smallexample
19417 @group
19418 (@value{GDBP}) whatis g
19419 type = double
19420 (@value{GDBP}) p g
19421 $1 = 1
19422 (@value{GDBP}) set g=4
19423 (@value{GDBP}) p g
19424 $2 = 1
19425 (@value{GDBP}) r
19426 The program being debugged has been started already.
19427 Start it from the beginning? (y or n) y
19428 Starting program: /home/smith/cc_progs/a.out
19429 "/home/smith/cc_progs/a.out": can't open to read symbols:
19430 Invalid bfd target.
19431 (@value{GDBP}) show g
19432 The current BFD target is "=4".
19433 @end group
19434 @end smallexample
19435
19436 @noindent
19437 The program variable @code{g} did not change, and you silently set the
19438 @code{gnutarget} to an invalid value. In order to set the variable
19439 @code{g}, use
19440
19441 @smallexample
19442 (@value{GDBP}) set var g=4
19443 @end smallexample
19444
19445 @value{GDBN} allows more implicit conversions in assignments than C; you can
19446 freely store an integer value into a pointer variable or vice versa,
19447 and you can convert any structure to any other structure that is the
19448 same length or shorter.
19449 @comment FIXME: how do structs align/pad in these conversions?
19450 @comment /doc@cygnus.com 18dec1990
19451
19452 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19453 construct to generate a value of specified type at a specified address
19454 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19455 to memory location @code{0x83040} as an integer (which implies a certain size
19456 and representation in memory), and
19457
19458 @smallexample
19459 set @{int@}0x83040 = 4
19460 @end smallexample
19461
19462 @noindent
19463 stores the value 4 into that memory location.
19464
19465 @node Jumping
19466 @section Continuing at a Different Address
19467
19468 Ordinarily, when you continue your program, you do so at the place where
19469 it stopped, with the @code{continue} command. You can instead continue at
19470 an address of your own choosing, with the following commands:
19471
19472 @table @code
19473 @kindex jump
19474 @kindex j @r{(@code{jump})}
19475 @item jump @var{location}
19476 @itemx j @var{location}
19477 Resume execution at @var{location}. Execution stops again immediately
19478 if there is a breakpoint there. @xref{Specify Location}, for a description
19479 of the different forms of @var{location}. It is common
19480 practice to use the @code{tbreak} command in conjunction with
19481 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19482
19483 The @code{jump} command does not change the current stack frame, or
19484 the stack pointer, or the contents of any memory location or any
19485 register other than the program counter. If @var{location} is in
19486 a different function from the one currently executing, the results may
19487 be bizarre if the two functions expect different patterns of arguments or
19488 of local variables. For this reason, the @code{jump} command requests
19489 confirmation if the specified line is not in the function currently
19490 executing. However, even bizarre results are predictable if you are
19491 well acquainted with the machine-language code of your program.
19492 @end table
19493
19494 On many systems, you can get much the same effect as the @code{jump}
19495 command by storing a new value into the register @code{$pc}. The
19496 difference is that this does not start your program running; it only
19497 changes the address of where it @emph{will} run when you continue. For
19498 example,
19499
19500 @smallexample
19501 set $pc = 0x485
19502 @end smallexample
19503
19504 @noindent
19505 makes the next @code{continue} command or stepping command execute at
19506 address @code{0x485}, rather than at the address where your program stopped.
19507 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19508
19509 The most common occasion to use the @code{jump} command is to back
19510 up---perhaps with more breakpoints set---over a portion of a program
19511 that has already executed, in order to examine its execution in more
19512 detail.
19513
19514 @c @group
19515 @node Signaling
19516 @section Giving your Program a Signal
19517 @cindex deliver a signal to a program
19518
19519 @table @code
19520 @kindex signal
19521 @item signal @var{signal}
19522 Resume execution where your program is stopped, but immediately give it the
19523 signal @var{signal}. The @var{signal} can be the name or the number of a
19524 signal. For example, on many systems @code{signal 2} and @code{signal
19525 SIGINT} are both ways of sending an interrupt signal.
19526
19527 Alternatively, if @var{signal} is zero, continue execution without
19528 giving a signal. This is useful when your program stopped on account of
19529 a signal and would ordinarily see the signal when resumed with the
19530 @code{continue} command; @samp{signal 0} causes it to resume without a
19531 signal.
19532
19533 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19534 delivered to the currently selected thread, not the thread that last
19535 reported a stop. This includes the situation where a thread was
19536 stopped due to a signal. So if you want to continue execution
19537 suppressing the signal that stopped a thread, you should select that
19538 same thread before issuing the @samp{signal 0} command. If you issue
19539 the @samp{signal 0} command with another thread as the selected one,
19540 @value{GDBN} detects that and asks for confirmation.
19541
19542 Invoking the @code{signal} command is not the same as invoking the
19543 @code{kill} utility from the shell. Sending a signal with @code{kill}
19544 causes @value{GDBN} to decide what to do with the signal depending on
19545 the signal handling tables (@pxref{Signals}). The @code{signal} command
19546 passes the signal directly to your program.
19547
19548 @code{signal} does not repeat when you press @key{RET} a second time
19549 after executing the command.
19550
19551 @kindex queue-signal
19552 @item queue-signal @var{signal}
19553 Queue @var{signal} to be delivered immediately to the current thread
19554 when execution of the thread resumes. The @var{signal} can be the name or
19555 the number of a signal. For example, on many systems @code{signal 2} and
19556 @code{signal SIGINT} are both ways of sending an interrupt signal.
19557 The handling of the signal must be set to pass the signal to the program,
19558 otherwise @value{GDBN} will report an error.
19559 You can control the handling of signals from @value{GDBN} with the
19560 @code{handle} command (@pxref{Signals}).
19561
19562 Alternatively, if @var{signal} is zero, any currently queued signal
19563 for the current thread is discarded and when execution resumes no signal
19564 will be delivered. This is useful when your program stopped on account
19565 of a signal and would ordinarily see the signal when resumed with the
19566 @code{continue} command.
19567
19568 This command differs from the @code{signal} command in that the signal
19569 is just queued, execution is not resumed. And @code{queue-signal} cannot
19570 be used to pass a signal whose handling state has been set to @code{nopass}
19571 (@pxref{Signals}).
19572 @end table
19573 @c @end group
19574
19575 @xref{stepping into signal handlers}, for information on how stepping
19576 commands behave when the thread has a signal queued.
19577
19578 @node Returning
19579 @section Returning from a Function
19580
19581 @table @code
19582 @cindex returning from a function
19583 @kindex return
19584 @item return
19585 @itemx return @var{expression}
19586 You can cancel execution of a function call with the @code{return}
19587 command. If you give an
19588 @var{expression} argument, its value is used as the function's return
19589 value.
19590 @end table
19591
19592 When you use @code{return}, @value{GDBN} discards the selected stack frame
19593 (and all frames within it). You can think of this as making the
19594 discarded frame return prematurely. If you wish to specify a value to
19595 be returned, give that value as the argument to @code{return}.
19596
19597 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19598 Frame}), and any other frames inside of it, leaving its caller as the
19599 innermost remaining frame. That frame becomes selected. The
19600 specified value is stored in the registers used for returning values
19601 of functions.
19602
19603 The @code{return} command does not resume execution; it leaves the
19604 program stopped in the state that would exist if the function had just
19605 returned. In contrast, the @code{finish} command (@pxref{Continuing
19606 and Stepping, ,Continuing and Stepping}) resumes execution until the
19607 selected stack frame returns naturally.
19608
19609 @value{GDBN} needs to know how the @var{expression} argument should be set for
19610 the inferior. The concrete registers assignment depends on the OS ABI and the
19611 type being returned by the selected stack frame. For example it is common for
19612 OS ABI to return floating point values in FPU registers while integer values in
19613 CPU registers. Still some ABIs return even floating point values in CPU
19614 registers. Larger integer widths (such as @code{long long int}) also have
19615 specific placement rules. @value{GDBN} already knows the OS ABI from its
19616 current target so it needs to find out also the type being returned to make the
19617 assignment into the right register(s).
19618
19619 Normally, the selected stack frame has debug info. @value{GDBN} will always
19620 use the debug info instead of the implicit type of @var{expression} when the
19621 debug info is available. For example, if you type @kbd{return -1}, and the
19622 function in the current stack frame is declared to return a @code{long long
19623 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19624 into a @code{long long int}:
19625
19626 @smallexample
19627 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19628 29 return 31;
19629 (@value{GDBP}) return -1
19630 Make func return now? (y or n) y
19631 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19632 43 printf ("result=%lld\n", func ());
19633 (@value{GDBP})
19634 @end smallexample
19635
19636 However, if the selected stack frame does not have a debug info, e.g., if the
19637 function was compiled without debug info, @value{GDBN} has to find out the type
19638 to return from user. Specifying a different type by mistake may set the value
19639 in different inferior registers than the caller code expects. For example,
19640 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19641 of a @code{long long int} result for a debug info less function (on 32-bit
19642 architectures). Therefore the user is required to specify the return type by
19643 an appropriate cast explicitly:
19644
19645 @smallexample
19646 Breakpoint 2, 0x0040050b in func ()
19647 (@value{GDBP}) return -1
19648 Return value type not available for selected stack frame.
19649 Please use an explicit cast of the value to return.
19650 (@value{GDBP}) return (long long int) -1
19651 Make selected stack frame return now? (y or n) y
19652 #0 0x00400526 in main ()
19653 (@value{GDBP})
19654 @end smallexample
19655
19656 @node Calling
19657 @section Calling Program Functions
19658
19659 @table @code
19660 @cindex calling functions
19661 @cindex inferior functions, calling
19662 @item print @var{expr}
19663 Evaluate the expression @var{expr} and display the resulting value.
19664 The expression may include calls to functions in the program being
19665 debugged.
19666
19667 @kindex call
19668 @item call @var{expr}
19669 Evaluate the expression @var{expr} without displaying @code{void}
19670 returned values.
19671
19672 You can use this variant of the @code{print} command if you want to
19673 execute a function from your program that does not return anything
19674 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19675 with @code{void} returned values that @value{GDBN} will otherwise
19676 print. If the result is not void, it is printed and saved in the
19677 value history.
19678 @end table
19679
19680 It is possible for the function you call via the @code{print} or
19681 @code{call} command to generate a signal (e.g., if there's a bug in
19682 the function, or if you passed it incorrect arguments). What happens
19683 in that case is controlled by the @code{set unwindonsignal} command.
19684
19685 Similarly, with a C@t{++} program it is possible for the function you
19686 call via the @code{print} or @code{call} command to generate an
19687 exception that is not handled due to the constraints of the dummy
19688 frame. In this case, any exception that is raised in the frame, but has
19689 an out-of-frame exception handler will not be found. GDB builds a
19690 dummy-frame for the inferior function call, and the unwinder cannot
19691 seek for exception handlers outside of this dummy-frame. What happens
19692 in that case is controlled by the
19693 @code{set unwind-on-terminating-exception} command.
19694
19695 @table @code
19696 @item set unwindonsignal
19697 @kindex set unwindonsignal
19698 @cindex unwind stack in called functions
19699 @cindex call dummy stack unwinding
19700 Set unwinding of the stack if a signal is received while in a function
19701 that @value{GDBN} called in the program being debugged. If set to on,
19702 @value{GDBN} unwinds the stack it created for the call and restores
19703 the context to what it was before the call. If set to off (the
19704 default), @value{GDBN} stops in the frame where the signal was
19705 received.
19706
19707 @item show unwindonsignal
19708 @kindex show unwindonsignal
19709 Show the current setting of stack unwinding in the functions called by
19710 @value{GDBN}.
19711
19712 @item set unwind-on-terminating-exception
19713 @kindex set unwind-on-terminating-exception
19714 @cindex unwind stack in called functions with unhandled exceptions
19715 @cindex call dummy stack unwinding on unhandled exception.
19716 Set unwinding of the stack if a C@t{++} exception is raised, but left
19717 unhandled while in a function that @value{GDBN} called in the program being
19718 debugged. If set to on (the default), @value{GDBN} unwinds the stack
19719 it created for the call and restores the context to what it was before
19720 the call. If set to off, @value{GDBN} the exception is delivered to
19721 the default C@t{++} exception handler and the inferior terminated.
19722
19723 @item show unwind-on-terminating-exception
19724 @kindex show unwind-on-terminating-exception
19725 Show the current setting of stack unwinding in the functions called by
19726 @value{GDBN}.
19727
19728 @item set may-call-functions
19729 @kindex set may-call-functions
19730 @cindex disabling calling functions in the program
19731 @cindex calling functions in the program, disabling
19732 Set permission to call functions in the program.
19733 This controls whether @value{GDBN} will attempt to call functions in
19734 the program, such as with expressions in the @code{print} command. It
19735 defaults to @code{on}.
19736
19737 To call a function in the program, @value{GDBN} has to temporarily
19738 modify the state of the inferior. This has potentially undesired side
19739 effects. Also, having @value{GDBN} call nested functions is likely to
19740 be erroneous and may even crash the program being debugged. You can
19741 avoid such hazards by forbidding @value{GDBN} from calling functions
19742 in the program being debugged. If calling functions in the program
19743 is forbidden, GDB will throw an error when a command (such as printing
19744 an expression) starts a function call in the program.
19745
19746 @item show may-call-functions
19747 @kindex show may-call-functions
19748 Show permission to call functions in the program.
19749
19750 @end table
19751
19752 @subsection Calling functions with no debug info
19753
19754 @cindex no debug info functions
19755 Sometimes, a function you wish to call is missing debug information.
19756 In such case, @value{GDBN} does not know the type of the function,
19757 including the types of the function's parameters. To avoid calling
19758 the inferior function incorrectly, which could result in the called
19759 function functioning erroneously and even crash, @value{GDBN} refuses
19760 to call the function unless you tell it the type of the function.
19761
19762 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19763 to do that. The simplest is to cast the call to the function's
19764 declared return type. For example:
19765
19766 @smallexample
19767 (@value{GDBP}) p getenv ("PATH")
19768 'getenv' has unknown return type; cast the call to its declared return type
19769 (@value{GDBP}) p (char *) getenv ("PATH")
19770 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19771 @end smallexample
19772
19773 Casting the return type of a no-debug function is equivalent to
19774 casting the function to a pointer to a prototyped function that has a
19775 prototype that matches the types of the passed-in arguments, and
19776 calling that. I.e., the call above is equivalent to:
19777
19778 @smallexample
19779 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19780 @end smallexample
19781
19782 @noindent
19783 and given this prototyped C or C++ function with float parameters:
19784
19785 @smallexample
19786 float multiply (float v1, float v2) @{ return v1 * v2; @}
19787 @end smallexample
19788
19789 @noindent
19790 these calls are equivalent:
19791
19792 @smallexample
19793 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19794 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19795 @end smallexample
19796
19797 If the function you wish to call is declared as unprototyped (i.e.@:
19798 old K&R style), you must use the cast-to-function-pointer syntax, so
19799 that @value{GDBN} knows that it needs to apply default argument
19800 promotions (promote float arguments to double). @xref{ABI, float
19801 promotion}. For example, given this unprototyped C function with
19802 float parameters, and no debug info:
19803
19804 @smallexample
19805 float
19806 multiply_noproto (v1, v2)
19807 float v1, v2;
19808 @{
19809 return v1 * v2;
19810 @}
19811 @end smallexample
19812
19813 @noindent
19814 you call it like this:
19815
19816 @smallexample
19817 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19818 @end smallexample
19819
19820 @node Patching
19821 @section Patching Programs
19822
19823 @cindex patching binaries
19824 @cindex writing into executables
19825 @cindex writing into corefiles
19826
19827 By default, @value{GDBN} opens the file containing your program's
19828 executable code (or the corefile) read-only. This prevents accidental
19829 alterations to machine code; but it also prevents you from intentionally
19830 patching your program's binary.
19831
19832 If you'd like to be able to patch the binary, you can specify that
19833 explicitly with the @code{set write} command. For example, you might
19834 want to turn on internal debugging flags, or even to make emergency
19835 repairs.
19836
19837 @table @code
19838 @kindex set write
19839 @item set write on
19840 @itemx set write off
19841 If you specify @samp{set write on}, @value{GDBN} opens executable and
19842 core files for both reading and writing; if you specify @kbd{set write
19843 off} (the default), @value{GDBN} opens them read-only.
19844
19845 If you have already loaded a file, you must load it again (using the
19846 @code{exec-file} or @code{core-file} command) after changing @code{set
19847 write}, for your new setting to take effect.
19848
19849 @item show write
19850 @kindex show write
19851 Display whether executable files and core files are opened for writing
19852 as well as reading.
19853 @end table
19854
19855 @node Compiling and Injecting Code
19856 @section Compiling and injecting code in @value{GDBN}
19857 @cindex injecting code
19858 @cindex writing into executables
19859 @cindex compiling code
19860
19861 @value{GDBN} supports on-demand compilation and code injection into
19862 programs running under @value{GDBN}. GCC 5.0 or higher built with
19863 @file{libcc1.so} must be installed for this functionality to be enabled.
19864 This functionality is implemented with the following commands.
19865
19866 @table @code
19867 @kindex compile code
19868 @item compile code @var{source-code}
19869 @itemx compile code -raw @var{--} @var{source-code}
19870 Compile @var{source-code} with the compiler language found as the current
19871 language in @value{GDBN} (@pxref{Languages}). If compilation and
19872 injection is not supported with the current language specified in
19873 @value{GDBN}, or the compiler does not support this feature, an error
19874 message will be printed. If @var{source-code} compiles and links
19875 successfully, @value{GDBN} will load the object-code emitted,
19876 and execute it within the context of the currently selected inferior.
19877 It is important to note that the compiled code is executed immediately.
19878 After execution, the compiled code is removed from @value{GDBN} and any
19879 new types or variables you have defined will be deleted.
19880
19881 The command allows you to specify @var{source-code} in two ways.
19882 The simplest method is to provide a single line of code to the command.
19883 E.g.:
19884
19885 @smallexample
19886 compile code printf ("hello world\n");
19887 @end smallexample
19888
19889 If you specify options on the command line as well as source code, they
19890 may conflict. The @samp{--} delimiter can be used to separate options
19891 from actual source code. E.g.:
19892
19893 @smallexample
19894 compile code -r -- printf ("hello world\n");
19895 @end smallexample
19896
19897 Alternatively you can enter source code as multiple lines of text. To
19898 enter this mode, invoke the @samp{compile code} command without any text
19899 following the command. This will start the multiple-line editor and
19900 allow you to type as many lines of source code as required. When you
19901 have completed typing, enter @samp{end} on its own line to exit the
19902 editor.
19903
19904 @smallexample
19905 compile code
19906 >printf ("hello\n");
19907 >printf ("world\n");
19908 >end
19909 @end smallexample
19910
19911 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19912 provided @var{source-code} in a callable scope. In this case, you must
19913 specify the entry point of the code by defining a function named
19914 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19915 inferior. Using @samp{-raw} option may be needed for example when
19916 @var{source-code} requires @samp{#include} lines which may conflict with
19917 inferior symbols otherwise.
19918
19919 @kindex compile file
19920 @item compile file @var{filename}
19921 @itemx compile file -raw @var{filename}
19922 Like @code{compile code}, but take the source code from @var{filename}.
19923
19924 @smallexample
19925 compile file /home/user/example.c
19926 @end smallexample
19927 @end table
19928
19929 @table @code
19930 @item compile print [[@var{options}] --] @var{expr}
19931 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
19932 Compile and execute @var{expr} with the compiler language found as the
19933 current language in @value{GDBN} (@pxref{Languages}). By default the
19934 value of @var{expr} is printed in a format appropriate to its data type;
19935 you can choose a different format by specifying @samp{/@var{f}}, where
19936 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
19937 Formats}. The @code{compile print} command accepts the same options
19938 as the @code{print} command; see @ref{print options}.
19939
19940 @item compile print [[@var{options}] --]
19941 @itemx compile print [[@var{options}] --] /@var{f}
19942 @cindex reprint the last value
19943 Alternatively you can enter the expression (source code producing it) as
19944 multiple lines of text. To enter this mode, invoke the @samp{compile print}
19945 command without any text following the command. This will start the
19946 multiple-line editor.
19947 @end table
19948
19949 @noindent
19950 The process of compiling and injecting the code can be inspected using:
19951
19952 @table @code
19953 @anchor{set debug compile}
19954 @item set debug compile
19955 @cindex compile command debugging info
19956 Turns on or off display of @value{GDBN} process of compiling and
19957 injecting the code. The default is off.
19958
19959 @item show debug compile
19960 Displays the current state of displaying @value{GDBN} process of
19961 compiling and injecting the code.
19962
19963 @anchor{set debug compile-cplus-types}
19964 @item set debug compile-cplus-types
19965 @cindex compile C@t{++} type conversion
19966 Turns on or off the display of C@t{++} type conversion debugging information.
19967 The default is off.
19968
19969 @item show debug compile-cplus-types
19970 Displays the current state of displaying debugging information for
19971 C@t{++} type conversion.
19972 @end table
19973
19974 @subsection Compilation options for the @code{compile} command
19975
19976 @value{GDBN} needs to specify the right compilation options for the code
19977 to be injected, in part to make its ABI compatible with the inferior
19978 and in part to make the injected code compatible with @value{GDBN}'s
19979 injecting process.
19980
19981 @noindent
19982 The options used, in increasing precedence:
19983
19984 @table @asis
19985 @item target architecture and OS options (@code{gdbarch})
19986 These options depend on target processor type and target operating
19987 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19988 (@code{-m64}) compilation option.
19989
19990 @item compilation options recorded in the target
19991 @value{NGCC} (since version 4.7) stores the options used for compilation
19992 into @code{DW_AT_producer} part of DWARF debugging information according
19993 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19994 explicitly specify @code{-g} during inferior compilation otherwise
19995 @value{NGCC} produces no DWARF. This feature is only relevant for
19996 platforms where @code{-g} produces DWARF by default, otherwise one may
19997 try to enforce DWARF by using @code{-gdwarf-4}.
19998
19999 @item compilation options set by @code{set compile-args}
20000 @end table
20001
20002 @noindent
20003 You can override compilation options using the following command:
20004
20005 @table @code
20006 @item set compile-args
20007 @cindex compile command options override
20008 Set compilation options used for compiling and injecting code with the
20009 @code{compile} commands. These options override any conflicting ones
20010 from the target architecture and/or options stored during inferior
20011 compilation.
20012
20013 @item show compile-args
20014 Displays the current state of compilation options override.
20015 This does not show all the options actually used during compilation,
20016 use @ref{set debug compile} for that.
20017 @end table
20018
20019 @subsection Caveats when using the @code{compile} command
20020
20021 There are a few caveats to keep in mind when using the @code{compile}
20022 command. As the caveats are different per language, the table below
20023 highlights specific issues on a per language basis.
20024
20025 @table @asis
20026 @item C code examples and caveats
20027 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20028 attempt to compile the source code with a @samp{C} compiler. The source
20029 code provided to the @code{compile} command will have much the same
20030 access to variables and types as it normally would if it were part of
20031 the program currently being debugged in @value{GDBN}.
20032
20033 Below is a sample program that forms the basis of the examples that
20034 follow. This program has been compiled and loaded into @value{GDBN},
20035 much like any other normal debugging session.
20036
20037 @smallexample
20038 void function1 (void)
20039 @{
20040 int i = 42;
20041 printf ("function 1\n");
20042 @}
20043
20044 void function2 (void)
20045 @{
20046 int j = 12;
20047 function1 ();
20048 @}
20049
20050 int main(void)
20051 @{
20052 int k = 6;
20053 int *p;
20054 function2 ();
20055 return 0;
20056 @}
20057 @end smallexample
20058
20059 For the purposes of the examples in this section, the program above has
20060 been compiled, loaded into @value{GDBN}, stopped at the function
20061 @code{main}, and @value{GDBN} is awaiting input from the user.
20062
20063 To access variables and types for any program in @value{GDBN}, the
20064 program must be compiled and packaged with debug information. The
20065 @code{compile} command is not an exception to this rule. Without debug
20066 information, you can still use the @code{compile} command, but you will
20067 be very limited in what variables and types you can access.
20068
20069 So with that in mind, the example above has been compiled with debug
20070 information enabled. The @code{compile} command will have access to
20071 all variables and types (except those that may have been optimized
20072 out). Currently, as @value{GDBN} has stopped the program in the
20073 @code{main} function, the @code{compile} command would have access to
20074 the variable @code{k}. You could invoke the @code{compile} command
20075 and type some source code to set the value of @code{k}. You can also
20076 read it, or do anything with that variable you would normally do in
20077 @code{C}. Be aware that changes to inferior variables in the
20078 @code{compile} command are persistent. In the following example:
20079
20080 @smallexample
20081 compile code k = 3;
20082 @end smallexample
20083
20084 @noindent
20085 the variable @code{k} is now 3. It will retain that value until
20086 something else in the example program changes it, or another
20087 @code{compile} command changes it.
20088
20089 Normal scope and access rules apply to source code compiled and
20090 injected by the @code{compile} command. In the example, the variables
20091 @code{j} and @code{k} are not accessible yet, because the program is
20092 currently stopped in the @code{main} function, where these variables
20093 are not in scope. Therefore, the following command
20094
20095 @smallexample
20096 compile code j = 3;
20097 @end smallexample
20098
20099 @noindent
20100 will result in a compilation error message.
20101
20102 Once the program is continued, execution will bring these variables in
20103 scope, and they will become accessible; then the code you specify via
20104 the @code{compile} command will be able to access them.
20105
20106 You can create variables and types with the @code{compile} command as
20107 part of your source code. Variables and types that are created as part
20108 of the @code{compile} command are not visible to the rest of the program for
20109 the duration of its run. This example is valid:
20110
20111 @smallexample
20112 compile code int ff = 5; printf ("ff is %d\n", ff);
20113 @end smallexample
20114
20115 However, if you were to type the following into @value{GDBN} after that
20116 command has completed:
20117
20118 @smallexample
20119 compile code printf ("ff is %d\n'', ff);
20120 @end smallexample
20121
20122 @noindent
20123 a compiler error would be raised as the variable @code{ff} no longer
20124 exists. Object code generated and injected by the @code{compile}
20125 command is removed when its execution ends. Caution is advised
20126 when assigning to program variables values of variables created by the
20127 code submitted to the @code{compile} command. This example is valid:
20128
20129 @smallexample
20130 compile code int ff = 5; k = ff;
20131 @end smallexample
20132
20133 The value of the variable @code{ff} is assigned to @code{k}. The variable
20134 @code{k} does not require the existence of @code{ff} to maintain the value
20135 it has been assigned. However, pointers require particular care in
20136 assignment. If the source code compiled with the @code{compile} command
20137 changed the address of a pointer in the example program, perhaps to a
20138 variable created in the @code{compile} command, that pointer would point
20139 to an invalid location when the command exits. The following example
20140 would likely cause issues with your debugged program:
20141
20142 @smallexample
20143 compile code int ff = 5; p = &ff;
20144 @end smallexample
20145
20146 In this example, @code{p} would point to @code{ff} when the
20147 @code{compile} command is executing the source code provided to it.
20148 However, as variables in the (example) program persist with their
20149 assigned values, the variable @code{p} would point to an invalid
20150 location when the command exists. A general rule should be followed
20151 in that you should either assign @code{NULL} to any assigned pointers,
20152 or restore a valid location to the pointer before the command exits.
20153
20154 Similar caution must be exercised with any structs, unions, and typedefs
20155 defined in @code{compile} command. Types defined in the @code{compile}
20156 command will no longer be available in the next @code{compile} command.
20157 Therefore, if you cast a variable to a type defined in the
20158 @code{compile} command, care must be taken to ensure that any future
20159 need to resolve the type can be achieved.
20160
20161 @smallexample
20162 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20163 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20164 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20165 Compilation failed.
20166 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20167 42
20168 @end smallexample
20169
20170 Variables that have been optimized away by the compiler are not
20171 accessible to the code submitted to the @code{compile} command.
20172 Access to those variables will generate a compiler error which @value{GDBN}
20173 will print to the console.
20174 @end table
20175
20176 @subsection Compiler search for the @code{compile} command
20177
20178 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20179 which may not be obvious for remote targets of different architecture
20180 than where @value{GDBN} is running. Environment variable @code{PATH} on
20181 @value{GDBN} host is searched for @value{NGCC} binary matching the
20182 target architecture and operating system. This search can be overriden
20183 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20184 taken from shell that executed @value{GDBN}, it is not the value set by
20185 @value{GDBN} command @code{set environment}). @xref{Environment}.
20186
20187
20188 Specifically @code{PATH} is searched for binaries matching regular expression
20189 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20190 debugged. @var{arch} is processor name --- multiarch is supported, so for
20191 example both @code{i386} and @code{x86_64} targets look for pattern
20192 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20193 for pattern @code{s390x?}. @var{os} is currently supported only for
20194 pattern @code{linux(-gnu)?}.
20195
20196 On Posix hosts the compiler driver @value{GDBN} needs to find also
20197 shared library @file{libcc1.so} from the compiler. It is searched in
20198 default shared library search path (overridable with usual environment
20199 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20200 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20201 according to the installation of the found compiler --- as possibly
20202 specified by the @code{set compile-gcc} command.
20203
20204 @table @code
20205 @item set compile-gcc
20206 @cindex compile command driver filename override
20207 Set compilation command used for compiling and injecting code with the
20208 @code{compile} commands. If this option is not set (it is set to
20209 an empty string), the search described above will occur --- that is the
20210 default.
20211
20212 @item show compile-gcc
20213 Displays the current compile command @value{NGCC} driver filename.
20214 If set, it is the main command @command{gcc}, found usually for example
20215 under name @file{x86_64-linux-gnu-gcc}.
20216 @end table
20217
20218 @node GDB Files
20219 @chapter @value{GDBN} Files
20220
20221 @value{GDBN} needs to know the file name of the program to be debugged,
20222 both in order to read its symbol table and in order to start your
20223 program. To debug a core dump of a previous run, you must also tell
20224 @value{GDBN} the name of the core dump file.
20225
20226 @menu
20227 * Files:: Commands to specify files
20228 * File Caching:: Information about @value{GDBN}'s file caching
20229 * Separate Debug Files:: Debugging information in separate files
20230 * MiniDebugInfo:: Debugging information in a special section
20231 * Index Files:: Index files speed up GDB
20232 * Symbol Errors:: Errors reading symbol files
20233 * Data Files:: GDB data files
20234 @end menu
20235
20236 @node Files
20237 @section Commands to Specify Files
20238
20239 @cindex symbol table
20240 @cindex core dump file
20241
20242 You may want to specify executable and core dump file names. The usual
20243 way to do this is at start-up time, using the arguments to
20244 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20245 Out of @value{GDBN}}).
20246
20247 Occasionally it is necessary to change to a different file during a
20248 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20249 specify a file you want to use. Or you are debugging a remote target
20250 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20251 Program}). In these situations the @value{GDBN} commands to specify
20252 new files are useful.
20253
20254 @table @code
20255 @cindex executable file
20256 @kindex file
20257 @item file @var{filename}
20258 Use @var{filename} as the program to be debugged. It is read for its
20259 symbols and for the contents of pure memory. It is also the program
20260 executed when you use the @code{run} command. If you do not specify a
20261 directory and the file is not found in the @value{GDBN} working directory,
20262 @value{GDBN} uses the environment variable @code{PATH} as a list of
20263 directories to search, just as the shell does when looking for a program
20264 to run. You can change the value of this variable, for both @value{GDBN}
20265 and your program, using the @code{path} command.
20266
20267 @cindex unlinked object files
20268 @cindex patching object files
20269 You can load unlinked object @file{.o} files into @value{GDBN} using
20270 the @code{file} command. You will not be able to ``run'' an object
20271 file, but you can disassemble functions and inspect variables. Also,
20272 if the underlying BFD functionality supports it, you could use
20273 @kbd{gdb -write} to patch object files using this technique. Note
20274 that @value{GDBN} can neither interpret nor modify relocations in this
20275 case, so branches and some initialized variables will appear to go to
20276 the wrong place. But this feature is still handy from time to time.
20277
20278 @item file
20279 @code{file} with no argument makes @value{GDBN} discard any information it
20280 has on both executable file and the symbol table.
20281
20282 @kindex exec-file
20283 @item exec-file @r{[} @var{filename} @r{]}
20284 Specify that the program to be run (but not the symbol table) is found
20285 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20286 if necessary to locate your program. Omitting @var{filename} means to
20287 discard information on the executable file.
20288
20289 @kindex symbol-file
20290 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20291 Read symbol table information from file @var{filename}. @code{PATH} is
20292 searched when necessary. Use the @code{file} command to get both symbol
20293 table and program to run from the same file.
20294
20295 If an optional @var{offset} is specified, it is added to the start
20296 address of each section in the symbol file. This is useful if the
20297 program is relocated at runtime, such as the Linux kernel with kASLR
20298 enabled.
20299
20300 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20301 program's symbol table.
20302
20303 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20304 some breakpoints and auto-display expressions. This is because they may
20305 contain pointers to the internal data recording symbols and data types,
20306 which are part of the old symbol table data being discarded inside
20307 @value{GDBN}.
20308
20309 @code{symbol-file} does not repeat if you press @key{RET} again after
20310 executing it once.
20311
20312 When @value{GDBN} is configured for a particular environment, it
20313 understands debugging information in whatever format is the standard
20314 generated for that environment; you may use either a @sc{gnu} compiler, or
20315 other compilers that adhere to the local conventions.
20316 Best results are usually obtained from @sc{gnu} compilers; for example,
20317 using @code{@value{NGCC}} you can generate debugging information for
20318 optimized code.
20319
20320 For most kinds of object files, with the exception of old SVR3 systems
20321 using COFF, the @code{symbol-file} command does not normally read the
20322 symbol table in full right away. Instead, it scans the symbol table
20323 quickly to find which source files and which symbols are present. The
20324 details are read later, one source file at a time, as they are needed.
20325
20326 The purpose of this two-stage reading strategy is to make @value{GDBN}
20327 start up faster. For the most part, it is invisible except for
20328 occasional pauses while the symbol table details for a particular source
20329 file are being read. (The @code{set verbose} command can turn these
20330 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20331 Warnings and Messages}.)
20332
20333 We have not implemented the two-stage strategy for COFF yet. When the
20334 symbol table is stored in COFF format, @code{symbol-file} reads the
20335 symbol table data in full right away. Note that ``stabs-in-COFF''
20336 still does the two-stage strategy, since the debug info is actually
20337 in stabs format.
20338
20339 @kindex readnow
20340 @cindex reading symbols immediately
20341 @cindex symbols, reading immediately
20342 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20343 @itemx file @r{[} -readnow @r{]} @var{filename}
20344 You can override the @value{GDBN} two-stage strategy for reading symbol
20345 tables by using the @samp{-readnow} option with any of the commands that
20346 load symbol table information, if you want to be sure @value{GDBN} has the
20347 entire symbol table available.
20348
20349 @cindex @code{-readnever}, option for symbol-file command
20350 @cindex never read symbols
20351 @cindex symbols, never read
20352 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20353 @itemx file @r{[} -readnever @r{]} @var{filename}
20354 You can instruct @value{GDBN} to never read the symbolic information
20355 contained in @var{filename} by using the @samp{-readnever} option.
20356 @xref{--readnever}.
20357
20358 @c FIXME: for now no mention of directories, since this seems to be in
20359 @c flux. 13mar1992 status is that in theory GDB would look either in
20360 @c current dir or in same dir as myprog; but issues like competing
20361 @c GDB's, or clutter in system dirs, mean that in practice right now
20362 @c only current dir is used. FFish says maybe a special GDB hierarchy
20363 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20364 @c files.
20365
20366 @kindex core-file
20367 @item core-file @r{[}@var{filename}@r{]}
20368 @itemx core
20369 Specify the whereabouts of a core dump file to be used as the ``contents
20370 of memory''. Traditionally, core files contain only some parts of the
20371 address space of the process that generated them; @value{GDBN} can access the
20372 executable file itself for other parts.
20373
20374 @code{core-file} with no argument specifies that no core file is
20375 to be used.
20376
20377 Note that the core file is ignored when your program is actually running
20378 under @value{GDBN}. So, if you have been running your program and you
20379 wish to debug a core file instead, you must kill the subprocess in which
20380 the program is running. To do this, use the @code{kill} command
20381 (@pxref{Kill Process, ,Killing the Child Process}).
20382
20383 @kindex add-symbol-file
20384 @cindex dynamic linking
20385 @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{]}
20386 The @code{add-symbol-file} command reads additional symbol table
20387 information from the file @var{filename}. You would use this command
20388 when @var{filename} has been dynamically loaded (by some other means)
20389 into the program that is running. The @var{textaddress} parameter gives
20390 the memory address at which the file's text section has been loaded.
20391 You can additionally specify the base address of other sections using
20392 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20393 If a section is omitted, @value{GDBN} will use its default addresses
20394 as found in @var{filename}. Any @var{address} or @var{textaddress}
20395 can be given as an expression.
20396
20397 If an optional @var{offset} is specified, it is added to the start
20398 address of each section, except those for which the address was
20399 specified explicitly.
20400
20401 The symbol table of the file @var{filename} is added to the symbol table
20402 originally read with the @code{symbol-file} command. You can use the
20403 @code{add-symbol-file} command any number of times; the new symbol data
20404 thus read is kept in addition to the old.
20405
20406 Changes can be reverted using the command @code{remove-symbol-file}.
20407
20408 @cindex relocatable object files, reading symbols from
20409 @cindex object files, relocatable, reading symbols from
20410 @cindex reading symbols from relocatable object files
20411 @cindex symbols, reading from relocatable object files
20412 @cindex @file{.o} files, reading symbols from
20413 Although @var{filename} is typically a shared library file, an
20414 executable file, or some other object file which has been fully
20415 relocated for loading into a process, you can also load symbolic
20416 information from relocatable @file{.o} files, as long as:
20417
20418 @itemize @bullet
20419 @item
20420 the file's symbolic information refers only to linker symbols defined in
20421 that file, not to symbols defined by other object files,
20422 @item
20423 every section the file's symbolic information refers to has actually
20424 been loaded into the inferior, as it appears in the file, and
20425 @item
20426 you can determine the address at which every section was loaded, and
20427 provide these to the @code{add-symbol-file} command.
20428 @end itemize
20429
20430 @noindent
20431 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20432 relocatable files into an already running program; such systems
20433 typically make the requirements above easy to meet. However, it's
20434 important to recognize that many native systems use complex link
20435 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20436 assembly, for example) that make the requirements difficult to meet. In
20437 general, one cannot assume that using @code{add-symbol-file} to read a
20438 relocatable object file's symbolic information will have the same effect
20439 as linking the relocatable object file into the program in the normal
20440 way.
20441
20442 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20443
20444 @kindex remove-symbol-file
20445 @item remove-symbol-file @var{filename}
20446 @item remove-symbol-file -a @var{address}
20447 Remove a symbol file added via the @code{add-symbol-file} command. The
20448 file to remove can be identified by its @var{filename} or by an @var{address}
20449 that lies within the boundaries of this symbol file in memory. Example:
20450
20451 @smallexample
20452 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20453 add symbol table from file "/home/user/gdb/mylib.so" at
20454 .text_addr = 0x7ffff7ff9480
20455 (y or n) y
20456 Reading symbols from /home/user/gdb/mylib.so...
20457 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20458 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20459 (gdb)
20460 @end smallexample
20461
20462
20463 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20464
20465 @kindex add-symbol-file-from-memory
20466 @cindex @code{syscall DSO}
20467 @cindex load symbols from memory
20468 @item add-symbol-file-from-memory @var{address}
20469 Load symbols from the given @var{address} in a dynamically loaded
20470 object file whose image is mapped directly into the inferior's memory.
20471 For example, the Linux kernel maps a @code{syscall DSO} into each
20472 process's address space; this DSO provides kernel-specific code for
20473 some system calls. The argument can be any expression whose
20474 evaluation yields the address of the file's shared object file header.
20475 For this command to work, you must have used @code{symbol-file} or
20476 @code{exec-file} commands in advance.
20477
20478 @kindex section
20479 @item section @var{section} @var{addr}
20480 The @code{section} command changes the base address of the named
20481 @var{section} of the exec file to @var{addr}. This can be used if the
20482 exec file does not contain section addresses, (such as in the
20483 @code{a.out} format), or when the addresses specified in the file
20484 itself are wrong. Each section must be changed separately. The
20485 @code{info files} command, described below, lists all the sections and
20486 their addresses.
20487
20488 @kindex info files
20489 @kindex info target
20490 @item info files
20491 @itemx info target
20492 @code{info files} and @code{info target} are synonymous; both print the
20493 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20494 including the names of the executable and core dump files currently in
20495 use by @value{GDBN}, and the files from which symbols were loaded. The
20496 command @code{help target} lists all possible targets rather than
20497 current ones.
20498
20499 @kindex maint info sections
20500 @item maint info sections
20501 Another command that can give you extra information about program sections
20502 is @code{maint info sections}. In addition to the section information
20503 displayed by @code{info files}, this command displays the flags and file
20504 offset of each section in the executable and core dump files. In addition,
20505 @code{maint info sections} provides the following command options (which
20506 may be arbitrarily combined):
20507
20508 @table @code
20509 @item ALLOBJ
20510 Display sections for all loaded object files, including shared libraries.
20511 @item @var{sections}
20512 Display info only for named @var{sections}.
20513 @item @var{section-flags}
20514 Display info only for sections for which @var{section-flags} are true.
20515 The section flags that @value{GDBN} currently knows about are:
20516 @table @code
20517 @item ALLOC
20518 Section will have space allocated in the process when loaded.
20519 Set for all sections except those containing debug information.
20520 @item LOAD
20521 Section will be loaded from the file into the child process memory.
20522 Set for pre-initialized code and data, clear for @code{.bss} sections.
20523 @item RELOC
20524 Section needs to be relocated before loading.
20525 @item READONLY
20526 Section cannot be modified by the child process.
20527 @item CODE
20528 Section contains executable code only.
20529 @item DATA
20530 Section contains data only (no executable code).
20531 @item ROM
20532 Section will reside in ROM.
20533 @item CONSTRUCTOR
20534 Section contains data for constructor/destructor lists.
20535 @item HAS_CONTENTS
20536 Section is not empty.
20537 @item NEVER_LOAD
20538 An instruction to the linker to not output the section.
20539 @item COFF_SHARED_LIBRARY
20540 A notification to the linker that the section contains
20541 COFF shared library information.
20542 @item IS_COMMON
20543 Section contains common symbols.
20544 @end table
20545 @end table
20546 @kindex set trust-readonly-sections
20547 @cindex read-only sections
20548 @item set trust-readonly-sections on
20549 Tell @value{GDBN} that readonly sections in your object file
20550 really are read-only (i.e.@: that their contents will not change).
20551 In that case, @value{GDBN} can fetch values from these sections
20552 out of the object file, rather than from the target program.
20553 For some targets (notably embedded ones), this can be a significant
20554 enhancement to debugging performance.
20555
20556 The default is off.
20557
20558 @item set trust-readonly-sections off
20559 Tell @value{GDBN} not to trust readonly sections. This means that
20560 the contents of the section might change while the program is running,
20561 and must therefore be fetched from the target when needed.
20562
20563 @item show trust-readonly-sections
20564 Show the current setting of trusting readonly sections.
20565 @end table
20566
20567 All file-specifying commands allow both absolute and relative file names
20568 as arguments. @value{GDBN} always converts the file name to an absolute file
20569 name and remembers it that way.
20570
20571 @cindex shared libraries
20572 @anchor{Shared Libraries}
20573 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20574 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20575 DSBT (TIC6X) shared libraries.
20576
20577 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20578 shared libraries. @xref{Expat}.
20579
20580 @value{GDBN} automatically loads symbol definitions from shared libraries
20581 when you use the @code{run} command, or when you examine a core file.
20582 (Before you issue the @code{run} command, @value{GDBN} does not understand
20583 references to a function in a shared library, however---unless you are
20584 debugging a core file).
20585
20586 @c FIXME: some @value{GDBN} release may permit some refs to undef
20587 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20588 @c FIXME...lib; check this from time to time when updating manual
20589
20590 There are times, however, when you may wish to not automatically load
20591 symbol definitions from shared libraries, such as when they are
20592 particularly large or there are many of them.
20593
20594 To control the automatic loading of shared library symbols, use the
20595 commands:
20596
20597 @table @code
20598 @kindex set auto-solib-add
20599 @item set auto-solib-add @var{mode}
20600 If @var{mode} is @code{on}, symbols from all shared object libraries
20601 will be loaded automatically when the inferior begins execution, you
20602 attach to an independently started inferior, or when the dynamic linker
20603 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20604 is @code{off}, symbols must be loaded manually, using the
20605 @code{sharedlibrary} command. The default value is @code{on}.
20606
20607 @cindex memory used for symbol tables
20608 If your program uses lots of shared libraries with debug info that
20609 takes large amounts of memory, you can decrease the @value{GDBN}
20610 memory footprint by preventing it from automatically loading the
20611 symbols from shared libraries. To that end, type @kbd{set
20612 auto-solib-add off} before running the inferior, then load each
20613 library whose debug symbols you do need with @kbd{sharedlibrary
20614 @var{regexp}}, where @var{regexp} is a regular expression that matches
20615 the libraries whose symbols you want to be loaded.
20616
20617 @kindex show auto-solib-add
20618 @item show auto-solib-add
20619 Display the current autoloading mode.
20620 @end table
20621
20622 @cindex load shared library
20623 To explicitly load shared library symbols, use the @code{sharedlibrary}
20624 command:
20625
20626 @table @code
20627 @kindex info sharedlibrary
20628 @kindex info share
20629 @item info share @var{regex}
20630 @itemx info sharedlibrary @var{regex}
20631 Print the names of the shared libraries which are currently loaded
20632 that match @var{regex}. If @var{regex} is omitted then print
20633 all shared libraries that are loaded.
20634
20635 @kindex info dll
20636 @item info dll @var{regex}
20637 This is an alias of @code{info sharedlibrary}.
20638
20639 @kindex sharedlibrary
20640 @kindex share
20641 @item sharedlibrary @var{regex}
20642 @itemx share @var{regex}
20643 Load shared object library symbols for files matching a
20644 Unix regular expression.
20645 As with files loaded automatically, it only loads shared libraries
20646 required by your program for a core file or after typing @code{run}. If
20647 @var{regex} is omitted all shared libraries required by your program are
20648 loaded.
20649
20650 @item nosharedlibrary
20651 @kindex nosharedlibrary
20652 @cindex unload symbols from shared libraries
20653 Unload all shared object library symbols. This discards all symbols
20654 that have been loaded from all shared libraries. Symbols from shared
20655 libraries that were loaded by explicit user requests are not
20656 discarded.
20657 @end table
20658
20659 Sometimes you may wish that @value{GDBN} stops and gives you control
20660 when any of shared library events happen. The best way to do this is
20661 to use @code{catch load} and @code{catch unload} (@pxref{Set
20662 Catchpoints}).
20663
20664 @value{GDBN} also supports the @code{set stop-on-solib-events}
20665 command for this. This command exists for historical reasons. It is
20666 less useful than setting a catchpoint, because it does not allow for
20667 conditions or commands as a catchpoint does.
20668
20669 @table @code
20670 @item set stop-on-solib-events
20671 @kindex set stop-on-solib-events
20672 This command controls whether @value{GDBN} should give you control
20673 when the dynamic linker notifies it about some shared library event.
20674 The most common event of interest is loading or unloading of a new
20675 shared library.
20676
20677 @item show stop-on-solib-events
20678 @kindex show stop-on-solib-events
20679 Show whether @value{GDBN} stops and gives you control when shared
20680 library events happen.
20681 @end table
20682
20683 Shared libraries are also supported in many cross or remote debugging
20684 configurations. @value{GDBN} needs to have access to the target's libraries;
20685 this can be accomplished either by providing copies of the libraries
20686 on the host system, or by asking @value{GDBN} to automatically retrieve the
20687 libraries from the target. If copies of the target libraries are
20688 provided, they need to be the same as the target libraries, although the
20689 copies on the target can be stripped as long as the copies on the host are
20690 not.
20691
20692 @cindex where to look for shared libraries
20693 For remote debugging, you need to tell @value{GDBN} where the target
20694 libraries are, so that it can load the correct copies---otherwise, it
20695 may try to load the host's libraries. @value{GDBN} has two variables
20696 to specify the search directories for target libraries.
20697
20698 @table @code
20699 @cindex prefix for executable and shared library file names
20700 @cindex system root, alternate
20701 @kindex set solib-absolute-prefix
20702 @kindex set sysroot
20703 @item set sysroot @var{path}
20704 Use @var{path} as the system root for the program being debugged. Any
20705 absolute shared library paths will be prefixed with @var{path}; many
20706 runtime loaders store the absolute paths to the shared library in the
20707 target program's memory. When starting processes remotely, and when
20708 attaching to already-running processes (local or remote), their
20709 executable filenames will be prefixed with @var{path} if reported to
20710 @value{GDBN} as absolute by the operating system. If you use
20711 @code{set sysroot} to find executables and shared libraries, they need
20712 to be laid out in the same way that they are on the target, with
20713 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20714 @var{path}.
20715
20716 If @var{path} starts with the sequence @file{target:} and the target
20717 system is remote then @value{GDBN} will retrieve the target binaries
20718 from the remote system. This is only supported when using a remote
20719 target that supports the @code{remote get} command (@pxref{File
20720 Transfer,,Sending files to a remote system}). The part of @var{path}
20721 following the initial @file{target:} (if present) is used as system
20722 root prefix on the remote file system. If @var{path} starts with the
20723 sequence @file{remote:} this is converted to the sequence
20724 @file{target:} by @code{set sysroot}@footnote{Historically the
20725 functionality to retrieve binaries from the remote system was
20726 provided by prefixing @var{path} with @file{remote:}}. If you want
20727 to specify a local system root using a directory that happens to be
20728 named @file{target:} or @file{remote:}, you need to use some
20729 equivalent variant of the name like @file{./target:}.
20730
20731 For targets with an MS-DOS based filesystem, such as MS-Windows and
20732 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20733 absolute file name with @var{path}. But first, on Unix hosts,
20734 @value{GDBN} converts all backslash directory separators into forward
20735 slashes, because the backslash is not a directory separator on Unix:
20736
20737 @smallexample
20738 c:\foo\bar.dll @result{} c:/foo/bar.dll
20739 @end smallexample
20740
20741 Then, @value{GDBN} attempts prefixing the target file name with
20742 @var{path}, and looks for the resulting file name in the host file
20743 system:
20744
20745 @smallexample
20746 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20747 @end smallexample
20748
20749 If that does not find the binary, @value{GDBN} tries removing
20750 the @samp{:} character from the drive spec, both for convenience, and,
20751 for the case of the host file system not supporting file names with
20752 colons:
20753
20754 @smallexample
20755 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20756 @end smallexample
20757
20758 This makes it possible to have a system root that mirrors a target
20759 with more than one drive. E.g., you may want to setup your local
20760 copies of the target system shared libraries like so (note @samp{c} vs
20761 @samp{z}):
20762
20763 @smallexample
20764 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20765 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20766 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20767 @end smallexample
20768
20769 @noindent
20770 and point the system root at @file{/path/to/sysroot}, so that
20771 @value{GDBN} can find the correct copies of both
20772 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20773
20774 If that still does not find the binary, @value{GDBN} tries
20775 removing the whole drive spec from the target file name:
20776
20777 @smallexample
20778 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20779 @end smallexample
20780
20781 This last lookup makes it possible to not care about the drive name,
20782 if you don't want or need to.
20783
20784 The @code{set solib-absolute-prefix} command is an alias for @code{set
20785 sysroot}.
20786
20787 @cindex default system root
20788 @cindex @samp{--with-sysroot}
20789 You can set the default system root by using the configure-time
20790 @samp{--with-sysroot} option. If the system root is inside
20791 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20792 @samp{--exec-prefix}), then the default system root will be updated
20793 automatically if the installed @value{GDBN} is moved to a new
20794 location.
20795
20796 @kindex show sysroot
20797 @item show sysroot
20798 Display the current executable and shared library prefix.
20799
20800 @kindex set solib-search-path
20801 @item set solib-search-path @var{path}
20802 If this variable is set, @var{path} is a colon-separated list of
20803 directories to search for shared libraries. @samp{solib-search-path}
20804 is used after @samp{sysroot} fails to locate the library, or if the
20805 path to the library is relative instead of absolute. If you want to
20806 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
20807 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
20808 finding your host's libraries. @samp{sysroot} is preferred; setting
20809 it to a nonexistent directory may interfere with automatic loading
20810 of shared library symbols.
20811
20812 @kindex show solib-search-path
20813 @item show solib-search-path
20814 Display the current shared library search path.
20815
20816 @cindex DOS file-name semantics of file names.
20817 @kindex set target-file-system-kind (unix|dos-based|auto)
20818 @kindex show target-file-system-kind
20819 @item set target-file-system-kind @var{kind}
20820 Set assumed file system kind for target reported file names.
20821
20822 Shared library file names as reported by the target system may not
20823 make sense as is on the system @value{GDBN} is running on. For
20824 example, when remote debugging a target that has MS-DOS based file
20825 system semantics, from a Unix host, the target may be reporting to
20826 @value{GDBN} a list of loaded shared libraries with file names such as
20827 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20828 drive letters, so the @samp{c:\} prefix is not normally understood as
20829 indicating an absolute file name, and neither is the backslash
20830 normally considered a directory separator character. In that case,
20831 the native file system would interpret this whole absolute file name
20832 as a relative file name with no directory components. This would make
20833 it impossible to point @value{GDBN} at a copy of the remote target's
20834 shared libraries on the host using @code{set sysroot}, and impractical
20835 with @code{set solib-search-path}. Setting
20836 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20837 to interpret such file names similarly to how the target would, and to
20838 map them to file names valid on @value{GDBN}'s native file system
20839 semantics. The value of @var{kind} can be @code{"auto"}, in addition
20840 to one of the supported file system kinds. In that case, @value{GDBN}
20841 tries to determine the appropriate file system variant based on the
20842 current target's operating system (@pxref{ABI, ,Configuring the
20843 Current ABI}). The supported file system settings are:
20844
20845 @table @code
20846 @item unix
20847 Instruct @value{GDBN} to assume the target file system is of Unix
20848 kind. Only file names starting the forward slash (@samp{/}) character
20849 are considered absolute, and the directory separator character is also
20850 the forward slash.
20851
20852 @item dos-based
20853 Instruct @value{GDBN} to assume the target file system is DOS based.
20854 File names starting with either a forward slash, or a drive letter
20855 followed by a colon (e.g., @samp{c:}), are considered absolute, and
20856 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20857 considered directory separators.
20858
20859 @item auto
20860 Instruct @value{GDBN} to use the file system kind associated with the
20861 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20862 This is the default.
20863 @end table
20864 @end table
20865
20866 @cindex file name canonicalization
20867 @cindex base name differences
20868 When processing file names provided by the user, @value{GDBN}
20869 frequently needs to compare them to the file names recorded in the
20870 program's debug info. Normally, @value{GDBN} compares just the
20871 @dfn{base names} of the files as strings, which is reasonably fast
20872 even for very large programs. (The base name of a file is the last
20873 portion of its name, after stripping all the leading directories.)
20874 This shortcut in comparison is based upon the assumption that files
20875 cannot have more than one base name. This is usually true, but
20876 references to files that use symlinks or similar filesystem
20877 facilities violate that assumption. If your program records files
20878 using such facilities, or if you provide file names to @value{GDBN}
20879 using symlinks etc., you can set @code{basenames-may-differ} to
20880 @code{true} to instruct @value{GDBN} to completely canonicalize each
20881 pair of file names it needs to compare. This will make file-name
20882 comparisons accurate, but at a price of a significant slowdown.
20883
20884 @table @code
20885 @item set basenames-may-differ
20886 @kindex set basenames-may-differ
20887 Set whether a source file may have multiple base names.
20888
20889 @item show basenames-may-differ
20890 @kindex show basenames-may-differ
20891 Show whether a source file may have multiple base names.
20892 @end table
20893
20894 @node File Caching
20895 @section File Caching
20896 @cindex caching of opened files
20897 @cindex caching of bfd objects
20898
20899 To speed up file loading, and reduce memory usage, @value{GDBN} will
20900 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20901 BFD, bfd, The Binary File Descriptor Library}. The following commands
20902 allow visibility and control of the caching behavior.
20903
20904 @table @code
20905 @kindex maint info bfds
20906 @item maint info bfds
20907 This prints information about each @code{bfd} object that is known to
20908 @value{GDBN}.
20909
20910 @kindex maint set bfd-sharing
20911 @kindex maint show bfd-sharing
20912 @kindex bfd caching
20913 @item maint set bfd-sharing
20914 @item maint show bfd-sharing
20915 Control whether @code{bfd} objects can be shared. When sharing is
20916 enabled @value{GDBN} reuses already open @code{bfd} objects rather
20917 than reopening the same file. Turning sharing off does not cause
20918 already shared @code{bfd} objects to be unshared, but all future files
20919 that are opened will create a new @code{bfd} object. Similarly,
20920 re-enabling sharing does not cause multiple existing @code{bfd}
20921 objects to be collapsed into a single shared @code{bfd} object.
20922
20923 @kindex set debug bfd-cache @var{level}
20924 @kindex bfd caching
20925 @item set debug bfd-cache @var{level}
20926 Turns on debugging of the bfd cache, setting the level to @var{level}.
20927
20928 @kindex show debug bfd-cache
20929 @kindex bfd caching
20930 @item show debug bfd-cache
20931 Show the current debugging level of the bfd cache.
20932 @end table
20933
20934 @node Separate Debug Files
20935 @section Debugging Information in Separate Files
20936 @cindex separate debugging information files
20937 @cindex debugging information in separate files
20938 @cindex @file{.debug} subdirectories
20939 @cindex debugging information directory, global
20940 @cindex global debugging information directories
20941 @cindex build ID, and separate debugging files
20942 @cindex @file{.build-id} directory
20943
20944 @value{GDBN} allows you to put a program's debugging information in a
20945 file separate from the executable itself, in a way that allows
20946 @value{GDBN} to find and load the debugging information automatically.
20947 Since debugging information can be very large---sometimes larger
20948 than the executable code itself---some systems distribute debugging
20949 information for their executables in separate files, which users can
20950 install only when they need to debug a problem.
20951
20952 @value{GDBN} supports two ways of specifying the separate debug info
20953 file:
20954
20955 @itemize @bullet
20956 @item
20957 The executable contains a @dfn{debug link} that specifies the name of
20958 the separate debug info file. The separate debug file's name is
20959 usually @file{@var{executable}.debug}, where @var{executable} is the
20960 name of the corresponding executable file without leading directories
20961 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
20962 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20963 checksum for the debug file, which @value{GDBN} uses to validate that
20964 the executable and the debug file came from the same build.
20965
20966 @item
20967 @anchor{build ID}
20968 The executable contains a @dfn{build ID}, a unique bit string that is
20969 also present in the corresponding debug info file. (This is supported
20970 only on some operating systems, when using the ELF or PE file formats
20971 for binary files and the @sc{gnu} Binutils.) For more details about
20972 this feature, see the description of the @option{--build-id}
20973 command-line option in @ref{Options, , Command Line Options, ld,
20974 The GNU Linker}. The debug info file's name is not specified
20975 explicitly by the build ID, but can be computed from the build ID, see
20976 below.
20977 @end itemize
20978
20979 Depending on the way the debug info file is specified, @value{GDBN}
20980 uses two different methods of looking for the debug file:
20981
20982 @itemize @bullet
20983 @item
20984 For the ``debug link'' method, @value{GDBN} looks up the named file in
20985 the directory of the executable file, then in a subdirectory of that
20986 directory named @file{.debug}, and finally under each one of the
20987 global debug directories, in a subdirectory whose name is identical to
20988 the leading directories of the executable's absolute file name. (On
20989 MS-Windows/MS-DOS, the drive letter of the executable's leading
20990 directories is converted to a one-letter subdirectory, i.e.@:
20991 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20992 filesystems disallow colons in file names.)
20993
20994 @item
20995 For the ``build ID'' method, @value{GDBN} looks in the
20996 @file{.build-id} subdirectory of each one of the global debug directories for
20997 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
20998 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
20999 are the rest of the bit string. (Real build ID strings are 32 or more
21000 hex characters, not 10.)
21001 @end itemize
21002
21003 So, for example, suppose you ask @value{GDBN} to debug
21004 @file{/usr/bin/ls}, which has a debug link that specifies the
21005 file @file{ls.debug}, and a build ID whose value in hex is
21006 @code{abcdef1234}. If the list of the global debug directories includes
21007 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21008 debug information files, in the indicated order:
21009
21010 @itemize @minus
21011 @item
21012 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21013 @item
21014 @file{/usr/bin/ls.debug}
21015 @item
21016 @file{/usr/bin/.debug/ls.debug}
21017 @item
21018 @file{/usr/lib/debug/usr/bin/ls.debug}.
21019 @end itemize
21020
21021 @anchor{debug-file-directory}
21022 Global debugging info directories default to what is set by @value{GDBN}
21023 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21024 you can also set the global debugging info directories, and view the list
21025 @value{GDBN} is currently using.
21026
21027 @table @code
21028
21029 @kindex set debug-file-directory
21030 @item set debug-file-directory @var{directories}
21031 Set the directories which @value{GDBN} searches for separate debugging
21032 information files to @var{directory}. Multiple path components can be set
21033 concatenating them by a path separator.
21034
21035 @kindex show debug-file-directory
21036 @item show debug-file-directory
21037 Show the directories @value{GDBN} searches for separate debugging
21038 information files.
21039
21040 @end table
21041
21042 @cindex @code{.gnu_debuglink} sections
21043 @cindex debug link sections
21044 A debug link is a special section of the executable file named
21045 @code{.gnu_debuglink}. The section must contain:
21046
21047 @itemize
21048 @item
21049 A filename, with any leading directory components removed, followed by
21050 a zero byte,
21051 @item
21052 zero to three bytes of padding, as needed to reach the next four-byte
21053 boundary within the section, and
21054 @item
21055 a four-byte CRC checksum, stored in the same endianness used for the
21056 executable file itself. The checksum is computed on the debugging
21057 information file's full contents by the function given below, passing
21058 zero as the @var{crc} argument.
21059 @end itemize
21060
21061 Any executable file format can carry a debug link, as long as it can
21062 contain a section named @code{.gnu_debuglink} with the contents
21063 described above.
21064
21065 @cindex @code{.note.gnu.build-id} sections
21066 @cindex build ID sections
21067 The build ID is a special section in the executable file (and in other
21068 ELF binary files that @value{GDBN} may consider). This section is
21069 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21070 It contains unique identification for the built files---the ID remains
21071 the same across multiple builds of the same build tree. The default
21072 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21073 content for the build ID string. The same section with an identical
21074 value is present in the original built binary with symbols, in its
21075 stripped variant, and in the separate debugging information file.
21076
21077 The debugging information file itself should be an ordinary
21078 executable, containing a full set of linker symbols, sections, and
21079 debugging information. The sections of the debugging information file
21080 should have the same names, addresses, and sizes as the original file,
21081 but they need not contain any data---much like a @code{.bss} section
21082 in an ordinary executable.
21083
21084 The @sc{gnu} binary utilities (Binutils) package includes the
21085 @samp{objcopy} utility that can produce
21086 the separated executable / debugging information file pairs using the
21087 following commands:
21088
21089 @smallexample
21090 @kbd{objcopy --only-keep-debug foo foo.debug}
21091 @kbd{strip -g foo}
21092 @end smallexample
21093
21094 @noindent
21095 These commands remove the debugging
21096 information from the executable file @file{foo} and place it in the file
21097 @file{foo.debug}. You can use the first, second or both methods to link the
21098 two files:
21099
21100 @itemize @bullet
21101 @item
21102 The debug link method needs the following additional command to also leave
21103 behind a debug link in @file{foo}:
21104
21105 @smallexample
21106 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21107 @end smallexample
21108
21109 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21110 a version of the @code{strip} command such that the command @kbd{strip foo -f
21111 foo.debug} has the same functionality as the two @code{objcopy} commands and
21112 the @code{ln -s} command above, together.
21113
21114 @item
21115 Build ID gets embedded into the main executable using @code{ld --build-id} or
21116 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21117 compatibility fixes for debug files separation are present in @sc{gnu} binary
21118 utilities (Binutils) package since version 2.18.
21119 @end itemize
21120
21121 @noindent
21122
21123 @cindex CRC algorithm definition
21124 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21125 IEEE 802.3 using the polynomial:
21126
21127 @c TexInfo requires naked braces for multi-digit exponents for Tex
21128 @c output, but this causes HTML output to barf. HTML has to be set using
21129 @c raw commands. So we end up having to specify this equation in 2
21130 @c different ways!
21131 @ifhtml
21132 @display
21133 @html
21134 <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>
21135 + <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
21136 @end html
21137 @end display
21138 @end ifhtml
21139 @ifnothtml
21140 @display
21141 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21142 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21143 @end display
21144 @end ifnothtml
21145
21146 The function is computed byte at a time, taking the least
21147 significant bit of each byte first. The initial pattern
21148 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21149 the final result is inverted to ensure trailing zeros also affect the
21150 CRC.
21151
21152 @emph{Note:} This is the same CRC polynomial as used in handling the
21153 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21154 However in the case of the Remote Serial Protocol, the CRC is computed
21155 @emph{most} significant bit first, and the result is not inverted, so
21156 trailing zeros have no effect on the CRC value.
21157
21158 To complete the description, we show below the code of the function
21159 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21160 initially supplied @code{crc} argument means that an initial call to
21161 this function passing in zero will start computing the CRC using
21162 @code{0xffffffff}.
21163
21164 @kindex gnu_debuglink_crc32
21165 @smallexample
21166 unsigned long
21167 gnu_debuglink_crc32 (unsigned long crc,
21168 unsigned char *buf, size_t len)
21169 @{
21170 static const unsigned long crc32_table[256] =
21171 @{
21172 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21173 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21174 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21175 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21176 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21177 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21178 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21179 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21180 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21181 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21182 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21183 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21184 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21185 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21186 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21187 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21188 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21189 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21190 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21191 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21192 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21193 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21194 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21195 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21196 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21197 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21198 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21199 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21200 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21201 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21202 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21203 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21204 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21205 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21206 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21207 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21208 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21209 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21210 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21211 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21212 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21213 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21214 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21215 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21216 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21217 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21218 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21219 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21220 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21221 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21222 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21223 0x2d02ef8d
21224 @};
21225 unsigned char *end;
21226
21227 crc = ~crc & 0xffffffff;
21228 for (end = buf + len; buf < end; ++buf)
21229 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21230 return ~crc & 0xffffffff;
21231 @}
21232 @end smallexample
21233
21234 @noindent
21235 This computation does not apply to the ``build ID'' method.
21236
21237 @node MiniDebugInfo
21238 @section Debugging information in a special section
21239 @cindex separate debug sections
21240 @cindex @samp{.gnu_debugdata} section
21241
21242 Some systems ship pre-built executables and libraries that have a
21243 special @samp{.gnu_debugdata} section. This feature is called
21244 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21245 is used to supply extra symbols for backtraces.
21246
21247 The intent of this section is to provide extra minimal debugging
21248 information for use in simple backtraces. It is not intended to be a
21249 replacement for full separate debugging information (@pxref{Separate
21250 Debug Files}). The example below shows the intended use; however,
21251 @value{GDBN} does not currently put restrictions on what sort of
21252 debugging information might be included in the section.
21253
21254 @value{GDBN} has support for this extension. If the section exists,
21255 then it is used provided that no other source of debugging information
21256 can be found, and that @value{GDBN} was configured with LZMA support.
21257
21258 This section can be easily created using @command{objcopy} and other
21259 standard utilities:
21260
21261 @smallexample
21262 # Extract the dynamic symbols from the main binary, there is no need
21263 # to also have these in the normal symbol table.
21264 nm -D @var{binary} --format=posix --defined-only \
21265 | awk '@{ print $1 @}' | sort > dynsyms
21266
21267 # Extract all the text (i.e. function) symbols from the debuginfo.
21268 # (Note that we actually also accept "D" symbols, for the benefit
21269 # of platforms like PowerPC64 that use function descriptors.)
21270 nm @var{binary} --format=posix --defined-only \
21271 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21272 | sort > funcsyms
21273
21274 # Keep all the function symbols not already in the dynamic symbol
21275 # table.
21276 comm -13 dynsyms funcsyms > keep_symbols
21277
21278 # Separate full debug info into debug binary.
21279 objcopy --only-keep-debug @var{binary} debug
21280
21281 # Copy the full debuginfo, keeping only a minimal set of symbols and
21282 # removing some unnecessary sections.
21283 objcopy -S --remove-section .gdb_index --remove-section .comment \
21284 --keep-symbols=keep_symbols debug mini_debuginfo
21285
21286 # Drop the full debug info from the original binary.
21287 strip --strip-all -R .comment @var{binary}
21288
21289 # Inject the compressed data into the .gnu_debugdata section of the
21290 # original binary.
21291 xz mini_debuginfo
21292 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21293 @end smallexample
21294
21295 @node Index Files
21296 @section Index Files Speed Up @value{GDBN}
21297 @cindex index files
21298 @cindex @samp{.gdb_index} section
21299
21300 When @value{GDBN} finds a symbol file, it scans the symbols in the
21301 file in order to construct an internal symbol table. This lets most
21302 @value{GDBN} operations work quickly---at the cost of a delay early
21303 on. For large programs, this delay can be quite lengthy, so
21304 @value{GDBN} provides a way to build an index, which speeds up
21305 startup.
21306
21307 For convenience, @value{GDBN} comes with a program,
21308 @command{gdb-add-index}, which can be used to add the index to a
21309 symbol file. It takes the symbol file as its only argument:
21310
21311 @smallexample
21312 $ gdb-add-index symfile
21313 @end smallexample
21314
21315 @xref{gdb-add-index}.
21316
21317 It is also possible to do the work manually. Here is what
21318 @command{gdb-add-index} does behind the curtains.
21319
21320 The index is stored as a section in the symbol file. @value{GDBN} can
21321 write the index to a file, then you can put it into the symbol file
21322 using @command{objcopy}.
21323
21324 To create an index file, use the @code{save gdb-index} command:
21325
21326 @table @code
21327 @item save gdb-index [-dwarf-5] @var{directory}
21328 @kindex save gdb-index
21329 Create index files for all symbol files currently known by
21330 @value{GDBN}. For each known @var{symbol-file}, this command by
21331 default creates it produces a single file
21332 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21333 the @option{-dwarf-5} option, it produces 2 files:
21334 @file{@var{symbol-file}.debug_names} and
21335 @file{@var{symbol-file}.debug_str}. The files are created in the
21336 given @var{directory}.
21337 @end table
21338
21339 Once you have created an index file you can merge it into your symbol
21340 file, here named @file{symfile}, using @command{objcopy}:
21341
21342 @smallexample
21343 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21344 --set-section-flags .gdb_index=readonly symfile symfile
21345 @end smallexample
21346
21347 Or for @code{-dwarf-5}:
21348
21349 @smallexample
21350 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21351 $ cat symfile.debug_str >>symfile.debug_str.new
21352 $ objcopy --add-section .debug_names=symfile.gdb-index \
21353 --set-section-flags .debug_names=readonly \
21354 --update-section .debug_str=symfile.debug_str.new symfile symfile
21355 @end smallexample
21356
21357 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21358 sections that have been deprecated. Usually they are deprecated because
21359 they are missing a new feature or have performance issues.
21360 To tell @value{GDBN} to use a deprecated index section anyway
21361 specify @code{set use-deprecated-index-sections on}.
21362 The default is @code{off}.
21363 This can speed up startup, but may result in some functionality being lost.
21364 @xref{Index Section Format}.
21365
21366 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21367 must be done before gdb reads the file. The following will not work:
21368
21369 @smallexample
21370 $ gdb -ex "set use-deprecated-index-sections on" <program>
21371 @end smallexample
21372
21373 Instead you must do, for example,
21374
21375 @smallexample
21376 $ gdb -iex "set use-deprecated-index-sections on" <program>
21377 @end smallexample
21378
21379 Indices only work when using DWARF debugging information, not stabs.
21380
21381 @subsection Automatic symbol index cache
21382
21383 @cindex automatic symbol index cache
21384 It is possible for @value{GDBN} to automatically save a copy of this index in a
21385 cache on disk and retrieve it from there when loading the same binary in the
21386 future. This feature can be turned on with @kbd{set index-cache on}. The
21387 following commands can be used to tweak the behavior of the index cache.
21388
21389 @table @code
21390
21391 @kindex set index-cache
21392 @item set index-cache on
21393 @itemx set index-cache off
21394 Enable or disable the use of the symbol index cache.
21395
21396 @item set index-cache directory @var{directory}
21397 @kindex show index-cache
21398 @itemx show index-cache directory
21399 Set/show the directory where index files will be saved.
21400
21401 The default value for this directory depends on the host platform. On
21402 most systems, the index is cached in the @file{gdb} subdirectory of
21403 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21404 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21405 of your home directory. However, on some systems, the default may
21406 differ according to local convention.
21407
21408 There is no limit on the disk space used by index cache. It is perfectly safe
21409 to delete the content of that directory to free up disk space.
21410
21411 @item show index-cache stats
21412 Print the number of cache hits and misses since the launch of @value{GDBN}.
21413
21414 @end table
21415
21416 @node Symbol Errors
21417 @section Errors Reading Symbol Files
21418
21419 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21420 such as symbol types it does not recognize, or known bugs in compiler
21421 output. By default, @value{GDBN} does not notify you of such problems, since
21422 they are relatively common and primarily of interest to people
21423 debugging compilers. If you are interested in seeing information
21424 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21425 only one message about each such type of problem, no matter how many
21426 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21427 to see how many times the problems occur, with the @code{set
21428 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21429 Messages}).
21430
21431 The messages currently printed, and their meanings, include:
21432
21433 @table @code
21434 @item inner block not inside outer block in @var{symbol}
21435
21436 The symbol information shows where symbol scopes begin and end
21437 (such as at the start of a function or a block of statements). This
21438 error indicates that an inner scope block is not fully contained
21439 in its outer scope blocks.
21440
21441 @value{GDBN} circumvents the problem by treating the inner block as if it had
21442 the same scope as the outer block. In the error message, @var{symbol}
21443 may be shown as ``@code{(don't know)}'' if the outer block is not a
21444 function.
21445
21446 @item block at @var{address} out of order
21447
21448 The symbol information for symbol scope blocks should occur in
21449 order of increasing addresses. This error indicates that it does not
21450 do so.
21451
21452 @value{GDBN} does not circumvent this problem, and has trouble
21453 locating symbols in the source file whose symbols it is reading. (You
21454 can often determine what source file is affected by specifying
21455 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21456 Messages}.)
21457
21458 @item bad block start address patched
21459
21460 The symbol information for a symbol scope block has a start address
21461 smaller than the address of the preceding source line. This is known
21462 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21463
21464 @value{GDBN} circumvents the problem by treating the symbol scope block as
21465 starting on the previous source line.
21466
21467 @item bad string table offset in symbol @var{n}
21468
21469 @cindex foo
21470 Symbol number @var{n} contains a pointer into the string table which is
21471 larger than the size of the string table.
21472
21473 @value{GDBN} circumvents the problem by considering the symbol to have the
21474 name @code{foo}, which may cause other problems if many symbols end up
21475 with this name.
21476
21477 @item unknown symbol type @code{0x@var{nn}}
21478
21479 The symbol information contains new data types that @value{GDBN} does
21480 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21481 uncomprehended information, in hexadecimal.
21482
21483 @value{GDBN} circumvents the error by ignoring this symbol information.
21484 This usually allows you to debug your program, though certain symbols
21485 are not accessible. If you encounter such a problem and feel like
21486 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21487 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21488 and examine @code{*bufp} to see the symbol.
21489
21490 @item stub type has NULL name
21491
21492 @value{GDBN} could not find the full definition for a struct or class.
21493
21494 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21495 The symbol information for a C@t{++} member function is missing some
21496 information that recent versions of the compiler should have output for
21497 it.
21498
21499 @item info mismatch between compiler and debugger
21500
21501 @value{GDBN} could not parse a type specification output by the compiler.
21502
21503 @end table
21504
21505 @node Data Files
21506 @section GDB Data Files
21507
21508 @cindex prefix for data files
21509 @value{GDBN} will sometimes read an auxiliary data file. These files
21510 are kept in a directory known as the @dfn{data directory}.
21511
21512 You can set the data directory's name, and view the name @value{GDBN}
21513 is currently using.
21514
21515 @table @code
21516 @kindex set data-directory
21517 @item set data-directory @var{directory}
21518 Set the directory which @value{GDBN} searches for auxiliary data files
21519 to @var{directory}.
21520
21521 @kindex show data-directory
21522 @item show data-directory
21523 Show the directory @value{GDBN} searches for auxiliary data files.
21524 @end table
21525
21526 @cindex default data directory
21527 @cindex @samp{--with-gdb-datadir}
21528 You can set the default data directory by using the configure-time
21529 @samp{--with-gdb-datadir} option. If the data directory is inside
21530 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21531 @samp{--exec-prefix}), then the default data directory will be updated
21532 automatically if the installed @value{GDBN} is moved to a new
21533 location.
21534
21535 The data directory may also be specified with the
21536 @code{--data-directory} command line option.
21537 @xref{Mode Options}.
21538
21539 @node Targets
21540 @chapter Specifying a Debugging Target
21541
21542 @cindex debugging target
21543 A @dfn{target} is the execution environment occupied by your program.
21544
21545 Often, @value{GDBN} runs in the same host environment as your program;
21546 in that case, the debugging target is specified as a side effect when
21547 you use the @code{file} or @code{core} commands. When you need more
21548 flexibility---for example, running @value{GDBN} on a physically separate
21549 host, or controlling a standalone system over a serial port or a
21550 realtime system over a TCP/IP connection---you can use the @code{target}
21551 command to specify one of the target types configured for @value{GDBN}
21552 (@pxref{Target Commands, ,Commands for Managing Targets}).
21553
21554 @cindex target architecture
21555 It is possible to build @value{GDBN} for several different @dfn{target
21556 architectures}. When @value{GDBN} is built like that, you can choose
21557 one of the available architectures with the @kbd{set architecture}
21558 command.
21559
21560 @table @code
21561 @kindex set architecture
21562 @kindex show architecture
21563 @item set architecture @var{arch}
21564 This command sets the current target architecture to @var{arch}. The
21565 value of @var{arch} can be @code{"auto"}, in addition to one of the
21566 supported architectures.
21567
21568 @item show architecture
21569 Show the current target architecture.
21570
21571 @item set processor
21572 @itemx processor
21573 @kindex set processor
21574 @kindex show processor
21575 These are alias commands for, respectively, @code{set architecture}
21576 and @code{show architecture}.
21577 @end table
21578
21579 @menu
21580 * Active Targets:: Active targets
21581 * Target Commands:: Commands for managing targets
21582 * Byte Order:: Choosing target byte order
21583 @end menu
21584
21585 @node Active Targets
21586 @section Active Targets
21587
21588 @cindex stacking targets
21589 @cindex active targets
21590 @cindex multiple targets
21591
21592 There are multiple classes of targets such as: processes, executable files or
21593 recording sessions. Core files belong to the process class, making core file
21594 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21595 on multiple active targets, one in each class. This allows you to (for
21596 example) start a process and inspect its activity, while still having access to
21597 the executable file after the process finishes. Or if you start process
21598 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21599 presented a virtual layer of the recording target, while the process target
21600 remains stopped at the chronologically last point of the process execution.
21601
21602 Use the @code{core-file} and @code{exec-file} commands to select a new core
21603 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21604 specify as a target a process that is already running, use the @code{attach}
21605 command (@pxref{Attach, ,Debugging an Already-running Process}).
21606
21607 @node Target Commands
21608 @section Commands for Managing Targets
21609
21610 @table @code
21611 @item target @var{type} @var{parameters}
21612 Connects the @value{GDBN} host environment to a target machine or
21613 process. A target is typically a protocol for talking to debugging
21614 facilities. You use the argument @var{type} to specify the type or
21615 protocol of the target machine.
21616
21617 Further @var{parameters} are interpreted by the target protocol, but
21618 typically include things like device names or host names to connect
21619 with, process numbers, and baud rates.
21620
21621 The @code{target} command does not repeat if you press @key{RET} again
21622 after executing the command.
21623
21624 @kindex help target
21625 @item help target
21626 Displays the names of all targets available. To display targets
21627 currently selected, use either @code{info target} or @code{info files}
21628 (@pxref{Files, ,Commands to Specify Files}).
21629
21630 @item help target @var{name}
21631 Describe a particular target, including any parameters necessary to
21632 select it.
21633
21634 @kindex set gnutarget
21635 @item set gnutarget @var{args}
21636 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21637 knows whether it is reading an @dfn{executable},
21638 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21639 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21640 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21641
21642 @quotation
21643 @emph{Warning:} To specify a file format with @code{set gnutarget},
21644 you must know the actual BFD name.
21645 @end quotation
21646
21647 @noindent
21648 @xref{Files, , Commands to Specify Files}.
21649
21650 @kindex show gnutarget
21651 @item show gnutarget
21652 Use the @code{show gnutarget} command to display what file format
21653 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21654 @value{GDBN} will determine the file format for each file automatically,
21655 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21656 @end table
21657
21658 @cindex common targets
21659 Here are some common targets (available, or not, depending on the GDB
21660 configuration):
21661
21662 @table @code
21663 @kindex target
21664 @item target exec @var{program}
21665 @cindex executable file target
21666 An executable file. @samp{target exec @var{program}} is the same as
21667 @samp{exec-file @var{program}}.
21668
21669 @item target core @var{filename}
21670 @cindex core dump file target
21671 A core dump file. @samp{target core @var{filename}} is the same as
21672 @samp{core-file @var{filename}}.
21673
21674 @item target remote @var{medium}
21675 @cindex remote target
21676 A remote system connected to @value{GDBN} via a serial line or network
21677 connection. This command tells @value{GDBN} to use its own remote
21678 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21679
21680 For example, if you have a board connected to @file{/dev/ttya} on the
21681 machine running @value{GDBN}, you could say:
21682
21683 @smallexample
21684 target remote /dev/ttya
21685 @end smallexample
21686
21687 @code{target remote} supports the @code{load} command. This is only
21688 useful if you have some other way of getting the stub to the target
21689 system, and you can put it somewhere in memory where it won't get
21690 clobbered by the download.
21691
21692 @item target sim @r{[}@var{simargs}@r{]} @dots{}
21693 @cindex built-in simulator target
21694 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
21695 In general,
21696 @smallexample
21697 target sim
21698 load
21699 run
21700 @end smallexample
21701 @noindent
21702 works; however, you cannot assume that a specific memory map, device
21703 drivers, or even basic I/O is available, although some simulators do
21704 provide these. For info about any processor-specific simulator details,
21705 see the appropriate section in @ref{Embedded Processors, ,Embedded
21706 Processors}.
21707
21708 @item target native
21709 @cindex native target
21710 Setup for local/native process debugging. Useful to make the
21711 @code{run} command spawn native processes (likewise @code{attach},
21712 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21713 (@pxref{set auto-connect-native-target}).
21714
21715 @end table
21716
21717 Different targets are available on different configurations of @value{GDBN};
21718 your configuration may have more or fewer targets.
21719
21720 Many remote targets require you to download the executable's code once
21721 you've successfully established a connection. You may wish to control
21722 various aspects of this process.
21723
21724 @table @code
21725
21726 @item set hash
21727 @kindex set hash@r{, for remote monitors}
21728 @cindex hash mark while downloading
21729 This command controls whether a hash mark @samp{#} is displayed while
21730 downloading a file to the remote monitor. If on, a hash mark is
21731 displayed after each S-record is successfully downloaded to the
21732 monitor.
21733
21734 @item show hash
21735 @kindex show hash@r{, for remote monitors}
21736 Show the current status of displaying the hash mark.
21737
21738 @item set debug monitor
21739 @kindex set debug monitor
21740 @cindex display remote monitor communications
21741 Enable or disable display of communications messages between
21742 @value{GDBN} and the remote monitor.
21743
21744 @item show debug monitor
21745 @kindex show debug monitor
21746 Show the current status of displaying communications between
21747 @value{GDBN} and the remote monitor.
21748 @end table
21749
21750 @table @code
21751
21752 @kindex load @var{filename} @var{offset}
21753 @item load @var{filename} @var{offset}
21754 @anchor{load}
21755 Depending on what remote debugging facilities are configured into
21756 @value{GDBN}, the @code{load} command may be available. Where it exists, it
21757 is meant to make @var{filename} (an executable) available for debugging
21758 on the remote system---by downloading, or dynamic linking, for example.
21759 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21760 the @code{add-symbol-file} command.
21761
21762 If your @value{GDBN} does not have a @code{load} command, attempting to
21763 execute it gets the error message ``@code{You can't do that when your
21764 target is @dots{}}''
21765
21766 The file is loaded at whatever address is specified in the executable.
21767 For some object file formats, you can specify the load address when you
21768 link the program; for other formats, like a.out, the object file format
21769 specifies a fixed address.
21770 @c FIXME! This would be a good place for an xref to the GNU linker doc.
21771
21772 It is also possible to tell @value{GDBN} to load the executable file at a
21773 specific offset described by the optional argument @var{offset}. When
21774 @var{offset} is provided, @var{filename} must also be provided.
21775
21776 Depending on the remote side capabilities, @value{GDBN} may be able to
21777 load programs into flash memory.
21778
21779 @code{load} does not repeat if you press @key{RET} again after using it.
21780 @end table
21781
21782 @table @code
21783
21784 @kindex flash-erase
21785 @item flash-erase
21786 @anchor{flash-erase}
21787
21788 Erases all known flash memory regions on the target.
21789
21790 @end table
21791
21792 @node Byte Order
21793 @section Choosing Target Byte Order
21794
21795 @cindex choosing target byte order
21796 @cindex target byte order
21797
21798 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
21799 offer the ability to run either big-endian or little-endian byte
21800 orders. Usually the executable or symbol will include a bit to
21801 designate the endian-ness, and you will not need to worry about
21802 which to use. However, you may still find it useful to adjust
21803 @value{GDBN}'s idea of processor endian-ness manually.
21804
21805 @table @code
21806 @kindex set endian
21807 @item set endian big
21808 Instruct @value{GDBN} to assume the target is big-endian.
21809
21810 @item set endian little
21811 Instruct @value{GDBN} to assume the target is little-endian.
21812
21813 @item set endian auto
21814 Instruct @value{GDBN} to use the byte order associated with the
21815 executable.
21816
21817 @item show endian
21818 Display @value{GDBN}'s current idea of the target byte order.
21819
21820 @end table
21821
21822 If the @code{set endian auto} mode is in effect and no executable has
21823 been selected, then the endianness used is the last one chosen either
21824 by one of the @code{set endian big} and @code{set endian little}
21825 commands or by inferring from the last executable used. If no
21826 endianness has been previously chosen, then the default for this mode
21827 is inferred from the target @value{GDBN} has been built for, and is
21828 @code{little} if the name of the target CPU has an @code{el} suffix
21829 and @code{big} otherwise.
21830
21831 Note that these commands merely adjust interpretation of symbolic
21832 data on the host, and that they have absolutely no effect on the
21833 target system.
21834
21835
21836 @node Remote Debugging
21837 @chapter Debugging Remote Programs
21838 @cindex remote debugging
21839
21840 If you are trying to debug a program running on a machine that cannot run
21841 @value{GDBN} in the usual way, it is often useful to use remote debugging.
21842 For example, you might use remote debugging on an operating system kernel,
21843 or on a small system which does not have a general purpose operating system
21844 powerful enough to run a full-featured debugger.
21845
21846 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21847 to make this work with particular debugging targets. In addition,
21848 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
21849 but not specific to any particular target system) which you can use if you
21850 write the remote stubs---the code that runs on the remote system to
21851 communicate with @value{GDBN}.
21852
21853 Other remote targets may be available in your
21854 configuration of @value{GDBN}; use @code{help target} to list them.
21855
21856 @menu
21857 * Connecting:: Connecting to a remote target
21858 * File Transfer:: Sending files to a remote system
21859 * Server:: Using the gdbserver program
21860 * Remote Configuration:: Remote configuration
21861 * Remote Stub:: Implementing a remote stub
21862 @end menu
21863
21864 @node Connecting
21865 @section Connecting to a Remote Target
21866 @cindex remote debugging, connecting
21867 @cindex @code{gdbserver}, connecting
21868 @cindex remote debugging, types of connections
21869 @cindex @code{gdbserver}, types of connections
21870 @cindex @code{gdbserver}, @code{target remote} mode
21871 @cindex @code{gdbserver}, @code{target extended-remote} mode
21872
21873 This section describes how to connect to a remote target, including the
21874 types of connections and their differences, how to set up executable and
21875 symbol files on the host and target, and the commands used for
21876 connecting to and disconnecting from the remote target.
21877
21878 @subsection Types of Remote Connections
21879
21880 @value{GDBN} supports two types of remote connections, @code{target remote}
21881 mode and @code{target extended-remote} mode. Note that many remote targets
21882 support only @code{target remote} mode. There are several major
21883 differences between the two types of connections, enumerated here:
21884
21885 @table @asis
21886
21887 @cindex remote debugging, detach and program exit
21888 @item Result of detach or program exit
21889 @strong{With target remote mode:} When the debugged program exits or you
21890 detach from it, @value{GDBN} disconnects from the target. When using
21891 @code{gdbserver}, @code{gdbserver} will exit.
21892
21893 @strong{With target extended-remote mode:} When the debugged program exits or
21894 you detach from it, @value{GDBN} remains connected to the target, even
21895 though no program is running. You can rerun the program, attach to a
21896 running program, or use @code{monitor} commands specific to the target.
21897
21898 When using @code{gdbserver} in this case, it does not exit unless it was
21899 invoked using the @option{--once} option. If the @option{--once} option
21900 was not used, you can ask @code{gdbserver} to exit using the
21901 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21902
21903 @item Specifying the program to debug
21904 For both connection types you use the @code{file} command to specify the
21905 program on the host system. If you are using @code{gdbserver} there are
21906 some differences in how to specify the location of the program on the
21907 target.
21908
21909 @strong{With target remote mode:} You must either specify the program to debug
21910 on the @code{gdbserver} command line or use the @option{--attach} option
21911 (@pxref{Attaching to a program,,Attaching to a Running Program}).
21912
21913 @cindex @option{--multi}, @code{gdbserver} option
21914 @strong{With target extended-remote mode:} You may specify the program to debug
21915 on the @code{gdbserver} command line, or you can load the program or attach
21916 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21917
21918 @anchor{--multi Option in Types of Remote Connnections}
21919 You can start @code{gdbserver} without supplying an initial command to run
21920 or process ID to attach. To do this, use the @option{--multi} command line
21921 option. Then you can connect using @code{target extended-remote} and start
21922 the program you want to debug (see below for details on using the
21923 @code{run} command in this scenario). Note that the conditions under which
21924 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
21925 (@code{target remote} or @code{target extended-remote}). The
21926 @option{--multi} option to @code{gdbserver} has no influence on that.
21927
21928 @item The @code{run} command
21929 @strong{With target remote mode:} The @code{run} command is not
21930 supported. Once a connection has been established, you can use all
21931 the usual @value{GDBN} commands to examine and change data. The
21932 remote program is already running, so you can use commands like
21933 @kbd{step} and @kbd{continue}.
21934
21935 @strong{With target extended-remote mode:} The @code{run} command is
21936 supported. The @code{run} command uses the value set by
21937 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
21938 the program to run. Command line arguments are supported, except for
21939 wildcard expansion and I/O redirection (@pxref{Arguments}).
21940
21941 If you specify the program to debug on the command line, then the
21942 @code{run} command is not required to start execution, and you can
21943 resume using commands like @kbd{step} and @kbd{continue} as with
21944 @code{target remote} mode.
21945
21946 @anchor{Attaching in Types of Remote Connections}
21947 @item Attaching
21948 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21949 not supported. To attach to a running program using @code{gdbserver}, you
21950 must use the @option{--attach} option (@pxref{Running gdbserver}).
21951
21952 @strong{With target extended-remote mode:} To attach to a running program,
21953 you may use the @code{attach} command after the connection has been
21954 established. If you are using @code{gdbserver}, you may also invoke
21955 @code{gdbserver} using the @option{--attach} option
21956 (@pxref{Running gdbserver}).
21957
21958 Some remote targets allow @value{GDBN} to determine the executable file running
21959 in the process the debugger is attaching to. In such a case, @value{GDBN}
21960 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21961 between the executable file name running in the process and the name of the
21962 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21963
21964 @end table
21965
21966 @anchor{Host and target files}
21967 @subsection Host and Target Files
21968 @cindex remote debugging, symbol files
21969 @cindex symbol files, remote debugging
21970
21971 @value{GDBN}, running on the host, needs access to symbol and debugging
21972 information for your program running on the target. This requires
21973 access to an unstripped copy of your program, and possibly any associated
21974 symbol files. Note that this section applies equally to both @code{target
21975 remote} mode and @code{target extended-remote} mode.
21976
21977 Some remote targets (@pxref{qXfer executable filename read}, and
21978 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21979 the same connection used to communicate with @value{GDBN}. With such a
21980 target, if the remote program is unstripped, the only command you need is
21981 @code{target remote} (or @code{target extended-remote}).
21982
21983 If the remote program is stripped, or the target does not support remote
21984 program file access, start up @value{GDBN} using the name of the local
21985 unstripped copy of your program as the first argument, or use the
21986 @code{file} command. Use @code{set sysroot} to specify the location (on
21987 the host) of target libraries (unless your @value{GDBN} was compiled with
21988 the correct sysroot using @code{--with-sysroot}). Alternatively, you
21989 may use @code{set solib-search-path} to specify how @value{GDBN} locates
21990 target libraries.
21991
21992 The symbol file and target libraries must exactly match the executable
21993 and libraries on the target, with one exception: the files on the host
21994 system should not be stripped, even if the files on the target system
21995 are. Mismatched or missing files will lead to confusing results
21996 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21997 files may also prevent @code{gdbserver} from debugging multi-threaded
21998 programs.
21999
22000 @subsection Remote Connection Commands
22001 @cindex remote connection commands
22002 @value{GDBN} can communicate with the target over a serial line, a
22003 local Unix domain socket, or
22004 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22005 each case, @value{GDBN} uses the same protocol for debugging your
22006 program; only the medium carrying the debugging packets varies. The
22007 @code{target remote} and @code{target extended-remote} commands
22008 establish a connection to the target. Both commands accept the same
22009 arguments, which indicate the medium to use:
22010
22011 @table @code
22012
22013 @item target remote @var{serial-device}
22014 @itemx target extended-remote @var{serial-device}
22015 @cindex serial line, @code{target remote}
22016 Use @var{serial-device} to communicate with the target. For example,
22017 to use a serial line connected to the device named @file{/dev/ttyb}:
22018
22019 @smallexample
22020 target remote /dev/ttyb
22021 @end smallexample
22022
22023 If you're using a serial line, you may want to give @value{GDBN} the
22024 @samp{--baud} option, or use the @code{set serial baud} command
22025 (@pxref{Remote Configuration, set serial baud}) before the
22026 @code{target} command.
22027
22028 @item target remote @var{local-socket}
22029 @itemx target extended-remote @var{local-socket}
22030 @cindex local socket, @code{target remote}
22031 @cindex Unix domain socket
22032 Use @var{local-socket} to communicate with the target. For example,
22033 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22034
22035 @smallexample
22036 target remote /tmp/gdb-socket0
22037 @end smallexample
22038
22039 Note that this command has the same form as the command to connect
22040 to a serial line. @value{GDBN} will automatically determine which
22041 kind of file you have specified and will make the appropriate kind
22042 of connection.
22043 This feature is not available if the host system does not support
22044 Unix domain sockets.
22045
22046 @item target remote @code{@var{host}:@var{port}}
22047 @itemx target remote @code{[@var{host}]:@var{port}}
22048 @itemx target remote @code{tcp:@var{host}:@var{port}}
22049 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22050 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22051 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22052 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22053 @itemx target extended-remote @code{@var{host}:@var{port}}
22054 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22055 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22056 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22057 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22058 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22059 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22060 @cindex @acronym{TCP} port, @code{target remote}
22061 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22062 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22063 address, or a numeric @acronym{IPv6} address (with or without the
22064 square brackets to separate the address from the port); @var{port}
22065 must be a decimal number. The @var{host} could be the target machine
22066 itself, if it is directly connected to the net, or it might be a
22067 terminal server which in turn has a serial line to the target.
22068
22069 For example, to connect to port 2828 on a terminal server named
22070 @code{manyfarms}:
22071
22072 @smallexample
22073 target remote manyfarms:2828
22074 @end smallexample
22075
22076 To connect to port 2828 on a terminal server whose address is
22077 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22078 square bracket syntax:
22079
22080 @smallexample
22081 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22082 @end smallexample
22083
22084 @noindent
22085 or explicitly specify the @acronym{IPv6} protocol:
22086
22087 @smallexample
22088 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22089 @end smallexample
22090
22091 This last example may be confusing to the reader, because there is no
22092 visible separation between the hostname and the port number.
22093 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22094 using square brackets for clarity. However, it is important to
22095 mention that for @value{GDBN} there is no ambiguity: the number after
22096 the last colon is considered to be the port number.
22097
22098 If your remote target is actually running on the same machine as your
22099 debugger session (e.g.@: a simulator for your target running on the
22100 same host), you can omit the hostname. For example, to connect to
22101 port 1234 on your local machine:
22102
22103 @smallexample
22104 target remote :1234
22105 @end smallexample
22106 @noindent
22107
22108 Note that the colon is still required here.
22109
22110 @item target remote @code{udp:@var{host}:@var{port}}
22111 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22112 @itemx target remote @code{udp4:@var{host}:@var{port}}
22113 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22114 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22115 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22116 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22117 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22118 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22119 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22120 @cindex @acronym{UDP} port, @code{target remote}
22121 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22122 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22123
22124 @smallexample
22125 target remote udp:manyfarms:2828
22126 @end smallexample
22127
22128 When using a @acronym{UDP} connection for remote debugging, you should
22129 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22130 can silently drop packets on busy or unreliable networks, which will
22131 cause havoc with your debugging session.
22132
22133 @item target remote | @var{command}
22134 @itemx target extended-remote | @var{command}
22135 @cindex pipe, @code{target remote} to
22136 Run @var{command} in the background and communicate with it using a
22137 pipe. The @var{command} is a shell command, to be parsed and expanded
22138 by the system's command shell, @code{/bin/sh}; it should expect remote
22139 protocol packets on its standard input, and send replies on its
22140 standard output. You could use this to run a stand-alone simulator
22141 that speaks the remote debugging protocol, to make net connections
22142 using programs like @code{ssh}, or for other similar tricks.
22143
22144 If @var{command} closes its standard output (perhaps by exiting),
22145 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22146 program has already exited, this will have no effect.)
22147
22148 @end table
22149
22150 @cindex interrupting remote programs
22151 @cindex remote programs, interrupting
22152 Whenever @value{GDBN} is waiting for the remote program, if you type the
22153 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22154 program. This may or may not succeed, depending in part on the hardware
22155 and the serial drivers the remote system uses. If you type the
22156 interrupt character once again, @value{GDBN} displays this prompt:
22157
22158 @smallexample
22159 Interrupted while waiting for the program.
22160 Give up (and stop debugging it)? (y or n)
22161 @end smallexample
22162
22163 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22164 the remote debugging session. (If you decide you want to try again later,
22165 you can use @kbd{target remote} again to connect once more.) If you type
22166 @kbd{n}, @value{GDBN} goes back to waiting.
22167
22168 In @code{target extended-remote} mode, typing @kbd{n} will leave
22169 @value{GDBN} connected to the target.
22170
22171 @table @code
22172 @kindex detach (remote)
22173 @item detach
22174 When you have finished debugging the remote program, you can use the
22175 @code{detach} command to release it from @value{GDBN} control.
22176 Detaching from the target normally resumes its execution, but the results
22177 will depend on your particular remote stub. After the @code{detach}
22178 command in @code{target remote} mode, @value{GDBN} is free to connect to
22179 another target. In @code{target extended-remote} mode, @value{GDBN} is
22180 still connected to the target.
22181
22182 @kindex disconnect
22183 @item disconnect
22184 The @code{disconnect} command closes the connection to the target, and
22185 the target is generally not resumed. It will wait for @value{GDBN}
22186 (this instance or another one) to connect and continue debugging. After
22187 the @code{disconnect} command, @value{GDBN} is again free to connect to
22188 another target.
22189
22190 @cindex send command to remote monitor
22191 @cindex extend @value{GDBN} for remote targets
22192 @cindex add new commands for external monitor
22193 @kindex monitor
22194 @item monitor @var{cmd}
22195 This command allows you to send arbitrary commands directly to the
22196 remote monitor. Since @value{GDBN} doesn't care about the commands it
22197 sends like this, this command is the way to extend @value{GDBN}---you
22198 can add new commands that only the external monitor will understand
22199 and implement.
22200 @end table
22201
22202 @node File Transfer
22203 @section Sending files to a remote system
22204 @cindex remote target, file transfer
22205 @cindex file transfer
22206 @cindex sending files to remote systems
22207
22208 Some remote targets offer the ability to transfer files over the same
22209 connection used to communicate with @value{GDBN}. This is convenient
22210 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22211 running @code{gdbserver} over a network interface. For other targets,
22212 e.g.@: embedded devices with only a single serial port, this may be
22213 the only way to upload or download files.
22214
22215 Not all remote targets support these commands.
22216
22217 @table @code
22218 @kindex remote put
22219 @item remote put @var{hostfile} @var{targetfile}
22220 Copy file @var{hostfile} from the host system (the machine running
22221 @value{GDBN}) to @var{targetfile} on the target system.
22222
22223 @kindex remote get
22224 @item remote get @var{targetfile} @var{hostfile}
22225 Copy file @var{targetfile} from the target system to @var{hostfile}
22226 on the host system.
22227
22228 @kindex remote delete
22229 @item remote delete @var{targetfile}
22230 Delete @var{targetfile} from the target system.
22231
22232 @end table
22233
22234 @node Server
22235 @section Using the @code{gdbserver} Program
22236
22237 @kindex gdbserver
22238 @cindex remote connection without stubs
22239 @code{gdbserver} is a control program for Unix-like systems, which
22240 allows you to connect your program with a remote @value{GDBN} via
22241 @code{target remote} or @code{target extended-remote}---but without
22242 linking in the usual debugging stub.
22243
22244 @code{gdbserver} is not a complete replacement for the debugging stubs,
22245 because it requires essentially the same operating-system facilities
22246 that @value{GDBN} itself does. In fact, a system that can run
22247 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22248 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22249 because it is a much smaller program than @value{GDBN} itself. It is
22250 also easier to port than all of @value{GDBN}, so you may be able to get
22251 started more quickly on a new system by using @code{gdbserver}.
22252 Finally, if you develop code for real-time systems, you may find that
22253 the tradeoffs involved in real-time operation make it more convenient to
22254 do as much development work as possible on another system, for example
22255 by cross-compiling. You can use @code{gdbserver} to make a similar
22256 choice for debugging.
22257
22258 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22259 or a TCP connection, using the standard @value{GDBN} remote serial
22260 protocol.
22261
22262 @quotation
22263 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22264 Do not run @code{gdbserver} connected to any public network; a
22265 @value{GDBN} connection to @code{gdbserver} provides access to the
22266 target system with the same privileges as the user running
22267 @code{gdbserver}.
22268 @end quotation
22269
22270 @anchor{Running gdbserver}
22271 @subsection Running @code{gdbserver}
22272 @cindex arguments, to @code{gdbserver}
22273 @cindex @code{gdbserver}, command-line arguments
22274
22275 Run @code{gdbserver} on the target system. You need a copy of the
22276 program you want to debug, including any libraries it requires.
22277 @code{gdbserver} does not need your program's symbol table, so you can
22278 strip the program if necessary to save space. @value{GDBN} on the host
22279 system does all the symbol handling.
22280
22281 To use the server, you must tell it how to communicate with @value{GDBN};
22282 the name of your program; and the arguments for your program. The usual
22283 syntax is:
22284
22285 @smallexample
22286 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22287 @end smallexample
22288
22289 @var{comm} is either a device name (to use a serial line), or a TCP
22290 hostname and portnumber, or @code{-} or @code{stdio} to use
22291 stdin/stdout of @code{gdbserver}.
22292 For example, to debug Emacs with the argument
22293 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22294 @file{/dev/com1}:
22295
22296 @smallexample
22297 target> gdbserver /dev/com1 emacs foo.txt
22298 @end smallexample
22299
22300 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22301 with it.
22302
22303 To use a TCP connection instead of a serial line:
22304
22305 @smallexample
22306 target> gdbserver host:2345 emacs foo.txt
22307 @end smallexample
22308
22309 The only difference from the previous example is the first argument,
22310 specifying that you are communicating with the host @value{GDBN} via
22311 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22312 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22313 (Currently, the @samp{host} part is ignored.) You can choose any number
22314 you want for the port number as long as it does not conflict with any
22315 TCP ports already in use on the target system (for example, @code{23} is
22316 reserved for @code{telnet}).@footnote{If you choose a port number that
22317 conflicts with another service, @code{gdbserver} prints an error message
22318 and exits.} You must use the same port number with the host @value{GDBN}
22319 @code{target remote} command.
22320
22321 The @code{stdio} connection is useful when starting @code{gdbserver}
22322 with ssh:
22323
22324 @smallexample
22325 (gdb) target remote | ssh -T hostname gdbserver - hello
22326 @end smallexample
22327
22328 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22329 and we don't want escape-character handling. Ssh does this by default when
22330 a command is provided, the flag is provided to make it explicit.
22331 You could elide it if you want to.
22332
22333 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22334 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22335 display through a pipe connected to gdbserver.
22336 Both @code{stdout} and @code{stderr} use the same pipe.
22337
22338 @anchor{Attaching to a program}
22339 @subsubsection Attaching to a Running Program
22340 @cindex attach to a program, @code{gdbserver}
22341 @cindex @option{--attach}, @code{gdbserver} option
22342
22343 On some targets, @code{gdbserver} can also attach to running programs.
22344 This is accomplished via the @code{--attach} argument. The syntax is:
22345
22346 @smallexample
22347 target> gdbserver --attach @var{comm} @var{pid}
22348 @end smallexample
22349
22350 @var{pid} is the process ID of a currently running process. It isn't
22351 necessary to point @code{gdbserver} at a binary for the running process.
22352
22353 In @code{target extended-remote} mode, you can also attach using the
22354 @value{GDBN} attach command
22355 (@pxref{Attaching in Types of Remote Connections}).
22356
22357 @pindex pidof
22358 You can debug processes by name instead of process ID if your target has the
22359 @code{pidof} utility:
22360
22361 @smallexample
22362 target> gdbserver --attach @var{comm} `pidof @var{program}`
22363 @end smallexample
22364
22365 In case more than one copy of @var{program} is running, or @var{program}
22366 has multiple threads, most versions of @code{pidof} support the
22367 @code{-s} option to only return the first process ID.
22368
22369 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22370
22371 This section applies only when @code{gdbserver} is run to listen on a TCP
22372 port.
22373
22374 @code{gdbserver} normally terminates after all of its debugged processes have
22375 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22376 extended-remote}, @code{gdbserver} stays running even with no processes left.
22377 @value{GDBN} normally terminates the spawned debugged process on its exit,
22378 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22379 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22380 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22381 stays running even in the @kbd{target remote} mode.
22382
22383 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22384 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22385 completeness, at most one @value{GDBN} can be connected at a time.
22386
22387 @cindex @option{--once}, @code{gdbserver} option
22388 By default, @code{gdbserver} keeps the listening TCP port open, so that
22389 subsequent connections are possible. However, if you start @code{gdbserver}
22390 with the @option{--once} option, it will stop listening for any further
22391 connection attempts after connecting to the first @value{GDBN} session. This
22392 means no further connections to @code{gdbserver} will be possible after the
22393 first one. It also means @code{gdbserver} will terminate after the first
22394 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22395 connections and even in the @kbd{target extended-remote} mode. The
22396 @option{--once} option allows reusing the same port number for connecting to
22397 multiple instances of @code{gdbserver} running on the same host, since each
22398 instance closes its port after the first connection.
22399
22400 @anchor{Other Command-Line Arguments for gdbserver}
22401 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22402
22403 You can use the @option{--multi} option to start @code{gdbserver} without
22404 specifying a program to debug or a process to attach to. Then you can
22405 attach in @code{target extended-remote} mode and run or attach to a
22406 program. For more information,
22407 @pxref{--multi Option in Types of Remote Connnections}.
22408
22409 @cindex @option{--debug}, @code{gdbserver} option
22410 The @option{--debug} option tells @code{gdbserver} to display extra
22411 status information about the debugging process.
22412 @cindex @option{--remote-debug}, @code{gdbserver} option
22413 The @option{--remote-debug} option tells @code{gdbserver} to display
22414 remote protocol debug output.
22415 @cindex @option{--debug-file}, @code{gdbserver} option
22416 @cindex @code{gdbserver}, send all debug output to a single file
22417 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22418 write any debug output to the given @var{filename}. These options are intended
22419 for @code{gdbserver} development and for bug reports to the developers.
22420
22421 @cindex @option{--debug-format}, @code{gdbserver} option
22422 The @option{--debug-format=option1[,option2,...]} option tells
22423 @code{gdbserver} to include additional information in each output.
22424 Possible options are:
22425
22426 @table @code
22427 @item none
22428 Turn off all extra information in debugging output.
22429 @item all
22430 Turn on all extra information in debugging output.
22431 @item timestamps
22432 Include a timestamp in each line of debugging output.
22433 @end table
22434
22435 Options are processed in order. Thus, for example, if @option{none}
22436 appears last then no additional information is added to debugging output.
22437
22438 @cindex @option{--wrapper}, @code{gdbserver} option
22439 The @option{--wrapper} option specifies a wrapper to launch programs
22440 for debugging. The option should be followed by the name of the
22441 wrapper, then any command-line arguments to pass to the wrapper, then
22442 @kbd{--} indicating the end of the wrapper arguments.
22443
22444 @code{gdbserver} runs the specified wrapper program with a combined
22445 command line including the wrapper arguments, then the name of the
22446 program to debug, then any arguments to the program. The wrapper
22447 runs until it executes your program, and then @value{GDBN} gains control.
22448
22449 You can use any program that eventually calls @code{execve} with
22450 its arguments as a wrapper. Several standard Unix utilities do
22451 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22452 with @code{exec "$@@"} will also work.
22453
22454 For example, you can use @code{env} to pass an environment variable to
22455 the debugged program, without setting the variable in @code{gdbserver}'s
22456 environment:
22457
22458 @smallexample
22459 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22460 @end smallexample
22461
22462 @cindex @option{--selftest}
22463 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22464
22465 @smallexample
22466 $ gdbserver --selftest
22467 Ran 2 unit tests, 0 failed
22468 @end smallexample
22469
22470 These tests are disabled in release.
22471 @subsection Connecting to @code{gdbserver}
22472
22473 The basic procedure for connecting to the remote target is:
22474 @itemize
22475
22476 @item
22477 Run @value{GDBN} on the host system.
22478
22479 @item
22480 Make sure you have the necessary symbol files
22481 (@pxref{Host and target files}).
22482 Load symbols for your application using the @code{file} command before you
22483 connect. Use @code{set sysroot} to locate target libraries (unless your
22484 @value{GDBN} was compiled with the correct sysroot using
22485 @code{--with-sysroot}).
22486
22487 @item
22488 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22489 For TCP connections, you must start up @code{gdbserver} prior to using
22490 the @code{target} command. Otherwise you may get an error whose
22491 text depends on the host system, but which usually looks something like
22492 @samp{Connection refused}. Don't use the @code{load}
22493 command in @value{GDBN} when using @code{target remote} mode, since the
22494 program is already on the target.
22495
22496 @end itemize
22497
22498 @anchor{Monitor Commands for gdbserver}
22499 @subsection Monitor Commands for @code{gdbserver}
22500 @cindex monitor commands, for @code{gdbserver}
22501
22502 During a @value{GDBN} session using @code{gdbserver}, you can use the
22503 @code{monitor} command to send special requests to @code{gdbserver}.
22504 Here are the available commands.
22505
22506 @table @code
22507 @item monitor help
22508 List the available monitor commands.
22509
22510 @item monitor set debug 0
22511 @itemx monitor set debug 1
22512 Disable or enable general debugging messages.
22513
22514 @item monitor set remote-debug 0
22515 @itemx monitor set remote-debug 1
22516 Disable or enable specific debugging messages associated with the remote
22517 protocol (@pxref{Remote Protocol}).
22518
22519 @item monitor set debug-file filename
22520 @itemx monitor set debug-file
22521 Send any debug output to the given file, or to stderr.
22522
22523 @item monitor set debug-format option1@r{[},option2,...@r{]}
22524 Specify additional text to add to debugging messages.
22525 Possible options are:
22526
22527 @table @code
22528 @item none
22529 Turn off all extra information in debugging output.
22530 @item all
22531 Turn on all extra information in debugging output.
22532 @item timestamps
22533 Include a timestamp in each line of debugging output.
22534 @end table
22535
22536 Options are processed in order. Thus, for example, if @option{none}
22537 appears last then no additional information is added to debugging output.
22538
22539 @item monitor set libthread-db-search-path [PATH]
22540 @cindex gdbserver, search path for @code{libthread_db}
22541 When this command is issued, @var{path} is a colon-separated list of
22542 directories to search for @code{libthread_db} (@pxref{Threads,,set
22543 libthread-db-search-path}). If you omit @var{path},
22544 @samp{libthread-db-search-path} will be reset to its default value.
22545
22546 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22547 not supported in @code{gdbserver}.
22548
22549 @item monitor exit
22550 Tell gdbserver to exit immediately. This command should be followed by
22551 @code{disconnect} to close the debugging session. @code{gdbserver} will
22552 detach from any attached processes and kill any processes it created.
22553 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22554 of a multi-process mode debug session.
22555
22556 @end table
22557
22558 @subsection Tracepoints support in @code{gdbserver}
22559 @cindex tracepoints support in @code{gdbserver}
22560
22561 On some targets, @code{gdbserver} supports tracepoints, fast
22562 tracepoints and static tracepoints.
22563
22564 For fast or static tracepoints to work, a special library called the
22565 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22566 This library is built and distributed as an integral part of
22567 @code{gdbserver}. In addition, support for static tracepoints
22568 requires building the in-process agent library with static tracepoints
22569 support. At present, the UST (LTTng Userspace Tracer,
22570 @url{http://lttng.org/ust}) tracing engine is supported. This support
22571 is automatically available if UST development headers are found in the
22572 standard include path when @code{gdbserver} is built, or if
22573 @code{gdbserver} was explicitly configured using @option{--with-ust}
22574 to point at such headers. You can explicitly disable the support
22575 using @option{--with-ust=no}.
22576
22577 There are several ways to load the in-process agent in your program:
22578
22579 @table @code
22580 @item Specifying it as dependency at link time
22581
22582 You can link your program dynamically with the in-process agent
22583 library. On most systems, this is accomplished by adding
22584 @code{-linproctrace} to the link command.
22585
22586 @item Using the system's preloading mechanisms
22587
22588 You can force loading the in-process agent at startup time by using
22589 your system's support for preloading shared libraries. Many Unixes
22590 support the concept of preloading user defined libraries. In most
22591 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22592 in the environment. See also the description of @code{gdbserver}'s
22593 @option{--wrapper} command line option.
22594
22595 @item Using @value{GDBN} to force loading the agent at run time
22596
22597 On some systems, you can force the inferior to load a shared library,
22598 by calling a dynamic loader function in the inferior that takes care
22599 of dynamically looking up and loading a shared library. On most Unix
22600 systems, the function is @code{dlopen}. You'll use the @code{call}
22601 command for that. For example:
22602
22603 @smallexample
22604 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22605 @end smallexample
22606
22607 Note that on most Unix systems, for the @code{dlopen} function to be
22608 available, the program needs to be linked with @code{-ldl}.
22609 @end table
22610
22611 On systems that have a userspace dynamic loader, like most Unix
22612 systems, when you connect to @code{gdbserver} using @code{target
22613 remote}, you'll find that the program is stopped at the dynamic
22614 loader's entry point, and no shared library has been loaded in the
22615 program's address space yet, including the in-process agent. In that
22616 case, before being able to use any of the fast or static tracepoints
22617 features, you need to let the loader run and load the shared
22618 libraries. The simplest way to do that is to run the program to the
22619 main procedure. E.g., if debugging a C or C@t{++} program, start
22620 @code{gdbserver} like so:
22621
22622 @smallexample
22623 $ gdbserver :9999 myprogram
22624 @end smallexample
22625
22626 Start GDB and connect to @code{gdbserver} like so, and run to main:
22627
22628 @smallexample
22629 $ gdb myprogram
22630 (@value{GDBP}) target remote myhost:9999
22631 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22632 (@value{GDBP}) b main
22633 (@value{GDBP}) continue
22634 @end smallexample
22635
22636 The in-process tracing agent library should now be loaded into the
22637 process; you can confirm it with the @code{info sharedlibrary}
22638 command, which will list @file{libinproctrace.so} as loaded in the
22639 process. You are now ready to install fast tracepoints, list static
22640 tracepoint markers, probe static tracepoints markers, and start
22641 tracing.
22642
22643 @node Remote Configuration
22644 @section Remote Configuration
22645
22646 @kindex set remote
22647 @kindex show remote
22648 This section documents the configuration options available when
22649 debugging remote programs. For the options related to the File I/O
22650 extensions of the remote protocol, see @ref{system,
22651 system-call-allowed}.
22652
22653 @table @code
22654 @item set remoteaddresssize @var{bits}
22655 @cindex address size for remote targets
22656 @cindex bits in remote address
22657 Set the maximum size of address in a memory packet to the specified
22658 number of bits. @value{GDBN} will mask off the address bits above
22659 that number, when it passes addresses to the remote target. The
22660 default value is the number of bits in the target's address.
22661
22662 @item show remoteaddresssize
22663 Show the current value of remote address size in bits.
22664
22665 @item set serial baud @var{n}
22666 @cindex baud rate for remote targets
22667 Set the baud rate for the remote serial I/O to @var{n} baud. The
22668 value is used to set the speed of the serial port used for debugging
22669 remote targets.
22670
22671 @item show serial baud
22672 Show the current speed of the remote connection.
22673
22674 @item set serial parity @var{parity}
22675 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22676 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22677
22678 @item show serial parity
22679 Show the current parity of the serial port.
22680
22681 @item set remotebreak
22682 @cindex interrupt remote programs
22683 @cindex BREAK signal instead of Ctrl-C
22684 @anchor{set remotebreak}
22685 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
22686 when you type @kbd{Ctrl-c} to interrupt the program running
22687 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
22688 character instead. The default is off, since most remote systems
22689 expect to see @samp{Ctrl-C} as the interrupt signal.
22690
22691 @item show remotebreak
22692 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22693 interrupt the remote program.
22694
22695 @item set remoteflow on
22696 @itemx set remoteflow off
22697 @kindex set remoteflow
22698 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22699 on the serial port used to communicate to the remote target.
22700
22701 @item show remoteflow
22702 @kindex show remoteflow
22703 Show the current setting of hardware flow control.
22704
22705 @item set remotelogbase @var{base}
22706 Set the base (a.k.a.@: radix) of logging serial protocol
22707 communications to @var{base}. Supported values of @var{base} are:
22708 @code{ascii}, @code{octal}, and @code{hex}. The default is
22709 @code{ascii}.
22710
22711 @item show remotelogbase
22712 Show the current setting of the radix for logging remote serial
22713 protocol.
22714
22715 @item set remotelogfile @var{file}
22716 @cindex record serial communications on file
22717 Record remote serial communications on the named @var{file}. The
22718 default is not to record at all.
22719
22720 @item show remotelogfile
22721 Show the current setting of the file name on which to record the
22722 serial communications.
22723
22724 @item set remotetimeout @var{num}
22725 @cindex timeout for serial communications
22726 @cindex remote timeout
22727 Set the timeout limit to wait for the remote target to respond to
22728 @var{num} seconds. The default is 2 seconds.
22729
22730 @item show remotetimeout
22731 Show the current number of seconds to wait for the remote target
22732 responses.
22733
22734 @cindex limit hardware breakpoints and watchpoints
22735 @cindex remote target, limit break- and watchpoints
22736 @anchor{set remote hardware-watchpoint-limit}
22737 @anchor{set remote hardware-breakpoint-limit}
22738 @item set remote hardware-watchpoint-limit @var{limit}
22739 @itemx set remote hardware-breakpoint-limit @var{limit}
22740 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22741 or breakpoints. The @var{limit} can be set to 0 to disable hardware
22742 watchpoints or breakpoints, and @code{unlimited} for unlimited
22743 watchpoints or breakpoints.
22744
22745 @item show remote hardware-watchpoint-limit
22746 @itemx show remote hardware-breakpoint-limit
22747 Show the current limit for the number of hardware watchpoints or
22748 breakpoints that @value{GDBN} can use.
22749
22750 @cindex limit hardware watchpoints length
22751 @cindex remote target, limit watchpoints length
22752 @anchor{set remote hardware-watchpoint-length-limit}
22753 @item set remote hardware-watchpoint-length-limit @var{limit}
22754 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22755 length of a remote hardware watchpoint. A @var{limit} of 0 disables
22756 hardware watchpoints and @code{unlimited} allows watchpoints of any
22757 length.
22758
22759 @item show remote hardware-watchpoint-length-limit
22760 Show the current limit (in bytes) of the maximum length of
22761 a remote hardware watchpoint.
22762
22763 @item set remote exec-file @var{filename}
22764 @itemx show remote exec-file
22765 @anchor{set remote exec-file}
22766 @cindex executable file, for remote target
22767 Select the file used for @code{run} with @code{target
22768 extended-remote}. This should be set to a filename valid on the
22769 target system. If it is not set, the target will use a default
22770 filename (e.g.@: the last program run).
22771
22772 @item set remote interrupt-sequence
22773 @cindex interrupt remote programs
22774 @cindex select Ctrl-C, BREAK or BREAK-g
22775 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22776 @samp{BREAK-g} as the
22777 sequence to the remote target in order to interrupt the execution.
22778 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22779 is high level of serial line for some certain time.
22780 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22781 It is @code{BREAK} signal followed by character @code{g}.
22782
22783 @item show interrupt-sequence
22784 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22785 is sent by @value{GDBN} to interrupt the remote program.
22786 @code{BREAK-g} is BREAK signal followed by @code{g} and
22787 also known as Magic SysRq g.
22788
22789 @item set remote interrupt-on-connect
22790 @cindex send interrupt-sequence on start
22791 Specify whether interrupt-sequence is sent to remote target when
22792 @value{GDBN} connects to it. This is mostly needed when you debug
22793 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22794 which is known as Magic SysRq g in order to connect @value{GDBN}.
22795
22796 @item show interrupt-on-connect
22797 Show whether interrupt-sequence is sent
22798 to remote target when @value{GDBN} connects to it.
22799
22800 @kindex set tcp
22801 @kindex show tcp
22802 @item set tcp auto-retry on
22803 @cindex auto-retry, for remote TCP target
22804 Enable auto-retry for remote TCP connections. This is useful if the remote
22805 debugging agent is launched in parallel with @value{GDBN}; there is a race
22806 condition because the agent may not become ready to accept the connection
22807 before @value{GDBN} attempts to connect. When auto-retry is
22808 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22809 to establish the connection using the timeout specified by
22810 @code{set tcp connect-timeout}.
22811
22812 @item set tcp auto-retry off
22813 Do not auto-retry failed TCP connections.
22814
22815 @item show tcp auto-retry
22816 Show the current auto-retry setting.
22817
22818 @item set tcp connect-timeout @var{seconds}
22819 @itemx set tcp connect-timeout unlimited
22820 @cindex connection timeout, for remote TCP target
22821 @cindex timeout, for remote target connection
22822 Set the timeout for establishing a TCP connection to the remote target to
22823 @var{seconds}. The timeout affects both polling to retry failed connections
22824 (enabled by @code{set tcp auto-retry on}) and waiting for connections
22825 that are merely slow to complete, and represents an approximate cumulative
22826 value. If @var{seconds} is @code{unlimited}, there is no timeout and
22827 @value{GDBN} will keep attempting to establish a connection forever,
22828 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
22829
22830 @item show tcp connect-timeout
22831 Show the current connection timeout setting.
22832 @end table
22833
22834 @cindex remote packets, enabling and disabling
22835 The @value{GDBN} remote protocol autodetects the packets supported by
22836 your debugging stub. If you need to override the autodetection, you
22837 can use these commands to enable or disable individual packets. Each
22838 packet can be set to @samp{on} (the remote target supports this
22839 packet), @samp{off} (the remote target does not support this packet),
22840 or @samp{auto} (detect remote target support for this packet). They
22841 all default to @samp{auto}. For more information about each packet,
22842 see @ref{Remote Protocol}.
22843
22844 During normal use, you should not have to use any of these commands.
22845 If you do, that may be a bug in your remote debugging stub, or a bug
22846 in @value{GDBN}. You may want to report the problem to the
22847 @value{GDBN} developers.
22848
22849 For each packet @var{name}, the command to enable or disable the
22850 packet is @code{set remote @var{name}-packet}. The available settings
22851 are:
22852
22853 @multitable @columnfractions 0.28 0.32 0.25
22854 @item Command Name
22855 @tab Remote Packet
22856 @tab Related Features
22857
22858 @item @code{fetch-register}
22859 @tab @code{p}
22860 @tab @code{info registers}
22861
22862 @item @code{set-register}
22863 @tab @code{P}
22864 @tab @code{set}
22865
22866 @item @code{binary-download}
22867 @tab @code{X}
22868 @tab @code{load}, @code{set}
22869
22870 @item @code{read-aux-vector}
22871 @tab @code{qXfer:auxv:read}
22872 @tab @code{info auxv}
22873
22874 @item @code{symbol-lookup}
22875 @tab @code{qSymbol}
22876 @tab Detecting multiple threads
22877
22878 @item @code{attach}
22879 @tab @code{vAttach}
22880 @tab @code{attach}
22881
22882 @item @code{verbose-resume}
22883 @tab @code{vCont}
22884 @tab Stepping or resuming multiple threads
22885
22886 @item @code{run}
22887 @tab @code{vRun}
22888 @tab @code{run}
22889
22890 @item @code{software-breakpoint}
22891 @tab @code{Z0}
22892 @tab @code{break}
22893
22894 @item @code{hardware-breakpoint}
22895 @tab @code{Z1}
22896 @tab @code{hbreak}
22897
22898 @item @code{write-watchpoint}
22899 @tab @code{Z2}
22900 @tab @code{watch}
22901
22902 @item @code{read-watchpoint}
22903 @tab @code{Z3}
22904 @tab @code{rwatch}
22905
22906 @item @code{access-watchpoint}
22907 @tab @code{Z4}
22908 @tab @code{awatch}
22909
22910 @item @code{pid-to-exec-file}
22911 @tab @code{qXfer:exec-file:read}
22912 @tab @code{attach}, @code{run}
22913
22914 @item @code{target-features}
22915 @tab @code{qXfer:features:read}
22916 @tab @code{set architecture}
22917
22918 @item @code{library-info}
22919 @tab @code{qXfer:libraries:read}
22920 @tab @code{info sharedlibrary}
22921
22922 @item @code{memory-map}
22923 @tab @code{qXfer:memory-map:read}
22924 @tab @code{info mem}
22925
22926 @item @code{read-sdata-object}
22927 @tab @code{qXfer:sdata:read}
22928 @tab @code{print $_sdata}
22929
22930 @item @code{read-siginfo-object}
22931 @tab @code{qXfer:siginfo:read}
22932 @tab @code{print $_siginfo}
22933
22934 @item @code{write-siginfo-object}
22935 @tab @code{qXfer:siginfo:write}
22936 @tab @code{set $_siginfo}
22937
22938 @item @code{threads}
22939 @tab @code{qXfer:threads:read}
22940 @tab @code{info threads}
22941
22942 @item @code{get-thread-local-@*storage-address}
22943 @tab @code{qGetTLSAddr}
22944 @tab Displaying @code{__thread} variables
22945
22946 @item @code{get-thread-information-block-address}
22947 @tab @code{qGetTIBAddr}
22948 @tab Display MS-Windows Thread Information Block.
22949
22950 @item @code{search-memory}
22951 @tab @code{qSearch:memory}
22952 @tab @code{find}
22953
22954 @item @code{supported-packets}
22955 @tab @code{qSupported}
22956 @tab Remote communications parameters
22957
22958 @item @code{catch-syscalls}
22959 @tab @code{QCatchSyscalls}
22960 @tab @code{catch syscall}
22961
22962 @item @code{pass-signals}
22963 @tab @code{QPassSignals}
22964 @tab @code{handle @var{signal}}
22965
22966 @item @code{program-signals}
22967 @tab @code{QProgramSignals}
22968 @tab @code{handle @var{signal}}
22969
22970 @item @code{hostio-close-packet}
22971 @tab @code{vFile:close}
22972 @tab @code{remote get}, @code{remote put}
22973
22974 @item @code{hostio-open-packet}
22975 @tab @code{vFile:open}
22976 @tab @code{remote get}, @code{remote put}
22977
22978 @item @code{hostio-pread-packet}
22979 @tab @code{vFile:pread}
22980 @tab @code{remote get}, @code{remote put}
22981
22982 @item @code{hostio-pwrite-packet}
22983 @tab @code{vFile:pwrite}
22984 @tab @code{remote get}, @code{remote put}
22985
22986 @item @code{hostio-unlink-packet}
22987 @tab @code{vFile:unlink}
22988 @tab @code{remote delete}
22989
22990 @item @code{hostio-readlink-packet}
22991 @tab @code{vFile:readlink}
22992 @tab Host I/O
22993
22994 @item @code{hostio-fstat-packet}
22995 @tab @code{vFile:fstat}
22996 @tab Host I/O
22997
22998 @item @code{hostio-setfs-packet}
22999 @tab @code{vFile:setfs}
23000 @tab Host I/O
23001
23002 @item @code{noack-packet}
23003 @tab @code{QStartNoAckMode}
23004 @tab Packet acknowledgment
23005
23006 @item @code{osdata}
23007 @tab @code{qXfer:osdata:read}
23008 @tab @code{info os}
23009
23010 @item @code{query-attached}
23011 @tab @code{qAttached}
23012 @tab Querying remote process attach state.
23013
23014 @item @code{trace-buffer-size}
23015 @tab @code{QTBuffer:size}
23016 @tab @code{set trace-buffer-size}
23017
23018 @item @code{trace-status}
23019 @tab @code{qTStatus}
23020 @tab @code{tstatus}
23021
23022 @item @code{traceframe-info}
23023 @tab @code{qXfer:traceframe-info:read}
23024 @tab Traceframe info
23025
23026 @item @code{install-in-trace}
23027 @tab @code{InstallInTrace}
23028 @tab Install tracepoint in tracing
23029
23030 @item @code{disable-randomization}
23031 @tab @code{QDisableRandomization}
23032 @tab @code{set disable-randomization}
23033
23034 @item @code{startup-with-shell}
23035 @tab @code{QStartupWithShell}
23036 @tab @code{set startup-with-shell}
23037
23038 @item @code{environment-hex-encoded}
23039 @tab @code{QEnvironmentHexEncoded}
23040 @tab @code{set environment}
23041
23042 @item @code{environment-unset}
23043 @tab @code{QEnvironmentUnset}
23044 @tab @code{unset environment}
23045
23046 @item @code{environment-reset}
23047 @tab @code{QEnvironmentReset}
23048 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23049
23050 @item @code{set-working-dir}
23051 @tab @code{QSetWorkingDir}
23052 @tab @code{set cwd}
23053
23054 @item @code{conditional-breakpoints-packet}
23055 @tab @code{Z0 and Z1}
23056 @tab @code{Support for target-side breakpoint condition evaluation}
23057
23058 @item @code{multiprocess-extensions}
23059 @tab @code{multiprocess extensions}
23060 @tab Debug multiple processes and remote process PID awareness
23061
23062 @item @code{swbreak-feature}
23063 @tab @code{swbreak stop reason}
23064 @tab @code{break}
23065
23066 @item @code{hwbreak-feature}
23067 @tab @code{hwbreak stop reason}
23068 @tab @code{hbreak}
23069
23070 @item @code{fork-event-feature}
23071 @tab @code{fork stop reason}
23072 @tab @code{fork}
23073
23074 @item @code{vfork-event-feature}
23075 @tab @code{vfork stop reason}
23076 @tab @code{vfork}
23077
23078 @item @code{exec-event-feature}
23079 @tab @code{exec stop reason}
23080 @tab @code{exec}
23081
23082 @item @code{thread-events}
23083 @tab @code{QThreadEvents}
23084 @tab Tracking thread lifetime.
23085
23086 @item @code{no-resumed-stop-reply}
23087 @tab @code{no resumed thread left stop reply}
23088 @tab Tracking thread lifetime.
23089
23090 @end multitable
23091
23092 @node Remote Stub
23093 @section Implementing a Remote Stub
23094
23095 @cindex debugging stub, example
23096 @cindex remote stub, example
23097 @cindex stub example, remote debugging
23098 The stub files provided with @value{GDBN} implement the target side of the
23099 communication protocol, and the @value{GDBN} side is implemented in the
23100 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23101 these subroutines to communicate, and ignore the details. (If you're
23102 implementing your own stub file, you can still ignore the details: start
23103 with one of the existing stub files. @file{sparc-stub.c} is the best
23104 organized, and therefore the easiest to read.)
23105
23106 @cindex remote serial debugging, overview
23107 To debug a program running on another machine (the debugging
23108 @dfn{target} machine), you must first arrange for all the usual
23109 prerequisites for the program to run by itself. For example, for a C
23110 program, you need:
23111
23112 @enumerate
23113 @item
23114 A startup routine to set up the C runtime environment; these usually
23115 have a name like @file{crt0}. The startup routine may be supplied by
23116 your hardware supplier, or you may have to write your own.
23117
23118 @item
23119 A C subroutine library to support your program's
23120 subroutine calls, notably managing input and output.
23121
23122 @item
23123 A way of getting your program to the other machine---for example, a
23124 download program. These are often supplied by the hardware
23125 manufacturer, but you may have to write your own from hardware
23126 documentation.
23127 @end enumerate
23128
23129 The next step is to arrange for your program to use a serial port to
23130 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23131 machine). In general terms, the scheme looks like this:
23132
23133 @table @emph
23134 @item On the host,
23135 @value{GDBN} already understands how to use this protocol; when everything
23136 else is set up, you can simply use the @samp{target remote} command
23137 (@pxref{Targets,,Specifying a Debugging Target}).
23138
23139 @item On the target,
23140 you must link with your program a few special-purpose subroutines that
23141 implement the @value{GDBN} remote serial protocol. The file containing these
23142 subroutines is called a @dfn{debugging stub}.
23143
23144 On certain remote targets, you can use an auxiliary program
23145 @code{gdbserver} instead of linking a stub into your program.
23146 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23147 @end table
23148
23149 The debugging stub is specific to the architecture of the remote
23150 machine; for example, use @file{sparc-stub.c} to debug programs on
23151 @sc{sparc} boards.
23152
23153 @cindex remote serial stub list
23154 These working remote stubs are distributed with @value{GDBN}:
23155
23156 @table @code
23157
23158 @item i386-stub.c
23159 @cindex @file{i386-stub.c}
23160 @cindex Intel
23161 @cindex i386
23162 For Intel 386 and compatible architectures.
23163
23164 @item m68k-stub.c
23165 @cindex @file{m68k-stub.c}
23166 @cindex Motorola 680x0
23167 @cindex m680x0
23168 For Motorola 680x0 architectures.
23169
23170 @item sh-stub.c
23171 @cindex @file{sh-stub.c}
23172 @cindex Renesas
23173 @cindex SH
23174 For Renesas SH architectures.
23175
23176 @item sparc-stub.c
23177 @cindex @file{sparc-stub.c}
23178 @cindex Sparc
23179 For @sc{sparc} architectures.
23180
23181 @item sparcl-stub.c
23182 @cindex @file{sparcl-stub.c}
23183 @cindex Fujitsu
23184 @cindex SparcLite
23185 For Fujitsu @sc{sparclite} architectures.
23186
23187 @end table
23188
23189 The @file{README} file in the @value{GDBN} distribution may list other
23190 recently added stubs.
23191
23192 @menu
23193 * Stub Contents:: What the stub can do for you
23194 * Bootstrapping:: What you must do for the stub
23195 * Debug Session:: Putting it all together
23196 @end menu
23197
23198 @node Stub Contents
23199 @subsection What the Stub Can Do for You
23200
23201 @cindex remote serial stub
23202 The debugging stub for your architecture supplies these three
23203 subroutines:
23204
23205 @table @code
23206 @item set_debug_traps
23207 @findex set_debug_traps
23208 @cindex remote serial stub, initialization
23209 This routine arranges for @code{handle_exception} to run when your
23210 program stops. You must call this subroutine explicitly in your
23211 program's startup code.
23212
23213 @item handle_exception
23214 @findex handle_exception
23215 @cindex remote serial stub, main routine
23216 This is the central workhorse, but your program never calls it
23217 explicitly---the setup code arranges for @code{handle_exception} to
23218 run when a trap is triggered.
23219
23220 @code{handle_exception} takes control when your program stops during
23221 execution (for example, on a breakpoint), and mediates communications
23222 with @value{GDBN} on the host machine. This is where the communications
23223 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23224 representative on the target machine. It begins by sending summary
23225 information on the state of your program, then continues to execute,
23226 retrieving and transmitting any information @value{GDBN} needs, until you
23227 execute a @value{GDBN} command that makes your program resume; at that point,
23228 @code{handle_exception} returns control to your own code on the target
23229 machine.
23230
23231 @item breakpoint
23232 @cindex @code{breakpoint} subroutine, remote
23233 Use this auxiliary subroutine to make your program contain a
23234 breakpoint. Depending on the particular situation, this may be the only
23235 way for @value{GDBN} to get control. For instance, if your target
23236 machine has some sort of interrupt button, you won't need to call this;
23237 pressing the interrupt button transfers control to
23238 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23239 simply receiving characters on the serial port may also trigger a trap;
23240 again, in that situation, you don't need to call @code{breakpoint} from
23241 your own program---simply running @samp{target remote} from the host
23242 @value{GDBN} session gets control.
23243
23244 Call @code{breakpoint} if none of these is true, or if you simply want
23245 to make certain your program stops at a predetermined point for the
23246 start of your debugging session.
23247 @end table
23248
23249 @node Bootstrapping
23250 @subsection What You Must Do for the Stub
23251
23252 @cindex remote stub, support routines
23253 The debugging stubs that come with @value{GDBN} are set up for a particular
23254 chip architecture, but they have no information about the rest of your
23255 debugging target machine.
23256
23257 First of all you need to tell the stub how to communicate with the
23258 serial port.
23259
23260 @table @code
23261 @item int getDebugChar()
23262 @findex getDebugChar
23263 Write this subroutine to read a single character from the serial port.
23264 It may be identical to @code{getchar} for your target system; a
23265 different name is used to allow you to distinguish the two if you wish.
23266
23267 @item void putDebugChar(int)
23268 @findex putDebugChar
23269 Write this subroutine to write a single character to the serial port.
23270 It may be identical to @code{putchar} for your target system; a
23271 different name is used to allow you to distinguish the two if you wish.
23272 @end table
23273
23274 @cindex control C, and remote debugging
23275 @cindex interrupting remote targets
23276 If you want @value{GDBN} to be able to stop your program while it is
23277 running, you need to use an interrupt-driven serial driver, and arrange
23278 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23279 character). That is the character which @value{GDBN} uses to tell the
23280 remote system to stop.
23281
23282 Getting the debugging target to return the proper status to @value{GDBN}
23283 probably requires changes to the standard stub; one quick and dirty way
23284 is to just execute a breakpoint instruction (the ``dirty'' part is that
23285 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23286
23287 Other routines you need to supply are:
23288
23289 @table @code
23290 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23291 @findex exceptionHandler
23292 Write this function to install @var{exception_address} in the exception
23293 handling tables. You need to do this because the stub does not have any
23294 way of knowing what the exception handling tables on your target system
23295 are like (for example, the processor's table might be in @sc{rom},
23296 containing entries which point to a table in @sc{ram}).
23297 The @var{exception_number} specifies the exception which should be changed;
23298 its meaning is architecture-dependent (for example, different numbers
23299 might represent divide by zero, misaligned access, etc). When this
23300 exception occurs, control should be transferred directly to
23301 @var{exception_address}, and the processor state (stack, registers,
23302 and so on) should be just as it is when a processor exception occurs. So if
23303 you want to use a jump instruction to reach @var{exception_address}, it
23304 should be a simple jump, not a jump to subroutine.
23305
23306 For the 386, @var{exception_address} should be installed as an interrupt
23307 gate so that interrupts are masked while the handler runs. The gate
23308 should be at privilege level 0 (the most privileged level). The
23309 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23310 help from @code{exceptionHandler}.
23311
23312 @item void flush_i_cache()
23313 @findex flush_i_cache
23314 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23315 instruction cache, if any, on your target machine. If there is no
23316 instruction cache, this subroutine may be a no-op.
23317
23318 On target machines that have instruction caches, @value{GDBN} requires this
23319 function to make certain that the state of your program is stable.
23320 @end table
23321
23322 @noindent
23323 You must also make sure this library routine is available:
23324
23325 @table @code
23326 @item void *memset(void *, int, int)
23327 @findex memset
23328 This is the standard library function @code{memset} that sets an area of
23329 memory to a known value. If you have one of the free versions of
23330 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23331 either obtain it from your hardware manufacturer, or write your own.
23332 @end table
23333
23334 If you do not use the GNU C compiler, you may need other standard
23335 library subroutines as well; this varies from one stub to another,
23336 but in general the stubs are likely to use any of the common library
23337 subroutines which @code{@value{NGCC}} generates as inline code.
23338
23339
23340 @node Debug Session
23341 @subsection Putting it All Together
23342
23343 @cindex remote serial debugging summary
23344 In summary, when your program is ready to debug, you must follow these
23345 steps.
23346
23347 @enumerate
23348 @item
23349 Make sure you have defined the supporting low-level routines
23350 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23351 @display
23352 @code{getDebugChar}, @code{putDebugChar},
23353 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23354 @end display
23355
23356 @item
23357 Insert these lines in your program's startup code, before the main
23358 procedure is called:
23359
23360 @smallexample
23361 set_debug_traps();
23362 breakpoint();
23363 @end smallexample
23364
23365 On some machines, when a breakpoint trap is raised, the hardware
23366 automatically makes the PC point to the instruction after the
23367 breakpoint. If your machine doesn't do that, you may need to adjust
23368 @code{handle_exception} to arrange for it to return to the instruction
23369 after the breakpoint on this first invocation, so that your program
23370 doesn't keep hitting the initial breakpoint instead of making
23371 progress.
23372
23373 @item
23374 For the 680x0 stub only, you need to provide a variable called
23375 @code{exceptionHook}. Normally you just use:
23376
23377 @smallexample
23378 void (*exceptionHook)() = 0;
23379 @end smallexample
23380
23381 @noindent
23382 but if before calling @code{set_debug_traps}, you set it to point to a
23383 function in your program, that function is called when
23384 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23385 error). The function indicated by @code{exceptionHook} is called with
23386 one parameter: an @code{int} which is the exception number.
23387
23388 @item
23389 Compile and link together: your program, the @value{GDBN} debugging stub for
23390 your target architecture, and the supporting subroutines.
23391
23392 @item
23393 Make sure you have a serial connection between your target machine and
23394 the @value{GDBN} host, and identify the serial port on the host.
23395
23396 @item
23397 @c The "remote" target now provides a `load' command, so we should
23398 @c document that. FIXME.
23399 Download your program to your target machine (or get it there by
23400 whatever means the manufacturer provides), and start it.
23401
23402 @item
23403 Start @value{GDBN} on the host, and connect to the target
23404 (@pxref{Connecting,,Connecting to a Remote Target}).
23405
23406 @end enumerate
23407
23408 @node Configurations
23409 @chapter Configuration-Specific Information
23410
23411 While nearly all @value{GDBN} commands are available for all native and
23412 cross versions of the debugger, there are some exceptions. This chapter
23413 describes things that are only available in certain configurations.
23414
23415 There are three major categories of configurations: native
23416 configurations, where the host and target are the same, embedded
23417 operating system configurations, which are usually the same for several
23418 different processor architectures, and bare embedded processors, which
23419 are quite different from each other.
23420
23421 @menu
23422 * Native::
23423 * Embedded OS::
23424 * Embedded Processors::
23425 * Architectures::
23426 @end menu
23427
23428 @node Native
23429 @section Native
23430
23431 This section describes details specific to particular native
23432 configurations.
23433
23434 @menu
23435 * BSD libkvm Interface:: Debugging BSD kernel memory images
23436 * Process Information:: Process information
23437 * DJGPP Native:: Features specific to the DJGPP port
23438 * Cygwin Native:: Features specific to the Cygwin port
23439 * Hurd Native:: Features specific to @sc{gnu} Hurd
23440 * Darwin:: Features specific to Darwin
23441 * FreeBSD:: Features specific to FreeBSD
23442 @end menu
23443
23444 @node BSD libkvm Interface
23445 @subsection BSD libkvm Interface
23446
23447 @cindex libkvm
23448 @cindex kernel memory image
23449 @cindex kernel crash dump
23450
23451 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23452 interface that provides a uniform interface for accessing kernel virtual
23453 memory images, including live systems and crash dumps. @value{GDBN}
23454 uses this interface to allow you to debug live kernels and kernel crash
23455 dumps on many native BSD configurations. This is implemented as a
23456 special @code{kvm} debugging target. For debugging a live system, load
23457 the currently running kernel into @value{GDBN} and connect to the
23458 @code{kvm} target:
23459
23460 @smallexample
23461 (@value{GDBP}) @b{target kvm}
23462 @end smallexample
23463
23464 For debugging crash dumps, provide the file name of the crash dump as an
23465 argument:
23466
23467 @smallexample
23468 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23469 @end smallexample
23470
23471 Once connected to the @code{kvm} target, the following commands are
23472 available:
23473
23474 @table @code
23475 @kindex kvm
23476 @item kvm pcb
23477 Set current context from the @dfn{Process Control Block} (PCB) address.
23478
23479 @item kvm proc
23480 Set current context from proc address. This command isn't available on
23481 modern FreeBSD systems.
23482 @end table
23483
23484 @node Process Information
23485 @subsection Process Information
23486 @cindex /proc
23487 @cindex examine process image
23488 @cindex process info via @file{/proc}
23489
23490 Some operating systems provide interfaces to fetch additional
23491 information about running processes beyond memory and per-thread
23492 register state. If @value{GDBN} is configured for an operating system
23493 with a supported interface, the command @code{info proc} is available
23494 to report information about the process running your program, or about
23495 any process running on your system.
23496
23497 One supported interface is a facility called @samp{/proc} that can be
23498 used to examine the image of a running process using file-system
23499 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23500 systems.
23501
23502 On FreeBSD and NetBSD systems, system control nodes are used to query
23503 process information.
23504
23505 In addition, some systems may provide additional process information
23506 in core files. Note that a core file may include a subset of the
23507 information available from a live process. Process information is
23508 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23509 systems.
23510
23511 @table @code
23512 @kindex info proc
23513 @cindex process ID
23514 @item info proc
23515 @itemx info proc @var{process-id}
23516 Summarize available information about a process. If a
23517 process ID is specified by @var{process-id}, display information about
23518 that process; otherwise display information about the program being
23519 debugged. The summary includes the debugged process ID, the command
23520 line used to invoke it, its current working directory, and its
23521 executable file's absolute file name.
23522
23523 On some systems, @var{process-id} can be of the form
23524 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23525 within a process. If the optional @var{pid} part is missing, it means
23526 a thread from the process being debugged (the leading @samp{/} still
23527 needs to be present, or else @value{GDBN} will interpret the number as
23528 a process ID rather than a thread ID).
23529
23530 @item info proc cmdline
23531 @cindex info proc cmdline
23532 Show the original command line of the process. This command is
23533 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23534
23535 @item info proc cwd
23536 @cindex info proc cwd
23537 Show the current working directory of the process. This command is
23538 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23539
23540 @item info proc exe
23541 @cindex info proc exe
23542 Show the name of executable of the process. This command is supported
23543 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23544
23545 @item info proc files
23546 @cindex info proc files
23547 Show the file descriptors open by the process. For each open file
23548 descriptor, @value{GDBN} shows its number, type (file, directory,
23549 character device, socket), file pointer offset, and the name of the
23550 resource open on the descriptor. The resource name can be a file name
23551 (for files, directories, and devices) or a protocol followed by socket
23552 address (for network connections). This command is supported on
23553 FreeBSD.
23554
23555 This example shows the open file descriptors for a process using a
23556 tty for standard input and output as well as two network sockets:
23557
23558 @smallexample
23559 (gdb) info proc files 22136
23560 process 22136
23561 Open files:
23562
23563 FD Type Offset Flags Name
23564 text file - r-------- /usr/bin/ssh
23565 ctty chr - rw------- /dev/pts/20
23566 cwd dir - r-------- /usr/home/john
23567 root dir - r-------- /
23568 0 chr 0x32933a4 rw------- /dev/pts/20
23569 1 chr 0x32933a4 rw------- /dev/pts/20
23570 2 chr 0x32933a4 rw------- /dev/pts/20
23571 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23572 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23573 @end smallexample
23574
23575 @item info proc mappings
23576 @cindex memory address space mappings
23577 Report the memory address space ranges accessible in a process. On
23578 Solaris, FreeBSD and NetBSD systems, each memory range includes information
23579 on whether the process has read, write, or execute access rights to each
23580 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23581 includes the object file which is mapped to that range.
23582
23583 @item info proc stat
23584 @itemx info proc status
23585 @cindex process detailed status information
23586 Show additional process-related information, including the user ID and
23587 group ID; virtual memory usage; the signals that are pending, blocked,
23588 and ignored; its TTY; its consumption of system and user time; its
23589 stack size; its @samp{nice} value; etc. These commands are supported
23590 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23591
23592 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23593 information (type @kbd{man 5 proc} from your shell prompt).
23594
23595 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23596 @code{info proc status}.
23597
23598 @item info proc all
23599 Show all the information about the process described under all of the
23600 above @code{info proc} subcommands.
23601
23602 @ignore
23603 @comment These sub-options of 'info proc' were not included when
23604 @comment procfs.c was re-written. Keep their descriptions around
23605 @comment against the day when someone finds the time to put them back in.
23606 @kindex info proc times
23607 @item info proc times
23608 Starting time, user CPU time, and system CPU time for your program and
23609 its children.
23610
23611 @kindex info proc id
23612 @item info proc id
23613 Report on the process IDs related to your program: its own process ID,
23614 the ID of its parent, the process group ID, and the session ID.
23615 @end ignore
23616
23617 @item set procfs-trace
23618 @kindex set procfs-trace
23619 @cindex @code{procfs} API calls
23620 This command enables and disables tracing of @code{procfs} API calls.
23621
23622 @item show procfs-trace
23623 @kindex show procfs-trace
23624 Show the current state of @code{procfs} API call tracing.
23625
23626 @item set procfs-file @var{file}
23627 @kindex set procfs-file
23628 Tell @value{GDBN} to write @code{procfs} API trace to the named
23629 @var{file}. @value{GDBN} appends the trace info to the previous
23630 contents of the file. The default is to display the trace on the
23631 standard output.
23632
23633 @item show procfs-file
23634 @kindex show procfs-file
23635 Show the file to which @code{procfs} API trace is written.
23636
23637 @item proc-trace-entry
23638 @itemx proc-trace-exit
23639 @itemx proc-untrace-entry
23640 @itemx proc-untrace-exit
23641 @kindex proc-trace-entry
23642 @kindex proc-trace-exit
23643 @kindex proc-untrace-entry
23644 @kindex proc-untrace-exit
23645 These commands enable and disable tracing of entries into and exits
23646 from the @code{syscall} interface.
23647
23648 @item info pidlist
23649 @kindex info pidlist
23650 @cindex process list, QNX Neutrino
23651 For QNX Neutrino only, this command displays the list of all the
23652 processes and all the threads within each process.
23653
23654 @item info meminfo
23655 @kindex info meminfo
23656 @cindex mapinfo list, QNX Neutrino
23657 For QNX Neutrino only, this command displays the list of all mapinfos.
23658 @end table
23659
23660 @node DJGPP Native
23661 @subsection Features for Debugging @sc{djgpp} Programs
23662 @cindex @sc{djgpp} debugging
23663 @cindex native @sc{djgpp} debugging
23664 @cindex MS-DOS-specific commands
23665
23666 @cindex DPMI
23667 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23668 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23669 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23670 top of real-mode DOS systems and their emulations.
23671
23672 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
23673 defines a few commands specific to the @sc{djgpp} port. This
23674 subsection describes those commands.
23675
23676 @table @code
23677 @kindex info dos
23678 @item info dos
23679 This is a prefix of @sc{djgpp}-specific commands which print
23680 information about the target system and important OS structures.
23681
23682 @kindex sysinfo
23683 @cindex MS-DOS system info
23684 @cindex free memory information (MS-DOS)
23685 @item info dos sysinfo
23686 This command displays assorted information about the underlying
23687 platform: the CPU type and features, the OS version and flavor, the
23688 DPMI version, and the available conventional and DPMI memory.
23689
23690 @cindex GDT
23691 @cindex LDT
23692 @cindex IDT
23693 @cindex segment descriptor tables
23694 @cindex descriptor tables display
23695 @item info dos gdt
23696 @itemx info dos ldt
23697 @itemx info dos idt
23698 These 3 commands display entries from, respectively, Global, Local,
23699 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23700 tables are data structures which store a descriptor for each segment
23701 that is currently in use. The segment's selector is an index into a
23702 descriptor table; the table entry for that index holds the
23703 descriptor's base address and limit, and its attributes and access
23704 rights.
23705
23706 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23707 segment (used for both data and the stack), and a DOS segment (which
23708 allows access to DOS/BIOS data structures and absolute addresses in
23709 conventional memory). However, the DPMI host will usually define
23710 additional segments in order to support the DPMI environment.
23711
23712 @cindex garbled pointers
23713 These commands allow to display entries from the descriptor tables.
23714 Without an argument, all entries from the specified table are
23715 displayed. An argument, which should be an integer expression, means
23716 display a single entry whose index is given by the argument. For
23717 example, here's a convenient way to display information about the
23718 debugged program's data segment:
23719
23720 @smallexample
23721 @exdent @code{(@value{GDBP}) info dos ldt $ds}
23722 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23723 @end smallexample
23724
23725 @noindent
23726 This comes in handy when you want to see whether a pointer is outside
23727 the data segment's limit (i.e.@: @dfn{garbled}).
23728
23729 @cindex page tables display (MS-DOS)
23730 @item info dos pde
23731 @itemx info dos pte
23732 These two commands display entries from, respectively, the Page
23733 Directory and the Page Tables. Page Directories and Page Tables are
23734 data structures which control how virtual memory addresses are mapped
23735 into physical addresses. A Page Table includes an entry for every
23736 page of memory that is mapped into the program's address space; there
23737 may be several Page Tables, each one holding up to 4096 entries. A
23738 Page Directory has up to 4096 entries, one each for every Page Table
23739 that is currently in use.
23740
23741 Without an argument, @kbd{info dos pde} displays the entire Page
23742 Directory, and @kbd{info dos pte} displays all the entries in all of
23743 the Page Tables. An argument, an integer expression, given to the
23744 @kbd{info dos pde} command means display only that entry from the Page
23745 Directory table. An argument given to the @kbd{info dos pte} command
23746 means display entries from a single Page Table, the one pointed to by
23747 the specified entry in the Page Directory.
23748
23749 @cindex direct memory access (DMA) on MS-DOS
23750 These commands are useful when your program uses @dfn{DMA} (Direct
23751 Memory Access), which needs physical addresses to program the DMA
23752 controller.
23753
23754 These commands are supported only with some DPMI servers.
23755
23756 @cindex physical address from linear address
23757 @item info dos address-pte @var{addr}
23758 This command displays the Page Table entry for a specified linear
23759 address. The argument @var{addr} is a linear address which should
23760 already have the appropriate segment's base address added to it,
23761 because this command accepts addresses which may belong to @emph{any}
23762 segment. For example, here's how to display the Page Table entry for
23763 the page where a variable @code{i} is stored:
23764
23765 @smallexample
23766 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23767 @exdent @code{Page Table entry for address 0x11a00d30:}
23768 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
23769 @end smallexample
23770
23771 @noindent
23772 This says that @code{i} is stored at offset @code{0xd30} from the page
23773 whose physical base address is @code{0x02698000}, and shows all the
23774 attributes of that page.
23775
23776 Note that you must cast the addresses of variables to a @code{char *},
23777 since otherwise the value of @code{__djgpp_base_address}, the base
23778 address of all variables and functions in a @sc{djgpp} program, will
23779 be added using the rules of C pointer arithmetics: if @code{i} is
23780 declared an @code{int}, @value{GDBN} will add 4 times the value of
23781 @code{__djgpp_base_address} to the address of @code{i}.
23782
23783 Here's another example, it displays the Page Table entry for the
23784 transfer buffer:
23785
23786 @smallexample
23787 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23788 @exdent @code{Page Table entry for address 0x29110:}
23789 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23790 @end smallexample
23791
23792 @noindent
23793 (The @code{+ 3} offset is because the transfer buffer's address is the
23794 3rd member of the @code{_go32_info_block} structure.) The output
23795 clearly shows that this DPMI server maps the addresses in conventional
23796 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23797 linear (@code{0x29110}) addresses are identical.
23798
23799 This command is supported only with some DPMI servers.
23800 @end table
23801
23802 @cindex DOS serial data link, remote debugging
23803 In addition to native debugging, the DJGPP port supports remote
23804 debugging via a serial data link. The following commands are specific
23805 to remote serial debugging in the DJGPP port of @value{GDBN}.
23806
23807 @table @code
23808 @kindex set com1base
23809 @kindex set com1irq
23810 @kindex set com2base
23811 @kindex set com2irq
23812 @kindex set com3base
23813 @kindex set com3irq
23814 @kindex set com4base
23815 @kindex set com4irq
23816 @item set com1base @var{addr}
23817 This command sets the base I/O port address of the @file{COM1} serial
23818 port.
23819
23820 @item set com1irq @var{irq}
23821 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23822 for the @file{COM1} serial port.
23823
23824 There are similar commands @samp{set com2base}, @samp{set com3irq},
23825 etc.@: for setting the port address and the @code{IRQ} lines for the
23826 other 3 COM ports.
23827
23828 @kindex show com1base
23829 @kindex show com1irq
23830 @kindex show com2base
23831 @kindex show com2irq
23832 @kindex show com3base
23833 @kindex show com3irq
23834 @kindex show com4base
23835 @kindex show com4irq
23836 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23837 display the current settings of the base address and the @code{IRQ}
23838 lines used by the COM ports.
23839
23840 @item info serial
23841 @kindex info serial
23842 @cindex DOS serial port status
23843 This command prints the status of the 4 DOS serial ports. For each
23844 port, it prints whether it's active or not, its I/O base address and
23845 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23846 counts of various errors encountered so far.
23847 @end table
23848
23849
23850 @node Cygwin Native
23851 @subsection Features for Debugging MS Windows PE Executables
23852 @cindex MS Windows debugging
23853 @cindex native Cygwin debugging
23854 @cindex Cygwin-specific commands
23855
23856 @value{GDBN} supports native debugging of MS Windows programs, including
23857 DLLs with and without symbolic debugging information.
23858
23859 @cindex Ctrl-BREAK, MS-Windows
23860 @cindex interrupt debuggee on MS-Windows
23861 MS-Windows programs that call @code{SetConsoleMode} to switch off the
23862 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23863 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23864 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23865 sequence, which can be used to interrupt the debuggee even if it
23866 ignores @kbd{C-c}.
23867
23868 There are various additional Cygwin-specific commands, described in
23869 this section. Working with DLLs that have no debugging symbols is
23870 described in @ref{Non-debug DLL Symbols}.
23871
23872 @table @code
23873 @kindex info w32
23874 @item info w32
23875 This is a prefix of MS Windows-specific commands which print
23876 information about the target system and important OS structures.
23877
23878 @item info w32 selector
23879 This command displays information returned by
23880 the Win32 API @code{GetThreadSelectorEntry} function.
23881 It takes an optional argument that is evaluated to
23882 a long value to give the information about this given selector.
23883 Without argument, this command displays information
23884 about the six segment registers.
23885
23886 @item info w32 thread-information-block
23887 This command displays thread specific information stored in the
23888 Thread Information Block (readable on the X86 CPU family using @code{$fs}
23889 selector for 32-bit programs and @code{$gs} for 64-bit programs).
23890
23891 @kindex signal-event
23892 @item signal-event @var{id}
23893 This command signals an event with user-provided @var{id}. Used to resume
23894 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23895
23896 To use it, create or edit the following keys in
23897 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23898 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23899 (for x86_64 versions):
23900
23901 @itemize @minus
23902 @item
23903 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
23904 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23905 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
23906
23907 The first @code{%ld} will be replaced by the process ID of the
23908 crashing process, the second @code{%ld} will be replaced by the ID of
23909 the event that blocks the crashing process, waiting for @value{GDBN}
23910 to attach.
23911
23912 @item
23913 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23914 make the system run debugger specified by the Debugger key
23915 automatically, @code{0} will cause a dialog box with ``OK'' and
23916 ``Cancel'' buttons to appear, which allows the user to either
23917 terminate the crashing process (OK) or debug it (Cancel).
23918 @end itemize
23919
23920 @kindex set cygwin-exceptions
23921 @cindex debugging the Cygwin DLL
23922 @cindex Cygwin DLL, debugging
23923 @item set cygwin-exceptions @var{mode}
23924 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23925 happen inside the Cygwin DLL. If @var{mode} is @code{off},
23926 @value{GDBN} will delay recognition of exceptions, and may ignore some
23927 exceptions which seem to be caused by internal Cygwin DLL
23928 ``bookkeeping''. This option is meant primarily for debugging the
23929 Cygwin DLL itself; the default value is @code{off} to avoid annoying
23930 @value{GDBN} users with false @code{SIGSEGV} signals.
23931
23932 @kindex show cygwin-exceptions
23933 @item show cygwin-exceptions
23934 Displays whether @value{GDBN} will break on exceptions that happen
23935 inside the Cygwin DLL itself.
23936
23937 @kindex set new-console
23938 @item set new-console @var{mode}
23939 If @var{mode} is @code{on} the debuggee will
23940 be started in a new console on next start.
23941 If @var{mode} is @code{off}, the debuggee will
23942 be started in the same console as the debugger.
23943
23944 @kindex show new-console
23945 @item show new-console
23946 Displays whether a new console is used
23947 when the debuggee is started.
23948
23949 @kindex set new-group
23950 @item set new-group @var{mode}
23951 This boolean value controls whether the debuggee should
23952 start a new group or stay in the same group as the debugger.
23953 This affects the way the Windows OS handles
23954 @samp{Ctrl-C}.
23955
23956 @kindex show new-group
23957 @item show new-group
23958 Displays current value of new-group boolean.
23959
23960 @kindex set debugevents
23961 @item set debugevents
23962 This boolean value adds debug output concerning kernel events related
23963 to the debuggee seen by the debugger. This includes events that
23964 signal thread and process creation and exit, DLL loading and
23965 unloading, console interrupts, and debugging messages produced by the
23966 Windows @code{OutputDebugString} API call.
23967
23968 @kindex set debugexec
23969 @item set debugexec
23970 This boolean value adds debug output concerning execute events
23971 (such as resume thread) seen by the debugger.
23972
23973 @kindex set debugexceptions
23974 @item set debugexceptions
23975 This boolean value adds debug output concerning exceptions in the
23976 debuggee seen by the debugger.
23977
23978 @kindex set debugmemory
23979 @item set debugmemory
23980 This boolean value adds debug output concerning debuggee memory reads
23981 and writes by the debugger.
23982
23983 @kindex set shell
23984 @item set shell
23985 This boolean values specifies whether the debuggee is called
23986 via a shell or directly (default value is on).
23987
23988 @kindex show shell
23989 @item show shell
23990 Displays if the debuggee will be started with a shell.
23991
23992 @end table
23993
23994 @menu
23995 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
23996 @end menu
23997
23998 @node Non-debug DLL Symbols
23999 @subsubsection Support for DLLs without Debugging Symbols
24000 @cindex DLLs with no debugging symbols
24001 @cindex Minimal symbols and DLLs
24002
24003 Very often on windows, some of the DLLs that your program relies on do
24004 not include symbolic debugging information (for example,
24005 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24006 symbols in a DLL, it relies on the minimal amount of symbolic
24007 information contained in the DLL's export table. This section
24008 describes working with such symbols, known internally to @value{GDBN} as
24009 ``minimal symbols''.
24010
24011 Note that before the debugged program has started execution, no DLLs
24012 will have been loaded. The easiest way around this problem is simply to
24013 start the program --- either by setting a breakpoint or letting the
24014 program run once to completion.
24015
24016 @subsubsection DLL Name Prefixes
24017
24018 In keeping with the naming conventions used by the Microsoft debugging
24019 tools, DLL export symbols are made available with a prefix based on the
24020 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24021 also entered into the symbol table, so @code{CreateFileA} is often
24022 sufficient. In some cases there will be name clashes within a program
24023 (particularly if the executable itself includes full debugging symbols)
24024 necessitating the use of the fully qualified name when referring to the
24025 contents of the DLL. Use single-quotes around the name to avoid the
24026 exclamation mark (``!'') being interpreted as a language operator.
24027
24028 Note that the internal name of the DLL may be all upper-case, even
24029 though the file name of the DLL is lower-case, or vice-versa. Since
24030 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24031 some confusion. If in doubt, try the @code{info functions} and
24032 @code{info variables} commands or even @code{maint print msymbols}
24033 (@pxref{Symbols}). Here's an example:
24034
24035 @smallexample
24036 (@value{GDBP}) info function CreateFileA
24037 All functions matching regular expression "CreateFileA":
24038
24039 Non-debugging symbols:
24040 0x77e885f4 CreateFileA
24041 0x77e885f4 KERNEL32!CreateFileA
24042 @end smallexample
24043
24044 @smallexample
24045 (@value{GDBP}) info function !
24046 All functions matching regular expression "!":
24047
24048 Non-debugging symbols:
24049 0x6100114c cygwin1!__assert
24050 0x61004034 cygwin1!_dll_crt0@@0
24051 0x61004240 cygwin1!dll_crt0(per_process *)
24052 [etc...]
24053 @end smallexample
24054
24055 @subsubsection Working with Minimal Symbols
24056
24057 Symbols extracted from a DLL's export table do not contain very much
24058 type information. All that @value{GDBN} can do is guess whether a symbol
24059 refers to a function or variable depending on the linker section that
24060 contains the symbol. Also note that the actual contents of the memory
24061 contained in a DLL are not available unless the program is running. This
24062 means that you cannot examine the contents of a variable or disassemble
24063 a function within a DLL without a running program.
24064
24065 Variables are generally treated as pointers and dereferenced
24066 automatically. For this reason, it is often necessary to prefix a
24067 variable name with the address-of operator (``&'') and provide explicit
24068 type information in the command. Here's an example of the type of
24069 problem:
24070
24071 @smallexample
24072 (@value{GDBP}) print 'cygwin1!__argv'
24073 'cygwin1!__argv' has unknown type; cast it to its declared type
24074 @end smallexample
24075
24076 @smallexample
24077 (@value{GDBP}) x 'cygwin1!__argv'
24078 'cygwin1!__argv' has unknown type; cast it to its declared type
24079 @end smallexample
24080
24081 And two possible solutions:
24082
24083 @smallexample
24084 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24085 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24086 @end smallexample
24087
24088 @smallexample
24089 (@value{GDBP}) x/2x &'cygwin1!__argv'
24090 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24091 (@value{GDBP}) x/x 0x10021608
24092 0x10021608: 0x0022fd98
24093 (@value{GDBP}) x/s 0x0022fd98
24094 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24095 @end smallexample
24096
24097 Setting a break point within a DLL is possible even before the program
24098 starts execution. However, under these circumstances, @value{GDBN} can't
24099 examine the initial instructions of the function in order to skip the
24100 function's frame set-up code. You can work around this by using ``*&''
24101 to set the breakpoint at a raw memory address:
24102
24103 @smallexample
24104 (@value{GDBP}) break *&'python22!PyOS_Readline'
24105 Breakpoint 1 at 0x1e04eff0
24106 @end smallexample
24107
24108 The author of these extensions is not entirely convinced that setting a
24109 break point within a shared DLL like @file{kernel32.dll} is completely
24110 safe.
24111
24112 @node Hurd Native
24113 @subsection Commands Specific to @sc{gnu} Hurd Systems
24114 @cindex @sc{gnu} Hurd debugging
24115
24116 This subsection describes @value{GDBN} commands specific to the
24117 @sc{gnu} Hurd native debugging.
24118
24119 @table @code
24120 @item set signals
24121 @itemx set sigs
24122 @kindex set signals@r{, Hurd command}
24123 @kindex set sigs@r{, Hurd command}
24124 This command toggles the state of inferior signal interception by
24125 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24126 affected by this command. @code{sigs} is a shorthand alias for
24127 @code{signals}.
24128
24129 @item show signals
24130 @itemx show sigs
24131 @kindex show signals@r{, Hurd command}
24132 @kindex show sigs@r{, Hurd command}
24133 Show the current state of intercepting inferior's signals.
24134
24135 @item set signal-thread
24136 @itemx set sigthread
24137 @kindex set signal-thread
24138 @kindex set sigthread
24139 This command tells @value{GDBN} which thread is the @code{libc} signal
24140 thread. That thread is run when a signal is delivered to a running
24141 process. @code{set sigthread} is the shorthand alias of @code{set
24142 signal-thread}.
24143
24144 @item show signal-thread
24145 @itemx show sigthread
24146 @kindex show signal-thread
24147 @kindex show sigthread
24148 These two commands show which thread will run when the inferior is
24149 delivered a signal.
24150
24151 @item set stopped
24152 @kindex set stopped@r{, Hurd command}
24153 This commands tells @value{GDBN} that the inferior process is stopped,
24154 as with the @code{SIGSTOP} signal. The stopped process can be
24155 continued by delivering a signal to it.
24156
24157 @item show stopped
24158 @kindex show stopped@r{, Hurd command}
24159 This command shows whether @value{GDBN} thinks the debuggee is
24160 stopped.
24161
24162 @item set exceptions
24163 @kindex set exceptions@r{, Hurd command}
24164 Use this command to turn off trapping of exceptions in the inferior.
24165 When exception trapping is off, neither breakpoints nor
24166 single-stepping will work. To restore the default, set exception
24167 trapping on.
24168
24169 @item show exceptions
24170 @kindex show exceptions@r{, Hurd command}
24171 Show the current state of trapping exceptions in the inferior.
24172
24173 @item set task pause
24174 @kindex set task@r{, Hurd commands}
24175 @cindex task attributes (@sc{gnu} Hurd)
24176 @cindex pause current task (@sc{gnu} Hurd)
24177 This command toggles task suspension when @value{GDBN} has control.
24178 Setting it to on takes effect immediately, and the task is suspended
24179 whenever @value{GDBN} gets control. Setting it to off will take
24180 effect the next time the inferior is continued. If this option is set
24181 to off, you can use @code{set thread default pause on} or @code{set
24182 thread pause on} (see below) to pause individual threads.
24183
24184 @item show task pause
24185 @kindex show task@r{, Hurd commands}
24186 Show the current state of task suspension.
24187
24188 @item set task detach-suspend-count
24189 @cindex task suspend count
24190 @cindex detach from task, @sc{gnu} Hurd
24191 This command sets the suspend count the task will be left with when
24192 @value{GDBN} detaches from it.
24193
24194 @item show task detach-suspend-count
24195 Show the suspend count the task will be left with when detaching.
24196
24197 @item set task exception-port
24198 @itemx set task excp
24199 @cindex task exception port, @sc{gnu} Hurd
24200 This command sets the task exception port to which @value{GDBN} will
24201 forward exceptions. The argument should be the value of the @dfn{send
24202 rights} of the task. @code{set task excp} is a shorthand alias.
24203
24204 @item set noninvasive
24205 @cindex noninvasive task options
24206 This command switches @value{GDBN} to a mode that is the least
24207 invasive as far as interfering with the inferior is concerned. This
24208 is the same as using @code{set task pause}, @code{set exceptions}, and
24209 @code{set signals} to values opposite to the defaults.
24210
24211 @item info send-rights
24212 @itemx info receive-rights
24213 @itemx info port-rights
24214 @itemx info port-sets
24215 @itemx info dead-names
24216 @itemx info ports
24217 @itemx info psets
24218 @cindex send rights, @sc{gnu} Hurd
24219 @cindex receive rights, @sc{gnu} Hurd
24220 @cindex port rights, @sc{gnu} Hurd
24221 @cindex port sets, @sc{gnu} Hurd
24222 @cindex dead names, @sc{gnu} Hurd
24223 These commands display information about, respectively, send rights,
24224 receive rights, port rights, port sets, and dead names of a task.
24225 There are also shorthand aliases: @code{info ports} for @code{info
24226 port-rights} and @code{info psets} for @code{info port-sets}.
24227
24228 @item set thread pause
24229 @kindex set thread@r{, Hurd command}
24230 @cindex thread properties, @sc{gnu} Hurd
24231 @cindex pause current thread (@sc{gnu} Hurd)
24232 This command toggles current thread suspension when @value{GDBN} has
24233 control. Setting it to on takes effect immediately, and the current
24234 thread is suspended whenever @value{GDBN} gets control. Setting it to
24235 off will take effect the next time the inferior is continued.
24236 Normally, this command has no effect, since when @value{GDBN} has
24237 control, the whole task is suspended. However, if you used @code{set
24238 task pause off} (see above), this command comes in handy to suspend
24239 only the current thread.
24240
24241 @item show thread pause
24242 @kindex show thread@r{, Hurd command}
24243 This command shows the state of current thread suspension.
24244
24245 @item set thread run
24246 This command sets whether the current thread is allowed to run.
24247
24248 @item show thread run
24249 Show whether the current thread is allowed to run.
24250
24251 @item set thread detach-suspend-count
24252 @cindex thread suspend count, @sc{gnu} Hurd
24253 @cindex detach from thread, @sc{gnu} Hurd
24254 This command sets the suspend count @value{GDBN} will leave on a
24255 thread when detaching. This number is relative to the suspend count
24256 found by @value{GDBN} when it notices the thread; use @code{set thread
24257 takeover-suspend-count} to force it to an absolute value.
24258
24259 @item show thread detach-suspend-count
24260 Show the suspend count @value{GDBN} will leave on the thread when
24261 detaching.
24262
24263 @item set thread exception-port
24264 @itemx set thread excp
24265 Set the thread exception port to which to forward exceptions. This
24266 overrides the port set by @code{set task exception-port} (see above).
24267 @code{set thread excp} is the shorthand alias.
24268
24269 @item set thread takeover-suspend-count
24270 Normally, @value{GDBN}'s thread suspend counts are relative to the
24271 value @value{GDBN} finds when it notices each thread. This command
24272 changes the suspend counts to be absolute instead.
24273
24274 @item set thread default
24275 @itemx show thread default
24276 @cindex thread default settings, @sc{gnu} Hurd
24277 Each of the above @code{set thread} commands has a @code{set thread
24278 default} counterpart (e.g., @code{set thread default pause}, @code{set
24279 thread default exception-port}, etc.). The @code{thread default}
24280 variety of commands sets the default thread properties for all
24281 threads; you can then change the properties of individual threads with
24282 the non-default commands.
24283 @end table
24284
24285 @node Darwin
24286 @subsection Darwin
24287 @cindex Darwin
24288
24289 @value{GDBN} provides the following commands specific to the Darwin target:
24290
24291 @table @code
24292 @item set debug darwin @var{num}
24293 @kindex set debug darwin
24294 When set to a non zero value, enables debugging messages specific to
24295 the Darwin support. Higher values produce more verbose output.
24296
24297 @item show debug darwin
24298 @kindex show debug darwin
24299 Show the current state of Darwin messages.
24300
24301 @item set debug mach-o @var{num}
24302 @kindex set debug mach-o
24303 When set to a non zero value, enables debugging messages while
24304 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24305 file format used on Darwin for object and executable files.) Higher
24306 values produce more verbose output. This is a command to diagnose
24307 problems internal to @value{GDBN} and should not be needed in normal
24308 usage.
24309
24310 @item show debug mach-o
24311 @kindex show debug mach-o
24312 Show the current state of Mach-O file messages.
24313
24314 @item set mach-exceptions on
24315 @itemx set mach-exceptions off
24316 @kindex set mach-exceptions
24317 On Darwin, faults are first reported as a Mach exception and are then
24318 mapped to a Posix signal. Use this command to turn on trapping of
24319 Mach exceptions in the inferior. This might be sometimes useful to
24320 better understand the cause of a fault. The default is off.
24321
24322 @item show mach-exceptions
24323 @kindex show mach-exceptions
24324 Show the current state of exceptions trapping.
24325 @end table
24326
24327 @node FreeBSD
24328 @subsection FreeBSD
24329 @cindex FreeBSD
24330
24331 When the ABI of a system call is changed in the FreeBSD kernel, this
24332 is implemented by leaving a compatibility system call using the old
24333 ABI at the existing number and allocating a new system call number for
24334 the version using the new ABI. As a convenience, when a system call
24335 is caught by name (@pxref{catch syscall}), compatibility system calls
24336 are also caught.
24337
24338 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24339 system call and catching the @code{kevent} system call by name catches
24340 both variants:
24341
24342 @smallexample
24343 (@value{GDBP}) catch syscall kevent
24344 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24345 (@value{GDBP})
24346 @end smallexample
24347
24348
24349 @node Embedded OS
24350 @section Embedded Operating Systems
24351
24352 This section describes configurations involving the debugging of
24353 embedded operating systems that are available for several different
24354 architectures.
24355
24356 @value{GDBN} includes the ability to debug programs running on
24357 various real-time operating systems.
24358
24359 @node Embedded Processors
24360 @section Embedded Processors
24361
24362 This section goes into details specific to particular embedded
24363 configurations.
24364
24365 @cindex send command to simulator
24366 Whenever a specific embedded processor has a simulator, @value{GDBN}
24367 allows to send an arbitrary command to the simulator.
24368
24369 @table @code
24370 @item sim @var{command}
24371 @kindex sim@r{, a command}
24372 Send an arbitrary @var{command} string to the simulator. Consult the
24373 documentation for the specific simulator in use for information about
24374 acceptable commands.
24375 @end table
24376
24377
24378 @menu
24379 * ARC:: Synopsys ARC
24380 * ARM:: ARM
24381 * M68K:: Motorola M68K
24382 * MicroBlaze:: Xilinx MicroBlaze
24383 * MIPS Embedded:: MIPS Embedded
24384 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24385 * PowerPC Embedded:: PowerPC Embedded
24386 * AVR:: Atmel AVR
24387 * CRIS:: CRIS
24388 * Super-H:: Renesas Super-H
24389 @end menu
24390
24391 @node ARC
24392 @subsection Synopsys ARC
24393 @cindex Synopsys ARC
24394 @cindex ARC specific commands
24395 @cindex ARC600
24396 @cindex ARC700
24397 @cindex ARC EM
24398 @cindex ARC HS
24399
24400 @value{GDBN} provides the following ARC-specific commands:
24401
24402 @table @code
24403 @item set debug arc
24404 @kindex set debug arc
24405 Control the level of ARC specific debug messages. Use 0 for no messages (the
24406 default), 1 for debug messages, and 2 for even more debug messages.
24407
24408 @item show debug arc
24409 @kindex show debug arc
24410 Show the level of ARC specific debugging in operation.
24411
24412 @item maint print arc arc-instruction @var{address}
24413 @kindex maint print arc arc-instruction
24414 Print internal disassembler information about instruction at a given address.
24415
24416 @end table
24417
24418 @node ARM
24419 @subsection ARM
24420
24421 @value{GDBN} provides the following ARM-specific commands:
24422
24423 @table @code
24424 @item set arm disassembler
24425 @kindex set arm
24426 This commands selects from a list of disassembly styles. The
24427 @code{"std"} style is the standard style.
24428
24429 @item show arm disassembler
24430 @kindex show arm
24431 Show the current disassembly style.
24432
24433 @item set arm apcs32
24434 @cindex ARM 32-bit mode
24435 This command toggles ARM operation mode between 32-bit and 26-bit.
24436
24437 @item show arm apcs32
24438 Display the current usage of the ARM 32-bit mode.
24439
24440 @item set arm fpu @var{fputype}
24441 This command sets the ARM floating-point unit (FPU) type. The
24442 argument @var{fputype} can be one of these:
24443
24444 @table @code
24445 @item auto
24446 Determine the FPU type by querying the OS ABI.
24447 @item softfpa
24448 Software FPU, with mixed-endian doubles on little-endian ARM
24449 processors.
24450 @item fpa
24451 GCC-compiled FPA co-processor.
24452 @item softvfp
24453 Software FPU with pure-endian doubles.
24454 @item vfp
24455 VFP co-processor.
24456 @end table
24457
24458 @item show arm fpu
24459 Show the current type of the FPU.
24460
24461 @item set arm abi
24462 This command forces @value{GDBN} to use the specified ABI.
24463
24464 @item show arm abi
24465 Show the currently used ABI.
24466
24467 @item set arm fallback-mode (arm|thumb|auto)
24468 @value{GDBN} uses the symbol table, when available, to determine
24469 whether instructions are ARM or Thumb. This command controls
24470 @value{GDBN}'s default behavior when the symbol table is not
24471 available. The default is @samp{auto}, which causes @value{GDBN} to
24472 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24473 register).
24474
24475 @item show arm fallback-mode
24476 Show the current fallback instruction mode.
24477
24478 @item set arm force-mode (arm|thumb|auto)
24479 This command overrides use of the symbol table to determine whether
24480 instructions are ARM or Thumb. The default is @samp{auto}, which
24481 causes @value{GDBN} to use the symbol table and then the setting
24482 of @samp{set arm fallback-mode}.
24483
24484 @item show arm force-mode
24485 Show the current forced instruction mode.
24486
24487 @item set debug arm
24488 Toggle whether to display ARM-specific debugging messages from the ARM
24489 target support subsystem.
24490
24491 @item show debug arm
24492 Show whether ARM-specific debugging messages are enabled.
24493 @end table
24494
24495 @table @code
24496 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24497 The @value{GDBN} ARM simulator accepts the following optional arguments.
24498
24499 @table @code
24500 @item --swi-support=@var{type}
24501 Tell the simulator which SWI interfaces to support. The argument
24502 @var{type} may be a comma separated list of the following values.
24503 The default value is @code{all}.
24504
24505 @table @code
24506 @item none
24507 @item demon
24508 @item angel
24509 @item redboot
24510 @item all
24511 @end table
24512 @end table
24513 @end table
24514
24515 @node M68K
24516 @subsection M68k
24517
24518 The Motorola m68k configuration includes ColdFire support.
24519
24520 @node MicroBlaze
24521 @subsection MicroBlaze
24522 @cindex Xilinx MicroBlaze
24523 @cindex XMD, Xilinx Microprocessor Debugger
24524
24525 The MicroBlaze is a soft-core processor supported on various Xilinx
24526 FPGAs, such as Spartan or Virtex series. Boards with these processors
24527 usually have JTAG ports which connect to a host system running the Xilinx
24528 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24529 This host system is used to download the configuration bitstream to
24530 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24531 communicates with the target board using the JTAG interface and
24532 presents a @code{gdbserver} interface to the board. By default
24533 @code{xmd} uses port @code{1234}. (While it is possible to change
24534 this default port, it requires the use of undocumented @code{xmd}
24535 commands. Contact Xilinx support if you need to do this.)
24536
24537 Use these GDB commands to connect to the MicroBlaze target processor.
24538
24539 @table @code
24540 @item target remote :1234
24541 Use this command to connect to the target if you are running @value{GDBN}
24542 on the same system as @code{xmd}.
24543
24544 @item target remote @var{xmd-host}:1234
24545 Use this command to connect to the target if it is connected to @code{xmd}
24546 running on a different system named @var{xmd-host}.
24547
24548 @item load
24549 Use this command to download a program to the MicroBlaze target.
24550
24551 @item set debug microblaze @var{n}
24552 Enable MicroBlaze-specific debugging messages if non-zero.
24553
24554 @item show debug microblaze @var{n}
24555 Show MicroBlaze-specific debugging level.
24556 @end table
24557
24558 @node MIPS Embedded
24559 @subsection @acronym{MIPS} Embedded
24560
24561 @noindent
24562 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24563
24564 @table @code
24565 @item set mipsfpu double
24566 @itemx set mipsfpu single
24567 @itemx set mipsfpu none
24568 @itemx set mipsfpu auto
24569 @itemx show mipsfpu
24570 @kindex set mipsfpu
24571 @kindex show mipsfpu
24572 @cindex @acronym{MIPS} remote floating point
24573 @cindex floating point, @acronym{MIPS} remote
24574 If your target board does not support the @acronym{MIPS} floating point
24575 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24576 need this, you may wish to put the command in your @value{GDBN} init
24577 file). This tells @value{GDBN} how to find the return value of
24578 functions which return floating point values. It also allows
24579 @value{GDBN} to avoid saving the floating point registers when calling
24580 functions on the board. If you are using a floating point coprocessor
24581 with only single precision floating point support, as on the @sc{r4650}
24582 processor, use the command @samp{set mipsfpu single}. The default
24583 double precision floating point coprocessor may be selected using
24584 @samp{set mipsfpu double}.
24585
24586 In previous versions the only choices were double precision or no
24587 floating point, so @samp{set mipsfpu on} will select double precision
24588 and @samp{set mipsfpu off} will select no floating point.
24589
24590 As usual, you can inquire about the @code{mipsfpu} variable with
24591 @samp{show mipsfpu}.
24592 @end table
24593
24594 @node OpenRISC 1000
24595 @subsection OpenRISC 1000
24596 @cindex OpenRISC 1000
24597
24598 @noindent
24599 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24600 mainly provided as a soft-core which can run on Xilinx, Altera and other
24601 FPGA's.
24602
24603 @value{GDBN} for OpenRISC supports the below commands when connecting to
24604 a target:
24605
24606 @table @code
24607
24608 @kindex target sim
24609 @item target sim
24610
24611 Runs the builtin CPU simulator which can run very basic
24612 programs but does not support most hardware functions like MMU.
24613 For more complex use cases the user is advised to run an external
24614 target, and connect using @samp{target remote}.
24615
24616 Example: @code{target sim}
24617
24618 @item set debug or1k
24619 Toggle whether to display OpenRISC-specific debugging messages from the
24620 OpenRISC target support subsystem.
24621
24622 @item show debug or1k
24623 Show whether OpenRISC-specific debugging messages are enabled.
24624 @end table
24625
24626 @node PowerPC Embedded
24627 @subsection PowerPC Embedded
24628
24629 @cindex DVC register
24630 @value{GDBN} supports using the DVC (Data Value Compare) register to
24631 implement in hardware simple hardware watchpoint conditions of the form:
24632
24633 @smallexample
24634 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24635 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24636 @end smallexample
24637
24638 The DVC register will be automatically used when @value{GDBN} detects
24639 such pattern in a condition expression, and the created watchpoint uses one
24640 debug register (either the @code{exact-watchpoints} option is on and the
24641 variable is scalar, or the variable has a length of one byte). This feature
24642 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24643 or newer.
24644
24645 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24646 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24647 in which case watchpoints using only one debug register are created when
24648 watching variables of scalar types.
24649
24650 You can create an artificial array to watch an arbitrary memory
24651 region using one of the following commands (@pxref{Expressions}):
24652
24653 @smallexample
24654 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24655 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24656 @end smallexample
24657
24658 PowerPC embedded processors support masked watchpoints. See the discussion
24659 about the @code{mask} argument in @ref{Set Watchpoints}.
24660
24661 @cindex ranged breakpoint
24662 PowerPC embedded processors support hardware accelerated
24663 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24664 the inferior whenever it executes an instruction at any address within
24665 the range it specifies. To set a ranged breakpoint in @value{GDBN},
24666 use the @code{break-range} command.
24667
24668 @value{GDBN} provides the following PowerPC-specific commands:
24669
24670 @table @code
24671 @kindex break-range
24672 @item break-range @var{start-location}, @var{end-location}
24673 Set a breakpoint for an address range given by
24674 @var{start-location} and @var{end-location}, which can specify a function name,
24675 a line number, an offset of lines from the current line or from the start
24676 location, or an address of an instruction (see @ref{Specify Location},
24677 for a list of all the possible ways to specify a @var{location}.)
24678 The breakpoint will stop execution of the inferior whenever it
24679 executes an instruction at any address within the specified range,
24680 (including @var{start-location} and @var{end-location}.)
24681
24682 @kindex set powerpc
24683 @item set powerpc soft-float
24684 @itemx show powerpc soft-float
24685 Force @value{GDBN} to use (or not use) a software floating point calling
24686 convention. By default, @value{GDBN} selects the calling convention based
24687 on the selected architecture and the provided executable file.
24688
24689 @item set powerpc vector-abi
24690 @itemx show powerpc vector-abi
24691 Force @value{GDBN} to use the specified calling convention for vector
24692 arguments and return values. The valid options are @samp{auto};
24693 @samp{generic}, to avoid vector registers even if they are present;
24694 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24695 registers. By default, @value{GDBN} selects the calling convention
24696 based on the selected architecture and the provided executable file.
24697
24698 @item set powerpc exact-watchpoints
24699 @itemx show powerpc exact-watchpoints
24700 Allow @value{GDBN} to use only one debug register when watching a variable
24701 of scalar type, thus assuming that the variable is accessed through the
24702 address of its first byte.
24703
24704 @end table
24705
24706 @node AVR
24707 @subsection Atmel AVR
24708 @cindex AVR
24709
24710 When configured for debugging the Atmel AVR, @value{GDBN} supports the
24711 following AVR-specific commands:
24712
24713 @table @code
24714 @item info io_registers
24715 @kindex info io_registers@r{, AVR}
24716 @cindex I/O registers (Atmel AVR)
24717 This command displays information about the AVR I/O registers. For
24718 each register, @value{GDBN} prints its number and value.
24719 @end table
24720
24721 @node CRIS
24722 @subsection CRIS
24723 @cindex CRIS
24724
24725 When configured for debugging CRIS, @value{GDBN} provides the
24726 following CRIS-specific commands:
24727
24728 @table @code
24729 @item set cris-version @var{ver}
24730 @cindex CRIS version
24731 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24732 The CRIS version affects register names and sizes. This command is useful in
24733 case autodetection of the CRIS version fails.
24734
24735 @item show cris-version
24736 Show the current CRIS version.
24737
24738 @item set cris-dwarf2-cfi
24739 @cindex DWARF-2 CFI and CRIS
24740 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24741 Change to @samp{off} when using @code{gcc-cris} whose version is below
24742 @code{R59}.
24743
24744 @item show cris-dwarf2-cfi
24745 Show the current state of using DWARF-2 CFI.
24746
24747 @item set cris-mode @var{mode}
24748 @cindex CRIS mode
24749 Set the current CRIS mode to @var{mode}. It should only be changed when
24750 debugging in guru mode, in which case it should be set to
24751 @samp{guru} (the default is @samp{normal}).
24752
24753 @item show cris-mode
24754 Show the current CRIS mode.
24755 @end table
24756
24757 @node Super-H
24758 @subsection Renesas Super-H
24759 @cindex Super-H
24760
24761 For the Renesas Super-H processor, @value{GDBN} provides these
24762 commands:
24763
24764 @table @code
24765 @item set sh calling-convention @var{convention}
24766 @kindex set sh calling-convention
24767 Set the calling-convention used when calling functions from @value{GDBN}.
24768 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24769 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24770 convention. If the DWARF-2 information of the called function specifies
24771 that the function follows the Renesas calling convention, the function
24772 is called using the Renesas calling convention. If the calling convention
24773 is set to @samp{renesas}, the Renesas calling convention is always used,
24774 regardless of the DWARF-2 information. This can be used to override the
24775 default of @samp{gcc} if debug information is missing, or the compiler
24776 does not emit the DWARF-2 calling convention entry for a function.
24777
24778 @item show sh calling-convention
24779 @kindex show sh calling-convention
24780 Show the current calling convention setting.
24781
24782 @end table
24783
24784
24785 @node Architectures
24786 @section Architectures
24787
24788 This section describes characteristics of architectures that affect
24789 all uses of @value{GDBN} with the architecture, both native and cross.
24790
24791 @menu
24792 * AArch64::
24793 * i386::
24794 * Alpha::
24795 * MIPS::
24796 * HPPA:: HP PA architecture
24797 * PowerPC::
24798 * Nios II::
24799 * Sparc64::
24800 * S12Z::
24801 @end menu
24802
24803 @node AArch64
24804 @subsection AArch64
24805 @cindex AArch64 support
24806
24807 When @value{GDBN} is debugging the AArch64 architecture, it provides the
24808 following special commands:
24809
24810 @table @code
24811 @item set debug aarch64
24812 @kindex set debug aarch64
24813 This command determines whether AArch64 architecture-specific debugging
24814 messages are to be displayed.
24815
24816 @item show debug aarch64
24817 Show whether AArch64 debugging messages are displayed.
24818
24819 @end table
24820
24821 @subsubsection AArch64 SVE.
24822 @cindex AArch64 SVE.
24823
24824 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24825 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24826 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24827 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24828 @code{$vg} will be provided. This is the vector granule for the current thread
24829 and represents the number of 64-bit chunks in an SVE @code{z} register.
24830
24831 If the vector length changes, then the @code{$vg} register will be updated,
24832 but the lengths of the @code{z} and @code{p} registers will not change. This
24833 is a known limitation of @value{GDBN} and does not affect the execution of the
24834 target process.
24835
24836 @subsubsection AArch64 Pointer Authentication.
24837 @cindex AArch64 Pointer Authentication.
24838
24839 When @value{GDBN} is debugging the AArch64 architecture, and the program is
24840 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
24841 register @code{$lr} is pointing to an PAC function its value will be masked.
24842 When GDB prints a backtrace, any addresses that required unmasking will be
24843 postfixed with the marker [PAC]. When using the MI, this is printed as part
24844 of the @code{addr_flags} field.
24845
24846 @node i386
24847 @subsection x86 Architecture-specific Issues
24848
24849 @table @code
24850 @item set struct-convention @var{mode}
24851 @kindex set struct-convention
24852 @cindex struct return convention
24853 @cindex struct/union returned in registers
24854 Set the convention used by the inferior to return @code{struct}s and
24855 @code{union}s from functions to @var{mode}. Possible values of
24856 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24857 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24858 are returned on the stack, while @code{"reg"} means that a
24859 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24860 be returned in a register.
24861
24862 @item show struct-convention
24863 @kindex show struct-convention
24864 Show the current setting of the convention to return @code{struct}s
24865 from functions.
24866 @end table
24867
24868
24869 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24870 @cindex Intel Memory Protection Extensions (MPX).
24871
24872 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24873 @footnote{The register named with capital letters represent the architecture
24874 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24875 which are the lower bound and upper bound. Bounds are effective addresses or
24876 memory locations. The upper bounds are architecturally represented in 1's
24877 complement form. A bound having lower bound = 0, and upper bound = 0
24878 (1's complement of all bits set) will allow access to the entire address space.
24879
24880 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24881 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24882 display the upper bound performing the complement of one operation on the
24883 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24884 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24885 can also be noted that the upper bounds are inclusive.
24886
24887 As an example, assume that the register BND0 holds bounds for a pointer having
24888 access allowed for the range between 0x32 and 0x71. The values present on
24889 bnd0raw and bnd registers are presented as follows:
24890
24891 @smallexample
24892 bnd0raw = @{0x32, 0xffffffff8e@}
24893 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24894 @end smallexample
24895
24896 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24897 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24898 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24899 Python, the display includes the memory size, in bits, accessible to
24900 the pointer.
24901
24902 Bounds can also be stored in bounds tables, which are stored in
24903 application memory. These tables store bounds for pointers by specifying
24904 the bounds pointer's value along with its bounds. Evaluating and changing
24905 bounds located in bound tables is therefore interesting while investigating
24906 bugs on MPX context. @value{GDBN} provides commands for this purpose:
24907
24908 @table @code
24909 @item show mpx bound @var{pointer}
24910 @kindex show mpx bound
24911 Display bounds of the given @var{pointer}.
24912
24913 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24914 @kindex set mpx bound
24915 Set the bounds of a pointer in the bound table.
24916 This command takes three parameters: @var{pointer} is the pointers
24917 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24918 for lower and upper bounds respectively.
24919 @end table
24920
24921 When you call an inferior function on an Intel MPX enabled program,
24922 GDB sets the inferior's bound registers to the init (disabled) state
24923 before calling the function. As a consequence, bounds checks for the
24924 pointer arguments passed to the function will always pass.
24925
24926 This is necessary because when you call an inferior function, the
24927 program is usually in the middle of the execution of other function.
24928 Since at that point bound registers are in an arbitrary state, not
24929 clearing them would lead to random bound violations in the called
24930 function.
24931
24932 You can still examine the influence of the bound registers on the
24933 execution of the called function by stopping the execution of the
24934 called function at its prologue, setting bound registers, and
24935 continuing the execution. For example:
24936
24937 @smallexample
24938 $ break *upper
24939 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24940 $ print upper (a, b, c, d, 1)
24941 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24942 $ print $bnd0
24943 @{lbound = 0x0, ubound = ffffffff@} : size -1
24944 @end smallexample
24945
24946 At this last step the value of bnd0 can be changed for investigation of bound
24947 violations caused along the execution of the call. In order to know how to
24948 set the bound registers or bound table for the call consult the ABI.
24949
24950 @node Alpha
24951 @subsection Alpha
24952
24953 See the following section.
24954
24955 @node MIPS
24956 @subsection @acronym{MIPS}
24957
24958 @cindex stack on Alpha
24959 @cindex stack on @acronym{MIPS}
24960 @cindex Alpha stack
24961 @cindex @acronym{MIPS} stack
24962 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
24963 sometimes requires @value{GDBN} to search backward in the object code to
24964 find the beginning of a function.
24965
24966 @cindex response time, @acronym{MIPS} debugging
24967 To improve response time (especially for embedded applications, where
24968 @value{GDBN} may be restricted to a slow serial line for this search)
24969 you may want to limit the size of this search, using one of these
24970 commands:
24971
24972 @table @code
24973 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
24974 @item set heuristic-fence-post @var{limit}
24975 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24976 search for the beginning of a function. A value of @var{0} (the
24977 default) means there is no limit. However, except for @var{0}, the
24978 larger the limit the more bytes @code{heuristic-fence-post} must search
24979 and therefore the longer it takes to run. You should only need to use
24980 this command when debugging a stripped executable.
24981
24982 @item show heuristic-fence-post
24983 Display the current limit.
24984 @end table
24985
24986 @noindent
24987 These commands are available @emph{only} when @value{GDBN} is configured
24988 for debugging programs on Alpha or @acronym{MIPS} processors.
24989
24990 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
24991 programs:
24992
24993 @table @code
24994 @item set mips abi @var{arg}
24995 @kindex set mips abi
24996 @cindex set ABI for @acronym{MIPS}
24997 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
24998 values of @var{arg} are:
24999
25000 @table @samp
25001 @item auto
25002 The default ABI associated with the current binary (this is the
25003 default).
25004 @item o32
25005 @item o64
25006 @item n32
25007 @item n64
25008 @item eabi32
25009 @item eabi64
25010 @end table
25011
25012 @item show mips abi
25013 @kindex show mips abi
25014 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25015
25016 @item set mips compression @var{arg}
25017 @kindex set mips compression
25018 @cindex code compression, @acronym{MIPS}
25019 Tell @value{GDBN} which @acronym{MIPS} compressed
25020 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25021 inferior. @value{GDBN} uses this for code disassembly and other
25022 internal interpretation purposes. This setting is only referred to
25023 when no executable has been associated with the debugging session or
25024 the executable does not provide information about the encoding it uses.
25025 Otherwise this setting is automatically updated from information
25026 provided by the executable.
25027
25028 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25029 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25030 executables containing @acronym{MIPS16} code frequently are not
25031 identified as such.
25032
25033 This setting is ``sticky''; that is, it retains its value across
25034 debugging sessions until reset either explicitly with this command or
25035 implicitly from an executable.
25036
25037 The compiler and/or assembler typically add symbol table annotations to
25038 identify functions compiled for the @acronym{MIPS16} or
25039 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25040 are present, @value{GDBN} uses them in preference to the global
25041 compressed @acronym{ISA} encoding setting.
25042
25043 @item show mips compression
25044 @kindex show mips compression
25045 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25046 @value{GDBN} to debug the inferior.
25047
25048 @item set mipsfpu
25049 @itemx show mipsfpu
25050 @xref{MIPS Embedded, set mipsfpu}.
25051
25052 @item set mips mask-address @var{arg}
25053 @kindex set mips mask-address
25054 @cindex @acronym{MIPS} addresses, masking
25055 This command determines whether the most-significant 32 bits of 64-bit
25056 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25057 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25058 setting, which lets @value{GDBN} determine the correct value.
25059
25060 @item show mips mask-address
25061 @kindex show mips mask-address
25062 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25063 not.
25064
25065 @item set remote-mips64-transfers-32bit-regs
25066 @kindex set remote-mips64-transfers-32bit-regs
25067 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25068 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25069 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25070 and 64 bits for other registers, set this option to @samp{on}.
25071
25072 @item show remote-mips64-transfers-32bit-regs
25073 @kindex show remote-mips64-transfers-32bit-regs
25074 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25075
25076 @item set debug mips
25077 @kindex set debug mips
25078 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25079 target code in @value{GDBN}.
25080
25081 @item show debug mips
25082 @kindex show debug mips
25083 Show the current setting of @acronym{MIPS} debugging messages.
25084 @end table
25085
25086
25087 @node HPPA
25088 @subsection HPPA
25089 @cindex HPPA support
25090
25091 When @value{GDBN} is debugging the HP PA architecture, it provides the
25092 following special commands:
25093
25094 @table @code
25095 @item set debug hppa
25096 @kindex set debug hppa
25097 This command determines whether HPPA architecture-specific debugging
25098 messages are to be displayed.
25099
25100 @item show debug hppa
25101 Show whether HPPA debugging messages are displayed.
25102
25103 @item maint print unwind @var{address}
25104 @kindex maint print unwind@r{, HPPA}
25105 This command displays the contents of the unwind table entry at the
25106 given @var{address}.
25107
25108 @end table
25109
25110
25111 @node PowerPC
25112 @subsection PowerPC
25113 @cindex PowerPC architecture
25114
25115 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25116 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25117 numbers stored in the floating point registers. These values must be stored
25118 in two consecutive registers, always starting at an even register like
25119 @code{f0} or @code{f2}.
25120
25121 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25122 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25123 @code{f2} and @code{f3} for @code{$dl1} and so on.
25124
25125 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25126 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25127
25128 @node Nios II
25129 @subsection Nios II
25130 @cindex Nios II architecture
25131
25132 When @value{GDBN} is debugging the Nios II architecture,
25133 it provides the following special commands:
25134
25135 @table @code
25136
25137 @item set debug nios2
25138 @kindex set debug nios2
25139 This command turns on and off debugging messages for the Nios II
25140 target code in @value{GDBN}.
25141
25142 @item show debug nios2
25143 @kindex show debug nios2
25144 Show the current setting of Nios II debugging messages.
25145 @end table
25146
25147 @node Sparc64
25148 @subsection Sparc64
25149 @cindex Sparc64 support
25150 @cindex Application Data Integrity
25151 @subsubsection ADI Support
25152
25153 The M7 processor supports an Application Data Integrity (ADI) feature that
25154 detects invalid data accesses. When software allocates memory and enables
25155 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25156 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25157 the 4-bit version in every cacheline of that data. Hardware saves the latter
25158 in spare bits in the cache and memory hierarchy. On each load and store,
25159 the processor compares the upper 4 VA (virtual address) bits to the
25160 cacheline's version. If there is a mismatch, the processor generates a
25161 version mismatch trap which can be either precise or disrupting. The trap
25162 is an error condition which the kernel delivers to the process as a SIGSEGV
25163 signal.
25164
25165 Note that only 64-bit applications can use ADI and need to be built with
25166 ADI-enabled.
25167
25168 Values of the ADI version tags, which are in granularity of a
25169 cacheline (64 bytes), can be viewed or modified.
25170
25171
25172 @table @code
25173 @kindex adi examine
25174 @item adi (examine | x) [ / @var{n} ] @var{addr}
25175
25176 The @code{adi examine} command displays the value of one ADI version tag per
25177 cacheline.
25178
25179 @var{n} is a decimal integer specifying the number in bytes; the default
25180 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25181 block size, to display.
25182
25183 @var{addr} is the address in user address space where you want @value{GDBN}
25184 to begin displaying the ADI version tags.
25185
25186 Below is an example of displaying ADI versions of variable "shmaddr".
25187
25188 @smallexample
25189 (@value{GDBP}) adi x/100 shmaddr
25190 0xfff800010002c000: 0 0
25191 @end smallexample
25192
25193 @kindex adi assign
25194 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25195
25196 The @code{adi assign} command is used to assign new ADI version tag
25197 to an address.
25198
25199 @var{n} is a decimal integer specifying the number in bytes;
25200 the default is 1. It specifies how much ADI version information, at the
25201 ratio of 1:ADI block size, to modify.
25202
25203 @var{addr} is the address in user address space where you want @value{GDBN}
25204 to begin modifying the ADI version tags.
25205
25206 @var{tag} is the new ADI version tag.
25207
25208 For example, do the following to modify then verify ADI versions of
25209 variable "shmaddr":
25210
25211 @smallexample
25212 (@value{GDBP}) adi a/100 shmaddr = 7
25213 (@value{GDBP}) adi x/100 shmaddr
25214 0xfff800010002c000: 7 7
25215 @end smallexample
25216
25217 @end table
25218
25219 @node S12Z
25220 @subsection S12Z
25221 @cindex S12Z support
25222
25223 When @value{GDBN} is debugging the S12Z architecture,
25224 it provides the following special command:
25225
25226 @table @code
25227 @item maint info bdccsr
25228 @kindex maint info bdccsr@r{, S12Z}
25229 This command displays the current value of the microprocessor's
25230 BDCCSR register.
25231 @end table
25232
25233
25234 @node Controlling GDB
25235 @chapter Controlling @value{GDBN}
25236
25237 You can alter the way @value{GDBN} interacts with you by using the
25238 @code{set} command. For commands controlling how @value{GDBN} displays
25239 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25240 described here.
25241
25242 @menu
25243 * Prompt:: Prompt
25244 * Editing:: Command editing
25245 * Command History:: Command history
25246 * Screen Size:: Screen size
25247 * Output Styling:: Output styling
25248 * Numbers:: Numbers
25249 * ABI:: Configuring the current ABI
25250 * Auto-loading:: Automatically loading associated files
25251 * Messages/Warnings:: Optional warnings and messages
25252 * Debugging Output:: Optional messages about internal happenings
25253 * Other Misc Settings:: Other Miscellaneous Settings
25254 @end menu
25255
25256 @node Prompt
25257 @section Prompt
25258
25259 @cindex prompt
25260
25261 @value{GDBN} indicates its readiness to read a command by printing a string
25262 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25263 can change the prompt string with the @code{set prompt} command. For
25264 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25265 the prompt in one of the @value{GDBN} sessions so that you can always tell
25266 which one you are talking to.
25267
25268 @emph{Note:} @code{set prompt} does not add a space for you after the
25269 prompt you set. This allows you to set a prompt which ends in a space
25270 or a prompt that does not.
25271
25272 @table @code
25273 @kindex set prompt
25274 @item set prompt @var{newprompt}
25275 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25276
25277 @kindex show prompt
25278 @item show prompt
25279 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25280 @end table
25281
25282 Versions of @value{GDBN} that ship with Python scripting enabled have
25283 prompt extensions. The commands for interacting with these extensions
25284 are:
25285
25286 @table @code
25287 @kindex set extended-prompt
25288 @item set extended-prompt @var{prompt}
25289 Set an extended prompt that allows for substitutions.
25290 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25291 substitution. Any escape sequences specified as part of the prompt
25292 string are replaced with the corresponding strings each time the prompt
25293 is displayed.
25294
25295 For example:
25296
25297 @smallexample
25298 set extended-prompt Current working directory: \w (gdb)
25299 @end smallexample
25300
25301 Note that when an extended-prompt is set, it takes control of the
25302 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25303
25304 @kindex show extended-prompt
25305 @item show extended-prompt
25306 Prints the extended prompt. Any escape sequences specified as part of
25307 the prompt string with @code{set extended-prompt}, are replaced with the
25308 corresponding strings each time the prompt is displayed.
25309 @end table
25310
25311 @node Editing
25312 @section Command Editing
25313 @cindex readline
25314 @cindex command line editing
25315
25316 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25317 @sc{gnu} library provides consistent behavior for programs which provide a
25318 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25319 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25320 substitution, and a storage and recall of command history across
25321 debugging sessions.
25322
25323 You may control the behavior of command line editing in @value{GDBN} with the
25324 command @code{set}.
25325
25326 @table @code
25327 @kindex set editing
25328 @cindex editing
25329 @item set editing
25330 @itemx set editing on
25331 Enable command line editing (enabled by default).
25332
25333 @item set editing off
25334 Disable command line editing.
25335
25336 @kindex show editing
25337 @item show editing
25338 Show whether command line editing is enabled.
25339 @end table
25340
25341 @ifset SYSTEM_READLINE
25342 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25343 @end ifset
25344 @ifclear SYSTEM_READLINE
25345 @xref{Command Line Editing},
25346 @end ifclear
25347 for more details about the Readline
25348 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25349 encouraged to read that chapter.
25350
25351 @cindex Readline application name
25352 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25353 is useful for conditions in @file{.inputrc}.
25354
25355 @cindex operate-and-get-next
25356 @value{GDBN} defines a bindable Readline command,
25357 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25358 This command accepts the current line for execution and fetches the
25359 next line relative to the current line from the history for editing.
25360 Any argument is ignored.
25361
25362 @node Command History
25363 @section Command History
25364 @cindex command history
25365
25366 @value{GDBN} can keep track of the commands you type during your
25367 debugging sessions, so that you can be certain of precisely what
25368 happened. Use these commands to manage the @value{GDBN} command
25369 history facility.
25370
25371 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25372 package, to provide the history facility.
25373 @ifset SYSTEM_READLINE
25374 @xref{Using History Interactively, , , history, GNU History Library},
25375 @end ifset
25376 @ifclear SYSTEM_READLINE
25377 @xref{Using History Interactively},
25378 @end ifclear
25379 for the detailed description of the History library.
25380
25381 To issue a command to @value{GDBN} without affecting certain aspects of
25382 the state which is seen by users, prefix it with @samp{server }
25383 (@pxref{Server Prefix}). This
25384 means that this command will not affect the command history, nor will it
25385 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25386 pressed on a line by itself.
25387
25388 @cindex @code{server}, command prefix
25389 The server prefix does not affect the recording of values into the value
25390 history; to print a value without recording it into the value history,
25391 use the @code{output} command instead of the @code{print} command.
25392
25393 Here is the description of @value{GDBN} commands related to command
25394 history.
25395
25396 @table @code
25397 @cindex history substitution
25398 @cindex history file
25399 @kindex set history filename
25400 @cindex @env{GDBHISTFILE}, environment variable
25401 @item set history filename @r{[}@var{fname}@r{]}
25402 Set the name of the @value{GDBN} command history file to @var{fname}.
25403 This is the file where @value{GDBN} reads an initial command history
25404 list, and where it writes the command history from this session when it
25405 exits. You can access this list through history expansion or through
25406 the history command editing characters listed below. This file defaults
25407 to the value of the environment variable @code{GDBHISTFILE}, or to
25408 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25409 is not set.
25410
25411 The @code{GDBHISTFILE} environment variable is read after processing
25412 any @value{GDBN} initialization files (@pxref{Startup}) and after
25413 processing any commands passed using command line options (for
25414 example, @code{-ex}).
25415
25416 If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25417 is the empty string then @value{GDBN} will neither try to load an
25418 existing history file, nor will it try to save the history on exit.
25419
25420 @cindex save command history
25421 @kindex set history save
25422 @item set history save
25423 @itemx set history save on
25424 Record command history in a file, whose name may be specified with the
25425 @code{set history filename} command. By default, this option is
25426 disabled. The command history will be recorded when @value{GDBN}
25427 exits. If @code{set history filename} is set to the empty string then
25428 history saving is disabled, even when @code{set history save} is
25429 @code{on}.
25430
25431 @item set history save off
25432 Don't record the command history into the file specified by @code{set
25433 history filename} when @value{GDBN} exits.
25434
25435 @cindex history size
25436 @kindex set history size
25437 @cindex @env{GDBHISTSIZE}, environment variable
25438 @item set history size @var{size}
25439 @itemx set history size unlimited
25440 Set the number of commands which @value{GDBN} keeps in its history list.
25441 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25442 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25443 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25444 either a negative number or the empty string, then the number of commands
25445 @value{GDBN} keeps in the history list is unlimited.
25446
25447 The @code{GDBHISTSIZE} environment variable is read after processing
25448 any @value{GDBN} initialization files (@pxref{Startup}) and after
25449 processing any commands passed using command line options (for
25450 example, @code{-ex}).
25451
25452 @cindex remove duplicate history
25453 @kindex set history remove-duplicates
25454 @item set history remove-duplicates @var{count}
25455 @itemx set history remove-duplicates unlimited
25456 Control the removal of duplicate history entries in the command history list.
25457 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25458 history entries and remove the first entry that is a duplicate of the current
25459 entry being added to the command history list. If @var{count} is
25460 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25461 removal of duplicate history entries is disabled.
25462
25463 Only history entries added during the current session are considered for
25464 removal. This option is set to 0 by default.
25465
25466 @end table
25467
25468 History expansion assigns special meaning to the character @kbd{!}.
25469 @ifset SYSTEM_READLINE
25470 @xref{Event Designators, , , history, GNU History Library},
25471 @end ifset
25472 @ifclear SYSTEM_READLINE
25473 @xref{Event Designators},
25474 @end ifclear
25475 for more details.
25476
25477 @cindex history expansion, turn on/off
25478 Since @kbd{!} is also the logical not operator in C, history expansion
25479 is off by default. If you decide to enable history expansion with the
25480 @code{set history expansion on} command, you may sometimes need to
25481 follow @kbd{!} (when it is used as logical not, in an expression) with
25482 a space or a tab to prevent it from being expanded. The readline
25483 history facilities do not attempt substitution on the strings
25484 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25485
25486 The commands to control history expansion are:
25487
25488 @table @code
25489 @item set history expansion on
25490 @itemx set history expansion
25491 @kindex set history expansion
25492 Enable history expansion. History expansion is off by default.
25493
25494 @item set history expansion off
25495 Disable history expansion.
25496
25497 @c @group
25498 @kindex show history
25499 @item show history
25500 @itemx show history filename
25501 @itemx show history save
25502 @itemx show history size
25503 @itemx show history expansion
25504 These commands display the state of the @value{GDBN} history parameters.
25505 @code{show history} by itself displays all four states.
25506 @c @end group
25507 @end table
25508
25509 @table @code
25510 @kindex show commands
25511 @cindex show last commands
25512 @cindex display command history
25513 @item show commands
25514 Display the last ten commands in the command history.
25515
25516 @item show commands @var{n}
25517 Print ten commands centered on command number @var{n}.
25518
25519 @item show commands +
25520 Print ten commands just after the commands last printed.
25521 @end table
25522
25523 @node Screen Size
25524 @section Screen Size
25525 @cindex size of screen
25526 @cindex screen size
25527 @cindex pagination
25528 @cindex page size
25529 @cindex pauses in output
25530
25531 Certain commands to @value{GDBN} may produce large amounts of
25532 information output to the screen. To help you read all of it,
25533 @value{GDBN} pauses and asks you for input at the end of each page of
25534 output. Type @key{RET} when you want to see one more page of output,
25535 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25536 without paging for the rest of the current command. Also, the screen
25537 width setting determines when to wrap lines of output. Depending on
25538 what is being printed, @value{GDBN} tries to break the line at a
25539 readable place, rather than simply letting it overflow onto the
25540 following line.
25541
25542 Normally @value{GDBN} knows the size of the screen from the terminal
25543 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25544 together with the value of the @code{TERM} environment variable and the
25545 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25546 you can override it with the @code{set height} and @code{set
25547 width} commands:
25548
25549 @table @code
25550 @kindex set height
25551 @kindex set width
25552 @kindex show width
25553 @kindex show height
25554 @item set height @var{lpp}
25555 @itemx set height unlimited
25556 @itemx show height
25557 @itemx set width @var{cpl}
25558 @itemx set width unlimited
25559 @itemx show width
25560 These @code{set} commands specify a screen height of @var{lpp} lines and
25561 a screen width of @var{cpl} characters. The associated @code{show}
25562 commands display the current settings.
25563
25564 If you specify a height of either @code{unlimited} or zero lines,
25565 @value{GDBN} does not pause during output no matter how long the
25566 output is. This is useful if output is to a file or to an editor
25567 buffer.
25568
25569 Likewise, you can specify @samp{set width unlimited} or @samp{set
25570 width 0} to prevent @value{GDBN} from wrapping its output.
25571
25572 @item set pagination on
25573 @itemx set pagination off
25574 @kindex set pagination
25575 Turn the output pagination on or off; the default is on. Turning
25576 pagination off is the alternative to @code{set height unlimited}. Note that
25577 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25578 Options, -batch}) also automatically disables pagination.
25579
25580 @item show pagination
25581 @kindex show pagination
25582 Show the current pagination mode.
25583 @end table
25584
25585 @node Output Styling
25586 @section Output Styling
25587 @cindex styling
25588 @cindex colors
25589
25590 @kindex set style
25591 @kindex show style
25592 @value{GDBN} can style its output on a capable terminal. This is
25593 enabled by default on most systems, but disabled by default when in
25594 batch mode (@pxref{Mode Options}). Various style settings are available;
25595 and styles can also be disabled entirely.
25596
25597 @table @code
25598 @item set style enabled @samp{on|off}
25599 Enable or disable all styling. The default is host-dependent, with
25600 most hosts defaulting to @samp{on}.
25601
25602 @item show style enabled
25603 Show the current state of styling.
25604
25605 @item set style sources @samp{on|off}
25606 Enable or disable source code styling. This affects whether source
25607 code, such as the output of the @code{list} command, is styled. Note
25608 that source styling only works if styling in general is enabled, and
25609 if @value{GDBN} was linked with the GNU Source Highlight library. The
25610 default is @samp{on}.
25611
25612 @item show style sources
25613 Show the current state of source code styling.
25614 @end table
25615
25616 Subcommands of @code{set style} control specific forms of styling.
25617 These subcommands all follow the same pattern: each style-able object
25618 can be styled with a foreground color, a background color, and an
25619 intensity.
25620
25621 For example, the style of file names can be controlled using the
25622 @code{set style filename} group of commands:
25623
25624 @table @code
25625 @item set style filename background @var{color}
25626 Set the background to @var{color}. Valid colors are @samp{none}
25627 (meaning the terminal's default color), @samp{black}, @samp{red},
25628 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25629 and@samp{white}.
25630
25631 @item set style filename foreground @var{color}
25632 Set the foreground to @var{color}. Valid colors are @samp{none}
25633 (meaning the terminal's default color), @samp{black}, @samp{red},
25634 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25635 and@samp{white}.
25636
25637 @item set style filename intensity @var{value}
25638 Set the intensity to @var{value}. Valid intensities are @samp{normal}
25639 (the default), @samp{bold}, and @samp{dim}.
25640 @end table
25641
25642 The @code{show style} command and its subcommands are styling
25643 a style name in their output using its own style.
25644 So, use @command{show style} to see the complete list of styles,
25645 their characteristics and the visual aspect of each style.
25646
25647 The style-able objects are:
25648 @table @code
25649 @item filename
25650 Control the styling of file names. By default, this style's
25651 foreground color is green.
25652
25653 @item function
25654 Control the styling of function names. These are managed with the
25655 @code{set style function} family of commands. By default, this
25656 style's foreground color is yellow.
25657
25658 @item variable
25659 Control the styling of variable names. These are managed with the
25660 @code{set style variable} family of commands. By default, this style's
25661 foreground color is cyan.
25662
25663 @item address
25664 Control the styling of addresses. These are managed with the
25665 @code{set style address} family of commands. By default, this style's
25666 foreground color is blue.
25667
25668 @item title
25669 Control the styling of titles. These are managed with the
25670 @code{set style title} family of commands. By default, this style's
25671 intensity is bold. Commands are using the title style to improve
25672 the readability of large output. For example, the commands
25673 @command{apropos} and @command{help} are using the title style
25674 for the command names.
25675
25676 @item highlight
25677 Control the styling of highlightings. These are managed with the
25678 @code{set style highlight} family of commands. By default, this style's
25679 foreground color is red. Commands are using the highlight style to draw
25680 the user attention to some specific parts of their output. For example,
25681 the command @command{apropos -v REGEXP} uses the highlight style to
25682 mark the documentation parts matching @var{regexp}.
25683
25684 @item tui-border
25685 Control the styling of the TUI border. Note that, unlike other
25686 styling options, only the color of the border can be controlled via
25687 @code{set style}. This was done for compatibility reasons, as TUI
25688 controls to set the border's intensity predated the addition of
25689 general styling to @value{GDBN}. @xref{TUI Configuration}.
25690
25691 @item tui-active-border
25692 Control the styling of the active TUI border; that is, the TUI window
25693 that has the focus.
25694
25695 @end table
25696
25697 @node Numbers
25698 @section Numbers
25699 @cindex number representation
25700 @cindex entering numbers
25701
25702 You can always enter numbers in octal, decimal, or hexadecimal in
25703 @value{GDBN} by the usual conventions: octal numbers begin with
25704 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
25705 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25706 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
25707 10; likewise, the default display for numbers---when no particular
25708 format is specified---is base 10. You can change the default base for
25709 both input and output with the commands described below.
25710
25711 @table @code
25712 @kindex set input-radix
25713 @item set input-radix @var{base}
25714 Set the default base for numeric input. Supported choices
25715 for @var{base} are decimal 8, 10, or 16. The base must itself be
25716 specified either unambiguously or using the current input radix; for
25717 example, any of
25718
25719 @smallexample
25720 set input-radix 012
25721 set input-radix 10.
25722 set input-radix 0xa
25723 @end smallexample
25724
25725 @noindent
25726 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
25727 leaves the input radix unchanged, no matter what it was, since
25728 @samp{10}, being without any leading or trailing signs of its base, is
25729 interpreted in the current radix. Thus, if the current radix is 16,
25730 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25731 change the radix.
25732
25733 @kindex set output-radix
25734 @item set output-radix @var{base}
25735 Set the default base for numeric display. Supported choices
25736 for @var{base} are decimal 8, 10, or 16. The base must itself be
25737 specified either unambiguously or using the current input radix.
25738
25739 @kindex show input-radix
25740 @item show input-radix
25741 Display the current default base for numeric input.
25742
25743 @kindex show output-radix
25744 @item show output-radix
25745 Display the current default base for numeric display.
25746
25747 @item set radix @r{[}@var{base}@r{]}
25748 @itemx show radix
25749 @kindex set radix
25750 @kindex show radix
25751 These commands set and show the default base for both input and output
25752 of numbers. @code{set radix} sets the radix of input and output to
25753 the same base; without an argument, it resets the radix back to its
25754 default value of 10.
25755
25756 @end table
25757
25758 @node ABI
25759 @section Configuring the Current ABI
25760
25761 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25762 application automatically. However, sometimes you need to override its
25763 conclusions. Use these commands to manage @value{GDBN}'s view of the
25764 current ABI.
25765
25766 @cindex OS ABI
25767 @kindex set osabi
25768 @kindex show osabi
25769 @cindex Newlib OS ABI and its influence on the longjmp handling
25770
25771 One @value{GDBN} configuration can debug binaries for multiple operating
25772 system targets, either via remote debugging or native emulation.
25773 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25774 but you can override its conclusion using the @code{set osabi} command.
25775 One example where this is useful is in debugging of binaries which use
25776 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25777 not have the same identifying marks that the standard C library for your
25778 platform provides.
25779
25780 When @value{GDBN} is debugging the AArch64 architecture, it provides a
25781 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25782 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25783 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25784
25785 @table @code
25786 @item show osabi
25787 Show the OS ABI currently in use.
25788
25789 @item set osabi
25790 With no argument, show the list of registered available OS ABI's.
25791
25792 @item set osabi @var{abi}
25793 Set the current OS ABI to @var{abi}.
25794 @end table
25795
25796 @cindex float promotion
25797
25798 Generally, the way that an argument of type @code{float} is passed to a
25799 function depends on whether the function is prototyped. For a prototyped
25800 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25801 according to the architecture's convention for @code{float}. For unprototyped
25802 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25803 @code{double} and then passed.
25804
25805 Unfortunately, some forms of debug information do not reliably indicate whether
25806 a function is prototyped. If @value{GDBN} calls a function that is not marked
25807 as prototyped, it consults @kbd{set coerce-float-to-double}.
25808
25809 @table @code
25810 @kindex set coerce-float-to-double
25811 @item set coerce-float-to-double
25812 @itemx set coerce-float-to-double on
25813 Arguments of type @code{float} will be promoted to @code{double} when passed
25814 to an unprototyped function. This is the default setting.
25815
25816 @item set coerce-float-to-double off
25817 Arguments of type @code{float} will be passed directly to unprototyped
25818 functions.
25819
25820 @kindex show coerce-float-to-double
25821 @item show coerce-float-to-double
25822 Show the current setting of promoting @code{float} to @code{double}.
25823 @end table
25824
25825 @kindex set cp-abi
25826 @kindex show cp-abi
25827 @value{GDBN} needs to know the ABI used for your program's C@t{++}
25828 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25829 used to build your application. @value{GDBN} only fully supports
25830 programs with a single C@t{++} ABI; if your program contains code using
25831 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25832 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25833 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25834 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25835 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25836 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25837 ``auto''.
25838
25839 @table @code
25840 @item show cp-abi
25841 Show the C@t{++} ABI currently in use.
25842
25843 @item set cp-abi
25844 With no argument, show the list of supported C@t{++} ABI's.
25845
25846 @item set cp-abi @var{abi}
25847 @itemx set cp-abi auto
25848 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25849 @end table
25850
25851 @node Auto-loading
25852 @section Automatically loading associated files
25853 @cindex auto-loading
25854
25855 @value{GDBN} sometimes reads files with commands and settings automatically,
25856 without being explicitly told so by the user. We call this feature
25857 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
25858 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
25859 results or introduce security risks (e.g., if the file comes from untrusted
25860 sources).
25861
25862 @menu
25863 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25864 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25865
25866 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25867 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
25868 @end menu
25869
25870 There are various kinds of files @value{GDBN} can automatically load.
25871 In addition to these files, @value{GDBN} supports auto-loading code written
25872 in various extension languages. @xref{Auto-loading extensions}.
25873
25874 Note that loading of these associated files (including the local @file{.gdbinit}
25875 file) requires accordingly configured @code{auto-load safe-path}
25876 (@pxref{Auto-loading safe path}).
25877
25878 For these reasons, @value{GDBN} includes commands and options to let you
25879 control when to auto-load files and which files should be auto-loaded.
25880
25881 @table @code
25882 @anchor{set auto-load off}
25883 @kindex set auto-load off
25884 @item set auto-load off
25885 Globally disable loading of all auto-loaded files.
25886 You may want to use this command with the @samp{-iex} option
25887 (@pxref{Option -init-eval-command}) such as:
25888 @smallexample
25889 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25890 @end smallexample
25891
25892 Be aware that system init file (@pxref{System-wide configuration})
25893 and init files from your home directory (@pxref{Home Directory Init File})
25894 still get read (as they come from generally trusted directories).
25895 To prevent @value{GDBN} from auto-loading even those init files, use the
25896 @option{-nx} option (@pxref{Mode Options}), in addition to
25897 @code{set auto-load no}.
25898
25899 @anchor{show auto-load}
25900 @kindex show auto-load
25901 @item show auto-load
25902 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25903 or disabled.
25904
25905 @smallexample
25906 (gdb) show auto-load
25907 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25908 libthread-db: Auto-loading of inferior specific libthread_db is on.
25909 local-gdbinit: Auto-loading of .gdbinit script from current directory
25910 is on.
25911 python-scripts: Auto-loading of Python scripts is on.
25912 safe-path: List of directories from which it is safe to auto-load files
25913 is $debugdir:$datadir/auto-load.
25914 scripts-directory: List of directories from which to load auto-loaded scripts
25915 is $debugdir:$datadir/auto-load.
25916 @end smallexample
25917
25918 @anchor{info auto-load}
25919 @kindex info auto-load
25920 @item info auto-load
25921 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25922 not.
25923
25924 @smallexample
25925 (gdb) info auto-load
25926 gdb-scripts:
25927 Loaded Script
25928 Yes /home/user/gdb/gdb-gdb.gdb
25929 libthread-db: No auto-loaded libthread-db.
25930 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25931 loaded.
25932 python-scripts:
25933 Loaded Script
25934 Yes /home/user/gdb/gdb-gdb.py
25935 @end smallexample
25936 @end table
25937
25938 These are @value{GDBN} control commands for the auto-loading:
25939
25940 @multitable @columnfractions .5 .5
25941 @item @xref{set auto-load off}.
25942 @tab Disable auto-loading globally.
25943 @item @xref{show auto-load}.
25944 @tab Show setting of all kinds of files.
25945 @item @xref{info auto-load}.
25946 @tab Show state of all kinds of files.
25947 @item @xref{set auto-load gdb-scripts}.
25948 @tab Control for @value{GDBN} command scripts.
25949 @item @xref{show auto-load gdb-scripts}.
25950 @tab Show setting of @value{GDBN} command scripts.
25951 @item @xref{info auto-load gdb-scripts}.
25952 @tab Show state of @value{GDBN} command scripts.
25953 @item @xref{set auto-load python-scripts}.
25954 @tab Control for @value{GDBN} Python scripts.
25955 @item @xref{show auto-load python-scripts}.
25956 @tab Show setting of @value{GDBN} Python scripts.
25957 @item @xref{info auto-load python-scripts}.
25958 @tab Show state of @value{GDBN} Python scripts.
25959 @item @xref{set auto-load guile-scripts}.
25960 @tab Control for @value{GDBN} Guile scripts.
25961 @item @xref{show auto-load guile-scripts}.
25962 @tab Show setting of @value{GDBN} Guile scripts.
25963 @item @xref{info auto-load guile-scripts}.
25964 @tab Show state of @value{GDBN} Guile scripts.
25965 @item @xref{set auto-load scripts-directory}.
25966 @tab Control for @value{GDBN} auto-loaded scripts location.
25967 @item @xref{show auto-load scripts-directory}.
25968 @tab Show @value{GDBN} auto-loaded scripts location.
25969 @item @xref{add-auto-load-scripts-directory}.
25970 @tab Add directory for auto-loaded scripts location list.
25971 @item @xref{set auto-load local-gdbinit}.
25972 @tab Control for init file in the current directory.
25973 @item @xref{show auto-load local-gdbinit}.
25974 @tab Show setting of init file in the current directory.
25975 @item @xref{info auto-load local-gdbinit}.
25976 @tab Show state of init file in the current directory.
25977 @item @xref{set auto-load libthread-db}.
25978 @tab Control for thread debugging library.
25979 @item @xref{show auto-load libthread-db}.
25980 @tab Show setting of thread debugging library.
25981 @item @xref{info auto-load libthread-db}.
25982 @tab Show state of thread debugging library.
25983 @item @xref{set auto-load safe-path}.
25984 @tab Control directories trusted for automatic loading.
25985 @item @xref{show auto-load safe-path}.
25986 @tab Show directories trusted for automatic loading.
25987 @item @xref{add-auto-load-safe-path}.
25988 @tab Add directory trusted for automatic loading.
25989 @end multitable
25990
25991 @node Init File in the Current Directory
25992 @subsection Automatically loading init file in the current directory
25993 @cindex auto-loading init file in the current directory
25994
25995 By default, @value{GDBN} reads and executes the canned sequences of commands
25996 from init file (if any) in the current working directory,
25997 see @ref{Init File in the Current Directory during Startup}.
25998
25999 Note that loading of this local @file{.gdbinit} file also requires accordingly
26000 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26001
26002 @table @code
26003 @anchor{set auto-load local-gdbinit}
26004 @kindex set auto-load local-gdbinit
26005 @item set auto-load local-gdbinit [on|off]
26006 Enable or disable the auto-loading of canned sequences of commands
26007 (@pxref{Sequences}) found in init file in the current directory.
26008
26009 @anchor{show auto-load local-gdbinit}
26010 @kindex show auto-load local-gdbinit
26011 @item show auto-load local-gdbinit
26012 Show whether auto-loading of canned sequences of commands from init file in the
26013 current directory is enabled or disabled.
26014
26015 @anchor{info auto-load local-gdbinit}
26016 @kindex info auto-load local-gdbinit
26017 @item info auto-load local-gdbinit
26018 Print whether canned sequences of commands from init file in the
26019 current directory have been auto-loaded.
26020 @end table
26021
26022 @node libthread_db.so.1 file
26023 @subsection Automatically loading thread debugging library
26024 @cindex auto-loading libthread_db.so.1
26025
26026 This feature is currently present only on @sc{gnu}/Linux native hosts.
26027
26028 @value{GDBN} reads in some cases thread debugging library from places specific
26029 to the inferior (@pxref{set libthread-db-search-path}).
26030
26031 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26032 without checking this @samp{set auto-load libthread-db} switch as system
26033 libraries have to be trusted in general. In all other cases of
26034 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26035 auto-load libthread-db} is enabled before trying to open such thread debugging
26036 library.
26037
26038 Note that loading of this debugging library also requires accordingly configured
26039 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26040
26041 @table @code
26042 @anchor{set auto-load libthread-db}
26043 @kindex set auto-load libthread-db
26044 @item set auto-load libthread-db [on|off]
26045 Enable or disable the auto-loading of inferior specific thread debugging library.
26046
26047 @anchor{show auto-load libthread-db}
26048 @kindex show auto-load libthread-db
26049 @item show auto-load libthread-db
26050 Show whether auto-loading of inferior specific thread debugging library is
26051 enabled or disabled.
26052
26053 @anchor{info auto-load libthread-db}
26054 @kindex info auto-load libthread-db
26055 @item info auto-load libthread-db
26056 Print the list of all loaded inferior specific thread debugging libraries and
26057 for each such library print list of inferior @var{pid}s using it.
26058 @end table
26059
26060 @node Auto-loading safe path
26061 @subsection Security restriction for auto-loading
26062 @cindex auto-loading safe-path
26063
26064 As the files of inferior can come from untrusted source (such as submitted by
26065 an application user) @value{GDBN} does not always load any files automatically.
26066 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26067 directories trusted for loading files not explicitly requested by user.
26068 Each directory can also be a shell wildcard pattern.
26069
26070 If the path is not set properly you will see a warning and the file will not
26071 get loaded:
26072
26073 @smallexample
26074 $ ./gdb -q ./gdb
26075 Reading symbols from /home/user/gdb/gdb...
26076 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26077 declined by your `auto-load safe-path' set
26078 to "$debugdir:$datadir/auto-load".
26079 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26080 declined by your `auto-load safe-path' set
26081 to "$debugdir:$datadir/auto-load".
26082 @end smallexample
26083
26084 @noindent
26085 To instruct @value{GDBN} to go ahead and use the init files anyway,
26086 invoke @value{GDBN} like this:
26087
26088 @smallexample
26089 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26090 @end smallexample
26091
26092 The list of trusted directories is controlled by the following commands:
26093
26094 @table @code
26095 @anchor{set auto-load safe-path}
26096 @kindex set auto-load safe-path
26097 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26098 Set the list of directories (and their subdirectories) trusted for automatic
26099 loading and execution of scripts. You can also enter a specific trusted file.
26100 Each directory can also be a shell wildcard pattern; wildcards do not match
26101 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26102 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26103 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26104 its default value as specified during @value{GDBN} compilation.
26105
26106 The list of directories uses path separator (@samp{:} on GNU and Unix
26107 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26108 to the @env{PATH} environment variable.
26109
26110 @anchor{show auto-load safe-path}
26111 @kindex show auto-load safe-path
26112 @item show auto-load safe-path
26113 Show the list of directories trusted for automatic loading and execution of
26114 scripts.
26115
26116 @anchor{add-auto-load-safe-path}
26117 @kindex add-auto-load-safe-path
26118 @item add-auto-load-safe-path
26119 Add an entry (or list of entries) to the list of directories trusted for
26120 automatic loading and execution of scripts. Multiple entries may be delimited
26121 by the host platform path separator in use.
26122 @end table
26123
26124 This variable defaults to what @code{--with-auto-load-dir} has been configured
26125 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26126 substitution applies the same as for @ref{set auto-load scripts-directory}.
26127 The default @code{set auto-load safe-path} value can be also overriden by
26128 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26129
26130 Setting this variable to @file{/} disables this security protection,
26131 corresponding @value{GDBN} configuration option is
26132 @option{--without-auto-load-safe-path}.
26133 This variable is supposed to be set to the system directories writable by the
26134 system superuser only. Users can add their source directories in init files in
26135 their home directories (@pxref{Home Directory Init File}). See also deprecated
26136 init file in the current directory
26137 (@pxref{Init File in the Current Directory during Startup}).
26138
26139 To force @value{GDBN} to load the files it declined to load in the previous
26140 example, you could use one of the following ways:
26141
26142 @table @asis
26143 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26144 Specify this trusted directory (or a file) as additional component of the list.
26145 You have to specify also any existing directories displayed by
26146 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26147
26148 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26149 Specify this directory as in the previous case but just for a single
26150 @value{GDBN} session.
26151
26152 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26153 Disable auto-loading safety for a single @value{GDBN} session.
26154 This assumes all the files you debug during this @value{GDBN} session will come
26155 from trusted sources.
26156
26157 @item @kbd{./configure --without-auto-load-safe-path}
26158 During compilation of @value{GDBN} you may disable any auto-loading safety.
26159 This assumes all the files you will ever debug with this @value{GDBN} come from
26160 trusted sources.
26161 @end table
26162
26163 On the other hand you can also explicitly forbid automatic files loading which
26164 also suppresses any such warning messages:
26165
26166 @table @asis
26167 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26168 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26169
26170 @item @file{~/.gdbinit}: @samp{set auto-load no}
26171 Disable auto-loading globally for the user
26172 (@pxref{Home Directory Init File}). While it is improbable, you could also
26173 use system init file instead (@pxref{System-wide configuration}).
26174 @end table
26175
26176 This setting applies to the file names as entered by user. If no entry matches
26177 @value{GDBN} tries as a last resort to also resolve all the file names into
26178 their canonical form (typically resolving symbolic links) and compare the
26179 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26180 own before starting the comparison so a canonical form of directories is
26181 recommended to be entered.
26182
26183 @node Auto-loading verbose mode
26184 @subsection Displaying files tried for auto-load
26185 @cindex auto-loading verbose mode
26186
26187 For better visibility of all the file locations where you can place scripts to
26188 be auto-loaded with inferior --- or to protect yourself against accidental
26189 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26190 all the files attempted to be loaded. Both existing and non-existing files may
26191 be printed.
26192
26193 For example the list of directories from which it is safe to auto-load files
26194 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26195 may not be too obvious while setting it up.
26196
26197 @smallexample
26198 (gdb) set debug auto-load on
26199 (gdb) file ~/src/t/true
26200 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26201 for objfile "/tmp/true".
26202 auto-load: Updating directories of "/usr:/opt".
26203 auto-load: Using directory "/usr".
26204 auto-load: Using directory "/opt".
26205 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26206 by your `auto-load safe-path' set to "/usr:/opt".
26207 @end smallexample
26208
26209 @table @code
26210 @anchor{set debug auto-load}
26211 @kindex set debug auto-load
26212 @item set debug auto-load [on|off]
26213 Set whether to print the filenames attempted to be auto-loaded.
26214
26215 @anchor{show debug auto-load}
26216 @kindex show debug auto-load
26217 @item show debug auto-load
26218 Show whether printing of the filenames attempted to be auto-loaded is turned
26219 on or off.
26220 @end table
26221
26222 @node Messages/Warnings
26223 @section Optional Warnings and Messages
26224
26225 @cindex verbose operation
26226 @cindex optional warnings
26227 By default, @value{GDBN} is silent about its inner workings. If you are
26228 running on a slow machine, you may want to use the @code{set verbose}
26229 command. This makes @value{GDBN} tell you when it does a lengthy
26230 internal operation, so you will not think it has crashed.
26231
26232 Currently, the messages controlled by @code{set verbose} are those
26233 which announce that the symbol table for a source file is being read;
26234 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26235
26236 @table @code
26237 @kindex set verbose
26238 @item set verbose on
26239 Enables @value{GDBN} output of certain informational messages.
26240
26241 @item set verbose off
26242 Disables @value{GDBN} output of certain informational messages.
26243
26244 @kindex show verbose
26245 @item show verbose
26246 Displays whether @code{set verbose} is on or off.
26247 @end table
26248
26249 By default, if @value{GDBN} encounters bugs in the symbol table of an
26250 object file, it is silent; but if you are debugging a compiler, you may
26251 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26252 Symbol Files}).
26253
26254 @table @code
26255
26256 @kindex set complaints
26257 @item set complaints @var{limit}
26258 Permits @value{GDBN} to output @var{limit} complaints about each type of
26259 unusual symbols before becoming silent about the problem. Set
26260 @var{limit} to zero to suppress all complaints; set it to a large number
26261 to prevent complaints from being suppressed.
26262
26263 @kindex show complaints
26264 @item show complaints
26265 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26266
26267 @end table
26268
26269 @anchor{confirmation requests}
26270 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26271 lot of stupid questions to confirm certain commands. For example, if
26272 you try to run a program which is already running:
26273
26274 @smallexample
26275 (@value{GDBP}) run
26276 The program being debugged has been started already.
26277 Start it from the beginning? (y or n)
26278 @end smallexample
26279
26280 If you are willing to unflinchingly face the consequences of your own
26281 commands, you can disable this ``feature'':
26282
26283 @table @code
26284
26285 @kindex set confirm
26286 @cindex flinching
26287 @cindex confirmation
26288 @cindex stupid questions
26289 @item set confirm off
26290 Disables confirmation requests. Note that running @value{GDBN} with
26291 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26292 automatically disables confirmation requests.
26293
26294 @item set confirm on
26295 Enables confirmation requests (the default).
26296
26297 @kindex show confirm
26298 @item show confirm
26299 Displays state of confirmation requests.
26300
26301 @end table
26302
26303 @cindex command tracing
26304 If you need to debug user-defined commands or sourced files you may find it
26305 useful to enable @dfn{command tracing}. In this mode each command will be
26306 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26307 quantity denoting the call depth of each command.
26308
26309 @table @code
26310 @kindex set trace-commands
26311 @cindex command scripts, debugging
26312 @item set trace-commands on
26313 Enable command tracing.
26314 @item set trace-commands off
26315 Disable command tracing.
26316 @item show trace-commands
26317 Display the current state of command tracing.
26318 @end table
26319
26320 @node Debugging Output
26321 @section Optional Messages about Internal Happenings
26322 @cindex optional debugging messages
26323
26324 @value{GDBN} has commands that enable optional debugging messages from
26325 various @value{GDBN} subsystems; normally these commands are of
26326 interest to @value{GDBN} maintainers, or when reporting a bug. This
26327 section documents those commands.
26328
26329 @table @code
26330 @kindex set exec-done-display
26331 @item set exec-done-display
26332 Turns on or off the notification of asynchronous commands'
26333 completion. When on, @value{GDBN} will print a message when an
26334 asynchronous command finishes its execution. The default is off.
26335 @kindex show exec-done-display
26336 @item show exec-done-display
26337 Displays the current setting of asynchronous command completion
26338 notification.
26339 @kindex set debug
26340 @cindex ARM AArch64
26341 @item set debug aarch64
26342 Turns on or off display of debugging messages related to ARM AArch64.
26343 The default is off.
26344 @kindex show debug
26345 @item show debug aarch64
26346 Displays the current state of displaying debugging messages related to
26347 ARM AArch64.
26348 @cindex gdbarch debugging info
26349 @cindex architecture debugging info
26350 @item set debug arch
26351 Turns on or off display of gdbarch debugging info. The default is off
26352 @item show debug arch
26353 Displays the current state of displaying gdbarch debugging info.
26354 @item set debug aix-solib
26355 @cindex AIX shared library debugging
26356 Control display of debugging messages from the AIX shared library
26357 support module. The default is off.
26358 @item show debug aix-thread
26359 Show the current state of displaying AIX shared library debugging messages.
26360 @item set debug aix-thread
26361 @cindex AIX threads
26362 Display debugging messages about inner workings of the AIX thread
26363 module.
26364 @item show debug aix-thread
26365 Show the current state of AIX thread debugging info display.
26366 @item set debug check-physname
26367 @cindex physname
26368 Check the results of the ``physname'' computation. When reading DWARF
26369 debugging information for C@t{++}, @value{GDBN} attempts to compute
26370 each entity's name. @value{GDBN} can do this computation in two
26371 different ways, depending on exactly what information is present.
26372 When enabled, this setting causes @value{GDBN} to compute the names
26373 both ways and display any discrepancies.
26374 @item show debug check-physname
26375 Show the current state of ``physname'' checking.
26376 @item set debug coff-pe-read
26377 @cindex COFF/PE exported symbols
26378 Control display of debugging messages related to reading of COFF/PE
26379 exported symbols. The default is off.
26380 @item show debug coff-pe-read
26381 Displays the current state of displaying debugging messages related to
26382 reading of COFF/PE exported symbols.
26383 @item set debug dwarf-die
26384 @cindex DWARF DIEs
26385 Dump DWARF DIEs after they are read in.
26386 The value is the number of nesting levels to print.
26387 A value of zero turns off the display.
26388 @item show debug dwarf-die
26389 Show the current state of DWARF DIE debugging.
26390 @item set debug dwarf-line
26391 @cindex DWARF Line Tables
26392 Turns on or off display of debugging messages related to reading
26393 DWARF line tables. The default is 0 (off).
26394 A value of 1 provides basic information.
26395 A value greater than 1 provides more verbose information.
26396 @item show debug dwarf-line
26397 Show the current state of DWARF line table debugging.
26398 @item set debug dwarf-read
26399 @cindex DWARF Reading
26400 Turns on or off display of debugging messages related to reading
26401 DWARF debug info. The default is 0 (off).
26402 A value of 1 provides basic information.
26403 A value greater than 1 provides more verbose information.
26404 @item show debug dwarf-read
26405 Show the current state of DWARF reader debugging.
26406 @item set debug displaced
26407 @cindex displaced stepping debugging info
26408 Turns on or off display of @value{GDBN} debugging info for the
26409 displaced stepping support. The default is off.
26410 @item show debug displaced
26411 Displays the current state of displaying @value{GDBN} debugging info
26412 related to displaced stepping.
26413 @item set debug event
26414 @cindex event debugging info
26415 Turns on or off display of @value{GDBN} event debugging info. The
26416 default is off.
26417 @item show debug event
26418 Displays the current state of displaying @value{GDBN} event debugging
26419 info.
26420 @item set debug expression
26421 @cindex expression debugging info
26422 Turns on or off display of debugging info about @value{GDBN}
26423 expression parsing. The default is off.
26424 @item show debug expression
26425 Displays the current state of displaying debugging info about
26426 @value{GDBN} expression parsing.
26427 @item set debug fbsd-lwp
26428 @cindex FreeBSD LWP debug messages
26429 Turns on or off debugging messages from the FreeBSD LWP debug support.
26430 @item show debug fbsd-lwp
26431 Show the current state of FreeBSD LWP debugging messages.
26432 @item set debug fbsd-nat
26433 @cindex FreeBSD native target debug messages
26434 Turns on or off debugging messages from the FreeBSD native target.
26435 @item show debug fbsd-nat
26436 Show the current state of FreeBSD native target debugging messages.
26437 @item set debug frame
26438 @cindex frame debugging info
26439 Turns on or off display of @value{GDBN} frame debugging info. The
26440 default is off.
26441 @item show debug frame
26442 Displays the current state of displaying @value{GDBN} frame debugging
26443 info.
26444 @item set debug gnu-nat
26445 @cindex @sc{gnu}/Hurd debug messages
26446 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26447 @item show debug gnu-nat
26448 Show the current state of @sc{gnu}/Hurd debugging messages.
26449 @item set debug infrun
26450 @cindex inferior debugging info
26451 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26452 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26453 for implementing operations such as single-stepping the inferior.
26454 @item show debug infrun
26455 Displays the current state of @value{GDBN} inferior debugging.
26456 @item set debug jit
26457 @cindex just-in-time compilation, debugging messages
26458 Turn on or off debugging messages from JIT debug support.
26459 @item show debug jit
26460 Displays the current state of @value{GDBN} JIT debugging.
26461 @item set debug lin-lwp
26462 @cindex @sc{gnu}/Linux LWP debug messages
26463 @cindex Linux lightweight processes
26464 Turn on or off debugging messages from the Linux LWP debug support.
26465 @item show debug lin-lwp
26466 Show the current state of Linux LWP debugging messages.
26467 @item set debug linux-namespaces
26468 @cindex @sc{gnu}/Linux namespaces debug messages
26469 Turn on or off debugging messages from the Linux namespaces debug support.
26470 @item show debug linux-namespaces
26471 Show the current state of Linux namespaces debugging messages.
26472 @item set debug mach-o
26473 @cindex Mach-O symbols processing
26474 Control display of debugging messages related to Mach-O symbols
26475 processing. The default is off.
26476 @item show debug mach-o
26477 Displays the current state of displaying debugging messages related to
26478 reading of COFF/PE exported symbols.
26479 @item set debug notification
26480 @cindex remote async notification debugging info
26481 Turn on or off debugging messages about remote async notification.
26482 The default is off.
26483 @item show debug notification
26484 Displays the current state of remote async notification debugging messages.
26485 @item set debug observer
26486 @cindex observer debugging info
26487 Turns on or off display of @value{GDBN} observer debugging. This
26488 includes info such as the notification of observable events.
26489 @item show debug observer
26490 Displays the current state of observer debugging.
26491 @item set debug overload
26492 @cindex C@t{++} overload debugging info
26493 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26494 info. This includes info such as ranking of functions, etc. The default
26495 is off.
26496 @item show debug overload
26497 Displays the current state of displaying @value{GDBN} C@t{++} overload
26498 debugging info.
26499 @cindex expression parser, debugging info
26500 @cindex debug expression parser
26501 @item set debug parser
26502 Turns on or off the display of expression parser debugging output.
26503 Internally, this sets the @code{yydebug} variable in the expression
26504 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26505 details. The default is off.
26506 @item show debug parser
26507 Show the current state of expression parser debugging.
26508 @cindex packets, reporting on stdout
26509 @cindex serial connections, debugging
26510 @cindex debug remote protocol
26511 @cindex remote protocol debugging
26512 @cindex display remote packets
26513 @item set debug remote
26514 Turns on or off display of reports on all packets sent back and forth across
26515 the serial line to the remote machine. The info is printed on the
26516 @value{GDBN} standard output stream. The default is off.
26517 @item show debug remote
26518 Displays the state of display of remote packets.
26519
26520 @item set debug remote-packet-max-chars
26521 Sets the maximum number of characters to display for each remote packet when
26522 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26523 displaying lengthy remote packets and polluting the console.
26524
26525 The default value is @code{512}, which means @value{GDBN} will truncate each
26526 remote packet after 512 bytes.
26527
26528 Setting this option to @code{unlimited} will disable truncation and will output
26529 the full length of the remote packets.
26530 @item show debug remote-packet-max-chars
26531 Displays the number of bytes to output for remote packet debugging.
26532
26533 @item set debug separate-debug-file
26534 Turns on or off display of debug output about separate debug file search.
26535 @item show debug separate-debug-file
26536 Displays the state of separate debug file search debug output.
26537
26538 @item set debug serial
26539 Turns on or off display of @value{GDBN} serial debugging info. The
26540 default is off.
26541 @item show debug serial
26542 Displays the current state of displaying @value{GDBN} serial debugging
26543 info.
26544 @item set debug solib-frv
26545 @cindex FR-V shared-library debugging
26546 Turn on or off debugging messages for FR-V shared-library code.
26547 @item show debug solib-frv
26548 Display the current state of FR-V shared-library code debugging
26549 messages.
26550 @item set debug symbol-lookup
26551 @cindex symbol lookup
26552 Turns on or off display of debugging messages related to symbol lookup.
26553 The default is 0 (off).
26554 A value of 1 provides basic information.
26555 A value greater than 1 provides more verbose information.
26556 @item show debug symbol-lookup
26557 Show the current state of symbol lookup debugging messages.
26558 @item set debug symfile
26559 @cindex symbol file functions
26560 Turns on or off display of debugging messages related to symbol file functions.
26561 The default is off. @xref{Files}.
26562 @item show debug symfile
26563 Show the current state of symbol file debugging messages.
26564 @item set debug symtab-create
26565 @cindex symbol table creation
26566 Turns on or off display of debugging messages related to symbol table creation.
26567 The default is 0 (off).
26568 A value of 1 provides basic information.
26569 A value greater than 1 provides more verbose information.
26570 @item show debug symtab-create
26571 Show the current state of symbol table creation debugging.
26572 @item set debug target
26573 @cindex target debugging info
26574 Turns on or off display of @value{GDBN} target debugging info. This info
26575 includes what is going on at the target level of GDB, as it happens. The
26576 default is 0. Set it to 1 to track events, and to 2 to also track the
26577 value of large memory transfers.
26578 @item show debug target
26579 Displays the current state of displaying @value{GDBN} target debugging
26580 info.
26581 @item set debug timestamp
26582 @cindex timestamping debugging info
26583 Turns on or off display of timestamps with @value{GDBN} debugging info.
26584 When enabled, seconds and microseconds are displayed before each debugging
26585 message.
26586 @item show debug timestamp
26587 Displays the current state of displaying timestamps with @value{GDBN}
26588 debugging info.
26589 @item set debug varobj
26590 @cindex variable object debugging info
26591 Turns on or off display of @value{GDBN} variable object debugging
26592 info. The default is off.
26593 @item show debug varobj
26594 Displays the current state of displaying @value{GDBN} variable object
26595 debugging info.
26596 @item set debug xml
26597 @cindex XML parser debugging
26598 Turn on or off debugging messages for built-in XML parsers.
26599 @item show debug xml
26600 Displays the current state of XML debugging messages.
26601 @end table
26602
26603 @node Other Misc Settings
26604 @section Other Miscellaneous Settings
26605 @cindex miscellaneous settings
26606
26607 @table @code
26608 @kindex set interactive-mode
26609 @item set interactive-mode
26610 If @code{on}, forces @value{GDBN} to assume that GDB was started
26611 in a terminal. In practice, this means that @value{GDBN} should wait
26612 for the user to answer queries generated by commands entered at
26613 the command prompt. If @code{off}, forces @value{GDBN} to operate
26614 in the opposite mode, and it uses the default answers to all queries.
26615 If @code{auto} (the default), @value{GDBN} tries to determine whether
26616 its standard input is a terminal, and works in interactive-mode if it
26617 is, non-interactively otherwise.
26618
26619 In the vast majority of cases, the debugger should be able to guess
26620 correctly which mode should be used. But this setting can be useful
26621 in certain specific cases, such as running a MinGW @value{GDBN}
26622 inside a cygwin window.
26623
26624 @kindex show interactive-mode
26625 @item show interactive-mode
26626 Displays whether the debugger is operating in interactive mode or not.
26627 @end table
26628
26629 @node Extending GDB
26630 @chapter Extending @value{GDBN}
26631 @cindex extending GDB
26632
26633 @value{GDBN} provides several mechanisms for extension.
26634 @value{GDBN} also provides the ability to automatically load
26635 extensions when it reads a file for debugging. This allows the
26636 user to automatically customize @value{GDBN} for the program
26637 being debugged.
26638
26639 @menu
26640 * Sequences:: Canned Sequences of @value{GDBN} Commands
26641 * Python:: Extending @value{GDBN} using Python
26642 * Guile:: Extending @value{GDBN} using Guile
26643 * Auto-loading extensions:: Automatically loading extensions
26644 * Multiple Extension Languages:: Working with multiple extension languages
26645 * Aliases:: Creating new spellings of existing commands
26646 @end menu
26647
26648 To facilitate the use of extension languages, @value{GDBN} is capable
26649 of evaluating the contents of a file. When doing so, @value{GDBN}
26650 can recognize which extension language is being used by looking at
26651 the filename extension. Files with an unrecognized filename extension
26652 are always treated as a @value{GDBN} Command Files.
26653 @xref{Command Files,, Command files}.
26654
26655 You can control how @value{GDBN} evaluates these files with the following
26656 setting:
26657
26658 @table @code
26659 @kindex set script-extension
26660 @kindex show script-extension
26661 @item set script-extension off
26662 All scripts are always evaluated as @value{GDBN} Command Files.
26663
26664 @item set script-extension soft
26665 The debugger determines the scripting language based on filename
26666 extension. If this scripting language is supported, @value{GDBN}
26667 evaluates the script using that language. Otherwise, it evaluates
26668 the file as a @value{GDBN} Command File.
26669
26670 @item set script-extension strict
26671 The debugger determines the scripting language based on filename
26672 extension, and evaluates the script using that language. If the
26673 language is not supported, then the evaluation fails.
26674
26675 @item show script-extension
26676 Display the current value of the @code{script-extension} option.
26677
26678 @end table
26679
26680 @ifset SYSTEM_GDBINIT_DIR
26681 This setting is not used for files in the system-wide gdbinit directory.
26682 Files in that directory must have an extension matching their language,
26683 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26684 commands. @xref{Startup}.
26685 @end ifset
26686
26687 @node Sequences
26688 @section Canned Sequences of Commands
26689
26690 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
26691 Command Lists}), @value{GDBN} provides two ways to store sequences of
26692 commands for execution as a unit: user-defined commands and command
26693 files.
26694
26695 @menu
26696 * Define:: How to define your own commands
26697 * Hooks:: Hooks for user-defined commands
26698 * Command Files:: How to write scripts of commands to be stored in a file
26699 * Output:: Commands for controlled output
26700 * Auto-loading sequences:: Controlling auto-loaded command files
26701 @end menu
26702
26703 @node Define
26704 @subsection User-defined Commands
26705
26706 @cindex user-defined command
26707 @cindex arguments, to user-defined commands
26708 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26709 which you assign a new name as a command. This is done with the
26710 @code{define} command. User commands may accept an unlimited number of arguments
26711 separated by whitespace. Arguments are accessed within the user command
26712 via @code{$arg0@dots{}$argN}. A trivial example:
26713
26714 @smallexample
26715 define adder
26716 print $arg0 + $arg1 + $arg2
26717 end
26718 @end smallexample
26719
26720 @noindent
26721 To execute the command use:
26722
26723 @smallexample
26724 adder 1 2 3
26725 @end smallexample
26726
26727 @noindent
26728 This defines the command @code{adder}, which prints the sum of
26729 its three arguments. Note the arguments are text substitutions, so they may
26730 reference variables, use complex expressions, or even perform inferior
26731 functions calls.
26732
26733 @cindex argument count in user-defined commands
26734 @cindex how many arguments (user-defined commands)
26735 In addition, @code{$argc} may be used to find out how many arguments have
26736 been passed.
26737
26738 @smallexample
26739 define adder
26740 if $argc == 2
26741 print $arg0 + $arg1
26742 end
26743 if $argc == 3
26744 print $arg0 + $arg1 + $arg2
26745 end
26746 end
26747 @end smallexample
26748
26749 Combining with the @code{eval} command (@pxref{eval}) makes it easier
26750 to process a variable number of arguments:
26751
26752 @smallexample
26753 define adder
26754 set $i = 0
26755 set $sum = 0
26756 while $i < $argc
26757 eval "set $sum = $sum + $arg%d", $i
26758 set $i = $i + 1
26759 end
26760 print $sum
26761 end
26762 @end smallexample
26763
26764 @table @code
26765
26766 @kindex define
26767 @item define @var{commandname}
26768 Define a command named @var{commandname}. If there is already a command
26769 by that name, you are asked to confirm that you want to redefine it.
26770 The argument @var{commandname} may be a bare command name consisting of letters,
26771 numbers, dashes, dots, and underscores. It may also start with any
26772 predefined or user-defined prefix command.
26773 For example, @samp{define target my-target} creates
26774 a user-defined @samp{target my-target} command.
26775
26776 The definition of the command is made up of other @value{GDBN} command lines,
26777 which are given following the @code{define} command. The end of these
26778 commands is marked by a line containing @code{end}.
26779
26780 @kindex document
26781 @kindex end@r{ (user-defined commands)}
26782 @item document @var{commandname}
26783 Document the user-defined command @var{commandname}, so that it can be
26784 accessed by @code{help}. The command @var{commandname} must already be
26785 defined. This command reads lines of documentation just as @code{define}
26786 reads the lines of the command definition, ending with @code{end}.
26787 After the @code{document} command is finished, @code{help} on command
26788 @var{commandname} displays the documentation you have written.
26789
26790 You may use the @code{document} command again to change the
26791 documentation of a command. Redefining the command with @code{define}
26792 does not change the documentation.
26793
26794 @kindex define-prefix
26795 @item define-prefix @var{commandname}
26796 Define or mark the command @var{commandname} as a user-defined prefix
26797 command. Once marked, @var{commandname} can be used as prefix command
26798 by the @code{define} command.
26799 Note that @code{define-prefix} can be used with a not yet defined
26800 @var{commandname}. In such a case, @var{commandname} is defined as
26801 an empty user-defined command.
26802 In case you redefine a command that was marked as a user-defined
26803 prefix command, the subcommands of the redefined command are kept
26804 (and @value{GDBN} indicates so to the user).
26805
26806 Example:
26807 @example
26808 (gdb) define-prefix abc
26809 (gdb) define-prefix abc def
26810 (gdb) define abc def
26811 Type commands for definition of "abc def".
26812 End with a line saying just "end".
26813 >echo command initial def\n
26814 >end
26815 (gdb) define abc def ghi
26816 Type commands for definition of "abc def ghi".
26817 End with a line saying just "end".
26818 >echo command ghi\n
26819 >end
26820 (gdb) define abc def
26821 Keeping subcommands of prefix command "def".
26822 Redefine command "def"? (y or n) y
26823 Type commands for definition of "abc def".
26824 End with a line saying just "end".
26825 >echo command def\n
26826 >end
26827 (gdb) abc def ghi
26828 command ghi
26829 (gdb) abc def
26830 command def
26831 (gdb)
26832 @end example
26833
26834 @kindex dont-repeat
26835 @cindex don't repeat command
26836 @item dont-repeat
26837 Used inside a user-defined command, this tells @value{GDBN} that this
26838 command should not be repeated when the user hits @key{RET}
26839 (@pxref{Command Syntax, repeat last command}).
26840
26841 @kindex help user-defined
26842 @item help user-defined
26843 List all user-defined commands and all python commands defined in class
26844 COMMAND_USER. The first line of the documentation or docstring is
26845 included (if any).
26846
26847 @kindex show user
26848 @item show user
26849 @itemx show user @var{commandname}
26850 Display the @value{GDBN} commands used to define @var{commandname} (but
26851 not its documentation). If no @var{commandname} is given, display the
26852 definitions for all user-defined commands.
26853 This does not work for user-defined python commands.
26854
26855 @cindex infinite recursion in user-defined commands
26856 @kindex show max-user-call-depth
26857 @kindex set max-user-call-depth
26858 @item show max-user-call-depth
26859 @itemx set max-user-call-depth
26860 The value of @code{max-user-call-depth} controls how many recursion
26861 levels are allowed in user-defined commands before @value{GDBN} suspects an
26862 infinite recursion and aborts the command.
26863 This does not apply to user-defined python commands.
26864 @end table
26865
26866 In addition to the above commands, user-defined commands frequently
26867 use control flow commands, described in @ref{Command Files}.
26868
26869 When user-defined commands are executed, the
26870 commands of the definition are not printed. An error in any command
26871 stops execution of the user-defined command.
26872
26873 If used interactively, commands that would ask for confirmation proceed
26874 without asking when used inside a user-defined command. Many @value{GDBN}
26875 commands that normally print messages to say what they are doing omit the
26876 messages when used in a user-defined command.
26877
26878 @node Hooks
26879 @subsection User-defined Command Hooks
26880 @cindex command hooks
26881 @cindex hooks, for commands
26882 @cindex hooks, pre-command
26883
26884 @kindex hook
26885 You may define @dfn{hooks}, which are a special kind of user-defined
26886 command. Whenever you run the command @samp{foo}, if the user-defined
26887 command @samp{hook-foo} exists, it is executed (with no arguments)
26888 before that command.
26889
26890 @cindex hooks, post-command
26891 @kindex hookpost
26892 A hook may also be defined which is run after the command you executed.
26893 Whenever you run the command @samp{foo}, if the user-defined command
26894 @samp{hookpost-foo} exists, it is executed (with no arguments) after
26895 that command. Post-execution hooks may exist simultaneously with
26896 pre-execution hooks, for the same command.
26897
26898 It is valid for a hook to call the command which it hooks. If this
26899 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
26900
26901 @c It would be nice if hookpost could be passed a parameter indicating
26902 @c if the command it hooks executed properly or not. FIXME!
26903
26904 @kindex stop@r{, a pseudo-command}
26905 In addition, a pseudo-command, @samp{stop} exists. Defining
26906 (@samp{hook-stop}) makes the associated commands execute every time
26907 execution stops in your program: before breakpoint commands are run,
26908 displays are printed, or the stack frame is printed.
26909
26910 For example, to ignore @code{SIGALRM} signals while
26911 single-stepping, but treat them normally during normal execution,
26912 you could define:
26913
26914 @smallexample
26915 define hook-stop
26916 handle SIGALRM nopass
26917 end
26918
26919 define hook-run
26920 handle SIGALRM pass
26921 end
26922
26923 define hook-continue
26924 handle SIGALRM pass
26925 end
26926 @end smallexample
26927
26928 As a further example, to hook at the beginning and end of the @code{echo}
26929 command, and to add extra text to the beginning and end of the message,
26930 you could define:
26931
26932 @smallexample
26933 define hook-echo
26934 echo <<<---
26935 end
26936
26937 define hookpost-echo
26938 echo --->>>\n
26939 end
26940
26941 (@value{GDBP}) echo Hello World
26942 <<<---Hello World--->>>
26943 (@value{GDBP})
26944
26945 @end smallexample
26946
26947 You can define a hook for any single-word command in @value{GDBN}, but
26948 not for command aliases; you should define a hook for the basic command
26949 name, e.g.@: @code{backtrace} rather than @code{bt}.
26950 @c FIXME! So how does Joe User discover whether a command is an alias
26951 @c or not?
26952 You can hook a multi-word command by adding @code{hook-} or
26953 @code{hookpost-} to the last word of the command, e.g.@:
26954 @samp{define target hook-remote} to add a hook to @samp{target remote}.
26955
26956 If an error occurs during the execution of your hook, execution of
26957 @value{GDBN} commands stops and @value{GDBN} issues a prompt
26958 (before the command that you actually typed had a chance to run).
26959
26960 If you try to define a hook which does not match any known command, you
26961 get a warning from the @code{define} command.
26962
26963 @node Command Files
26964 @subsection Command Files
26965
26966 @cindex command files
26967 @cindex scripting commands
26968 A command file for @value{GDBN} is a text file made of lines that are
26969 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26970 also be included. An empty line in a command file does nothing; it
26971 does not mean to repeat the last command, as it would from the
26972 terminal.
26973
26974 You can request the execution of a command file with the @code{source}
26975 command. Note that the @code{source} command is also used to evaluate
26976 scripts that are not Command Files. The exact behavior can be configured
26977 using the @code{script-extension} setting.
26978 @xref{Extending GDB,, Extending GDB}.
26979
26980 @table @code
26981 @kindex source
26982 @cindex execute commands from a file
26983 @item source [-s] [-v] @var{filename}
26984 Execute the command file @var{filename}.
26985 @end table
26986
26987 The lines in a command file are generally executed sequentially,
26988 unless the order of execution is changed by one of the
26989 @emph{flow-control commands} described below. The commands are not
26990 printed as they are executed. An error in any command terminates
26991 execution of the command file and control is returned to the console.
26992
26993 @value{GDBN} first searches for @var{filename} in the current directory.
26994 If the file is not found there, and @var{filename} does not specify a
26995 directory, then @value{GDBN} also looks for the file on the source search path
26996 (specified with the @samp{directory} command);
26997 except that @file{$cdir} is not searched because the compilation directory
26998 is not relevant to scripts.
26999
27000 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27001 on the search path even if @var{filename} specifies a directory.
27002 The search is done by appending @var{filename} to each element of the
27003 search path. So, for example, if @var{filename} is @file{mylib/myscript}
27004 and the search path contains @file{/home/user} then @value{GDBN} will
27005 look for the script @file{/home/user/mylib/myscript}.
27006 The search is also done if @var{filename} is an absolute path.
27007 For example, if @var{filename} is @file{/tmp/myscript} and
27008 the search path contains @file{/home/user} then @value{GDBN} will
27009 look for the script @file{/home/user/tmp/myscript}.
27010 For DOS-like systems, if @var{filename} contains a drive specification,
27011 it is stripped before concatenation. For example, if @var{filename} is
27012 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27013 will look for the script @file{c:/tmp/myscript}.
27014
27015 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27016 each command as it is executed. The option must be given before
27017 @var{filename}, and is interpreted as part of the filename anywhere else.
27018
27019 Commands that would ask for confirmation if used interactively proceed
27020 without asking when used in a command file. Many @value{GDBN} commands that
27021 normally print messages to say what they are doing omit the messages
27022 when called from command files.
27023
27024 @value{GDBN} also accepts command input from standard input. In this
27025 mode, normal output goes to standard output and error output goes to
27026 standard error. Errors in a command file supplied on standard input do
27027 not terminate execution of the command file---execution continues with
27028 the next command.
27029
27030 @smallexample
27031 gdb < cmds > log 2>&1
27032 @end smallexample
27033
27034 (The syntax above will vary depending on the shell used.) This example
27035 will execute commands from the file @file{cmds}. All output and errors
27036 would be directed to @file{log}.
27037
27038 Since commands stored on command files tend to be more general than
27039 commands typed interactively, they frequently need to deal with
27040 complicated situations, such as different or unexpected values of
27041 variables and symbols, changes in how the program being debugged is
27042 built, etc. @value{GDBN} provides a set of flow-control commands to
27043 deal with these complexities. Using these commands, you can write
27044 complex scripts that loop over data structures, execute commands
27045 conditionally, etc.
27046
27047 @table @code
27048 @kindex if
27049 @kindex else
27050 @item if
27051 @itemx else
27052 This command allows to include in your script conditionally executed
27053 commands. The @code{if} command takes a single argument, which is an
27054 expression to evaluate. It is followed by a series of commands that
27055 are executed only if the expression is true (its value is nonzero).
27056 There can then optionally be an @code{else} line, followed by a series
27057 of commands that are only executed if the expression was false. The
27058 end of the list is marked by a line containing @code{end}.
27059
27060 @kindex while
27061 @item while
27062 This command allows to write loops. Its syntax is similar to
27063 @code{if}: the command takes a single argument, which is an expression
27064 to evaluate, and must be followed by the commands to execute, one per
27065 line, terminated by an @code{end}. These commands are called the
27066 @dfn{body} of the loop. The commands in the body of @code{while} are
27067 executed repeatedly as long as the expression evaluates to true.
27068
27069 @kindex loop_break
27070 @item loop_break
27071 This command exits the @code{while} loop in whose body it is included.
27072 Execution of the script continues after that @code{while}s @code{end}
27073 line.
27074
27075 @kindex loop_continue
27076 @item loop_continue
27077 This command skips the execution of the rest of the body of commands
27078 in the @code{while} loop in whose body it is included. Execution
27079 branches to the beginning of the @code{while} loop, where it evaluates
27080 the controlling expression.
27081
27082 @kindex end@r{ (if/else/while commands)}
27083 @item end
27084 Terminate the block of commands that are the body of @code{if},
27085 @code{else}, or @code{while} flow-control commands.
27086 @end table
27087
27088
27089 @node Output
27090 @subsection Commands for Controlled Output
27091
27092 During the execution of a command file or a user-defined command, normal
27093 @value{GDBN} output is suppressed; the only output that appears is what is
27094 explicitly printed by the commands in the definition. This section
27095 describes three commands useful for generating exactly the output you
27096 want.
27097
27098 @table @code
27099 @kindex echo
27100 @item echo @var{text}
27101 @c I do not consider backslash-space a standard C escape sequence
27102 @c because it is not in ANSI.
27103 Print @var{text}. Nonprinting characters can be included in
27104 @var{text} using C escape sequences, such as @samp{\n} to print a
27105 newline. @strong{No newline is printed unless you specify one.}
27106 In addition to the standard C escape sequences, a backslash followed
27107 by a space stands for a space. This is useful for displaying a
27108 string with spaces at the beginning or the end, since leading and
27109 trailing spaces are otherwise trimmed from all arguments.
27110 To print @samp{@w{ }and foo =@w{ }}, use the command
27111 @samp{echo \@w{ }and foo = \@w{ }}.
27112
27113 A backslash at the end of @var{text} can be used, as in C, to continue
27114 the command onto subsequent lines. For example,
27115
27116 @smallexample
27117 echo This is some text\n\
27118 which is continued\n\
27119 onto several lines.\n
27120 @end smallexample
27121
27122 produces the same output as
27123
27124 @smallexample
27125 echo This is some text\n
27126 echo which is continued\n
27127 echo onto several lines.\n
27128 @end smallexample
27129
27130 @kindex output
27131 @item output @var{expression}
27132 Print the value of @var{expression} and nothing but that value: no
27133 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27134 value history either. @xref{Expressions, ,Expressions}, for more information
27135 on expressions.
27136
27137 @item output/@var{fmt} @var{expression}
27138 Print the value of @var{expression} in format @var{fmt}. You can use
27139 the same formats as for @code{print}. @xref{Output Formats,,Output
27140 Formats}, for more information.
27141
27142 @kindex printf
27143 @item printf @var{template}, @var{expressions}@dots{}
27144 Print the values of one or more @var{expressions} under the control of
27145 the string @var{template}. To print several values, make
27146 @var{expressions} be a comma-separated list of individual expressions,
27147 which may be either numbers or pointers. Their values are printed as
27148 specified by @var{template}, exactly as a C program would do by
27149 executing the code below:
27150
27151 @smallexample
27152 printf (@var{template}, @var{expressions}@dots{});
27153 @end smallexample
27154
27155 As in @code{C} @code{printf}, ordinary characters in @var{template}
27156 are printed verbatim, while @dfn{conversion specification} introduced
27157 by the @samp{%} character cause subsequent @var{expressions} to be
27158 evaluated, their values converted and formatted according to type and
27159 style information encoded in the conversion specifications, and then
27160 printed.
27161
27162 For example, you can print two values in hex like this:
27163
27164 @smallexample
27165 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27166 @end smallexample
27167
27168 @code{printf} supports all the standard @code{C} conversion
27169 specifications, including the flags and modifiers between the @samp{%}
27170 character and the conversion letter, with the following exceptions:
27171
27172 @itemize @bullet
27173 @item
27174 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27175
27176 @item
27177 The modifier @samp{*} is not supported for specifying precision or
27178 width.
27179
27180 @item
27181 The @samp{'} flag (for separation of digits into groups according to
27182 @code{LC_NUMERIC'}) is not supported.
27183
27184 @item
27185 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27186 supported.
27187
27188 @item
27189 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27190
27191 @item
27192 The conversion letters @samp{a} and @samp{A} are not supported.
27193 @end itemize
27194
27195 @noindent
27196 Note that the @samp{ll} type modifier is supported only if the
27197 underlying @code{C} implementation used to build @value{GDBN} supports
27198 the @code{long long int} type, and the @samp{L} type modifier is
27199 supported only if @code{long double} type is available.
27200
27201 As in @code{C}, @code{printf} supports simple backslash-escape
27202 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27203 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27204 single character. Octal and hexadecimal escape sequences are not
27205 supported.
27206
27207 Additionally, @code{printf} supports conversion specifications for DFP
27208 (@dfn{Decimal Floating Point}) types using the following length modifiers
27209 together with a floating point specifier.
27210 letters:
27211
27212 @itemize @bullet
27213 @item
27214 @samp{H} for printing @code{Decimal32} types.
27215
27216 @item
27217 @samp{D} for printing @code{Decimal64} types.
27218
27219 @item
27220 @samp{DD} for printing @code{Decimal128} types.
27221 @end itemize
27222
27223 If the underlying @code{C} implementation used to build @value{GDBN} has
27224 support for the three length modifiers for DFP types, other modifiers
27225 such as width and precision will also be available for @value{GDBN} to use.
27226
27227 In case there is no such @code{C} support, no additional modifiers will be
27228 available and the value will be printed in the standard way.
27229
27230 Here's an example of printing DFP types using the above conversion letters:
27231 @smallexample
27232 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27233 @end smallexample
27234
27235 @anchor{eval}
27236 @kindex eval
27237 @item eval @var{template}, @var{expressions}@dots{}
27238 Convert the values of one or more @var{expressions} under the control of
27239 the string @var{template} to a command line, and call it.
27240
27241 @end table
27242
27243 @node Auto-loading sequences
27244 @subsection Controlling auto-loading native @value{GDBN} scripts
27245 @cindex native script auto-loading
27246
27247 When a new object file is read (for example, due to the @code{file}
27248 command, or because the inferior has loaded a shared library),
27249 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27250 @xref{Auto-loading extensions}.
27251
27252 Auto-loading can be enabled or disabled,
27253 and the list of auto-loaded scripts can be printed.
27254
27255 @table @code
27256 @anchor{set auto-load gdb-scripts}
27257 @kindex set auto-load gdb-scripts
27258 @item set auto-load gdb-scripts [on|off]
27259 Enable or disable the auto-loading of canned sequences of commands scripts.
27260
27261 @anchor{show auto-load gdb-scripts}
27262 @kindex show auto-load gdb-scripts
27263 @item show auto-load gdb-scripts
27264 Show whether auto-loading of canned sequences of commands scripts is enabled or
27265 disabled.
27266
27267 @anchor{info auto-load gdb-scripts}
27268 @kindex info auto-load gdb-scripts
27269 @cindex print list of auto-loaded canned sequences of commands scripts
27270 @item info auto-load gdb-scripts [@var{regexp}]
27271 Print the list of all canned sequences of commands scripts that @value{GDBN}
27272 auto-loaded.
27273 @end table
27274
27275 If @var{regexp} is supplied only canned sequences of commands scripts with
27276 matching names are printed.
27277
27278 @c Python docs live in a separate file.
27279 @include python.texi
27280
27281 @c Guile docs live in a separate file.
27282 @include guile.texi
27283
27284 @node Auto-loading extensions
27285 @section Auto-loading extensions
27286 @cindex auto-loading extensions
27287
27288 @value{GDBN} provides two mechanisms for automatically loading extensions
27289 when a new object file is read (for example, due to the @code{file}
27290 command, or because the inferior has loaded a shared library):
27291 @file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27292 section of modern file formats like ELF.
27293
27294 @menu
27295 * objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27296 * .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27297 * Which flavor to choose?::
27298 @end menu
27299
27300 The auto-loading feature is useful for supplying application-specific
27301 debugging commands and features.
27302
27303 Auto-loading can be enabled or disabled,
27304 and the list of auto-loaded scripts can be printed.
27305 See the @samp{auto-loading} section of each extension language
27306 for more information.
27307 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27308 For Python files see @ref{Python Auto-loading}.
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 @node objfile-gdbdotext file
27314 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27315 @cindex @file{@var{objfile}-gdb.gdb}
27316 @cindex @file{@var{objfile}-gdb.py}
27317 @cindex @file{@var{objfile}-gdb.scm}
27318
27319 When a new object file is read, @value{GDBN} looks for a file named
27320 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27321 where @var{objfile} is the object file's name and
27322 where @var{ext} is the file extension for the extension language:
27323
27324 @table @code
27325 @item @file{@var{objfile}-gdb.gdb}
27326 GDB's own command language
27327 @item @file{@var{objfile}-gdb.py}
27328 Python
27329 @item @file{@var{objfile}-gdb.scm}
27330 Guile
27331 @end table
27332
27333 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27334 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27335 components, and appending the @file{-gdb.@var{ext}} suffix.
27336 If this file exists and is readable, @value{GDBN} will evaluate it as a
27337 script in the specified extension language.
27338
27339 If this file does not exist, then @value{GDBN} will look for
27340 @var{script-name} file in all of the directories as specified below.
27341
27342 Note that loading of these files requires an accordingly configured
27343 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27344
27345 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27346 scripts normally according to its @file{.exe} filename. But if no scripts are
27347 found @value{GDBN} also tries script filenames matching the object file without
27348 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27349 is attempted on any platform. This makes the script filenames compatible
27350 between Unix and MS-Windows hosts.
27351
27352 @table @code
27353 @anchor{set auto-load scripts-directory}
27354 @kindex set auto-load scripts-directory
27355 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27356 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27357 may be delimited by the host platform path separator in use
27358 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27359
27360 Each entry here needs to be covered also by the security setting
27361 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27362
27363 @anchor{with-auto-load-dir}
27364 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27365 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27366 configuration option @option{--with-auto-load-dir}.
27367
27368 Any reference to @file{$debugdir} will get replaced by
27369 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27370 reference to @file{$datadir} will get replaced by @var{data-directory} which is
27371 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27372 @file{$datadir} must be placed as a directory component --- either alone or
27373 delimited by @file{/} or @file{\} directory separators, depending on the host
27374 platform.
27375
27376 The list of directories uses path separator (@samp{:} on GNU and Unix
27377 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27378 to the @env{PATH} environment variable.
27379
27380 @anchor{show auto-load scripts-directory}
27381 @kindex show auto-load scripts-directory
27382 @item show auto-load scripts-directory
27383 Show @value{GDBN} auto-loaded scripts location.
27384
27385 @anchor{add-auto-load-scripts-directory}
27386 @kindex add-auto-load-scripts-directory
27387 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27388 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27389 Multiple entries may be delimited by the host platform path separator in use.
27390 @end table
27391
27392 @value{GDBN} does not track which files it has already auto-loaded this way.
27393 @value{GDBN} will load the associated script every time the corresponding
27394 @var{objfile} is opened.
27395 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27396 is evaluated more than once.
27397
27398 @node dotdebug_gdb_scripts section
27399 @subsection The @code{.debug_gdb_scripts} section
27400 @cindex @code{.debug_gdb_scripts} section
27401
27402 For systems using file formats like ELF and COFF,
27403 when @value{GDBN} loads a new object file
27404 it will look for a special section named @code{.debug_gdb_scripts}.
27405 If this section exists, its contents is a list of null-terminated entries
27406 specifying scripts to load. Each entry begins with a non-null prefix byte that
27407 specifies the kind of entry, typically the extension language and whether the
27408 script is in a file or inlined in @code{.debug_gdb_scripts}.
27409
27410 The following entries are supported:
27411
27412 @table @code
27413 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27414 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27415 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27416 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27417 @end table
27418
27419 @subsubsection Script File Entries
27420
27421 If the entry specifies a file, @value{GDBN} will look for the file first
27422 in the current directory and then along the source search path
27423 (@pxref{Source Path, ,Specifying Source Directories}),
27424 except that @file{$cdir} is not searched, since the compilation
27425 directory is not relevant to scripts.
27426
27427 File entries can be placed in section @code{.debug_gdb_scripts} with,
27428 for example, this GCC macro for Python scripts.
27429
27430 @example
27431 /* Note: The "MS" section flags are to remove duplicates. */
27432 #define DEFINE_GDB_PY_SCRIPT(script_name) \
27433 asm("\
27434 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27435 .byte 1 /* Python */\n\
27436 .asciz \"" script_name "\"\n\
27437 .popsection \n\
27438 ");
27439 @end example
27440
27441 @noindent
27442 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
27443 Then one can reference the macro in a header or source file like this:
27444
27445 @example
27446 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27447 @end example
27448
27449 The script name may include directories if desired.
27450
27451 Note that loading of this script file also requires accordingly configured
27452 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27453
27454 If the macro invocation is put in a header, any application or library
27455 using this header will get a reference to the specified script,
27456 and with the use of @code{"MS"} attributes on the section, the linker
27457 will remove duplicates.
27458
27459 @subsubsection Script Text Entries
27460
27461 Script text entries allow to put the executable script in the entry
27462 itself instead of loading it from a file.
27463 The first line of the entry, everything after the prefix byte and up to
27464 the first newline (@code{0xa}) character, is the script name, and must not
27465 contain any kind of space character, e.g., spaces or tabs.
27466 The rest of the entry, up to the trailing null byte, is the script to
27467 execute in the specified language. The name needs to be unique among
27468 all script names, as @value{GDBN} executes each script only once based
27469 on its name.
27470
27471 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27472 testsuite.
27473
27474 @example
27475 #include "symcat.h"
27476 #include "gdb/section-scripts.h"
27477 asm(
27478 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27479 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27480 ".ascii \"gdb.inlined-script\\n\"\n"
27481 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27482 ".ascii \" def __init__ (self):\\n\"\n"
27483 ".ascii \" super (test_cmd, self).__init__ ("
27484 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27485 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27486 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27487 ".ascii \"test_cmd ()\\n\"\n"
27488 ".byte 0\n"
27489 ".popsection\n"
27490 );
27491 @end example
27492
27493 Loading of inlined scripts requires a properly configured
27494 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27495 The path to specify in @code{auto-load safe-path} is the path of the file
27496 containing the @code{.debug_gdb_scripts} section.
27497
27498 @node Which flavor to choose?
27499 @subsection Which flavor to choose?
27500
27501 Given the multiple ways of auto-loading extensions, it might not always
27502 be clear which one to choose. This section provides some guidance.
27503
27504 @noindent
27505 Benefits of the @file{-gdb.@var{ext}} way:
27506
27507 @itemize @bullet
27508 @item
27509 Can be used with file formats that don't support multiple sections.
27510
27511 @item
27512 Ease of finding scripts for public libraries.
27513
27514 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27515 in the source search path.
27516 For publicly installed libraries, e.g., @file{libstdc++}, there typically
27517 isn't a source directory in which to find the script.
27518
27519 @item
27520 Doesn't require source code additions.
27521 @end itemize
27522
27523 @noindent
27524 Benefits of the @code{.debug_gdb_scripts} way:
27525
27526 @itemize @bullet
27527 @item
27528 Works with static linking.
27529
27530 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27531 trigger their loading. When an application is statically linked the only
27532 objfile available is the executable, and it is cumbersome to attach all the
27533 scripts from all the input libraries to the executable's
27534 @file{-gdb.@var{ext}} script.
27535
27536 @item
27537 Works with classes that are entirely inlined.
27538
27539 Some classes can be entirely inlined, and thus there may not be an associated
27540 shared library to attach a @file{-gdb.@var{ext}} script to.
27541
27542 @item
27543 Scripts needn't be copied out of the source tree.
27544
27545 In some circumstances, apps can be built out of large collections of internal
27546 libraries, and the build infrastructure necessary to install the
27547 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27548 cumbersome. It may be easier to specify the scripts in the
27549 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
27550 top of the source tree to the source search path.
27551 @end itemize
27552
27553 @node Multiple Extension Languages
27554 @section Multiple Extension Languages
27555
27556 The Guile and Python extension languages do not share any state,
27557 and generally do not interfere with each other.
27558 There are some things to be aware of, however.
27559
27560 @subsection Python comes first
27561
27562 Python was @value{GDBN}'s first extension language, and to avoid breaking
27563 existing behaviour Python comes first. This is generally solved by the
27564 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
27565 extension languages, and when it makes a call to an extension language,
27566 (say to pretty-print a value), it tries each in turn until an extension
27567 language indicates it has performed the request (e.g., has returned the
27568 pretty-printed form of a value).
27569 This extends to errors while performing such requests: If an error happens
27570 while, for example, trying to pretty-print an object then the error is
27571 reported and any following extension languages are not tried.
27572
27573 @node Aliases
27574 @section Creating new spellings of existing commands
27575 @cindex aliases for commands
27576
27577 It is often useful to define alternate spellings of existing commands.
27578 For example, if a new @value{GDBN} command defined in Python has
27579 a long name to type, it is handy to have an abbreviated version of it
27580 that involves less typing.
27581
27582 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27583 of the @samp{step} command even though it is otherwise an ambiguous
27584 abbreviation of other commands like @samp{set} and @samp{show}.
27585
27586 Aliases are also used to provide shortened or more common versions
27587 of multi-word commands. For example, @value{GDBN} provides the
27588 @samp{tty} alias of the @samp{set inferior-tty} command.
27589
27590 You can define a new alias with the @samp{alias} command.
27591
27592 @table @code
27593
27594 @kindex alias
27595 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
27596
27597 @end table
27598
27599 @var{ALIAS} specifies the name of the new alias.
27600 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27601 underscores.
27602
27603 @var{COMMAND} specifies the name of an existing command
27604 that is being aliased.
27605
27606 @var{COMMAND} can also be the name of an existing alias. In this case,
27607 @var{COMMAND} cannot be an alias that has default arguments.
27608
27609 The @samp{-a} option specifies that the new alias is an abbreviation
27610 of the command. Abbreviations are not used in command completion.
27611
27612 The @samp{--} option specifies the end of options,
27613 and is useful when @var{ALIAS} begins with a dash.
27614
27615 You can specify @var{default-args} for your alias.
27616 These @var{default-args} will be automatically added before the alias
27617 arguments typed explicitly on the command line.
27618
27619 For example, the below defines an alias @code{btfullall} that shows all local
27620 variables and all frame arguments:
27621 @smallexample
27622 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27623 @end smallexample
27624
27625 For more information about @var{default-args}, see @ref{Command aliases default args,
27626 ,Automatically prepend default arguments to user-defined aliases}.
27627
27628 Here is a simple example showing how to make an abbreviation
27629 of a command so that there is less to type.
27630 Suppose you were tired of typing @samp{disas}, the current
27631 shortest unambiguous abbreviation of the @samp{disassemble} command
27632 and you wanted an even shorter version named @samp{di}.
27633 The following will accomplish this.
27634
27635 @smallexample
27636 (gdb) alias -a di = disas
27637 @end smallexample
27638
27639 Note that aliases are different from user-defined commands.
27640 With a user-defined command, you also need to write documentation
27641 for it with the @samp{document} command.
27642 An alias automatically picks up the documentation of the existing command.
27643
27644 Here is an example where we make @samp{elms} an abbreviation of
27645 @samp{elements} in the @samp{set print elements} command.
27646 This is to show that you can make an abbreviation of any part
27647 of a command.
27648
27649 @smallexample
27650 (gdb) alias -a set print elms = set print elements
27651 (gdb) alias -a show print elms = show print elements
27652 (gdb) set p elms 20
27653 (gdb) show p elms
27654 Limit on string chars or array elements to print is 200.
27655 @end smallexample
27656
27657 Note that if you are defining an alias of a @samp{set} command,
27658 and you want to have an alias for the corresponding @samp{show}
27659 command, then you need to define the latter separately.
27660
27661 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27662 @var{ALIAS}, just as they are normally.
27663
27664 @smallexample
27665 (gdb) alias -a set pr elms = set p ele
27666 @end smallexample
27667
27668 Finally, here is an example showing the creation of a one word
27669 alias for a more complex command.
27670 This creates alias @samp{spe} of the command @samp{set print elements}.
27671
27672 @smallexample
27673 (gdb) alias spe = set print elements
27674 (gdb) spe 20
27675 @end smallexample
27676
27677 @node Interpreters
27678 @chapter Command Interpreters
27679 @cindex command interpreters
27680
27681 @value{GDBN} supports multiple command interpreters, and some command
27682 infrastructure to allow users or user interface writers to switch
27683 between interpreters or run commands in other interpreters.
27684
27685 @value{GDBN} currently supports two command interpreters, the console
27686 interpreter (sometimes called the command-line interpreter or @sc{cli})
27687 and the machine interface interpreter (or @sc{gdb/mi}). This manual
27688 describes both of these interfaces in great detail.
27689
27690 By default, @value{GDBN} will start with the console interpreter.
27691 However, the user may choose to start @value{GDBN} with another
27692 interpreter by specifying the @option{-i} or @option{--interpreter}
27693 startup options. Defined interpreters include:
27694
27695 @table @code
27696 @item console
27697 @cindex console interpreter
27698 The traditional console or command-line interpreter. This is the most often
27699 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27700 @value{GDBN} will use this interpreter.
27701
27702 @item mi
27703 @cindex mi interpreter
27704 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
27705 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27706 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27707 Interface}.
27708
27709 @item mi3
27710 @cindex mi3 interpreter
27711 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27712
27713 @item mi2
27714 @cindex mi2 interpreter
27715 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
27716
27717 @item mi1
27718 @cindex mi1 interpreter
27719 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
27720
27721 @end table
27722
27723 @cindex invoke another interpreter
27724
27725 @kindex interpreter-exec
27726 You may execute commands in any interpreter from the current
27727 interpreter using the appropriate command. If you are running the
27728 console interpreter, simply use the @code{interpreter-exec} command:
27729
27730 @smallexample
27731 interpreter-exec mi "-data-list-register-names"
27732 @end smallexample
27733
27734 @sc{gdb/mi} has a similar command, although it is only available in versions of
27735 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27736
27737 Note that @code{interpreter-exec} only changes the interpreter for the
27738 duration of the specified command. It does not change the interpreter
27739 permanently.
27740
27741 @cindex start a new independent interpreter
27742
27743 Although you may only choose a single interpreter at startup, it is
27744 possible to run an independent interpreter on a specified input/output
27745 device (usually a tty).
27746
27747 For example, consider a debugger GUI or IDE that wants to provide a
27748 @value{GDBN} console view. It may do so by embedding a terminal
27749 emulator widget in its GUI, starting @value{GDBN} in the traditional
27750 command-line mode with stdin/stdout/stderr redirected to that
27751 terminal, and then creating an MI interpreter running on a specified
27752 input/output device. The console interpreter created by @value{GDBN}
27753 at startup handles commands the user types in the terminal widget,
27754 while the GUI controls and synchronizes state with @value{GDBN} using
27755 the separate MI interpreter.
27756
27757 To start a new secondary @dfn{user interface} running MI, use the
27758 @code{new-ui} command:
27759
27760 @kindex new-ui
27761 @cindex new user interface
27762 @smallexample
27763 new-ui @var{interpreter} @var{tty}
27764 @end smallexample
27765
27766 The @var{interpreter} parameter specifies the interpreter to run.
27767 This accepts the same values as the @code{interpreter-exec} command.
27768 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27769 @var{tty} parameter specifies the name of the bidirectional file the
27770 interpreter uses for input/output, usually the name of a
27771 pseudoterminal slave on Unix systems. For example:
27772
27773 @smallexample
27774 (@value{GDBP}) new-ui mi /dev/pts/9
27775 @end smallexample
27776
27777 @noindent
27778 runs an MI interpreter on @file{/dev/pts/9}.
27779
27780 @node TUI
27781 @chapter @value{GDBN} Text User Interface
27782 @cindex TUI
27783 @cindex Text User Interface
27784
27785 @menu
27786 * TUI Overview:: TUI overview
27787 * TUI Keys:: TUI key bindings
27788 * TUI Single Key Mode:: TUI single key mode
27789 * TUI Commands:: TUI-specific commands
27790 * TUI Configuration:: TUI configuration variables
27791 @end menu
27792
27793 The @value{GDBN} Text User Interface (TUI) is a terminal
27794 interface which uses the @code{curses} library to show the source
27795 file, the assembly output, the program registers and @value{GDBN}
27796 commands in separate text windows. The TUI mode is supported only
27797 on platforms where a suitable version of the @code{curses} library
27798 is available.
27799
27800 The TUI mode is enabled by default when you invoke @value{GDBN} as
27801 @samp{@value{GDBP} -tui}.
27802 You can also switch in and out of TUI mode while @value{GDBN} runs by
27803 using various TUI commands and key bindings, such as @command{tui
27804 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
27805 @ref{TUI Keys, ,TUI Key Bindings}.
27806
27807 @node TUI Overview
27808 @section TUI Overview
27809
27810 In TUI mode, @value{GDBN} can display several text windows:
27811
27812 @table @emph
27813 @item command
27814 This window is the @value{GDBN} command window with the @value{GDBN}
27815 prompt and the @value{GDBN} output. The @value{GDBN} input is still
27816 managed using readline.
27817
27818 @item source
27819 The source window shows the source file of the program. The current
27820 line and active breakpoints are displayed in this window.
27821
27822 @item assembly
27823 The assembly window shows the disassembly output of the program.
27824
27825 @item register
27826 This window shows the processor registers. Registers are highlighted
27827 when their values change.
27828 @end table
27829
27830 The source and assembly windows show the current program position
27831 by highlighting the current line and marking it with a @samp{>} marker.
27832 Breakpoints are indicated with two markers. The first marker
27833 indicates the breakpoint type:
27834
27835 @table @code
27836 @item B
27837 Breakpoint which was hit at least once.
27838
27839 @item b
27840 Breakpoint which was never hit.
27841
27842 @item H
27843 Hardware breakpoint which was hit at least once.
27844
27845 @item h
27846 Hardware breakpoint which was never hit.
27847 @end table
27848
27849 The second marker indicates whether the breakpoint is enabled or not:
27850
27851 @table @code
27852 @item +
27853 Breakpoint is enabled.
27854
27855 @item -
27856 Breakpoint is disabled.
27857 @end table
27858
27859 The source, assembly and register windows are updated when the current
27860 thread changes, when the frame changes, or when the program counter
27861 changes.
27862
27863 These windows are not all visible at the same time. The command
27864 window is always visible. The others can be arranged in several
27865 layouts:
27866
27867 @itemize @bullet
27868 @item
27869 source only,
27870
27871 @item
27872 assembly only,
27873
27874 @item
27875 source and assembly,
27876
27877 @item
27878 source and registers, or
27879
27880 @item
27881 assembly and registers.
27882 @end itemize
27883
27884 These are the standard layouts, but other layouts can be defined.
27885
27886 A status line above the command window shows the following information:
27887
27888 @table @emph
27889 @item target
27890 Indicates the current @value{GDBN} target.
27891 (@pxref{Targets, ,Specifying a Debugging Target}).
27892
27893 @item process
27894 Gives the current process or thread number.
27895 When no process is being debugged, this field is set to @code{No process}.
27896
27897 @item function
27898 Gives the current function name for the selected frame.
27899 The name is demangled if demangling is turned on (@pxref{Print Settings}).
27900 When there is no symbol corresponding to the current program counter,
27901 the string @code{??} is displayed.
27902
27903 @item line
27904 Indicates the current line number for the selected frame.
27905 When the current line number is not known, the string @code{??} is displayed.
27906
27907 @item pc
27908 Indicates the current program counter address.
27909 @end table
27910
27911 @node TUI Keys
27912 @section TUI Key Bindings
27913 @cindex TUI key bindings
27914
27915 The TUI installs several key bindings in the readline keymaps
27916 @ifset SYSTEM_READLINE
27917 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27918 @end ifset
27919 @ifclear SYSTEM_READLINE
27920 (@pxref{Command Line Editing}).
27921 @end ifclear
27922 The following key bindings are installed for both TUI mode and the
27923 @value{GDBN} standard mode.
27924
27925 @table @kbd
27926 @kindex C-x C-a
27927 @item C-x C-a
27928 @kindex C-x a
27929 @itemx C-x a
27930 @kindex C-x A
27931 @itemx C-x A
27932 Enter or leave the TUI mode. When leaving the TUI mode,
27933 the curses window management stops and @value{GDBN} operates using
27934 its standard mode, writing on the terminal directly. When reentering
27935 the TUI mode, control is given back to the curses windows.
27936 The screen is then refreshed.
27937
27938 This key binding uses the bindable Readline function
27939 @code{tui-switch-mode}.
27940
27941 @kindex C-x 1
27942 @item C-x 1
27943 Use a TUI layout with only one window. The layout will
27944 either be @samp{source} or @samp{assembly}. When the TUI mode
27945 is not active, it will switch to the TUI mode.
27946
27947 Think of this key binding as the Emacs @kbd{C-x 1} binding.
27948
27949 This key binding uses the bindable Readline function
27950 @code{tui-delete-other-windows}.
27951
27952 @kindex C-x 2
27953 @item C-x 2
27954 Use a TUI layout with at least two windows. When the current
27955 layout already has two windows, the next layout with two windows is used.
27956 When a new layout is chosen, one window will always be common to the
27957 previous layout and the new one.
27958
27959 Think of it as the Emacs @kbd{C-x 2} binding.
27960
27961 This key binding uses the bindable Readline function
27962 @code{tui-change-windows}.
27963
27964 @kindex C-x o
27965 @item C-x o
27966 Change the active window. The TUI associates several key bindings
27967 (like scrolling and arrow keys) with the active window. This command
27968 gives the focus to the next TUI window.
27969
27970 Think of it as the Emacs @kbd{C-x o} binding.
27971
27972 This key binding uses the bindable Readline function
27973 @code{tui-other-window}.
27974
27975 @kindex C-x s
27976 @item C-x s
27977 Switch in and out of the TUI SingleKey mode that binds single
27978 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
27979
27980 This key binding uses the bindable Readline function
27981 @code{next-keymap}.
27982 @end table
27983
27984 The following key bindings only work in the TUI mode:
27985
27986 @table @asis
27987 @kindex PgUp
27988 @item @key{PgUp}
27989 Scroll the active window one page up.
27990
27991 @kindex PgDn
27992 @item @key{PgDn}
27993 Scroll the active window one page down.
27994
27995 @kindex Up
27996 @item @key{Up}
27997 Scroll the active window one line up.
27998
27999 @kindex Down
28000 @item @key{Down}
28001 Scroll the active window one line down.
28002
28003 @kindex Left
28004 @item @key{Left}
28005 Scroll the active window one column left.
28006
28007 @kindex Right
28008 @item @key{Right}
28009 Scroll the active window one column right.
28010
28011 @kindex C-L
28012 @item @kbd{C-L}
28013 Refresh the screen.
28014 @end table
28015
28016 Because the arrow keys scroll the active window in the TUI mode, they
28017 are not available for their normal use by readline unless the command
28018 window has the focus. When another window is active, you must use
28019 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28020 and @kbd{C-f} to control the command window.
28021
28022 @node TUI Single Key Mode
28023 @section TUI Single Key Mode
28024 @cindex TUI single key mode
28025
28026 The TUI also provides a @dfn{SingleKey} mode, which binds several
28027 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28028 switch into this mode, where the following key bindings are used:
28029
28030 @table @kbd
28031 @kindex c @r{(SingleKey TUI key)}
28032 @item c
28033 continue
28034
28035 @kindex d @r{(SingleKey TUI key)}
28036 @item d
28037 down
28038
28039 @kindex f @r{(SingleKey TUI key)}
28040 @item f
28041 finish
28042
28043 @kindex n @r{(SingleKey TUI key)}
28044 @item n
28045 next
28046
28047 @kindex o @r{(SingleKey TUI key)}
28048 @item o
28049 nexti. The shortcut letter @samp{o} stands for ``step Over''.
28050
28051 @kindex q @r{(SingleKey TUI key)}
28052 @item q
28053 exit the SingleKey mode.
28054
28055 @kindex r @r{(SingleKey TUI key)}
28056 @item r
28057 run
28058
28059 @kindex s @r{(SingleKey TUI key)}
28060 @item s
28061 step
28062
28063 @kindex i @r{(SingleKey TUI key)}
28064 @item i
28065 stepi. The shortcut letter @samp{i} stands for ``step Into''.
28066
28067 @kindex u @r{(SingleKey TUI key)}
28068 @item u
28069 up
28070
28071 @kindex v @r{(SingleKey TUI key)}
28072 @item v
28073 info locals
28074
28075 @kindex w @r{(SingleKey TUI key)}
28076 @item w
28077 where
28078 @end table
28079
28080 Other keys temporarily switch to the @value{GDBN} command prompt.
28081 The key that was pressed is inserted in the editing buffer so that
28082 it is possible to type most @value{GDBN} commands without interaction
28083 with the TUI SingleKey mode. Once the command is entered the TUI
28084 SingleKey mode is restored. The only way to permanently leave
28085 this mode is by typing @kbd{q} or @kbd{C-x s}.
28086
28087 @cindex SingleKey keymap name
28088 If @value{GDBN} was built with Readline 8.0 or later, the TUI
28089 SingleKey keymap will be named @samp{SingleKey}. This can be used in
28090 @file{.inputrc} to add additional bindings to this keymap.
28091
28092 @node TUI Commands
28093 @section TUI-specific Commands
28094 @cindex TUI commands
28095
28096 The TUI has specific commands to control the text windows.
28097 These commands are always available, even when @value{GDBN} is not in
28098 the TUI mode. When @value{GDBN} is in the standard mode, most
28099 of these commands will automatically switch to the TUI mode.
28100
28101 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28102 terminal, or @value{GDBN} has been started with the machine interface
28103 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28104 these commands will fail with an error, because it would not be
28105 possible or desirable to enable curses window management.
28106
28107 @table @code
28108 @item tui enable
28109 @kindex tui enable
28110 Activate TUI mode. The last active TUI window layout will be used if
28111 TUI mode has previously been used in the current debugging session,
28112 otherwise a default layout is used.
28113
28114 @item tui disable
28115 @kindex tui disable
28116 Disable TUI mode, returning to the console interpreter.
28117
28118 @item info win
28119 @kindex info win
28120 List and give the size of all displayed windows.
28121
28122 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28123 @kindex tui new-layout
28124 Create a new TUI layout. The new layout will be named @var{name}, and
28125 can be accessed using the @code{layout} command (see below).
28126
28127 Each @var{window} parameter is either the name of a window to display,
28128 or a window description. The windows will be displayed from top to
28129 bottom in the order listed.
28130
28131 The names of the windows are the same as the ones given to the
28132 @code{focus} command (see below); additional, the @code{status}
28133 window can be specified. Note that, because it is of fixed height,
28134 the weight assigned to the status window is of no importance. It is
28135 conventional to use @samp{0} here.
28136
28137 A window description looks a bit like an invocation of @code{tui
28138 new-layout}, and is of the form
28139 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28140
28141 This specifies a sub-layout. If @code{-horizontal} is given, the
28142 windows in this description will be arranged side-by-side, rather than
28143 top-to-bottom.
28144
28145 Each @var{weight} is an integer. It is the weight of this window
28146 relative to all the other windows in the layout. These numbers are
28147 used to calculate how much of the screen is given to each window.
28148
28149 For example:
28150
28151 @example
28152 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28153 @end example
28154
28155 Here, the new layout is called @samp{example}. It shows the source
28156 and register windows, followed by the status window, and then finally
28157 the command window. The non-status windows all have the same weight,
28158 so the terminal will be split into three roughly equal sections.
28159
28160 Here is a more complex example, showing a horizontal layout:
28161
28162 @example
28163 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28164 @end example
28165
28166 This will result in side-by-side source and assembly windows; with the
28167 status and command window being beneath these, filling the entire
28168 width of the terminal. Because they have weight 2, the source and
28169 assembly windows will be twice the height of the command window.
28170
28171 @item layout @var{name}
28172 @kindex layout
28173 Changes which TUI windows are displayed. The @var{name} parameter
28174 controls which layout is shown. It can be either one of the built-in
28175 layout names, or the name of a layout defined by the user using
28176 @code{tui new-layout}.
28177
28178 The built-in layouts are as follows:
28179
28180 @table @code
28181 @item next
28182 Display the next layout.
28183
28184 @item prev
28185 Display the previous layout.
28186
28187 @item src
28188 Display the source and command windows.
28189
28190 @item asm
28191 Display the assembly and command windows.
28192
28193 @item split
28194 Display the source, assembly, and command windows.
28195
28196 @item regs
28197 When in @code{src} layout display the register, source, and command
28198 windows. When in @code{asm} or @code{split} layout display the
28199 register, assembler, and command windows.
28200 @end table
28201
28202 @item focus @var{name}
28203 @kindex focus
28204 Changes which TUI window is currently active for scrolling. The
28205 @var{name} parameter can be any of the following:
28206
28207 @table @code
28208 @item next
28209 Make the next window active for scrolling.
28210
28211 @item prev
28212 Make the previous window active for scrolling.
28213
28214 @item src
28215 Make the source window active for scrolling.
28216
28217 @item asm
28218 Make the assembly window active for scrolling.
28219
28220 @item regs
28221 Make the register window active for scrolling.
28222
28223 @item cmd
28224 Make the command window active for scrolling.
28225 @end table
28226
28227 @item refresh
28228 @kindex refresh
28229 Refresh the screen. This is similar to typing @kbd{C-L}.
28230
28231 @item tui reg @var{group}
28232 @kindex tui reg
28233 Changes the register group displayed in the tui register window to
28234 @var{group}. If the register window is not currently displayed this
28235 command will cause the register window to be displayed. The list of
28236 register groups, as well as their order is target specific. The
28237 following groups are available on most targets:
28238 @table @code
28239 @item next
28240 Repeatedly selecting this group will cause the display to cycle
28241 through all of the available register groups.
28242
28243 @item prev
28244 Repeatedly selecting this group will cause the display to cycle
28245 through all of the available register groups in the reverse order to
28246 @var{next}.
28247
28248 @item general
28249 Display the general registers.
28250 @item float
28251 Display the floating point registers.
28252 @item system
28253 Display the system registers.
28254 @item vector
28255 Display the vector registers.
28256 @item all
28257 Display all registers.
28258 @end table
28259
28260 @item update
28261 @kindex update
28262 Update the source window and the current execution point.
28263
28264 @item winheight @var{name} +@var{count}
28265 @itemx winheight @var{name} -@var{count}
28266 @kindex winheight
28267 Change the height of the window @var{name} by @var{count}
28268 lines. Positive counts increase the height, while negative counts
28269 decrease it. The @var{name} parameter can be one of @code{src} (the
28270 source window), @code{cmd} (the command window), @code{asm} (the
28271 disassembly window), or @code{regs} (the register display window).
28272 @end table
28273
28274 @node TUI Configuration
28275 @section TUI Configuration Variables
28276 @cindex TUI configuration variables
28277
28278 Several configuration variables control the appearance of TUI windows.
28279
28280 @table @code
28281 @item set tui border-kind @var{kind}
28282 @kindex set tui border-kind
28283 Select the border appearance for the source, assembly and register windows.
28284 The possible values are the following:
28285 @table @code
28286 @item space
28287 Use a space character to draw the border.
28288
28289 @item ascii
28290 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28291
28292 @item acs
28293 Use the Alternate Character Set to draw the border. The border is
28294 drawn using character line graphics if the terminal supports them.
28295 @end table
28296
28297 @item set tui border-mode @var{mode}
28298 @kindex set tui border-mode
28299 @itemx set tui active-border-mode @var{mode}
28300 @kindex set tui active-border-mode
28301 Select the display attributes for the borders of the inactive windows
28302 or the active window. The @var{mode} can be one of the following:
28303 @table @code
28304 @item normal
28305 Use normal attributes to display the border.
28306
28307 @item standout
28308 Use standout mode.
28309
28310 @item reverse
28311 Use reverse video mode.
28312
28313 @item half
28314 Use half bright mode.
28315
28316 @item half-standout
28317 Use half bright and standout mode.
28318
28319 @item bold
28320 Use extra bright or bold mode.
28321
28322 @item bold-standout
28323 Use extra bright or bold and standout mode.
28324 @end table
28325
28326 @item set tui tab-width @var{nchars}
28327 @kindex set tui tab-width
28328 @kindex tabset
28329 Set the width of tab stops to be @var{nchars} characters. This
28330 setting affects the display of TAB characters in the source and
28331 assembly windows.
28332
28333 @item set tui compact-source @r{[}on@r{|}off@r{]}
28334 @kindex set tui compact-source
28335 Set whether the TUI source window is displayed in ``compact'' form.
28336 The default display uses more space for line numbers and starts the
28337 source text at the next tab stop; the compact display uses only as
28338 much space as is needed for the line numbers in the current file, and
28339 only a single space to separate the line numbers from the source.
28340 @end table
28341
28342 Note that the colors of the TUI borders can be controlled using the
28343 appropriate @code{set style} commands. @xref{Output Styling}.
28344
28345 @node Emacs
28346 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28347
28348 @cindex Emacs
28349 @cindex @sc{gnu} Emacs
28350 A special interface allows you to use @sc{gnu} Emacs to view (and
28351 edit) the source files for the program you are debugging with
28352 @value{GDBN}.
28353
28354 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28355 executable file you want to debug as an argument. This command starts
28356 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28357 created Emacs buffer.
28358 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28359
28360 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28361 things:
28362
28363 @itemize @bullet
28364 @item
28365 All ``terminal'' input and output goes through an Emacs buffer, called
28366 the GUD buffer.
28367
28368 This applies both to @value{GDBN} commands and their output, and to the input
28369 and output done by the program you are debugging.
28370
28371 This is useful because it means that you can copy the text of previous
28372 commands and input them again; you can even use parts of the output
28373 in this way.
28374
28375 All the facilities of Emacs' Shell mode are available for interacting
28376 with your program. In particular, you can send signals the usual
28377 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28378 stop.
28379
28380 @item
28381 @value{GDBN} displays source code through Emacs.
28382
28383 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28384 source file for that frame and puts an arrow (@samp{=>}) at the
28385 left margin of the current line. Emacs uses a separate buffer for
28386 source display, and splits the screen to show both your @value{GDBN} session
28387 and the source.
28388
28389 Explicit @value{GDBN} @code{list} or search commands still produce output as
28390 usual, but you probably have no reason to use them from Emacs.
28391 @end itemize
28392
28393 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28394 a graphical mode, enabled by default, which provides further buffers
28395 that can control the execution and describe the state of your program.
28396 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28397
28398 If you specify an absolute file name when prompted for the @kbd{M-x
28399 gdb} argument, then Emacs sets your current working directory to where
28400 your program resides. If you only specify the file name, then Emacs
28401 sets your current working directory to the directory associated
28402 with the previous buffer. In this case, @value{GDBN} may find your
28403 program by searching your environment's @code{PATH} variable, but on
28404 some operating systems it might not find the source. So, although the
28405 @value{GDBN} input and output session proceeds normally, the auxiliary
28406 buffer does not display the current source and line of execution.
28407
28408 The initial working directory of @value{GDBN} is printed on the top
28409 line of the GUD buffer and this serves as a default for the commands
28410 that specify files for @value{GDBN} to operate on. @xref{Files,
28411 ,Commands to Specify Files}.
28412
28413 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28414 need to call @value{GDBN} by a different name (for example, if you
28415 keep several configurations around, with different names) you can
28416 customize the Emacs variable @code{gud-gdb-command-name} to run the
28417 one you want.
28418
28419 In the GUD buffer, you can use these special Emacs commands in
28420 addition to the standard Shell mode commands:
28421
28422 @table @kbd
28423 @item C-h m
28424 Describe the features of Emacs' GUD Mode.
28425
28426 @item C-c C-s
28427 Execute to another source line, like the @value{GDBN} @code{step} command; also
28428 update the display window to show the current file and location.
28429
28430 @item C-c C-n
28431 Execute to next source line in this function, skipping all function
28432 calls, like the @value{GDBN} @code{next} command. Then update the display window
28433 to show the current file and location.
28434
28435 @item C-c C-i
28436 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28437 display window accordingly.
28438
28439 @item C-c C-f
28440 Execute until exit from the selected stack frame, like the @value{GDBN}
28441 @code{finish} command.
28442
28443 @item C-c C-r
28444 Continue execution of your program, like the @value{GDBN} @code{continue}
28445 command.
28446
28447 @item C-c <
28448 Go up the number of frames indicated by the numeric argument
28449 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28450 like the @value{GDBN} @code{up} command.
28451
28452 @item C-c >
28453 Go down the number of frames indicated by the numeric argument, like the
28454 @value{GDBN} @code{down} command.
28455 @end table
28456
28457 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28458 tells @value{GDBN} to set a breakpoint on the source line point is on.
28459
28460 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28461 separate frame which shows a backtrace when the GUD buffer is current.
28462 Move point to any frame in the stack and type @key{RET} to make it
28463 become the current frame and display the associated source in the
28464 source buffer. Alternatively, click @kbd{Mouse-2} to make the
28465 selected frame become the current one. In graphical mode, the
28466 speedbar displays watch expressions.
28467
28468 If you accidentally delete the source-display buffer, an easy way to get
28469 it back is to type the command @code{f} in the @value{GDBN} buffer, to
28470 request a frame display; when you run under Emacs, this recreates
28471 the source buffer if necessary to show you the context of the current
28472 frame.
28473
28474 The source files displayed in Emacs are in ordinary Emacs buffers
28475 which are visiting the source files in the usual way. You can edit
28476 the files with these buffers if you wish; but keep in mind that @value{GDBN}
28477 communicates with Emacs in terms of line numbers. If you add or
28478 delete lines from the text, the line numbers that @value{GDBN} knows cease
28479 to correspond properly with the code.
28480
28481 A more detailed description of Emacs' interaction with @value{GDBN} is
28482 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28483 Emacs Manual}).
28484
28485 @node GDB/MI
28486 @chapter The @sc{gdb/mi} Interface
28487
28488 @unnumberedsec Function and Purpose
28489
28490 @cindex @sc{gdb/mi}, its purpose
28491 @sc{gdb/mi} is a line based machine oriented text interface to
28492 @value{GDBN} and is activated by specifying using the
28493 @option{--interpreter} command line option (@pxref{Mode Options}). It
28494 is specifically intended to support the development of systems which
28495 use the debugger as just one small component of a larger system.
28496
28497 This chapter is a specification of the @sc{gdb/mi} interface. It is written
28498 in the form of a reference manual.
28499
28500 Note that @sc{gdb/mi} is still under construction, so some of the
28501 features described below are incomplete and subject to change
28502 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28503
28504 @unnumberedsec Notation and Terminology
28505
28506 @cindex notational conventions, for @sc{gdb/mi}
28507 This chapter uses the following notation:
28508
28509 @itemize @bullet
28510 @item
28511 @code{|} separates two alternatives.
28512
28513 @item
28514 @code{[ @var{something} ]} indicates that @var{something} is optional:
28515 it may or may not be given.
28516
28517 @item
28518 @code{( @var{group} )*} means that @var{group} inside the parentheses
28519 may repeat zero or more times.
28520
28521 @item
28522 @code{( @var{group} )+} means that @var{group} inside the parentheses
28523 may repeat one or more times.
28524
28525 @item
28526 @code{"@var{string}"} means a literal @var{string}.
28527 @end itemize
28528
28529 @ignore
28530 @heading Dependencies
28531 @end ignore
28532
28533 @menu
28534 * GDB/MI General Design::
28535 * GDB/MI Command Syntax::
28536 * GDB/MI Compatibility with CLI::
28537 * GDB/MI Development and Front Ends::
28538 * GDB/MI Output Records::
28539 * GDB/MI Simple Examples::
28540 * GDB/MI Command Description Format::
28541 * GDB/MI Breakpoint Commands::
28542 * GDB/MI Catchpoint Commands::
28543 * GDB/MI Program Context::
28544 * GDB/MI Thread Commands::
28545 * GDB/MI Ada Tasking Commands::
28546 * GDB/MI Program Execution::
28547 * GDB/MI Stack Manipulation::
28548 * GDB/MI Variable Objects::
28549 * GDB/MI Data Manipulation::
28550 * GDB/MI Tracepoint Commands::
28551 * GDB/MI Symbol Query::
28552 * GDB/MI File Commands::
28553 @ignore
28554 * GDB/MI Kod Commands::
28555 * GDB/MI Memory Overlay Commands::
28556 * GDB/MI Signal Handling Commands::
28557 @end ignore
28558 * GDB/MI Target Manipulation::
28559 * GDB/MI File Transfer Commands::
28560 * GDB/MI Ada Exceptions Commands::
28561 * GDB/MI Support Commands::
28562 * GDB/MI Miscellaneous Commands::
28563 @end menu
28564
28565 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28566 @node GDB/MI General Design
28567 @section @sc{gdb/mi} General Design
28568 @cindex GDB/MI General Design
28569
28570 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28571 parts---commands sent to @value{GDBN}, responses to those commands
28572 and notifications. Each command results in exactly one response,
28573 indicating either successful completion of the command, or an error.
28574 For the commands that do not resume the target, the response contains the
28575 requested information. For the commands that resume the target, the
28576 response only indicates whether the target was successfully resumed.
28577 Notifications is the mechanism for reporting changes in the state of the
28578 target, or in @value{GDBN} state, that cannot conveniently be associated with
28579 a command and reported as part of that command response.
28580
28581 The important examples of notifications are:
28582 @itemize @bullet
28583
28584 @item
28585 Exec notifications. These are used to report changes in
28586 target state---when a target is resumed, or stopped. It would not
28587 be feasible to include this information in response of resuming
28588 commands, because one resume commands can result in multiple events in
28589 different threads. Also, quite some time may pass before any event
28590 happens in the target, while a frontend needs to know whether the resuming
28591 command itself was successfully executed.
28592
28593 @item
28594 Console output, and status notifications. Console output
28595 notifications are used to report output of CLI commands, as well as
28596 diagnostics for other commands. Status notifications are used to
28597 report the progress of a long-running operation. Naturally, including
28598 this information in command response would mean no output is produced
28599 until the command is finished, which is undesirable.
28600
28601 @item
28602 General notifications. Commands may have various side effects on
28603 the @value{GDBN} or target state beyond their official purpose. For example,
28604 a command may change the selected thread. Although such changes can
28605 be included in command response, using notification allows for more
28606 orthogonal frontend design.
28607
28608 @end itemize
28609
28610 There's no guarantee that whenever an MI command reports an error,
28611 @value{GDBN} or the target are in any specific state, and especially,
28612 the state is not reverted to the state before the MI command was
28613 processed. Therefore, whenever an MI command results in an error,
28614 we recommend that the frontend refreshes all the information shown in
28615 the user interface.
28616
28617
28618 @menu
28619 * Context management::
28620 * Asynchronous and non-stop modes::
28621 * Thread groups::
28622 @end menu
28623
28624 @node Context management
28625 @subsection Context management
28626
28627 @subsubsection Threads and Frames
28628
28629 In most cases when @value{GDBN} accesses the target, this access is
28630 done in context of a specific thread and frame (@pxref{Frames}).
28631 Often, even when accessing global data, the target requires that a thread
28632 be specified. The CLI interface maintains the selected thread and frame,
28633 and supplies them to target on each command. This is convenient,
28634 because a command line user would not want to specify that information
28635 explicitly on each command, and because user interacts with
28636 @value{GDBN} via a single terminal, so no confusion is possible as
28637 to what thread and frame are the current ones.
28638
28639 In the case of MI, the concept of selected thread and frame is less
28640 useful. First, a frontend can easily remember this information
28641 itself. Second, a graphical frontend can have more than one window,
28642 each one used for debugging a different thread, and the frontend might
28643 want to access additional threads for internal purposes. This
28644 increases the risk that by relying on implicitly selected thread, the
28645 frontend may be operating on a wrong one. Therefore, each MI command
28646 should explicitly specify which thread and frame to operate on. To
28647 make it possible, each MI command accepts the @samp{--thread} and
28648 @samp{--frame} options, the value to each is @value{GDBN} global
28649 identifier for thread and frame to operate on.
28650
28651 Usually, each top-level window in a frontend allows the user to select
28652 a thread and a frame, and remembers the user selection for further
28653 operations. However, in some cases @value{GDBN} may suggest that the
28654 current thread or frame be changed. For example, when stopping on a
28655 breakpoint it is reasonable to switch to the thread where breakpoint is
28656 hit. For another example, if the user issues the CLI @samp{thread} or
28657 @samp{frame} commands via the frontend, it is desirable to change the
28658 frontend's selection to the one specified by user. @value{GDBN}
28659 communicates the suggestion to change current thread and frame using the
28660 @samp{=thread-selected} notification.
28661
28662 Note that historically, MI shares the selected thread with CLI, so
28663 frontends used the @code{-thread-select} to execute commands in the
28664 right context. However, getting this to work right is cumbersome. The
28665 simplest way is for frontend to emit @code{-thread-select} command
28666 before every command. This doubles the number of commands that need
28667 to be sent. The alternative approach is to suppress @code{-thread-select}
28668 if the selected thread in @value{GDBN} is supposed to be identical to the
28669 thread the frontend wants to operate on. However, getting this
28670 optimization right can be tricky. In particular, if the frontend
28671 sends several commands to @value{GDBN}, and one of the commands changes the
28672 selected thread, then the behaviour of subsequent commands will
28673 change. So, a frontend should either wait for response from such
28674 problematic commands, or explicitly add @code{-thread-select} for
28675 all subsequent commands. No frontend is known to do this exactly
28676 right, so it is suggested to just always pass the @samp{--thread} and
28677 @samp{--frame} options.
28678
28679 @subsubsection Language
28680
28681 The execution of several commands depends on which language is selected.
28682 By default, the current language (@pxref{show language}) is used.
28683 But for commands known to be language-sensitive, it is recommended
28684 to use the @samp{--language} option. This option takes one argument,
28685 which is the name of the language to use while executing the command.
28686 For instance:
28687
28688 @smallexample
28689 -data-evaluate-expression --language c "sizeof (void*)"
28690 ^done,value="4"
28691 (gdb)
28692 @end smallexample
28693
28694 The valid language names are the same names accepted by the
28695 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28696 @samp{local} or @samp{unknown}.
28697
28698 @node Asynchronous and non-stop modes
28699 @subsection Asynchronous command execution and non-stop mode
28700
28701 On some targets, @value{GDBN} is capable of processing MI commands
28702 even while the target is running. This is called @dfn{asynchronous
28703 command execution} (@pxref{Background Execution}). The frontend may
28704 specify a preference for asynchronous execution using the
28705 @code{-gdb-set mi-async 1} command, which should be emitted before
28706 either running the executable or attaching to the target. After the
28707 frontend has started the executable or attached to the target, it can
28708 find if asynchronous execution is enabled using the
28709 @code{-list-target-features} command.
28710
28711 @table @code
28712 @item -gdb-set mi-async on
28713 @item -gdb-set mi-async off
28714 Set whether MI is in asynchronous mode.
28715
28716 When @code{off}, which is the default, MI execution commands (e.g.,
28717 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28718 for the program to stop before processing further commands.
28719
28720 When @code{on}, MI execution commands are background execution
28721 commands (e.g., @code{-exec-continue} becomes the equivalent of the
28722 @code{c&} CLI command), and so @value{GDBN} is capable of processing
28723 MI commands even while the target is running.
28724
28725 @item -gdb-show mi-async
28726 Show whether MI asynchronous mode is enabled.
28727 @end table
28728
28729 Note: In @value{GDBN} version 7.7 and earlier, this option was called
28730 @code{target-async} instead of @code{mi-async}, and it had the effect
28731 of both putting MI in asynchronous mode and making CLI background
28732 commands possible. CLI background commands are now always possible
28733 ``out of the box'' if the target supports them. The old spelling is
28734 kept as a deprecated alias for backwards compatibility.
28735
28736 Even if @value{GDBN} can accept a command while target is running,
28737 many commands that access the target do not work when the target is
28738 running. Therefore, asynchronous command execution is most useful
28739 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28740 it is possible to examine the state of one thread, while other threads
28741 are running.
28742
28743 When a given thread is running, MI commands that try to access the
28744 target in the context of that thread may not work, or may work only on
28745 some targets. In particular, commands that try to operate on thread's
28746 stack will not work, on any target. Commands that read memory, or
28747 modify breakpoints, may work or not work, depending on the target. Note
28748 that even commands that operate on global state, such as @code{print},
28749 @code{set}, and breakpoint commands, still access the target in the
28750 context of a specific thread, so frontend should try to find a
28751 stopped thread and perform the operation on that thread (using the
28752 @samp{--thread} option).
28753
28754 Which commands will work in the context of a running thread is
28755 highly target dependent. However, the two commands
28756 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28757 to find the state of a thread, will always work.
28758
28759 @node Thread groups
28760 @subsection Thread groups
28761 @value{GDBN} may be used to debug several processes at the same time.
28762 On some platforms, @value{GDBN} may support debugging of several
28763 hardware systems, each one having several cores with several different
28764 processes running on each core. This section describes the MI
28765 mechanism to support such debugging scenarios.
28766
28767 The key observation is that regardless of the structure of the
28768 target, MI can have a global list of threads, because most commands that
28769 accept the @samp{--thread} option do not need to know what process that
28770 thread belongs to. Therefore, it is not necessary to introduce
28771 neither additional @samp{--process} option, nor an notion of the
28772 current process in the MI interface. The only strictly new feature
28773 that is required is the ability to find how the threads are grouped
28774 into processes.
28775
28776 To allow the user to discover such grouping, and to support arbitrary
28777 hierarchy of machines/cores/processes, MI introduces the concept of a
28778 @dfn{thread group}. Thread group is a collection of threads and other
28779 thread groups. A thread group always has a string identifier, a type,
28780 and may have additional attributes specific to the type. A new
28781 command, @code{-list-thread-groups}, returns the list of top-level
28782 thread groups, which correspond to processes that @value{GDBN} is
28783 debugging at the moment. By passing an identifier of a thread group
28784 to the @code{-list-thread-groups} command, it is possible to obtain
28785 the members of specific thread group.
28786
28787 To allow the user to easily discover processes, and other objects, he
28788 wishes to debug, a concept of @dfn{available thread group} is
28789 introduced. Available thread group is an thread group that
28790 @value{GDBN} is not debugging, but that can be attached to, using the
28791 @code{-target-attach} command. The list of available top-level thread
28792 groups can be obtained using @samp{-list-thread-groups --available}.
28793 In general, the content of a thread group may be only retrieved only
28794 after attaching to that thread group.
28795
28796 Thread groups are related to inferiors (@pxref{Inferiors Connections and
28797 Programs}). Each inferior corresponds to a thread group of a special
28798 type @samp{process}, and some additional operations are permitted on
28799 such thread groups.
28800
28801 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28802 @node GDB/MI Command Syntax
28803 @section @sc{gdb/mi} Command Syntax
28804
28805 @menu
28806 * GDB/MI Input Syntax::
28807 * GDB/MI Output Syntax::
28808 @end menu
28809
28810 @node GDB/MI Input Syntax
28811 @subsection @sc{gdb/mi} Input Syntax
28812
28813 @cindex input syntax for @sc{gdb/mi}
28814 @cindex @sc{gdb/mi}, input syntax
28815 @table @code
28816 @item @var{command} @expansion{}
28817 @code{@var{cli-command} | @var{mi-command}}
28818
28819 @item @var{cli-command} @expansion{}
28820 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28821 @var{cli-command} is any existing @value{GDBN} CLI command.
28822
28823 @item @var{mi-command} @expansion{}
28824 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28825 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28826
28827 @item @var{token} @expansion{}
28828 "any sequence of digits"
28829
28830 @item @var{option} @expansion{}
28831 @code{"-" @var{parameter} [ " " @var{parameter} ]}
28832
28833 @item @var{parameter} @expansion{}
28834 @code{@var{non-blank-sequence} | @var{c-string}}
28835
28836 @item @var{operation} @expansion{}
28837 @emph{any of the operations described in this chapter}
28838
28839 @item @var{non-blank-sequence} @expansion{}
28840 @emph{anything, provided it doesn't contain special characters such as
28841 "-", @var{nl}, """ and of course " "}
28842
28843 @item @var{c-string} @expansion{}
28844 @code{""" @var{seven-bit-iso-c-string-content} """}
28845
28846 @item @var{nl} @expansion{}
28847 @code{CR | CR-LF}
28848 @end table
28849
28850 @noindent
28851 Notes:
28852
28853 @itemize @bullet
28854 @item
28855 The CLI commands are still handled by the @sc{mi} interpreter; their
28856 output is described below.
28857
28858 @item
28859 The @code{@var{token}}, when present, is passed back when the command
28860 finishes.
28861
28862 @item
28863 Some @sc{mi} commands accept optional arguments as part of the parameter
28864 list. Each option is identified by a leading @samp{-} (dash) and may be
28865 followed by an optional argument parameter. Options occur first in the
28866 parameter list and can be delimited from normal parameters using
28867 @samp{--} (this is useful when some parameters begin with a dash).
28868 @end itemize
28869
28870 Pragmatics:
28871
28872 @itemize @bullet
28873 @item
28874 We want easy access to the existing CLI syntax (for debugging).
28875
28876 @item
28877 We want it to be easy to spot a @sc{mi} operation.
28878 @end itemize
28879
28880 @node GDB/MI Output Syntax
28881 @subsection @sc{gdb/mi} Output Syntax
28882
28883 @cindex output syntax of @sc{gdb/mi}
28884 @cindex @sc{gdb/mi}, output syntax
28885 The output from @sc{gdb/mi} consists of zero or more out-of-band records
28886 followed, optionally, by a single result record. This result record
28887 is for the most recent command. The sequence of output records is
28888 terminated by @samp{(gdb)}.
28889
28890 If an input command was prefixed with a @code{@var{token}} then the
28891 corresponding output for that command will also be prefixed by that same
28892 @var{token}.
28893
28894 @table @code
28895 @item @var{output} @expansion{}
28896 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
28897
28898 @item @var{result-record} @expansion{}
28899 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28900
28901 @item @var{out-of-band-record} @expansion{}
28902 @code{@var{async-record} | @var{stream-record}}
28903
28904 @item @var{async-record} @expansion{}
28905 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28906
28907 @item @var{exec-async-output} @expansion{}
28908 @code{[ @var{token} ] "*" @var{async-output nl}}
28909
28910 @item @var{status-async-output} @expansion{}
28911 @code{[ @var{token} ] "+" @var{async-output nl}}
28912
28913 @item @var{notify-async-output} @expansion{}
28914 @code{[ @var{token} ] "=" @var{async-output nl}}
28915
28916 @item @var{async-output} @expansion{}
28917 @code{@var{async-class} ( "," @var{result} )*}
28918
28919 @item @var{result-class} @expansion{}
28920 @code{"done" | "running" | "connected" | "error" | "exit"}
28921
28922 @item @var{async-class} @expansion{}
28923 @code{"stopped" | @var{others}} (where @var{others} will be added
28924 depending on the needs---this is still in development).
28925
28926 @item @var{result} @expansion{}
28927 @code{ @var{variable} "=" @var{value}}
28928
28929 @item @var{variable} @expansion{}
28930 @code{ @var{string} }
28931
28932 @item @var{value} @expansion{}
28933 @code{ @var{const} | @var{tuple} | @var{list} }
28934
28935 @item @var{const} @expansion{}
28936 @code{@var{c-string}}
28937
28938 @item @var{tuple} @expansion{}
28939 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28940
28941 @item @var{list} @expansion{}
28942 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28943 @var{result} ( "," @var{result} )* "]" }
28944
28945 @item @var{stream-record} @expansion{}
28946 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28947
28948 @item @var{console-stream-output} @expansion{}
28949 @code{"~" @var{c-string nl}}
28950
28951 @item @var{target-stream-output} @expansion{}
28952 @code{"@@" @var{c-string nl}}
28953
28954 @item @var{log-stream-output} @expansion{}
28955 @code{"&" @var{c-string nl}}
28956
28957 @item @var{nl} @expansion{}
28958 @code{CR | CR-LF}
28959
28960 @item @var{token} @expansion{}
28961 @emph{any sequence of digits}.
28962 @end table
28963
28964 @noindent
28965 Notes:
28966
28967 @itemize @bullet
28968 @item
28969 All output sequences end in a single line containing a period.
28970
28971 @item
28972 The @code{@var{token}} is from the corresponding request. Note that
28973 for all async output, while the token is allowed by the grammar and
28974 may be output by future versions of @value{GDBN} for select async
28975 output messages, it is generally omitted. Frontends should treat
28976 all async output as reporting general changes in the state of the
28977 target and there should be no need to associate async output to any
28978 prior command.
28979
28980 @item
28981 @cindex status output in @sc{gdb/mi}
28982 @var{status-async-output} contains on-going status information about the
28983 progress of a slow operation. It can be discarded. All status output is
28984 prefixed by @samp{+}.
28985
28986 @item
28987 @cindex async output in @sc{gdb/mi}
28988 @var{exec-async-output} contains asynchronous state change on the target
28989 (stopped, started, disappeared). All async output is prefixed by
28990 @samp{*}.
28991
28992 @item
28993 @cindex notify output in @sc{gdb/mi}
28994 @var{notify-async-output} contains supplementary information that the
28995 client should handle (e.g., a new breakpoint information). All notify
28996 output is prefixed by @samp{=}.
28997
28998 @item
28999 @cindex console output in @sc{gdb/mi}
29000 @var{console-stream-output} is output that should be displayed as is in the
29001 console. It is the textual response to a CLI command. All the console
29002 output is prefixed by @samp{~}.
29003
29004 @item
29005 @cindex target output in @sc{gdb/mi}
29006 @var{target-stream-output} is the output produced by the target program.
29007 All the target output is prefixed by @samp{@@}.
29008
29009 @item
29010 @cindex log output in @sc{gdb/mi}
29011 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29012 instance messages that should be displayed as part of an error log. All
29013 the log output is prefixed by @samp{&}.
29014
29015 @item
29016 @cindex list output in @sc{gdb/mi}
29017 New @sc{gdb/mi} commands should only output @var{lists} containing
29018 @var{values}.
29019
29020
29021 @end itemize
29022
29023 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29024 details about the various output records.
29025
29026 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29027 @node GDB/MI Compatibility with CLI
29028 @section @sc{gdb/mi} Compatibility with CLI
29029
29030 @cindex compatibility, @sc{gdb/mi} and CLI
29031 @cindex @sc{gdb/mi}, compatibility with CLI
29032
29033 For the developers convenience CLI commands can be entered directly,
29034 but there may be some unexpected behaviour. For example, commands
29035 that query the user will behave as if the user replied yes, breakpoint
29036 command lists are not executed and some CLI commands, such as
29037 @code{if}, @code{when} and @code{define}, prompt for further input with
29038 @samp{>}, which is not valid MI output.
29039
29040 This feature may be removed at some stage in the future and it is
29041 recommended that front ends use the @code{-interpreter-exec} command
29042 (@pxref{-interpreter-exec}).
29043
29044 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29045 @node GDB/MI Development and Front Ends
29046 @section @sc{gdb/mi} Development and Front Ends
29047 @cindex @sc{gdb/mi} development
29048
29049 The application which takes the MI output and presents the state of the
29050 program being debugged to the user is called a @dfn{front end}.
29051
29052 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29053 to the MI interface may break existing usage. This section describes how the
29054 protocol changes and how to request previous version of the protocol when it
29055 does.
29056
29057 Some changes in MI need not break a carefully designed front end, and
29058 for these the MI version will remain unchanged. The following is a
29059 list of changes that may occur within one level, so front ends should
29060 parse MI output in a way that can handle them:
29061
29062 @itemize @bullet
29063 @item
29064 New MI commands may be added.
29065
29066 @item
29067 New fields may be added to the output of any MI command.
29068
29069 @item
29070 The range of values for fields with specified values, e.g.,
29071 @code{in_scope} (@pxref{-var-update}) may be extended.
29072
29073 @c The format of field's content e.g type prefix, may change so parse it
29074 @c at your own risk. Yes, in general?
29075
29076 @c The order of fields may change? Shouldn't really matter but it might
29077 @c resolve inconsistencies.
29078 @end itemize
29079
29080 If the changes are likely to break front ends, the MI version level
29081 will be increased by one. The new versions of the MI protocol are not compatible
29082 with the old versions. Old versions of MI remain available, allowing front ends
29083 to keep using them until they are modified to use the latest MI version.
29084
29085 Since @code{--interpreter=mi} always points to the latest MI version, it is
29086 recommended that front ends request a specific version of MI when launching
29087 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29088 interpreter with the MI version they expect.
29089
29090 The following table gives a summary of the released versions of the MI
29091 interface: the version number, the version of GDB in which it first appeared
29092 and the breaking changes compared to the previous version.
29093
29094 @multitable @columnfractions .05 .05 .9
29095 @headitem MI version @tab GDB version @tab Breaking changes
29096
29097 @item
29098 @center 1
29099 @tab
29100 @center 5.1
29101 @tab
29102 None
29103
29104 @item
29105 @center 2
29106 @tab
29107 @center 6.0
29108 @tab
29109
29110 @itemize
29111 @item
29112 The @code{-environment-pwd}, @code{-environment-directory} and
29113 @code{-environment-path} commands now returns values using the MI output
29114 syntax, rather than CLI output syntax.
29115
29116 @item
29117 @code{-var-list-children}'s @code{children} result field is now a list, rather
29118 than a tuple.
29119
29120 @item
29121 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29122 a tuple.
29123 @end itemize
29124
29125 @item
29126 @center 3
29127 @tab
29128 @center 9.1
29129 @tab
29130
29131 @itemize
29132 @item
29133 The output of information about multi-location breakpoints has changed in the
29134 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29135 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29136 The multiple locations are now placed in a @code{locations} field, whose value
29137 is a list.
29138 @end itemize
29139
29140 @end multitable
29141
29142 If your front end cannot yet migrate to a more recent version of the
29143 MI protocol, you can nevertheless selectively enable specific features
29144 available in those recent MI versions, using the following commands:
29145
29146 @table @code
29147
29148 @item -fix-multi-location-breakpoint-output
29149 Use the output for multi-location breakpoints which was introduced by
29150 MI 3, even when using MI versions 2 or 1. This command has no
29151 effect when using MI version 3 or later.
29152
29153 @end table
29154
29155 The best way to avoid unexpected changes in MI that might break your front
29156 end is to make your project known to @value{GDBN} developers and
29157 follow development on @email{gdb@@sourceware.org} and
29158 @email{gdb-patches@@sourceware.org}.
29159 @cindex mailing lists
29160
29161 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29162 @node GDB/MI Output Records
29163 @section @sc{gdb/mi} Output Records
29164
29165 @menu
29166 * GDB/MI Result Records::
29167 * GDB/MI Stream Records::
29168 * GDB/MI Async Records::
29169 * GDB/MI Breakpoint Information::
29170 * GDB/MI Frame Information::
29171 * GDB/MI Thread Information::
29172 * GDB/MI Ada Exception Information::
29173 @end menu
29174
29175 @node GDB/MI Result Records
29176 @subsection @sc{gdb/mi} Result Records
29177
29178 @cindex result records in @sc{gdb/mi}
29179 @cindex @sc{gdb/mi}, result records
29180 In addition to a number of out-of-band notifications, the response to a
29181 @sc{gdb/mi} command includes one of the following result indications:
29182
29183 @table @code
29184 @findex ^done
29185 @item "^done" [ "," @var{results} ]
29186 The synchronous operation was successful, @code{@var{results}} are the return
29187 values.
29188
29189 @item "^running"
29190 @findex ^running
29191 This result record is equivalent to @samp{^done}. Historically, it
29192 was output instead of @samp{^done} if the command has resumed the
29193 target. This behaviour is maintained for backward compatibility, but
29194 all frontends should treat @samp{^done} and @samp{^running}
29195 identically and rely on the @samp{*running} output record to determine
29196 which threads are resumed.
29197
29198 @item "^connected"
29199 @findex ^connected
29200 @value{GDBN} has connected to a remote target.
29201
29202 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29203 @findex ^error
29204 The operation failed. The @code{msg=@var{c-string}} variable contains
29205 the corresponding error message.
29206
29207 If present, the @code{code=@var{c-string}} variable provides an error
29208 code on which consumers can rely on to detect the corresponding
29209 error condition. At present, only one error code is defined:
29210
29211 @table @samp
29212 @item "undefined-command"
29213 Indicates that the command causing the error does not exist.
29214 @end table
29215
29216 @item "^exit"
29217 @findex ^exit
29218 @value{GDBN} has terminated.
29219
29220 @end table
29221
29222 @node GDB/MI Stream Records
29223 @subsection @sc{gdb/mi} Stream Records
29224
29225 @cindex @sc{gdb/mi}, stream records
29226 @cindex stream records in @sc{gdb/mi}
29227 @value{GDBN} internally maintains a number of output streams: the console, the
29228 target, and the log. The output intended for each of these streams is
29229 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29230
29231 Each stream record begins with a unique @dfn{prefix character} which
29232 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29233 Syntax}). In addition to the prefix, each stream record contains a
29234 @code{@var{string-output}}. This is either raw text (with an implicit new
29235 line) or a quoted C string (which does not contain an implicit newline).
29236
29237 @table @code
29238 @item "~" @var{string-output}
29239 The console output stream contains text that should be displayed in the
29240 CLI console window. It contains the textual responses to CLI commands.
29241
29242 @item "@@" @var{string-output}
29243 The target output stream contains any textual output from the running
29244 target. This is only present when GDB's event loop is truly
29245 asynchronous, which is currently only the case for remote targets.
29246
29247 @item "&" @var{string-output}
29248 The log stream contains debugging messages being produced by @value{GDBN}'s
29249 internals.
29250 @end table
29251
29252 @node GDB/MI Async Records
29253 @subsection @sc{gdb/mi} Async Records
29254
29255 @cindex async records in @sc{gdb/mi}
29256 @cindex @sc{gdb/mi}, async records
29257 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29258 additional changes that have occurred. Those changes can either be a
29259 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29260 target activity (e.g., target stopped).
29261
29262 The following is the list of possible async records:
29263
29264 @table @code
29265
29266 @item *running,thread-id="@var{thread}"
29267 The target is now running. The @var{thread} field can be the global
29268 thread ID of the thread that is now running, and it can be
29269 @samp{all} if all threads are running. The frontend should assume
29270 that no interaction with a running thread is possible after this
29271 notification is produced. The frontend should not assume that this
29272 notification is output only once for any command. @value{GDBN} may
29273 emit this notification several times, either for different threads,
29274 because it cannot resume all threads together, or even for a single
29275 thread, if the thread must be stepped though some code before letting
29276 it run freely.
29277
29278 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29279 The target has stopped. The @var{reason} field can have one of the
29280 following values:
29281
29282 @table @code
29283 @item breakpoint-hit
29284 A breakpoint was reached.
29285 @item watchpoint-trigger
29286 A watchpoint was triggered.
29287 @item read-watchpoint-trigger
29288 A read watchpoint was triggered.
29289 @item access-watchpoint-trigger
29290 An access watchpoint was triggered.
29291 @item function-finished
29292 An -exec-finish or similar CLI command was accomplished.
29293 @item location-reached
29294 An -exec-until or similar CLI command was accomplished.
29295 @item watchpoint-scope
29296 A watchpoint has gone out of scope.
29297 @item end-stepping-range
29298 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29299 similar CLI command was accomplished.
29300 @item exited-signalled
29301 The inferior exited because of a signal.
29302 @item exited
29303 The inferior exited.
29304 @item exited-normally
29305 The inferior exited normally.
29306 @item signal-received
29307 A signal was received by the inferior.
29308 @item solib-event
29309 The inferior has stopped due to a library being loaded or unloaded.
29310 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29311 set or when a @code{catch load} or @code{catch unload} catchpoint is
29312 in use (@pxref{Set Catchpoints}).
29313 @item fork
29314 The inferior has forked. This is reported when @code{catch fork}
29315 (@pxref{Set Catchpoints}) has been used.
29316 @item vfork
29317 The inferior has vforked. This is reported in when @code{catch vfork}
29318 (@pxref{Set Catchpoints}) has been used.
29319 @item syscall-entry
29320 The inferior entered a system call. This is reported when @code{catch
29321 syscall} (@pxref{Set Catchpoints}) has been used.
29322 @item syscall-return
29323 The inferior returned from a system call. This is reported when
29324 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29325 @item exec
29326 The inferior called @code{exec}. This is reported when @code{catch exec}
29327 (@pxref{Set Catchpoints}) has been used.
29328 @end table
29329
29330 The @var{id} field identifies the global thread ID of the thread
29331 that directly caused the stop -- for example by hitting a breakpoint.
29332 Depending on whether all-stop
29333 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29334 stop all threads, or only the thread that directly triggered the stop.
29335 If all threads are stopped, the @var{stopped} field will have the
29336 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29337 field will be a list of thread identifiers. Presently, this list will
29338 always include a single thread, but frontend should be prepared to see
29339 several threads in the list. The @var{core} field reports the
29340 processor core on which the stop event has happened. This field may be absent
29341 if such information is not available.
29342
29343 @item =thread-group-added,id="@var{id}"
29344 @itemx =thread-group-removed,id="@var{id}"
29345 A thread group was either added or removed. The @var{id} field
29346 contains the @value{GDBN} identifier of the thread group. When a thread
29347 group is added, it generally might not be associated with a running
29348 process. When a thread group is removed, its id becomes invalid and
29349 cannot be used in any way.
29350
29351 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29352 A thread group became associated with a running program,
29353 either because the program was just started or the thread group
29354 was attached to a program. The @var{id} field contains the
29355 @value{GDBN} identifier of the thread group. The @var{pid} field
29356 contains process identifier, specific to the operating system.
29357
29358 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29359 A thread group is no longer associated with a running program,
29360 either because the program has exited, or because it was detached
29361 from. The @var{id} field contains the @value{GDBN} identifier of the
29362 thread group. The @var{code} field is the exit code of the inferior; it exists
29363 only when the inferior exited with some code.
29364
29365 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29366 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29367 A thread either was created, or has exited. The @var{id} field
29368 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29369 field identifies the thread group this thread belongs to.
29370
29371 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29372 Informs that the selected thread or frame were changed. This notification
29373 is not emitted as result of the @code{-thread-select} or
29374 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29375 that is not documented to change the selected thread and frame actually
29376 changes them. In particular, invoking, directly or indirectly
29377 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29378 will generate this notification. Changing the thread or frame from another
29379 user interface (see @ref{Interpreters}) will also generate this notification.
29380
29381 The @var{frame} field is only present if the newly selected thread is
29382 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29383
29384 We suggest that in response to this notification, front ends
29385 highlight the selected thread and cause subsequent commands to apply to
29386 that thread.
29387
29388 @item =library-loaded,...
29389 Reports that a new library file was loaded by the program. This
29390 notification has 5 fields---@var{id}, @var{target-name},
29391 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29392 opaque identifier of the library. For remote debugging case,
29393 @var{target-name} and @var{host-name} fields give the name of the
29394 library file on the target, and on the host respectively. For native
29395 debugging, both those fields have the same value. The
29396 @var{symbols-loaded} field is emitted only for backward compatibility
29397 and should not be relied on to convey any useful information. The
29398 @var{thread-group} field, if present, specifies the id of the thread
29399 group in whose context the library was loaded. If the field is
29400 absent, it means the library was loaded in the context of all present
29401 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29402 to this library.
29403
29404 @item =library-unloaded,...
29405 Reports that a library was unloaded by the program. This notification
29406 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29407 the same meaning as for the @code{=library-loaded} notification.
29408 The @var{thread-group} field, if present, specifies the id of the
29409 thread group in whose context the library was unloaded. If the field is
29410 absent, it means the library was unloaded in the context of all present
29411 thread groups.
29412
29413 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29414 @itemx =traceframe-changed,end
29415 Reports that the trace frame was changed and its new number is
29416 @var{tfnum}. The number of the tracepoint associated with this trace
29417 frame is @var{tpnum}.
29418
29419 @item =tsv-created,name=@var{name},initial=@var{initial}
29420 Reports that the new trace state variable @var{name} is created with
29421 initial value @var{initial}.
29422
29423 @item =tsv-deleted,name=@var{name}
29424 @itemx =tsv-deleted
29425 Reports that the trace state variable @var{name} is deleted or all
29426 trace state variables are deleted.
29427
29428 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29429 Reports that the trace state variable @var{name} is modified with
29430 the initial value @var{initial}. The current value @var{current} of
29431 trace state variable is optional and is reported if the current
29432 value of trace state variable is known.
29433
29434 @item =breakpoint-created,bkpt=@{...@}
29435 @itemx =breakpoint-modified,bkpt=@{...@}
29436 @itemx =breakpoint-deleted,id=@var{number}
29437 Reports that a breakpoint was created, modified, or deleted,
29438 respectively. Only user-visible breakpoints are reported to the MI
29439 user.
29440
29441 The @var{bkpt} argument is of the same form as returned by the various
29442 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29443 @var{number} is the ordinal number of the breakpoint.
29444
29445 Note that if a breakpoint is emitted in the result record of a
29446 command, then it will not also be emitted in an async record.
29447
29448 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29449 @itemx =record-stopped,thread-group="@var{id}"
29450 Execution log recording was either started or stopped on an
29451 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29452 group corresponding to the affected inferior.
29453
29454 The @var{method} field indicates the method used to record execution. If the
29455 method in use supports multiple recording formats, @var{format} will be present
29456 and contain the currently used format. @xref{Process Record and Replay},
29457 for existing method and format values.
29458
29459 @item =cmd-param-changed,param=@var{param},value=@var{value}
29460 Reports that a parameter of the command @code{set @var{param}} is
29461 changed to @var{value}. In the multi-word @code{set} command,
29462 the @var{param} is the whole parameter list to @code{set} command.
29463 For example, In command @code{set check type on}, @var{param}
29464 is @code{check type} and @var{value} is @code{on}.
29465
29466 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29467 Reports that bytes from @var{addr} to @var{data} + @var{len} were
29468 written in an inferior. The @var{id} is the identifier of the
29469 thread group corresponding to the affected inferior. The optional
29470 @code{type="code"} part is reported if the memory written to holds
29471 executable code.
29472 @end table
29473
29474 @node GDB/MI Breakpoint Information
29475 @subsection @sc{gdb/mi} Breakpoint Information
29476
29477 When @value{GDBN} reports information about a breakpoint, a
29478 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29479 following fields:
29480
29481 @table @code
29482 @item number
29483 The breakpoint number.
29484
29485 @item type
29486 The type of the breakpoint. For ordinary breakpoints this will be
29487 @samp{breakpoint}, but many values are possible.
29488
29489 @item catch-type
29490 If the type of the breakpoint is @samp{catchpoint}, then this
29491 indicates the exact type of catchpoint.
29492
29493 @item disp
29494 This is the breakpoint disposition---either @samp{del}, meaning that
29495 the breakpoint will be deleted at the next stop, or @samp{keep},
29496 meaning that the breakpoint will not be deleted.
29497
29498 @item enabled
29499 This indicates whether the breakpoint is enabled, in which case the
29500 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29501 Note that this is not the same as the field @code{enable}.
29502
29503 @item addr
29504 The address of the breakpoint. This may be a hexidecimal number,
29505 giving the address; or the string @samp{<PENDING>}, for a pending
29506 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29507 multiple locations. This field will not be present if no address can
29508 be determined. For example, a watchpoint does not have an address.
29509
29510 @item addr_flags
29511 Optional field containing any flags related to the address. These flags are
29512 architecture-dependent; see @ref{Architectures} for their meaning for a
29513 particular CPU.
29514
29515 @item func
29516 If known, the function in which the breakpoint appears.
29517 If not known, this field is not present.
29518
29519 @item filename
29520 The name of the source file which contains this function, if known.
29521 If not known, this field is not present.
29522
29523 @item fullname
29524 The full file name of the source file which contains this function, if
29525 known. If not known, this field is not present.
29526
29527 @item line
29528 The line number at which this breakpoint appears, if known.
29529 If not known, this field is not present.
29530
29531 @item at
29532 If the source file is not known, this field may be provided. If
29533 provided, this holds the address of the breakpoint, possibly followed
29534 by a symbol name.
29535
29536 @item pending
29537 If this breakpoint is pending, this field is present and holds the
29538 text used to set the breakpoint, as entered by the user.
29539
29540 @item evaluated-by
29541 Where this breakpoint's condition is evaluated, either @samp{host} or
29542 @samp{target}.
29543
29544 @item thread
29545 If this is a thread-specific breakpoint, then this identifies the
29546 thread in which the breakpoint can trigger.
29547
29548 @item task
29549 If this breakpoint is restricted to a particular Ada task, then this
29550 field will hold the task identifier.
29551
29552 @item cond
29553 If the breakpoint is conditional, this is the condition expression.
29554
29555 @item ignore
29556 The ignore count of the breakpoint.
29557
29558 @item enable
29559 The enable count of the breakpoint.
29560
29561 @item traceframe-usage
29562 FIXME.
29563
29564 @item static-tracepoint-marker-string-id
29565 For a static tracepoint, the name of the static tracepoint marker.
29566
29567 @item mask
29568 For a masked watchpoint, this is the mask.
29569
29570 @item pass
29571 A tracepoint's pass count.
29572
29573 @item original-location
29574 The location of the breakpoint as originally specified by the user.
29575 This field is optional.
29576
29577 @item times
29578 The number of times the breakpoint has been hit.
29579
29580 @item installed
29581 This field is only given for tracepoints. This is either @samp{y},
29582 meaning that the tracepoint is installed, or @samp{n}, meaning that it
29583 is not.
29584
29585 @item what
29586 Some extra data, the exact contents of which are type-dependent.
29587
29588 @item locations
29589 This field is present if the breakpoint has multiple locations. It is also
29590 exceptionally present if the breakpoint is enabled and has a single, disabled
29591 location.
29592
29593 The value is a list of locations. The format of a location is described below.
29594
29595 @end table
29596
29597 A location in a multi-location breakpoint is represented as a tuple with the
29598 following fields:
29599
29600 @table @code
29601
29602 @item number
29603 The location number as a dotted pair, like @samp{1.2}. The first digit is the
29604 number of the parent breakpoint. The second digit is the number of the
29605 location within that breakpoint.
29606
29607 @item enabled
29608 This indicates whether the location is enabled, in which case the
29609 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29610 Note that this is not the same as the field @code{enable}.
29611
29612 @item addr
29613 The address of this location as an hexidecimal number.
29614
29615 @item addr_flags
29616 Optional field containing any flags related to the address. These flags are
29617 architecture-dependent; see @ref{Architectures} for their meaning for a
29618 particular CPU.
29619
29620 @item func
29621 If known, the function in which the location appears.
29622 If not known, this field is not present.
29623
29624 @item file
29625 The name of the source file which contains this location, if known.
29626 If not known, this field is not present.
29627
29628 @item fullname
29629 The full file name of the source file which contains this location, if
29630 known. If not known, this field is not present.
29631
29632 @item line
29633 The line number at which this location appears, if known.
29634 If not known, this field is not present.
29635
29636 @item thread-groups
29637 The thread groups this location is in.
29638
29639 @end table
29640
29641 For example, here is what the output of @code{-break-insert}
29642 (@pxref{GDB/MI Breakpoint Commands}) might be:
29643
29644 @smallexample
29645 -> -break-insert main
29646 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29647 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29648 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29649 times="0"@}
29650 <- (gdb)
29651 @end smallexample
29652
29653 @node GDB/MI Frame Information
29654 @subsection @sc{gdb/mi} Frame Information
29655
29656 Response from many MI commands includes an information about stack
29657 frame. This information is a tuple that may have the following
29658 fields:
29659
29660 @table @code
29661 @item level
29662 The level of the stack frame. The innermost frame has the level of
29663 zero. This field is always present.
29664
29665 @item func
29666 The name of the function corresponding to the frame. This field may
29667 be absent if @value{GDBN} is unable to determine the function name.
29668
29669 @item addr
29670 The code address for the frame. This field is always present.
29671
29672 @item addr_flags
29673 Optional field containing any flags related to the address. These flags are
29674 architecture-dependent; see @ref{Architectures} for their meaning for a
29675 particular CPU.
29676
29677 @item file
29678 The name of the source files that correspond to the frame's code
29679 address. This field may be absent.
29680
29681 @item line
29682 The source line corresponding to the frames' code address. This field
29683 may be absent.
29684
29685 @item from
29686 The name of the binary file (either executable or shared library) the
29687 corresponds to the frame's code address. This field may be absent.
29688
29689 @end table
29690
29691 @node GDB/MI Thread Information
29692 @subsection @sc{gdb/mi} Thread Information
29693
29694 Whenever @value{GDBN} has to report an information about a thread, it
29695 uses a tuple with the following fields. The fields are always present unless
29696 stated otherwise.
29697
29698 @table @code
29699 @item id
29700 The global numeric id assigned to the thread by @value{GDBN}.
29701
29702 @item target-id
29703 The target-specific string identifying the thread.
29704
29705 @item details
29706 Additional information about the thread provided by the target.
29707 It is supposed to be human-readable and not interpreted by the
29708 frontend. This field is optional.
29709
29710 @item name
29711 The name of the thread. If the user specified a name using the
29712 @code{thread name} command, then this name is given. Otherwise, if
29713 @value{GDBN} can extract the thread name from the target, then that
29714 name is given. If @value{GDBN} cannot find the thread name, then this
29715 field is omitted.
29716
29717 @item state
29718 The execution state of the thread, either @samp{stopped} or @samp{running},
29719 depending on whether the thread is presently running.
29720
29721 @item frame
29722 The stack frame currently executing in the thread. This field is only present
29723 if the thread is stopped. Its format is documented in
29724 @ref{GDB/MI Frame Information}.
29725
29726 @item core
29727 The value of this field is an integer number of the processor core the
29728 thread was last seen on. This field is optional.
29729 @end table
29730
29731 @node GDB/MI Ada Exception Information
29732 @subsection @sc{gdb/mi} Ada Exception Information
29733
29734 Whenever a @code{*stopped} record is emitted because the program
29735 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29736 @value{GDBN} provides the name of the exception that was raised via
29737 the @code{exception-name} field. Also, for exceptions that were raised
29738 with an exception message, @value{GDBN} provides that message via
29739 the @code{exception-message} field.
29740
29741 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29742 @node GDB/MI Simple Examples
29743 @section Simple Examples of @sc{gdb/mi} Interaction
29744 @cindex @sc{gdb/mi}, simple examples
29745
29746 This subsection presents several simple examples of interaction using
29747 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29748 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29749 the output received from @sc{gdb/mi}.
29750
29751 Note the line breaks shown in the examples are here only for
29752 readability, they don't appear in the real output.
29753
29754 @subheading Setting a Breakpoint
29755
29756 Setting a breakpoint generates synchronous output which contains detailed
29757 information of the breakpoint.
29758
29759 @smallexample
29760 -> -break-insert main
29761 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29762 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29763 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29764 times="0"@}
29765 <- (gdb)
29766 @end smallexample
29767
29768 @subheading Program Execution
29769
29770 Program execution generates asynchronous records and MI gives the
29771 reason that execution stopped.
29772
29773 @smallexample
29774 -> -exec-run
29775 <- ^running
29776 <- (gdb)
29777 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
29778 frame=@{addr="0x08048564",func="main",
29779 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
29780 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29781 arch="i386:x86_64"@}
29782 <- (gdb)
29783 -> -exec-continue
29784 <- ^running
29785 <- (gdb)
29786 <- *stopped,reason="exited-normally"
29787 <- (gdb)
29788 @end smallexample
29789
29790 @subheading Quitting @value{GDBN}
29791
29792 Quitting @value{GDBN} just prints the result class @samp{^exit}.
29793
29794 @smallexample
29795 -> (gdb)
29796 <- -gdb-exit
29797 <- ^exit
29798 @end smallexample
29799
29800 Please note that @samp{^exit} is printed immediately, but it might
29801 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29802 performs necessary cleanups, including killing programs being debugged
29803 or disconnecting from debug hardware, so the frontend should wait till
29804 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29805 fails to exit in reasonable time.
29806
29807 @subheading A Bad Command
29808
29809 Here's what happens if you pass a non-existent command:
29810
29811 @smallexample
29812 -> -rubbish
29813 <- ^error,msg="Undefined MI command: rubbish"
29814 <- (gdb)
29815 @end smallexample
29816
29817
29818 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29819 @node GDB/MI Command Description Format
29820 @section @sc{gdb/mi} Command Description Format
29821
29822 The remaining sections describe blocks of commands. Each block of
29823 commands is laid out in a fashion similar to this section.
29824
29825 @subheading Motivation
29826
29827 The motivation for this collection of commands.
29828
29829 @subheading Introduction
29830
29831 A brief introduction to this collection of commands as a whole.
29832
29833 @subheading Commands
29834
29835 For each command in the block, the following is described:
29836
29837 @subsubheading Synopsis
29838
29839 @smallexample
29840 -command @var{args}@dots{}
29841 @end smallexample
29842
29843 @subsubheading Result
29844
29845 @subsubheading @value{GDBN} Command
29846
29847 The corresponding @value{GDBN} CLI command(s), if any.
29848
29849 @subsubheading Example
29850
29851 Example(s) formatted for readability. Some of the described commands have
29852 not been implemented yet and these are labeled N.A.@: (not available).
29853
29854
29855 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29856 @node GDB/MI Breakpoint Commands
29857 @section @sc{gdb/mi} Breakpoint Commands
29858
29859 @cindex breakpoint commands for @sc{gdb/mi}
29860 @cindex @sc{gdb/mi}, breakpoint commands
29861 This section documents @sc{gdb/mi} commands for manipulating
29862 breakpoints.
29863
29864 @subheading The @code{-break-after} Command
29865 @findex -break-after
29866
29867 @subsubheading Synopsis
29868
29869 @smallexample
29870 -break-after @var{number} @var{count}
29871 @end smallexample
29872
29873 The breakpoint number @var{number} is not in effect until it has been
29874 hit @var{count} times. To see how this is reflected in the output of
29875 the @samp{-break-list} command, see the description of the
29876 @samp{-break-list} command below.
29877
29878 @subsubheading @value{GDBN} Command
29879
29880 The corresponding @value{GDBN} command is @samp{ignore}.
29881
29882 @subsubheading Example
29883
29884 @smallexample
29885 (gdb)
29886 -break-insert main
29887 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29888 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29889 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29890 times="0"@}
29891 (gdb)
29892 -break-after 1 3
29893 ~
29894 ^done
29895 (gdb)
29896 -break-list
29897 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29898 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29899 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29900 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29901 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29902 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29903 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29904 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29905 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29906 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
29907 (gdb)
29908 @end smallexample
29909
29910 @ignore
29911 @subheading The @code{-break-catch} Command
29912 @findex -break-catch
29913 @end ignore
29914
29915 @subheading The @code{-break-commands} Command
29916 @findex -break-commands
29917
29918 @subsubheading Synopsis
29919
29920 @smallexample
29921 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29922 @end smallexample
29923
29924 Specifies the CLI commands that should be executed when breakpoint
29925 @var{number} is hit. The parameters @var{command1} to @var{commandN}
29926 are the commands. If no command is specified, any previously-set
29927 commands are cleared. @xref{Break Commands}. Typical use of this
29928 functionality is tracing a program, that is, printing of values of
29929 some variables whenever breakpoint is hit and then continuing.
29930
29931 @subsubheading @value{GDBN} Command
29932
29933 The corresponding @value{GDBN} command is @samp{commands}.
29934
29935 @subsubheading Example
29936
29937 @smallexample
29938 (gdb)
29939 -break-insert main
29940 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29941 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29942 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29943 times="0"@}
29944 (gdb)
29945 -break-commands 1 "print v" "continue"
29946 ^done
29947 (gdb)
29948 @end smallexample
29949
29950 @subheading The @code{-break-condition} Command
29951 @findex -break-condition
29952
29953 @subsubheading Synopsis
29954
29955 @smallexample
29956 -break-condition @var{number} @var{expr}
29957 @end smallexample
29958
29959 Breakpoint @var{number} will stop the program only if the condition in
29960 @var{expr} is true. The condition becomes part of the
29961 @samp{-break-list} output (see the description of the @samp{-break-list}
29962 command below).
29963
29964 @subsubheading @value{GDBN} Command
29965
29966 The corresponding @value{GDBN} command is @samp{condition}.
29967
29968 @subsubheading Example
29969
29970 @smallexample
29971 (gdb)
29972 -break-condition 1 1
29973 ^done
29974 (gdb)
29975 -break-list
29976 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29977 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29978 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29979 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29980 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29981 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29982 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29983 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29984 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29985 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
29986 (gdb)
29987 @end smallexample
29988
29989 @subheading The @code{-break-delete} Command
29990 @findex -break-delete
29991
29992 @subsubheading Synopsis
29993
29994 @smallexample
29995 -break-delete ( @var{breakpoint} )+
29996 @end smallexample
29997
29998 Delete the breakpoint(s) whose number(s) are specified in the argument
29999 list. This is obviously reflected in the breakpoint list.
30000
30001 @subsubheading @value{GDBN} Command
30002
30003 The corresponding @value{GDBN} command is @samp{delete}.
30004
30005 @subsubheading Example
30006
30007 @smallexample
30008 (gdb)
30009 -break-delete 1
30010 ^done
30011 (gdb)
30012 -break-list
30013 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30014 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30015 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30016 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30017 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30018 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30019 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30020 body=[]@}
30021 (gdb)
30022 @end smallexample
30023
30024 @subheading The @code{-break-disable} Command
30025 @findex -break-disable
30026
30027 @subsubheading Synopsis
30028
30029 @smallexample
30030 -break-disable ( @var{breakpoint} )+
30031 @end smallexample
30032
30033 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30034 break list is now set to @samp{n} for the named @var{breakpoint}(s).
30035
30036 @subsubheading @value{GDBN} Command
30037
30038 The corresponding @value{GDBN} command is @samp{disable}.
30039
30040 @subsubheading Example
30041
30042 @smallexample
30043 (gdb)
30044 -break-disable 2
30045 ^done
30046 (gdb)
30047 -break-list
30048 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30049 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30050 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30051 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30052 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30053 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30054 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30055 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30056 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30057 line="5",thread-groups=["i1"],times="0"@}]@}
30058 (gdb)
30059 @end smallexample
30060
30061 @subheading The @code{-break-enable} Command
30062 @findex -break-enable
30063
30064 @subsubheading Synopsis
30065
30066 @smallexample
30067 -break-enable ( @var{breakpoint} )+
30068 @end smallexample
30069
30070 Enable (previously disabled) @var{breakpoint}(s).
30071
30072 @subsubheading @value{GDBN} Command
30073
30074 The corresponding @value{GDBN} command is @samp{enable}.
30075
30076 @subsubheading Example
30077
30078 @smallexample
30079 (gdb)
30080 -break-enable 2
30081 ^done
30082 (gdb)
30083 -break-list
30084 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30085 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30086 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30087 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30088 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30089 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30090 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30091 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30092 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30093 line="5",thread-groups=["i1"],times="0"@}]@}
30094 (gdb)
30095 @end smallexample
30096
30097 @subheading The @code{-break-info} Command
30098 @findex -break-info
30099
30100 @subsubheading Synopsis
30101
30102 @smallexample
30103 -break-info @var{breakpoint}
30104 @end smallexample
30105
30106 @c REDUNDANT???
30107 Get information about a single breakpoint.
30108
30109 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30110 Information}, for details on the format of each breakpoint in the
30111 table.
30112
30113 @subsubheading @value{GDBN} Command
30114
30115 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30116
30117 @subsubheading Example
30118 N.A.
30119
30120 @subheading The @code{-break-insert} Command
30121 @findex -break-insert
30122 @anchor{-break-insert}
30123
30124 @subsubheading Synopsis
30125
30126 @smallexample
30127 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
30128 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30129 [ -p @var{thread-id} ] [ @var{location} ]
30130 @end smallexample
30131
30132 @noindent
30133 If specified, @var{location}, can be one of:
30134
30135 @table @var
30136 @item linespec location
30137 A linespec location. @xref{Linespec Locations}.
30138
30139 @item explicit location
30140 An explicit location. @sc{gdb/mi} explicit locations are
30141 analogous to the CLI's explicit locations using the option names
30142 listed below. @xref{Explicit Locations}.
30143
30144 @table @samp
30145 @item --source @var{filename}
30146 The source file name of the location. This option requires the use
30147 of either @samp{--function} or @samp{--line}.
30148
30149 @item --function @var{function}
30150 The name of a function or method.
30151
30152 @item --label @var{label}
30153 The name of a label.
30154
30155 @item --line @var{lineoffset}
30156 An absolute or relative line offset from the start of the location.
30157 @end table
30158
30159 @item address location
30160 An address location, *@var{address}. @xref{Address Locations}.
30161 @end table
30162
30163 @noindent
30164 The possible optional parameters of this command are:
30165
30166 @table @samp
30167 @item -t
30168 Insert a temporary breakpoint.
30169 @item -h
30170 Insert a hardware breakpoint.
30171 @item -f
30172 If @var{location} cannot be parsed (for example if it
30173 refers to unknown files or functions), create a pending
30174 breakpoint. Without this flag, @value{GDBN} will report
30175 an error, and won't create a breakpoint, if @var{location}
30176 cannot be parsed.
30177 @item -d
30178 Create a disabled breakpoint.
30179 @item -a
30180 Create a tracepoint. @xref{Tracepoints}. When this parameter
30181 is used together with @samp{-h}, a fast tracepoint is created.
30182 @item -c @var{condition}
30183 Make the breakpoint conditional on @var{condition}.
30184 @item -i @var{ignore-count}
30185 Initialize the @var{ignore-count}.
30186 @item -p @var{thread-id}
30187 Restrict the breakpoint to the thread with the specified global
30188 @var{thread-id}.
30189 @end table
30190
30191 @subsubheading Result
30192
30193 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30194 resulting breakpoint.
30195
30196 Note: this format is open to change.
30197 @c An out-of-band breakpoint instead of part of the result?
30198
30199 @subsubheading @value{GDBN} Command
30200
30201 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30202 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30203
30204 @subsubheading Example
30205
30206 @smallexample
30207 (gdb)
30208 -break-insert main
30209 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30210 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30211 times="0"@}
30212 (gdb)
30213 -break-insert -t foo
30214 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30215 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30216 times="0"@}
30217 (gdb)
30218 -break-list
30219 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30220 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30221 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30222 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30223 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30224 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30225 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30226 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30227 addr="0x0001072c", func="main",file="recursive2.c",
30228 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30229 times="0"@},
30230 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30231 addr="0x00010774",func="foo",file="recursive2.c",
30232 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30233 times="0"@}]@}
30234 (gdb)
30235 @c -break-insert -r foo.*
30236 @c ~int foo(int, int);
30237 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30238 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30239 @c times="0"@}
30240 @c (gdb)
30241 @end smallexample
30242
30243 @subheading The @code{-dprintf-insert} Command
30244 @findex -dprintf-insert
30245
30246 @subsubheading Synopsis
30247
30248 @smallexample
30249 -dprintf-insert [ -t ] [ -f ] [ -d ]
30250 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30251 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30252 [ @var{argument} ]
30253 @end smallexample
30254
30255 @noindent
30256 If supplied, @var{location} may be specified the same way as for
30257 the @code{-break-insert} command. @xref{-break-insert}.
30258
30259 The possible optional parameters of this command are:
30260
30261 @table @samp
30262 @item -t
30263 Insert a temporary breakpoint.
30264 @item -f
30265 If @var{location} cannot be parsed (for example, if it
30266 refers to unknown files or functions), create a pending
30267 breakpoint. Without this flag, @value{GDBN} will report
30268 an error, and won't create a breakpoint, if @var{location}
30269 cannot be parsed.
30270 @item -d
30271 Create a disabled breakpoint.
30272 @item -c @var{condition}
30273 Make the breakpoint conditional on @var{condition}.
30274 @item -i @var{ignore-count}
30275 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30276 to @var{ignore-count}.
30277 @item -p @var{thread-id}
30278 Restrict the breakpoint to the thread with the specified global
30279 @var{thread-id}.
30280 @end table
30281
30282 @subsubheading Result
30283
30284 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30285 resulting breakpoint.
30286
30287 @c An out-of-band breakpoint instead of part of the result?
30288
30289 @subsubheading @value{GDBN} Command
30290
30291 The corresponding @value{GDBN} command is @samp{dprintf}.
30292
30293 @subsubheading Example
30294
30295 @smallexample
30296 (gdb)
30297 4-dprintf-insert foo "At foo entry\n"
30298 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30299 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30300 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30301 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30302 original-location="foo"@}
30303 (gdb)
30304 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30305 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30306 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30307 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30308 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30309 original-location="mi-dprintf.c:26"@}
30310 (gdb)
30311 @end smallexample
30312
30313 @subheading The @code{-break-list} Command
30314 @findex -break-list
30315
30316 @subsubheading Synopsis
30317
30318 @smallexample
30319 -break-list
30320 @end smallexample
30321
30322 Displays the list of inserted breakpoints, showing the following fields:
30323
30324 @table @samp
30325 @item Number
30326 number of the breakpoint
30327 @item Type
30328 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30329 @item Disposition
30330 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30331 or @samp{nokeep}
30332 @item Enabled
30333 is the breakpoint enabled or no: @samp{y} or @samp{n}
30334 @item Address
30335 memory location at which the breakpoint is set
30336 @item What
30337 logical location of the breakpoint, expressed by function name, file
30338 name, line number
30339 @item Thread-groups
30340 list of thread groups to which this breakpoint applies
30341 @item Times
30342 number of times the breakpoint has been hit
30343 @end table
30344
30345 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30346 @code{body} field is an empty list.
30347
30348 @subsubheading @value{GDBN} Command
30349
30350 The corresponding @value{GDBN} command is @samp{info break}.
30351
30352 @subsubheading Example
30353
30354 @smallexample
30355 (gdb)
30356 -break-list
30357 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30358 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30359 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30360 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30361 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30362 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30363 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30364 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30365 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30366 times="0"@},
30367 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30368 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30369 line="13",thread-groups=["i1"],times="0"@}]@}
30370 (gdb)
30371 @end smallexample
30372
30373 Here's an example of the result when there are no breakpoints:
30374
30375 @smallexample
30376 (gdb)
30377 -break-list
30378 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30379 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30380 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30381 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30382 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30383 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30384 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30385 body=[]@}
30386 (gdb)
30387 @end smallexample
30388
30389 @subheading The @code{-break-passcount} Command
30390 @findex -break-passcount
30391
30392 @subsubheading Synopsis
30393
30394 @smallexample
30395 -break-passcount @var{tracepoint-number} @var{passcount}
30396 @end smallexample
30397
30398 Set the passcount for tracepoint @var{tracepoint-number} to
30399 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30400 is not a tracepoint, error is emitted. This corresponds to CLI
30401 command @samp{passcount}.
30402
30403 @subheading The @code{-break-watch} Command
30404 @findex -break-watch
30405
30406 @subsubheading Synopsis
30407
30408 @smallexample
30409 -break-watch [ -a | -r ]
30410 @end smallexample
30411
30412 Create a watchpoint. With the @samp{-a} option it will create an
30413 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30414 read from or on a write to the memory location. With the @samp{-r}
30415 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30416 trigger only when the memory location is accessed for reading. Without
30417 either of the options, the watchpoint created is a regular watchpoint,
30418 i.e., it will trigger when the memory location is accessed for writing.
30419 @xref{Set Watchpoints, , Setting Watchpoints}.
30420
30421 Note that @samp{-break-list} will report a single list of watchpoints and
30422 breakpoints inserted.
30423
30424 @subsubheading @value{GDBN} Command
30425
30426 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30427 @samp{rwatch}.
30428
30429 @subsubheading Example
30430
30431 Setting a watchpoint on a variable in the @code{main} function:
30432
30433 @smallexample
30434 (gdb)
30435 -break-watch x
30436 ^done,wpt=@{number="2",exp="x"@}
30437 (gdb)
30438 -exec-continue
30439 ^running
30440 (gdb)
30441 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30442 value=@{old="-268439212",new="55"@},
30443 frame=@{func="main",args=[],file="recursive2.c",
30444 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30445 (gdb)
30446 @end smallexample
30447
30448 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30449 the program execution twice: first for the variable changing value, then
30450 for the watchpoint going out of scope.
30451
30452 @smallexample
30453 (gdb)
30454 -break-watch C
30455 ^done,wpt=@{number="5",exp="C"@}
30456 (gdb)
30457 -exec-continue
30458 ^running
30459 (gdb)
30460 *stopped,reason="watchpoint-trigger",
30461 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30462 frame=@{func="callee4",args=[],
30463 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30464 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30465 arch="i386:x86_64"@}
30466 (gdb)
30467 -exec-continue
30468 ^running
30469 (gdb)
30470 *stopped,reason="watchpoint-scope",wpnum="5",
30471 frame=@{func="callee3",args=[@{name="strarg",
30472 value="0x11940 \"A string argument.\""@}],
30473 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30474 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30475 arch="i386:x86_64"@}
30476 (gdb)
30477 @end smallexample
30478
30479 Listing breakpoints and watchpoints, at different points in the program
30480 execution. Note that once the watchpoint goes out of scope, it is
30481 deleted.
30482
30483 @smallexample
30484 (gdb)
30485 -break-watch C
30486 ^done,wpt=@{number="2",exp="C"@}
30487 (gdb)
30488 -break-list
30489 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30490 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30491 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30492 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30493 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30494 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30495 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30496 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30497 addr="0x00010734",func="callee4",
30498 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30499 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30500 times="1"@},
30501 bkpt=@{number="2",type="watchpoint",disp="keep",
30502 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30503 (gdb)
30504 -exec-continue
30505 ^running
30506 (gdb)
30507 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30508 value=@{old="-276895068",new="3"@},
30509 frame=@{func="callee4",args=[],
30510 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30511 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30512 arch="i386:x86_64"@}
30513 (gdb)
30514 -break-list
30515 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30516 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30517 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30518 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30519 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30520 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30521 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30522 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30523 addr="0x00010734",func="callee4",
30524 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30525 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30526 times="1"@},
30527 bkpt=@{number="2",type="watchpoint",disp="keep",
30528 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30529 (gdb)
30530 -exec-continue
30531 ^running
30532 ^done,reason="watchpoint-scope",wpnum="2",
30533 frame=@{func="callee3",args=[@{name="strarg",
30534 value="0x11940 \"A string argument.\""@}],
30535 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30536 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30537 arch="i386:x86_64"@}
30538 (gdb)
30539 -break-list
30540 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30541 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30542 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30543 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30544 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30545 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30546 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30547 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30548 addr="0x00010734",func="callee4",
30549 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30550 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30551 thread-groups=["i1"],times="1"@}]@}
30552 (gdb)
30553 @end smallexample
30554
30555
30556 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30557 @node GDB/MI Catchpoint Commands
30558 @section @sc{gdb/mi} Catchpoint Commands
30559
30560 This section documents @sc{gdb/mi} commands for manipulating
30561 catchpoints.
30562
30563 @menu
30564 * Shared Library GDB/MI Catchpoint Commands::
30565 * Ada Exception GDB/MI Catchpoint Commands::
30566 * C++ Exception GDB/MI Catchpoint Commands::
30567 @end menu
30568
30569 @node Shared Library GDB/MI Catchpoint Commands
30570 @subsection Shared Library @sc{gdb/mi} Catchpoints
30571
30572 @subheading The @code{-catch-load} Command
30573 @findex -catch-load
30574
30575 @subsubheading Synopsis
30576
30577 @smallexample
30578 -catch-load [ -t ] [ -d ] @var{regexp}
30579 @end smallexample
30580
30581 Add a catchpoint for library load events. If the @samp{-t} option is used,
30582 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30583 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30584 in a disabled state. The @samp{regexp} argument is a regular
30585 expression used to match the name of the loaded library.
30586
30587
30588 @subsubheading @value{GDBN} Command
30589
30590 The corresponding @value{GDBN} command is @samp{catch load}.
30591
30592 @subsubheading Example
30593
30594 @smallexample
30595 -catch-load -t foo.so
30596 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30597 what="load of library matching foo.so",catch-type="load",times="0"@}
30598 (gdb)
30599 @end smallexample
30600
30601
30602 @subheading The @code{-catch-unload} Command
30603 @findex -catch-unload
30604
30605 @subsubheading Synopsis
30606
30607 @smallexample
30608 -catch-unload [ -t ] [ -d ] @var{regexp}
30609 @end smallexample
30610
30611 Add a catchpoint for library unload events. If the @samp{-t} option is
30612 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30613 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30614 created in a disabled state. The @samp{regexp} argument is a regular
30615 expression used to match the name of the unloaded library.
30616
30617 @subsubheading @value{GDBN} Command
30618
30619 The corresponding @value{GDBN} command is @samp{catch unload}.
30620
30621 @subsubheading Example
30622
30623 @smallexample
30624 -catch-unload -d bar.so
30625 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30626 what="load of library matching bar.so",catch-type="unload",times="0"@}
30627 (gdb)
30628 @end smallexample
30629
30630 @node Ada Exception GDB/MI Catchpoint Commands
30631 @subsection Ada Exception @sc{gdb/mi} Catchpoints
30632
30633 The following @sc{gdb/mi} commands can be used to create catchpoints
30634 that stop the execution when Ada exceptions are being raised.
30635
30636 @subheading The @code{-catch-assert} Command
30637 @findex -catch-assert
30638
30639 @subsubheading Synopsis
30640
30641 @smallexample
30642 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30643 @end smallexample
30644
30645 Add a catchpoint for failed Ada assertions.
30646
30647 The possible optional parameters for this command are:
30648
30649 @table @samp
30650 @item -c @var{condition}
30651 Make the catchpoint conditional on @var{condition}.
30652 @item -d
30653 Create a disabled catchpoint.
30654 @item -t
30655 Create a temporary catchpoint.
30656 @end table
30657
30658 @subsubheading @value{GDBN} Command
30659
30660 The corresponding @value{GDBN} command is @samp{catch assert}.
30661
30662 @subsubheading Example
30663
30664 @smallexample
30665 -catch-assert
30666 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30667 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30668 thread-groups=["i1"],times="0",
30669 original-location="__gnat_debug_raise_assert_failure"@}
30670 (gdb)
30671 @end smallexample
30672
30673 @subheading The @code{-catch-exception} Command
30674 @findex -catch-exception
30675
30676 @subsubheading Synopsis
30677
30678 @smallexample
30679 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30680 [ -t ] [ -u ]
30681 @end smallexample
30682
30683 Add a catchpoint stopping when Ada exceptions are raised.
30684 By default, the command stops the program when any Ada exception
30685 gets raised. But it is also possible, by using some of the
30686 optional parameters described below, to create more selective
30687 catchpoints.
30688
30689 The possible optional parameters for this command are:
30690
30691 @table @samp
30692 @item -c @var{condition}
30693 Make the catchpoint conditional on @var{condition}.
30694 @item -d
30695 Create a disabled catchpoint.
30696 @item -e @var{exception-name}
30697 Only stop when @var{exception-name} is raised. This option cannot
30698 be used combined with @samp{-u}.
30699 @item -t
30700 Create a temporary catchpoint.
30701 @item -u
30702 Stop only when an unhandled exception gets raised. This option
30703 cannot be used combined with @samp{-e}.
30704 @end table
30705
30706 @subsubheading @value{GDBN} Command
30707
30708 The corresponding @value{GDBN} commands are @samp{catch exception}
30709 and @samp{catch exception unhandled}.
30710
30711 @subsubheading Example
30712
30713 @smallexample
30714 -catch-exception -e Program_Error
30715 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30716 enabled="y",addr="0x0000000000404874",
30717 what="`Program_Error' Ada exception", thread-groups=["i1"],
30718 times="0",original-location="__gnat_debug_raise_exception"@}
30719 (gdb)
30720 @end smallexample
30721
30722 @subheading The @code{-catch-handlers} Command
30723 @findex -catch-handlers
30724
30725 @subsubheading Synopsis
30726
30727 @smallexample
30728 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30729 [ -t ]
30730 @end smallexample
30731
30732 Add a catchpoint stopping when Ada exceptions are handled.
30733 By default, the command stops the program when any Ada exception
30734 gets handled. But it is also possible, by using some of the
30735 optional parameters described below, to create more selective
30736 catchpoints.
30737
30738 The possible optional parameters for this command are:
30739
30740 @table @samp
30741 @item -c @var{condition}
30742 Make the catchpoint conditional on @var{condition}.
30743 @item -d
30744 Create a disabled catchpoint.
30745 @item -e @var{exception-name}
30746 Only stop when @var{exception-name} is handled.
30747 @item -t
30748 Create a temporary catchpoint.
30749 @end table
30750
30751 @subsubheading @value{GDBN} Command
30752
30753 The corresponding @value{GDBN} command is @samp{catch handlers}.
30754
30755 @subsubheading Example
30756
30757 @smallexample
30758 -catch-handlers -e Constraint_Error
30759 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30760 enabled="y",addr="0x0000000000402f68",
30761 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30762 times="0",original-location="__gnat_begin_handler"@}
30763 (gdb)
30764 @end smallexample
30765
30766 @node C++ Exception GDB/MI Catchpoint Commands
30767 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30768
30769 The following @sc{gdb/mi} commands can be used to create catchpoints
30770 that stop the execution when C@t{++} exceptions are being throw, rethrown,
30771 or caught.
30772
30773 @subheading The @code{-catch-throw} Command
30774 @findex -catch-throw
30775
30776 @subsubheading Synopsis
30777
30778 @smallexample
30779 -catch-throw [ -t ] [ -r @var{regexp}]
30780 @end smallexample
30781
30782 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30783 given, then only exceptions whose type matches the regular expression
30784 will be caught.
30785
30786 If @samp{-t} is given, then the catchpoint is enabled only for one
30787 stop, the catchpoint is automatically deleted after stopping once for
30788 the event.
30789
30790 @subsubheading @value{GDBN} Command
30791
30792 The corresponding @value{GDBN} commands are @samp{catch throw}
30793 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30794
30795 @subsubheading Example
30796
30797 @smallexample
30798 -catch-throw -r exception_type
30799 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30800 what="exception throw",catch-type="throw",
30801 thread-groups=["i1"],
30802 regexp="exception_type",times="0"@}
30803 (gdb)
30804 -exec-run
30805 ^running
30806 (gdb)
30807 ~"\n"
30808 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30809 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30810 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30811 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30812 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30813 thread-id="1",stopped-threads="all",core="6"
30814 (gdb)
30815 @end smallexample
30816
30817 @subheading The @code{-catch-rethrow} Command
30818 @findex -catch-rethrow
30819
30820 @subsubheading Synopsis
30821
30822 @smallexample
30823 -catch-rethrow [ -t ] [ -r @var{regexp}]
30824 @end smallexample
30825
30826 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30827 then only exceptions whose type matches the regular expression will be
30828 caught.
30829
30830 If @samp{-t} is given, then the catchpoint is enabled only for one
30831 stop, the catchpoint is automatically deleted after the first event is
30832 caught.
30833
30834 @subsubheading @value{GDBN} Command
30835
30836 The corresponding @value{GDBN} commands are @samp{catch rethrow}
30837 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30838
30839 @subsubheading Example
30840
30841 @smallexample
30842 -catch-rethrow -r exception_type
30843 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30844 what="exception rethrow",catch-type="rethrow",
30845 thread-groups=["i1"],
30846 regexp="exception_type",times="0"@}
30847 (gdb)
30848 -exec-run
30849 ^running
30850 (gdb)
30851 ~"\n"
30852 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30853 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30854 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30855 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30856 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30857 thread-id="1",stopped-threads="all",core="6"
30858 (gdb)
30859 @end smallexample
30860
30861 @subheading The @code{-catch-catch} Command
30862 @findex -catch-catch
30863
30864 @subsubheading Synopsis
30865
30866 @smallexample
30867 -catch-catch [ -t ] [ -r @var{regexp}]
30868 @end smallexample
30869
30870 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30871 is given, then only exceptions whose type matches the regular
30872 expression will be caught.
30873
30874 If @samp{-t} is given, then the catchpoint is enabled only for one
30875 stop, the catchpoint is automatically deleted after the first event is
30876 caught.
30877
30878 @subsubheading @value{GDBN} Command
30879
30880 The corresponding @value{GDBN} commands are @samp{catch catch}
30881 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30882
30883 @subsubheading Example
30884
30885 @smallexample
30886 -catch-catch -r exception_type
30887 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30888 what="exception catch",catch-type="catch",
30889 thread-groups=["i1"],
30890 regexp="exception_type",times="0"@}
30891 (gdb)
30892 -exec-run
30893 ^running
30894 (gdb)
30895 ~"\n"
30896 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30897 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30898 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30899 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30900 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30901 thread-id="1",stopped-threads="all",core="6"
30902 (gdb)
30903 @end smallexample
30904
30905 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30906 @node GDB/MI Program Context
30907 @section @sc{gdb/mi} Program Context
30908
30909 @subheading The @code{-exec-arguments} Command
30910 @findex -exec-arguments
30911
30912
30913 @subsubheading Synopsis
30914
30915 @smallexample
30916 -exec-arguments @var{args}
30917 @end smallexample
30918
30919 Set the inferior program arguments, to be used in the next
30920 @samp{-exec-run}.
30921
30922 @subsubheading @value{GDBN} Command
30923
30924 The corresponding @value{GDBN} command is @samp{set args}.
30925
30926 @subsubheading Example
30927
30928 @smallexample
30929 (gdb)
30930 -exec-arguments -v word
30931 ^done
30932 (gdb)
30933 @end smallexample
30934
30935
30936 @ignore
30937 @subheading The @code{-exec-show-arguments} Command
30938 @findex -exec-show-arguments
30939
30940 @subsubheading Synopsis
30941
30942 @smallexample
30943 -exec-show-arguments
30944 @end smallexample
30945
30946 Print the arguments of the program.
30947
30948 @subsubheading @value{GDBN} Command
30949
30950 The corresponding @value{GDBN} command is @samp{show args}.
30951
30952 @subsubheading Example
30953 N.A.
30954 @end ignore
30955
30956
30957 @subheading The @code{-environment-cd} Command
30958 @findex -environment-cd
30959
30960 @subsubheading Synopsis
30961
30962 @smallexample
30963 -environment-cd @var{pathdir}
30964 @end smallexample
30965
30966 Set @value{GDBN}'s working directory.
30967
30968 @subsubheading @value{GDBN} Command
30969
30970 The corresponding @value{GDBN} command is @samp{cd}.
30971
30972 @subsubheading Example
30973
30974 @smallexample
30975 (gdb)
30976 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30977 ^done
30978 (gdb)
30979 @end smallexample
30980
30981
30982 @subheading The @code{-environment-directory} Command
30983 @findex -environment-directory
30984
30985 @subsubheading Synopsis
30986
30987 @smallexample
30988 -environment-directory [ -r ] [ @var{pathdir} ]+
30989 @end smallexample
30990
30991 Add directories @var{pathdir} to beginning of search path for source files.
30992 If the @samp{-r} option is used, the search path is reset to the default
30993 search path. If directories @var{pathdir} are supplied in addition to the
30994 @samp{-r} option, the search path is first reset and then addition
30995 occurs as normal.
30996 Multiple directories may be specified, separated by blanks. Specifying
30997 multiple directories in a single command
30998 results in the directories added to the beginning of the
30999 search path in the same order they were presented in the command.
31000 If blanks are needed as
31001 part of a directory name, double-quotes should be used around
31002 the name. In the command output, the path will show up separated
31003 by the system directory-separator character. The directory-separator
31004 character must not be used
31005 in any directory name.
31006 If no directories are specified, the current search path is displayed.
31007
31008 @subsubheading @value{GDBN} Command
31009
31010 The corresponding @value{GDBN} command is @samp{dir}.
31011
31012 @subsubheading Example
31013
31014 @smallexample
31015 (gdb)
31016 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31017 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31018 (gdb)
31019 -environment-directory ""
31020 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31021 (gdb)
31022 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
31023 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31024 (gdb)
31025 -environment-directory -r
31026 ^done,source-path="$cdir:$cwd"
31027 (gdb)
31028 @end smallexample
31029
31030
31031 @subheading The @code{-environment-path} Command
31032 @findex -environment-path
31033
31034 @subsubheading Synopsis
31035
31036 @smallexample
31037 -environment-path [ -r ] [ @var{pathdir} ]+
31038 @end smallexample
31039
31040 Add directories @var{pathdir} to beginning of search path for object files.
31041 If the @samp{-r} option is used, the search path is reset to the original
31042 search path that existed at gdb start-up. If directories @var{pathdir} are
31043 supplied in addition to the
31044 @samp{-r} option, the search path is first reset and then addition
31045 occurs as normal.
31046 Multiple directories may be specified, separated by blanks. Specifying
31047 multiple directories in a single command
31048 results in the directories added to the beginning of the
31049 search path in the same order they were presented in the command.
31050 If blanks are needed as
31051 part of a directory name, double-quotes should be used around
31052 the name. In the command output, the path will show up separated
31053 by the system directory-separator character. The directory-separator
31054 character must not be used
31055 in any directory name.
31056 If no directories are specified, the current path is displayed.
31057
31058
31059 @subsubheading @value{GDBN} Command
31060
31061 The corresponding @value{GDBN} command is @samp{path}.
31062
31063 @subsubheading Example
31064
31065 @smallexample
31066 (gdb)
31067 -environment-path
31068 ^done,path="/usr/bin"
31069 (gdb)
31070 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31071 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31072 (gdb)
31073 -environment-path -r /usr/local/bin
31074 ^done,path="/usr/local/bin:/usr/bin"
31075 (gdb)
31076 @end smallexample
31077
31078
31079 @subheading The @code{-environment-pwd} Command
31080 @findex -environment-pwd
31081
31082 @subsubheading Synopsis
31083
31084 @smallexample
31085 -environment-pwd
31086 @end smallexample
31087
31088 Show the current working directory.
31089
31090 @subsubheading @value{GDBN} Command
31091
31092 The corresponding @value{GDBN} command is @samp{pwd}.
31093
31094 @subsubheading Example
31095
31096 @smallexample
31097 (gdb)
31098 -environment-pwd
31099 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31100 (gdb)
31101 @end smallexample
31102
31103 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31104 @node GDB/MI Thread Commands
31105 @section @sc{gdb/mi} Thread Commands
31106
31107
31108 @subheading The @code{-thread-info} Command
31109 @findex -thread-info
31110
31111 @subsubheading Synopsis
31112
31113 @smallexample
31114 -thread-info [ @var{thread-id} ]
31115 @end smallexample
31116
31117 Reports information about either a specific thread, if the
31118 @var{thread-id} parameter is present, or about all threads.
31119 @var{thread-id} is the thread's global thread ID. When printing
31120 information about all threads, also reports the global ID of the
31121 current thread.
31122
31123 @subsubheading @value{GDBN} Command
31124
31125 The @samp{info thread} command prints the same information
31126 about all threads.
31127
31128 @subsubheading Result
31129
31130 The result contains the following attributes:
31131
31132 @table @samp
31133 @item threads
31134 A list of threads. The format of the elements of the list is described in
31135 @ref{GDB/MI Thread Information}.
31136
31137 @item current-thread-id
31138 The global id of the currently selected thread. This field is omitted if there
31139 is no selected thread (for example, when the selected inferior is not running,
31140 and therefore has no threads) or if a @var{thread-id} argument was passed to
31141 the command.
31142
31143 @end table
31144
31145 @subsubheading Example
31146
31147 @smallexample
31148 -thread-info
31149 ^done,threads=[
31150 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31151 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31152 args=[]@},state="running"@},
31153 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31154 frame=@{level="0",addr="0x0804891f",func="foo",
31155 args=[@{name="i",value="10"@}],
31156 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31157 state="running"@}],
31158 current-thread-id="1"
31159 (gdb)
31160 @end smallexample
31161
31162 @subheading The @code{-thread-list-ids} Command
31163 @findex -thread-list-ids
31164
31165 @subsubheading Synopsis
31166
31167 @smallexample
31168 -thread-list-ids
31169 @end smallexample
31170
31171 Produces a list of the currently known global @value{GDBN} thread ids.
31172 At the end of the list it also prints the total number of such
31173 threads.
31174
31175 This command is retained for historical reasons, the
31176 @code{-thread-info} command should be used instead.
31177
31178 @subsubheading @value{GDBN} Command
31179
31180 Part of @samp{info threads} supplies the same information.
31181
31182 @subsubheading Example
31183
31184 @smallexample
31185 (gdb)
31186 -thread-list-ids
31187 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31188 current-thread-id="1",number-of-threads="3"
31189 (gdb)
31190 @end smallexample
31191
31192
31193 @subheading The @code{-thread-select} Command
31194 @findex -thread-select
31195
31196 @subsubheading Synopsis
31197
31198 @smallexample
31199 -thread-select @var{thread-id}
31200 @end smallexample
31201
31202 Make thread with global thread number @var{thread-id} the current
31203 thread. It prints the number of the new current thread, and the
31204 topmost frame for that thread.
31205
31206 This command is deprecated in favor of explicitly using the
31207 @samp{--thread} option to each command.
31208
31209 @subsubheading @value{GDBN} Command
31210
31211 The corresponding @value{GDBN} command is @samp{thread}.
31212
31213 @subsubheading Example
31214
31215 @smallexample
31216 (gdb)
31217 -exec-next
31218 ^running
31219 (gdb)
31220 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31221 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31222 (gdb)
31223 -thread-list-ids
31224 ^done,
31225 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31226 number-of-threads="3"
31227 (gdb)
31228 -thread-select 3
31229 ^done,new-thread-id="3",
31230 frame=@{level="0",func="vprintf",
31231 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31232 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31233 (gdb)
31234 @end smallexample
31235
31236 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31237 @node GDB/MI Ada Tasking Commands
31238 @section @sc{gdb/mi} Ada Tasking Commands
31239
31240 @subheading The @code{-ada-task-info} Command
31241 @findex -ada-task-info
31242
31243 @subsubheading Synopsis
31244
31245 @smallexample
31246 -ada-task-info [ @var{task-id} ]
31247 @end smallexample
31248
31249 Reports information about either a specific Ada task, if the
31250 @var{task-id} parameter is present, or about all Ada tasks.
31251
31252 @subsubheading @value{GDBN} Command
31253
31254 The @samp{info tasks} command prints the same information
31255 about all Ada tasks (@pxref{Ada Tasks}).
31256
31257 @subsubheading Result
31258
31259 The result is a table of Ada tasks. The following columns are
31260 defined for each Ada task:
31261
31262 @table @samp
31263 @item current
31264 This field exists only for the current thread. It has the value @samp{*}.
31265
31266 @item id
31267 The identifier that @value{GDBN} uses to refer to the Ada task.
31268
31269 @item task-id
31270 The identifier that the target uses to refer to the Ada task.
31271
31272 @item thread-id
31273 The global thread identifier of the thread corresponding to the Ada
31274 task.
31275
31276 This field should always exist, as Ada tasks are always implemented
31277 on top of a thread. But if @value{GDBN} cannot find this corresponding
31278 thread for any reason, the field is omitted.
31279
31280 @item parent-id
31281 This field exists only when the task was created by another task.
31282 In this case, it provides the ID of the parent task.
31283
31284 @item priority
31285 The base priority of the task.
31286
31287 @item state
31288 The current state of the task. For a detailed description of the
31289 possible states, see @ref{Ada Tasks}.
31290
31291 @item name
31292 The name of the task.
31293
31294 @end table
31295
31296 @subsubheading Example
31297
31298 @smallexample
31299 -ada-task-info
31300 ^done,tasks=@{nr_rows="3",nr_cols="8",
31301 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31302 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31303 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31304 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31305 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31306 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31307 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31308 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31309 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31310 state="Child Termination Wait",name="main_task"@}]@}
31311 (gdb)
31312 @end smallexample
31313
31314 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31315 @node GDB/MI Program Execution
31316 @section @sc{gdb/mi} Program Execution
31317
31318 These are the asynchronous commands which generate the out-of-band
31319 record @samp{*stopped}. Currently @value{GDBN} only really executes
31320 asynchronously with remote targets and this interaction is mimicked in
31321 other cases.
31322
31323 @subheading The @code{-exec-continue} Command
31324 @findex -exec-continue
31325
31326 @subsubheading Synopsis
31327
31328 @smallexample
31329 -exec-continue [--reverse] [--all|--thread-group N]
31330 @end smallexample
31331
31332 Resumes the execution of the inferior program, which will continue
31333 to execute until it reaches a debugger stop event. If the
31334 @samp{--reverse} option is specified, execution resumes in reverse until
31335 it reaches a stop event. Stop events may include
31336 @itemize @bullet
31337 @item
31338 breakpoints or watchpoints
31339 @item
31340 signals or exceptions
31341 @item
31342 the end of the process (or its beginning under @samp{--reverse})
31343 @item
31344 the end or beginning of a replay log if one is being used.
31345 @end itemize
31346 In all-stop mode (@pxref{All-Stop
31347 Mode}), may resume only one thread, or all threads, depending on the
31348 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31349 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31350 ignored in all-stop mode. If the @samp{--thread-group} options is
31351 specified, then all threads in that thread group are resumed.
31352
31353 @subsubheading @value{GDBN} Command
31354
31355 The corresponding @value{GDBN} corresponding is @samp{continue}.
31356
31357 @subsubheading Example
31358
31359 @smallexample
31360 -exec-continue
31361 ^running
31362 (gdb)
31363 @@Hello world
31364 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31365 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31366 line="13",arch="i386:x86_64"@}
31367 (gdb)
31368 @end smallexample
31369
31370
31371 @subheading The @code{-exec-finish} Command
31372 @findex -exec-finish
31373
31374 @subsubheading Synopsis
31375
31376 @smallexample
31377 -exec-finish [--reverse]
31378 @end smallexample
31379
31380 Resumes the execution of the inferior program until the current
31381 function is exited. Displays the results returned by the function.
31382 If the @samp{--reverse} option is specified, resumes the reverse
31383 execution of the inferior program until the point where current
31384 function was called.
31385
31386 @subsubheading @value{GDBN} Command
31387
31388 The corresponding @value{GDBN} command is @samp{finish}.
31389
31390 @subsubheading Example
31391
31392 Function returning @code{void}.
31393
31394 @smallexample
31395 -exec-finish
31396 ^running
31397 (gdb)
31398 @@hello from foo
31399 *stopped,reason="function-finished",frame=@{func="main",args=[],
31400 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31401 (gdb)
31402 @end smallexample
31403
31404 Function returning other than @code{void}. The name of the internal
31405 @value{GDBN} variable storing the result is printed, together with the
31406 value itself.
31407
31408 @smallexample
31409 -exec-finish
31410 ^running
31411 (gdb)
31412 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31413 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31414 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31415 arch="i386:x86_64"@},
31416 gdb-result-var="$1",return-value="0"
31417 (gdb)
31418 @end smallexample
31419
31420
31421 @subheading The @code{-exec-interrupt} Command
31422 @findex -exec-interrupt
31423
31424 @subsubheading Synopsis
31425
31426 @smallexample
31427 -exec-interrupt [--all|--thread-group N]
31428 @end smallexample
31429
31430 Interrupts the background execution of the target. Note how the token
31431 associated with the stop message is the one for the execution command
31432 that has been interrupted. The token for the interrupt itself only
31433 appears in the @samp{^done} output. If the user is trying to
31434 interrupt a non-running program, an error message will be printed.
31435
31436 Note that when asynchronous execution is enabled, this command is
31437 asynchronous just like other execution commands. That is, first the
31438 @samp{^done} response will be printed, and the target stop will be
31439 reported after that using the @samp{*stopped} notification.
31440
31441 In non-stop mode, only the context thread is interrupted by default.
31442 All threads (in all inferiors) will be interrupted if the
31443 @samp{--all} option is specified. If the @samp{--thread-group}
31444 option is specified, all threads in that group will be interrupted.
31445
31446 @subsubheading @value{GDBN} Command
31447
31448 The corresponding @value{GDBN} command is @samp{interrupt}.
31449
31450 @subsubheading Example
31451
31452 @smallexample
31453 (gdb)
31454 111-exec-continue
31455 111^running
31456
31457 (gdb)
31458 222-exec-interrupt
31459 222^done
31460 (gdb)
31461 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
31462 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
31463 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
31464 (gdb)
31465
31466 (gdb)
31467 -exec-interrupt
31468 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
31469 (gdb)
31470 @end smallexample
31471
31472 @subheading The @code{-exec-jump} Command
31473 @findex -exec-jump
31474
31475 @subsubheading Synopsis
31476
31477 @smallexample
31478 -exec-jump @var{location}
31479 @end smallexample
31480
31481 Resumes execution of the inferior program at the location specified by
31482 parameter. @xref{Specify Location}, for a description of the
31483 different forms of @var{location}.
31484
31485 @subsubheading @value{GDBN} Command
31486
31487 The corresponding @value{GDBN} command is @samp{jump}.
31488
31489 @subsubheading Example
31490
31491 @smallexample
31492 -exec-jump foo.c:10
31493 *running,thread-id="all"
31494 ^running
31495 @end smallexample
31496
31497
31498 @subheading The @code{-exec-next} Command
31499 @findex -exec-next
31500
31501 @subsubheading Synopsis
31502
31503 @smallexample
31504 -exec-next [--reverse]
31505 @end smallexample
31506
31507 Resumes execution of the inferior program, stopping when the beginning
31508 of the next source line is reached.
31509
31510 If the @samp{--reverse} option is specified, resumes reverse execution
31511 of the inferior program, stopping at the beginning of the previous
31512 source line. If you issue this command on the first line of a
31513 function, it will take you back to the caller of that function, to the
31514 source line where the function was called.
31515
31516
31517 @subsubheading @value{GDBN} Command
31518
31519 The corresponding @value{GDBN} command is @samp{next}.
31520
31521 @subsubheading Example
31522
31523 @smallexample
31524 -exec-next
31525 ^running
31526 (gdb)
31527 *stopped,reason="end-stepping-range",line="8",file="hello.c"
31528 (gdb)
31529 @end smallexample
31530
31531
31532 @subheading The @code{-exec-next-instruction} Command
31533 @findex -exec-next-instruction
31534
31535 @subsubheading Synopsis
31536
31537 @smallexample
31538 -exec-next-instruction [--reverse]
31539 @end smallexample
31540
31541 Executes one machine instruction. If the instruction is a function
31542 call, continues until the function returns. If the program stops at an
31543 instruction in the middle of a source line, the address will be
31544 printed as well.
31545
31546 If the @samp{--reverse} option is specified, resumes reverse execution
31547 of the inferior program, stopping at the previous instruction. If the
31548 previously executed instruction was a return from another function,
31549 it will continue to execute in reverse until the call to that function
31550 (from the current stack frame) is reached.
31551
31552 @subsubheading @value{GDBN} Command
31553
31554 The corresponding @value{GDBN} command is @samp{nexti}.
31555
31556 @subsubheading Example
31557
31558 @smallexample
31559 (gdb)
31560 -exec-next-instruction
31561 ^running
31562
31563 (gdb)
31564 *stopped,reason="end-stepping-range",
31565 addr="0x000100d4",line="5",file="hello.c"
31566 (gdb)
31567 @end smallexample
31568
31569
31570 @subheading The @code{-exec-return} Command
31571 @findex -exec-return
31572
31573 @subsubheading Synopsis
31574
31575 @smallexample
31576 -exec-return
31577 @end smallexample
31578
31579 Makes current function return immediately. Doesn't execute the inferior.
31580 Displays the new current frame.
31581
31582 @subsubheading @value{GDBN} Command
31583
31584 The corresponding @value{GDBN} command is @samp{return}.
31585
31586 @subsubheading Example
31587
31588 @smallexample
31589 (gdb)
31590 200-break-insert callee4
31591 200^done,bkpt=@{number="1",addr="0x00010734",
31592 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31593 (gdb)
31594 000-exec-run
31595 000^running
31596 (gdb)
31597 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31598 frame=@{func="callee4",args=[],
31599 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31600 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31601 arch="i386:x86_64"@}
31602 (gdb)
31603 205-break-delete
31604 205^done
31605 (gdb)
31606 111-exec-return
31607 111^done,frame=@{level="0",func="callee3",
31608 args=[@{name="strarg",
31609 value="0x11940 \"A string argument.\""@}],
31610 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31611 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31612 arch="i386:x86_64"@}
31613 (gdb)
31614 @end smallexample
31615
31616
31617 @subheading The @code{-exec-run} Command
31618 @findex -exec-run
31619
31620 @subsubheading Synopsis
31621
31622 @smallexample
31623 -exec-run [ --all | --thread-group N ] [ --start ]
31624 @end smallexample
31625
31626 Starts execution of the inferior from the beginning. The inferior
31627 executes until either a breakpoint is encountered or the program
31628 exits. In the latter case the output will include an exit code, if
31629 the program has exited exceptionally.
31630
31631 When neither the @samp{--all} nor the @samp{--thread-group} option
31632 is specified, the current inferior is started. If the
31633 @samp{--thread-group} option is specified, it should refer to a thread
31634 group of type @samp{process}, and that thread group will be started.
31635 If the @samp{--all} option is specified, then all inferiors will be started.
31636
31637 Using the @samp{--start} option instructs the debugger to stop
31638 the execution at the start of the inferior's main subprogram,
31639 following the same behavior as the @code{start} command
31640 (@pxref{Starting}).
31641
31642 @subsubheading @value{GDBN} Command
31643
31644 The corresponding @value{GDBN} command is @samp{run}.
31645
31646 @subsubheading Examples
31647
31648 @smallexample
31649 (gdb)
31650 -break-insert main
31651 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31652 (gdb)
31653 -exec-run
31654 ^running
31655 (gdb)
31656 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31657 frame=@{func="main",args=[],file="recursive2.c",
31658 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
31659 (gdb)
31660 @end smallexample
31661
31662 @noindent
31663 Program exited normally:
31664
31665 @smallexample
31666 (gdb)
31667 -exec-run
31668 ^running
31669 (gdb)
31670 x = 55
31671 *stopped,reason="exited-normally"
31672 (gdb)
31673 @end smallexample
31674
31675 @noindent
31676 Program exited exceptionally:
31677
31678 @smallexample
31679 (gdb)
31680 -exec-run
31681 ^running
31682 (gdb)
31683 x = 55
31684 *stopped,reason="exited",exit-code="01"
31685 (gdb)
31686 @end smallexample
31687
31688 Another way the program can terminate is if it receives a signal such as
31689 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31690
31691 @smallexample
31692 (gdb)
31693 *stopped,reason="exited-signalled",signal-name="SIGINT",
31694 signal-meaning="Interrupt"
31695 @end smallexample
31696
31697
31698 @c @subheading -exec-signal
31699
31700
31701 @subheading The @code{-exec-step} Command
31702 @findex -exec-step
31703
31704 @subsubheading Synopsis
31705
31706 @smallexample
31707 -exec-step [--reverse]
31708 @end smallexample
31709
31710 Resumes execution of the inferior program, stopping when the beginning
31711 of the next source line is reached, if the next source line is not a
31712 function call. If it is, stop at the first instruction of the called
31713 function. If the @samp{--reverse} option is specified, resumes reverse
31714 execution of the inferior program, stopping at the beginning of the
31715 previously executed source line.
31716
31717 @subsubheading @value{GDBN} Command
31718
31719 The corresponding @value{GDBN} command is @samp{step}.
31720
31721 @subsubheading Example
31722
31723 Stepping into a function:
31724
31725 @smallexample
31726 -exec-step
31727 ^running
31728 (gdb)
31729 *stopped,reason="end-stepping-range",
31730 frame=@{func="foo",args=[@{name="a",value="10"@},
31731 @{name="b",value="0"@}],file="recursive2.c",
31732 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
31733 (gdb)
31734 @end smallexample
31735
31736 Regular stepping:
31737
31738 @smallexample
31739 -exec-step
31740 ^running
31741 (gdb)
31742 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
31743 (gdb)
31744 @end smallexample
31745
31746
31747 @subheading The @code{-exec-step-instruction} Command
31748 @findex -exec-step-instruction
31749
31750 @subsubheading Synopsis
31751
31752 @smallexample
31753 -exec-step-instruction [--reverse]
31754 @end smallexample
31755
31756 Resumes the inferior which executes one machine instruction. If the
31757 @samp{--reverse} option is specified, resumes reverse execution of the
31758 inferior program, stopping at the previously executed instruction.
31759 The output, once @value{GDBN} has stopped, will vary depending on
31760 whether we have stopped in the middle of a source line or not. In the
31761 former case, the address at which the program stopped will be printed
31762 as well.
31763
31764 @subsubheading @value{GDBN} Command
31765
31766 The corresponding @value{GDBN} command is @samp{stepi}.
31767
31768 @subsubheading Example
31769
31770 @smallexample
31771 (gdb)
31772 -exec-step-instruction
31773 ^running
31774
31775 (gdb)
31776 *stopped,reason="end-stepping-range",
31777 frame=@{func="foo",args=[],file="try.c",
31778 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31779 (gdb)
31780 -exec-step-instruction
31781 ^running
31782
31783 (gdb)
31784 *stopped,reason="end-stepping-range",
31785 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
31786 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31787 (gdb)
31788 @end smallexample
31789
31790
31791 @subheading The @code{-exec-until} Command
31792 @findex -exec-until
31793
31794 @subsubheading Synopsis
31795
31796 @smallexample
31797 -exec-until [ @var{location} ]
31798 @end smallexample
31799
31800 Executes the inferior until the @var{location} specified in the
31801 argument is reached. If there is no argument, the inferior executes
31802 until a source line greater than the current one is reached. The
31803 reason for stopping in this case will be @samp{location-reached}.
31804
31805 @subsubheading @value{GDBN} Command
31806
31807 The corresponding @value{GDBN} command is @samp{until}.
31808
31809 @subsubheading Example
31810
31811 @smallexample
31812 (gdb)
31813 -exec-until recursive2.c:6
31814 ^running
31815 (gdb)
31816 x = 55
31817 *stopped,reason="location-reached",frame=@{func="main",args=[],
31818 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31819 arch="i386:x86_64"@}
31820 (gdb)
31821 @end smallexample
31822
31823 @ignore
31824 @subheading -file-clear
31825 Is this going away????
31826 @end ignore
31827
31828 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31829 @node GDB/MI Stack Manipulation
31830 @section @sc{gdb/mi} Stack Manipulation Commands
31831
31832 @subheading The @code{-enable-frame-filters} Command
31833 @findex -enable-frame-filters
31834
31835 @smallexample
31836 -enable-frame-filters
31837 @end smallexample
31838
31839 @value{GDBN} allows Python-based frame filters to affect the output of
31840 the MI commands relating to stack traces. As there is no way to
31841 implement this in a fully backward-compatible way, a front end must
31842 request that this functionality be enabled.
31843
31844 Once enabled, this feature cannot be disabled.
31845
31846 Note that if Python support has not been compiled into @value{GDBN},
31847 this command will still succeed (and do nothing).
31848
31849 @subheading The @code{-stack-info-frame} Command
31850 @findex -stack-info-frame
31851
31852 @subsubheading Synopsis
31853
31854 @smallexample
31855 -stack-info-frame
31856 @end smallexample
31857
31858 Get info on the selected frame.
31859
31860 @subsubheading @value{GDBN} Command
31861
31862 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31863 (without arguments).
31864
31865 @subsubheading Example
31866
31867 @smallexample
31868 (gdb)
31869 -stack-info-frame
31870 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31871 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31872 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31873 arch="i386:x86_64"@}
31874 (gdb)
31875 @end smallexample
31876
31877 @subheading The @code{-stack-info-depth} Command
31878 @findex -stack-info-depth
31879
31880 @subsubheading Synopsis
31881
31882 @smallexample
31883 -stack-info-depth [ @var{max-depth} ]
31884 @end smallexample
31885
31886 Return the depth of the stack. If the integer argument @var{max-depth}
31887 is specified, do not count beyond @var{max-depth} frames.
31888
31889 @subsubheading @value{GDBN} Command
31890
31891 There's no equivalent @value{GDBN} command.
31892
31893 @subsubheading Example
31894
31895 For a stack with frame levels 0 through 11:
31896
31897 @smallexample
31898 (gdb)
31899 -stack-info-depth
31900 ^done,depth="12"
31901 (gdb)
31902 -stack-info-depth 4
31903 ^done,depth="4"
31904 (gdb)
31905 -stack-info-depth 12
31906 ^done,depth="12"
31907 (gdb)
31908 -stack-info-depth 11
31909 ^done,depth="11"
31910 (gdb)
31911 -stack-info-depth 13
31912 ^done,depth="12"
31913 (gdb)
31914 @end smallexample
31915
31916 @anchor{-stack-list-arguments}
31917 @subheading The @code{-stack-list-arguments} Command
31918 @findex -stack-list-arguments
31919
31920 @subsubheading Synopsis
31921
31922 @smallexample
31923 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31924 [ @var{low-frame} @var{high-frame} ]
31925 @end smallexample
31926
31927 Display a list of the arguments for the frames between @var{low-frame}
31928 and @var{high-frame} (inclusive). If @var{low-frame} and
31929 @var{high-frame} are not provided, list the arguments for the whole
31930 call stack. If the two arguments are equal, show the single frame
31931 at the corresponding level. It is an error if @var{low-frame} is
31932 larger than the actual number of frames. On the other hand,
31933 @var{high-frame} may be larger than the actual number of frames, in
31934 which case only existing frames will be returned.
31935
31936 If @var{print-values} is 0 or @code{--no-values}, print only the names of
31937 the variables; if it is 1 or @code{--all-values}, print also their
31938 values; and if it is 2 or @code{--simple-values}, print the name,
31939 type and value for simple data types, and the name and type for arrays,
31940 structures and unions. If the option @code{--no-frame-filters} is
31941 supplied, then Python frame filters will not be executed.
31942
31943 If the @code{--skip-unavailable} option is specified, arguments that
31944 are not available are not listed. Partially available arguments
31945 are still displayed, however.
31946
31947 Use of this command to obtain arguments in a single frame is
31948 deprecated in favor of the @samp{-stack-list-variables} command.
31949
31950 @subsubheading @value{GDBN} Command
31951
31952 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31953 @samp{gdb_get_args} command which partially overlaps with the
31954 functionality of @samp{-stack-list-arguments}.
31955
31956 @subsubheading Example
31957
31958 @smallexample
31959 (gdb)
31960 -stack-list-frames
31961 ^done,
31962 stack=[
31963 frame=@{level="0",addr="0x00010734",func="callee4",
31964 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31965 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31966 arch="i386:x86_64"@},
31967 frame=@{level="1",addr="0x0001076c",func="callee3",
31968 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31969 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31970 arch="i386:x86_64"@},
31971 frame=@{level="2",addr="0x0001078c",func="callee2",
31972 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31973 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31974 arch="i386:x86_64"@},
31975 frame=@{level="3",addr="0x000107b4",func="callee1",
31976 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31977 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31978 arch="i386:x86_64"@},
31979 frame=@{level="4",addr="0x000107e0",func="main",
31980 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31981 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31982 arch="i386:x86_64"@}]
31983 (gdb)
31984 -stack-list-arguments 0
31985 ^done,
31986 stack-args=[
31987 frame=@{level="0",args=[]@},
31988 frame=@{level="1",args=[name="strarg"]@},
31989 frame=@{level="2",args=[name="intarg",name="strarg"]@},
31990 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31991 frame=@{level="4",args=[]@}]
31992 (gdb)
31993 -stack-list-arguments 1
31994 ^done,
31995 stack-args=[
31996 frame=@{level="0",args=[]@},
31997 frame=@{level="1",
31998 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31999 frame=@{level="2",args=[
32000 @{name="intarg",value="2"@},
32001 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32002 @{frame=@{level="3",args=[
32003 @{name="intarg",value="2"@},
32004 @{name="strarg",value="0x11940 \"A string argument.\""@},
32005 @{name="fltarg",value="3.5"@}]@},
32006 frame=@{level="4",args=[]@}]
32007 (gdb)
32008 -stack-list-arguments 0 2 2
32009 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32010 (gdb)
32011 -stack-list-arguments 1 2 2
32012 ^done,stack-args=[frame=@{level="2",
32013 args=[@{name="intarg",value="2"@},
32014 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32015 (gdb)
32016 @end smallexample
32017
32018 @c @subheading -stack-list-exception-handlers
32019
32020
32021 @anchor{-stack-list-frames}
32022 @subheading The @code{-stack-list-frames} Command
32023 @findex -stack-list-frames
32024
32025 @subsubheading Synopsis
32026
32027 @smallexample
32028 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32029 @end smallexample
32030
32031 List the frames currently on the stack. For each frame it displays the
32032 following info:
32033
32034 @table @samp
32035 @item @var{level}
32036 The frame number, 0 being the topmost frame, i.e., the innermost function.
32037 @item @var{addr}
32038 The @code{$pc} value for that frame.
32039 @item @var{func}
32040 Function name.
32041 @item @var{file}
32042 File name of the source file where the function lives.
32043 @item @var{fullname}
32044 The full file name of the source file where the function lives.
32045 @item @var{line}
32046 Line number corresponding to the @code{$pc}.
32047 @item @var{from}
32048 The shared library where this function is defined. This is only given
32049 if the frame's function is not known.
32050 @item @var{arch}
32051 Frame's architecture.
32052 @end table
32053
32054 If invoked without arguments, this command prints a backtrace for the
32055 whole stack. If given two integer arguments, it shows the frames whose
32056 levels are between the two arguments (inclusive). If the two arguments
32057 are equal, it shows the single frame at the corresponding level. It is
32058 an error if @var{low-frame} is larger than the actual number of
32059 frames. On the other hand, @var{high-frame} may be larger than the
32060 actual number of frames, in which case only existing frames will be
32061 returned. If the option @code{--no-frame-filters} is supplied, then
32062 Python frame filters will not be executed.
32063
32064 @subsubheading @value{GDBN} Command
32065
32066 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32067
32068 @subsubheading Example
32069
32070 Full stack backtrace:
32071
32072 @smallexample
32073 (gdb)
32074 -stack-list-frames
32075 ^done,stack=
32076 [frame=@{level="0",addr="0x0001076c",func="foo",
32077 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32078 arch="i386:x86_64"@},
32079 frame=@{level="1",addr="0x000107a4",func="foo",
32080 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32081 arch="i386:x86_64"@},
32082 frame=@{level="2",addr="0x000107a4",func="foo",
32083 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32084 arch="i386:x86_64"@},
32085 frame=@{level="3",addr="0x000107a4",func="foo",
32086 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32087 arch="i386:x86_64"@},
32088 frame=@{level="4",addr="0x000107a4",func="foo",
32089 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32090 arch="i386:x86_64"@},
32091 frame=@{level="5",addr="0x000107a4",func="foo",
32092 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32093 arch="i386:x86_64"@},
32094 frame=@{level="6",addr="0x000107a4",func="foo",
32095 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32096 arch="i386:x86_64"@},
32097 frame=@{level="7",addr="0x000107a4",func="foo",
32098 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32099 arch="i386:x86_64"@},
32100 frame=@{level="8",addr="0x000107a4",func="foo",
32101 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32102 arch="i386:x86_64"@},
32103 frame=@{level="9",addr="0x000107a4",func="foo",
32104 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32105 arch="i386:x86_64"@},
32106 frame=@{level="10",addr="0x000107a4",func="foo",
32107 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32108 arch="i386:x86_64"@},
32109 frame=@{level="11",addr="0x00010738",func="main",
32110 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32111 arch="i386:x86_64"@}]
32112 (gdb)
32113 @end smallexample
32114
32115 Show frames between @var{low_frame} and @var{high_frame}:
32116
32117 @smallexample
32118 (gdb)
32119 -stack-list-frames 3 5
32120 ^done,stack=
32121 [frame=@{level="3",addr="0x000107a4",func="foo",
32122 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32123 arch="i386:x86_64"@},
32124 frame=@{level="4",addr="0x000107a4",func="foo",
32125 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32126 arch="i386:x86_64"@},
32127 frame=@{level="5",addr="0x000107a4",func="foo",
32128 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32129 arch="i386:x86_64"@}]
32130 (gdb)
32131 @end smallexample
32132
32133 Show a single frame:
32134
32135 @smallexample
32136 (gdb)
32137 -stack-list-frames 3 3
32138 ^done,stack=
32139 [frame=@{level="3",addr="0x000107a4",func="foo",
32140 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32141 arch="i386:x86_64"@}]
32142 (gdb)
32143 @end smallexample
32144
32145
32146 @subheading The @code{-stack-list-locals} Command
32147 @findex -stack-list-locals
32148 @anchor{-stack-list-locals}
32149
32150 @subsubheading Synopsis
32151
32152 @smallexample
32153 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32154 @end smallexample
32155
32156 Display the local variable names for the selected frame. If
32157 @var{print-values} is 0 or @code{--no-values}, print only the names of
32158 the variables; if it is 1 or @code{--all-values}, print also their
32159 values; and if it is 2 or @code{--simple-values}, print the name,
32160 type and value for simple data types, and the name and type for arrays,
32161 structures and unions. In this last case, a frontend can immediately
32162 display the value of simple data types and create variable objects for
32163 other data types when the user wishes to explore their values in
32164 more detail. If the option @code{--no-frame-filters} is supplied, then
32165 Python frame filters will not be executed.
32166
32167 If the @code{--skip-unavailable} option is specified, local variables
32168 that are not available are not listed. Partially available local
32169 variables are still displayed, however.
32170
32171 This command is deprecated in favor of the
32172 @samp{-stack-list-variables} command.
32173
32174 @subsubheading @value{GDBN} Command
32175
32176 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32177
32178 @subsubheading Example
32179
32180 @smallexample
32181 (gdb)
32182 -stack-list-locals 0
32183 ^done,locals=[name="A",name="B",name="C"]
32184 (gdb)
32185 -stack-list-locals --all-values
32186 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32187 @{name="C",value="@{1, 2, 3@}"@}]
32188 -stack-list-locals --simple-values
32189 ^done,locals=[@{name="A",type="int",value="1"@},
32190 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32191 (gdb)
32192 @end smallexample
32193
32194 @anchor{-stack-list-variables}
32195 @subheading The @code{-stack-list-variables} Command
32196 @findex -stack-list-variables
32197
32198 @subsubheading Synopsis
32199
32200 @smallexample
32201 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32202 @end smallexample
32203
32204 Display the names of local variables and function arguments for the selected frame. If
32205 @var{print-values} is 0 or @code{--no-values}, print only the names of
32206 the variables; if it is 1 or @code{--all-values}, print also their
32207 values; and if it is 2 or @code{--simple-values}, print the name,
32208 type and value for simple data types, and the name and type for arrays,
32209 structures and unions. If the option @code{--no-frame-filters} is
32210 supplied, then Python frame filters will not be executed.
32211
32212 If the @code{--skip-unavailable} option is specified, local variables
32213 and arguments that are not available are not listed. Partially
32214 available arguments and local variables are still displayed, however.
32215
32216 @subsubheading Example
32217
32218 @smallexample
32219 (gdb)
32220 -stack-list-variables --thread 1 --frame 0 --all-values
32221 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32222 (gdb)
32223 @end smallexample
32224
32225
32226 @subheading The @code{-stack-select-frame} Command
32227 @findex -stack-select-frame
32228
32229 @subsubheading Synopsis
32230
32231 @smallexample
32232 -stack-select-frame @var{framenum}
32233 @end smallexample
32234
32235 Change the selected frame. Select a different frame @var{framenum} on
32236 the stack.
32237
32238 This command in deprecated in favor of passing the @samp{--frame}
32239 option to every command.
32240
32241 @subsubheading @value{GDBN} Command
32242
32243 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32244 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32245
32246 @subsubheading Example
32247
32248 @smallexample
32249 (gdb)
32250 -stack-select-frame 2
32251 ^done
32252 (gdb)
32253 @end smallexample
32254
32255 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32256 @node GDB/MI Variable Objects
32257 @section @sc{gdb/mi} Variable Objects
32258
32259 @ignore
32260
32261 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32262
32263 For the implementation of a variable debugger window (locals, watched
32264 expressions, etc.), we are proposing the adaptation of the existing code
32265 used by @code{Insight}.
32266
32267 The two main reasons for that are:
32268
32269 @enumerate 1
32270 @item
32271 It has been proven in practice (it is already on its second generation).
32272
32273 @item
32274 It will shorten development time (needless to say how important it is
32275 now).
32276 @end enumerate
32277
32278 The original interface was designed to be used by Tcl code, so it was
32279 slightly changed so it could be used through @sc{gdb/mi}. This section
32280 describes the @sc{gdb/mi} operations that will be available and gives some
32281 hints about their use.
32282
32283 @emph{Note}: In addition to the set of operations described here, we
32284 expect the @sc{gui} implementation of a variable window to require, at
32285 least, the following operations:
32286
32287 @itemize @bullet
32288 @item @code{-gdb-show} @code{output-radix}
32289 @item @code{-stack-list-arguments}
32290 @item @code{-stack-list-locals}
32291 @item @code{-stack-select-frame}
32292 @end itemize
32293
32294 @end ignore
32295
32296 @subheading Introduction to Variable Objects
32297
32298 @cindex variable objects in @sc{gdb/mi}
32299
32300 Variable objects are "object-oriented" MI interface for examining and
32301 changing values of expressions. Unlike some other MI interfaces that
32302 work with expressions, variable objects are specifically designed for
32303 simple and efficient presentation in the frontend. A variable object
32304 is identified by string name. When a variable object is created, the
32305 frontend specifies the expression for that variable object. The
32306 expression can be a simple variable, or it can be an arbitrary complex
32307 expression, and can even involve CPU registers. After creating a
32308 variable object, the frontend can invoke other variable object
32309 operations---for example to obtain or change the value of a variable
32310 object, or to change display format.
32311
32312 Variable objects have hierarchical tree structure. Any variable object
32313 that corresponds to a composite type, such as structure in C, has
32314 a number of child variable objects, for example corresponding to each
32315 element of a structure. A child variable object can itself have
32316 children, recursively. Recursion ends when we reach
32317 leaf variable objects, which always have built-in types. Child variable
32318 objects are created only by explicit request, so if a frontend
32319 is not interested in the children of a particular variable object, no
32320 child will be created.
32321
32322 For a leaf variable object it is possible to obtain its value as a
32323 string, or set the value from a string. String value can be also
32324 obtained for a non-leaf variable object, but it's generally a string
32325 that only indicates the type of the object, and does not list its
32326 contents. Assignment to a non-leaf variable object is not allowed.
32327
32328 A frontend does not need to read the values of all variable objects each time
32329 the program stops. Instead, MI provides an update command that lists all
32330 variable objects whose values has changed since the last update
32331 operation. This considerably reduces the amount of data that must
32332 be transferred to the frontend. As noted above, children variable
32333 objects are created on demand, and only leaf variable objects have a
32334 real value. As result, gdb will read target memory only for leaf
32335 variables that frontend has created.
32336
32337 The automatic update is not always desirable. For example, a frontend
32338 might want to keep a value of some expression for future reference,
32339 and never update it. For another example, fetching memory is
32340 relatively slow for embedded targets, so a frontend might want
32341 to disable automatic update for the variables that are either not
32342 visible on the screen, or ``closed''. This is possible using so
32343 called ``frozen variable objects''. Such variable objects are never
32344 implicitly updated.
32345
32346 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32347 fixed variable object, the expression is parsed when the variable
32348 object is created, including associating identifiers to specific
32349 variables. The meaning of expression never changes. For a floating
32350 variable object the values of variables whose names appear in the
32351 expressions are re-evaluated every time in the context of the current
32352 frame. Consider this example:
32353
32354 @smallexample
32355 void do_work(...)
32356 @{
32357 struct work_state state;
32358
32359 if (...)
32360 do_work(...);
32361 @}
32362 @end smallexample
32363
32364 If a fixed variable object for the @code{state} variable is created in
32365 this function, and we enter the recursive call, the variable
32366 object will report the value of @code{state} in the top-level
32367 @code{do_work} invocation. On the other hand, a floating variable
32368 object will report the value of @code{state} in the current frame.
32369
32370 If an expression specified when creating a fixed variable object
32371 refers to a local variable, the variable object becomes bound to the
32372 thread and frame in which the variable object is created. When such
32373 variable object is updated, @value{GDBN} makes sure that the
32374 thread/frame combination the variable object is bound to still exists,
32375 and re-evaluates the variable object in context of that thread/frame.
32376
32377 The following is the complete set of @sc{gdb/mi} operations defined to
32378 access this functionality:
32379
32380 @multitable @columnfractions .4 .6
32381 @item @strong{Operation}
32382 @tab @strong{Description}
32383
32384 @item @code{-enable-pretty-printing}
32385 @tab enable Python-based pretty-printing
32386 @item @code{-var-create}
32387 @tab create a variable object
32388 @item @code{-var-delete}
32389 @tab delete the variable object and/or its children
32390 @item @code{-var-set-format}
32391 @tab set the display format of this variable
32392 @item @code{-var-show-format}
32393 @tab show the display format of this variable
32394 @item @code{-var-info-num-children}
32395 @tab tells how many children this object has
32396 @item @code{-var-list-children}
32397 @tab return a list of the object's children
32398 @item @code{-var-info-type}
32399 @tab show the type of this variable object
32400 @item @code{-var-info-expression}
32401 @tab print parent-relative expression that this variable object represents
32402 @item @code{-var-info-path-expression}
32403 @tab print full expression that this variable object represents
32404 @item @code{-var-show-attributes}
32405 @tab is this variable editable? does it exist here?
32406 @item @code{-var-evaluate-expression}
32407 @tab get the value of this variable
32408 @item @code{-var-assign}
32409 @tab set the value of this variable
32410 @item @code{-var-update}
32411 @tab update the variable and its children
32412 @item @code{-var-set-frozen}
32413 @tab set frozenness attribute
32414 @item @code{-var-set-update-range}
32415 @tab set range of children to display on update
32416 @end multitable
32417
32418 In the next subsection we describe each operation in detail and suggest
32419 how it can be used.
32420
32421 @subheading Description And Use of Operations on Variable Objects
32422
32423 @subheading The @code{-enable-pretty-printing} Command
32424 @findex -enable-pretty-printing
32425
32426 @smallexample
32427 -enable-pretty-printing
32428 @end smallexample
32429
32430 @value{GDBN} allows Python-based visualizers to affect the output of the
32431 MI variable object commands. However, because there was no way to
32432 implement this in a fully backward-compatible way, a front end must
32433 request that this functionality be enabled.
32434
32435 Once enabled, this feature cannot be disabled.
32436
32437 Note that if Python support has not been compiled into @value{GDBN},
32438 this command will still succeed (and do nothing).
32439
32440 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32441 may work differently in future versions of @value{GDBN}.
32442
32443 @subheading The @code{-var-create} Command
32444 @findex -var-create
32445
32446 @subsubheading Synopsis
32447
32448 @smallexample
32449 -var-create @{@var{name} | "-"@}
32450 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32451 @end smallexample
32452
32453 This operation creates a variable object, which allows the monitoring of
32454 a variable, the result of an expression, a memory cell or a CPU
32455 register.
32456
32457 The @var{name} parameter is the string by which the object can be
32458 referenced. It must be unique. If @samp{-} is specified, the varobj
32459 system will generate a string ``varNNNNNN'' automatically. It will be
32460 unique provided that one does not specify @var{name} of that format.
32461 The command fails if a duplicate name is found.
32462
32463 The frame under which the expression should be evaluated can be
32464 specified by @var{frame-addr}. A @samp{*} indicates that the current
32465 frame should be used. A @samp{@@} indicates that a floating variable
32466 object must be created.
32467
32468 @var{expression} is any expression valid on the current language set (must not
32469 begin with a @samp{*}), or one of the following:
32470
32471 @itemize @bullet
32472 @item
32473 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
32474
32475 @item
32476 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
32477
32478 @item
32479 @samp{$@var{regname}} --- a CPU register name
32480 @end itemize
32481
32482 @cindex dynamic varobj
32483 A varobj's contents may be provided by a Python-based pretty-printer. In this
32484 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32485 have slightly different semantics in some cases. If the
32486 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32487 will never create a dynamic varobj. This ensures backward
32488 compatibility for existing clients.
32489
32490 @subsubheading Result
32491
32492 This operation returns attributes of the newly-created varobj. These
32493 are:
32494
32495 @table @samp
32496 @item name
32497 The name of the varobj.
32498
32499 @item numchild
32500 The number of children of the varobj. This number is not necessarily
32501 reliable for a dynamic varobj. Instead, you must examine the
32502 @samp{has_more} attribute.
32503
32504 @item value
32505 The varobj's scalar value. For a varobj whose type is some sort of
32506 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32507 will not be interesting.
32508
32509 @item type
32510 The varobj's type. This is a string representation of the type, as
32511 would be printed by the @value{GDBN} CLI. If @samp{print object}
32512 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32513 @emph{actual} (derived) type of the object is shown rather than the
32514 @emph{declared} one.
32515
32516 @item thread-id
32517 If a variable object is bound to a specific thread, then this is the
32518 thread's global identifier.
32519
32520 @item has_more
32521 For a dynamic varobj, this indicates whether there appear to be any
32522 children available. For a non-dynamic varobj, this will be 0.
32523
32524 @item dynamic
32525 This attribute will be present and have the value @samp{1} if the
32526 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32527 then this attribute will not be present.
32528
32529 @item displayhint
32530 A dynamic varobj can supply a display hint to the front end. The
32531 value comes directly from the Python pretty-printer object's
32532 @code{display_hint} method. @xref{Pretty Printing API}.
32533 @end table
32534
32535 Typical output will look like this:
32536
32537 @smallexample
32538 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32539 has_more="@var{has_more}"
32540 @end smallexample
32541
32542
32543 @subheading The @code{-var-delete} Command
32544 @findex -var-delete
32545
32546 @subsubheading Synopsis
32547
32548 @smallexample
32549 -var-delete [ -c ] @var{name}
32550 @end smallexample
32551
32552 Deletes a previously created variable object and all of its children.
32553 With the @samp{-c} option, just deletes the children.
32554
32555 Returns an error if the object @var{name} is not found.
32556
32557
32558 @subheading The @code{-var-set-format} Command
32559 @findex -var-set-format
32560
32561 @subsubheading Synopsis
32562
32563 @smallexample
32564 -var-set-format @var{name} @var{format-spec}
32565 @end smallexample
32566
32567 Sets the output format for the value of the object @var{name} to be
32568 @var{format-spec}.
32569
32570 @anchor{-var-set-format}
32571 The syntax for the @var{format-spec} is as follows:
32572
32573 @smallexample
32574 @var{format-spec} @expansion{}
32575 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
32576 @end smallexample
32577
32578 The natural format is the default format choosen automatically
32579 based on the variable type (like decimal for an @code{int}, hex
32580 for pointers, etc.).
32581
32582 The zero-hexadecimal format has a representation similar to hexadecimal
32583 but with padding zeroes to the left of the value. For example, a 32-bit
32584 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32585 zero-hexadecimal format.
32586
32587 For a variable with children, the format is set only on the
32588 variable itself, and the children are not affected.
32589
32590 @subheading The @code{-var-show-format} Command
32591 @findex -var-show-format
32592
32593 @subsubheading Synopsis
32594
32595 @smallexample
32596 -var-show-format @var{name}
32597 @end smallexample
32598
32599 Returns the format used to display the value of the object @var{name}.
32600
32601 @smallexample
32602 @var{format} @expansion{}
32603 @var{format-spec}
32604 @end smallexample
32605
32606
32607 @subheading The @code{-var-info-num-children} Command
32608 @findex -var-info-num-children
32609
32610 @subsubheading Synopsis
32611
32612 @smallexample
32613 -var-info-num-children @var{name}
32614 @end smallexample
32615
32616 Returns the number of children of a variable object @var{name}:
32617
32618 @smallexample
32619 numchild=@var{n}
32620 @end smallexample
32621
32622 Note that this number is not completely reliable for a dynamic varobj.
32623 It will return the current number of children, but more children may
32624 be available.
32625
32626
32627 @subheading The @code{-var-list-children} Command
32628 @findex -var-list-children
32629
32630 @subsubheading Synopsis
32631
32632 @smallexample
32633 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32634 @end smallexample
32635 @anchor{-var-list-children}
32636
32637 Return a list of the children of the specified variable object and
32638 create variable objects for them, if they do not already exist. With
32639 a single argument or if @var{print-values} has a value of 0 or
32640 @code{--no-values}, print only the names of the variables; if
32641 @var{print-values} is 1 or @code{--all-values}, also print their
32642 values; and if it is 2 or @code{--simple-values} print the name and
32643 value for simple data types and just the name for arrays, structures
32644 and unions.
32645
32646 @var{from} and @var{to}, if specified, indicate the range of children
32647 to report. If @var{from} or @var{to} is less than zero, the range is
32648 reset and all children will be reported. Otherwise, children starting
32649 at @var{from} (zero-based) and up to and excluding @var{to} will be
32650 reported.
32651
32652 If a child range is requested, it will only affect the current call to
32653 @code{-var-list-children}, but not future calls to @code{-var-update}.
32654 For this, you must instead use @code{-var-set-update-range}. The
32655 intent of this approach is to enable a front end to implement any
32656 update approach it likes; for example, scrolling a view may cause the
32657 front end to request more children with @code{-var-list-children}, and
32658 then the front end could call @code{-var-set-update-range} with a
32659 different range to ensure that future updates are restricted to just
32660 the visible items.
32661
32662 For each child the following results are returned:
32663
32664 @table @var
32665
32666 @item name
32667 Name of the variable object created for this child.
32668
32669 @item exp
32670 The expression to be shown to the user by the front end to designate this child.
32671 For example this may be the name of a structure member.
32672
32673 For a dynamic varobj, this value cannot be used to form an
32674 expression. There is no way to do this at all with a dynamic varobj.
32675
32676 For C/C@t{++} structures there are several pseudo children returned to
32677 designate access qualifiers. For these pseudo children @var{exp} is
32678 @samp{public}, @samp{private}, or @samp{protected}. In this case the
32679 type and value are not present.
32680
32681 A dynamic varobj will not report the access qualifying
32682 pseudo-children, regardless of the language. This information is not
32683 available at all with a dynamic varobj.
32684
32685 @item numchild
32686 Number of children this child has. For a dynamic varobj, this will be
32687 0.
32688
32689 @item type
32690 The type of the child. If @samp{print object}
32691 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32692 @emph{actual} (derived) type of the object is shown rather than the
32693 @emph{declared} one.
32694
32695 @item value
32696 If values were requested, this is the value.
32697
32698 @item thread-id
32699 If this variable object is associated with a thread, this is the
32700 thread's global thread id. Otherwise this result is not present.
32701
32702 @item frozen
32703 If the variable object is frozen, this variable will be present with a value of 1.
32704
32705 @item displayhint
32706 A dynamic varobj can supply a display hint to the front end. The
32707 value comes directly from the Python pretty-printer object's
32708 @code{display_hint} method. @xref{Pretty Printing API}.
32709
32710 @item dynamic
32711 This attribute will be present and have the value @samp{1} if the
32712 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32713 then this attribute will not be present.
32714
32715 @end table
32716
32717 The result may have its own attributes:
32718
32719 @table @samp
32720 @item displayhint
32721 A dynamic varobj can supply a display hint to the front end. The
32722 value comes directly from the Python pretty-printer object's
32723 @code{display_hint} method. @xref{Pretty Printing API}.
32724
32725 @item has_more
32726 This is an integer attribute which is nonzero if there are children
32727 remaining after the end of the selected range.
32728 @end table
32729
32730 @subsubheading Example
32731
32732 @smallexample
32733 (gdb)
32734 -var-list-children n
32735 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32736 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
32737 (gdb)
32738 -var-list-children --all-values n
32739 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32740 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
32741 @end smallexample
32742
32743
32744 @subheading The @code{-var-info-type} Command
32745 @findex -var-info-type
32746
32747 @subsubheading Synopsis
32748
32749 @smallexample
32750 -var-info-type @var{name}
32751 @end smallexample
32752
32753 Returns the type of the specified variable @var{name}. The type is
32754 returned as a string in the same format as it is output by the
32755 @value{GDBN} CLI:
32756
32757 @smallexample
32758 type=@var{typename}
32759 @end smallexample
32760
32761
32762 @subheading The @code{-var-info-expression} Command
32763 @findex -var-info-expression
32764
32765 @subsubheading Synopsis
32766
32767 @smallexample
32768 -var-info-expression @var{name}
32769 @end smallexample
32770
32771 Returns a string that is suitable for presenting this
32772 variable object in user interface. The string is generally
32773 not valid expression in the current language, and cannot be evaluated.
32774
32775 For example, if @code{a} is an array, and variable object
32776 @code{A} was created for @code{a}, then we'll get this output:
32777
32778 @smallexample
32779 (gdb) -var-info-expression A.1
32780 ^done,lang="C",exp="1"
32781 @end smallexample
32782
32783 @noindent
32784 Here, the value of @code{lang} is the language name, which can be
32785 found in @ref{Supported Languages}.
32786
32787 Note that the output of the @code{-var-list-children} command also
32788 includes those expressions, so the @code{-var-info-expression} command
32789 is of limited use.
32790
32791 @subheading The @code{-var-info-path-expression} Command
32792 @findex -var-info-path-expression
32793
32794 @subsubheading Synopsis
32795
32796 @smallexample
32797 -var-info-path-expression @var{name}
32798 @end smallexample
32799
32800 Returns an expression that can be evaluated in the current
32801 context and will yield the same value that a variable object has.
32802 Compare this with the @code{-var-info-expression} command, which
32803 result can be used only for UI presentation. Typical use of
32804 the @code{-var-info-path-expression} command is creating a
32805 watchpoint from a variable object.
32806
32807 This command is currently not valid for children of a dynamic varobj,
32808 and will give an error when invoked on one.
32809
32810 For example, suppose @code{C} is a C@t{++} class, derived from class
32811 @code{Base}, and that the @code{Base} class has a member called
32812 @code{m_size}. Assume a variable @code{c} is has the type of
32813 @code{C} and a variable object @code{C} was created for variable
32814 @code{c}. Then, we'll get this output:
32815 @smallexample
32816 (gdb) -var-info-path-expression C.Base.public.m_size
32817 ^done,path_expr=((Base)c).m_size)
32818 @end smallexample
32819
32820 @subheading The @code{-var-show-attributes} Command
32821 @findex -var-show-attributes
32822
32823 @subsubheading Synopsis
32824
32825 @smallexample
32826 -var-show-attributes @var{name}
32827 @end smallexample
32828
32829 List attributes of the specified variable object @var{name}:
32830
32831 @smallexample
32832 status=@var{attr} [ ( ,@var{attr} )* ]
32833 @end smallexample
32834
32835 @noindent
32836 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32837
32838 @subheading The @code{-var-evaluate-expression} Command
32839 @findex -var-evaluate-expression
32840
32841 @subsubheading Synopsis
32842
32843 @smallexample
32844 -var-evaluate-expression [-f @var{format-spec}] @var{name}
32845 @end smallexample
32846
32847 Evaluates the expression that is represented by the specified variable
32848 object and returns its value as a string. The format of the string
32849 can be specified with the @samp{-f} option. The possible values of
32850 this option are the same as for @code{-var-set-format}
32851 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32852 the current display format will be used. The current display format
32853 can be changed using the @code{-var-set-format} command.
32854
32855 @smallexample
32856 value=@var{value}
32857 @end smallexample
32858
32859 Note that one must invoke @code{-var-list-children} for a variable
32860 before the value of a child variable can be evaluated.
32861
32862 @subheading The @code{-var-assign} Command
32863 @findex -var-assign
32864
32865 @subsubheading Synopsis
32866
32867 @smallexample
32868 -var-assign @var{name} @var{expression}
32869 @end smallexample
32870
32871 Assigns the value of @var{expression} to the variable object specified
32872 by @var{name}. The object must be @samp{editable}. If the variable's
32873 value is altered by the assign, the variable will show up in any
32874 subsequent @code{-var-update} list.
32875
32876 @subsubheading Example
32877
32878 @smallexample
32879 (gdb)
32880 -var-assign var1 3
32881 ^done,value="3"
32882 (gdb)
32883 -var-update *
32884 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
32885 (gdb)
32886 @end smallexample
32887
32888 @subheading The @code{-var-update} Command
32889 @findex -var-update
32890
32891 @subsubheading Synopsis
32892
32893 @smallexample
32894 -var-update [@var{print-values}] @{@var{name} | "*"@}
32895 @end smallexample
32896
32897 Reevaluate the expressions corresponding to the variable object
32898 @var{name} and all its direct and indirect children, and return the
32899 list of variable objects whose values have changed; @var{name} must
32900 be a root variable object. Here, ``changed'' means that the result of
32901 @code{-var-evaluate-expression} before and after the
32902 @code{-var-update} is different. If @samp{*} is used as the variable
32903 object names, all existing variable objects are updated, except
32904 for frozen ones (@pxref{-var-set-frozen}). The option
32905 @var{print-values} determines whether both names and values, or just
32906 names are printed. The possible values of this option are the same
32907 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32908 recommended to use the @samp{--all-values} option, to reduce the
32909 number of MI commands needed on each program stop.
32910
32911 With the @samp{*} parameter, if a variable object is bound to a
32912 currently running thread, it will not be updated, without any
32913 diagnostic.
32914
32915 If @code{-var-set-update-range} was previously used on a varobj, then
32916 only the selected range of children will be reported.
32917
32918 @code{-var-update} reports all the changed varobjs in a tuple named
32919 @samp{changelist}.
32920
32921 Each item in the change list is itself a tuple holding:
32922
32923 @table @samp
32924 @item name
32925 The name of the varobj.
32926
32927 @item value
32928 If values were requested for this update, then this field will be
32929 present and will hold the value of the varobj.
32930
32931 @item in_scope
32932 @anchor{-var-update}
32933 This field is a string which may take one of three values:
32934
32935 @table @code
32936 @item "true"
32937 The variable object's current value is valid.
32938
32939 @item "false"
32940 The variable object does not currently hold a valid value but it may
32941 hold one in the future if its associated expression comes back into
32942 scope.
32943
32944 @item "invalid"
32945 The variable object no longer holds a valid value.
32946 This can occur when the executable file being debugged has changed,
32947 either through recompilation or by using the @value{GDBN} @code{file}
32948 command. The front end should normally choose to delete these variable
32949 objects.
32950 @end table
32951
32952 In the future new values may be added to this list so the front should
32953 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32954
32955 @item type_changed
32956 This is only present if the varobj is still valid. If the type
32957 changed, then this will be the string @samp{true}; otherwise it will
32958 be @samp{false}.
32959
32960 When a varobj's type changes, its children are also likely to have
32961 become incorrect. Therefore, the varobj's children are automatically
32962 deleted when this attribute is @samp{true}. Also, the varobj's update
32963 range, when set using the @code{-var-set-update-range} command, is
32964 unset.
32965
32966 @item new_type
32967 If the varobj's type changed, then this field will be present and will
32968 hold the new type.
32969
32970 @item new_num_children
32971 For a dynamic varobj, if the number of children changed, or if the
32972 type changed, this will be the new number of children.
32973
32974 The @samp{numchild} field in other varobj responses is generally not
32975 valid for a dynamic varobj -- it will show the number of children that
32976 @value{GDBN} knows about, but because dynamic varobjs lazily
32977 instantiate their children, this will not reflect the number of
32978 children which may be available.
32979
32980 The @samp{new_num_children} attribute only reports changes to the
32981 number of children known by @value{GDBN}. This is the only way to
32982 detect whether an update has removed children (which necessarily can
32983 only happen at the end of the update range).
32984
32985 @item displayhint
32986 The display hint, if any.
32987
32988 @item has_more
32989 This is an integer value, which will be 1 if there are more children
32990 available outside the varobj's update range.
32991
32992 @item dynamic
32993 This attribute will be present and have the value @samp{1} if the
32994 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32995 then this attribute will not be present.
32996
32997 @item new_children
32998 If new children were added to a dynamic varobj within the selected
32999 update range (as set by @code{-var-set-update-range}), then they will
33000 be listed in this attribute.
33001 @end table
33002
33003 @subsubheading Example
33004
33005 @smallexample
33006 (gdb)
33007 -var-assign var1 3
33008 ^done,value="3"
33009 (gdb)
33010 -var-update --all-values var1
33011 ^done,changelist=[@{name="var1",value="3",in_scope="true",
33012 type_changed="false"@}]
33013 (gdb)
33014 @end smallexample
33015
33016 @subheading The @code{-var-set-frozen} Command
33017 @findex -var-set-frozen
33018 @anchor{-var-set-frozen}
33019
33020 @subsubheading Synopsis
33021
33022 @smallexample
33023 -var-set-frozen @var{name} @var{flag}
33024 @end smallexample
33025
33026 Set the frozenness flag on the variable object @var{name}. The
33027 @var{flag} parameter should be either @samp{1} to make the variable
33028 frozen or @samp{0} to make it unfrozen. If a variable object is
33029 frozen, then neither itself, nor any of its children, are
33030 implicitly updated by @code{-var-update} of
33031 a parent variable or by @code{-var-update *}. Only
33032 @code{-var-update} of the variable itself will update its value and
33033 values of its children. After a variable object is unfrozen, it is
33034 implicitly updated by all subsequent @code{-var-update} operations.
33035 Unfreezing a variable does not update it, only subsequent
33036 @code{-var-update} does.
33037
33038 @subsubheading Example
33039
33040 @smallexample
33041 (gdb)
33042 -var-set-frozen V 1
33043 ^done
33044 (gdb)
33045 @end smallexample
33046
33047 @subheading The @code{-var-set-update-range} command
33048 @findex -var-set-update-range
33049 @anchor{-var-set-update-range}
33050
33051 @subsubheading Synopsis
33052
33053 @smallexample
33054 -var-set-update-range @var{name} @var{from} @var{to}
33055 @end smallexample
33056
33057 Set the range of children to be returned by future invocations of
33058 @code{-var-update}.
33059
33060 @var{from} and @var{to} indicate the range of children to report. If
33061 @var{from} or @var{to} is less than zero, the range is reset and all
33062 children will be reported. Otherwise, children starting at @var{from}
33063 (zero-based) and up to and excluding @var{to} will be reported.
33064
33065 @subsubheading Example
33066
33067 @smallexample
33068 (gdb)
33069 -var-set-update-range V 1 2
33070 ^done
33071 @end smallexample
33072
33073 @subheading The @code{-var-set-visualizer} command
33074 @findex -var-set-visualizer
33075 @anchor{-var-set-visualizer}
33076
33077 @subsubheading Synopsis
33078
33079 @smallexample
33080 -var-set-visualizer @var{name} @var{visualizer}
33081 @end smallexample
33082
33083 Set a visualizer for the variable object @var{name}.
33084
33085 @var{visualizer} is the visualizer to use. The special value
33086 @samp{None} means to disable any visualizer in use.
33087
33088 If not @samp{None}, @var{visualizer} must be a Python expression.
33089 This expression must evaluate to a callable object which accepts a
33090 single argument. @value{GDBN} will call this object with the value of
33091 the varobj @var{name} as an argument (this is done so that the same
33092 Python pretty-printing code can be used for both the CLI and MI).
33093 When called, this object must return an object which conforms to the
33094 pretty-printing interface (@pxref{Pretty Printing API}).
33095
33096 The pre-defined function @code{gdb.default_visualizer} may be used to
33097 select a visualizer by following the built-in process
33098 (@pxref{Selecting Pretty-Printers}). This is done automatically when
33099 a varobj is created, and so ordinarily is not needed.
33100
33101 This feature is only available if Python support is enabled. The MI
33102 command @code{-list-features} (@pxref{GDB/MI Support Commands})
33103 can be used to check this.
33104
33105 @subsubheading Example
33106
33107 Resetting the visualizer:
33108
33109 @smallexample
33110 (gdb)
33111 -var-set-visualizer V None
33112 ^done
33113 @end smallexample
33114
33115 Reselecting the default (type-based) visualizer:
33116
33117 @smallexample
33118 (gdb)
33119 -var-set-visualizer V gdb.default_visualizer
33120 ^done
33121 @end smallexample
33122
33123 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33124 can be used to instantiate this class for a varobj:
33125
33126 @smallexample
33127 (gdb)
33128 -var-set-visualizer V "lambda val: SomeClass()"
33129 ^done
33130 @end smallexample
33131
33132 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33133 @node GDB/MI Data Manipulation
33134 @section @sc{gdb/mi} Data Manipulation
33135
33136 @cindex data manipulation, in @sc{gdb/mi}
33137 @cindex @sc{gdb/mi}, data manipulation
33138 This section describes the @sc{gdb/mi} commands that manipulate data:
33139 examine memory and registers, evaluate expressions, etc.
33140
33141 For details about what an addressable memory unit is,
33142 @pxref{addressable memory unit}.
33143
33144 @c REMOVED FROM THE INTERFACE.
33145 @c @subheading -data-assign
33146 @c Change the value of a program variable. Plenty of side effects.
33147 @c @subsubheading GDB Command
33148 @c set variable
33149 @c @subsubheading Example
33150 @c N.A.
33151
33152 @subheading The @code{-data-disassemble} Command
33153 @findex -data-disassemble
33154
33155 @subsubheading Synopsis
33156
33157 @smallexample
33158 -data-disassemble
33159 [ -s @var{start-addr} -e @var{end-addr} ]
33160 | [ -a @var{addr} ]
33161 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33162 -- @var{mode}
33163 @end smallexample
33164
33165 @noindent
33166 Where:
33167
33168 @table @samp
33169 @item @var{start-addr}
33170 is the beginning address (or @code{$pc})
33171 @item @var{end-addr}
33172 is the end address
33173 @item @var{addr}
33174 is an address anywhere within (or the name of) the function to
33175 disassemble. If an address is specified, the whole function
33176 surrounding that address will be disassembled. If a name is
33177 specified, the whole function with that name will be disassembled.
33178 @item @var{filename}
33179 is the name of the file to disassemble
33180 @item @var{linenum}
33181 is the line number to disassemble around
33182 @item @var{lines}
33183 is the number of disassembly lines to be produced. If it is -1,
33184 the whole function will be disassembled, in case no @var{end-addr} is
33185 specified. If @var{end-addr} is specified as a non-zero value, and
33186 @var{lines} is lower than the number of disassembly lines between
33187 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
33188 displayed; if @var{lines} is higher than the number of lines between
33189 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33190 are displayed.
33191 @item @var{mode}
33192 is one of:
33193 @itemize @bullet
33194 @item 0 disassembly only
33195 @item 1 mixed source and disassembly (deprecated)
33196 @item 2 disassembly with raw opcodes
33197 @item 3 mixed source and disassembly with raw opcodes (deprecated)
33198 @item 4 mixed source and disassembly
33199 @item 5 mixed source and disassembly with raw opcodes
33200 @end itemize
33201
33202 Modes 1 and 3 are deprecated. The output is ``source centric''
33203 which hasn't proved useful in practice.
33204 @xref{Machine Code}, for a discussion of the difference between
33205 @code{/m} and @code{/s} output of the @code{disassemble} command.
33206 @end table
33207
33208 @subsubheading Result
33209
33210 The result of the @code{-data-disassemble} command will be a list named
33211 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33212 used with the @code{-data-disassemble} command.
33213
33214 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33215 following fields:
33216
33217 @table @code
33218 @item address
33219 The address at which this instruction was disassembled.
33220
33221 @item func-name
33222 The name of the function this instruction is within.
33223
33224 @item offset
33225 The decimal offset in bytes from the start of @samp{func-name}.
33226
33227 @item inst
33228 The text disassembly for this @samp{address}.
33229
33230 @item opcodes
33231 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33232 bytes for the @samp{inst} field.
33233
33234 @end table
33235
33236 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33237 @samp{src_and_asm_line}, each of which has the following fields:
33238
33239 @table @code
33240 @item line
33241 The line number within @samp{file}.
33242
33243 @item file
33244 The file name from the compilation unit. This might be an absolute
33245 file name or a relative file name depending on the compile command
33246 used.
33247
33248 @item fullname
33249 Absolute file name of @samp{file}. It is converted to a canonical form
33250 using the source file search path
33251 (@pxref{Source Path, ,Specifying Source Directories})
33252 and after resolving all the symbolic links.
33253
33254 If the source file is not found this field will contain the path as
33255 present in the debug information.
33256
33257 @item line_asm_insn
33258 This is a list of tuples containing the disassembly for @samp{line} in
33259 @samp{file}. The fields of each tuple are the same as for
33260 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33261 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33262 @samp{opcodes}.
33263
33264 @end table
33265
33266 Note that whatever included in the @samp{inst} field, is not
33267 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33268 adjust its format.
33269
33270 @subsubheading @value{GDBN} Command
33271
33272 The corresponding @value{GDBN} command is @samp{disassemble}.
33273
33274 @subsubheading Example
33275
33276 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33277
33278 @smallexample
33279 (gdb)
33280 -data-disassemble -s $pc -e "$pc + 20" -- 0
33281 ^done,
33282 asm_insns=[
33283 @{address="0x000107c0",func-name="main",offset="4",
33284 inst="mov 2, %o0"@},
33285 @{address="0x000107c4",func-name="main",offset="8",
33286 inst="sethi %hi(0x11800), %o2"@},
33287 @{address="0x000107c8",func-name="main",offset="12",
33288 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33289 @{address="0x000107cc",func-name="main",offset="16",
33290 inst="sethi %hi(0x11800), %o2"@},
33291 @{address="0x000107d0",func-name="main",offset="20",
33292 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33293 (gdb)
33294 @end smallexample
33295
33296 Disassemble the whole @code{main} function. Line 32 is part of
33297 @code{main}.
33298
33299 @smallexample
33300 -data-disassemble -f basics.c -l 32 -- 0
33301 ^done,asm_insns=[
33302 @{address="0x000107bc",func-name="main",offset="0",
33303 inst="save %sp, -112, %sp"@},
33304 @{address="0x000107c0",func-name="main",offset="4",
33305 inst="mov 2, %o0"@},
33306 @{address="0x000107c4",func-name="main",offset="8",
33307 inst="sethi %hi(0x11800), %o2"@},
33308 [@dots{}]
33309 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33310 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33311 (gdb)
33312 @end smallexample
33313
33314 Disassemble 3 instructions from the start of @code{main}:
33315
33316 @smallexample
33317 (gdb)
33318 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33319 ^done,asm_insns=[
33320 @{address="0x000107bc",func-name="main",offset="0",
33321 inst="save %sp, -112, %sp"@},
33322 @{address="0x000107c0",func-name="main",offset="4",
33323 inst="mov 2, %o0"@},
33324 @{address="0x000107c4",func-name="main",offset="8",
33325 inst="sethi %hi(0x11800), %o2"@}]
33326 (gdb)
33327 @end smallexample
33328
33329 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33330
33331 @smallexample
33332 (gdb)
33333 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33334 ^done,asm_insns=[
33335 src_and_asm_line=@{line="31",
33336 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33337 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33338 line_asm_insn=[@{address="0x000107bc",
33339 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33340 src_and_asm_line=@{line="32",
33341 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33342 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33343 line_asm_insn=[@{address="0x000107c0",
33344 func-name="main",offset="4",inst="mov 2, %o0"@},
33345 @{address="0x000107c4",func-name="main",offset="8",
33346 inst="sethi %hi(0x11800), %o2"@}]@}]
33347 (gdb)
33348 @end smallexample
33349
33350
33351 @subheading The @code{-data-evaluate-expression} Command
33352 @findex -data-evaluate-expression
33353
33354 @subsubheading Synopsis
33355
33356 @smallexample
33357 -data-evaluate-expression @var{expr}
33358 @end smallexample
33359
33360 Evaluate @var{expr} as an expression. The expression could contain an
33361 inferior function call. The function call will execute synchronously.
33362 If the expression contains spaces, it must be enclosed in double quotes.
33363
33364 @subsubheading @value{GDBN} Command
33365
33366 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33367 @samp{call}. In @code{gdbtk} only, there's a corresponding
33368 @samp{gdb_eval} command.
33369
33370 @subsubheading Example
33371
33372 In the following example, the numbers that precede the commands are the
33373 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33374 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33375 output.
33376
33377 @smallexample
33378 211-data-evaluate-expression A
33379 211^done,value="1"
33380 (gdb)
33381 311-data-evaluate-expression &A
33382 311^done,value="0xefffeb7c"
33383 (gdb)
33384 411-data-evaluate-expression A+3
33385 411^done,value="4"
33386 (gdb)
33387 511-data-evaluate-expression "A + 3"
33388 511^done,value="4"
33389 (gdb)
33390 @end smallexample
33391
33392
33393 @subheading The @code{-data-list-changed-registers} Command
33394 @findex -data-list-changed-registers
33395
33396 @subsubheading Synopsis
33397
33398 @smallexample
33399 -data-list-changed-registers
33400 @end smallexample
33401
33402 Display a list of the registers that have changed.
33403
33404 @subsubheading @value{GDBN} Command
33405
33406 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33407 has the corresponding command @samp{gdb_changed_register_list}.
33408
33409 @subsubheading Example
33410
33411 On a PPC MBX board:
33412
33413 @smallexample
33414 (gdb)
33415 -exec-continue
33416 ^running
33417
33418 (gdb)
33419 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33420 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33421 line="5",arch="powerpc"@}
33422 (gdb)
33423 -data-list-changed-registers
33424 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33425 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33426 "24","25","26","27","28","30","31","64","65","66","67","69"]
33427 (gdb)
33428 @end smallexample
33429
33430
33431 @subheading The @code{-data-list-register-names} Command
33432 @findex -data-list-register-names
33433
33434 @subsubheading Synopsis
33435
33436 @smallexample
33437 -data-list-register-names [ ( @var{regno} )+ ]
33438 @end smallexample
33439
33440 Show a list of register names for the current target. If no arguments
33441 are given, it shows a list of the names of all the registers. If
33442 integer numbers are given as arguments, it will print a list of the
33443 names of the registers corresponding to the arguments. To ensure
33444 consistency between a register name and its number, the output list may
33445 include empty register names.
33446
33447 @subsubheading @value{GDBN} Command
33448
33449 @value{GDBN} does not have a command which corresponds to
33450 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33451 corresponding command @samp{gdb_regnames}.
33452
33453 @subsubheading Example
33454
33455 For the PPC MBX board:
33456 @smallexample
33457 (gdb)
33458 -data-list-register-names
33459 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33460 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33461 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33462 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33463 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33464 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33465 "", "pc","ps","cr","lr","ctr","xer"]
33466 (gdb)
33467 -data-list-register-names 1 2 3
33468 ^done,register-names=["r1","r2","r3"]
33469 (gdb)
33470 @end smallexample
33471
33472 @subheading The @code{-data-list-register-values} Command
33473 @findex -data-list-register-values
33474
33475 @subsubheading Synopsis
33476
33477 @smallexample
33478 -data-list-register-values
33479 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
33480 @end smallexample
33481
33482 Display the registers' contents. The format according to which the
33483 registers' contents are to be returned is given by @var{fmt}, followed
33484 by an optional list of numbers specifying the registers to display. A
33485 missing list of numbers indicates that the contents of all the
33486 registers must be returned. The @code{--skip-unavailable} option
33487 indicates that only the available registers are to be returned.
33488
33489 Allowed formats for @var{fmt} are:
33490
33491 @table @code
33492 @item x
33493 Hexadecimal
33494 @item o
33495 Octal
33496 @item t
33497 Binary
33498 @item d
33499 Decimal
33500 @item r
33501 Raw
33502 @item N
33503 Natural
33504 @end table
33505
33506 @subsubheading @value{GDBN} Command
33507
33508 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33509 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
33510
33511 @subsubheading Example
33512
33513 For a PPC MBX board (note: line breaks are for readability only, they
33514 don't appear in the actual output):
33515
33516 @smallexample
33517 (gdb)
33518 -data-list-register-values r 64 65
33519 ^done,register-values=[@{number="64",value="0xfe00a300"@},
33520 @{number="65",value="0x00029002"@}]
33521 (gdb)
33522 -data-list-register-values x
33523 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
33524 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33525 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
33526 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33527 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33528 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33529 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
33530 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33531 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33532 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33533 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33534 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33535 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33536 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33537 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33538 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33539 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
33540 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
33541 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
33542 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
33543 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
33544 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
33545 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
33546 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
33547 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
33548 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
33549 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
33550 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
33551 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
33552 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
33553 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
33554 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
33555 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33556 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33557 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33558 @{number="69",value="0x20002b03"@}]
33559 (gdb)
33560 @end smallexample
33561
33562
33563 @subheading The @code{-data-read-memory} Command
33564 @findex -data-read-memory
33565
33566 This command is deprecated, use @code{-data-read-memory-bytes} instead.
33567
33568 @subsubheading Synopsis
33569
33570 @smallexample
33571 -data-read-memory [ -o @var{byte-offset} ]
33572 @var{address} @var{word-format} @var{word-size}
33573 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
33574 @end smallexample
33575
33576 @noindent
33577 where:
33578
33579 @table @samp
33580 @item @var{address}
33581 An expression specifying the address of the first memory word to be
33582 read. Complex expressions containing embedded white space should be
33583 quoted using the C convention.
33584
33585 @item @var{word-format}
33586 The format to be used to print the memory words. The notation is the
33587 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
33588 ,Output Formats}).
33589
33590 @item @var{word-size}
33591 The size of each memory word in bytes.
33592
33593 @item @var{nr-rows}
33594 The number of rows in the output table.
33595
33596 @item @var{nr-cols}
33597 The number of columns in the output table.
33598
33599 @item @var{aschar}
33600 If present, indicates that each row should include an @sc{ascii} dump. The
33601 value of @var{aschar} is used as a padding character when a byte is not a
33602 member of the printable @sc{ascii} character set (printable @sc{ascii}
33603 characters are those whose code is between 32 and 126, inclusively).
33604
33605 @item @var{byte-offset}
33606 An offset to add to the @var{address} before fetching memory.
33607 @end table
33608
33609 This command displays memory contents as a table of @var{nr-rows} by
33610 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
33611 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33612 (returned as @samp{total-bytes}). Should less than the requested number
33613 of bytes be returned by the target, the missing words are identified
33614 using @samp{N/A}. The number of bytes read from the target is returned
33615 in @samp{nr-bytes} and the starting address used to read memory in
33616 @samp{addr}.
33617
33618 The address of the next/previous row or page is available in
33619 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
33620 @samp{prev-page}.
33621
33622 @subsubheading @value{GDBN} Command
33623
33624 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33625 @samp{gdb_get_mem} memory read command.
33626
33627 @subsubheading Example
33628
33629 Read six bytes of memory starting at @code{bytes+6} but then offset by
33630 @code{-6} bytes. Format as three rows of two columns. One byte per
33631 word. Display each word in hex.
33632
33633 @smallexample
33634 (gdb)
33635 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
33636 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33637 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33638 prev-page="0x0000138a",memory=[
33639 @{addr="0x00001390",data=["0x00","0x01"]@},
33640 @{addr="0x00001392",data=["0x02","0x03"]@},
33641 @{addr="0x00001394",data=["0x04","0x05"]@}]
33642 (gdb)
33643 @end smallexample
33644
33645 Read two bytes of memory starting at address @code{shorts + 64} and
33646 display as a single word formatted in decimal.
33647
33648 @smallexample
33649 (gdb)
33650 5-data-read-memory shorts+64 d 2 1 1
33651 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33652 next-row="0x00001512",prev-row="0x0000150e",
33653 next-page="0x00001512",prev-page="0x0000150e",memory=[
33654 @{addr="0x00001510",data=["128"]@}]
33655 (gdb)
33656 @end smallexample
33657
33658 Read thirty two bytes of memory starting at @code{bytes+16} and format
33659 as eight rows of four columns. Include a string encoding with @samp{x}
33660 used as the non-printable character.
33661
33662 @smallexample
33663 (gdb)
33664 4-data-read-memory bytes+16 x 1 8 4 x
33665 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33666 next-row="0x000013c0",prev-row="0x0000139c",
33667 next-page="0x000013c0",prev-page="0x00001380",memory=[
33668 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33669 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33670 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33671 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33672 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33673 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33674 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33675 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33676 (gdb)
33677 @end smallexample
33678
33679 @subheading The @code{-data-read-memory-bytes} Command
33680 @findex -data-read-memory-bytes
33681
33682 @subsubheading Synopsis
33683
33684 @smallexample
33685 -data-read-memory-bytes [ -o @var{offset} ]
33686 @var{address} @var{count}
33687 @end smallexample
33688
33689 @noindent
33690 where:
33691
33692 @table @samp
33693 @item @var{address}
33694 An expression specifying the address of the first addressable memory unit
33695 to be read. Complex expressions containing embedded white space should be
33696 quoted using the C convention.
33697
33698 @item @var{count}
33699 The number of addressable memory units to read. This should be an integer
33700 literal.
33701
33702 @item @var{offset}
33703 The offset relative to @var{address} at which to start reading. This
33704 should be an integer literal. This option is provided so that a frontend
33705 is not required to first evaluate address and then perform address
33706 arithmetics itself.
33707
33708 @end table
33709
33710 This command attempts to read all accessible memory regions in the
33711 specified range. First, all regions marked as unreadable in the memory
33712 map (if one is defined) will be skipped. @xref{Memory Region
33713 Attributes}. Second, @value{GDBN} will attempt to read the remaining
33714 regions. For each one, if reading full region results in an errors,
33715 @value{GDBN} will try to read a subset of the region.
33716
33717 In general, every single memory unit in the region may be readable or not,
33718 and the only way to read every readable unit is to try a read at
33719 every address, which is not practical. Therefore, @value{GDBN} will
33720 attempt to read all accessible memory units at either beginning or the end
33721 of the region, using a binary division scheme. This heuristic works
33722 well for reading across a memory map boundary. Note that if a region
33723 has a readable range that is neither at the beginning or the end,
33724 @value{GDBN} will not read it.
33725
33726 The result record (@pxref{GDB/MI Result Records}) that is output of
33727 the command includes a field named @samp{memory} whose content is a
33728 list of tuples. Each tuple represent a successfully read memory block
33729 and has the following fields:
33730
33731 @table @code
33732 @item begin
33733 The start address of the memory block, as hexadecimal literal.
33734
33735 @item end
33736 The end address of the memory block, as hexadecimal literal.
33737
33738 @item offset
33739 The offset of the memory block, as hexadecimal literal, relative to
33740 the start address passed to @code{-data-read-memory-bytes}.
33741
33742 @item contents
33743 The contents of the memory block, in hex.
33744
33745 @end table
33746
33747
33748
33749 @subsubheading @value{GDBN} Command
33750
33751 The corresponding @value{GDBN} command is @samp{x}.
33752
33753 @subsubheading Example
33754
33755 @smallexample
33756 (gdb)
33757 -data-read-memory-bytes &a 10
33758 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33759 end="0xbffff15e",
33760 contents="01000000020000000300"@}]
33761 (gdb)
33762 @end smallexample
33763
33764
33765 @subheading The @code{-data-write-memory-bytes} Command
33766 @findex -data-write-memory-bytes
33767
33768 @subsubheading Synopsis
33769
33770 @smallexample
33771 -data-write-memory-bytes @var{address} @var{contents}
33772 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
33773 @end smallexample
33774
33775 @noindent
33776 where:
33777
33778 @table @samp
33779 @item @var{address}
33780 An expression specifying the address of the first addressable memory unit
33781 to be written. Complex expressions containing embedded white space should
33782 be quoted using the C convention.
33783
33784 @item @var{contents}
33785 The hex-encoded data to write. It is an error if @var{contents} does
33786 not represent an integral number of addressable memory units.
33787
33788 @item @var{count}
33789 Optional argument indicating the number of addressable memory units to be
33790 written. If @var{count} is greater than @var{contents}' length,
33791 @value{GDBN} will repeatedly write @var{contents} until it fills
33792 @var{count} memory units.
33793
33794 @end table
33795
33796 @subsubheading @value{GDBN} Command
33797
33798 There's no corresponding @value{GDBN} command.
33799
33800 @subsubheading Example
33801
33802 @smallexample
33803 (gdb)
33804 -data-write-memory-bytes &a "aabbccdd"
33805 ^done
33806 (gdb)
33807 @end smallexample
33808
33809 @smallexample
33810 (gdb)
33811 -data-write-memory-bytes &a "aabbccdd" 16e
33812 ^done
33813 (gdb)
33814 @end smallexample
33815
33816 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33817 @node GDB/MI Tracepoint Commands
33818 @section @sc{gdb/mi} Tracepoint Commands
33819
33820 The commands defined in this section implement MI support for
33821 tracepoints. For detailed introduction, see @ref{Tracepoints}.
33822
33823 @subheading The @code{-trace-find} Command
33824 @findex -trace-find
33825
33826 @subsubheading Synopsis
33827
33828 @smallexample
33829 -trace-find @var{mode} [@var{parameters}@dots{}]
33830 @end smallexample
33831
33832 Find a trace frame using criteria defined by @var{mode} and
33833 @var{parameters}. The following table lists permissible
33834 modes and their parameters. For details of operation, see @ref{tfind}.
33835
33836 @table @samp
33837
33838 @item none
33839 No parameters are required. Stops examining trace frames.
33840
33841 @item frame-number
33842 An integer is required as parameter. Selects tracepoint frame with
33843 that index.
33844
33845 @item tracepoint-number
33846 An integer is required as parameter. Finds next
33847 trace frame that corresponds to tracepoint with the specified number.
33848
33849 @item pc
33850 An address is required as parameter. Finds
33851 next trace frame that corresponds to any tracepoint at the specified
33852 address.
33853
33854 @item pc-inside-range
33855 Two addresses are required as parameters. Finds next trace
33856 frame that corresponds to a tracepoint at an address inside the
33857 specified range. Both bounds are considered to be inside the range.
33858
33859 @item pc-outside-range
33860 Two addresses are required as parameters. Finds
33861 next trace frame that corresponds to a tracepoint at an address outside
33862 the specified range. Both bounds are considered to be inside the range.
33863
33864 @item line
33865 Line specification is required as parameter. @xref{Specify Location}.
33866 Finds next trace frame that corresponds to a tracepoint at
33867 the specified location.
33868
33869 @end table
33870
33871 If @samp{none} was passed as @var{mode}, the response does not
33872 have fields. Otherwise, the response may have the following fields:
33873
33874 @table @samp
33875 @item found
33876 This field has either @samp{0} or @samp{1} as the value, depending
33877 on whether a matching tracepoint was found.
33878
33879 @item traceframe
33880 The index of the found traceframe. This field is present iff
33881 the @samp{found} field has value of @samp{1}.
33882
33883 @item tracepoint
33884 The index of the found tracepoint. This field is present iff
33885 the @samp{found} field has value of @samp{1}.
33886
33887 @item frame
33888 The information about the frame corresponding to the found trace
33889 frame. This field is present only if a trace frame was found.
33890 @xref{GDB/MI Frame Information}, for description of this field.
33891
33892 @end table
33893
33894 @subsubheading @value{GDBN} Command
33895
33896 The corresponding @value{GDBN} command is @samp{tfind}.
33897
33898 @subheading -trace-define-variable
33899 @findex -trace-define-variable
33900
33901 @subsubheading Synopsis
33902
33903 @smallexample
33904 -trace-define-variable @var{name} [ @var{value} ]
33905 @end smallexample
33906
33907 Create trace variable @var{name} if it does not exist. If
33908 @var{value} is specified, sets the initial value of the specified
33909 trace variable to that value. Note that the @var{name} should start
33910 with the @samp{$} character.
33911
33912 @subsubheading @value{GDBN} Command
33913
33914 The corresponding @value{GDBN} command is @samp{tvariable}.
33915
33916 @subheading The @code{-trace-frame-collected} Command
33917 @findex -trace-frame-collected
33918
33919 @subsubheading Synopsis
33920
33921 @smallexample
33922 -trace-frame-collected
33923 [--var-print-values @var{var_pval}]
33924 [--comp-print-values @var{comp_pval}]
33925 [--registers-format @var{regformat}]
33926 [--memory-contents]
33927 @end smallexample
33928
33929 This command returns the set of collected objects, register names,
33930 trace state variable names, memory ranges and computed expressions
33931 that have been collected at a particular trace frame. The optional
33932 parameters to the command affect the output format in different ways.
33933 See the output description table below for more details.
33934
33935 The reported names can be used in the normal manner to create
33936 varobjs and inspect the objects themselves. The items returned by
33937 this command are categorized so that it is clear which is a variable,
33938 which is a register, which is a trace state variable, which is a
33939 memory range and which is a computed expression.
33940
33941 For instance, if the actions were
33942 @smallexample
33943 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33944 collect *(int*)0xaf02bef0@@40
33945 @end smallexample
33946
33947 @noindent
33948 the object collected in its entirety would be @code{myVar}. The
33949 object @code{myArray} would be partially collected, because only the
33950 element at index @code{myIndex} would be collected. The remaining
33951 objects would be computed expressions.
33952
33953 An example output would be:
33954
33955 @smallexample
33956 (gdb)
33957 -trace-frame-collected
33958 ^done,
33959 explicit-variables=[@{name="myVar",value="1"@}],
33960 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33961 @{name="myObj.field",value="0"@},
33962 @{name="myPtr->field",value="1"@},
33963 @{name="myCount + 2",value="3"@},
33964 @{name="$tvar1 + 1",value="43970027"@}],
33965 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33966 @{number="1",value="0x0"@},
33967 @{number="2",value="0x4"@},
33968 ...
33969 @{number="125",value="0x0"@}],
33970 tvars=[@{name="$tvar1",current="43970026"@}],
33971 memory=[@{address="0x0000000000602264",length="4"@},
33972 @{address="0x0000000000615bc0",length="4"@}]
33973 (gdb)
33974 @end smallexample
33975
33976 Where:
33977
33978 @table @code
33979 @item explicit-variables
33980 The set of objects that have been collected in their entirety (as
33981 opposed to collecting just a few elements of an array or a few struct
33982 members). For each object, its name and value are printed.
33983 The @code{--var-print-values} option affects how or whether the value
33984 field is output. If @var{var_pval} is 0, then print only the names;
33985 if it is 1, print also their values; and if it is 2, print the name,
33986 type and value for simple data types, and the name and type for
33987 arrays, structures and unions.
33988
33989 @item computed-expressions
33990 The set of computed expressions that have been collected at the
33991 current trace frame. The @code{--comp-print-values} option affects
33992 this set like the @code{--var-print-values} option affects the
33993 @code{explicit-variables} set. See above.
33994
33995 @item registers
33996 The registers that have been collected at the current trace frame.
33997 For each register collected, the name and current value are returned.
33998 The value is formatted according to the @code{--registers-format}
33999 option. See the @command{-data-list-register-values} command for a
34000 list of the allowed formats. The default is @samp{x}.
34001
34002 @item tvars
34003 The trace state variables that have been collected at the current
34004 trace frame. For each trace state variable collected, the name and
34005 current value are returned.
34006
34007 @item memory
34008 The set of memory ranges that have been collected at the current trace
34009 frame. Its content is a list of tuples. Each tuple represents a
34010 collected memory range and has the following fields:
34011
34012 @table @code
34013 @item address
34014 The start address of the memory range, as hexadecimal literal.
34015
34016 @item length
34017 The length of the memory range, as decimal literal.
34018
34019 @item contents
34020 The contents of the memory block, in hex. This field is only present
34021 if the @code{--memory-contents} option is specified.
34022
34023 @end table
34024
34025 @end table
34026
34027 @subsubheading @value{GDBN} Command
34028
34029 There is no corresponding @value{GDBN} command.
34030
34031 @subsubheading Example
34032
34033 @subheading -trace-list-variables
34034 @findex -trace-list-variables
34035
34036 @subsubheading Synopsis
34037
34038 @smallexample
34039 -trace-list-variables
34040 @end smallexample
34041
34042 Return a table of all defined trace variables. Each element of the
34043 table has the following fields:
34044
34045 @table @samp
34046 @item name
34047 The name of the trace variable. This field is always present.
34048
34049 @item initial
34050 The initial value. This is a 64-bit signed integer. This
34051 field is always present.
34052
34053 @item current
34054 The value the trace variable has at the moment. This is a 64-bit
34055 signed integer. This field is absent iff current value is
34056 not defined, for example if the trace was never run, or is
34057 presently running.
34058
34059 @end table
34060
34061 @subsubheading @value{GDBN} Command
34062
34063 The corresponding @value{GDBN} command is @samp{tvariables}.
34064
34065 @subsubheading Example
34066
34067 @smallexample
34068 (gdb)
34069 -trace-list-variables
34070 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
34071 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34072 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34073 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34074 body=[variable=@{name="$trace_timestamp",initial="0"@}
34075 variable=@{name="$foo",initial="10",current="15"@}]@}
34076 (gdb)
34077 @end smallexample
34078
34079 @subheading -trace-save
34080 @findex -trace-save
34081
34082 @subsubheading Synopsis
34083
34084 @smallexample
34085 -trace-save [ -r ] [ -ctf ] @var{filename}
34086 @end smallexample
34087
34088 Saves the collected trace data to @var{filename}. Without the
34089 @samp{-r} option, the data is downloaded from the target and saved
34090 in a local file. With the @samp{-r} option the target is asked
34091 to perform the save.
34092
34093 By default, this command will save the trace in the tfile format. You can
34094 supply the optional @samp{-ctf} argument to save it the CTF format. See
34095 @ref{Trace Files} for more information about CTF.
34096
34097 @subsubheading @value{GDBN} Command
34098
34099 The corresponding @value{GDBN} command is @samp{tsave}.
34100
34101
34102 @subheading -trace-start
34103 @findex -trace-start
34104
34105 @subsubheading Synopsis
34106
34107 @smallexample
34108 -trace-start
34109 @end smallexample
34110
34111 Starts a tracing experiment. The result of this command does not
34112 have any fields.
34113
34114 @subsubheading @value{GDBN} Command
34115
34116 The corresponding @value{GDBN} command is @samp{tstart}.
34117
34118 @subheading -trace-status
34119 @findex -trace-status
34120
34121 @subsubheading Synopsis
34122
34123 @smallexample
34124 -trace-status
34125 @end smallexample
34126
34127 Obtains the status of a tracing experiment. The result may include
34128 the following fields:
34129
34130 @table @samp
34131
34132 @item supported
34133 May have a value of either @samp{0}, when no tracing operations are
34134 supported, @samp{1}, when all tracing operations are supported, or
34135 @samp{file} when examining trace file. In the latter case, examining
34136 of trace frame is possible but new tracing experiement cannot be
34137 started. This field is always present.
34138
34139 @item running
34140 May have a value of either @samp{0} or @samp{1} depending on whether
34141 tracing experiement is in progress on target. This field is present
34142 if @samp{supported} field is not @samp{0}.
34143
34144 @item stop-reason
34145 Report the reason why the tracing was stopped last time. This field
34146 may be absent iff tracing was never stopped on target yet. The
34147 value of @samp{request} means the tracing was stopped as result of
34148 the @code{-trace-stop} command. The value of @samp{overflow} means
34149 the tracing buffer is full. The value of @samp{disconnection} means
34150 tracing was automatically stopped when @value{GDBN} has disconnected.
34151 The value of @samp{passcount} means tracing was stopped when a
34152 tracepoint was passed a maximal number of times for that tracepoint.
34153 This field is present if @samp{supported} field is not @samp{0}.
34154
34155 @item stopping-tracepoint
34156 The number of tracepoint whose passcount as exceeded. This field is
34157 present iff the @samp{stop-reason} field has the value of
34158 @samp{passcount}.
34159
34160 @item frames
34161 @itemx frames-created
34162 The @samp{frames} field is a count of the total number of trace frames
34163 in the trace buffer, while @samp{frames-created} is the total created
34164 during the run, including ones that were discarded, such as when a
34165 circular trace buffer filled up. Both fields are optional.
34166
34167 @item buffer-size
34168 @itemx buffer-free
34169 These fields tell the current size of the tracing buffer and the
34170 remaining space. These fields are optional.
34171
34172 @item circular
34173 The value of the circular trace buffer flag. @code{1} means that the
34174 trace buffer is circular and old trace frames will be discarded if
34175 necessary to make room, @code{0} means that the trace buffer is linear
34176 and may fill up.
34177
34178 @item disconnected
34179 The value of the disconnected tracing flag. @code{1} means that
34180 tracing will continue after @value{GDBN} disconnects, @code{0} means
34181 that the trace run will stop.
34182
34183 @item trace-file
34184 The filename of the trace file being examined. This field is
34185 optional, and only present when examining a trace file.
34186
34187 @end table
34188
34189 @subsubheading @value{GDBN} Command
34190
34191 The corresponding @value{GDBN} command is @samp{tstatus}.
34192
34193 @subheading -trace-stop
34194 @findex -trace-stop
34195
34196 @subsubheading Synopsis
34197
34198 @smallexample
34199 -trace-stop
34200 @end smallexample
34201
34202 Stops a tracing experiment. The result of this command has the same
34203 fields as @code{-trace-status}, except that the @samp{supported} and
34204 @samp{running} fields are not output.
34205
34206 @subsubheading @value{GDBN} Command
34207
34208 The corresponding @value{GDBN} command is @samp{tstop}.
34209
34210
34211 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34212 @node GDB/MI Symbol Query
34213 @section @sc{gdb/mi} Symbol Query Commands
34214
34215
34216 @ignore
34217 @subheading The @code{-symbol-info-address} Command
34218 @findex -symbol-info-address
34219
34220 @subsubheading Synopsis
34221
34222 @smallexample
34223 -symbol-info-address @var{symbol}
34224 @end smallexample
34225
34226 Describe where @var{symbol} is stored.
34227
34228 @subsubheading @value{GDBN} Command
34229
34230 The corresponding @value{GDBN} command is @samp{info address}.
34231
34232 @subsubheading Example
34233 N.A.
34234
34235
34236 @subheading The @code{-symbol-info-file} Command
34237 @findex -symbol-info-file
34238
34239 @subsubheading Synopsis
34240
34241 @smallexample
34242 -symbol-info-file
34243 @end smallexample
34244
34245 Show the file for the symbol.
34246
34247 @subsubheading @value{GDBN} Command
34248
34249 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34250 @samp{gdb_find_file}.
34251
34252 @subsubheading Example
34253 N.A.
34254 @end ignore
34255
34256 @subheading The @code{-symbol-info-functions} Command
34257 @findex -symbol-info-functions
34258 @anchor{-symbol-info-functions}
34259
34260 @subsubheading Synopsis
34261
34262 @smallexample
34263 -symbol-info-functions [--include-nondebug]
34264 [--type @var{type_regexp}]
34265 [--name @var{name_regexp}]
34266 [--max-results @var{limit}]
34267 @end smallexample
34268
34269 @noindent
34270 Return a list containing the names and types for all global functions
34271 taken from the debug information. The functions are grouped by source
34272 file, and shown with the line number on which each function is
34273 defined.
34274
34275 The @code{--include-nondebug} option causes the output to include
34276 code symbols from the symbol table.
34277
34278 The options @code{--type} and @code{--name} allow the symbols returned
34279 to be filtered based on either the name of the function, or the type
34280 signature of the function.
34281
34282 The option @code{--max-results} restricts the command to return no
34283 more than @var{limit} results. If exactly @var{limit} results are
34284 returned then there might be additional results available if a higher
34285 limit is used.
34286
34287 @subsubheading @value{GDBN} Command
34288
34289 The corresponding @value{GDBN} command is @samp{info functions}.
34290
34291 @subsubheading Example
34292 @smallexample
34293 @group
34294 (gdb)
34295 -symbol-info-functions
34296 ^done,symbols=
34297 @{debug=
34298 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34299 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34300 symbols=[@{line="36", name="f4", type="void (int *)",
34301 description="void f4(int *);"@},
34302 @{line="42", name="main", type="int ()",
34303 description="int main();"@},
34304 @{line="30", name="f1", type="my_int_t (int, int)",
34305 description="static my_int_t f1(int, int);"@}]@},
34306 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34307 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34308 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34309 description="float f2(another_float_t);"@},
34310 @{line="39", name="f3", type="int (another_int_t)",
34311 description="int f3(another_int_t);"@},
34312 @{line="27", name="f1", type="another_float_t (int)",
34313 description="static another_float_t f1(int);"@}]@}]@}
34314 @end group
34315 @group
34316 (gdb)
34317 -symbol-info-functions --name f1
34318 ^done,symbols=
34319 @{debug=
34320 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34321 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34322 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34323 description="static my_int_t f1(int, int);"@}]@},
34324 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34325 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34326 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34327 description="static another_float_t f1(int);"@}]@}]@}
34328 @end group
34329 @group
34330 (gdb)
34331 -symbol-info-functions --type void
34332 ^done,symbols=
34333 @{debug=
34334 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34335 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34336 symbols=[@{line="36", name="f4", type="void (int *)",
34337 description="void f4(int *);"@}]@}]@}
34338 @end group
34339 @group
34340 (gdb)
34341 -symbol-info-functions --include-nondebug
34342 ^done,symbols=
34343 @{debug=
34344 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34345 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34346 symbols=[@{line="36", name="f4", type="void (int *)",
34347 description="void f4(int *);"@},
34348 @{line="42", name="main", type="int ()",
34349 description="int main();"@},
34350 @{line="30", name="f1", type="my_int_t (int, int)",
34351 description="static my_int_t f1(int, int);"@}]@},
34352 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34353 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34354 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34355 description="float f2(another_float_t);"@},
34356 @{line="39", name="f3", type="int (another_int_t)",
34357 description="int f3(another_int_t);"@},
34358 @{line="27", name="f1", type="another_float_t (int)",
34359 description="static another_float_t f1(int);"@}]@}],
34360 nondebug=
34361 [@{address="0x0000000000400398",name="_init"@},
34362 @{address="0x00000000004003b0",name="_start"@},
34363 ...
34364 ]@}
34365 @end group
34366 @end smallexample
34367
34368 @subheading The @code{-symbol-info-module-functions} Command
34369 @findex -symbol-info-module-functions
34370 @anchor{-symbol-info-module-functions}
34371
34372 @subsubheading Synopsis
34373
34374 @smallexample
34375 -symbol-info-module-functions [--module @var{module_regexp}]
34376 [--name @var{name_regexp}]
34377 [--type @var{type_regexp}]
34378 @end smallexample
34379
34380 @noindent
34381 Return a list containing the names of all known functions within all
34382 know Fortran modules. The functions are grouped by source file and
34383 containing module, and shown with the line number on which each
34384 function is defined.
34385
34386 The option @code{--module} only returns results for modules matching
34387 @var{module_regexp}. The option @code{--name} only returns functions
34388 whose name matches @var{name_regexp}, and @code{--type} only returns
34389 functions whose type matches @var{type_regexp}.
34390
34391 @subsubheading @value{GDBN} Command
34392
34393 The corresponding @value{GDBN} command is @samp{info module functions}.
34394
34395 @subsubheading Example
34396
34397 @smallexample
34398 @group
34399 (gdb)
34400 -symbol-info-module-functions
34401 ^done,symbols=
34402 [@{module="mod1",
34403 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34404 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34405 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34406 description="void mod1::check_all(void);"@}]@}]@},
34407 @{module="mod2",
34408 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34409 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34410 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34411 description="void mod2::check_var_i(void);"@}]@}]@},
34412 @{module="mod3",
34413 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34414 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34415 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34416 description="void mod3::check_all(void);"@},
34417 @{line="27",name="mod3::check_mod2",type="void (void)",
34418 description="void mod3::check_mod2(void);"@}]@}]@},
34419 @{module="modmany",
34420 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34421 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34422 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34423 description="void modmany::check_some(void);"@}]@}]@},
34424 @{module="moduse",
34425 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34426 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34427 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34428 description="void moduse::check_all(void);"@},
34429 @{line="49",name="moduse::check_var_x",type="void (void)",
34430 description="void moduse::check_var_x(void);"@}]@}]@}]
34431 @end group
34432 @end smallexample
34433
34434 @subheading The @code{-symbol-info-module-variables} Command
34435 @findex -symbol-info-module-variables
34436 @anchor{-symbol-info-module-variables}
34437
34438 @subsubheading Synopsis
34439
34440 @smallexample
34441 -symbol-info-module-variables [--module @var{module_regexp}]
34442 [--name @var{name_regexp}]
34443 [--type @var{type_regexp}]
34444 @end smallexample
34445
34446 @noindent
34447 Return a list containing the names of all known variables within all
34448 know Fortran modules. The variables are grouped by source file and
34449 containing module, and shown with the line number on which each
34450 variable is defined.
34451
34452 The option @code{--module} only returns results for modules matching
34453 @var{module_regexp}. The option @code{--name} only returns variables
34454 whose name matches @var{name_regexp}, and @code{--type} only returns
34455 variables whose type matches @var{type_regexp}.
34456
34457 @subsubheading @value{GDBN} Command
34458
34459 The corresponding @value{GDBN} command is @samp{info module variables}.
34460
34461 @subsubheading Example
34462
34463 @smallexample
34464 @group
34465 (gdb)
34466 -symbol-info-module-variables
34467 ^done,symbols=
34468 [@{module="mod1",
34469 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34470 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34471 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34472 description="integer(kind=4) mod1::var_const;"@},
34473 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34474 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34475 @{module="mod2",
34476 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34477 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34478 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34479 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34480 @{module="mod3",
34481 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34482 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34483 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34484 description="integer(kind=4) mod3::mod1;"@},
34485 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34486 description="integer(kind=4) mod3::mod2;"@},
34487 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34488 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34489 @{module="modmany",
34490 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34491 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34492 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34493 description="integer(kind=4) modmany::var_a;"@},
34494 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34495 description="integer(kind=4) modmany::var_b;"@},
34496 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34497 description="integer(kind=4) modmany::var_c;"@},
34498 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34499 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34500 @{module="moduse",
34501 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34502 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34503 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34504 description="integer(kind=4) moduse::var_x;"@},
34505 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34506 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34507 @end group
34508 @end smallexample
34509
34510 @subheading The @code{-symbol-info-modules} Command
34511 @findex -symbol-info-modules
34512 @anchor{-symbol-info-modules}
34513
34514 @subsubheading Synopsis
34515
34516 @smallexample
34517 -symbol-info-modules [--name @var{name_regexp}]
34518 [--max-results @var{limit}]
34519
34520 @end smallexample
34521
34522 @noindent
34523 Return a list containing the names of all known Fortran modules. The
34524 modules are grouped by source file, and shown with the line number on
34525 which each modules is defined.
34526
34527 The option @code{--name} allows the modules returned to be filtered
34528 based the name of the module.
34529
34530 The option @code{--max-results} restricts the command to return no
34531 more than @var{limit} results. If exactly @var{limit} results are
34532 returned then there might be additional results available if a higher
34533 limit is used.
34534
34535 @subsubheading @value{GDBN} Command
34536
34537 The corresponding @value{GDBN} command is @samp{info modules}.
34538
34539 @subsubheading Example
34540 @smallexample
34541 @group
34542 (gdb)
34543 -symbol-info-modules
34544 ^done,symbols=
34545 @{debug=
34546 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34547 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34548 symbols=[@{line="16",name="mod1"@},
34549 @{line="22",name="mod2"@}]@},
34550 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34551 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34552 symbols=[@{line="16",name="mod3"@},
34553 @{line="22",name="modmany"@},
34554 @{line="26",name="moduse"@}]@}]@}
34555 @end group
34556 @group
34557 (gdb)
34558 -symbol-info-modules --name mod[123]
34559 ^done,symbols=
34560 @{debug=
34561 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34562 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34563 symbols=[@{line="16",name="mod1"@},
34564 @{line="22",name="mod2"@}]@},
34565 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34566 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34567 symbols=[@{line="16",name="mod3"@}]@}]@}
34568 @end group
34569 @end smallexample
34570
34571 @subheading The @code{-symbol-info-types} Command
34572 @findex -symbol-info-types
34573 @anchor{-symbol-info-types}
34574
34575 @subsubheading Synopsis
34576
34577 @smallexample
34578 -symbol-info-types [--name @var{name_regexp}]
34579 [--max-results @var{limit}]
34580
34581 @end smallexample
34582
34583 @noindent
34584 Return a list of all defined types. The types are grouped by source
34585 file, and shown with the line number on which each user defined type
34586 is defined. Some base types are not defined in the source code but
34587 are added to the debug information by the compiler, for example
34588 @code{int}, @code{float}, etc.; these types do not have an associated
34589 line number.
34590
34591 The option @code{--name} allows the list of types returned to be
34592 filtered by name.
34593
34594 The option @code{--max-results} restricts the command to return no
34595 more than @var{limit} results. If exactly @var{limit} results are
34596 returned then there might be additional results available if a higher
34597 limit is used.
34598
34599 @subsubheading @value{GDBN} Command
34600
34601 The corresponding @value{GDBN} command is @samp{info types}.
34602
34603 @subsubheading Example
34604 @smallexample
34605 @group
34606 (gdb)
34607 -symbol-info-types
34608 ^done,symbols=
34609 @{debug=
34610 [@{filename="gdb.mi/mi-sym-info-1.c",
34611 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34612 symbols=[@{name="float"@},
34613 @{name="int"@},
34614 @{line="27",name="typedef int my_int_t;"@}]@},
34615 @{filename="gdb.mi/mi-sym-info-2.c",
34616 fullname="/project/gdb.mi/mi-sym-info-2.c",
34617 symbols=[@{line="24",name="typedef float another_float_t;"@},
34618 @{line="23",name="typedef int another_int_t;"@},
34619 @{name="float"@},
34620 @{name="int"@}]@}]@}
34621 @end group
34622 @group
34623 (gdb)
34624 -symbol-info-types --name _int_
34625 ^done,symbols=
34626 @{debug=
34627 [@{filename="gdb.mi/mi-sym-info-1.c",
34628 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34629 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34630 @{filename="gdb.mi/mi-sym-info-2.c",
34631 fullname="/project/gdb.mi/mi-sym-info-2.c",
34632 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34633 @end group
34634 @end smallexample
34635
34636 @subheading The @code{-symbol-info-variables} Command
34637 @findex -symbol-info-variables
34638 @anchor{-symbol-info-variables}
34639
34640 @subsubheading Synopsis
34641
34642 @smallexample
34643 -symbol-info-variables [--include-nondebug]
34644 [--type @var{type_regexp}]
34645 [--name @var{name_regexp}]
34646 [--max-results @var{limit}]
34647
34648 @end smallexample
34649
34650 @noindent
34651 Return a list containing the names and types for all global variables
34652 taken from the debug information. The variables are grouped by source
34653 file, and shown with the line number on which each variable is
34654 defined.
34655
34656 The @code{--include-nondebug} option causes the output to include
34657 data symbols from the symbol table.
34658
34659 The options @code{--type} and @code{--name} allow the symbols returned
34660 to be filtered based on either the name of the variable, or the type
34661 of the variable.
34662
34663 The option @code{--max-results} restricts the command to return no
34664 more than @var{limit} results. If exactly @var{limit} results are
34665 returned then there might be additional results available if a higher
34666 limit is used.
34667
34668 @subsubheading @value{GDBN} Command
34669
34670 The corresponding @value{GDBN} command is @samp{info variables}.
34671
34672 @subsubheading Example
34673 @smallexample
34674 @group
34675 (gdb)
34676 -symbol-info-variables
34677 ^done,symbols=
34678 @{debug=
34679 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34680 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34681 symbols=[@{line="25",name="global_f1",type="float",
34682 description="static float global_f1;"@},
34683 @{line="24",name="global_i1",type="int",
34684 description="static int global_i1;"@}]@},
34685 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34686 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34687 symbols=[@{line="21",name="global_f2",type="int",
34688 description="int global_f2;"@},
34689 @{line="20",name="global_i2",type="int",
34690 description="int global_i2;"@},
34691 @{line="19",name="global_f1",type="float",
34692 description="static float global_f1;"@},
34693 @{line="18",name="global_i1",type="int",
34694 description="static int global_i1;"@}]@}]@}
34695 @end group
34696 @group
34697 (gdb)
34698 -symbol-info-variables --name f1
34699 ^done,symbols=
34700 @{debug=
34701 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34702 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34703 symbols=[@{line="25",name="global_f1",type="float",
34704 description="static float global_f1;"@}]@},
34705 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34706 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34707 symbols=[@{line="19",name="global_f1",type="float",
34708 description="static float global_f1;"@}]@}]@}
34709 @end group
34710 @group
34711 (gdb)
34712 -symbol-info-variables --type float
34713 ^done,symbols=
34714 @{debug=
34715 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34716 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34717 symbols=[@{line="25",name="global_f1",type="float",
34718 description="static float global_f1;"@}]@},
34719 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34720 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34721 symbols=[@{line="19",name="global_f1",type="float",
34722 description="static float global_f1;"@}]@}]@}
34723 @end group
34724 @group
34725 (gdb)
34726 -symbol-info-variables --include-nondebug
34727 ^done,symbols=
34728 @{debug=
34729 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34730 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34731 symbols=[@{line="25",name="global_f1",type="float",
34732 description="static float global_f1;"@},
34733 @{line="24",name="global_i1",type="int",
34734 description="static int global_i1;"@}]@},
34735 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34736 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34737 symbols=[@{line="21",name="global_f2",type="int",
34738 description="int global_f2;"@},
34739 @{line="20",name="global_i2",type="int",
34740 description="int global_i2;"@},
34741 @{line="19",name="global_f1",type="float",
34742 description="static float global_f1;"@},
34743 @{line="18",name="global_i1",type="int",
34744 description="static int global_i1;"@}]@}],
34745 nondebug=
34746 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34747 @{address="0x00000000004005d8",name="__dso_handle"@}
34748 ...
34749 ]@}
34750 @end group
34751 @end smallexample
34752
34753 @ignore
34754 @subheading The @code{-symbol-info-line} Command
34755 @findex -symbol-info-line
34756
34757 @subsubheading Synopsis
34758
34759 @smallexample
34760 -symbol-info-line
34761 @end smallexample
34762
34763 Show the core addresses of the code for a source line.
34764
34765 @subsubheading @value{GDBN} Command
34766
34767 The corresponding @value{GDBN} command is @samp{info line}.
34768 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
34769
34770 @subsubheading Example
34771 N.A.
34772
34773
34774 @subheading The @code{-symbol-info-symbol} Command
34775 @findex -symbol-info-symbol
34776
34777 @subsubheading Synopsis
34778
34779 @smallexample
34780 -symbol-info-symbol @var{addr}
34781 @end smallexample
34782
34783 Describe what symbol is at location @var{addr}.
34784
34785 @subsubheading @value{GDBN} Command
34786
34787 The corresponding @value{GDBN} command is @samp{info symbol}.
34788
34789 @subsubheading Example
34790 N.A.
34791
34792
34793 @subheading The @code{-symbol-list-functions} Command
34794 @findex -symbol-list-functions
34795
34796 @subsubheading Synopsis
34797
34798 @smallexample
34799 -symbol-list-functions
34800 @end smallexample
34801
34802 List the functions in the executable.
34803
34804 @subsubheading @value{GDBN} Command
34805
34806 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34807 @samp{gdb_search} in @code{gdbtk}.
34808
34809 @subsubheading Example
34810 N.A.
34811 @end ignore
34812
34813
34814 @subheading The @code{-symbol-list-lines} Command
34815 @findex -symbol-list-lines
34816
34817 @subsubheading Synopsis
34818
34819 @smallexample
34820 -symbol-list-lines @var{filename}
34821 @end smallexample
34822
34823 Print the list of lines that contain code and their associated program
34824 addresses for the given source filename. The entries are sorted in
34825 ascending PC order.
34826
34827 @subsubheading @value{GDBN} Command
34828
34829 There is no corresponding @value{GDBN} command.
34830
34831 @subsubheading Example
34832 @smallexample
34833 (gdb)
34834 -symbol-list-lines basics.c
34835 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
34836 (gdb)
34837 @end smallexample
34838
34839
34840 @ignore
34841 @subheading The @code{-symbol-list-types} Command
34842 @findex -symbol-list-types
34843
34844 @subsubheading Synopsis
34845
34846 @smallexample
34847 -symbol-list-types
34848 @end smallexample
34849
34850 List all the type names.
34851
34852 @subsubheading @value{GDBN} Command
34853
34854 The corresponding commands are @samp{info types} in @value{GDBN},
34855 @samp{gdb_search} in @code{gdbtk}.
34856
34857 @subsubheading Example
34858 N.A.
34859
34860
34861 @subheading The @code{-symbol-list-variables} Command
34862 @findex -symbol-list-variables
34863
34864 @subsubheading Synopsis
34865
34866 @smallexample
34867 -symbol-list-variables
34868 @end smallexample
34869
34870 List all the global and static variable names.
34871
34872 @subsubheading @value{GDBN} Command
34873
34874 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
34875
34876 @subsubheading Example
34877 N.A.
34878
34879
34880 @subheading The @code{-symbol-locate} Command
34881 @findex -symbol-locate
34882
34883 @subsubheading Synopsis
34884
34885 @smallexample
34886 -symbol-locate
34887 @end smallexample
34888
34889 @subsubheading @value{GDBN} Command
34890
34891 @samp{gdb_loc} in @code{gdbtk}.
34892
34893 @subsubheading Example
34894 N.A.
34895
34896
34897 @subheading The @code{-symbol-type} Command
34898 @findex -symbol-type
34899
34900 @subsubheading Synopsis
34901
34902 @smallexample
34903 -symbol-type @var{variable}
34904 @end smallexample
34905
34906 Show type of @var{variable}.
34907
34908 @subsubheading @value{GDBN} Command
34909
34910 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34911 @samp{gdb_obj_variable}.
34912
34913 @subsubheading Example
34914 N.A.
34915 @end ignore
34916
34917
34918 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34919 @node GDB/MI File Commands
34920 @section @sc{gdb/mi} File Commands
34921
34922 This section describes the GDB/MI commands to specify executable file names
34923 and to read in and obtain symbol table information.
34924
34925 @subheading The @code{-file-exec-and-symbols} Command
34926 @findex -file-exec-and-symbols
34927
34928 @subsubheading Synopsis
34929
34930 @smallexample
34931 -file-exec-and-symbols @var{file}
34932 @end smallexample
34933
34934 Specify the executable file to be debugged. This file is the one from
34935 which the symbol table is also read. If no file is specified, the
34936 command clears the executable and symbol information. If breakpoints
34937 are set when using this command with no arguments, @value{GDBN} will produce
34938 error messages. Otherwise, no output is produced, except a completion
34939 notification.
34940
34941 @subsubheading @value{GDBN} Command
34942
34943 The corresponding @value{GDBN} command is @samp{file}.
34944
34945 @subsubheading Example
34946
34947 @smallexample
34948 (gdb)
34949 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34950 ^done
34951 (gdb)
34952 @end smallexample
34953
34954
34955 @subheading The @code{-file-exec-file} Command
34956 @findex -file-exec-file
34957
34958 @subsubheading Synopsis
34959
34960 @smallexample
34961 -file-exec-file @var{file}
34962 @end smallexample
34963
34964 Specify the executable file to be debugged. Unlike
34965 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34966 from this file. If used without argument, @value{GDBN} clears the information
34967 about the executable file. No output is produced, except a completion
34968 notification.
34969
34970 @subsubheading @value{GDBN} Command
34971
34972 The corresponding @value{GDBN} command is @samp{exec-file}.
34973
34974 @subsubheading Example
34975
34976 @smallexample
34977 (gdb)
34978 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34979 ^done
34980 (gdb)
34981 @end smallexample
34982
34983
34984 @ignore
34985 @subheading The @code{-file-list-exec-sections} Command
34986 @findex -file-list-exec-sections
34987
34988 @subsubheading Synopsis
34989
34990 @smallexample
34991 -file-list-exec-sections
34992 @end smallexample
34993
34994 List the sections of the current executable file.
34995
34996 @subsubheading @value{GDBN} Command
34997
34998 The @value{GDBN} command @samp{info file} shows, among the rest, the same
34999 information as this command. @code{gdbtk} has a corresponding command
35000 @samp{gdb_load_info}.
35001
35002 @subsubheading Example
35003 N.A.
35004 @end ignore
35005
35006
35007 @subheading The @code{-file-list-exec-source-file} Command
35008 @findex -file-list-exec-source-file
35009
35010 @subsubheading Synopsis
35011
35012 @smallexample
35013 -file-list-exec-source-file
35014 @end smallexample
35015
35016 List the line number, the current source file, and the absolute path
35017 to the current source file for the current executable. The macro
35018 information field has a value of @samp{1} or @samp{0} depending on
35019 whether or not the file includes preprocessor macro information.
35020
35021 @subsubheading @value{GDBN} Command
35022
35023 The @value{GDBN} equivalent is @samp{info source}
35024
35025 @subsubheading Example
35026
35027 @smallexample
35028 (gdb)
35029 123-file-list-exec-source-file
35030 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35031 (gdb)
35032 @end smallexample
35033
35034
35035 @subheading The @code{-file-list-exec-source-files} Command
35036 @findex -file-list-exec-source-files
35037
35038 @subsubheading Synopsis
35039
35040 @smallexample
35041 -file-list-exec-source-files
35042 @end smallexample
35043
35044 List the source files for the current executable.
35045
35046 It will always output both the filename and fullname (absolute file
35047 name) of a source file.
35048
35049 @subsubheading @value{GDBN} Command
35050
35051 The @value{GDBN} equivalent is @samp{info sources}.
35052 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35053
35054 @subsubheading Example
35055 @smallexample
35056 (gdb)
35057 -file-list-exec-source-files
35058 ^done,files=[
35059 @{file=foo.c,fullname=/home/foo.c@},
35060 @{file=/home/bar.c,fullname=/home/bar.c@},
35061 @{file=gdb_could_not_find_fullpath.c@}]
35062 (gdb)
35063 @end smallexample
35064
35065 @subheading The @code{-file-list-shared-libraries} Command
35066 @findex -file-list-shared-libraries
35067
35068 @subsubheading Synopsis
35069
35070 @smallexample
35071 -file-list-shared-libraries [ @var{regexp} ]
35072 @end smallexample
35073
35074 List the shared libraries in the program.
35075 With a regular expression @var{regexp}, only those libraries whose
35076 names match @var{regexp} are listed.
35077
35078 @subsubheading @value{GDBN} Command
35079
35080 The corresponding @value{GDBN} command is @samp{info shared}. The fields
35081 have a similar meaning to the @code{=library-loaded} notification.
35082 The @code{ranges} field specifies the multiple segments belonging to this
35083 library. Each range has the following fields:
35084
35085 @table @samp
35086 @item from
35087 The address defining the inclusive lower bound of the segment.
35088 @item to
35089 The address defining the exclusive upper bound of the segment.
35090 @end table
35091
35092 @subsubheading Example
35093 @smallexample
35094 (gdb)
35095 -file-list-exec-source-files
35096 ^done,shared-libraries=[
35097 @{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"@}]@},
35098 @{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"@}]@}]
35099 (gdb)
35100 @end smallexample
35101
35102
35103 @ignore
35104 @subheading The @code{-file-list-symbol-files} Command
35105 @findex -file-list-symbol-files
35106
35107 @subsubheading Synopsis
35108
35109 @smallexample
35110 -file-list-symbol-files
35111 @end smallexample
35112
35113 List symbol files.
35114
35115 @subsubheading @value{GDBN} Command
35116
35117 The corresponding @value{GDBN} command is @samp{info file} (part of it).
35118
35119 @subsubheading Example
35120 N.A.
35121 @end ignore
35122
35123
35124 @subheading The @code{-file-symbol-file} Command
35125 @findex -file-symbol-file
35126
35127 @subsubheading Synopsis
35128
35129 @smallexample
35130 -file-symbol-file @var{file}
35131 @end smallexample
35132
35133 Read symbol table info from the specified @var{file} argument. When
35134 used without arguments, clears @value{GDBN}'s symbol table info. No output is
35135 produced, except for a completion notification.
35136
35137 @subsubheading @value{GDBN} Command
35138
35139 The corresponding @value{GDBN} command is @samp{symbol-file}.
35140
35141 @subsubheading Example
35142
35143 @smallexample
35144 (gdb)
35145 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35146 ^done
35147 (gdb)
35148 @end smallexample
35149
35150 @ignore
35151 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35152 @node GDB/MI Memory Overlay Commands
35153 @section @sc{gdb/mi} Memory Overlay Commands
35154
35155 The memory overlay commands are not implemented.
35156
35157 @c @subheading -overlay-auto
35158
35159 @c @subheading -overlay-list-mapping-state
35160
35161 @c @subheading -overlay-list-overlays
35162
35163 @c @subheading -overlay-map
35164
35165 @c @subheading -overlay-off
35166
35167 @c @subheading -overlay-on
35168
35169 @c @subheading -overlay-unmap
35170
35171 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35172 @node GDB/MI Signal Handling Commands
35173 @section @sc{gdb/mi} Signal Handling Commands
35174
35175 Signal handling commands are not implemented.
35176
35177 @c @subheading -signal-handle
35178
35179 @c @subheading -signal-list-handle-actions
35180
35181 @c @subheading -signal-list-signal-types
35182 @end ignore
35183
35184
35185 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35186 @node GDB/MI Target Manipulation
35187 @section @sc{gdb/mi} Target Manipulation Commands
35188
35189
35190 @subheading The @code{-target-attach} Command
35191 @findex -target-attach
35192
35193 @subsubheading Synopsis
35194
35195 @smallexample
35196 -target-attach @var{pid} | @var{gid} | @var{file}
35197 @end smallexample
35198
35199 Attach to a process @var{pid} or a file @var{file} outside of
35200 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35201 group, the id previously returned by
35202 @samp{-list-thread-groups --available} must be used.
35203
35204 @subsubheading @value{GDBN} Command
35205
35206 The corresponding @value{GDBN} command is @samp{attach}.
35207
35208 @subsubheading Example
35209 @smallexample
35210 (gdb)
35211 -target-attach 34
35212 =thread-created,id="1"
35213 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35214 ^done
35215 (gdb)
35216 @end smallexample
35217
35218 @ignore
35219 @subheading The @code{-target-compare-sections} Command
35220 @findex -target-compare-sections
35221
35222 @subsubheading Synopsis
35223
35224 @smallexample
35225 -target-compare-sections [ @var{section} ]
35226 @end smallexample
35227
35228 Compare data of section @var{section} on target to the exec file.
35229 Without the argument, all sections are compared.
35230
35231 @subsubheading @value{GDBN} Command
35232
35233 The @value{GDBN} equivalent is @samp{compare-sections}.
35234
35235 @subsubheading Example
35236 N.A.
35237 @end ignore
35238
35239
35240 @subheading The @code{-target-detach} Command
35241 @findex -target-detach
35242
35243 @subsubheading Synopsis
35244
35245 @smallexample
35246 -target-detach [ @var{pid} | @var{gid} ]
35247 @end smallexample
35248
35249 Detach from the remote target which normally resumes its execution.
35250 If either @var{pid} or @var{gid} is specified, detaches from either
35251 the specified process, or specified thread group. There's no output.
35252
35253 @subsubheading @value{GDBN} Command
35254
35255 The corresponding @value{GDBN} command is @samp{detach}.
35256
35257 @subsubheading Example
35258
35259 @smallexample
35260 (gdb)
35261 -target-detach
35262 ^done
35263 (gdb)
35264 @end smallexample
35265
35266
35267 @subheading The @code{-target-disconnect} Command
35268 @findex -target-disconnect
35269
35270 @subsubheading Synopsis
35271
35272 @smallexample
35273 -target-disconnect
35274 @end smallexample
35275
35276 Disconnect from the remote target. There's no output and the target is
35277 generally not resumed.
35278
35279 @subsubheading @value{GDBN} Command
35280
35281 The corresponding @value{GDBN} command is @samp{disconnect}.
35282
35283 @subsubheading Example
35284
35285 @smallexample
35286 (gdb)
35287 -target-disconnect
35288 ^done
35289 (gdb)
35290 @end smallexample
35291
35292
35293 @subheading The @code{-target-download} Command
35294 @findex -target-download
35295
35296 @subsubheading Synopsis
35297
35298 @smallexample
35299 -target-download
35300 @end smallexample
35301
35302 Loads the executable onto the remote target.
35303 It prints out an update message every half second, which includes the fields:
35304
35305 @table @samp
35306 @item section
35307 The name of the section.
35308 @item section-sent
35309 The size of what has been sent so far for that section.
35310 @item section-size
35311 The size of the section.
35312 @item total-sent
35313 The total size of what was sent so far (the current and the previous sections).
35314 @item total-size
35315 The size of the overall executable to download.
35316 @end table
35317
35318 @noindent
35319 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35320 @sc{gdb/mi} Output Syntax}).
35321
35322 In addition, it prints the name and size of the sections, as they are
35323 downloaded. These messages include the following fields:
35324
35325 @table @samp
35326 @item section
35327 The name of the section.
35328 @item section-size
35329 The size of the section.
35330 @item total-size
35331 The size of the overall executable to download.
35332 @end table
35333
35334 @noindent
35335 At the end, a summary is printed.
35336
35337 @subsubheading @value{GDBN} Command
35338
35339 The corresponding @value{GDBN} command is @samp{load}.
35340
35341 @subsubheading Example
35342
35343 Note: each status message appears on a single line. Here the messages
35344 have been broken down so that they can fit onto a page.
35345
35346 @smallexample
35347 (gdb)
35348 -target-download
35349 +download,@{section=".text",section-size="6668",total-size="9880"@}
35350 +download,@{section=".text",section-sent="512",section-size="6668",
35351 total-sent="512",total-size="9880"@}
35352 +download,@{section=".text",section-sent="1024",section-size="6668",
35353 total-sent="1024",total-size="9880"@}
35354 +download,@{section=".text",section-sent="1536",section-size="6668",
35355 total-sent="1536",total-size="9880"@}
35356 +download,@{section=".text",section-sent="2048",section-size="6668",
35357 total-sent="2048",total-size="9880"@}
35358 +download,@{section=".text",section-sent="2560",section-size="6668",
35359 total-sent="2560",total-size="9880"@}
35360 +download,@{section=".text",section-sent="3072",section-size="6668",
35361 total-sent="3072",total-size="9880"@}
35362 +download,@{section=".text",section-sent="3584",section-size="6668",
35363 total-sent="3584",total-size="9880"@}
35364 +download,@{section=".text",section-sent="4096",section-size="6668",
35365 total-sent="4096",total-size="9880"@}
35366 +download,@{section=".text",section-sent="4608",section-size="6668",
35367 total-sent="4608",total-size="9880"@}
35368 +download,@{section=".text",section-sent="5120",section-size="6668",
35369 total-sent="5120",total-size="9880"@}
35370 +download,@{section=".text",section-sent="5632",section-size="6668",
35371 total-sent="5632",total-size="9880"@}
35372 +download,@{section=".text",section-sent="6144",section-size="6668",
35373 total-sent="6144",total-size="9880"@}
35374 +download,@{section=".text",section-sent="6656",section-size="6668",
35375 total-sent="6656",total-size="9880"@}
35376 +download,@{section=".init",section-size="28",total-size="9880"@}
35377 +download,@{section=".fini",section-size="28",total-size="9880"@}
35378 +download,@{section=".data",section-size="3156",total-size="9880"@}
35379 +download,@{section=".data",section-sent="512",section-size="3156",
35380 total-sent="7236",total-size="9880"@}
35381 +download,@{section=".data",section-sent="1024",section-size="3156",
35382 total-sent="7748",total-size="9880"@}
35383 +download,@{section=".data",section-sent="1536",section-size="3156",
35384 total-sent="8260",total-size="9880"@}
35385 +download,@{section=".data",section-sent="2048",section-size="3156",
35386 total-sent="8772",total-size="9880"@}
35387 +download,@{section=".data",section-sent="2560",section-size="3156",
35388 total-sent="9284",total-size="9880"@}
35389 +download,@{section=".data",section-sent="3072",section-size="3156",
35390 total-sent="9796",total-size="9880"@}
35391 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35392 write-rate="429"
35393 (gdb)
35394 @end smallexample
35395
35396
35397 @ignore
35398 @subheading The @code{-target-exec-status} Command
35399 @findex -target-exec-status
35400
35401 @subsubheading Synopsis
35402
35403 @smallexample
35404 -target-exec-status
35405 @end smallexample
35406
35407 Provide information on the state of the target (whether it is running or
35408 not, for instance).
35409
35410 @subsubheading @value{GDBN} Command
35411
35412 There's no equivalent @value{GDBN} command.
35413
35414 @subsubheading Example
35415 N.A.
35416
35417
35418 @subheading The @code{-target-list-available-targets} Command
35419 @findex -target-list-available-targets
35420
35421 @subsubheading Synopsis
35422
35423 @smallexample
35424 -target-list-available-targets
35425 @end smallexample
35426
35427 List the possible targets to connect to.
35428
35429 @subsubheading @value{GDBN} Command
35430
35431 The corresponding @value{GDBN} command is @samp{help target}.
35432
35433 @subsubheading Example
35434 N.A.
35435
35436
35437 @subheading The @code{-target-list-current-targets} Command
35438 @findex -target-list-current-targets
35439
35440 @subsubheading Synopsis
35441
35442 @smallexample
35443 -target-list-current-targets
35444 @end smallexample
35445
35446 Describe the current target.
35447
35448 @subsubheading @value{GDBN} Command
35449
35450 The corresponding information is printed by @samp{info file} (among
35451 other things).
35452
35453 @subsubheading Example
35454 N.A.
35455
35456
35457 @subheading The @code{-target-list-parameters} Command
35458 @findex -target-list-parameters
35459
35460 @subsubheading Synopsis
35461
35462 @smallexample
35463 -target-list-parameters
35464 @end smallexample
35465
35466 @c ????
35467 @end ignore
35468
35469 @subsubheading @value{GDBN} Command
35470
35471 No equivalent.
35472
35473 @subsubheading Example
35474 N.A.
35475
35476 @subheading The @code{-target-flash-erase} Command
35477 @findex -target-flash-erase
35478
35479 @subsubheading Synopsis
35480
35481 @smallexample
35482 -target-flash-erase
35483 @end smallexample
35484
35485 Erases all known flash memory regions on the target.
35486
35487 The corresponding @value{GDBN} command is @samp{flash-erase}.
35488
35489 The output is a list of flash regions that have been erased, with starting
35490 addresses and memory region sizes.
35491
35492 @smallexample
35493 (gdb)
35494 -target-flash-erase
35495 ^done,erased-regions=@{address="0x0",size="0x40000"@}
35496 (gdb)
35497 @end smallexample
35498
35499 @subheading The @code{-target-select} Command
35500 @findex -target-select
35501
35502 @subsubheading Synopsis
35503
35504 @smallexample
35505 -target-select @var{type} @var{parameters @dots{}}
35506 @end smallexample
35507
35508 Connect @value{GDBN} to the remote target. This command takes two args:
35509
35510 @table @samp
35511 @item @var{type}
35512 The type of target, for instance @samp{remote}, etc.
35513 @item @var{parameters}
35514 Device names, host names and the like. @xref{Target Commands, ,
35515 Commands for Managing Targets}, for more details.
35516 @end table
35517
35518 The output is a connection notification, followed by the address at
35519 which the target program is, in the following form:
35520
35521 @smallexample
35522 ^connected,addr="@var{address}",func="@var{function name}",
35523 args=[@var{arg list}]
35524 @end smallexample
35525
35526 @subsubheading @value{GDBN} Command
35527
35528 The corresponding @value{GDBN} command is @samp{target}.
35529
35530 @subsubheading Example
35531
35532 @smallexample
35533 (gdb)
35534 -target-select remote /dev/ttya
35535 ^connected,addr="0xfe00a300",func="??",args=[]
35536 (gdb)
35537 @end smallexample
35538
35539 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35540 @node GDB/MI File Transfer Commands
35541 @section @sc{gdb/mi} File Transfer Commands
35542
35543
35544 @subheading The @code{-target-file-put} Command
35545 @findex -target-file-put
35546
35547 @subsubheading Synopsis
35548
35549 @smallexample
35550 -target-file-put @var{hostfile} @var{targetfile}
35551 @end smallexample
35552
35553 Copy file @var{hostfile} from the host system (the machine running
35554 @value{GDBN}) to @var{targetfile} on the target system.
35555
35556 @subsubheading @value{GDBN} Command
35557
35558 The corresponding @value{GDBN} command is @samp{remote put}.
35559
35560 @subsubheading Example
35561
35562 @smallexample
35563 (gdb)
35564 -target-file-put localfile remotefile
35565 ^done
35566 (gdb)
35567 @end smallexample
35568
35569
35570 @subheading The @code{-target-file-get} Command
35571 @findex -target-file-get
35572
35573 @subsubheading Synopsis
35574
35575 @smallexample
35576 -target-file-get @var{targetfile} @var{hostfile}
35577 @end smallexample
35578
35579 Copy file @var{targetfile} from the target system to @var{hostfile}
35580 on the host system.
35581
35582 @subsubheading @value{GDBN} Command
35583
35584 The corresponding @value{GDBN} command is @samp{remote get}.
35585
35586 @subsubheading Example
35587
35588 @smallexample
35589 (gdb)
35590 -target-file-get remotefile localfile
35591 ^done
35592 (gdb)
35593 @end smallexample
35594
35595
35596 @subheading The @code{-target-file-delete} Command
35597 @findex -target-file-delete
35598
35599 @subsubheading Synopsis
35600
35601 @smallexample
35602 -target-file-delete @var{targetfile}
35603 @end smallexample
35604
35605 Delete @var{targetfile} from the target system.
35606
35607 @subsubheading @value{GDBN} Command
35608
35609 The corresponding @value{GDBN} command is @samp{remote delete}.
35610
35611 @subsubheading Example
35612
35613 @smallexample
35614 (gdb)
35615 -target-file-delete remotefile
35616 ^done
35617 (gdb)
35618 @end smallexample
35619
35620
35621 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35622 @node GDB/MI Ada Exceptions Commands
35623 @section Ada Exceptions @sc{gdb/mi} Commands
35624
35625 @subheading The @code{-info-ada-exceptions} Command
35626 @findex -info-ada-exceptions
35627
35628 @subsubheading Synopsis
35629
35630 @smallexample
35631 -info-ada-exceptions [ @var{regexp}]
35632 @end smallexample
35633
35634 List all Ada exceptions defined within the program being debugged.
35635 With a regular expression @var{regexp}, only those exceptions whose
35636 names match @var{regexp} are listed.
35637
35638 @subsubheading @value{GDBN} Command
35639
35640 The corresponding @value{GDBN} command is @samp{info exceptions}.
35641
35642 @subsubheading Result
35643
35644 The result is a table of Ada exceptions. The following columns are
35645 defined for each exception:
35646
35647 @table @samp
35648 @item name
35649 The name of the exception.
35650
35651 @item address
35652 The address of the exception.
35653
35654 @end table
35655
35656 @subsubheading Example
35657
35658 @smallexample
35659 -info-ada-exceptions aint
35660 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35661 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35662 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35663 body=[@{name="constraint_error",address="0x0000000000613da0"@},
35664 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35665 @end smallexample
35666
35667 @subheading Catching Ada Exceptions
35668
35669 The commands describing how to ask @value{GDBN} to stop when a program
35670 raises an exception are described at @ref{Ada Exception GDB/MI
35671 Catchpoint Commands}.
35672
35673
35674 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35675 @node GDB/MI Support Commands
35676 @section @sc{gdb/mi} Support Commands
35677
35678 Since new commands and features get regularly added to @sc{gdb/mi},
35679 some commands are available to help front-ends query the debugger
35680 about support for these capabilities. Similarly, it is also possible
35681 to query @value{GDBN} about target support of certain features.
35682
35683 @subheading The @code{-info-gdb-mi-command} Command
35684 @cindex @code{-info-gdb-mi-command}
35685 @findex -info-gdb-mi-command
35686
35687 @subsubheading Synopsis
35688
35689 @smallexample
35690 -info-gdb-mi-command @var{cmd_name}
35691 @end smallexample
35692
35693 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35694
35695 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35696 is technically not part of the command name (@pxref{GDB/MI Input
35697 Syntax}), and thus should be omitted in @var{cmd_name}. However,
35698 for ease of use, this command also accepts the form with the leading
35699 dash.
35700
35701 @subsubheading @value{GDBN} Command
35702
35703 There is no corresponding @value{GDBN} command.
35704
35705 @subsubheading Result
35706
35707 The result is a tuple. There is currently only one field:
35708
35709 @table @samp
35710 @item exists
35711 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35712 @code{"false"} otherwise.
35713
35714 @end table
35715
35716 @subsubheading Example
35717
35718 Here is an example where the @sc{gdb/mi} command does not exist:
35719
35720 @smallexample
35721 -info-gdb-mi-command unsupported-command
35722 ^done,command=@{exists="false"@}
35723 @end smallexample
35724
35725 @noindent
35726 And here is an example where the @sc{gdb/mi} command is known
35727 to the debugger:
35728
35729 @smallexample
35730 -info-gdb-mi-command symbol-list-lines
35731 ^done,command=@{exists="true"@}
35732 @end smallexample
35733
35734 @subheading The @code{-list-features} Command
35735 @findex -list-features
35736 @cindex supported @sc{gdb/mi} features, list
35737
35738 Returns a list of particular features of the MI protocol that
35739 this version of gdb implements. A feature can be a command,
35740 or a new field in an output of some command, or even an
35741 important bugfix. While a frontend can sometimes detect presence
35742 of a feature at runtime, it is easier to perform detection at debugger
35743 startup.
35744
35745 The command returns a list of strings, with each string naming an
35746 available feature. Each returned string is just a name, it does not
35747 have any internal structure. The list of possible feature names
35748 is given below.
35749
35750 Example output:
35751
35752 @smallexample
35753 (gdb) -list-features
35754 ^done,result=["feature1","feature2"]
35755 @end smallexample
35756
35757 The current list of features is:
35758
35759 @ftable @samp
35760 @item frozen-varobjs
35761 Indicates support for the @code{-var-set-frozen} command, as well
35762 as possible presence of the @code{frozen} field in the output
35763 of @code{-varobj-create}.
35764 @item pending-breakpoints
35765 Indicates support for the @option{-f} option to the @code{-break-insert}
35766 command.
35767 @item python
35768 Indicates Python scripting support, Python-based
35769 pretty-printing commands, and possible presence of the
35770 @samp{display_hint} field in the output of @code{-var-list-children}
35771 @item thread-info
35772 Indicates support for the @code{-thread-info} command.
35773 @item data-read-memory-bytes
35774 Indicates support for the @code{-data-read-memory-bytes} and the
35775 @code{-data-write-memory-bytes} commands.
35776 @item breakpoint-notifications
35777 Indicates that changes to breakpoints and breakpoints created via the
35778 CLI will be announced via async records.
35779 @item ada-task-info
35780 Indicates support for the @code{-ada-task-info} command.
35781 @item language-option
35782 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35783 option (@pxref{Context management}).
35784 @item info-gdb-mi-command
35785 Indicates support for the @code{-info-gdb-mi-command} command.
35786 @item undefined-command-error-code
35787 Indicates support for the "undefined-command" error code in error result
35788 records, produced when trying to execute an undefined @sc{gdb/mi} command
35789 (@pxref{GDB/MI Result Records}).
35790 @item exec-run-start-option
35791 Indicates that the @code{-exec-run} command supports the @option{--start}
35792 option (@pxref{GDB/MI Program Execution}).
35793 @item data-disassemble-a-option
35794 Indicates that the @code{-data-disassemble} command supports the @option{-a}
35795 option (@pxref{GDB/MI Data Manipulation}).
35796 @end ftable
35797
35798 @subheading The @code{-list-target-features} Command
35799 @findex -list-target-features
35800
35801 Returns a list of particular features that are supported by the
35802 target. Those features affect the permitted MI commands, but
35803 unlike the features reported by the @code{-list-features} command, the
35804 features depend on which target GDB is using at the moment. Whenever
35805 a target can change, due to commands such as @code{-target-select},
35806 @code{-target-attach} or @code{-exec-run}, the list of target features
35807 may change, and the frontend should obtain it again.
35808 Example output:
35809
35810 @smallexample
35811 (gdb) -list-target-features
35812 ^done,result=["async"]
35813 @end smallexample
35814
35815 The current list of features is:
35816
35817 @table @samp
35818 @item async
35819 Indicates that the target is capable of asynchronous command
35820 execution, which means that @value{GDBN} will accept further commands
35821 while the target is running.
35822
35823 @item reverse
35824 Indicates that the target is capable of reverse execution.
35825 @xref{Reverse Execution}, for more information.
35826
35827 @end table
35828
35829 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35830 @node GDB/MI Miscellaneous Commands
35831 @section Miscellaneous @sc{gdb/mi} Commands
35832
35833 @c @subheading -gdb-complete
35834
35835 @subheading The @code{-gdb-exit} Command
35836 @findex -gdb-exit
35837
35838 @subsubheading Synopsis
35839
35840 @smallexample
35841 -gdb-exit
35842 @end smallexample
35843
35844 Exit @value{GDBN} immediately.
35845
35846 @subsubheading @value{GDBN} Command
35847
35848 Approximately corresponds to @samp{quit}.
35849
35850 @subsubheading Example
35851
35852 @smallexample
35853 (gdb)
35854 -gdb-exit
35855 ^exit
35856 @end smallexample
35857
35858
35859 @ignore
35860 @subheading The @code{-exec-abort} Command
35861 @findex -exec-abort
35862
35863 @subsubheading Synopsis
35864
35865 @smallexample
35866 -exec-abort
35867 @end smallexample
35868
35869 Kill the inferior running program.
35870
35871 @subsubheading @value{GDBN} Command
35872
35873 The corresponding @value{GDBN} command is @samp{kill}.
35874
35875 @subsubheading Example
35876 N.A.
35877 @end ignore
35878
35879
35880 @subheading The @code{-gdb-set} Command
35881 @findex -gdb-set
35882
35883 @subsubheading Synopsis
35884
35885 @smallexample
35886 -gdb-set
35887 @end smallexample
35888
35889 Set an internal @value{GDBN} variable.
35890 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35891
35892 @subsubheading @value{GDBN} Command
35893
35894 The corresponding @value{GDBN} command is @samp{set}.
35895
35896 @subsubheading Example
35897
35898 @smallexample
35899 (gdb)
35900 -gdb-set $foo=3
35901 ^done
35902 (gdb)
35903 @end smallexample
35904
35905
35906 @subheading The @code{-gdb-show} Command
35907 @findex -gdb-show
35908
35909 @subsubheading Synopsis
35910
35911 @smallexample
35912 -gdb-show
35913 @end smallexample
35914
35915 Show the current value of a @value{GDBN} variable.
35916
35917 @subsubheading @value{GDBN} Command
35918
35919 The corresponding @value{GDBN} command is @samp{show}.
35920
35921 @subsubheading Example
35922
35923 @smallexample
35924 (gdb)
35925 -gdb-show annotate
35926 ^done,value="0"
35927 (gdb)
35928 @end smallexample
35929
35930 @c @subheading -gdb-source
35931
35932
35933 @subheading The @code{-gdb-version} Command
35934 @findex -gdb-version
35935
35936 @subsubheading Synopsis
35937
35938 @smallexample
35939 -gdb-version
35940 @end smallexample
35941
35942 Show version information for @value{GDBN}. Used mostly in testing.
35943
35944 @subsubheading @value{GDBN} Command
35945
35946 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35947 default shows this information when you start an interactive session.
35948
35949 @subsubheading Example
35950
35951 @c This example modifies the actual output from GDB to avoid overfull
35952 @c box in TeX.
35953 @smallexample
35954 (gdb)
35955 -gdb-version
35956 ~GNU gdb 5.2.1
35957 ~Copyright 2000 Free Software Foundation, Inc.
35958 ~GDB is free software, covered by the GNU General Public License, and
35959 ~you are welcome to change it and/or distribute copies of it under
35960 ~ certain conditions.
35961 ~Type "show copying" to see the conditions.
35962 ~There is absolutely no warranty for GDB. Type "show warranty" for
35963 ~ details.
35964 ~This GDB was configured as
35965 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35966 ^done
35967 (gdb)
35968 @end smallexample
35969
35970 @subheading The @code{-list-thread-groups} Command
35971 @findex -list-thread-groups
35972
35973 @subheading Synopsis
35974
35975 @smallexample
35976 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
35977 @end smallexample
35978
35979 Lists thread groups (@pxref{Thread groups}). When a single thread
35980 group is passed as the argument, lists the children of that group.
35981 When several thread group are passed, lists information about those
35982 thread groups. Without any parameters, lists information about all
35983 top-level thread groups.
35984
35985 Normally, thread groups that are being debugged are reported.
35986 With the @samp{--available} option, @value{GDBN} reports thread groups
35987 available on the target.
35988
35989 The output of this command may have either a @samp{threads} result or
35990 a @samp{groups} result. The @samp{thread} result has a list of tuples
35991 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35992 Information}). The @samp{groups} result has a list of tuples as value,
35993 each tuple describing a thread group. If top-level groups are
35994 requested (that is, no parameter is passed), or when several groups
35995 are passed, the output always has a @samp{groups} result. The format
35996 of the @samp{group} result is described below.
35997
35998 To reduce the number of roundtrips it's possible to list thread groups
35999 together with their children, by passing the @samp{--recurse} option
36000 and the recursion depth. Presently, only recursion depth of 1 is
36001 permitted. If this option is present, then every reported thread group
36002 will also include its children, either as @samp{group} or
36003 @samp{threads} field.
36004
36005 In general, any combination of option and parameters is permitted, with
36006 the following caveats:
36007
36008 @itemize @bullet
36009 @item
36010 When a single thread group is passed, the output will typically
36011 be the @samp{threads} result. Because threads may not contain
36012 anything, the @samp{recurse} option will be ignored.
36013
36014 @item
36015 When the @samp{--available} option is passed, limited information may
36016 be available. In particular, the list of threads of a process might
36017 be inaccessible. Further, specifying specific thread groups might
36018 not give any performance advantage over listing all thread groups.
36019 The frontend should assume that @samp{-list-thread-groups --available}
36020 is always an expensive operation and cache the results.
36021
36022 @end itemize
36023
36024 The @samp{groups} result is a list of tuples, where each tuple may
36025 have the following fields:
36026
36027 @table @code
36028 @item id
36029 Identifier of the thread group. This field is always present.
36030 The identifier is an opaque string; frontends should not try to
36031 convert it to an integer, even though it might look like one.
36032
36033 @item type
36034 The type of the thread group. At present, only @samp{process} is a
36035 valid type.
36036
36037 @item pid
36038 The target-specific process identifier. This field is only present
36039 for thread groups of type @samp{process} and only if the process exists.
36040
36041 @item exit-code
36042 The exit code of this group's last exited thread, formatted in octal.
36043 This field is only present for thread groups of type @samp{process} and
36044 only if the process is not running.
36045
36046 @item num_children
36047 The number of children this thread group has. This field may be
36048 absent for an available thread group.
36049
36050 @item threads
36051 This field has a list of tuples as value, each tuple describing a
36052 thread. It may be present if the @samp{--recurse} option is
36053 specified, and it's actually possible to obtain the threads.
36054
36055 @item cores
36056 This field is a list of integers, each identifying a core that one
36057 thread of the group is running on. This field may be absent if
36058 such information is not available.
36059
36060 @item executable
36061 The name of the executable file that corresponds to this thread group.
36062 The field is only present for thread groups of type @samp{process},
36063 and only if there is a corresponding executable file.
36064
36065 @end table
36066
36067 @subheading Example
36068
36069 @smallexample
36070 @value{GDBP}
36071 -list-thread-groups
36072 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36073 -list-thread-groups 17
36074 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36075 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36076 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36077 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
36078 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
36079 -list-thread-groups --available
36080 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36081 -list-thread-groups --available --recurse 1
36082 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36083 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36084 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36085 -list-thread-groups --available --recurse 1 17 18
36086 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36087 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36088 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
36089 @end smallexample
36090
36091 @subheading The @code{-info-os} Command
36092 @findex -info-os
36093
36094 @subsubheading Synopsis
36095
36096 @smallexample
36097 -info-os [ @var{type} ]
36098 @end smallexample
36099
36100 If no argument is supplied, the command returns a table of available
36101 operating-system-specific information types. If one of these types is
36102 supplied as an argument @var{type}, then the command returns a table
36103 of data of that type.
36104
36105 The types of information available depend on the target operating
36106 system.
36107
36108 @subsubheading @value{GDBN} Command
36109
36110 The corresponding @value{GDBN} command is @samp{info os}.
36111
36112 @subsubheading Example
36113
36114 When run on a @sc{gnu}/Linux system, the output will look something
36115 like this:
36116
36117 @smallexample
36118 @value{GDBP}
36119 -info-os
36120 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36121 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36122 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36123 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36124 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36125 col2="CPUs"@},
36126 item=@{col0="files",col1="Listing of all file descriptors",
36127 col2="File descriptors"@},
36128 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36129 col2="Kernel modules"@},
36130 item=@{col0="msg",col1="Listing of all message queues",
36131 col2="Message queues"@},
36132 item=@{col0="processes",col1="Listing of all processes",
36133 col2="Processes"@},
36134 item=@{col0="procgroups",col1="Listing of all process groups",
36135 col2="Process groups"@},
36136 item=@{col0="semaphores",col1="Listing of all semaphores",
36137 col2="Semaphores"@},
36138 item=@{col0="shm",col1="Listing of all shared-memory regions",
36139 col2="Shared-memory regions"@},
36140 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36141 col2="Sockets"@},
36142 item=@{col0="threads",col1="Listing of all threads",
36143 col2="Threads"@}]
36144 @value{GDBP}
36145 -info-os processes
36146 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36147 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36148 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36149 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36150 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36151 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36152 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36153 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36154 ...
36155 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36156 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36157 (gdb)
36158 @end smallexample
36159
36160 (Note that the MI output here includes a @code{"Title"} column that
36161 does not appear in command-line @code{info os}; this column is useful
36162 for MI clients that want to enumerate the types of data, such as in a
36163 popup menu, but is needless clutter on the command line, and
36164 @code{info os} omits it.)
36165
36166 @subheading The @code{-add-inferior} Command
36167 @findex -add-inferior
36168
36169 @subheading Synopsis
36170
36171 @smallexample
36172 -add-inferior
36173 @end smallexample
36174
36175 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
36176 inferior is not associated with any executable. Such association may
36177 be established with the @samp{-file-exec-and-symbols} command
36178 (@pxref{GDB/MI File Commands}). The command response has a single
36179 field, @samp{inferior}, whose value is the identifier of the
36180 thread group corresponding to the new inferior.
36181
36182 @subheading Example
36183
36184 @smallexample
36185 @value{GDBP}
36186 -add-inferior
36187 ^done,inferior="i3"
36188 @end smallexample
36189
36190 @subheading The @code{-interpreter-exec} Command
36191 @findex -interpreter-exec
36192
36193 @subheading Synopsis
36194
36195 @smallexample
36196 -interpreter-exec @var{interpreter} @var{command}
36197 @end smallexample
36198 @anchor{-interpreter-exec}
36199
36200 Execute the specified @var{command} in the given @var{interpreter}.
36201
36202 @subheading @value{GDBN} Command
36203
36204 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36205
36206 @subheading Example
36207
36208 @smallexample
36209 (gdb)
36210 -interpreter-exec console "break main"
36211 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36212 &"During symbol reading, bad structure-type format.\n"
36213 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36214 ^done
36215 (gdb)
36216 @end smallexample
36217
36218 @subheading The @code{-inferior-tty-set} Command
36219 @findex -inferior-tty-set
36220
36221 @subheading Synopsis
36222
36223 @smallexample
36224 -inferior-tty-set /dev/pts/1
36225 @end smallexample
36226
36227 Set terminal for future runs of the program being debugged.
36228
36229 @subheading @value{GDBN} Command
36230
36231 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36232
36233 @subheading Example
36234
36235 @smallexample
36236 (gdb)
36237 -inferior-tty-set /dev/pts/1
36238 ^done
36239 (gdb)
36240 @end smallexample
36241
36242 @subheading The @code{-inferior-tty-show} Command
36243 @findex -inferior-tty-show
36244
36245 @subheading Synopsis
36246
36247 @smallexample
36248 -inferior-tty-show
36249 @end smallexample
36250
36251 Show terminal for future runs of program being debugged.
36252
36253 @subheading @value{GDBN} Command
36254
36255 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36256
36257 @subheading Example
36258
36259 @smallexample
36260 (gdb)
36261 -inferior-tty-set /dev/pts/1
36262 ^done
36263 (gdb)
36264 -inferior-tty-show
36265 ^done,inferior_tty_terminal="/dev/pts/1"
36266 (gdb)
36267 @end smallexample
36268
36269 @subheading The @code{-enable-timings} Command
36270 @findex -enable-timings
36271
36272 @subheading Synopsis
36273
36274 @smallexample
36275 -enable-timings [yes | no]
36276 @end smallexample
36277
36278 Toggle the printing of the wallclock, user and system times for an MI
36279 command as a field in its output. This command is to help frontend
36280 developers optimize the performance of their code. No argument is
36281 equivalent to @samp{yes}.
36282
36283 @subheading @value{GDBN} Command
36284
36285 No equivalent.
36286
36287 @subheading Example
36288
36289 @smallexample
36290 (gdb)
36291 -enable-timings
36292 ^done
36293 (gdb)
36294 -break-insert main
36295 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36296 addr="0x080484ed",func="main",file="myprog.c",
36297 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36298 times="0"@},
36299 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36300 (gdb)
36301 -enable-timings no
36302 ^done
36303 (gdb)
36304 -exec-run
36305 ^running
36306 (gdb)
36307 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36308 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36309 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36310 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36311 (gdb)
36312 @end smallexample
36313
36314 @subheading The @code{-complete} Command
36315 @findex -complete
36316
36317 @subheading Synopsis
36318
36319 @smallexample
36320 -complete @var{command}
36321 @end smallexample
36322
36323 Show a list of completions for partially typed CLI @var{command}.
36324
36325 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36326 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36327 because @value{GDBN} is used remotely via a SSH connection.
36328
36329 @subheading Result
36330
36331 The result consists of two or three fields:
36332
36333 @table @samp
36334 @item completion
36335 This field contains the completed @var{command}. If @var{command}
36336 has no known completions, this field is omitted.
36337
36338 @item matches
36339 This field contains a (possibly empty) array of matches. It is always present.
36340
36341 @item max_completions_reached
36342 This field contains @code{1} if number of known completions is above
36343 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36344 @code{0}. It is always present.
36345
36346 @end table
36347
36348 @subheading @value{GDBN} Command
36349
36350 The corresponding @value{GDBN} command is @samp{complete}.
36351
36352 @subheading Example
36353
36354 @smallexample
36355 (gdb)
36356 -complete br
36357 ^done,completion="break",
36358 matches=["break","break-range"],
36359 max_completions_reached="0"
36360 (gdb)
36361 -complete "b ma"
36362 ^done,completion="b ma",
36363 matches=["b madvise","b main"],max_completions_reached="0"
36364 (gdb)
36365 -complete "b push_b"
36366 ^done,completion="b push_back(",
36367 matches=[
36368 "b A::push_back(void*)",
36369 "b std::string::push_back(char)",
36370 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36371 max_completions_reached="0"
36372 (gdb)
36373 -complete "nonexist"
36374 ^done,matches=[],max_completions_reached="0"
36375 (gdb)
36376
36377 @end smallexample
36378
36379 @node Annotations
36380 @chapter @value{GDBN} Annotations
36381
36382 This chapter describes annotations in @value{GDBN}. Annotations were
36383 designed to interface @value{GDBN} to graphical user interfaces or other
36384 similar programs which want to interact with @value{GDBN} at a
36385 relatively high level.
36386
36387 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36388 (@pxref{GDB/MI}).
36389
36390 @ignore
36391 This is Edition @value{EDITION}, @value{DATE}.
36392 @end ignore
36393
36394 @menu
36395 * Annotations Overview:: What annotations are; the general syntax.
36396 * Server Prefix:: Issuing a command without affecting user state.
36397 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36398 * Errors:: Annotations for error messages.
36399 * Invalidation:: Some annotations describe things now invalid.
36400 * Annotations for Running::
36401 Whether the program is running, how it stopped, etc.
36402 * Source Annotations:: Annotations describing source code.
36403 @end menu
36404
36405 @node Annotations Overview
36406 @section What is an Annotation?
36407 @cindex annotations
36408
36409 Annotations start with a newline character, two @samp{control-z}
36410 characters, and the name of the annotation. If there is no additional
36411 information associated with this annotation, the name of the annotation
36412 is followed immediately by a newline. If there is additional
36413 information, the name of the annotation is followed by a space, the
36414 additional information, and a newline. The additional information
36415 cannot contain newline characters.
36416
36417 Any output not beginning with a newline and two @samp{control-z}
36418 characters denotes literal output from @value{GDBN}. Currently there is
36419 no need for @value{GDBN} to output a newline followed by two
36420 @samp{control-z} characters, but if there was such a need, the
36421 annotations could be extended with an @samp{escape} annotation which
36422 means those three characters as output.
36423
36424 The annotation @var{level}, which is specified using the
36425 @option{--annotate} command line option (@pxref{Mode Options}), controls
36426 how much information @value{GDBN} prints together with its prompt,
36427 values of expressions, source lines, and other types of output. Level 0
36428 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36429 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36430 for programs that control @value{GDBN}, and level 2 annotations have
36431 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36432 Interface, annotate, GDB's Obsolete Annotations}).
36433
36434 @table @code
36435 @kindex set annotate
36436 @item set annotate @var{level}
36437 The @value{GDBN} command @code{set annotate} sets the level of
36438 annotations to the specified @var{level}.
36439
36440 @item show annotate
36441 @kindex show annotate
36442 Show the current annotation level.
36443 @end table
36444
36445 This chapter describes level 3 annotations.
36446
36447 A simple example of starting up @value{GDBN} with annotations is:
36448
36449 @smallexample
36450 $ @kbd{gdb --annotate=3}
36451 GNU gdb 6.0
36452 Copyright 2003 Free Software Foundation, Inc.
36453 GDB is free software, covered by the GNU General Public License,
36454 and you are welcome to change it and/or distribute copies of it
36455 under certain conditions.
36456 Type "show copying" to see the conditions.
36457 There is absolutely no warranty for GDB. Type "show warranty"
36458 for details.
36459 This GDB was configured as "i386-pc-linux-gnu"
36460
36461 ^Z^Zpre-prompt
36462 (@value{GDBP})
36463 ^Z^Zprompt
36464 @kbd{quit}
36465
36466 ^Z^Zpost-prompt
36467 $
36468 @end smallexample
36469
36470 Here @samp{quit} is input to @value{GDBN}; the rest is output from
36471 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36472 denotes a @samp{control-z} character) are annotations; the rest is
36473 output from @value{GDBN}.
36474
36475 @node Server Prefix
36476 @section The Server Prefix
36477 @cindex server prefix
36478
36479 If you prefix a command with @samp{server } then it will not affect
36480 the command history, nor will it affect @value{GDBN}'s notion of which
36481 command to repeat if @key{RET} is pressed on a line by itself. This
36482 means that commands can be run behind a user's back by a front-end in
36483 a transparent manner.
36484
36485 The @code{server } prefix does not affect the recording of values into
36486 the value history; to print a value without recording it into the
36487 value history, use the @code{output} command instead of the
36488 @code{print} command.
36489
36490 Using this prefix also disables confirmation requests
36491 (@pxref{confirmation requests}).
36492
36493 @node Prompting
36494 @section Annotation for @value{GDBN} Input
36495
36496 @cindex annotations for prompts
36497 When @value{GDBN} prompts for input, it annotates this fact so it is possible
36498 to know when to send output, when the output from a given command is
36499 over, etc.
36500
36501 Different kinds of input each have a different @dfn{input type}. Each
36502 input type has three annotations: a @code{pre-} annotation, which
36503 denotes the beginning of any prompt which is being output, a plain
36504 annotation, which denotes the end of the prompt, and then a @code{post-}
36505 annotation which denotes the end of any echo which may (or may not) be
36506 associated with the input. For example, the @code{prompt} input type
36507 features the following annotations:
36508
36509 @smallexample
36510 ^Z^Zpre-prompt
36511 ^Z^Zprompt
36512 ^Z^Zpost-prompt
36513 @end smallexample
36514
36515 The input types are
36516
36517 @table @code
36518 @findex pre-prompt annotation
36519 @findex prompt annotation
36520 @findex post-prompt annotation
36521 @item prompt
36522 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36523
36524 @findex pre-commands annotation
36525 @findex commands annotation
36526 @findex post-commands annotation
36527 @item commands
36528 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36529 command. The annotations are repeated for each command which is input.
36530
36531 @findex pre-overload-choice annotation
36532 @findex overload-choice annotation
36533 @findex post-overload-choice annotation
36534 @item overload-choice
36535 When @value{GDBN} wants the user to select between various overloaded functions.
36536
36537 @findex pre-query annotation
36538 @findex query annotation
36539 @findex post-query annotation
36540 @item query
36541 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36542
36543 @findex pre-prompt-for-continue annotation
36544 @findex prompt-for-continue annotation
36545 @findex post-prompt-for-continue annotation
36546 @item prompt-for-continue
36547 When @value{GDBN} is asking the user to press return to continue. Note: Don't
36548 expect this to work well; instead use @code{set height 0} to disable
36549 prompting. This is because the counting of lines is buggy in the
36550 presence of annotations.
36551 @end table
36552
36553 @node Errors
36554 @section Errors
36555 @cindex annotations for errors, warnings and interrupts
36556
36557 @findex quit annotation
36558 @smallexample
36559 ^Z^Zquit
36560 @end smallexample
36561
36562 This annotation occurs right before @value{GDBN} responds to an interrupt.
36563
36564 @findex error annotation
36565 @smallexample
36566 ^Z^Zerror
36567 @end smallexample
36568
36569 This annotation occurs right before @value{GDBN} responds to an error.
36570
36571 Quit and error annotations indicate that any annotations which @value{GDBN} was
36572 in the middle of may end abruptly. For example, if a
36573 @code{value-history-begin} annotation is followed by a @code{error}, one
36574 cannot expect to receive the matching @code{value-history-end}. One
36575 cannot expect not to receive it either, however; an error annotation
36576 does not necessarily mean that @value{GDBN} is immediately returning all the way
36577 to the top level.
36578
36579 @findex error-begin annotation
36580 A quit or error annotation may be preceded by
36581
36582 @smallexample
36583 ^Z^Zerror-begin
36584 @end smallexample
36585
36586 Any output between that and the quit or error annotation is the error
36587 message.
36588
36589 Warning messages are not yet annotated.
36590 @c If we want to change that, need to fix warning(), type_error(),
36591 @c range_error(), and possibly other places.
36592
36593 @node Invalidation
36594 @section Invalidation Notices
36595
36596 @cindex annotations for invalidation messages
36597 The following annotations say that certain pieces of state may have
36598 changed.
36599
36600 @table @code
36601 @findex frames-invalid annotation
36602 @item ^Z^Zframes-invalid
36603
36604 The frames (for example, output from the @code{backtrace} command) may
36605 have changed.
36606
36607 @findex breakpoints-invalid annotation
36608 @item ^Z^Zbreakpoints-invalid
36609
36610 The breakpoints may have changed. For example, the user just added or
36611 deleted a breakpoint.
36612 @end table
36613
36614 @node Annotations for Running
36615 @section Running the Program
36616 @cindex annotations for running programs
36617
36618 @findex starting annotation
36619 @findex stopping annotation
36620 When the program starts executing due to a @value{GDBN} command such as
36621 @code{step} or @code{continue},
36622
36623 @smallexample
36624 ^Z^Zstarting
36625 @end smallexample
36626
36627 is output. When the program stops,
36628
36629 @smallexample
36630 ^Z^Zstopped
36631 @end smallexample
36632
36633 is output. Before the @code{stopped} annotation, a variety of
36634 annotations describe how the program stopped.
36635
36636 @table @code
36637 @findex exited annotation
36638 @item ^Z^Zexited @var{exit-status}
36639 The program exited, and @var{exit-status} is the exit status (zero for
36640 successful exit, otherwise nonzero).
36641
36642 @findex signalled annotation
36643 @findex signal-name annotation
36644 @findex signal-name-end annotation
36645 @findex signal-string annotation
36646 @findex signal-string-end annotation
36647 @item ^Z^Zsignalled
36648 The program exited with a signal. After the @code{^Z^Zsignalled}, the
36649 annotation continues:
36650
36651 @smallexample
36652 @var{intro-text}
36653 ^Z^Zsignal-name
36654 @var{name}
36655 ^Z^Zsignal-name-end
36656 @var{middle-text}
36657 ^Z^Zsignal-string
36658 @var{string}
36659 ^Z^Zsignal-string-end
36660 @var{end-text}
36661 @end smallexample
36662
36663 @noindent
36664 where @var{name} is the name of the signal, such as @code{SIGILL} or
36665 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
36666 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
36667 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36668 user's benefit and have no particular format.
36669
36670 @findex signal annotation
36671 @item ^Z^Zsignal
36672 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36673 just saying that the program received the signal, not that it was
36674 terminated with it.
36675
36676 @findex breakpoint annotation
36677 @item ^Z^Zbreakpoint @var{number}
36678 The program hit breakpoint number @var{number}.
36679
36680 @findex watchpoint annotation
36681 @item ^Z^Zwatchpoint @var{number}
36682 The program hit watchpoint number @var{number}.
36683 @end table
36684
36685 @node Source Annotations
36686 @section Displaying Source
36687 @cindex annotations for source display
36688
36689 @findex source annotation
36690 The following annotation is used instead of displaying source code:
36691
36692 @smallexample
36693 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36694 @end smallexample
36695
36696 where @var{filename} is an absolute file name indicating which source
36697 file, @var{line} is the line number within that file (where 1 is the
36698 first line in the file), @var{character} is the character position
36699 within the file (where 0 is the first character in the file) (for most
36700 debug formats this will necessarily point to the beginning of a line),
36701 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
36702 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36703 @var{addr} is the address in the target program associated with the
36704 source which is being displayed. The @var{addr} is in the form @samp{0x}
36705 followed by one or more lowercase hex digits (note that this does not
36706 depend on the language).
36707
36708 @node JIT Interface
36709 @chapter JIT Compilation Interface
36710 @cindex just-in-time compilation
36711 @cindex JIT compilation interface
36712
36713 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36714 interface. A JIT compiler is a program or library that generates native
36715 executable code at runtime and executes it, usually in order to achieve good
36716 performance while maintaining platform independence.
36717
36718 Programs that use JIT compilation are normally difficult to debug because
36719 portions of their code are generated at runtime, instead of being loaded from
36720 object files, which is where @value{GDBN} normally finds the program's symbols
36721 and debug information. In order to debug programs that use JIT compilation,
36722 @value{GDBN} has an interface that allows the program to register in-memory
36723 symbol files with @value{GDBN} at runtime.
36724
36725 If you are using @value{GDBN} to debug a program that uses this interface, then
36726 it should work transparently so long as you have not stripped the binary. If
36727 you are developing a JIT compiler, then the interface is documented in the rest
36728 of this chapter. At this time, the only known client of this interface is the
36729 LLVM JIT.
36730
36731 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36732 JIT compiler communicates with @value{GDBN} by writing data into a global
36733 variable and calling a function at a well-known symbol. When @value{GDBN}
36734 attaches, it reads a linked list of symbol files from the global variable to
36735 find existing code, and puts a breakpoint in the function so that it can find
36736 out about additional code.
36737
36738 @menu
36739 * Declarations:: Relevant C struct declarations
36740 * Registering Code:: Steps to register code
36741 * Unregistering Code:: Steps to unregister code
36742 * Custom Debug Info:: Emit debug information in a custom format
36743 @end menu
36744
36745 @node Declarations
36746 @section JIT Declarations
36747
36748 These are the relevant struct declarations that a C program should include to
36749 implement the interface:
36750
36751 @smallexample
36752 typedef enum
36753 @{
36754 JIT_NOACTION = 0,
36755 JIT_REGISTER_FN,
36756 JIT_UNREGISTER_FN
36757 @} jit_actions_t;
36758
36759 struct jit_code_entry
36760 @{
36761 struct jit_code_entry *next_entry;
36762 struct jit_code_entry *prev_entry;
36763 const char *symfile_addr;
36764 uint64_t symfile_size;
36765 @};
36766
36767 struct jit_descriptor
36768 @{
36769 uint32_t version;
36770 /* This type should be jit_actions_t, but we use uint32_t
36771 to be explicit about the bitwidth. */
36772 uint32_t action_flag;
36773 struct jit_code_entry *relevant_entry;
36774 struct jit_code_entry *first_entry;
36775 @};
36776
36777 /* GDB puts a breakpoint in this function. */
36778 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36779
36780 /* Make sure to specify the version statically, because the
36781 debugger may check the version before we can set it. */
36782 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36783 @end smallexample
36784
36785 If the JIT is multi-threaded, then it is important that the JIT synchronize any
36786 modifications to this global data properly, which can easily be done by putting
36787 a global mutex around modifications to these structures.
36788
36789 @node Registering Code
36790 @section Registering Code
36791
36792 To register code with @value{GDBN}, the JIT should follow this protocol:
36793
36794 @itemize @bullet
36795 @item
36796 Generate an object file in memory with symbols and other desired debug
36797 information. The file must include the virtual addresses of the sections.
36798
36799 @item
36800 Create a code entry for the file, which gives the start and size of the symbol
36801 file.
36802
36803 @item
36804 Add it to the linked list in the JIT descriptor.
36805
36806 @item
36807 Point the relevant_entry field of the descriptor at the entry.
36808
36809 @item
36810 Set @code{action_flag} to @code{JIT_REGISTER} and call
36811 @code{__jit_debug_register_code}.
36812 @end itemize
36813
36814 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36815 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
36816 new code. However, the linked list must still be maintained in order to allow
36817 @value{GDBN} to attach to a running process and still find the symbol files.
36818
36819 @node Unregistering Code
36820 @section Unregistering Code
36821
36822 If code is freed, then the JIT should use the following protocol:
36823
36824 @itemize @bullet
36825 @item
36826 Remove the code entry corresponding to the code from the linked list.
36827
36828 @item
36829 Point the @code{relevant_entry} field of the descriptor at the code entry.
36830
36831 @item
36832 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36833 @code{__jit_debug_register_code}.
36834 @end itemize
36835
36836 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36837 and the JIT will leak the memory used for the associated symbol files.
36838
36839 @node Custom Debug Info
36840 @section Custom Debug Info
36841 @cindex custom JIT debug info
36842 @cindex JIT debug info reader
36843
36844 Generating debug information in platform-native file formats (like ELF
36845 or COFF) may be an overkill for JIT compilers; especially if all the
36846 debug info is used for is displaying a meaningful backtrace. The
36847 issue can be resolved by having the JIT writers decide on a debug info
36848 format and also provide a reader that parses the debug info generated
36849 by the JIT compiler. This section gives a brief overview on writing
36850 such a parser. More specific details can be found in the source file
36851 @file{gdb/jit-reader.in}, which is also installed as a header at
36852 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36853
36854 The reader is implemented as a shared object (so this functionality is
36855 not available on platforms which don't allow loading shared objects at
36856 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36857 @code{jit-reader-unload} are provided, to be used to load and unload
36858 the readers from a preconfigured directory. Once loaded, the shared
36859 object is used the parse the debug information emitted by the JIT
36860 compiler.
36861
36862 @menu
36863 * Using JIT Debug Info Readers:: How to use supplied readers correctly
36864 * Writing JIT Debug Info Readers:: Creating a debug-info reader
36865 @end menu
36866
36867 @node Using JIT Debug Info Readers
36868 @subsection Using JIT Debug Info Readers
36869 @kindex jit-reader-load
36870 @kindex jit-reader-unload
36871
36872 Readers can be loaded and unloaded using the @code{jit-reader-load}
36873 and @code{jit-reader-unload} commands.
36874
36875 @table @code
36876 @item jit-reader-load @var{reader}
36877 Load the JIT reader named @var{reader}, which is a shared
36878 object specified as either an absolute or a relative file name. In
36879 the latter case, @value{GDBN} will try to load the reader from a
36880 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36881 system (here @var{libdir} is the system library directory, often
36882 @file{/usr/local/lib}).
36883
36884 Only one reader can be active at a time; trying to load a second
36885 reader when one is already loaded will result in @value{GDBN}
36886 reporting an error. A new JIT reader can be loaded by first unloading
36887 the current one using @code{jit-reader-unload} and then invoking
36888 @code{jit-reader-load}.
36889
36890 @item jit-reader-unload
36891 Unload the currently loaded JIT reader.
36892
36893 @end table
36894
36895 @node Writing JIT Debug Info Readers
36896 @subsection Writing JIT Debug Info Readers
36897 @cindex writing JIT debug info readers
36898
36899 As mentioned, a reader is essentially a shared object conforming to a
36900 certain ABI. This ABI is described in @file{jit-reader.h}.
36901
36902 @file{jit-reader.h} defines the structures, macros and functions
36903 required to write a reader. It is installed (along with
36904 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36905 the system include directory.
36906
36907 Readers need to be released under a GPL compatible license. A reader
36908 can be declared as released under such a license by placing the macro
36909 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36910
36911 The entry point for readers is the symbol @code{gdb_init_reader},
36912 which is expected to be a function with the prototype
36913
36914 @findex gdb_init_reader
36915 @smallexample
36916 extern struct gdb_reader_funcs *gdb_init_reader (void);
36917 @end smallexample
36918
36919 @cindex @code{struct gdb_reader_funcs}
36920
36921 @code{struct gdb_reader_funcs} contains a set of pointers to callback
36922 functions. These functions are executed to read the debug info
36923 generated by the JIT compiler (@code{read}), to unwind stack frames
36924 (@code{unwind}) and to create canonical frame IDs
36925 (@code{get_frame_id}). It also has a callback that is called when the
36926 reader is being unloaded (@code{destroy}). The struct looks like this
36927
36928 @smallexample
36929 struct gdb_reader_funcs
36930 @{
36931 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36932 int reader_version;
36933
36934 /* For use by the reader. */
36935 void *priv_data;
36936
36937 gdb_read_debug_info *read;
36938 gdb_unwind_frame *unwind;
36939 gdb_get_frame_id *get_frame_id;
36940 gdb_destroy_reader *destroy;
36941 @};
36942 @end smallexample
36943
36944 @cindex @code{struct gdb_symbol_callbacks}
36945 @cindex @code{struct gdb_unwind_callbacks}
36946
36947 The callbacks are provided with another set of callbacks by
36948 @value{GDBN} to do their job. For @code{read}, these callbacks are
36949 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36950 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36951 @code{struct gdb_symbol_callbacks} has callbacks to create new object
36952 files and new symbol tables inside those object files. @code{struct
36953 gdb_unwind_callbacks} has callbacks to read registers off the current
36954 frame and to write out the values of the registers in the previous
36955 frame. Both have a callback (@code{target_read}) to read bytes off the
36956 target's address space.
36957
36958 @node In-Process Agent
36959 @chapter In-Process Agent
36960 @cindex debugging agent
36961 The traditional debugging model is conceptually low-speed, but works fine,
36962 because most bugs can be reproduced in debugging-mode execution. However,
36963 as multi-core or many-core processors are becoming mainstream, and
36964 multi-threaded programs become more and more popular, there should be more
36965 and more bugs that only manifest themselves at normal-mode execution, for
36966 example, thread races, because debugger's interference with the program's
36967 timing may conceal the bugs. On the other hand, in some applications,
36968 it is not feasible for the debugger to interrupt the program's execution
36969 long enough for the developer to learn anything helpful about its behavior.
36970 If the program's correctness depends on its real-time behavior, delays
36971 introduced by a debugger might cause the program to fail, even when the
36972 code itself is correct. It is useful to be able to observe the program's
36973 behavior without interrupting it.
36974
36975 Therefore, traditional debugging model is too intrusive to reproduce
36976 some bugs. In order to reduce the interference with the program, we can
36977 reduce the number of operations performed by debugger. The
36978 @dfn{In-Process Agent}, a shared library, is running within the same
36979 process with inferior, and is able to perform some debugging operations
36980 itself. As a result, debugger is only involved when necessary, and
36981 performance of debugging can be improved accordingly. Note that
36982 interference with program can be reduced but can't be removed completely,
36983 because the in-process agent will still stop or slow down the program.
36984
36985 The in-process agent can interpret and execute Agent Expressions
36986 (@pxref{Agent Expressions}) during performing debugging operations. The
36987 agent expressions can be used for different purposes, such as collecting
36988 data in tracepoints, and condition evaluation in breakpoints.
36989
36990 @anchor{Control Agent}
36991 You can control whether the in-process agent is used as an aid for
36992 debugging with the following commands:
36993
36994 @table @code
36995 @kindex set agent on
36996 @item set agent on
36997 Causes the in-process agent to perform some operations on behalf of the
36998 debugger. Just which operations requested by the user will be done
36999 by the in-process agent depends on the its capabilities. For example,
37000 if you request to evaluate breakpoint conditions in the in-process agent,
37001 and the in-process agent has such capability as well, then breakpoint
37002 conditions will be evaluated in the in-process agent.
37003
37004 @kindex set agent off
37005 @item set agent off
37006 Disables execution of debugging operations by the in-process agent. All
37007 of the operations will be performed by @value{GDBN}.
37008
37009 @kindex show agent
37010 @item show agent
37011 Display the current setting of execution of debugging operations by
37012 the in-process agent.
37013 @end table
37014
37015 @menu
37016 * In-Process Agent Protocol::
37017 @end menu
37018
37019 @node In-Process Agent Protocol
37020 @section In-Process Agent Protocol
37021 @cindex in-process agent protocol
37022
37023 The in-process agent is able to communicate with both @value{GDBN} and
37024 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37025 used for communications between @value{GDBN} or GDBserver and the IPA.
37026 In general, @value{GDBN} or GDBserver sends commands
37027 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37028 in-process agent replies back with the return result of the command, or
37029 some other information. The data sent to in-process agent is composed
37030 of primitive data types, such as 4-byte or 8-byte type, and composite
37031 types, which are called objects (@pxref{IPA Protocol Objects}).
37032
37033 @menu
37034 * IPA Protocol Objects::
37035 * IPA Protocol Commands::
37036 @end menu
37037
37038 @node IPA Protocol Objects
37039 @subsection IPA Protocol Objects
37040 @cindex ipa protocol objects
37041
37042 The commands sent to and results received from agent may contain some
37043 complex data types called @dfn{objects}.
37044
37045 The in-process agent is running on the same machine with @value{GDBN}
37046 or GDBserver, so it doesn't have to handle as much differences between
37047 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37048 However, there are still some differences of two ends in two processes:
37049
37050 @enumerate
37051 @item
37052 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37053 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37054 @item
37055 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37056 GDBserver is compiled with one, and in-process agent is compiled with
37057 the other one.
37058 @end enumerate
37059
37060 Here are the IPA Protocol Objects:
37061
37062 @enumerate
37063 @item
37064 agent expression object. It represents an agent expression
37065 (@pxref{Agent Expressions}).
37066 @anchor{agent expression object}
37067 @item
37068 tracepoint action object. It represents a tracepoint action
37069 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37070 memory, static trace data and to evaluate expression.
37071 @anchor{tracepoint action object}
37072 @item
37073 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37074 @anchor{tracepoint object}
37075
37076 @end enumerate
37077
37078 The following table describes important attributes of each IPA protocol
37079 object:
37080
37081 @multitable @columnfractions .30 .20 .50
37082 @headitem Name @tab Size @tab Description
37083 @item @emph{agent expression object} @tab @tab
37084 @item length @tab 4 @tab length of bytes code
37085 @item byte code @tab @var{length} @tab contents of byte code
37086 @item @emph{tracepoint action for collecting memory} @tab @tab
37087 @item 'M' @tab 1 @tab type of tracepoint action
37088 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37089 address of the lowest byte to collect, otherwise @var{addr} is the offset
37090 of @var{basereg} for memory collecting.
37091 @item len @tab 8 @tab length of memory for collecting
37092 @item basereg @tab 4 @tab the register number containing the starting
37093 memory address for collecting.
37094 @item @emph{tracepoint action for collecting registers} @tab @tab
37095 @item 'R' @tab 1 @tab type of tracepoint action
37096 @item @emph{tracepoint action for collecting static trace data} @tab @tab
37097 @item 'L' @tab 1 @tab type of tracepoint action
37098 @item @emph{tracepoint action for expression evaluation} @tab @tab
37099 @item 'X' @tab 1 @tab type of tracepoint action
37100 @item agent expression @tab length of @tab @ref{agent expression object}
37101 @item @emph{tracepoint object} @tab @tab
37102 @item number @tab 4 @tab number of tracepoint
37103 @item address @tab 8 @tab address of tracepoint inserted on
37104 @item type @tab 4 @tab type of tracepoint
37105 @item enabled @tab 1 @tab enable or disable of tracepoint
37106 @item step_count @tab 8 @tab step
37107 @item pass_count @tab 8 @tab pass
37108 @item numactions @tab 4 @tab number of tracepoint actions
37109 @item hit count @tab 8 @tab hit count
37110 @item trace frame usage @tab 8 @tab trace frame usage
37111 @item compiled_cond @tab 8 @tab compiled condition
37112 @item orig_size @tab 8 @tab orig size
37113 @item condition @tab 4 if condition is NULL otherwise length of
37114 @ref{agent expression object}
37115 @tab zero if condition is NULL, otherwise is
37116 @ref{agent expression object}
37117 @item actions @tab variable
37118 @tab numactions number of @ref{tracepoint action object}
37119 @end multitable
37120
37121 @node IPA Protocol Commands
37122 @subsection IPA Protocol Commands
37123 @cindex ipa protocol commands
37124
37125 The spaces in each command are delimiters to ease reading this commands
37126 specification. They don't exist in real commands.
37127
37128 @table @samp
37129
37130 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37131 Installs a new fast tracepoint described by @var{tracepoint_object}
37132 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
37133 head of @dfn{jumppad}, which is used to jump to data collection routine
37134 in IPA finally.
37135
37136 Replies:
37137 @table @samp
37138 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37139 @var{target_address} is address of tracepoint in the inferior.
37140 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
37141 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37142 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37143 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37144 @item E @var{NN}
37145 for an error
37146
37147 @end table
37148
37149 @item close
37150 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37151 is about to kill inferiors.
37152
37153 @item qTfSTM
37154 @xref{qTfSTM}.
37155 @item qTsSTM
37156 @xref{qTsSTM}.
37157 @item qTSTMat
37158 @xref{qTSTMat}.
37159 @item probe_marker_at:@var{address}
37160 Asks in-process agent to probe the marker at @var{address}.
37161
37162 Replies:
37163 @table @samp
37164 @item E @var{NN}
37165 for an error
37166 @end table
37167 @item unprobe_marker_at:@var{address}
37168 Asks in-process agent to unprobe the marker at @var{address}.
37169 @end table
37170
37171 @node GDB Bugs
37172 @chapter Reporting Bugs in @value{GDBN}
37173 @cindex bugs in @value{GDBN}
37174 @cindex reporting bugs in @value{GDBN}
37175
37176 Your bug reports play an essential role in making @value{GDBN} reliable.
37177
37178 Reporting a bug may help you by bringing a solution to your problem, or it
37179 may not. But in any case the principal function of a bug report is to help
37180 the entire community by making the next version of @value{GDBN} work better. Bug
37181 reports are your contribution to the maintenance of @value{GDBN}.
37182
37183 In order for a bug report to serve its purpose, you must include the
37184 information that enables us to fix the bug.
37185
37186 @menu
37187 * Bug Criteria:: Have you found a bug?
37188 * Bug Reporting:: How to report bugs
37189 @end menu
37190
37191 @node Bug Criteria
37192 @section Have You Found a Bug?
37193 @cindex bug criteria
37194
37195 If you are not sure whether you have found a bug, here are some guidelines:
37196
37197 @itemize @bullet
37198 @cindex fatal signal
37199 @cindex debugger crash
37200 @cindex crash of debugger
37201 @item
37202 If the debugger gets a fatal signal, for any input whatever, that is a
37203 @value{GDBN} bug. Reliable debuggers never crash.
37204
37205 @cindex error on valid input
37206 @item
37207 If @value{GDBN} produces an error message for valid input, that is a
37208 bug. (Note that if you're cross debugging, the problem may also be
37209 somewhere in the connection to the target.)
37210
37211 @cindex invalid input
37212 @item
37213 If @value{GDBN} does not produce an error message for invalid input,
37214 that is a bug. However, you should note that your idea of
37215 ``invalid input'' might be our idea of ``an extension'' or ``support
37216 for traditional practice''.
37217
37218 @item
37219 If you are an experienced user of debugging tools, your suggestions
37220 for improvement of @value{GDBN} are welcome in any case.
37221 @end itemize
37222
37223 @node Bug Reporting
37224 @section How to Report Bugs
37225 @cindex bug reports
37226 @cindex @value{GDBN} bugs, reporting
37227
37228 A number of companies and individuals offer support for @sc{gnu} products.
37229 If you obtained @value{GDBN} from a support organization, we recommend you
37230 contact that organization first.
37231
37232 You can find contact information for many support companies and
37233 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37234 distribution.
37235 @c should add a web page ref...
37236
37237 @ifset BUGURL
37238 @ifset BUGURL_DEFAULT
37239 In any event, we also recommend that you submit bug reports for
37240 @value{GDBN}. The preferred method is to submit them directly using
37241 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37242 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37243 be used.
37244
37245 @strong{Do not send bug reports to @samp{info-gdb}, or to
37246 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37247 not want to receive bug reports. Those that do have arranged to receive
37248 @samp{bug-gdb}.
37249
37250 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37251 serves as a repeater. The mailing list and the newsgroup carry exactly
37252 the same messages. Often people think of posting bug reports to the
37253 newsgroup instead of mailing them. This appears to work, but it has one
37254 problem which can be crucial: a newsgroup posting often lacks a mail
37255 path back to the sender. Thus, if we need to ask for more information,
37256 we may be unable to reach you. For this reason, it is better to send
37257 bug reports to the mailing list.
37258 @end ifset
37259 @ifclear BUGURL_DEFAULT
37260 In any event, we also recommend that you submit bug reports for
37261 @value{GDBN} to @value{BUGURL}.
37262 @end ifclear
37263 @end ifset
37264
37265 The fundamental principle of reporting bugs usefully is this:
37266 @strong{report all the facts}. If you are not sure whether to state a
37267 fact or leave it out, state it!
37268
37269 Often people omit facts because they think they know what causes the
37270 problem and assume that some details do not matter. Thus, you might
37271 assume that the name of the variable you use in an example does not matter.
37272 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37273 stray memory reference which happens to fetch from the location where that
37274 name is stored in memory; perhaps, if the name were different, the contents
37275 of that location would fool the debugger into doing the right thing despite
37276 the bug. Play it safe and give a specific, complete example. That is the
37277 easiest thing for you to do, and the most helpful.
37278
37279 Keep in mind that the purpose of a bug report is to enable us to fix the
37280 bug. It may be that the bug has been reported previously, but neither
37281 you nor we can know that unless your bug report is complete and
37282 self-contained.
37283
37284 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37285 bell?'' Those bug reports are useless, and we urge everyone to
37286 @emph{refuse to respond to them} except to chide the sender to report
37287 bugs properly.
37288
37289 To enable us to fix the bug, you should include all these things:
37290
37291 @itemize @bullet
37292 @item
37293 The version of @value{GDBN}. @value{GDBN} announces it if you start
37294 with no arguments; you can also print it at any time using @code{show
37295 version}.
37296
37297 Without this, we will not know whether there is any point in looking for
37298 the bug in the current version of @value{GDBN}.
37299
37300 @item
37301 The type of machine you are using, and the operating system name and
37302 version number.
37303
37304 @item
37305 The details of the @value{GDBN} build-time configuration.
37306 @value{GDBN} shows these details if you invoke it with the
37307 @option{--configuration} command-line option, or if you type
37308 @code{show configuration} at @value{GDBN}'s prompt.
37309
37310 @item
37311 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37312 ``@value{GCC}--2.8.1''.
37313
37314 @item
37315 What compiler (and its version) was used to compile the program you are
37316 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37317 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37318 to get this information; for other compilers, see the documentation for
37319 those compilers.
37320
37321 @item
37322 The command arguments you gave the compiler to compile your example and
37323 observe the bug. For example, did you use @samp{-O}? To guarantee
37324 you will not omit something important, list them all. A copy of the
37325 Makefile (or the output from make) is sufficient.
37326
37327 If we were to try to guess the arguments, we would probably guess wrong
37328 and then we might not encounter the bug.
37329
37330 @item
37331 A complete input script, and all necessary source files, that will
37332 reproduce the bug.
37333
37334 @item
37335 A description of what behavior you observe that you believe is
37336 incorrect. For example, ``It gets a fatal signal.''
37337
37338 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37339 will certainly notice it. But if the bug is incorrect output, we might
37340 not notice unless it is glaringly wrong. You might as well not give us
37341 a chance to make a mistake.
37342
37343 Even if the problem you experience is a fatal signal, you should still
37344 say so explicitly. Suppose something strange is going on, such as, your
37345 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37346 the C library on your system. (This has happened!) Your copy might
37347 crash and ours would not. If you told us to expect a crash, then when
37348 ours fails to crash, we would know that the bug was not happening for
37349 us. If you had not told us to expect a crash, then we would not be able
37350 to draw any conclusion from our observations.
37351
37352 @pindex script
37353 @cindex recording a session script
37354 To collect all this information, you can use a session recording program
37355 such as @command{script}, which is available on many Unix systems.
37356 Just run your @value{GDBN} session inside @command{script} and then
37357 include the @file{typescript} file with your bug report.
37358
37359 Another way to record a @value{GDBN} session is to run @value{GDBN}
37360 inside Emacs and then save the entire buffer to a file.
37361
37362 @item
37363 If you wish to suggest changes to the @value{GDBN} source, send us context
37364 diffs. If you even discuss something in the @value{GDBN} source, refer to
37365 it by context, not by line number.
37366
37367 The line numbers in our development sources will not match those in your
37368 sources. Your line numbers would convey no useful information to us.
37369
37370 @end itemize
37371
37372 Here are some things that are not necessary:
37373
37374 @itemize @bullet
37375 @item
37376 A description of the envelope of the bug.
37377
37378 Often people who encounter a bug spend a lot of time investigating
37379 which changes to the input file will make the bug go away and which
37380 changes will not affect it.
37381
37382 This is often time consuming and not very useful, because the way we
37383 will find the bug is by running a single example under the debugger
37384 with breakpoints, not by pure deduction from a series of examples.
37385 We recommend that you save your time for something else.
37386
37387 Of course, if you can find a simpler example to report @emph{instead}
37388 of the original one, that is a convenience for us. Errors in the
37389 output will be easier to spot, running under the debugger will take
37390 less time, and so on.
37391
37392 However, simplification is not vital; if you do not want to do this,
37393 report the bug anyway and send us the entire test case you used.
37394
37395 @item
37396 A patch for the bug.
37397
37398 A patch for the bug does help us if it is a good one. But do not omit
37399 the necessary information, such as the test case, on the assumption that
37400 a patch is all we need. We might see problems with your patch and decide
37401 to fix the problem another way, or we might not understand it at all.
37402
37403 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37404 construct an example that will make the program follow a certain path
37405 through the code. If you do not send us the example, we will not be able
37406 to construct one, so we will not be able to verify that the bug is fixed.
37407
37408 And if we cannot understand what bug you are trying to fix, or why your
37409 patch should be an improvement, we will not install it. A test case will
37410 help us to understand.
37411
37412 @item
37413 A guess about what the bug is or what it depends on.
37414
37415 Such guesses are usually wrong. Even we cannot guess right about such
37416 things without first using the debugger to find the facts.
37417 @end itemize
37418
37419 @c The readline documentation is distributed with the readline code
37420 @c and consists of the two following files:
37421 @c rluser.texi
37422 @c hsuser.texi
37423 @c Use -I with makeinfo to point to the appropriate directory,
37424 @c environment var TEXINPUTS with TeX.
37425 @ifclear SYSTEM_READLINE
37426 @include rluser.texi
37427 @include hsuser.texi
37428 @end ifclear
37429
37430 @node In Memoriam
37431 @appendix In Memoriam
37432
37433 The @value{GDBN} project mourns the loss of the following long-time
37434 contributors:
37435
37436 @table @code
37437 @item Fred Fish
37438 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37439 to Free Software in general. Outside of @value{GDBN}, he was known in
37440 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37441
37442 @item Michael Snyder
37443 Michael was one of the Global Maintainers of the @value{GDBN} project,
37444 with contributions recorded as early as 1996, until 2011. In addition
37445 to his day to day participation, he was a large driving force behind
37446 adding Reverse Debugging to @value{GDBN}.
37447 @end table
37448
37449 Beyond their technical contributions to the project, they were also
37450 enjoyable members of the Free Software Community. We will miss them.
37451
37452 @node Formatting Documentation
37453 @appendix Formatting Documentation
37454
37455 @cindex @value{GDBN} reference card
37456 @cindex reference card
37457 The @value{GDBN} 4 release includes an already-formatted reference card, ready
37458 for printing with PostScript or Ghostscript, in the @file{gdb}
37459 subdirectory of the main source directory@footnote{In
37460 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37461 release.}. If you can use PostScript or Ghostscript with your printer,
37462 you can print the reference card immediately with @file{refcard.ps}.
37463
37464 The release also includes the source for the reference card. You
37465 can format it, using @TeX{}, by typing:
37466
37467 @smallexample
37468 make refcard.dvi
37469 @end smallexample
37470
37471 The @value{GDBN} reference card is designed to print in @dfn{landscape}
37472 mode on US ``letter'' size paper;
37473 that is, on a sheet 11 inches wide by 8.5 inches
37474 high. You will need to specify this form of printing as an option to
37475 your @sc{dvi} output program.
37476
37477 @cindex documentation
37478
37479 All the documentation for @value{GDBN} comes as part of the machine-readable
37480 distribution. The documentation is written in Texinfo format, which is
37481 a documentation system that uses a single source file to produce both
37482 on-line information and a printed manual. You can use one of the Info
37483 formatting commands to create the on-line version of the documentation
37484 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
37485
37486 @value{GDBN} includes an already formatted copy of the on-line Info
37487 version of this manual in the @file{gdb} subdirectory. The main Info
37488 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37489 subordinate files matching @samp{gdb.info*} in the same directory. If
37490 necessary, you can print out these files, or read them with any editor;
37491 but they are easier to read using the @code{info} subsystem in @sc{gnu}
37492 Emacs or the standalone @code{info} program, available as part of the
37493 @sc{gnu} Texinfo distribution.
37494
37495 If you want to format these Info files yourself, you need one of the
37496 Info formatting programs, such as @code{texinfo-format-buffer} or
37497 @code{makeinfo}.
37498
37499 If you have @code{makeinfo} installed, and are in the top level
37500 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37501 version @value{GDBVN}), you can make the Info file by typing:
37502
37503 @smallexample
37504 cd gdb
37505 make gdb.info
37506 @end smallexample
37507
37508 If you want to typeset and print copies of this manual, you need @TeX{},
37509 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37510 Texinfo definitions file.
37511
37512 @TeX{} is a typesetting program; it does not print files directly, but
37513 produces output files called @sc{dvi} files. To print a typeset
37514 document, you need a program to print @sc{dvi} files. If your system
37515 has @TeX{} installed, chances are it has such a program. The precise
37516 command to use depends on your system; @kbd{lpr -d} is common; another
37517 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37518 require a file name without any extension or a @samp{.dvi} extension.
37519
37520 @TeX{} also requires a macro definitions file called
37521 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37522 written in Texinfo format. On its own, @TeX{} cannot either read or
37523 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37524 and is located in the @file{gdb-@var{version-number}/texinfo}
37525 directory.
37526
37527 If you have @TeX{} and a @sc{dvi} printer program installed, you can
37528 typeset and print this manual. First switch to the @file{gdb}
37529 subdirectory of the main source directory (for example, to
37530 @file{gdb-@value{GDBVN}/gdb}) and type:
37531
37532 @smallexample
37533 make gdb.dvi
37534 @end smallexample
37535
37536 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
37537
37538 @node Installing GDB
37539 @appendix Installing @value{GDBN}
37540 @cindex installation
37541
37542 @menu
37543 * Requirements:: Requirements for building @value{GDBN}
37544 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
37545 * Separate Objdir:: Compiling @value{GDBN} in another directory
37546 * Config Names:: Specifying names for hosts and targets
37547 * Configure Options:: Summary of options for configure
37548 * System-wide configuration:: Having a system-wide init file
37549 @end menu
37550
37551 @node Requirements
37552 @section Requirements for Building @value{GDBN}
37553 @cindex building @value{GDBN}, requirements for
37554
37555 Building @value{GDBN} requires various tools and packages to be available.
37556 Other packages will be used only if they are found.
37557
37558 @heading Tools/Packages Necessary for Building @value{GDBN}
37559 @table @asis
37560 @item C@t{++}11 compiler
37561 @value{GDBN} is written in C@t{++}11. It should be buildable with any
37562 recent C@t{++}11 compiler, e.g.@: GCC.
37563
37564 @item GNU make
37565 @value{GDBN}'s build system relies on features only found in the GNU
37566 make program. Other variants of @code{make} will not work.
37567 @end table
37568
37569 @heading Tools/Packages Optional for Building @value{GDBN}
37570 @table @asis
37571 @item Expat
37572 @anchor{Expat}
37573 @value{GDBN} can use the Expat XML parsing library. This library may be
37574 included with your operating system distribution; if it is not, you
37575 can get the latest version from @url{http://expat.sourceforge.net}.
37576 The @file{configure} script will search for this library in several
37577 standard locations; if it is installed in an unusual path, you can
37578 use the @option{--with-libexpat-prefix} option to specify its location.
37579
37580 Expat is used for:
37581
37582 @itemize @bullet
37583 @item
37584 Remote protocol memory maps (@pxref{Memory Map Format})
37585 @item
37586 Target descriptions (@pxref{Target Descriptions})
37587 @item
37588 Remote shared library lists (@xref{Library List Format},
37589 or alternatively @pxref{Library List Format for SVR4 Targets})
37590 @item
37591 MS-Windows shared libraries (@pxref{Shared Libraries})
37592 @item
37593 Traceframe info (@pxref{Traceframe Info Format})
37594 @item
37595 Branch trace (@pxref{Branch Trace Format},
37596 @pxref{Branch Trace Configuration Format})
37597 @end itemize
37598
37599 @item Guile
37600 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37601 default, @value{GDBN} will be compiled if the Guile libraries are
37602 installed and are found by @file{configure}. You can use the
37603 @code{--with-guile} option to request Guile, and pass either the Guile
37604 version number or the file name of the relevant @code{pkg-config}
37605 program to choose a particular version of Guile.
37606
37607 @item iconv
37608 @value{GDBN}'s features related to character sets (@pxref{Character
37609 Sets}) require a functioning @code{iconv} implementation. If you are
37610 on a GNU system, then this is provided by the GNU C Library. Some
37611 other systems also provide a working @code{iconv}.
37612
37613 If @value{GDBN} is using the @code{iconv} program which is installed
37614 in a non-standard place, you will need to tell @value{GDBN} where to
37615 find it. This is done with @option{--with-iconv-bin} which specifies
37616 the directory that contains the @code{iconv} program. This program is
37617 run in order to make a list of the available character sets.
37618
37619 On systems without @code{iconv}, you can install GNU Libiconv. If
37620 Libiconv is installed in a standard place, @value{GDBN} will
37621 automatically use it if it is needed. If you have previously
37622 installed Libiconv in a non-standard place, you can use the
37623 @option{--with-libiconv-prefix} option to @file{configure}.
37624
37625 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37626 arrange to build Libiconv if a directory named @file{libiconv} appears
37627 in the top-most source directory. If Libiconv is built this way, and
37628 if the operating system does not provide a suitable @code{iconv}
37629 implementation, then the just-built library will automatically be used
37630 by @value{GDBN}. One easy way to set this up is to download GNU
37631 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37632 source tree, and then rename the directory holding the Libiconv source
37633 code to @samp{libiconv}.
37634
37635 @item lzma
37636 @value{GDBN} can support debugging sections that are compressed with
37637 the LZMA library. @xref{MiniDebugInfo}. If this library is not
37638 included with your operating system, you can find it in the xz package
37639 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37640 the usual place, then the @file{configure} script will use it
37641 automatically. If it is installed in an unusual path, you can use the
37642 @option{--with-lzma-prefix} option to specify its location.
37643
37644 @item MPFR
37645 @anchor{MPFR}
37646 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
37647 library. This library may be included with your operating system
37648 distribution; if it is not, you can get the latest version from
37649 @url{http://www.mpfr.org}. The @file{configure} script will search
37650 for this library in several standard locations; if it is installed
37651 in an unusual path, you can use the @option{--with-libmpfr-prefix}
37652 option to specify its location.
37653
37654 GNU MPFR is used to emulate target floating-point arithmetic during
37655 expression evaluation when the target uses different floating-point
37656 formats than the host. If GNU MPFR it is not available, @value{GDBN}
37657 will fall back to using host floating-point arithmetic.
37658
37659 @item Python
37660 @value{GDBN} can be scripted using Python language. @xref{Python}.
37661 By default, @value{GDBN} will be compiled if the Python libraries are
37662 installed and are found by @file{configure}. You can use the
37663 @code{--with-python} option to request Python, and pass either the
37664 file name of the relevant @code{python} executable, or the name of the
37665 directory in which Python is installed, to choose a particular
37666 installation of Python.
37667
37668 @item zlib
37669 @cindex compressed debug sections
37670 @value{GDBN} will use the @samp{zlib} library, if available, to read
37671 compressed debug sections. Some linkers, such as GNU gold, are capable
37672 of producing binaries with compressed debug sections. If @value{GDBN}
37673 is compiled with @samp{zlib}, it will be able to read the debug
37674 information in such binaries.
37675
37676 The @samp{zlib} library is likely included with your operating system
37677 distribution; if it is not, you can get the latest version from
37678 @url{http://zlib.net}.
37679 @end table
37680
37681 @node Running Configure
37682 @section Invoking the @value{GDBN} @file{configure} Script
37683 @cindex configuring @value{GDBN}
37684 @value{GDBN} comes with a @file{configure} script that automates the process
37685 of preparing @value{GDBN} for installation; you can then use @code{make} to
37686 build the @code{gdb} program.
37687 @iftex
37688 @c irrelevant in info file; it's as current as the code it lives with.
37689 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37690 look at the @file{README} file in the sources; we may have improved the
37691 installation procedures since publishing this manual.}
37692 @end iftex
37693
37694 The @value{GDBN} distribution includes all the source code you need for
37695 @value{GDBN} in a single directory, whose name is usually composed by
37696 appending the version number to @samp{gdb}.
37697
37698 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37699 @file{gdb-@value{GDBVN}} directory. That directory contains:
37700
37701 @table @code
37702 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37703 script for configuring @value{GDBN} and all its supporting libraries
37704
37705 @item gdb-@value{GDBVN}/gdb
37706 the source specific to @value{GDBN} itself
37707
37708 @item gdb-@value{GDBVN}/bfd
37709 source for the Binary File Descriptor library
37710
37711 @item gdb-@value{GDBVN}/include
37712 @sc{gnu} include files
37713
37714 @item gdb-@value{GDBVN}/libiberty
37715 source for the @samp{-liberty} free software library
37716
37717 @item gdb-@value{GDBVN}/opcodes
37718 source for the library of opcode tables and disassemblers
37719
37720 @item gdb-@value{GDBVN}/readline
37721 source for the @sc{gnu} command-line interface
37722 @end table
37723
37724 There may be other subdirectories as well.
37725
37726 The simplest way to configure and build @value{GDBN} is to run @file{configure}
37727 from the @file{gdb-@var{version-number}} source directory, which in
37728 this example is the @file{gdb-@value{GDBVN}} directory.
37729
37730 First switch to the @file{gdb-@var{version-number}} source directory
37731 if you are not already in it; then run @file{configure}. Pass the
37732 identifier for the platform on which @value{GDBN} will run as an
37733 argument.
37734
37735 For example:
37736
37737 @smallexample
37738 cd gdb-@value{GDBVN}
37739 ./configure
37740 make
37741 @end smallexample
37742
37743 Running @samp{configure} and then running @code{make} builds the
37744 included supporting libraries, then @code{gdb} itself. The configured
37745 source files, and the binaries, are left in the corresponding source
37746 directories.
37747
37748 @need 750
37749 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
37750 system does not recognize this automatically when you run a different
37751 shell, you may need to run @code{sh} on it explicitly:
37752
37753 @smallexample
37754 sh configure
37755 @end smallexample
37756
37757 You should run the @file{configure} script from the top directory in the
37758 source tree, the @file{gdb-@var{version-number}} directory. If you run
37759 @file{configure} from one of the subdirectories, you will configure only
37760 that subdirectory. That is usually not what you want. In particular,
37761 if you run the first @file{configure} from the @file{gdb} subdirectory
37762 of the @file{gdb-@var{version-number}} directory, you will omit the
37763 configuration of @file{bfd}, @file{readline}, and other sibling
37764 directories of the @file{gdb} subdirectory. This leads to build errors
37765 about missing include files such as @file{bfd/bfd.h}.
37766
37767 You can install @code{@value{GDBN}} anywhere. The best way to do this
37768 is to pass the @code{--prefix} option to @code{configure}, and then
37769 install it with @code{make install}.
37770
37771 @node Separate Objdir
37772 @section Compiling @value{GDBN} in Another Directory
37773
37774 If you want to run @value{GDBN} versions for several host or target machines,
37775 you need a different @code{gdb} compiled for each combination of
37776 host and target. @file{configure} is designed to make this easy by
37777 allowing you to generate each configuration in a separate subdirectory,
37778 rather than in the source directory. If your @code{make} program
37779 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37780 @code{make} in each of these directories builds the @code{gdb}
37781 program specified there.
37782
37783 To build @code{gdb} in a separate directory, run @file{configure}
37784 with the @samp{--srcdir} option to specify where to find the source.
37785 (You also need to specify a path to find @file{configure}
37786 itself from your working directory. If the path to @file{configure}
37787 would be the same as the argument to @samp{--srcdir}, you can leave out
37788 the @samp{--srcdir} option; it is assumed.)
37789
37790 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37791 separate directory for a Sun 4 like this:
37792
37793 @smallexample
37794 @group
37795 cd gdb-@value{GDBVN}
37796 mkdir ../gdb-sun4
37797 cd ../gdb-sun4
37798 ../gdb-@value{GDBVN}/configure
37799 make
37800 @end group
37801 @end smallexample
37802
37803 When @file{configure} builds a configuration using a remote source
37804 directory, it creates a tree for the binaries with the same structure
37805 (and using the same names) as the tree under the source directory. In
37806 the example, you'd find the Sun 4 library @file{libiberty.a} in the
37807 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37808 @file{gdb-sun4/gdb}.
37809
37810 Make sure that your path to the @file{configure} script has just one
37811 instance of @file{gdb} in it. If your path to @file{configure} looks
37812 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37813 one subdirectory of @value{GDBN}, not the whole package. This leads to
37814 build errors about missing include files such as @file{bfd/bfd.h}.
37815
37816 One popular reason to build several @value{GDBN} configurations in separate
37817 directories is to configure @value{GDBN} for cross-compiling (where
37818 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
37819 programs that run on another machine---the @dfn{target}).
37820 You specify a cross-debugging target by
37821 giving the @samp{--target=@var{target}} option to @file{configure}.
37822
37823 When you run @code{make} to build a program or library, you must run
37824 it in a configured directory---whatever directory you were in when you
37825 called @file{configure} (or one of its subdirectories).
37826
37827 The @code{Makefile} that @file{configure} generates in each source
37828 directory also runs recursively. If you type @code{make} in a source
37829 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37830 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37831 will build all the required libraries, and then build GDB.
37832
37833 When you have multiple hosts or targets configured in separate
37834 directories, you can run @code{make} on them in parallel (for example,
37835 if they are NFS-mounted on each of the hosts); they will not interfere
37836 with each other.
37837
37838 @node Config Names
37839 @section Specifying Names for Hosts and Targets
37840
37841 The specifications used for hosts and targets in the @file{configure}
37842 script are based on a three-part naming scheme, but some short predefined
37843 aliases are also supported. The full naming scheme encodes three pieces
37844 of information in the following pattern:
37845
37846 @smallexample
37847 @var{architecture}-@var{vendor}-@var{os}
37848 @end smallexample
37849
37850 For example, you can use the alias @code{sun4} as a @var{host} argument,
37851 or as the value for @var{target} in a @code{--target=@var{target}}
37852 option. The equivalent full name is @samp{sparc-sun-sunos4}.
37853
37854 The @file{configure} script accompanying @value{GDBN} does not provide
37855 any query facility to list all supported host and target names or
37856 aliases. @file{configure} calls the Bourne shell script
37857 @code{config.sub} to map abbreviations to full names; you can read the
37858 script, if you wish, or you can use it to test your guesses on
37859 abbreviations---for example:
37860
37861 @smallexample
37862 % sh config.sub i386-linux
37863 i386-pc-linux-gnu
37864 % sh config.sub alpha-linux
37865 alpha-unknown-linux-gnu
37866 % sh config.sub hp9k700
37867 hppa1.1-hp-hpux
37868 % sh config.sub sun4
37869 sparc-sun-sunos4.1.1
37870 % sh config.sub sun3
37871 m68k-sun-sunos4.1.1
37872 % sh config.sub i986v
37873 Invalid configuration `i986v': machine `i986v' not recognized
37874 @end smallexample
37875
37876 @noindent
37877 @code{config.sub} is also distributed in the @value{GDBN} source
37878 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
37879
37880 @node Configure Options
37881 @section @file{configure} Options
37882
37883 Here is a summary of the @file{configure} options and arguments that
37884 are most often useful for building @value{GDBN}. @file{configure}
37885 also has several other options not listed here. @inforef{Running
37886 configure scripts,,autoconf.info}, for a full
37887 explanation of @file{configure}.
37888
37889 @smallexample
37890 configure @r{[}--help@r{]}
37891 @r{[}--prefix=@var{dir}@r{]}
37892 @r{[}--exec-prefix=@var{dir}@r{]}
37893 @r{[}--srcdir=@var{dirname}@r{]}
37894 @r{[}--target=@var{target}@r{]}
37895 @end smallexample
37896
37897 @noindent
37898 You may introduce options with a single @samp{-} rather than
37899 @samp{--} if you prefer; but you may abbreviate option names if you use
37900 @samp{--}.
37901
37902 @table @code
37903 @item --help
37904 Display a quick summary of how to invoke @file{configure}.
37905
37906 @item --prefix=@var{dir}
37907 Configure the source to install programs and files under directory
37908 @file{@var{dir}}.
37909
37910 @item --exec-prefix=@var{dir}
37911 Configure the source to install programs under directory
37912 @file{@var{dir}}.
37913
37914 @c avoid splitting the warning from the explanation:
37915 @need 2000
37916 @item --srcdir=@var{dirname}
37917 Use this option to make configurations in directories separate from the
37918 @value{GDBN} source directories. Among other things, you can use this to
37919 build (or maintain) several configurations simultaneously, in separate
37920 directories. @file{configure} writes configuration-specific files in
37921 the current directory, but arranges for them to use the source in the
37922 directory @var{dirname}. @file{configure} creates directories under
37923 the working directory in parallel to the source directories below
37924 @var{dirname}.
37925
37926 @item --target=@var{target}
37927 Configure @value{GDBN} for cross-debugging programs running on the specified
37928 @var{target}. Without this option, @value{GDBN} is configured to debug
37929 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
37930
37931 There is no convenient way to generate a list of all available
37932 targets. Also see the @code{--enable-targets} option, below.
37933 @end table
37934
37935 There are many other options that are specific to @value{GDBN}. This
37936 lists just the most common ones; there are some very specialized
37937 options not described here.
37938
37939 @table @code
37940 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37941 @itemx --enable-targets=all
37942 Configure @value{GDBN} for cross-debugging programs running on the
37943 specified list of targets. The special value @samp{all} configures
37944 @value{GDBN} for debugging programs running on any target it supports.
37945
37946 @item --with-gdb-datadir=@var{path}
37947 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37948 here for certain supporting files or scripts. This defaults to the
37949 @file{gdb} subdirectory of @samp{datadir} (which can be set using
37950 @code{--datadir}).
37951
37952 @item --with-relocated-sources=@var{dir}
37953 Sets up the default source path substitution rule so that directory
37954 names recorded in debug information will be automatically adjusted for
37955 any directory under @var{dir}. @var{dir} should be a subdirectory of
37956 @value{GDBN}'s configured prefix, the one mentioned in the
37957 @code{--prefix} or @code{--exec-prefix} options to configure. This
37958 option is useful if GDB is supposed to be moved to a different place
37959 after it is built.
37960
37961 @item --enable-64-bit-bfd
37962 Enable 64-bit support in BFD on 32-bit hosts.
37963
37964 @item --disable-gdbmi
37965 Build @value{GDBN} without the GDB/MI machine interface
37966 (@pxref{GDB/MI}).
37967
37968 @item --enable-tui
37969 Build @value{GDBN} with the text-mode full-screen user interface
37970 (TUI). Requires a curses library (ncurses and cursesX are also
37971 supported).
37972
37973 @item --with-curses
37974 Use the curses library instead of the termcap library, for text-mode
37975 terminal operations.
37976
37977 @item --with-debuginfod
37978 Build @value{GDBN} with libdebuginfod, the debuginfod client library.
37979 Used to automatically fetch source files and separate debug files from
37980 debuginfod servers using the associated executable's build ID. Enabled
37981 by default if libdebuginfod is installed and found at configure time.
37982 debuginfod is packaged with elfutils, starting with version 0.178. You
37983 can get the latest version from `https://sourceware.org/elfutils/'.
37984
37985 @item --with-libunwind-ia64
37986 Use the libunwind library for unwinding function call stack on ia64
37987 target platforms. See http://www.nongnu.org/libunwind/index.html for
37988 details.
37989
37990 @item --with-system-readline
37991 Use the readline library installed on the host, rather than the
37992 library supplied as part of @value{GDBN}. Readline 7 or newer is
37993 required; this is enforced by the build system.
37994
37995 @item --with-system-zlib
37996 Use the zlib library installed on the host, rather than the library
37997 supplied as part of @value{GDBN}.
37998
37999 @item --with-expat
38000 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38001 default if libexpat is installed and found at configure time.) This
38002 library is used to read XML files supplied with @value{GDBN}. If it
38003 is unavailable, some features, such as remote protocol memory maps,
38004 target descriptions, and shared library lists, that are based on XML
38005 files, will not be available in @value{GDBN}. If your host does not
38006 have libexpat installed, you can get the latest version from
38007 `http://expat.sourceforge.net'.
38008
38009 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38010
38011 Build @value{GDBN} with GNU libiconv, a character set encoding
38012 conversion library. This is not done by default, as on GNU systems
38013 the @code{iconv} that is built in to the C library is sufficient. If
38014 your host does not have a working @code{iconv}, you can get the latest
38015 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38016
38017 @value{GDBN}'s build system also supports building GNU libiconv as
38018 part of the overall build. @xref{Requirements}.
38019
38020 @item --with-lzma
38021 Build @value{GDBN} with LZMA, a compression library. (Done by default
38022 if liblzma is installed and found at configure time.) LZMA is used by
38023 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
38024 platforms using the ELF object file format. If your host does not
38025 have liblzma installed, you can get the latest version from
38026 `https://tukaani.org/xz/'.
38027
38028 @item --with-mpfr
38029 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38030 floating-point computation with correct rounding. (Done by default if
38031 GNU MPFR is installed and found at configure time.) This library is
38032 used to emulate target floating-point arithmetic during expression
38033 evaluation when the target uses different floating-point formats than
38034 the host. If GNU MPFR is not available, @value{GDBN} will fall back
38035 to using host floating-point arithmetic. If your host does not have
38036 GNU MPFR installed, you can get the latest version from
38037 `http://www.mpfr.org'.
38038
38039 @item --with-python@r{[}=@var{python}@r{]}
38040 Build @value{GDBN} with Python scripting support. (Done by default if
38041 libpython is present and found at configure time.) Python makes
38042 @value{GDBN} scripting much more powerful than the restricted CLI
38043 scripting language. If your host does not have Python installed, you
38044 can find it on `http://www.python.org/download/'. The oldest version
38045 of Python supported by GDB is 2.6. The optional argument @var{python}
38046 is used to find the Python headers and libraries. It can be either
38047 the name of a Python executable, or the name of the directory in which
38048 Python is installed.
38049
38050 @item --with-guile[=GUILE]'
38051 Build @value{GDBN} with GNU Guile scripting support. (Done by default
38052 if libguile is present and found at configure time.) If your host
38053 does not have Guile installed, you can find it at
38054 `https://www.gnu.org/software/guile/'. The optional argument GUILE
38055 can be a version number, which will cause @code{configure} to try to
38056 use that version of Guile; or the file name of a @code{pkg-config}
38057 executable, which will be queried to find the information needed to
38058 compile and link against Guile.
38059
38060 @item --without-included-regex
38061 Don't use the regex library included with @value{GDBN} (as part of the
38062 libiberty library). This is the default on hosts with version 2 of
38063 the GNU C library.
38064
38065 @item --with-sysroot=@var{dir}
38066 Use @var{dir} as the default system root directory for libraries whose
38067 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38068 @var{dir} can be modified at run time by using the @command{set
38069 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38070 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38071 default system root will be automatically adjusted if and when
38072 @value{GDBN} is moved to a different location.
38073
38074 @item --with-system-gdbinit=@var{file}
38075 Configure @value{GDBN} to automatically load a system-wide init file.
38076 @var{file} should be an absolute file name. If @var{file} is in a
38077 directory under the configured prefix, and @value{GDBN} is moved to
38078 another location after being built, the location of the system-wide
38079 init file will be adjusted accordingly.
38080
38081 @item --with-system-gdbinit-dir=@var{directory}
38082 Configure @value{GDBN} to automatically load init files from a
38083 system-wide directory. @var{directory} should be an absolute directory
38084 name. If @var{directory} is in a directory under the configured
38085 prefix, and @value{GDBN} is moved to another location after being
38086 built, the location of the system-wide init directory will be
38087 adjusted accordingly.
38088
38089 @item --enable-build-warnings
38090 When building the @value{GDBN} sources, ask the compiler to warn about
38091 any code which looks even vaguely suspicious. It passes many
38092 different warning flags, depending on the exact version of the
38093 compiler you are using.
38094
38095 @item --enable-werror
38096 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38097 to the compiler, which will fail the compilation if the compiler
38098 outputs any warning messages.
38099
38100 @item --enable-ubsan
38101 Enable the GCC undefined behavior sanitizer. This is disabled by
38102 default, but passing @code{--enable-ubsan=yes} or
38103 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
38104 undefined behavior sanitizer checks for C@t{++} undefined behavior.
38105 It has a performance cost, so if you are looking at @value{GDBN}'s
38106 performance, you should disable it. The undefined behavior sanitizer
38107 was first introduced in GCC 4.9.
38108 @end table
38109
38110 @node System-wide configuration
38111 @section System-wide configuration and settings
38112 @cindex system-wide init file
38113
38114 @value{GDBN} can be configured to have a system-wide init file and a
38115 system-wide init file directory; this file and files in that directory
38116 (if they have a recognized file extension) will be read and executed at
38117 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38118
38119 Here are the corresponding configure options:
38120
38121 @table @code
38122 @item --with-system-gdbinit=@var{file}
38123 Specify that the default location of the system-wide init file is
38124 @var{file}.
38125 @item --with-system-gdbinit-dir=@var{directory}
38126 Specify that the default location of the system-wide init file directory
38127 is @var{directory}.
38128 @end table
38129
38130 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38131 they may be subject to relocation. Two possible cases:
38132
38133 @itemize @bullet
38134 @item
38135 If the default location of this init file/directory contains @file{$prefix},
38136 it will be subject to relocation. Suppose that the configure options
38137 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38138 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38139 init file is looked for as @file{$install/etc/gdbinit} instead of
38140 @file{$prefix/etc/gdbinit}.
38141
38142 @item
38143 By contrast, if the default location does not contain the prefix,
38144 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38145 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38146 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38147 wherever @value{GDBN} is installed.
38148 @end itemize
38149
38150 If the configured location of the system-wide init file (as given by the
38151 @option{--with-system-gdbinit} option at configure time) is in the
38152 data-directory (as specified by @option{--with-gdb-datadir} at configure
38153 time) or in one of its subdirectories, then @value{GDBN} will look for the
38154 system-wide init file in the directory specified by the
38155 @option{--data-directory} command-line option.
38156 Note that the system-wide init file is only read once, during @value{GDBN}
38157 initialization. If the data-directory is changed after @value{GDBN} has
38158 started with the @code{set data-directory} command, the file will not be
38159 reread.
38160
38161 This applies similarly to the system-wide directory specified in
38162 @option{--with-system-gdbinit-dir}.
38163
38164 Any supported scripting language can be used for these init files, as long
38165 as the file extension matches the scripting language. To be interpreted
38166 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38167 extension.
38168
38169 @menu
38170 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38171 @end menu
38172
38173 @node System-wide Configuration Scripts
38174 @subsection Installed System-wide Configuration Scripts
38175 @cindex system-wide configuration scripts
38176
38177 The @file{system-gdbinit} directory, located inside the data-directory
38178 (as specified by @option{--with-gdb-datadir} at configure time) contains
38179 a number of scripts which can be used as system-wide init files. To
38180 automatically source those scripts at startup, @value{GDBN} should be
38181 configured with @option{--with-system-gdbinit}. Otherwise, any user
38182 should be able to source them by hand as needed.
38183
38184 The following scripts are currently available:
38185 @itemize @bullet
38186
38187 @item @file{elinos.py}
38188 @pindex elinos.py
38189 @cindex ELinOS system-wide configuration script
38190 This script is useful when debugging a program on an ELinOS target.
38191 It takes advantage of the environment variables defined in a standard
38192 ELinOS environment in order to determine the location of the system
38193 shared libraries, and then sets the @samp{solib-absolute-prefix}
38194 and @samp{solib-search-path} variables appropriately.
38195
38196 @item @file{wrs-linux.py}
38197 @pindex wrs-linux.py
38198 @cindex Wind River Linux system-wide configuration script
38199 This script is useful when debugging a program on a target running
38200 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38201 the host-side sysroot used by the target system.
38202
38203 @end itemize
38204
38205 @node Maintenance Commands
38206 @appendix Maintenance Commands
38207 @cindex maintenance commands
38208 @cindex internal commands
38209
38210 In addition to commands intended for @value{GDBN} users, @value{GDBN}
38211 includes a number of commands intended for @value{GDBN} developers,
38212 that are not documented elsewhere in this manual. These commands are
38213 provided here for reference. (For commands that turn on debugging
38214 messages, see @ref{Debugging Output}.)
38215
38216 @table @code
38217 @kindex maint agent
38218 @kindex maint agent-eval
38219 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38220 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38221 Translate the given @var{expression} into remote agent bytecodes.
38222 This command is useful for debugging the Agent Expression mechanism
38223 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38224 expression useful for data collection, such as by tracepoints, while
38225 @samp{maint agent-eval} produces an expression that evaluates directly
38226 to a result. For instance, a collection expression for @code{globa +
38227 globb} will include bytecodes to record four bytes of memory at each
38228 of the addresses of @code{globa} and @code{globb}, while discarding
38229 the result of the addition, while an evaluation expression will do the
38230 addition and return the sum.
38231 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38232 If not, generate remote agent bytecode for current frame PC address.
38233
38234 @kindex maint agent-printf
38235 @item maint agent-printf @var{format},@var{expr},...
38236 Translate the given format string and list of argument expressions
38237 into remote agent bytecodes and display them as a disassembled list.
38238 This command is useful for debugging the agent version of dynamic
38239 printf (@pxref{Dynamic Printf}).
38240
38241 @kindex maint info breakpoints
38242 @item @anchor{maint info breakpoints}maint info breakpoints
38243 Using the same format as @samp{info breakpoints}, display both the
38244 breakpoints you've set explicitly, and those @value{GDBN} is using for
38245 internal purposes. Internal breakpoints are shown with negative
38246 breakpoint numbers. The type column identifies what kind of breakpoint
38247 is shown:
38248
38249 @table @code
38250 @item breakpoint
38251 Normal, explicitly set breakpoint.
38252
38253 @item watchpoint
38254 Normal, explicitly set watchpoint.
38255
38256 @item longjmp
38257 Internal breakpoint, used to handle correctly stepping through
38258 @code{longjmp} calls.
38259
38260 @item longjmp resume
38261 Internal breakpoint at the target of a @code{longjmp}.
38262
38263 @item until
38264 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38265
38266 @item finish
38267 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38268
38269 @item shlib events
38270 Shared library events.
38271
38272 @end table
38273
38274 @kindex maint info btrace
38275 @item maint info btrace
38276 Pint information about raw branch tracing data.
38277
38278 @kindex maint btrace packet-history
38279 @item maint btrace packet-history
38280 Print the raw branch trace packets that are used to compute the
38281 execution history for the @samp{record btrace} command. Both the
38282 information and the format in which it is printed depend on the btrace
38283 recording format.
38284
38285 @table @code
38286 @item bts
38287 For the BTS recording format, print a list of blocks of sequential
38288 code. For each block, the following information is printed:
38289
38290 @table @asis
38291 @item Block number
38292 Newer blocks have higher numbers. The oldest block has number zero.
38293 @item Lowest @samp{PC}
38294 @item Highest @samp{PC}
38295 @end table
38296
38297 @item pt
38298 For the Intel Processor Trace recording format, print a list of
38299 Intel Processor Trace packets. For each packet, the following
38300 information is printed:
38301
38302 @table @asis
38303 @item Packet number
38304 Newer packets have higher numbers. The oldest packet has number zero.
38305 @item Trace offset
38306 The packet's offset in the trace stream.
38307 @item Packet opcode and payload
38308 @end table
38309 @end table
38310
38311 @kindex maint btrace clear-packet-history
38312 @item maint btrace clear-packet-history
38313 Discards the cached packet history printed by the @samp{maint btrace
38314 packet-history} command. The history will be computed again when
38315 needed.
38316
38317 @kindex maint btrace clear
38318 @item maint btrace clear
38319 Discard the branch trace data. The data will be fetched anew and the
38320 branch trace will be recomputed when needed.
38321
38322 This implicitly truncates the branch trace to a single branch trace
38323 buffer. When updating branch trace incrementally, the branch trace
38324 available to @value{GDBN} may be bigger than a single branch trace
38325 buffer.
38326
38327 @kindex maint set btrace pt skip-pad
38328 @item maint set btrace pt skip-pad
38329 @kindex maint show btrace pt skip-pad
38330 @item maint show btrace pt skip-pad
38331 Control whether @value{GDBN} will skip PAD packets when computing the
38332 packet history.
38333
38334 @kindex set displaced-stepping
38335 @kindex show displaced-stepping
38336 @cindex displaced stepping support
38337 @cindex out-of-line single-stepping
38338 @item set displaced-stepping
38339 @itemx show displaced-stepping
38340 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38341 if the target supports it. Displaced stepping is a way to single-step
38342 over breakpoints without removing them from the inferior, by executing
38343 an out-of-line copy of the instruction that was originally at the
38344 breakpoint location. It is also known as out-of-line single-stepping.
38345
38346 @table @code
38347 @item set displaced-stepping on
38348 If the target architecture supports it, @value{GDBN} will use
38349 displaced stepping to step over breakpoints.
38350
38351 @item set displaced-stepping off
38352 @value{GDBN} will not use displaced stepping to step over breakpoints,
38353 even if such is supported by the target architecture.
38354
38355 @cindex non-stop mode, and @samp{set displaced-stepping}
38356 @item set displaced-stepping auto
38357 This is the default mode. @value{GDBN} will use displaced stepping
38358 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38359 architecture supports displaced stepping.
38360 @end table
38361
38362 @kindex maint check-psymtabs
38363 @item maint check-psymtabs
38364 Check the consistency of currently expanded psymtabs versus symtabs.
38365 Use this to check, for example, whether a symbol is in one but not the other.
38366
38367 @kindex maint check-symtabs
38368 @item maint check-symtabs
38369 Check the consistency of currently expanded symtabs.
38370
38371 @kindex maint expand-symtabs
38372 @item maint expand-symtabs [@var{regexp}]
38373 Expand symbol tables.
38374 If @var{regexp} is specified, only expand symbol tables for file
38375 names matching @var{regexp}.
38376
38377 @kindex maint set catch-demangler-crashes
38378 @kindex maint show catch-demangler-crashes
38379 @cindex demangler crashes
38380 @item maint set catch-demangler-crashes [on|off]
38381 @itemx maint show catch-demangler-crashes
38382 Control whether @value{GDBN} should attempt to catch crashes in the
38383 symbol name demangler. The default is to attempt to catch crashes.
38384 If enabled, the first time a crash is caught, a core file is created,
38385 the offending symbol is displayed and the user is presented with the
38386 option to terminate the current session.
38387
38388 @kindex maint cplus first_component
38389 @item maint cplus first_component @var{name}
38390 Print the first C@t{++} class/namespace component of @var{name}.
38391
38392 @kindex maint cplus namespace
38393 @item maint cplus namespace
38394 Print the list of possible C@t{++} namespaces.
38395
38396 @kindex maint deprecate
38397 @kindex maint undeprecate
38398 @cindex deprecated commands
38399 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38400 @itemx maint undeprecate @var{command}
38401 Deprecate or undeprecate the named @var{command}. Deprecated commands
38402 cause @value{GDBN} to issue a warning when you use them. The optional
38403 argument @var{replacement} says which newer command should be used in
38404 favor of the deprecated one; if it is given, @value{GDBN} will mention
38405 the replacement as part of the warning.
38406
38407 @kindex maint dump-me
38408 @item maint dump-me
38409 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38410 Cause a fatal signal in the debugger and force it to dump its core.
38411 This is supported only on systems which support aborting a program
38412 with the @code{SIGQUIT} signal.
38413
38414 @kindex maint internal-error
38415 @kindex maint internal-warning
38416 @kindex maint demangler-warning
38417 @cindex demangler crashes
38418 @item maint internal-error @r{[}@var{message-text}@r{]}
38419 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38420 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38421
38422 Cause @value{GDBN} to call the internal function @code{internal_error},
38423 @code{internal_warning} or @code{demangler_warning} and hence behave
38424 as though an internal problem has been detected. In addition to
38425 reporting the internal problem, these functions give the user the
38426 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38427 and @code{internal_warning}) create a core file of the current
38428 @value{GDBN} session.
38429
38430 These commands take an optional parameter @var{message-text} that is
38431 used as the text of the error or warning message.
38432
38433 Here's an example of using @code{internal-error}:
38434
38435 @smallexample
38436 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38437 @dots{}/maint.c:121: internal-error: testing, 1, 2
38438 A problem internal to GDB has been detected. Further
38439 debugging may prove unreliable.
38440 Quit this debugging session? (y or n) @kbd{n}
38441 Create a core file? (y or n) @kbd{n}
38442 (@value{GDBP})
38443 @end smallexample
38444
38445 @cindex @value{GDBN} internal error
38446 @cindex internal errors, control of @value{GDBN} behavior
38447 @cindex demangler crashes
38448
38449 @kindex maint set internal-error
38450 @kindex maint show internal-error
38451 @kindex maint set internal-warning
38452 @kindex maint show internal-warning
38453 @kindex maint set demangler-warning
38454 @kindex maint show demangler-warning
38455 @item maint set internal-error @var{action} [ask|yes|no]
38456 @itemx maint show internal-error @var{action}
38457 @itemx maint set internal-warning @var{action} [ask|yes|no]
38458 @itemx maint show internal-warning @var{action}
38459 @itemx maint set demangler-warning @var{action} [ask|yes|no]
38460 @itemx maint show demangler-warning @var{action}
38461 When @value{GDBN} reports an internal problem (error or warning) it
38462 gives the user the opportunity to both quit @value{GDBN} and create a
38463 core file of the current @value{GDBN} session. These commands let you
38464 override the default behaviour for each particular @var{action},
38465 described in the table below.
38466
38467 @table @samp
38468 @item quit
38469 You can specify that @value{GDBN} should always (yes) or never (no)
38470 quit. The default is to ask the user what to do.
38471
38472 @item corefile
38473 You can specify that @value{GDBN} should always (yes) or never (no)
38474 create a core file. The default is to ask the user what to do. Note
38475 that there is no @code{corefile} option for @code{demangler-warning}:
38476 demangler warnings always create a core file and this cannot be
38477 disabled.
38478 @end table
38479
38480 @kindex maint packet
38481 @item maint packet @var{text}
38482 If @value{GDBN} is talking to an inferior via the serial protocol,
38483 then this command sends the string @var{text} to the inferior, and
38484 displays the response packet. @value{GDBN} supplies the initial
38485 @samp{$} character, the terminating @samp{#} character, and the
38486 checksum.
38487
38488 @kindex maint print architecture
38489 @item maint print architecture @r{[}@var{file}@r{]}
38490 Print the entire architecture configuration. The optional argument
38491 @var{file} names the file where the output goes.
38492
38493 @kindex maint print c-tdesc @r{[}@var{file}@r{]}
38494 @item maint print c-tdesc
38495 Print the target description (@pxref{Target Descriptions}) as
38496 a C source file. By default, the target description is for the current
38497 target, but if the optional argument @var{file} is provided, that file
38498 is used to produce the description. The @var{file} should be an XML
38499 document, of the form described in @ref{Target Description Format}.
38500 The created source file is built into @value{GDBN} when @value{GDBN} is
38501 built again. This command is used by developers after they add or
38502 modify XML target descriptions.
38503
38504 @kindex maint print xml-tdesc
38505 @item maint print xml-tdesc @r{[}@var{file}@r{]}
38506 Print the target description (@pxref{Target Descriptions}) as an XML
38507 file. By default print the target description for the current target,
38508 but if the optional argument @var{file} is provided, then that file is
38509 read in by GDB and then used to produce the description. The
38510 @var{file} should be an XML document, of the form described in
38511 @ref{Target Description Format}.
38512
38513 @kindex maint check xml-descriptions
38514 @item maint check xml-descriptions @var{dir}
38515 Check that the target descriptions dynamically created by @value{GDBN}
38516 equal the descriptions created from XML files found in @var{dir}.
38517
38518 @anchor{maint check libthread-db}
38519 @kindex maint check libthread-db
38520 @item maint check libthread-db
38521 Run integrity checks on the current inferior's thread debugging
38522 library. This exercises all @code{libthread_db} functionality used by
38523 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
38524 @code{proc_service} functions provided by @value{GDBN} that
38525 @code{libthread_db} uses. Note that parts of the test may be skipped
38526 on some platforms when debugging core files.
38527
38528 @kindex maint print dummy-frames
38529 @item maint print dummy-frames
38530 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38531
38532 @smallexample
38533 (@value{GDBP}) @kbd{b add}
38534 @dots{}
38535 (@value{GDBP}) @kbd{print add(2,3)}
38536 Breakpoint 2, add (a=2, b=3) at @dots{}
38537 58 return (a + b);
38538 The program being debugged stopped while in a function called from GDB.
38539 @dots{}
38540 (@value{GDBP}) @kbd{maint print dummy-frames}
38541 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
38542 (@value{GDBP})
38543 @end smallexample
38544
38545 Takes an optional file parameter.
38546
38547 @kindex maint print registers
38548 @kindex maint print raw-registers
38549 @kindex maint print cooked-registers
38550 @kindex maint print register-groups
38551 @kindex maint print remote-registers
38552 @item maint print registers @r{[}@var{file}@r{]}
38553 @itemx maint print raw-registers @r{[}@var{file}@r{]}
38554 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
38555 @itemx maint print register-groups @r{[}@var{file}@r{]}
38556 @itemx maint print remote-registers @r{[}@var{file}@r{]}
38557 Print @value{GDBN}'s internal register data structures.
38558
38559 The command @code{maint print raw-registers} includes the contents of
38560 the raw register cache; the command @code{maint print
38561 cooked-registers} includes the (cooked) value of all registers,
38562 including registers which aren't available on the target nor visible
38563 to user; the command @code{maint print register-groups} includes the
38564 groups that each register is a member of; and the command @code{maint
38565 print remote-registers} includes the remote target's register numbers
38566 and offsets in the `G' packets.
38567
38568 These commands take an optional parameter, a file name to which to
38569 write the information.
38570
38571 @kindex maint print reggroups
38572 @item maint print reggroups @r{[}@var{file}@r{]}
38573 Print @value{GDBN}'s internal register group data structures. The
38574 optional argument @var{file} tells to what file to write the
38575 information.
38576
38577 The register groups info looks like this:
38578
38579 @smallexample
38580 (@value{GDBP}) @kbd{maint print reggroups}
38581 Group Type
38582 general user
38583 float user
38584 all user
38585 vector user
38586 system user
38587 save internal
38588 restore internal
38589 @end smallexample
38590
38591 @kindex flushregs
38592 @item flushregs
38593 This command forces @value{GDBN} to flush its internal register cache.
38594
38595 @kindex maint print objfiles
38596 @cindex info for known object files
38597 @item maint print objfiles @r{[}@var{regexp}@r{]}
38598 Print a dump of all known object files.
38599 If @var{regexp} is specified, only print object files whose names
38600 match @var{regexp}. For each object file, this command prints its name,
38601 address in memory, and all of its psymtabs and symtabs.
38602
38603 @kindex maint print user-registers
38604 @cindex user registers
38605 @item maint print user-registers
38606 List all currently available @dfn{user registers}. User registers
38607 typically provide alternate names for actual hardware registers. They
38608 include the four ``standard'' registers @code{$fp}, @code{$pc},
38609 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
38610 registers can be used in expressions in the same way as the canonical
38611 register names, but only the latter are listed by the @code{info
38612 registers} and @code{maint print registers} commands.
38613
38614 @kindex maint print section-scripts
38615 @cindex info for known .debug_gdb_scripts-loaded scripts
38616 @item maint print section-scripts [@var{regexp}]
38617 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38618 If @var{regexp} is specified, only print scripts loaded by object files
38619 matching @var{regexp}.
38620 For each script, this command prints its name as specified in the objfile,
38621 and the full path if known.
38622 @xref{dotdebug_gdb_scripts section}.
38623
38624 @kindex maint print statistics
38625 @cindex bcache statistics
38626 @item maint print statistics
38627 This command prints, for each object file in the program, various data
38628 about that object file followed by the byte cache (@dfn{bcache})
38629 statistics for the object file. The objfile data includes the number
38630 of minimal, partial, full, and stabs symbols, the number of types
38631 defined by the objfile, the number of as yet unexpanded psym tables,
38632 the number of line tables and string tables, and the amount of memory
38633 used by the various tables. The bcache statistics include the counts,
38634 sizes, and counts of duplicates of all and unique objects, max,
38635 average, and median entry size, total memory used and its overhead and
38636 savings, and various measures of the hash table size and chain
38637 lengths.
38638
38639 @kindex maint print target-stack
38640 @cindex target stack description
38641 @item maint print target-stack
38642 A @dfn{target} is an interface between the debugger and a particular
38643 kind of file or process. Targets can be stacked in @dfn{strata},
38644 so that more than one target can potentially respond to a request.
38645 In particular, memory accesses will walk down the stack of targets
38646 until they find a target that is interested in handling that particular
38647 address.
38648
38649 This command prints a short description of each layer that was pushed on
38650 the @dfn{target stack}, starting from the top layer down to the bottom one.
38651
38652 @kindex maint print type
38653 @cindex type chain of a data type
38654 @item maint print type @var{expr}
38655 Print the type chain for a type specified by @var{expr}. The argument
38656 can be either a type name or a symbol. If it is a symbol, the type of
38657 that symbol is described. The type chain produced by this command is
38658 a recursive definition of the data type as stored in @value{GDBN}'s
38659 data structures, including its flags and contained types.
38660
38661 @kindex maint selftest
38662 @cindex self tests
38663 @item maint selftest @r{[}@var{filter}@r{]}
38664 Run any self tests that were compiled in to @value{GDBN}. This will
38665 print a message showing how many tests were run, and how many failed.
38666 If a @var{filter} is passed, only the tests with @var{filter} in their
38667 name will by ran.
38668
38669 @kindex maint info selftests
38670 @cindex self tests
38671 @item maint info selftests
38672 List the selftests compiled in to @value{GDBN}.
38673
38674 @kindex maint set dwarf always-disassemble
38675 @kindex maint show dwarf always-disassemble
38676 @item maint set dwarf always-disassemble
38677 @item maint show dwarf always-disassemble
38678 Control the behavior of @code{info address} when using DWARF debugging
38679 information.
38680
38681 The default is @code{off}, which means that @value{GDBN} should try to
38682 describe a variable's location in an easily readable format. When
38683 @code{on}, @value{GDBN} will instead display the DWARF location
38684 expression in an assembly-like format. Note that some locations are
38685 too complex for @value{GDBN} to describe simply; in this case you will
38686 always see the disassembly form.
38687
38688 Here is an example of the resulting disassembly:
38689
38690 @smallexample
38691 (gdb) info addr argc
38692 Symbol "argc" is a complex DWARF expression:
38693 1: DW_OP_fbreg 0
38694 @end smallexample
38695
38696 For more information on these expressions, see
38697 @uref{http://www.dwarfstd.org/, the DWARF standard}.
38698
38699 @kindex maint set dwarf max-cache-age
38700 @kindex maint show dwarf max-cache-age
38701 @item maint set dwarf max-cache-age
38702 @itemx maint show dwarf max-cache-age
38703 Control the DWARF compilation unit cache.
38704
38705 @cindex DWARF compilation units cache
38706 In object files with inter-compilation-unit references, such as those
38707 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
38708 reader needs to frequently refer to previously read compilation units.
38709 This setting controls how long a compilation unit will remain in the
38710 cache if it is not referenced. A higher limit means that cached
38711 compilation units will be stored in memory longer, and more total
38712 memory will be used. Setting it to zero disables caching, which will
38713 slow down @value{GDBN} startup, but reduce memory consumption.
38714
38715 @kindex maint set dwarf unwinders
38716 @kindex maint show dwarf unwinders
38717 @item maint set dwarf unwinders
38718 @itemx maint show dwarf unwinders
38719 Control use of the DWARF frame unwinders.
38720
38721 @cindex DWARF frame unwinders
38722 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38723 frame unwinders to build the backtrace. Many of these targets will
38724 also have a second mechanism for building the backtrace for use in
38725 cases where DWARF information is not available, this second mechanism
38726 is often an analysis of a function's prologue.
38727
38728 In order to extend testing coverage of the second level stack
38729 unwinding mechanisms it is helpful to be able to disable the DWARF
38730 stack unwinders, this can be done with this switch.
38731
38732 In normal use of @value{GDBN} disabling the DWARF unwinders is not
38733 advisable, there are cases that are better handled through DWARF than
38734 prologue analysis, and the debug experience is likely to be better
38735 with the DWARF frame unwinders enabled.
38736
38737 If DWARF frame unwinders are not supported for a particular target
38738 architecture, then enabling this flag does not cause them to be used.
38739
38740 @kindex maint set worker-threads
38741 @kindex maint show worker-threads
38742 @item maint set worker-threads
38743 @item maint show worker-threads
38744 Control the number of worker threads that may be used by @value{GDBN}.
38745 On capable hosts, @value{GDBN} may use multiple threads to speed up
38746 certain CPU-intensive operations, such as demangling symbol names.
38747 While the number of threads used by @value{GDBN} may vary, this
38748 command can be used to set an upper bound on this number. The default
38749 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38750 number. Note that this only controls worker threads started by
38751 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
38752 of their own.
38753
38754 @kindex maint set profile
38755 @kindex maint show profile
38756 @cindex profiling GDB
38757 @item maint set profile
38758 @itemx maint show profile
38759 Control profiling of @value{GDBN}.
38760
38761 Profiling will be disabled until you use the @samp{maint set profile}
38762 command to enable it. When you enable profiling, the system will begin
38763 collecting timing and execution count data; when you disable profiling or
38764 exit @value{GDBN}, the results will be written to a log file. Remember that
38765 if you use profiling, @value{GDBN} will overwrite the profiling log file
38766 (often called @file{gmon.out}). If you have a record of important profiling
38767 data in a @file{gmon.out} file, be sure to move it to a safe location.
38768
38769 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
38770 compiled with the @samp{-pg} compiler option.
38771
38772 @kindex maint set show-debug-regs
38773 @kindex maint show show-debug-regs
38774 @cindex hardware debug registers
38775 @item maint set show-debug-regs
38776 @itemx maint show show-debug-regs
38777 Control whether to show variables that mirror the hardware debug
38778 registers. Use @code{on} to enable, @code{off} to disable. If
38779 enabled, the debug registers values are shown when @value{GDBN} inserts or
38780 removes a hardware breakpoint or watchpoint, and when the inferior
38781 triggers a hardware-assisted breakpoint or watchpoint.
38782
38783 @kindex maint set show-all-tib
38784 @kindex maint show show-all-tib
38785 @item maint set show-all-tib
38786 @itemx maint show show-all-tib
38787 Control whether to show all non zero areas within a 1k block starting
38788 at thread local base, when using the @samp{info w32 thread-information-block}
38789 command.
38790
38791 @kindex maint set target-async
38792 @kindex maint show target-async
38793 @item maint set target-async
38794 @itemx maint show target-async
38795 This controls whether @value{GDBN} targets operate in synchronous or
38796 asynchronous mode (@pxref{Background Execution}). Normally the
38797 default is asynchronous, if it is available; but this can be changed
38798 to more easily debug problems occurring only in synchronous mode.
38799
38800 @kindex maint set target-non-stop @var{mode} [on|off|auto]
38801 @kindex maint show target-non-stop
38802 @item maint set target-non-stop
38803 @itemx maint show target-non-stop
38804
38805 This controls whether @value{GDBN} targets always operate in non-stop
38806 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38807 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38808 if supported by the target.
38809
38810 @table @code
38811 @item maint set target-non-stop auto
38812 This is the default mode. @value{GDBN} controls the target in
38813 non-stop mode if the target supports it.
38814
38815 @item maint set target-non-stop on
38816 @value{GDBN} controls the target in non-stop mode even if the target
38817 does not indicate support.
38818
38819 @item maint set target-non-stop off
38820 @value{GDBN} does not control the target in non-stop mode even if the
38821 target supports it.
38822 @end table
38823
38824 @kindex maint set tui-resize-message
38825 @kindex maint show tui-resize-message
38826 @item maint set tui-resize-message
38827 @item maint show tui-resize-message
38828 Control whether @value{GDBN} displays a message each time the terminal
38829 is resized when in TUI mode. The default is @code{off}, which means
38830 that @value{GDBN} is silent during resizes. When @code{on},
38831 @value{GDBN} will display a message after a resize is completed; the
38832 message will include a number indicating how many times the terminal
38833 has been resized. This setting is intended for use by the test suite,
38834 where it would otherwise be difficult to determine when a resize and
38835 refresh has been completed.
38836
38837 @kindex maint set per-command
38838 @kindex maint show per-command
38839 @item maint set per-command
38840 @itemx maint show per-command
38841 @cindex resources used by commands
38842
38843 @value{GDBN} can display the resources used by each command.
38844 This is useful in debugging performance problems.
38845
38846 @table @code
38847 @item maint set per-command space [on|off]
38848 @itemx maint show per-command space
38849 Enable or disable the printing of the memory used by GDB for each command.
38850 If enabled, @value{GDBN} will display how much memory each command
38851 took, following the command's own output.
38852 This can also be requested by invoking @value{GDBN} with the
38853 @option{--statistics} command-line switch (@pxref{Mode Options}).
38854
38855 @item maint set per-command time [on|off]
38856 @itemx maint show per-command time
38857 Enable or disable the printing of the execution time of @value{GDBN}
38858 for each command.
38859 If enabled, @value{GDBN} will display how much time it
38860 took to execute each command, following the command's own output.
38861 Both CPU time and wallclock time are printed.
38862 Printing both is useful when trying to determine whether the cost is
38863 CPU or, e.g., disk/network latency.
38864 Note that the CPU time printed is for @value{GDBN} only, it does not include
38865 the execution time of the inferior because there's no mechanism currently
38866 to compute how much time was spent by @value{GDBN} and how much time was
38867 spent by the program been debugged.
38868 This can also be requested by invoking @value{GDBN} with the
38869 @option{--statistics} command-line switch (@pxref{Mode Options}).
38870
38871 @item maint set per-command symtab [on|off]
38872 @itemx maint show per-command symtab
38873 Enable or disable the printing of basic symbol table statistics
38874 for each command.
38875 If enabled, @value{GDBN} will display the following information:
38876
38877 @enumerate a
38878 @item
38879 number of symbol tables
38880 @item
38881 number of primary symbol tables
38882 @item
38883 number of blocks in the blockvector
38884 @end enumerate
38885 @end table
38886
38887 @kindex maint set check-libthread-db
38888 @kindex maint show check-libthread-db
38889 @item maint set check-libthread-db [on|off]
38890 @itemx maint show check-libthread-db
38891 Control whether @value{GDBN} should run integrity checks on inferior
38892 specific thread debugging libraries as they are loaded. The default
38893 is not to perform such checks. If any check fails @value{GDBN} will
38894 unload the library and continue searching for a suitable candidate as
38895 described in @ref{set libthread-db-search-path}. For more information
38896 about the tests, see @ref{maint check libthread-db}.
38897
38898 @kindex maint space
38899 @cindex memory used by commands
38900 @item maint space @var{value}
38901 An alias for @code{maint set per-command space}.
38902 A non-zero value enables it, zero disables it.
38903
38904 @kindex maint time
38905 @cindex time of command execution
38906 @item maint time @var{value}
38907 An alias for @code{maint set per-command time}.
38908 A non-zero value enables it, zero disables it.
38909
38910 @kindex maint translate-address
38911 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38912 Find the symbol stored at the location specified by the address
38913 @var{addr} and an optional section name @var{section}. If found,
38914 @value{GDBN} prints the name of the closest symbol and an offset from
38915 the symbol's location to the specified address. This is similar to
38916 the @code{info address} command (@pxref{Symbols}), except that this
38917 command also allows to find symbols in other sections.
38918
38919 If section was not specified, the section in which the symbol was found
38920 is also printed. For dynamically linked executables, the name of
38921 executable or shared library containing the symbol is printed as well.
38922
38923 @kindex maint test-options
38924 @item maint test-options require-delimiter
38925 @itemx maint test-options unknown-is-error
38926 @itemx maint test-options unknown-is-operand
38927 These commands are used by the testsuite to validate the command
38928 options framework. The @code{require-delimiter} variant requires a
38929 double-dash delimiter to indicate end of options. The
38930 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
38931 @code{unknown-is-error} variant throws an error on unknown option,
38932 while @code{unknown-is-operand} treats unknown options as the start of
38933 the command's operands. When run, the commands output the result of
38934 the processed options. When completed, the commands store the
38935 internal result of completion in a variable exposed by the @code{maint
38936 show test-options-completion-result} command.
38937
38938 @kindex maint show test-options-completion-result
38939 @item maint show test-options-completion-result
38940 Shows the result of completing the @code{maint test-options}
38941 subcommands. This is used by the testsuite to validate completion
38942 support in the command options framework.
38943
38944 @kindex maint set test-settings
38945 @kindex maint show test-settings
38946 @item maint set test-settings @var{kind}
38947 @itemx maint show test-settings @var{kind}
38948 These are representative commands for each @var{kind} of setting type
38949 @value{GDBN} supports. They are used by the testsuite for exercising
38950 the settings infrastructure.
38951
38952 @kindex maint with
38953 @item maint with @var{setting} [@var{value}] [-- @var{command}]
38954 Like the @code{with} command, but works with @code{maintenance set}
38955 variables. This is used by the testsuite to exercise the @code{with}
38956 command's infrastructure.
38957
38958 @end table
38959
38960 The following command is useful for non-interactive invocations of
38961 @value{GDBN}, such as in the test suite.
38962
38963 @table @code
38964 @item set watchdog @var{nsec}
38965 @kindex set watchdog
38966 @cindex watchdog timer
38967 @cindex timeout for commands
38968 Set the maximum number of seconds @value{GDBN} will wait for the
38969 target operation to finish. If this time expires, @value{GDBN}
38970 reports and error and the command is aborted.
38971
38972 @item show watchdog
38973 Show the current setting of the target wait timeout.
38974 @end table
38975
38976 @node Remote Protocol
38977 @appendix @value{GDBN} Remote Serial Protocol
38978
38979 @menu
38980 * Overview::
38981 * Packets::
38982 * Stop Reply Packets::
38983 * General Query Packets::
38984 * Architecture-Specific Protocol Details::
38985 * Tracepoint Packets::
38986 * Host I/O Packets::
38987 * Interrupts::
38988 * Notification Packets::
38989 * Remote Non-Stop::
38990 * Packet Acknowledgment::
38991 * Examples::
38992 * File-I/O Remote Protocol Extension::
38993 * Library List Format::
38994 * Library List Format for SVR4 Targets::
38995 * Memory Map Format::
38996 * Thread List Format::
38997 * Traceframe Info Format::
38998 * Branch Trace Format::
38999 * Branch Trace Configuration Format::
39000 @end menu
39001
39002 @node Overview
39003 @section Overview
39004
39005 There may be occasions when you need to know something about the
39006 protocol---for example, if there is only one serial port to your target
39007 machine, you might want your program to do something special if it
39008 recognizes a packet meant for @value{GDBN}.
39009
39010 In the examples below, @samp{->} and @samp{<-} are used to indicate
39011 transmitted and received data, respectively.
39012
39013 @cindex protocol, @value{GDBN} remote serial
39014 @cindex serial protocol, @value{GDBN} remote
39015 @cindex remote serial protocol
39016 All @value{GDBN} commands and responses (other than acknowledgments
39017 and notifications, see @ref{Notification Packets}) are sent as a
39018 @var{packet}. A @var{packet} is introduced with the character
39019 @samp{$}, the actual @var{packet-data}, and the terminating character
39020 @samp{#} followed by a two-digit @var{checksum}:
39021
39022 @smallexample
39023 @code{$}@var{packet-data}@code{#}@var{checksum}
39024 @end smallexample
39025 @noindent
39026
39027 @cindex checksum, for @value{GDBN} remote
39028 @noindent
39029 The two-digit @var{checksum} is computed as the modulo 256 sum of all
39030 characters between the leading @samp{$} and the trailing @samp{#} (an
39031 eight bit unsigned checksum).
39032
39033 Implementors should note that prior to @value{GDBN} 5.0 the protocol
39034 specification also included an optional two-digit @var{sequence-id}:
39035
39036 @smallexample
39037 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
39038 @end smallexample
39039
39040 @cindex sequence-id, for @value{GDBN} remote
39041 @noindent
39042 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39043 has never output @var{sequence-id}s. Stubs that handle packets added
39044 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
39045
39046 When either the host or the target machine receives a packet, the first
39047 response expected is an acknowledgment: either @samp{+} (to indicate
39048 the package was received correctly) or @samp{-} (to request
39049 retransmission):
39050
39051 @smallexample
39052 -> @code{$}@var{packet-data}@code{#}@var{checksum}
39053 <- @code{+}
39054 @end smallexample
39055 @noindent
39056
39057 The @samp{+}/@samp{-} acknowledgments can be disabled
39058 once a connection is established.
39059 @xref{Packet Acknowledgment}, for details.
39060
39061 The host (@value{GDBN}) sends @var{command}s, and the target (the
39062 debugging stub incorporated in your program) sends a @var{response}. In
39063 the case of step and continue @var{command}s, the response is only sent
39064 when the operation has completed, and the target has again stopped all
39065 threads in all attached processes. This is the default all-stop mode
39066 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39067 execution mode; see @ref{Remote Non-Stop}, for details.
39068
39069 @var{packet-data} consists of a sequence of characters with the
39070 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39071 exceptions).
39072
39073 @cindex remote protocol, field separator
39074 Fields within the packet should be separated using @samp{,} @samp{;} or
39075 @samp{:}. Except where otherwise noted all numbers are represented in
39076 @sc{hex} with leading zeros suppressed.
39077
39078 Implementors should note that prior to @value{GDBN} 5.0, the character
39079 @samp{:} could not appear as the third character in a packet (as it
39080 would potentially conflict with the @var{sequence-id}).
39081
39082 @cindex remote protocol, binary data
39083 @anchor{Binary Data}
39084 Binary data in most packets is encoded either as two hexadecimal
39085 digits per byte of binary data. This allowed the traditional remote
39086 protocol to work over connections which were only seven-bit clean.
39087 Some packets designed more recently assume an eight-bit clean
39088 connection, and use a more efficient encoding to send and receive
39089 binary data.
39090
39091 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39092 as an escape character. Any escaped byte is transmitted as the escape
39093 character followed by the original character XORed with @code{0x20}.
39094 For example, the byte @code{0x7d} would be transmitted as the two
39095 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39096 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39097 @samp{@}}) must always be escaped. Responses sent by the stub
39098 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39099 is not interpreted as the start of a run-length encoded sequence
39100 (described next).
39101
39102 Response @var{data} can be run-length encoded to save space.
39103 Run-length encoding replaces runs of identical characters with one
39104 instance of the repeated character, followed by a @samp{*} and a
39105 repeat count. The repeat count is itself sent encoded, to avoid
39106 binary characters in @var{data}: a value of @var{n} is sent as
39107 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
39108 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39109 code 32) for a repeat count of 3. (This is because run-length
39110 encoding starts to win for counts 3 or more.) Thus, for example,
39111 @samp{0* } is a run-length encoding of ``0000'': the space character
39112 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
39113 3}} more times.
39114
39115 The printable characters @samp{#} and @samp{$} or with a numeric value
39116 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39117 seven repeats (@samp{$}) can be expanded using a repeat count of only
39118 five (@samp{"}). For example, @samp{00000000} can be encoded as
39119 @samp{0*"00}.
39120
39121 The error response returned for some packets includes a two character
39122 error number. That number is not well defined.
39123
39124 @cindex empty response, for unsupported packets
39125 For any @var{command} not supported by the stub, an empty response
39126 (@samp{$#00}) should be returned. That way it is possible to extend the
39127 protocol. A newer @value{GDBN} can tell if a packet is supported based
39128 on that response.
39129
39130 At a minimum, a stub is required to support the @samp{g} and @samp{G}
39131 commands for register access, and the @samp{m} and @samp{M} commands
39132 for memory access. Stubs that only control single-threaded targets
39133 can implement run control with the @samp{c} (continue), and @samp{s}
39134 (step) commands. Stubs that support multi-threading targets should
39135 support the @samp{vCont} command. All other commands are optional.
39136
39137 @node Packets
39138 @section Packets
39139
39140 The following table provides a complete list of all currently defined
39141 @var{command}s and their corresponding response @var{data}.
39142 @xref{File-I/O Remote Protocol Extension}, for details about the File
39143 I/O extension of the remote protocol.
39144
39145 Each packet's description has a template showing the packet's overall
39146 syntax, followed by an explanation of the packet's meaning. We
39147 include spaces in some of the templates for clarity; these are not
39148 part of the packet's syntax. No @value{GDBN} packet uses spaces to
39149 separate its components. For example, a template like @samp{foo
39150 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
39151 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39152 @var{baz}. @value{GDBN} does not transmit a space character between the
39153 @samp{foo} and the @var{bar}, or between the @var{bar} and the
39154 @var{baz}.
39155
39156 @cindex @var{thread-id}, in remote protocol
39157 @anchor{thread-id syntax}
39158 Several packets and replies include a @var{thread-id} field to identify
39159 a thread. Normally these are positive numbers with a target-specific
39160 interpretation, formatted as big-endian hex strings. A @var{thread-id}
39161 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39162 pick any thread.
39163
39164 In addition, the remote protocol supports a multiprocess feature in
39165 which the @var{thread-id} syntax is extended to optionally include both
39166 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39167 The @var{pid} (process) and @var{tid} (thread) components each have the
39168 format described above: a positive number with target-specific
39169 interpretation formatted as a big-endian hex string, literal @samp{-1}
39170 to indicate all processes or threads (respectively), or @samp{0} to
39171 indicate an arbitrary process or thread. Specifying just a process, as
39172 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39173 error to specify all processes but a specific thread, such as
39174 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39175 for those packets and replies explicitly documented to include a process
39176 ID, rather than a @var{thread-id}.
39177
39178 The multiprocess @var{thread-id} syntax extensions are only used if both
39179 @value{GDBN} and the stub report support for the @samp{multiprocess}
39180 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39181 more information.
39182
39183 Note that all packet forms beginning with an upper- or lower-case
39184 letter, other than those described here, are reserved for future use.
39185
39186 Here are the packet descriptions.
39187
39188 @table @samp
39189
39190 @item !
39191 @cindex @samp{!} packet
39192 @anchor{extended mode}
39193 Enable extended mode. In extended mode, the remote server is made
39194 persistent. The @samp{R} packet is used to restart the program being
39195 debugged.
39196
39197 Reply:
39198 @table @samp
39199 @item OK
39200 The remote target both supports and has enabled extended mode.
39201 @end table
39202
39203 @item ?
39204 @cindex @samp{?} packet
39205 @anchor{? packet}
39206 Indicate the reason the target halted. The reply is the same as for
39207 step and continue. This packet has a special interpretation when the
39208 target is in non-stop mode; see @ref{Remote Non-Stop}.
39209
39210 Reply:
39211 @xref{Stop Reply Packets}, for the reply specifications.
39212
39213 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
39214 @cindex @samp{A} packet
39215 Initialized @code{argv[]} array passed into program. @var{arglen}
39216 specifies the number of bytes in the hex encoded byte stream
39217 @var{arg}. See @code{gdbserver} for more details.
39218
39219 Reply:
39220 @table @samp
39221 @item OK
39222 The arguments were set.
39223 @item E @var{NN}
39224 An error occurred.
39225 @end table
39226
39227 @item b @var{baud}
39228 @cindex @samp{b} packet
39229 (Don't use this packet; its behavior is not well-defined.)
39230 Change the serial line speed to @var{baud}.
39231
39232 JTC: @emph{When does the transport layer state change? When it's
39233 received, or after the ACK is transmitted. In either case, there are
39234 problems if the command or the acknowledgment packet is dropped.}
39235
39236 Stan: @emph{If people really wanted to add something like this, and get
39237 it working for the first time, they ought to modify ser-unix.c to send
39238 some kind of out-of-band message to a specially-setup stub and have the
39239 switch happen "in between" packets, so that from remote protocol's point
39240 of view, nothing actually happened.}
39241
39242 @item B @var{addr},@var{mode}
39243 @cindex @samp{B} packet
39244 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39245 breakpoint at @var{addr}.
39246
39247 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39248 (@pxref{insert breakpoint or watchpoint packet}).
39249
39250 @cindex @samp{bc} packet
39251 @anchor{bc}
39252 @item bc
39253 Backward continue. Execute the target system in reverse. No parameter.
39254 @xref{Reverse Execution}, for more information.
39255
39256 Reply:
39257 @xref{Stop Reply Packets}, for the reply specifications.
39258
39259 @cindex @samp{bs} packet
39260 @anchor{bs}
39261 @item bs
39262 Backward single step. Execute one instruction in reverse. No parameter.
39263 @xref{Reverse Execution}, for more information.
39264
39265 Reply:
39266 @xref{Stop Reply Packets}, for the reply specifications.
39267
39268 @item c @r{[}@var{addr}@r{]}
39269 @cindex @samp{c} packet
39270 Continue at @var{addr}, which is the address to resume. If @var{addr}
39271 is omitted, resume at current address.
39272
39273 This packet is deprecated for multi-threading support. @xref{vCont
39274 packet}.
39275
39276 Reply:
39277 @xref{Stop Reply Packets}, for the reply specifications.
39278
39279 @item C @var{sig}@r{[};@var{addr}@r{]}
39280 @cindex @samp{C} packet
39281 Continue with signal @var{sig} (hex signal number). If
39282 @samp{;@var{addr}} is omitted, resume at same address.
39283
39284 This packet is deprecated for multi-threading support. @xref{vCont
39285 packet}.
39286
39287 Reply:
39288 @xref{Stop Reply Packets}, for the reply specifications.
39289
39290 @item d
39291 @cindex @samp{d} packet
39292 Toggle debug flag.
39293
39294 Don't use this packet; instead, define a general set packet
39295 (@pxref{General Query Packets}).
39296
39297 @item D
39298 @itemx D;@var{pid}
39299 @cindex @samp{D} packet
39300 The first form of the packet is used to detach @value{GDBN} from the
39301 remote system. It is sent to the remote target
39302 before @value{GDBN} disconnects via the @code{detach} command.
39303
39304 The second form, including a process ID, is used when multiprocess
39305 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39306 detach only a specific process. The @var{pid} is specified as a
39307 big-endian hex string.
39308
39309 Reply:
39310 @table @samp
39311 @item OK
39312 for success
39313 @item E @var{NN}
39314 for an error
39315 @end table
39316
39317 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39318 @cindex @samp{F} packet
39319 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39320 This is part of the File-I/O protocol extension. @xref{File-I/O
39321 Remote Protocol Extension}, for the specification.
39322
39323 @item g
39324 @anchor{read registers packet}
39325 @cindex @samp{g} packet
39326 Read general registers.
39327
39328 Reply:
39329 @table @samp
39330 @item @var{XX@dots{}}
39331 Each byte of register data is described by two hex digits. The bytes
39332 with the register are transmitted in target byte order. The size of
39333 each register and their position within the @samp{g} packet are
39334 determined by the @value{GDBN} internal gdbarch functions
39335 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39336
39337 When reading registers from a trace frame (@pxref{Analyze Collected
39338 Data,,Using the Collected Data}), the stub may also return a string of
39339 literal @samp{x}'s in place of the register data digits, to indicate
39340 that the corresponding register has not been collected, thus its value
39341 is unavailable. For example, for an architecture with 4 registers of
39342 4 bytes each, the following reply indicates to @value{GDBN} that
39343 registers 0 and 2 have not been collected, while registers 1 and 3
39344 have been collected, and both have zero value:
39345
39346 @smallexample
39347 -> @code{g}
39348 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39349 @end smallexample
39350
39351 @item E @var{NN}
39352 for an error.
39353 @end table
39354
39355 @item G @var{XX@dots{}}
39356 @cindex @samp{G} packet
39357 Write general registers. @xref{read registers packet}, for a
39358 description of the @var{XX@dots{}} data.
39359
39360 Reply:
39361 @table @samp
39362 @item OK
39363 for success
39364 @item E @var{NN}
39365 for an error
39366 @end table
39367
39368 @item H @var{op} @var{thread-id}
39369 @cindex @samp{H} packet
39370 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39371 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39372 should be @samp{c} for step and continue operations (note that this
39373 is deprecated, supporting the @samp{vCont} command is a better
39374 option), and @samp{g} for other operations. The thread designator
39375 @var{thread-id} has the format and interpretation described in
39376 @ref{thread-id syntax}.
39377
39378 Reply:
39379 @table @samp
39380 @item OK
39381 for success
39382 @item E @var{NN}
39383 for an error
39384 @end table
39385
39386 @c FIXME: JTC:
39387 @c 'H': How restrictive (or permissive) is the thread model. If a
39388 @c thread is selected and stopped, are other threads allowed
39389 @c to continue to execute? As I mentioned above, I think the
39390 @c semantics of each command when a thread is selected must be
39391 @c described. For example:
39392 @c
39393 @c 'g': If the stub supports threads and a specific thread is
39394 @c selected, returns the register block from that thread;
39395 @c otherwise returns current registers.
39396 @c
39397 @c 'G' If the stub supports threads and a specific thread is
39398 @c selected, sets the registers of the register block of
39399 @c that thread; otherwise sets current registers.
39400
39401 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39402 @anchor{cycle step packet}
39403 @cindex @samp{i} packet
39404 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39405 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39406 step starting at that address.
39407
39408 @item I
39409 @cindex @samp{I} packet
39410 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39411 step packet}.
39412
39413 @item k
39414 @cindex @samp{k} packet
39415 Kill request.
39416
39417 The exact effect of this packet is not specified.
39418
39419 For a bare-metal target, it may power cycle or reset the target
39420 system. For that reason, the @samp{k} packet has no reply.
39421
39422 For a single-process target, it may kill that process if possible.
39423
39424 A multiple-process target may choose to kill just one process, or all
39425 that are under @value{GDBN}'s control. For more precise control, use
39426 the vKill packet (@pxref{vKill packet}).
39427
39428 If the target system immediately closes the connection in response to
39429 @samp{k}, @value{GDBN} does not consider the lack of packet
39430 acknowledgment to be an error, and assumes the kill was successful.
39431
39432 If connected using @kbd{target extended-remote}, and the target does
39433 not close the connection in response to a kill request, @value{GDBN}
39434 probes the target state as if a new connection was opened
39435 (@pxref{? packet}).
39436
39437 @item m @var{addr},@var{length}
39438 @cindex @samp{m} packet
39439 Read @var{length} addressable memory units starting at address @var{addr}
39440 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39441 any particular boundary.
39442
39443 The stub need not use any particular size or alignment when gathering
39444 data from memory for the response; even if @var{addr} is word-aligned
39445 and @var{length} is a multiple of the word size, the stub is free to
39446 use byte accesses, or not. For this reason, this packet may not be
39447 suitable for accessing memory-mapped I/O devices.
39448 @cindex alignment of remote memory accesses
39449 @cindex size of remote memory accesses
39450 @cindex memory, alignment and size of remote accesses
39451
39452 Reply:
39453 @table @samp
39454 @item @var{XX@dots{}}
39455 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39456 The reply may contain fewer addressable memory units than requested if the
39457 server was able to read only part of the region of memory.
39458 @item E @var{NN}
39459 @var{NN} is errno
39460 @end table
39461
39462 @item M @var{addr},@var{length}:@var{XX@dots{}}
39463 @cindex @samp{M} packet
39464 Write @var{length} addressable memory units starting at address @var{addr}
39465 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39466 byte is transmitted as a two-digit hexadecimal number.
39467
39468 Reply:
39469 @table @samp
39470 @item OK
39471 for success
39472 @item E @var{NN}
39473 for an error (this includes the case where only part of the data was
39474 written).
39475 @end table
39476
39477 @item p @var{n}
39478 @cindex @samp{p} packet
39479 Read the value of register @var{n}; @var{n} is in hex.
39480 @xref{read registers packet}, for a description of how the returned
39481 register value is encoded.
39482
39483 Reply:
39484 @table @samp
39485 @item @var{XX@dots{}}
39486 the register's value
39487 @item E @var{NN}
39488 for an error
39489 @item @w{}
39490 Indicating an unrecognized @var{query}.
39491 @end table
39492
39493 @item P @var{n@dots{}}=@var{r@dots{}}
39494 @anchor{write register packet}
39495 @cindex @samp{P} packet
39496 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
39497 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
39498 digits for each byte in the register (target byte order).
39499
39500 Reply:
39501 @table @samp
39502 @item OK
39503 for success
39504 @item E @var{NN}
39505 for an error
39506 @end table
39507
39508 @item q @var{name} @var{params}@dots{}
39509 @itemx Q @var{name} @var{params}@dots{}
39510 @cindex @samp{q} packet
39511 @cindex @samp{Q} packet
39512 General query (@samp{q}) and set (@samp{Q}). These packets are
39513 described fully in @ref{General Query Packets}.
39514
39515 @item r
39516 @cindex @samp{r} packet
39517 Reset the entire system.
39518
39519 Don't use this packet; use the @samp{R} packet instead.
39520
39521 @item R @var{XX}
39522 @cindex @samp{R} packet
39523 Restart the program being debugged. The @var{XX}, while needed, is ignored.
39524 This packet is only available in extended mode (@pxref{extended mode}).
39525
39526 The @samp{R} packet has no reply.
39527
39528 @item s @r{[}@var{addr}@r{]}
39529 @cindex @samp{s} packet
39530 Single step, resuming at @var{addr}. If
39531 @var{addr} is omitted, resume at same address.
39532
39533 This packet is deprecated for multi-threading support. @xref{vCont
39534 packet}.
39535
39536 Reply:
39537 @xref{Stop Reply Packets}, for the reply specifications.
39538
39539 @item S @var{sig}@r{[};@var{addr}@r{]}
39540 @anchor{step with signal packet}
39541 @cindex @samp{S} packet
39542 Step with signal. This is analogous to the @samp{C} packet, but
39543 requests a single-step, rather than a normal resumption of execution.
39544
39545 This packet is deprecated for multi-threading support. @xref{vCont
39546 packet}.
39547
39548 Reply:
39549 @xref{Stop Reply Packets}, for the reply specifications.
39550
39551 @item t @var{addr}:@var{PP},@var{MM}
39552 @cindex @samp{t} packet
39553 Search backwards starting at address @var{addr} for a match with pattern
39554 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
39555 There must be at least 3 digits in @var{addr}.
39556
39557 @item T @var{thread-id}
39558 @cindex @samp{T} packet
39559 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
39560
39561 Reply:
39562 @table @samp
39563 @item OK
39564 thread is still alive
39565 @item E @var{NN}
39566 thread is dead
39567 @end table
39568
39569 @item v
39570 Packets starting with @samp{v} are identified by a multi-letter name,
39571 up to the first @samp{;} or @samp{?} (or the end of the packet).
39572
39573 @item vAttach;@var{pid}
39574 @cindex @samp{vAttach} packet
39575 Attach to a new process with the specified process ID @var{pid}.
39576 The process ID is a
39577 hexadecimal integer identifying the process. In all-stop mode, all
39578 threads in the attached process are stopped; in non-stop mode, it may be
39579 attached without being stopped if that is supported by the target.
39580
39581 @c In non-stop mode, on a successful vAttach, the stub should set the
39582 @c current thread to a thread of the newly-attached process. After
39583 @c attaching, GDB queries for the attached process's thread ID with qC.
39584 @c Also note that, from a user perspective, whether or not the
39585 @c target is stopped on attach in non-stop mode depends on whether you
39586 @c use the foreground or background version of the attach command, not
39587 @c on what vAttach does; GDB does the right thing with respect to either
39588 @c stopping or restarting threads.
39589
39590 This packet is only available in extended mode (@pxref{extended mode}).
39591
39592 Reply:
39593 @table @samp
39594 @item E @var{nn}
39595 for an error
39596 @item @r{Any stop packet}
39597 for success in all-stop mode (@pxref{Stop Reply Packets})
39598 @item OK
39599 for success in non-stop mode (@pxref{Remote Non-Stop})
39600 @end table
39601
39602 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
39603 @cindex @samp{vCont} packet
39604 @anchor{vCont packet}
39605 Resume the inferior, specifying different actions for each thread.
39606
39607 For each inferior thread, the leftmost action with a matching
39608 @var{thread-id} is applied. Threads that don't match any action
39609 remain in their current state. Thread IDs are specified using the
39610 syntax described in @ref{thread-id syntax}. If multiprocess
39611 extensions (@pxref{multiprocess extensions}) are supported, actions
39612 can be specified to match all threads in a process by using the
39613 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39614 @var{thread-id} matches all threads. Specifying no actions is an
39615 error.
39616
39617 Currently supported actions are:
39618
39619 @table @samp
39620 @item c
39621 Continue.
39622 @item C @var{sig}
39623 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
39624 @item s
39625 Step.
39626 @item S @var{sig}
39627 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39628 @item t
39629 Stop.
39630 @item r @var{start},@var{end}
39631 Step once, and then keep stepping as long as the thread stops at
39632 addresses between @var{start} (inclusive) and @var{end} (exclusive).
39633 The remote stub reports a stop reply when either the thread goes out
39634 of the range or is stopped due to an unrelated reason, such as hitting
39635 a breakpoint. @xref{range stepping}.
39636
39637 If the range is empty (@var{start} == @var{end}), then the action
39638 becomes equivalent to the @samp{s} action. In other words,
39639 single-step once, and report the stop (even if the stepped instruction
39640 jumps to @var{start}).
39641
39642 (A stop reply may be sent at any point even if the PC is still within
39643 the stepping range; for example, it is valid to implement this packet
39644 in a degenerate way as a single instruction step operation.)
39645
39646 @end table
39647
39648 The optional argument @var{addr} normally associated with the
39649 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
39650 not supported in @samp{vCont}.
39651
39652 The @samp{t} action is only relevant in non-stop mode
39653 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
39654 A stop reply should be generated for any affected thread not already stopped.
39655 When a thread is stopped by means of a @samp{t} action,
39656 the corresponding stop reply should indicate that the thread has stopped with
39657 signal @samp{0}, regardless of whether the target uses some other signal
39658 as an implementation detail.
39659
39660 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39661 @samp{r} actions for threads that are already running. Conversely,
39662 the server must ignore @samp{t} actions for threads that are already
39663 stopped.
39664
39665 @emph{Note:} In non-stop mode, a thread is considered running until
39666 @value{GDBN} acknowledges an asynchronous stop notification for it with
39667 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39668
39669 The stub must support @samp{vCont} if it reports support for
39670 multiprocess extensions (@pxref{multiprocess extensions}).
39671
39672 Reply:
39673 @xref{Stop Reply Packets}, for the reply specifications.
39674
39675 @item vCont?
39676 @cindex @samp{vCont?} packet
39677 Request a list of actions supported by the @samp{vCont} packet.
39678
39679 Reply:
39680 @table @samp
39681 @item vCont@r{[};@var{action}@dots{}@r{]}
39682 The @samp{vCont} packet is supported. Each @var{action} is a supported
39683 command in the @samp{vCont} packet.
39684 @item @w{}
39685 The @samp{vCont} packet is not supported.
39686 @end table
39687
39688 @anchor{vCtrlC packet}
39689 @item vCtrlC
39690 @cindex @samp{vCtrlC} packet
39691 Interrupt remote target as if a control-C was pressed on the remote
39692 terminal. This is the equivalent to reacting to the @code{^C}
39693 (@samp{\003}, the control-C character) character in all-stop mode
39694 while the target is running, except this works in non-stop mode.
39695 @xref{interrupting remote targets}, for more info on the all-stop
39696 variant.
39697
39698 Reply:
39699 @table @samp
39700 @item E @var{nn}
39701 for an error
39702 @item OK
39703 for success
39704 @end table
39705
39706 @item vFile:@var{operation}:@var{parameter}@dots{}
39707 @cindex @samp{vFile} packet
39708 Perform a file operation on the target system. For details,
39709 see @ref{Host I/O Packets}.
39710
39711 @item vFlashErase:@var{addr},@var{length}
39712 @cindex @samp{vFlashErase} packet
39713 Direct the stub to erase @var{length} bytes of flash starting at
39714 @var{addr}. The region may enclose any number of flash blocks, but
39715 its start and end must fall on block boundaries, as indicated by the
39716 flash block size appearing in the memory map (@pxref{Memory Map
39717 Format}). @value{GDBN} groups flash memory programming operations
39718 together, and sends a @samp{vFlashDone} request after each group; the
39719 stub is allowed to delay erase operation until the @samp{vFlashDone}
39720 packet is received.
39721
39722 Reply:
39723 @table @samp
39724 @item OK
39725 for success
39726 @item E @var{NN}
39727 for an error
39728 @end table
39729
39730 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
39731 @cindex @samp{vFlashWrite} packet
39732 Direct the stub to write data to flash address @var{addr}. The data
39733 is passed in binary form using the same encoding as for the @samp{X}
39734 packet (@pxref{Binary Data}). The memory ranges specified by
39735 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39736 not overlap, and must appear in order of increasing addresses
39737 (although @samp{vFlashErase} packets for higher addresses may already
39738 have been received; the ordering is guaranteed only between
39739 @samp{vFlashWrite} packets). If a packet writes to an address that was
39740 neither erased by a preceding @samp{vFlashErase} packet nor by some other
39741 target-specific method, the results are unpredictable.
39742
39743
39744 Reply:
39745 @table @samp
39746 @item OK
39747 for success
39748 @item E.memtype
39749 for vFlashWrite addressing non-flash memory
39750 @item E @var{NN}
39751 for an error
39752 @end table
39753
39754 @item vFlashDone
39755 @cindex @samp{vFlashDone} packet
39756 Indicate to the stub that flash programming operation is finished.
39757 The stub is permitted to delay or batch the effects of a group of
39758 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
39759 @samp{vFlashDone} packet is received. The contents of the affected
39760 regions of flash memory are unpredictable until the @samp{vFlashDone}
39761 request is completed.
39762
39763 @item vKill;@var{pid}
39764 @cindex @samp{vKill} packet
39765 @anchor{vKill packet}
39766 Kill the process with the specified process ID @var{pid}, which is a
39767 hexadecimal integer identifying the process. This packet is used in
39768 preference to @samp{k} when multiprocess protocol extensions are
39769 supported; see @ref{multiprocess extensions}.
39770
39771 Reply:
39772 @table @samp
39773 @item E @var{nn}
39774 for an error
39775 @item OK
39776 for success
39777 @end table
39778
39779 @item vMustReplyEmpty
39780 @cindex @samp{vMustReplyEmpty} packet
39781 The correct reply to an unknown @samp{v} packet is to return the empty
39782 string, however, some older versions of @command{gdbserver} would
39783 incorrectly return @samp{OK} for unknown @samp{v} packets.
39784
39785 The @samp{vMustReplyEmpty} is used as a feature test to check how
39786 @command{gdbserver} handles unknown packets, it is important that this
39787 packet be handled in the same way as other unknown @samp{v} packets.
39788 If this packet is handled differently to other unknown @samp{v}
39789 packets then it is possible that @value{GDBN} may run into problems in
39790 other areas, specifically around use of @samp{vFile:setfs:}.
39791
39792 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39793 @cindex @samp{vRun} packet
39794 Run the program @var{filename}, passing it each @var{argument} on its
39795 command line. The file and arguments are hex-encoded strings. If
39796 @var{filename} is an empty string, the stub may use a default program
39797 (e.g.@: the last program run). The program is created in the stopped
39798 state.
39799
39800 @c FIXME: What about non-stop mode?
39801
39802 This packet is only available in extended mode (@pxref{extended mode}).
39803
39804 Reply:
39805 @table @samp
39806 @item E @var{nn}
39807 for an error
39808 @item @r{Any stop packet}
39809 for success (@pxref{Stop Reply Packets})
39810 @end table
39811
39812 @item vStopped
39813 @cindex @samp{vStopped} packet
39814 @xref{Notification Packets}.
39815
39816 @item X @var{addr},@var{length}:@var{XX@dots{}}
39817 @anchor{X packet}
39818 @cindex @samp{X} packet
39819 Write data to memory, where the data is transmitted in binary.
39820 Memory is specified by its address @var{addr} and number of addressable memory
39821 units @var{length} (@pxref{addressable memory unit});
39822 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
39823
39824 Reply:
39825 @table @samp
39826 @item OK
39827 for success
39828 @item E @var{NN}
39829 for an error
39830 @end table
39831
39832 @item z @var{type},@var{addr},@var{kind}
39833 @itemx Z @var{type},@var{addr},@var{kind}
39834 @anchor{insert breakpoint or watchpoint packet}
39835 @cindex @samp{z} packet
39836 @cindex @samp{Z} packets
39837 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
39838 watchpoint starting at address @var{address} of kind @var{kind}.
39839
39840 Each breakpoint and watchpoint packet @var{type} is documented
39841 separately.
39842
39843 @emph{Implementation notes: A remote target shall return an empty string
39844 for an unrecognized breakpoint or watchpoint packet @var{type}. A
39845 remote target shall support either both or neither of a given
39846 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
39847 avoid potential problems with duplicate packets, the operations should
39848 be implemented in an idempotent way.}
39849
39850 @item z0,@var{addr},@var{kind}
39851 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39852 @cindex @samp{z0} packet
39853 @cindex @samp{Z0} packet
39854 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
39855 @var{addr} of type @var{kind}.
39856
39857 A software breakpoint is implemented by replacing the instruction at
39858 @var{addr} with a software breakpoint or trap instruction. The
39859 @var{kind} is target-specific and typically indicates the size of the
39860 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39861 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39862 architectures have additional meanings for @var{kind}
39863 (@pxref{Architecture-Specific Protocol Details}); if no
39864 architecture-specific value is being used, it should be @samp{0}.
39865 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
39866 conditional expressions in bytecode form that should be evaluated on
39867 the target's side. These are the conditions that should be taken into
39868 consideration when deciding if the breakpoint trigger should be
39869 reported back to @value{GDBN}.
39870
39871 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
39872 for how to best report a software breakpoint event to @value{GDBN}.
39873
39874 The @var{cond_list} parameter is comprised of a series of expressions,
39875 concatenated without separators. Each expression has the following form:
39876
39877 @table @samp
39878
39879 @item X @var{len},@var{expr}
39880 @var{len} is the length of the bytecode expression and @var{expr} is the
39881 actual conditional expression in bytecode form.
39882
39883 @end table
39884
39885 The optional @var{cmd_list} parameter introduces commands that may be
39886 run on the target, rather than being reported back to @value{GDBN}.
39887 The parameter starts with a numeric flag @var{persist}; if the flag is
39888 nonzero, then the breakpoint may remain active and the commands
39889 continue to be run even when @value{GDBN} disconnects from the target.
39890 Following this flag is a series of expressions concatenated with no
39891 separators. Each expression has the following form:
39892
39893 @table @samp
39894
39895 @item X @var{len},@var{expr}
39896 @var{len} is the length of the bytecode expression and @var{expr} is the
39897 actual commands expression in bytecode form.
39898
39899 @end table
39900
39901 @emph{Implementation note: It is possible for a target to copy or move
39902 code that contains software breakpoints (e.g., when implementing
39903 overlays). The behavior of this packet, in the presence of such a
39904 target, is not defined.}
39905
39906 Reply:
39907 @table @samp
39908 @item OK
39909 success
39910 @item @w{}
39911 not supported
39912 @item E @var{NN}
39913 for an error
39914 @end table
39915
39916 @item z1,@var{addr},@var{kind}
39917 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39918 @cindex @samp{z1} packet
39919 @cindex @samp{Z1} packet
39920 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
39921 address @var{addr}.
39922
39923 A hardware breakpoint is implemented using a mechanism that is not
39924 dependent on being able to modify the target's memory. The
39925 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39926 same meaning as in @samp{Z0} packets.
39927
39928 @emph{Implementation note: A hardware breakpoint is not affected by code
39929 movement.}
39930
39931 Reply:
39932 @table @samp
39933 @item OK
39934 success
39935 @item @w{}
39936 not supported
39937 @item E @var{NN}
39938 for an error
39939 @end table
39940
39941 @item z2,@var{addr},@var{kind}
39942 @itemx Z2,@var{addr},@var{kind}
39943 @cindex @samp{z2} packet
39944 @cindex @samp{Z2} packet
39945 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
39946 The number of bytes to watch is specified by @var{kind}.
39947
39948 Reply:
39949 @table @samp
39950 @item OK
39951 success
39952 @item @w{}
39953 not supported
39954 @item E @var{NN}
39955 for an error
39956 @end table
39957
39958 @item z3,@var{addr},@var{kind}
39959 @itemx Z3,@var{addr},@var{kind}
39960 @cindex @samp{z3} packet
39961 @cindex @samp{Z3} packet
39962 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
39963 The number of bytes to watch is specified by @var{kind}.
39964
39965 Reply:
39966 @table @samp
39967 @item OK
39968 success
39969 @item @w{}
39970 not supported
39971 @item E @var{NN}
39972 for an error
39973 @end table
39974
39975 @item z4,@var{addr},@var{kind}
39976 @itemx Z4,@var{addr},@var{kind}
39977 @cindex @samp{z4} packet
39978 @cindex @samp{Z4} packet
39979 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
39980 The number of bytes to watch is specified by @var{kind}.
39981
39982 Reply:
39983 @table @samp
39984 @item OK
39985 success
39986 @item @w{}
39987 not supported
39988 @item E @var{NN}
39989 for an error
39990 @end table
39991
39992 @end table
39993
39994 @node Stop Reply Packets
39995 @section Stop Reply Packets
39996 @cindex stop reply packets
39997
39998 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
39999 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40000 receive any of the below as a reply. Except for @samp{?}
40001 and @samp{vStopped}, that reply is only returned
40002 when the target halts. In the below the exact meaning of @dfn{signal
40003 number} is defined by the header @file{include/gdb/signals.h} in the
40004 @value{GDBN} source code.
40005
40006 In non-stop mode, the server will simply reply @samp{OK} to commands
40007 such as @samp{vCont}; any stop will be the subject of a future
40008 notification. @xref{Remote Non-Stop}.
40009
40010 As in the description of request packets, we include spaces in the
40011 reply templates for clarity; these are not part of the reply packet's
40012 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40013 components.
40014
40015 @table @samp
40016
40017 @item S @var{AA}
40018 The program received signal number @var{AA} (a two-digit hexadecimal
40019 number). This is equivalent to a @samp{T} response with no
40020 @var{n}:@var{r} pairs.
40021
40022 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40023 @cindex @samp{T} packet reply
40024 The program received signal number @var{AA} (a two-digit hexadecimal
40025 number). This is equivalent to an @samp{S} response, except that the
40026 @samp{@var{n}:@var{r}} pairs can carry values of important registers
40027 and other information directly in the stop reply packet, reducing
40028 round-trip latency. Single-step and breakpoint traps are reported
40029 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
40030
40031 @itemize @bullet
40032 @item
40033 If @var{n} is a hexadecimal number, it is a register number, and the
40034 corresponding @var{r} gives that register's value. The data @var{r} is a
40035 series of bytes in target byte order, with each byte given by a
40036 two-digit hex number.
40037
40038 @item
40039 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40040 the stopped thread, as specified in @ref{thread-id syntax}.
40041
40042 @item
40043 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40044 the core on which the stop event was detected.
40045
40046 @item
40047 If @var{n} is a recognized @dfn{stop reason}, it describes a more
40048 specific event that stopped the target. The currently defined stop
40049 reasons are listed below. The @var{aa} should be @samp{05}, the trap
40050 signal. At most one stop reason should be present.
40051
40052 @item
40053 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40054 and go on to the next; this allows us to extend the protocol in the
40055 future.
40056 @end itemize
40057
40058 The currently defined stop reasons are:
40059
40060 @table @samp
40061 @item watch
40062 @itemx rwatch
40063 @itemx awatch
40064 The packet indicates a watchpoint hit, and @var{r} is the data address, in
40065 hex.
40066
40067 @item syscall_entry
40068 @itemx syscall_return
40069 The packet indicates a syscall entry or return, and @var{r} is the
40070 syscall number, in hex.
40071
40072 @cindex shared library events, remote reply
40073 @item library
40074 The packet indicates that the loaded libraries have changed.
40075 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
40076 list of loaded libraries. The @var{r} part is ignored.
40077
40078 @cindex replay log events, remote reply
40079 @item replaylog
40080 The packet indicates that the target cannot continue replaying
40081 logged execution events, because it has reached the end (or the
40082 beginning when executing backward) of the log. The value of @var{r}
40083 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40084 for more information.
40085
40086 @item swbreak
40087 @anchor{swbreak stop reason}
40088 The packet indicates a software breakpoint instruction was executed,
40089 irrespective of whether it was @value{GDBN} that planted the
40090 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40091 part must be left empty.
40092
40093 On some architectures, such as x86, at the architecture level, when a
40094 breakpoint instruction executes the program counter points at the
40095 breakpoint address plus an offset. On such targets, the stub is
40096 responsible for adjusting the PC to point back at the breakpoint
40097 address.
40098
40099 This packet should not be sent by default; older @value{GDBN} versions
40100 did not support it. @value{GDBN} requests it, by supplying an
40101 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40102 remote stub must also supply the appropriate @samp{qSupported} feature
40103 indicating support.
40104
40105 This packet is required for correct non-stop mode operation.
40106
40107 @item hwbreak
40108 The packet indicates the target stopped for a hardware breakpoint.
40109 The @var{r} part must be left empty.
40110
40111 The same remarks about @samp{qSupported} and non-stop mode above
40112 apply.
40113
40114 @cindex fork events, remote reply
40115 @item fork
40116 The packet indicates that @code{fork} was called, and @var{r}
40117 is the thread ID of the new child process. Refer to
40118 @ref{thread-id syntax} for the format of the @var{thread-id}
40119 field. This packet is only applicable to targets that support
40120 fork events.
40121
40122 This packet should not be sent by default; older @value{GDBN} versions
40123 did not support it. @value{GDBN} requests it, by supplying an
40124 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40125 remote stub must also supply the appropriate @samp{qSupported} feature
40126 indicating support.
40127
40128 @cindex vfork events, remote reply
40129 @item vfork
40130 The packet indicates that @code{vfork} was called, and @var{r}
40131 is the thread ID of the new child process. Refer to
40132 @ref{thread-id syntax} for the format of the @var{thread-id}
40133 field. This packet is only applicable to targets that support
40134 vfork events.
40135
40136 This packet should not be sent by default; older @value{GDBN} versions
40137 did not support it. @value{GDBN} requests it, by supplying an
40138 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40139 remote stub must also supply the appropriate @samp{qSupported} feature
40140 indicating support.
40141
40142 @cindex vforkdone events, remote reply
40143 @item vforkdone
40144 The packet indicates that a child process created by a vfork
40145 has either called @code{exec} or terminated, so that the
40146 address spaces of the parent and child process are no longer
40147 shared. The @var{r} part is ignored. This packet is only
40148 applicable to targets that support vforkdone events.
40149
40150 This packet should not be sent by default; older @value{GDBN} versions
40151 did not support it. @value{GDBN} requests it, by supplying an
40152 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40153 remote stub must also supply the appropriate @samp{qSupported} feature
40154 indicating support.
40155
40156 @cindex exec events, remote reply
40157 @item exec
40158 The packet indicates that @code{execve} was called, and @var{r}
40159 is the absolute pathname of the file that was executed, in hex.
40160 This packet is only applicable to targets that support exec events.
40161
40162 This packet should not be sent by default; older @value{GDBN} versions
40163 did not support it. @value{GDBN} requests it, by supplying an
40164 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40165 remote stub must also supply the appropriate @samp{qSupported} feature
40166 indicating support.
40167
40168 @cindex thread create event, remote reply
40169 @anchor{thread create event}
40170 @item create
40171 The packet indicates that the thread was just created. The new thread
40172 is stopped until @value{GDBN} sets it running with a resumption packet
40173 (@pxref{vCont packet}). This packet should not be sent by default;
40174 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
40175 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40176 @var{r} part is ignored.
40177
40178 @end table
40179
40180 @item W @var{AA}
40181 @itemx W @var{AA} ; process:@var{pid}
40182 The process exited, and @var{AA} is the exit status. This is only
40183 applicable to certain targets.
40184
40185 The second form of the response, including the process ID of the
40186 exited process, can be used only when @value{GDBN} has reported
40187 support for multiprocess protocol extensions; see @ref{multiprocess
40188 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40189 hex strings.
40190
40191 @item X @var{AA}
40192 @itemx X @var{AA} ; process:@var{pid}
40193 The process terminated with signal @var{AA}.
40194
40195 The second form of the response, including the process ID of the
40196 terminated process, can be used only when @value{GDBN} has reported
40197 support for multiprocess protocol extensions; see @ref{multiprocess
40198 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40199 hex strings.
40200
40201 @anchor{thread exit event}
40202 @cindex thread exit event, remote reply
40203 @item w @var{AA} ; @var{tid}
40204
40205 The thread exited, and @var{AA} is the exit status. This response
40206 should not be sent by default; @value{GDBN} requests it with the
40207 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
40208 @var{AA} is formatted as a big-endian hex string.
40209
40210 @item N
40211 There are no resumed threads left in the target. In other words, even
40212 though the process is alive, the last resumed thread has exited. For
40213 example, say the target process has two threads: thread 1 and thread
40214 2. The client leaves thread 1 stopped, and resumes thread 2, which
40215 subsequently exits. At this point, even though the process is still
40216 alive, and thus no @samp{W} stop reply is sent, no thread is actually
40217 executing either. The @samp{N} stop reply thus informs the client
40218 that it can stop waiting for stop replies. This packet should not be
40219 sent by default; older @value{GDBN} versions did not support it.
40220 @value{GDBN} requests it, by supplying an appropriate
40221 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40222 also supply the appropriate @samp{qSupported} feature indicating
40223 support.
40224
40225 @item O @var{XX}@dots{}
40226 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40227 written as the program's console output. This can happen at any time
40228 while the program is running and the debugger should continue to wait
40229 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40230
40231 @item F @var{call-id},@var{parameter}@dots{}
40232 @var{call-id} is the identifier which says which host system call should
40233 be called. This is just the name of the function. Translation into the
40234 correct system call is only applicable as it's defined in @value{GDBN}.
40235 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40236 system calls.
40237
40238 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40239 this very system call.
40240
40241 The target replies with this packet when it expects @value{GDBN} to
40242 call a host system call on behalf of the target. @value{GDBN} replies
40243 with an appropriate @samp{F} packet and keeps up waiting for the next
40244 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40245 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40246 Protocol Extension}, for more details.
40247
40248 @end table
40249
40250 @node General Query Packets
40251 @section General Query Packets
40252 @cindex remote query requests
40253
40254 Packets starting with @samp{q} are @dfn{general query packets};
40255 packets starting with @samp{Q} are @dfn{general set packets}. General
40256 query and set packets are a semi-unified form for retrieving and
40257 sending information to and from the stub.
40258
40259 The initial letter of a query or set packet is followed by a name
40260 indicating what sort of thing the packet applies to. For example,
40261 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40262 definitions with the stub. These packet names follow some
40263 conventions:
40264
40265 @itemize @bullet
40266 @item
40267 The name must not contain commas, colons or semicolons.
40268 @item
40269 Most @value{GDBN} query and set packets have a leading upper case
40270 letter.
40271 @item
40272 The names of custom vendor packets should use a company prefix, in
40273 lower case, followed by a period. For example, packets designed at
40274 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40275 foos) or @samp{Qacme.bar} (for setting bars).
40276 @end itemize
40277
40278 The name of a query or set packet should be separated from any
40279 parameters by a @samp{:}; the parameters themselves should be
40280 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40281 full packet name, and check for a separator or the end of the packet,
40282 in case two packet names share a common prefix. New packets should not begin
40283 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40284 packets predate these conventions, and have arguments without any terminator
40285 for the packet name; we suspect they are in widespread use in places that
40286 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40287 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40288 packet.}.
40289
40290 Like the descriptions of the other packets, each description here
40291 has a template showing the packet's overall syntax, followed by an
40292 explanation of the packet's meaning. We include spaces in some of the
40293 templates for clarity; these are not part of the packet's syntax. No
40294 @value{GDBN} packet uses spaces to separate its components.
40295
40296 Here are the currently defined query and set packets:
40297
40298 @table @samp
40299
40300 @item QAgent:1
40301 @itemx QAgent:0
40302 Turn on or off the agent as a helper to perform some debugging operations
40303 delegated from @value{GDBN} (@pxref{Control Agent}).
40304
40305 @item QAllow:@var{op}:@var{val}@dots{}
40306 @cindex @samp{QAllow} packet
40307 Specify which operations @value{GDBN} expects to request of the
40308 target, as a semicolon-separated list of operation name and value
40309 pairs. Possible values for @var{op} include @samp{WriteReg},
40310 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40311 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40312 indicating that @value{GDBN} will not request the operation, or 1,
40313 indicating that it may. (The target can then use this to set up its
40314 own internals optimally, for instance if the debugger never expects to
40315 insert breakpoints, it may not need to install its own trap handler.)
40316
40317 @item qC
40318 @cindex current thread, remote request
40319 @cindex @samp{qC} packet
40320 Return the current thread ID.
40321
40322 Reply:
40323 @table @samp
40324 @item QC @var{thread-id}
40325 Where @var{thread-id} is a thread ID as documented in
40326 @ref{thread-id syntax}.
40327 @item @r{(anything else)}
40328 Any other reply implies the old thread ID.
40329 @end table
40330
40331 @item qCRC:@var{addr},@var{length}
40332 @cindex CRC of memory block, remote request
40333 @cindex @samp{qCRC} packet
40334 @anchor{qCRC packet}
40335 Compute the CRC checksum of a block of memory using CRC-32 defined in
40336 IEEE 802.3. The CRC is computed byte at a time, taking the most
40337 significant bit of each byte first. The initial pattern code
40338 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40339
40340 @emph{Note:} This is the same CRC used in validating separate debug
40341 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40342 Files}). However the algorithm is slightly different. When validating
40343 separate debug files, the CRC is computed taking the @emph{least}
40344 significant bit of each byte first, and the final result is inverted to
40345 detect trailing zeros.
40346
40347 Reply:
40348 @table @samp
40349 @item E @var{NN}
40350 An error (such as memory fault)
40351 @item C @var{crc32}
40352 The specified memory region's checksum is @var{crc32}.
40353 @end table
40354
40355 @item QDisableRandomization:@var{value}
40356 @cindex disable address space randomization, remote request
40357 @cindex @samp{QDisableRandomization} packet
40358 Some target operating systems will randomize the virtual address space
40359 of the inferior process as a security feature, but provide a feature
40360 to disable such randomization, e.g.@: to allow for a more deterministic
40361 debugging experience. On such systems, this packet with a @var{value}
40362 of 1 directs the target to disable address space randomization for
40363 processes subsequently started via @samp{vRun} packets, while a packet
40364 with a @var{value} of 0 tells the target to enable address space
40365 randomization.
40366
40367 This packet is only available in extended mode (@pxref{extended mode}).
40368
40369 Reply:
40370 @table @samp
40371 @item OK
40372 The request succeeded.
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{QDisableRandomization} is not supported
40379 by the stub.
40380 @end table
40381
40382 This packet is not probed by default; the remote stub must request it,
40383 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40384 This should only be done on targets that actually support disabling
40385 address space randomization.
40386
40387 @item QStartupWithShell:@var{value}
40388 @cindex startup with shell, remote request
40389 @cindex @samp{QStartupWithShell} packet
40390 On UNIX-like targets, it is possible to start the inferior using a
40391 shell program. This is the default behavior on both @value{GDBN} and
40392 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40393 used to inform @command{gdbserver} whether it should start the
40394 inferior using a shell or not.
40395
40396 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40397 to start the inferior. If @var{value} is @samp{1},
40398 @command{gdbserver} will use a shell to start the inferior. All other
40399 values are considered an error.
40400
40401 This packet is only available in extended mode (@pxref{extended
40402 mode}).
40403
40404 Reply:
40405 @table @samp
40406 @item OK
40407 The request succeeded.
40408
40409 @item E @var{nn}
40410 An error occurred. The error number @var{nn} is given as hex digits.
40411 @end table
40412
40413 This packet is not probed by default; the remote stub must request it,
40414 by supplying an appropriate @samp{qSupported} response
40415 (@pxref{qSupported}). This should only be done on targets that
40416 actually support starting the inferior using a shell.
40417
40418 Use of this packet is controlled by the @code{set startup-with-shell}
40419 command; @pxref{set startup-with-shell}.
40420
40421 @item QEnvironmentHexEncoded:@var{hex-value}
40422 @anchor{QEnvironmentHexEncoded}
40423 @cindex set environment variable, remote request
40424 @cindex @samp{QEnvironmentHexEncoded} packet
40425 On UNIX-like targets, it is possible to set environment variables that
40426 will be passed to the inferior during the startup process. This
40427 packet is used to inform @command{gdbserver} of an environment
40428 variable that has been defined by the user on @value{GDBN} (@pxref{set
40429 environment}).
40430
40431 The packet is composed by @var{hex-value}, an hex encoded
40432 representation of the @var{name=value} format representing an
40433 environment variable. The name of the environment variable is
40434 represented by @var{name}, and the value to be assigned to the
40435 environment variable is represented by @var{value}. If the variable
40436 has no value (i.e., the value is @code{null}), then @var{value} will
40437 not be present.
40438
40439 This packet is only available in extended mode (@pxref{extended
40440 mode}).
40441
40442 Reply:
40443 @table @samp
40444 @item OK
40445 The request succeeded.
40446 @end table
40447
40448 This packet is not probed by default; the remote stub must request it,
40449 by supplying an appropriate @samp{qSupported} response
40450 (@pxref{qSupported}). This should only be done on targets that
40451 actually support passing environment variables to the starting
40452 inferior.
40453
40454 This packet is related to the @code{set environment} command;
40455 @pxref{set environment}.
40456
40457 @item QEnvironmentUnset:@var{hex-value}
40458 @anchor{QEnvironmentUnset}
40459 @cindex unset environment variable, remote request
40460 @cindex @samp{QEnvironmentUnset} packet
40461 On UNIX-like targets, it is possible to unset environment variables
40462 before starting the inferior in the remote target. This packet is
40463 used to inform @command{gdbserver} of an environment variable that has
40464 been unset by the user on @value{GDBN} (@pxref{unset environment}).
40465
40466 The packet is composed by @var{hex-value}, an hex encoded
40467 representation of the name of the environment variable to be unset.
40468
40469 This packet is only available in extended mode (@pxref{extended
40470 mode}).
40471
40472 Reply:
40473 @table @samp
40474 @item OK
40475 The request succeeded.
40476 @end table
40477
40478 This packet is not probed by default; the remote stub must request it,
40479 by supplying an appropriate @samp{qSupported} response
40480 (@pxref{qSupported}). This should only be done on targets that
40481 actually support passing environment variables to the starting
40482 inferior.
40483
40484 This packet is related to the @code{unset environment} command;
40485 @pxref{unset environment}.
40486
40487 @item QEnvironmentReset
40488 @anchor{QEnvironmentReset}
40489 @cindex reset environment, remote request
40490 @cindex @samp{QEnvironmentReset} packet
40491 On UNIX-like targets, this packet is used to reset the state of
40492 environment variables in the remote target before starting the
40493 inferior. In this context, reset means unsetting all environment
40494 variables that were previously set by the user (i.e., were not
40495 initially present in the environment). It is sent to
40496 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40497 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40498 (@pxref{QEnvironmentUnset}) packets.
40499
40500 This packet is only available in extended mode (@pxref{extended
40501 mode}).
40502
40503 Reply:
40504 @table @samp
40505 @item OK
40506 The request succeeded.
40507 @end table
40508
40509 This packet is not probed by default; the remote stub must request it,
40510 by supplying an appropriate @samp{qSupported} response
40511 (@pxref{qSupported}). This should only be done on targets that
40512 actually support passing environment variables to the starting
40513 inferior.
40514
40515 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
40516 @anchor{QSetWorkingDir packet}
40517 @cindex set working directory, remote request
40518 @cindex @samp{QSetWorkingDir} packet
40519 This packet is used to inform the remote server of the intended
40520 current working directory for programs that are going to be executed.
40521
40522 The packet is composed by @var{directory}, an hex encoded
40523 representation of the directory that the remote inferior will use as
40524 its current working directory. If @var{directory} is an empty string,
40525 the remote server should reset the inferior's current working
40526 directory to its original, empty value.
40527
40528 This packet is only available in extended mode (@pxref{extended
40529 mode}).
40530
40531 Reply:
40532 @table @samp
40533 @item OK
40534 The request succeeded.
40535 @end table
40536
40537 @item qfThreadInfo
40538 @itemx qsThreadInfo
40539 @cindex list active threads, remote request
40540 @cindex @samp{qfThreadInfo} packet
40541 @cindex @samp{qsThreadInfo} packet
40542 Obtain a list of all active thread IDs from the target (OS). Since there
40543 may be too many active threads to fit into one reply packet, this query
40544 works iteratively: it may require more than one query/reply sequence to
40545 obtain the entire list of threads. The first query of the sequence will
40546 be the @samp{qfThreadInfo} query; subsequent queries in the
40547 sequence will be the @samp{qsThreadInfo} query.
40548
40549 NOTE: This packet replaces the @samp{qL} query (see below).
40550
40551 Reply:
40552 @table @samp
40553 @item m @var{thread-id}
40554 A single thread ID
40555 @item m @var{thread-id},@var{thread-id}@dots{}
40556 a comma-separated list of thread IDs
40557 @item l
40558 (lower case letter @samp{L}) denotes end of list.
40559 @end table
40560
40561 In response to each query, the target will reply with a list of one or
40562 more thread IDs, separated by commas.
40563 @value{GDBN} will respond to each reply with a request for more thread
40564 ids (using the @samp{qs} form of the query), until the target responds
40565 with @samp{l} (lower-case ell, for @dfn{last}).
40566 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40567 fields.
40568
40569 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40570 initial connection with the remote target, and the very first thread ID
40571 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40572 message. Therefore, the stub should ensure that the first thread ID in
40573 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40574
40575 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
40576 @cindex get thread-local storage address, remote request
40577 @cindex @samp{qGetTLSAddr} packet
40578 Fetch the address associated with thread local storage specified
40579 by @var{thread-id}, @var{offset}, and @var{lm}.
40580
40581 @var{thread-id} is the thread ID associated with the
40582 thread for which to fetch the TLS address. @xref{thread-id syntax}.
40583
40584 @var{offset} is the (big endian, hex encoded) offset associated with the
40585 thread local variable. (This offset is obtained from the debug
40586 information associated with the variable.)
40587
40588 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
40589 load module associated with the thread local storage. For example,
40590 a @sc{gnu}/Linux system will pass the link map address of the shared
40591 object associated with the thread local storage under consideration.
40592 Other operating environments may choose to represent the load module
40593 differently, so the precise meaning of this parameter will vary.
40594
40595 Reply:
40596 @table @samp
40597 @item @var{XX}@dots{}
40598 Hex encoded (big endian) bytes representing the address of the thread
40599 local storage requested.
40600
40601 @item E @var{nn}
40602 An error occurred. The error number @var{nn} is given as hex digits.
40603
40604 @item @w{}
40605 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
40606 @end table
40607
40608 @item qGetTIBAddr:@var{thread-id}
40609 @cindex get thread information block address
40610 @cindex @samp{qGetTIBAddr} packet
40611 Fetch address of the Windows OS specific Thread Information Block.
40612
40613 @var{thread-id} is the thread ID associated with the thread.
40614
40615 Reply:
40616 @table @samp
40617 @item @var{XX}@dots{}
40618 Hex encoded (big endian) bytes representing the linear address of the
40619 thread information block.
40620
40621 @item E @var{nn}
40622 An error occured. This means that either the thread was not found, or the
40623 address could not be retrieved.
40624
40625 @item @w{}
40626 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40627 @end table
40628
40629 @item qL @var{startflag} @var{threadcount} @var{nextthread}
40630 Obtain thread information from RTOS. Where: @var{startflag} (one hex
40631 digit) is one to indicate the first query and zero to indicate a
40632 subsequent query; @var{threadcount} (two hex digits) is the maximum
40633 number of threads the response packet can contain; and @var{nextthread}
40634 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
40635 returned in the response as @var{argthread}.
40636
40637 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
40638
40639 Reply:
40640 @table @samp
40641 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
40642 Where: @var{count} (two hex digits) is the number of threads being
40643 returned; @var{done} (one hex digit) is zero to indicate more threads
40644 and one indicates no further threads; @var{argthreadid} (eight hex
40645 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
40646 is a sequence of thread IDs, @var{threadid} (eight hex
40647 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
40648 @end table
40649
40650 @item qOffsets
40651 @cindex section offsets, remote request
40652 @cindex @samp{qOffsets} packet
40653 Get section offsets that the target used when relocating the downloaded
40654 image.
40655
40656 Reply:
40657 @table @samp
40658 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40659 Relocate the @code{Text} section by @var{xxx} from its original address.
40660 Relocate the @code{Data} section by @var{yyy} from its original address.
40661 If the object file format provides segment information (e.g.@: @sc{elf}
40662 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40663 segments by the supplied offsets.
40664
40665 @emph{Note: while a @code{Bss} offset may be included in the response,
40666 @value{GDBN} ignores this and instead applies the @code{Data} offset
40667 to the @code{Bss} section.}
40668
40669 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40670 Relocate the first segment of the object file, which conventionally
40671 contains program code, to a starting address of @var{xxx}. If
40672 @samp{DataSeg} is specified, relocate the second segment, which
40673 conventionally contains modifiable data, to a starting address of
40674 @var{yyy}. @value{GDBN} will report an error if the object file
40675 does not contain segment information, or does not contain at least
40676 as many segments as mentioned in the reply. Extra segments are
40677 kept at fixed offsets relative to the last relocated segment.
40678 @end table
40679
40680 @item qP @var{mode} @var{thread-id}
40681 @cindex thread information, remote request
40682 @cindex @samp{qP} packet
40683 Returns information on @var{thread-id}. Where: @var{mode} is a hex
40684 encoded 32 bit mode; @var{thread-id} is a thread ID
40685 (@pxref{thread-id syntax}).
40686
40687 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40688 (see below).
40689
40690 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
40691
40692 @item QNonStop:1
40693 @itemx QNonStop:0
40694 @cindex non-stop mode, remote request
40695 @cindex @samp{QNonStop} packet
40696 @anchor{QNonStop}
40697 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40698 @xref{Remote Non-Stop}, for more information.
40699
40700 Reply:
40701 @table @samp
40702 @item OK
40703 The request succeeded.
40704
40705 @item E @var{nn}
40706 An error occurred. The error number @var{nn} is given as hex digits.
40707
40708 @item @w{}
40709 An empty reply indicates that @samp{QNonStop} is not supported by
40710 the stub.
40711 @end table
40712
40713 This packet is not probed by default; the remote stub must request it,
40714 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40715 Use of this packet is controlled by the @code{set non-stop} command;
40716 @pxref{Non-Stop Mode}.
40717
40718 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40719 @itemx QCatchSyscalls:0
40720 @cindex catch syscalls from inferior, remote request
40721 @cindex @samp{QCatchSyscalls} packet
40722 @anchor{QCatchSyscalls}
40723 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40724 catching syscalls from the inferior process.
40725
40726 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40727 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40728 is listed, every system call should be reported.
40729
40730 Note that if a syscall not in the list is reported, @value{GDBN} will
40731 still filter the event according to its own list from all corresponding
40732 @code{catch syscall} commands. However, it is more efficient to only
40733 report the requested syscalls.
40734
40735 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40736 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
40737
40738 If the inferior process execs, the state of @samp{QCatchSyscalls} is
40739 kept for the new process too. On targets where exec may affect syscall
40740 numbers, for example with exec between 32 and 64-bit processes, the
40741 client should send a new packet with the new syscall list.
40742
40743 Reply:
40744 @table @samp
40745 @item OK
40746 The request succeeded.
40747
40748 @item E @var{nn}
40749 An error occurred. @var{nn} are hex digits.
40750
40751 @item @w{}
40752 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40753 the stub.
40754 @end table
40755
40756 Use of this packet is controlled by the @code{set remote catch-syscalls}
40757 command (@pxref{Remote Configuration, set remote catch-syscalls}).
40758 This packet is not probed by default; the remote stub must request it,
40759 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40760
40761 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40762 @cindex pass signals to inferior, remote request
40763 @cindex @samp{QPassSignals} packet
40764 @anchor{QPassSignals}
40765 Each listed @var{signal} should be passed directly to the inferior process.
40766 Signals are numbered identically to continue packets and stop replies
40767 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40768 strictly greater than the previous item. These signals do not need to stop
40769 the inferior, or be reported to @value{GDBN}. All other signals should be
40770 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40771 combine; any earlier @samp{QPassSignals} list is completely replaced by the
40772 new list. This packet improves performance when using @samp{handle
40773 @var{signal} nostop noprint pass}.
40774
40775 Reply:
40776 @table @samp
40777 @item OK
40778 The request succeeded.
40779
40780 @item E @var{nn}
40781 An error occurred. The error number @var{nn} is given as hex digits.
40782
40783 @item @w{}
40784 An empty reply indicates that @samp{QPassSignals} is not supported by
40785 the stub.
40786 @end table
40787
40788 Use of this packet is controlled by the @code{set remote pass-signals}
40789 command (@pxref{Remote Configuration, set remote pass-signals}).
40790 This packet is not probed by default; the remote stub must request it,
40791 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40792
40793 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40794 @cindex signals the inferior may see, remote request
40795 @cindex @samp{QProgramSignals} packet
40796 @anchor{QProgramSignals}
40797 Each listed @var{signal} may be delivered to the inferior process.
40798 Others should be silently discarded.
40799
40800 In some cases, the remote stub may need to decide whether to deliver a
40801 signal to the program or not without @value{GDBN} involvement. One
40802 example of that is while detaching --- the program's threads may have
40803 stopped for signals that haven't yet had a chance of being reported to
40804 @value{GDBN}, and so the remote stub can use the signal list specified
40805 by this packet to know whether to deliver or ignore those pending
40806 signals.
40807
40808 This does not influence whether to deliver a signal as requested by a
40809 resumption packet (@pxref{vCont packet}).
40810
40811 Signals are numbered identically to continue packets and stop replies
40812 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40813 strictly greater than the previous item. Multiple
40814 @samp{QProgramSignals} packets do not combine; any earlier
40815 @samp{QProgramSignals} list is completely replaced by the new list.
40816
40817 Reply:
40818 @table @samp
40819 @item OK
40820 The request succeeded.
40821
40822 @item E @var{nn}
40823 An error occurred. The error number @var{nn} is given as hex digits.
40824
40825 @item @w{}
40826 An empty reply indicates that @samp{QProgramSignals} is not supported
40827 by the stub.
40828 @end table
40829
40830 Use of this packet is controlled by the @code{set remote program-signals}
40831 command (@pxref{Remote Configuration, set remote program-signals}).
40832 This packet is not probed by default; the remote stub must request it,
40833 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40834
40835 @anchor{QThreadEvents}
40836 @item QThreadEvents:1
40837 @itemx QThreadEvents:0
40838 @cindex thread create/exit events, remote request
40839 @cindex @samp{QThreadEvents} packet
40840
40841 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40842 reporting of thread create and exit events. @xref{thread create
40843 event}, for the reply specifications. For example, this is used in
40844 non-stop mode when @value{GDBN} stops a set of threads and
40845 synchronously waits for the their corresponding stop replies. Without
40846 exit events, if one of the threads exits, @value{GDBN} would hang
40847 forever not knowing that it should no longer expect a stop for that
40848 same thread. @value{GDBN} does not enable this feature unless the
40849 stub reports that it supports it by including @samp{QThreadEvents+} in
40850 its @samp{qSupported} reply.
40851
40852 Reply:
40853 @table @samp
40854 @item OK
40855 The request succeeded.
40856
40857 @item E @var{nn}
40858 An error occurred. The error number @var{nn} is given as hex digits.
40859
40860 @item @w{}
40861 An empty reply indicates that @samp{QThreadEvents} is not supported by
40862 the stub.
40863 @end table
40864
40865 Use of this packet is controlled by the @code{set remote thread-events}
40866 command (@pxref{Remote Configuration, set remote thread-events}).
40867
40868 @item qRcmd,@var{command}
40869 @cindex execute remote command, remote request
40870 @cindex @samp{qRcmd} packet
40871 @var{command} (hex encoded) is passed to the local interpreter for
40872 execution. Invalid commands should be reported using the output
40873 string. Before the final result packet, the target may also respond
40874 with a number of intermediate @samp{O@var{output}} console output
40875 packets. @emph{Implementors should note that providing access to a
40876 stubs's interpreter may have security implications}.
40877
40878 Reply:
40879 @table @samp
40880 @item OK
40881 A command response with no output.
40882 @item @var{OUTPUT}
40883 A command response with the hex encoded output string @var{OUTPUT}.
40884 @item E @var{NN}
40885 Indicate a badly formed request.
40886 @item @w{}
40887 An empty reply indicates that @samp{qRcmd} is not recognized.
40888 @end table
40889
40890 (Note that the @code{qRcmd} packet's name is separated from the
40891 command by a @samp{,}, not a @samp{:}, contrary to the naming
40892 conventions above. Please don't use this packet as a model for new
40893 packets.)
40894
40895 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40896 @cindex searching memory, in remote debugging
40897 @ifnotinfo
40898 @cindex @samp{qSearch:memory} packet
40899 @end ifnotinfo
40900 @cindex @samp{qSearch memory} packet
40901 @anchor{qSearch memory}
40902 Search @var{length} bytes at @var{address} for @var{search-pattern}.
40903 Both @var{address} and @var{length} are encoded in hex;
40904 @var{search-pattern} is a sequence of bytes, also hex encoded.
40905
40906 Reply:
40907 @table @samp
40908 @item 0
40909 The pattern was not found.
40910 @item 1,address
40911 The pattern was found at @var{address}.
40912 @item E @var{NN}
40913 A badly formed request or an error was encountered while searching memory.
40914 @item @w{}
40915 An empty reply indicates that @samp{qSearch:memory} is not recognized.
40916 @end table
40917
40918 @item QStartNoAckMode
40919 @cindex @samp{QStartNoAckMode} packet
40920 @anchor{QStartNoAckMode}
40921 Request that the remote stub disable the normal @samp{+}/@samp{-}
40922 protocol acknowledgments (@pxref{Packet Acknowledgment}).
40923
40924 Reply:
40925 @table @samp
40926 @item OK
40927 The stub has switched to no-acknowledgment mode.
40928 @value{GDBN} acknowledges this response,
40929 but neither the stub nor @value{GDBN} shall send or expect further
40930 @samp{+}/@samp{-} acknowledgments in the current connection.
40931 @item @w{}
40932 An empty reply indicates that the stub does not support no-acknowledgment mode.
40933 @end table
40934
40935 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40936 @cindex supported packets, remote query
40937 @cindex features of the remote protocol
40938 @cindex @samp{qSupported} packet
40939 @anchor{qSupported}
40940 Tell the remote stub about features supported by @value{GDBN}, and
40941 query the stub for features it supports. This packet allows
40942 @value{GDBN} and the remote stub to take advantage of each others'
40943 features. @samp{qSupported} also consolidates multiple feature probes
40944 at startup, to improve @value{GDBN} performance---a single larger
40945 packet performs better than multiple smaller probe packets on
40946 high-latency links. Some features may enable behavior which must not
40947 be on by default, e.g.@: because it would confuse older clients or
40948 stubs. Other features may describe packets which could be
40949 automatically probed for, but are not. These features must be
40950 reported before @value{GDBN} will use them. This ``default
40951 unsupported'' behavior is not appropriate for all packets, but it
40952 helps to keep the initial connection time under control with new
40953 versions of @value{GDBN} which support increasing numbers of packets.
40954
40955 Reply:
40956 @table @samp
40957 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40958 The stub supports or does not support each returned @var{stubfeature},
40959 depending on the form of each @var{stubfeature} (see below for the
40960 possible forms).
40961 @item @w{}
40962 An empty reply indicates that @samp{qSupported} is not recognized,
40963 or that no features needed to be reported to @value{GDBN}.
40964 @end table
40965
40966 The allowed forms for each feature (either a @var{gdbfeature} in the
40967 @samp{qSupported} packet, or a @var{stubfeature} in the response)
40968 are:
40969
40970 @table @samp
40971 @item @var{name}=@var{value}
40972 The remote protocol feature @var{name} is supported, and associated
40973 with the specified @var{value}. The format of @var{value} depends
40974 on the feature, but it must not include a semicolon.
40975 @item @var{name}+
40976 The remote protocol feature @var{name} is supported, and does not
40977 need an associated value.
40978 @item @var{name}-
40979 The remote protocol feature @var{name} is not supported.
40980 @item @var{name}?
40981 The remote protocol feature @var{name} may be supported, and
40982 @value{GDBN} should auto-detect support in some other way when it is
40983 needed. This form will not be used for @var{gdbfeature} notifications,
40984 but may be used for @var{stubfeature} responses.
40985 @end table
40986
40987 Whenever the stub receives a @samp{qSupported} request, the
40988 supplied set of @value{GDBN} features should override any previous
40989 request. This allows @value{GDBN} to put the stub in a known
40990 state, even if the stub had previously been communicating with
40991 a different version of @value{GDBN}.
40992
40993 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
40994 are defined:
40995
40996 @table @samp
40997 @item multiprocess
40998 This feature indicates whether @value{GDBN} supports multiprocess
40999 extensions to the remote protocol. @value{GDBN} does not use such
41000 extensions unless the stub also reports that it supports them by
41001 including @samp{multiprocess+} in its @samp{qSupported} reply.
41002 @xref{multiprocess extensions}, for details.
41003
41004 @item xmlRegisters
41005 This feature indicates that @value{GDBN} supports the XML target
41006 description. If the stub sees @samp{xmlRegisters=} with target
41007 specific strings separated by a comma, it will report register
41008 description.
41009
41010 @item qRelocInsn
41011 This feature indicates whether @value{GDBN} supports the
41012 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41013 instruction reply packet}).
41014
41015 @item swbreak
41016 This feature indicates whether @value{GDBN} supports the swbreak stop
41017 reason in stop replies. @xref{swbreak stop reason}, for details.
41018
41019 @item hwbreak
41020 This feature indicates whether @value{GDBN} supports the hwbreak stop
41021 reason in stop replies. @xref{swbreak stop reason}, for details.
41022
41023 @item fork-events
41024 This feature indicates whether @value{GDBN} supports fork event
41025 extensions to the remote protocol. @value{GDBN} does not use such
41026 extensions unless the stub also reports that it supports them by
41027 including @samp{fork-events+} in its @samp{qSupported} reply.
41028
41029 @item vfork-events
41030 This feature indicates whether @value{GDBN} supports vfork event
41031 extensions to the remote protocol. @value{GDBN} does not use such
41032 extensions unless the stub also reports that it supports them by
41033 including @samp{vfork-events+} in its @samp{qSupported} reply.
41034
41035 @item exec-events
41036 This feature indicates whether @value{GDBN} supports exec event
41037 extensions to the remote protocol. @value{GDBN} does not use such
41038 extensions unless the stub also reports that it supports them by
41039 including @samp{exec-events+} in its @samp{qSupported} reply.
41040
41041 @item vContSupported
41042 This feature indicates whether @value{GDBN} wants to know the
41043 supported actions in the reply to @samp{vCont?} packet.
41044 @end table
41045
41046 Stubs should ignore any unknown values for
41047 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41048 packet supports receiving packets of unlimited length (earlier
41049 versions of @value{GDBN} may reject overly long responses). Additional values
41050 for @var{gdbfeature} may be defined in the future to let the stub take
41051 advantage of new features in @value{GDBN}, e.g.@: incompatible
41052 improvements in the remote protocol---the @samp{multiprocess} feature is
41053 an example of such a feature. The stub's reply should be independent
41054 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41055 describes all the features it supports, and then the stub replies with
41056 all the features it supports.
41057
41058 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41059 responses, as long as each response uses one of the standard forms.
41060
41061 Some features are flags. A stub which supports a flag feature
41062 should respond with a @samp{+} form response. Other features
41063 require values, and the stub should respond with an @samp{=}
41064 form response.
41065
41066 Each feature has a default value, which @value{GDBN} will use if
41067 @samp{qSupported} is not available or if the feature is not mentioned
41068 in the @samp{qSupported} response. The default values are fixed; a
41069 stub is free to omit any feature responses that match the defaults.
41070
41071 Not all features can be probed, but for those which can, the probing
41072 mechanism is useful: in some cases, a stub's internal
41073 architecture may not allow the protocol layer to know some information
41074 about the underlying target in advance. This is especially common in
41075 stubs which may be configured for multiple targets.
41076
41077 These are the currently defined stub features and their properties:
41078
41079 @multitable @columnfractions 0.35 0.2 0.12 0.2
41080 @c NOTE: The first row should be @headitem, but we do not yet require
41081 @c a new enough version of Texinfo (4.7) to use @headitem.
41082 @item Feature Name
41083 @tab Value Required
41084 @tab Default
41085 @tab Probe Allowed
41086
41087 @item @samp{PacketSize}
41088 @tab Yes
41089 @tab @samp{-}
41090 @tab No
41091
41092 @item @samp{qXfer:auxv:read}
41093 @tab No
41094 @tab @samp{-}
41095 @tab Yes
41096
41097 @item @samp{qXfer:btrace:read}
41098 @tab No
41099 @tab @samp{-}
41100 @tab Yes
41101
41102 @item @samp{qXfer:btrace-conf:read}
41103 @tab No
41104 @tab @samp{-}
41105 @tab Yes
41106
41107 @item @samp{qXfer:exec-file:read}
41108 @tab No
41109 @tab @samp{-}
41110 @tab Yes
41111
41112 @item @samp{qXfer:features:read}
41113 @tab No
41114 @tab @samp{-}
41115 @tab Yes
41116
41117 @item @samp{qXfer:libraries:read}
41118 @tab No
41119 @tab @samp{-}
41120 @tab Yes
41121
41122 @item @samp{qXfer:libraries-svr4:read}
41123 @tab No
41124 @tab @samp{-}
41125 @tab Yes
41126
41127 @item @samp{augmented-libraries-svr4-read}
41128 @tab No
41129 @tab @samp{-}
41130 @tab No
41131
41132 @item @samp{qXfer:memory-map:read}
41133 @tab No
41134 @tab @samp{-}
41135 @tab Yes
41136
41137 @item @samp{qXfer:sdata:read}
41138 @tab No
41139 @tab @samp{-}
41140 @tab Yes
41141
41142 @item @samp{qXfer:siginfo:read}
41143 @tab No
41144 @tab @samp{-}
41145 @tab Yes
41146
41147 @item @samp{qXfer:siginfo:write}
41148 @tab No
41149 @tab @samp{-}
41150 @tab Yes
41151
41152 @item @samp{qXfer:threads:read}
41153 @tab No
41154 @tab @samp{-}
41155 @tab Yes
41156
41157 @item @samp{qXfer:traceframe-info:read}
41158 @tab No
41159 @tab @samp{-}
41160 @tab Yes
41161
41162 @item @samp{qXfer:uib:read}
41163 @tab No
41164 @tab @samp{-}
41165 @tab Yes
41166
41167 @item @samp{qXfer:fdpic:read}
41168 @tab No
41169 @tab @samp{-}
41170 @tab Yes
41171
41172 @item @samp{Qbtrace:off}
41173 @tab Yes
41174 @tab @samp{-}
41175 @tab Yes
41176
41177 @item @samp{Qbtrace:bts}
41178 @tab Yes
41179 @tab @samp{-}
41180 @tab Yes
41181
41182 @item @samp{Qbtrace:pt}
41183 @tab Yes
41184 @tab @samp{-}
41185 @tab Yes
41186
41187 @item @samp{Qbtrace-conf:bts:size}
41188 @tab Yes
41189 @tab @samp{-}
41190 @tab Yes
41191
41192 @item @samp{Qbtrace-conf:pt:size}
41193 @tab Yes
41194 @tab @samp{-}
41195 @tab Yes
41196
41197 @item @samp{QNonStop}
41198 @tab No
41199 @tab @samp{-}
41200 @tab Yes
41201
41202 @item @samp{QCatchSyscalls}
41203 @tab No
41204 @tab @samp{-}
41205 @tab Yes
41206
41207 @item @samp{QPassSignals}
41208 @tab No
41209 @tab @samp{-}
41210 @tab Yes
41211
41212 @item @samp{QStartNoAckMode}
41213 @tab No
41214 @tab @samp{-}
41215 @tab Yes
41216
41217 @item @samp{multiprocess}
41218 @tab No
41219 @tab @samp{-}
41220 @tab No
41221
41222 @item @samp{ConditionalBreakpoints}
41223 @tab No
41224 @tab @samp{-}
41225 @tab No
41226
41227 @item @samp{ConditionalTracepoints}
41228 @tab No
41229 @tab @samp{-}
41230 @tab No
41231
41232 @item @samp{ReverseContinue}
41233 @tab No
41234 @tab @samp{-}
41235 @tab No
41236
41237 @item @samp{ReverseStep}
41238 @tab No
41239 @tab @samp{-}
41240 @tab No
41241
41242 @item @samp{TracepointSource}
41243 @tab No
41244 @tab @samp{-}
41245 @tab No
41246
41247 @item @samp{QAgent}
41248 @tab No
41249 @tab @samp{-}
41250 @tab No
41251
41252 @item @samp{QAllow}
41253 @tab No
41254 @tab @samp{-}
41255 @tab No
41256
41257 @item @samp{QDisableRandomization}
41258 @tab No
41259 @tab @samp{-}
41260 @tab No
41261
41262 @item @samp{EnableDisableTracepoints}
41263 @tab No
41264 @tab @samp{-}
41265 @tab No
41266
41267 @item @samp{QTBuffer:size}
41268 @tab No
41269 @tab @samp{-}
41270 @tab No
41271
41272 @item @samp{tracenz}
41273 @tab No
41274 @tab @samp{-}
41275 @tab No
41276
41277 @item @samp{BreakpointCommands}
41278 @tab No
41279 @tab @samp{-}
41280 @tab No
41281
41282 @item @samp{swbreak}
41283 @tab No
41284 @tab @samp{-}
41285 @tab No
41286
41287 @item @samp{hwbreak}
41288 @tab No
41289 @tab @samp{-}
41290 @tab No
41291
41292 @item @samp{fork-events}
41293 @tab No
41294 @tab @samp{-}
41295 @tab No
41296
41297 @item @samp{vfork-events}
41298 @tab No
41299 @tab @samp{-}
41300 @tab No
41301
41302 @item @samp{exec-events}
41303 @tab No
41304 @tab @samp{-}
41305 @tab No
41306
41307 @item @samp{QThreadEvents}
41308 @tab No
41309 @tab @samp{-}
41310 @tab No
41311
41312 @item @samp{no-resumed}
41313 @tab No
41314 @tab @samp{-}
41315 @tab No
41316
41317 @end multitable
41318
41319 These are the currently defined stub features, in more detail:
41320
41321 @table @samp
41322 @cindex packet size, remote protocol
41323 @item PacketSize=@var{bytes}
41324 The remote stub can accept packets up to at least @var{bytes} in
41325 length. @value{GDBN} will send packets up to this size for bulk
41326 transfers, and will never send larger packets. This is a limit on the
41327 data characters in the packet, including the frame and checksum.
41328 There is no trailing NUL byte in a remote protocol packet; if the stub
41329 stores packets in a NUL-terminated format, it should allow an extra
41330 byte in its buffer for the NUL. If this stub feature is not supported,
41331 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41332
41333 @item qXfer:auxv:read
41334 The remote stub understands the @samp{qXfer:auxv:read} packet
41335 (@pxref{qXfer auxiliary vector read}).
41336
41337 @item qXfer:btrace:read
41338 The remote stub understands the @samp{qXfer:btrace:read}
41339 packet (@pxref{qXfer btrace read}).
41340
41341 @item qXfer:btrace-conf:read
41342 The remote stub understands the @samp{qXfer:btrace-conf:read}
41343 packet (@pxref{qXfer btrace-conf read}).
41344
41345 @item qXfer:exec-file:read
41346 The remote stub understands the @samp{qXfer:exec-file:read} packet
41347 (@pxref{qXfer executable filename read}).
41348
41349 @item qXfer:features:read
41350 The remote stub understands the @samp{qXfer:features:read} packet
41351 (@pxref{qXfer target description read}).
41352
41353 @item qXfer:libraries:read
41354 The remote stub understands the @samp{qXfer:libraries:read} packet
41355 (@pxref{qXfer library list read}).
41356
41357 @item qXfer:libraries-svr4:read
41358 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41359 (@pxref{qXfer svr4 library list read}).
41360
41361 @item augmented-libraries-svr4-read
41362 The remote stub understands the augmented form of the
41363 @samp{qXfer:libraries-svr4:read} packet
41364 (@pxref{qXfer svr4 library list read}).
41365
41366 @item qXfer:memory-map:read
41367 The remote stub understands the @samp{qXfer:memory-map:read} packet
41368 (@pxref{qXfer memory map read}).
41369
41370 @item qXfer:sdata:read
41371 The remote stub understands the @samp{qXfer:sdata:read} packet
41372 (@pxref{qXfer sdata read}).
41373
41374 @item qXfer:siginfo:read
41375 The remote stub understands the @samp{qXfer:siginfo:read} packet
41376 (@pxref{qXfer siginfo read}).
41377
41378 @item qXfer:siginfo:write
41379 The remote stub understands the @samp{qXfer:siginfo:write} packet
41380 (@pxref{qXfer siginfo write}).
41381
41382 @item qXfer:threads:read
41383 The remote stub understands the @samp{qXfer:threads:read} packet
41384 (@pxref{qXfer threads read}).
41385
41386 @item qXfer:traceframe-info:read
41387 The remote stub understands the @samp{qXfer:traceframe-info:read}
41388 packet (@pxref{qXfer traceframe info read}).
41389
41390 @item qXfer:uib:read
41391 The remote stub understands the @samp{qXfer:uib:read}
41392 packet (@pxref{qXfer unwind info block}).
41393
41394 @item qXfer:fdpic:read
41395 The remote stub understands the @samp{qXfer:fdpic:read}
41396 packet (@pxref{qXfer fdpic loadmap read}).
41397
41398 @item QNonStop
41399 The remote stub understands the @samp{QNonStop} packet
41400 (@pxref{QNonStop}).
41401
41402 @item QCatchSyscalls
41403 The remote stub understands the @samp{QCatchSyscalls} packet
41404 (@pxref{QCatchSyscalls}).
41405
41406 @item QPassSignals
41407 The remote stub understands the @samp{QPassSignals} packet
41408 (@pxref{QPassSignals}).
41409
41410 @item QStartNoAckMode
41411 The remote stub understands the @samp{QStartNoAckMode} packet and
41412 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41413
41414 @item multiprocess
41415 @anchor{multiprocess extensions}
41416 @cindex multiprocess extensions, in remote protocol
41417 The remote stub understands the multiprocess extensions to the remote
41418 protocol syntax. The multiprocess extensions affect the syntax of
41419 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41420 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41421 replies. Note that reporting this feature indicates support for the
41422 syntactic extensions only, not that the stub necessarily supports
41423 debugging of more than one process at a time. The stub must not use
41424 multiprocess extensions in packet replies unless @value{GDBN} has also
41425 indicated it supports them in its @samp{qSupported} request.
41426
41427 @item qXfer:osdata:read
41428 The remote stub understands the @samp{qXfer:osdata:read} packet
41429 ((@pxref{qXfer osdata read}).
41430
41431 @item ConditionalBreakpoints
41432 The target accepts and implements evaluation of conditional expressions
41433 defined for breakpoints. The target will only report breakpoint triggers
41434 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41435
41436 @item ConditionalTracepoints
41437 The remote stub accepts and implements conditional expressions defined
41438 for tracepoints (@pxref{Tracepoint Conditions}).
41439
41440 @item ReverseContinue
41441 The remote stub accepts and implements the reverse continue packet
41442 (@pxref{bc}).
41443
41444 @item ReverseStep
41445 The remote stub accepts and implements the reverse step packet
41446 (@pxref{bs}).
41447
41448 @item TracepointSource
41449 The remote stub understands the @samp{QTDPsrc} packet that supplies
41450 the source form of tracepoint definitions.
41451
41452 @item QAgent
41453 The remote stub understands the @samp{QAgent} packet.
41454
41455 @item QAllow
41456 The remote stub understands the @samp{QAllow} packet.
41457
41458 @item QDisableRandomization
41459 The remote stub understands the @samp{QDisableRandomization} packet.
41460
41461 @item StaticTracepoint
41462 @cindex static tracepoints, in remote protocol
41463 The remote stub supports static tracepoints.
41464
41465 @item InstallInTrace
41466 @anchor{install tracepoint in tracing}
41467 The remote stub supports installing tracepoint in tracing.
41468
41469 @item EnableDisableTracepoints
41470 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41471 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41472 to be enabled and disabled while a trace experiment is running.
41473
41474 @item QTBuffer:size
41475 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
41476 packet that allows to change the size of the trace buffer.
41477
41478 @item tracenz
41479 @cindex string tracing, in remote protocol
41480 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41481 See @ref{Bytecode Descriptions} for details about the bytecode.
41482
41483 @item BreakpointCommands
41484 @cindex breakpoint commands, in remote protocol
41485 The remote stub supports running a breakpoint's command list itself,
41486 rather than reporting the hit to @value{GDBN}.
41487
41488 @item Qbtrace:off
41489 The remote stub understands the @samp{Qbtrace:off} packet.
41490
41491 @item Qbtrace:bts
41492 The remote stub understands the @samp{Qbtrace:bts} packet.
41493
41494 @item Qbtrace:pt
41495 The remote stub understands the @samp{Qbtrace:pt} packet.
41496
41497 @item Qbtrace-conf:bts:size
41498 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41499
41500 @item Qbtrace-conf:pt:size
41501 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41502
41503 @item swbreak
41504 The remote stub reports the @samp{swbreak} stop reason for memory
41505 breakpoints.
41506
41507 @item hwbreak
41508 The remote stub reports the @samp{hwbreak} stop reason for hardware
41509 breakpoints.
41510
41511 @item fork-events
41512 The remote stub reports the @samp{fork} stop reason for fork events.
41513
41514 @item vfork-events
41515 The remote stub reports the @samp{vfork} stop reason for vfork events
41516 and vforkdone events.
41517
41518 @item exec-events
41519 The remote stub reports the @samp{exec} stop reason for exec events.
41520
41521 @item vContSupported
41522 The remote stub reports the supported actions in the reply to
41523 @samp{vCont?} packet.
41524
41525 @item QThreadEvents
41526 The remote stub understands the @samp{QThreadEvents} packet.
41527
41528 @item no-resumed
41529 The remote stub reports the @samp{N} stop reply.
41530
41531 @end table
41532
41533 @item qSymbol::
41534 @cindex symbol lookup, remote request
41535 @cindex @samp{qSymbol} packet
41536 Notify the target that @value{GDBN} is prepared to serve symbol lookup
41537 requests. Accept requests from the target for the values of symbols.
41538
41539 Reply:
41540 @table @samp
41541 @item OK
41542 The target does not need to look up any (more) symbols.
41543 @item qSymbol:@var{sym_name}
41544 The target requests the value of symbol @var{sym_name} (hex encoded).
41545 @value{GDBN} may provide the value by using the
41546 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41547 below.
41548 @end table
41549
41550 @item qSymbol:@var{sym_value}:@var{sym_name}
41551 Set the value of @var{sym_name} to @var{sym_value}.
41552
41553 @var{sym_name} (hex encoded) is the name of a symbol whose value the
41554 target has previously requested.
41555
41556 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41557 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
41558 will be empty.
41559
41560 Reply:
41561 @table @samp
41562 @item OK
41563 The target does not need to look up any (more) symbols.
41564 @item qSymbol:@var{sym_name}
41565 The target requests the value of a new symbol @var{sym_name} (hex
41566 encoded). @value{GDBN} will continue to supply the values of symbols
41567 (if available), until the target ceases to request them.
41568 @end table
41569
41570 @item qTBuffer
41571 @itemx QTBuffer
41572 @itemx QTDisconnected
41573 @itemx QTDP
41574 @itemx QTDPsrc
41575 @itemx QTDV
41576 @itemx qTfP
41577 @itemx qTfV
41578 @itemx QTFrame
41579 @itemx qTMinFTPILen
41580
41581 @xref{Tracepoint Packets}.
41582
41583 @item qThreadExtraInfo,@var{thread-id}
41584 @cindex thread attributes info, remote request
41585 @cindex @samp{qThreadExtraInfo} packet
41586 Obtain from the target OS a printable string description of thread
41587 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41588 for the forms of @var{thread-id}. This
41589 string may contain anything that the target OS thinks is interesting
41590 for @value{GDBN} to tell the user about the thread. The string is
41591 displayed in @value{GDBN}'s @code{info threads} display. Some
41592 examples of possible thread extra info strings are @samp{Runnable}, or
41593 @samp{Blocked on Mutex}.
41594
41595 Reply:
41596 @table @samp
41597 @item @var{XX}@dots{}
41598 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41599 comprising the printable string containing the extra information about
41600 the thread's attributes.
41601 @end table
41602
41603 (Note that the @code{qThreadExtraInfo} packet's name is separated from
41604 the command by a @samp{,}, not a @samp{:}, contrary to the naming
41605 conventions above. Please don't use this packet as a model for new
41606 packets.)
41607
41608 @item QTNotes
41609 @itemx qTP
41610 @itemx QTSave
41611 @itemx qTsP
41612 @itemx qTsV
41613 @itemx QTStart
41614 @itemx QTStop
41615 @itemx QTEnable
41616 @itemx QTDisable
41617 @itemx QTinit
41618 @itemx QTro
41619 @itemx qTStatus
41620 @itemx qTV
41621 @itemx qTfSTM
41622 @itemx qTsSTM
41623 @itemx qTSTMat
41624 @xref{Tracepoint Packets}.
41625
41626 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41627 @cindex read special object, remote request
41628 @cindex @samp{qXfer} packet
41629 @anchor{qXfer read}
41630 Read uninterpreted bytes from the target's special data area
41631 identified by the keyword @var{object}. Request @var{length} bytes
41632 starting at @var{offset} bytes into the data. The content and
41633 encoding of @var{annex} is specific to @var{object}; it can supply
41634 additional details about what data to access.
41635
41636 Reply:
41637 @table @samp
41638 @item m @var{data}
41639 Data @var{data} (@pxref{Binary Data}) has been read from the
41640 target. There may be more data at a higher address (although
41641 it is permitted to return @samp{m} even for the last valid
41642 block of data, as long as at least one byte of data was read).
41643 It is possible for @var{data} to have fewer bytes than the @var{length} in the
41644 request.
41645
41646 @item l @var{data}
41647 Data @var{data} (@pxref{Binary Data}) has been read from the target.
41648 There is no more data to be read. It is possible for @var{data} to
41649 have fewer bytes than the @var{length} in the request.
41650
41651 @item l
41652 The @var{offset} in the request is at the end of the data.
41653 There is no more data to be read.
41654
41655 @item E00
41656 The request was malformed, or @var{annex} was invalid.
41657
41658 @item E @var{nn}
41659 The offset was invalid, or there was an error encountered reading the data.
41660 The @var{nn} part is a hex-encoded @code{errno} value.
41661
41662 @item @w{}
41663 An empty reply indicates the @var{object} string was not recognized by
41664 the stub, or that the object does not support reading.
41665 @end table
41666
41667 Here are the specific requests of this form defined so far. All the
41668 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
41669 formats, listed above.
41670
41671 @table @samp
41672 @item qXfer:auxv:read::@var{offset},@var{length}
41673 @anchor{qXfer auxiliary vector read}
41674 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
41675 auxiliary vector}. Note @var{annex} must be empty.
41676
41677 This packet is not probed by default; the remote stub must request it,
41678 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41679
41680 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41681 @anchor{qXfer btrace read}
41682
41683 Return a description of the current branch trace.
41684 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41685 packet may have one of the following values:
41686
41687 @table @code
41688 @item all
41689 Returns all available branch trace.
41690
41691 @item new
41692 Returns all available branch trace if the branch trace changed since
41693 the last read request.
41694
41695 @item delta
41696 Returns the new branch trace since the last read request. Adds a new
41697 block to the end of the trace that begins at zero and ends at the source
41698 location of the first branch in the trace buffer. This extra block is
41699 used to stitch traces together.
41700
41701 If the trace buffer overflowed, returns an error indicating the overflow.
41702 @end table
41703
41704 This packet is not probed by default; the remote stub must request it
41705 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41706
41707 @item qXfer:btrace-conf:read::@var{offset},@var{length}
41708 @anchor{qXfer btrace-conf read}
41709
41710 Return a description of the current branch trace configuration.
41711 @xref{Branch Trace Configuration Format}.
41712
41713 This packet is not probed by default; the remote stub must request it
41714 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41715
41716 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41717 @anchor{qXfer executable filename read}
41718 Return the full absolute name of the file that was executed to create
41719 a process running on the remote system. The annex specifies the
41720 numeric process ID of the process to query, encoded as a hexadecimal
41721 number. If the annex part is empty the remote stub should return the
41722 filename corresponding to the currently executing process.
41723
41724 This packet is not probed by default; the remote stub must request it,
41725 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41726
41727 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41728 @anchor{qXfer target description read}
41729 Access the @dfn{target description}. @xref{Target Descriptions}. The
41730 annex specifies which XML document to access. The main description is
41731 always loaded from the @samp{target.xml} annex.
41732
41733 This packet is not probed by default; the remote stub must request it,
41734 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41735
41736 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41737 @anchor{qXfer library list read}
41738 Access the target's list of loaded libraries. @xref{Library List Format}.
41739 The annex part of the generic @samp{qXfer} packet must be empty
41740 (@pxref{qXfer read}).
41741
41742 Targets which maintain a list of libraries in the program's memory do
41743 not need to implement this packet; it is designed for platforms where
41744 the operating system manages the list of loaded libraries.
41745
41746 This packet is not probed by default; the remote stub must request it,
41747 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41748
41749 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41750 @anchor{qXfer svr4 library list read}
41751 Access the target's list of loaded libraries when the target is an SVR4
41752 platform. @xref{Library List Format for SVR4 Targets}. The annex part
41753 of the generic @samp{qXfer} packet must be empty unless the remote
41754 stub indicated it supports the augmented form of this packet
41755 by supplying an appropriate @samp{qSupported} response
41756 (@pxref{qXfer read}, @ref{qSupported}).
41757
41758 This packet is optional for better performance on SVR4 targets.
41759 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41760
41761 This packet is not probed by default; the remote stub must request it,
41762 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41763
41764 If the remote stub indicates it supports the augmented form of this
41765 packet then the annex part of the generic @samp{qXfer} packet may
41766 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41767 arguments. The currently supported arguments are:
41768
41769 @table @code
41770 @item start=@var{address}
41771 A hexadecimal number specifying the address of the @samp{struct
41772 link_map} to start reading the library list from. If unset or zero
41773 then the first @samp{struct link_map} in the library list will be
41774 chosen as the starting point.
41775
41776 @item prev=@var{address}
41777 A hexadecimal number specifying the address of the @samp{struct
41778 link_map} immediately preceding the @samp{struct link_map}
41779 specified by the @samp{start} argument. If unset or zero then
41780 the remote stub will expect that no @samp{struct link_map}
41781 exists prior to the starting point.
41782
41783 @end table
41784
41785 Arguments that are not understood by the remote stub will be silently
41786 ignored.
41787
41788 @item qXfer:memory-map:read::@var{offset},@var{length}
41789 @anchor{qXfer memory map read}
41790 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
41791 annex part of the generic @samp{qXfer} packet must be empty
41792 (@pxref{qXfer read}).
41793
41794 This packet is not probed by default; the remote stub must request it,
41795 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41796
41797 @item qXfer:sdata:read::@var{offset},@var{length}
41798 @anchor{qXfer sdata read}
41799
41800 Read contents of the extra collected static tracepoint marker
41801 information. The annex part of the generic @samp{qXfer} packet must
41802 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41803 Action Lists}.
41804
41805 This packet is not probed by default; the remote stub must request it,
41806 by supplying an appropriate @samp{qSupported} response
41807 (@pxref{qSupported}).
41808
41809 @item qXfer:siginfo:read::@var{offset},@var{length}
41810 @anchor{qXfer siginfo read}
41811 Read contents of the extra signal information on the target
41812 system. The annex part of the generic @samp{qXfer} packet must be
41813 empty (@pxref{qXfer read}).
41814
41815 This packet is not probed by default; the remote stub must request it,
41816 by supplying an appropriate @samp{qSupported} response
41817 (@pxref{qSupported}).
41818
41819 @item qXfer:threads:read::@var{offset},@var{length}
41820 @anchor{qXfer threads read}
41821 Access the list of threads on target. @xref{Thread List Format}. The
41822 annex part of the generic @samp{qXfer} packet must be empty
41823 (@pxref{qXfer read}).
41824
41825 This packet is not probed by default; the remote stub must request it,
41826 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41827
41828 @item qXfer:traceframe-info:read::@var{offset},@var{length}
41829 @anchor{qXfer traceframe info read}
41830
41831 Return a description of the current traceframe's contents.
41832 @xref{Traceframe Info Format}. The annex part of the generic
41833 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
41834
41835 This packet is not probed by default; the remote stub must request it,
41836 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41837
41838 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41839 @anchor{qXfer unwind info block}
41840
41841 Return the unwind information block for @var{pc}. This packet is used
41842 on OpenVMS/ia64 to ask the kernel unwind information.
41843
41844 This packet is not probed by default.
41845
41846 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41847 @anchor{qXfer fdpic loadmap read}
41848 Read contents of @code{loadmap}s on the target system. The
41849 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41850 executable @code{loadmap} or interpreter @code{loadmap} to read.
41851
41852 This packet is not probed by default; the remote stub must request it,
41853 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41854
41855 @item qXfer:osdata:read::@var{offset},@var{length}
41856 @anchor{qXfer osdata read}
41857 Access the target's @dfn{operating system information}.
41858 @xref{Operating System Information}.
41859
41860 @end table
41861
41862 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41863 @cindex write data into object, remote request
41864 @anchor{qXfer write}
41865 Write uninterpreted bytes into the target's special data area
41866 identified by the keyword @var{object}, starting at @var{offset} bytes
41867 into the data. The binary-encoded data (@pxref{Binary Data}) to be
41868 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41869 is specific to @var{object}; it can supply additional details about what data
41870 to access.
41871
41872 Reply:
41873 @table @samp
41874 @item @var{nn}
41875 @var{nn} (hex encoded) is the number of bytes written.
41876 This may be fewer bytes than supplied in the request.
41877
41878 @item E00
41879 The request was malformed, or @var{annex} was invalid.
41880
41881 @item E @var{nn}
41882 The offset was invalid, or there was an error encountered writing the data.
41883 The @var{nn} part is a hex-encoded @code{errno} value.
41884
41885 @item @w{}
41886 An empty reply indicates the @var{object} string was not
41887 recognized by the stub, or that the object does not support writing.
41888 @end table
41889
41890 Here are the specific requests of this form defined so far. All the
41891 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
41892 formats, listed above.
41893
41894 @table @samp
41895 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41896 @anchor{qXfer siginfo write}
41897 Write @var{data} to the extra signal information on the target system.
41898 The annex part of the generic @samp{qXfer} packet must be
41899 empty (@pxref{qXfer write}).
41900
41901 This packet is not probed by default; the remote stub must request it,
41902 by supplying an appropriate @samp{qSupported} response
41903 (@pxref{qSupported}).
41904 @end table
41905
41906 @item qXfer:@var{object}:@var{operation}:@dots{}
41907 Requests of this form may be added in the future. When a stub does
41908 not recognize the @var{object} keyword, or its support for
41909 @var{object} does not recognize the @var{operation} keyword, the stub
41910 must respond with an empty packet.
41911
41912 @item qAttached:@var{pid}
41913 @cindex query attached, remote request
41914 @cindex @samp{qAttached} packet
41915 Return an indication of whether the remote server attached to an
41916 existing process or created a new process. When the multiprocess
41917 protocol extensions are supported (@pxref{multiprocess extensions}),
41918 @var{pid} is an integer in hexadecimal format identifying the target
41919 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41920 the query packet will be simplified as @samp{qAttached}.
41921
41922 This query is used, for example, to know whether the remote process
41923 should be detached or killed when a @value{GDBN} session is ended with
41924 the @code{quit} command.
41925
41926 Reply:
41927 @table @samp
41928 @item 1
41929 The remote server attached to an existing process.
41930 @item 0
41931 The remote server created a new process.
41932 @item E @var{NN}
41933 A badly formed request or an error was encountered.
41934 @end table
41935
41936 @item Qbtrace:bts
41937 Enable branch tracing for the current thread using Branch Trace Store.
41938
41939 Reply:
41940 @table @samp
41941 @item OK
41942 Branch tracing has been enabled.
41943 @item E.errtext
41944 A badly formed request or an error was encountered.
41945 @end table
41946
41947 @item Qbtrace:pt
41948 Enable branch tracing for the current thread using Intel Processor Trace.
41949
41950 Reply:
41951 @table @samp
41952 @item OK
41953 Branch tracing has been enabled.
41954 @item E.errtext
41955 A badly formed request or an error was encountered.
41956 @end table
41957
41958 @item Qbtrace:off
41959 Disable branch tracing for the current thread.
41960
41961 Reply:
41962 @table @samp
41963 @item OK
41964 Branch tracing has been disabled.
41965 @item E.errtext
41966 A badly formed request or an error was encountered.
41967 @end table
41968
41969 @item Qbtrace-conf:bts:size=@var{value}
41970 Set the requested ring buffer size for new threads that use the
41971 btrace recording method in bts format.
41972
41973 Reply:
41974 @table @samp
41975 @item OK
41976 The ring buffer size has been set.
41977 @item E.errtext
41978 A badly formed request or an error was encountered.
41979 @end table
41980
41981 @item Qbtrace-conf:pt:size=@var{value}
41982 Set the requested ring buffer size for new threads that use the
41983 btrace recording method in pt format.
41984
41985 Reply:
41986 @table @samp
41987 @item OK
41988 The ring buffer size has been set.
41989 @item E.errtext
41990 A badly formed request or an error was encountered.
41991 @end table
41992
41993 @end table
41994
41995 @node Architecture-Specific Protocol Details
41996 @section Architecture-Specific Protocol Details
41997
41998 This section describes how the remote protocol is applied to specific
41999 target architectures. Also see @ref{Standard Target Features}, for
42000 details of XML target descriptions for each architecture.
42001
42002 @menu
42003 * ARM-Specific Protocol Details::
42004 * MIPS-Specific Protocol Details::
42005 @end menu
42006
42007 @node ARM-Specific Protocol Details
42008 @subsection @acronym{ARM}-specific Protocol Details
42009
42010 @menu
42011 * ARM Breakpoint Kinds::
42012 @end menu
42013
42014 @node ARM Breakpoint Kinds
42015 @subsubsection @acronym{ARM} Breakpoint Kinds
42016 @cindex breakpoint kinds, @acronym{ARM}
42017
42018 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42019
42020 @table @r
42021
42022 @item 2
42023 16-bit Thumb mode breakpoint.
42024
42025 @item 3
42026 32-bit Thumb mode (Thumb-2) breakpoint.
42027
42028 @item 4
42029 32-bit @acronym{ARM} mode breakpoint.
42030
42031 @end table
42032
42033 @node MIPS-Specific Protocol Details
42034 @subsection @acronym{MIPS}-specific Protocol Details
42035
42036 @menu
42037 * MIPS Register packet Format::
42038 * MIPS Breakpoint Kinds::
42039 @end menu
42040
42041 @node MIPS Register packet Format
42042 @subsubsection @acronym{MIPS} Register Packet Format
42043 @cindex register packet format, @acronym{MIPS}
42044
42045 The following @code{g}/@code{G} packets have previously been defined.
42046 In the below, some thirty-two bit registers are transferred as
42047 sixty-four bits. Those registers should be zero/sign extended (which?)
42048 to fill the space allocated. Register bytes are transferred in target
42049 byte order. The two nibbles within a register byte are transferred
42050 most-significant -- least-significant.
42051
42052 @table @r
42053
42054 @item MIPS32
42055 All registers are transferred as thirty-two bit quantities in the order:
42056 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42057 registers; fsr; fir; fp.
42058
42059 @item MIPS64
42060 All registers are transferred as sixty-four bit quantities (including
42061 thirty-two bit registers such as @code{sr}). The ordering is the same
42062 as @code{MIPS32}.
42063
42064 @end table
42065
42066 @node MIPS Breakpoint Kinds
42067 @subsubsection @acronym{MIPS} Breakpoint Kinds
42068 @cindex breakpoint kinds, @acronym{MIPS}
42069
42070 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42071
42072 @table @r
42073
42074 @item 2
42075 16-bit @acronym{MIPS16} mode breakpoint.
42076
42077 @item 3
42078 16-bit @acronym{microMIPS} mode breakpoint.
42079
42080 @item 4
42081 32-bit standard @acronym{MIPS} mode breakpoint.
42082
42083 @item 5
42084 32-bit @acronym{microMIPS} mode breakpoint.
42085
42086 @end table
42087
42088 @node Tracepoint Packets
42089 @section Tracepoint Packets
42090 @cindex tracepoint packets
42091 @cindex packets, tracepoint
42092
42093 Here we describe the packets @value{GDBN} uses to implement
42094 tracepoints (@pxref{Tracepoints}).
42095
42096 @table @samp
42097
42098 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
42099 @cindex @samp{QTDP} packet
42100 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42101 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
42102 the tracepoint is disabled. The @var{step} gives the tracepoint's step
42103 count, and @var{pass} gives its pass count. If an @samp{F} is present,
42104 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42105 the number of bytes that the target should copy elsewhere to make room
42106 for the tracepoint. If an @samp{X} is present, it introduces a
42107 tracepoint condition, which consists of a hexadecimal length, followed
42108 by a comma and hex-encoded bytes, in a manner similar to action
42109 encodings as described below. If the trailing @samp{-} is present,
42110 further @samp{QTDP} packets will follow to specify this tracepoint's
42111 actions.
42112
42113 Replies:
42114 @table @samp
42115 @item OK
42116 The packet was understood and carried out.
42117 @item qRelocInsn
42118 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42119 @item @w{}
42120 The packet was not recognized.
42121 @end table
42122
42123 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42124 Define actions to be taken when a tracepoint is hit. The @var{n} and
42125 @var{addr} must be the same as in the initial @samp{QTDP} packet for
42126 this tracepoint. This packet may only be sent immediately after
42127 another @samp{QTDP} packet that ended with a @samp{-}. If the
42128 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42129 specifying more actions for this tracepoint.
42130
42131 In the series of action packets for a given tracepoint, at most one
42132 can have an @samp{S} before its first @var{action}. If such a packet
42133 is sent, it and the following packets define ``while-stepping''
42134 actions. Any prior packets define ordinary actions --- that is, those
42135 taken when the tracepoint is first hit. If no action packet has an
42136 @samp{S}, then all the packets in the series specify ordinary
42137 tracepoint actions.
42138
42139 The @samp{@var{action}@dots{}} portion of the packet is a series of
42140 actions, concatenated without separators. Each action has one of the
42141 following forms:
42142
42143 @table @samp
42144
42145 @item R @var{mask}
42146 Collect the registers whose bits are set in @var{mask},
42147 a hexadecimal number whose @var{i}'th bit is set if register number
42148 @var{i} should be collected. (The least significant bit is numbered
42149 zero.) Note that @var{mask} may be any number of digits long; it may
42150 not fit in a 32-bit word.
42151
42152 @item M @var{basereg},@var{offset},@var{len}
42153 Collect @var{len} bytes of memory starting at the address in register
42154 number @var{basereg}, plus @var{offset}. If @var{basereg} is
42155 @samp{-1}, then the range has a fixed address: @var{offset} is the
42156 address of the lowest byte to collect. The @var{basereg},
42157 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
42158 values (the @samp{-1} value for @var{basereg} is a special case).
42159
42160 @item X @var{len},@var{expr}
42161 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42162 it directs. The agent expression @var{expr} is as described in
42163 @ref{Agent Expressions}. Each byte of the expression is encoded as a
42164 two-digit hex number in the packet; @var{len} is the number of bytes
42165 in the expression (and thus one-half the number of hex digits in the
42166 packet).
42167
42168 @end table
42169
42170 Any number of actions may be packed together in a single @samp{QTDP}
42171 packet, as long as the packet does not exceed the maximum packet
42172 length (400 bytes, for many stubs). There may be only one @samp{R}
42173 action per tracepoint, and it must precede any @samp{M} or @samp{X}
42174 actions. Any registers referred to by @samp{M} and @samp{X} actions
42175 must be collected by a preceding @samp{R} action. (The
42176 ``while-stepping'' actions are treated as if they were attached to a
42177 separate tracepoint, as far as these restrictions are concerned.)
42178
42179 Replies:
42180 @table @samp
42181 @item OK
42182 The packet was understood and carried out.
42183 @item qRelocInsn
42184 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42185 @item @w{}
42186 The packet was not recognized.
42187 @end table
42188
42189 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42190 @cindex @samp{QTDPsrc} packet
42191 Specify a source string of tracepoint @var{n} at address @var{addr}.
42192 This is useful to get accurate reproduction of the tracepoints
42193 originally downloaded at the beginning of the trace run. The @var{type}
42194 is the name of the tracepoint part, such as @samp{cond} for the
42195 tracepoint's conditional expression (see below for a list of types), while
42196 @var{bytes} is the string, encoded in hexadecimal.
42197
42198 @var{start} is the offset of the @var{bytes} within the overall source
42199 string, while @var{slen} is the total length of the source string.
42200 This is intended for handling source strings that are longer than will
42201 fit in a single packet.
42202 @c Add detailed example when this info is moved into a dedicated
42203 @c tracepoint descriptions section.
42204
42205 The available string types are @samp{at} for the location,
42206 @samp{cond} for the conditional, and @samp{cmd} for an action command.
42207 @value{GDBN} sends a separate packet for each command in the action
42208 list, in the same order in which the commands are stored in the list.
42209
42210 The target does not need to do anything with source strings except
42211 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42212 query packets.
42213
42214 Although this packet is optional, and @value{GDBN} will only send it
42215 if the target replies with @samp{TracepointSource} @xref{General
42216 Query Packets}, it makes both disconnected tracing and trace files
42217 much easier to use. Otherwise the user must be careful that the
42218 tracepoints in effect while looking at trace frames are identical to
42219 the ones in effect during the trace run; even a small discrepancy
42220 could cause @samp{tdump} not to work, or a particular trace frame not
42221 be found.
42222
42223 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42224 @cindex define trace state variable, remote request
42225 @cindex @samp{QTDV} packet
42226 Create a new trace state variable, number @var{n}, with an initial
42227 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42228 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42229 the option of not using this packet for initial values of zero; the
42230 target should simply create the trace state variables as they are
42231 mentioned in expressions. The value @var{builtin} should be 1 (one)
42232 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42233 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42234 @samp{qTsV} packet had it set. The contents of @var{name} is the
42235 hex-encoded name (without the leading @samp{$}) of the trace state
42236 variable.
42237
42238 @item QTFrame:@var{n}
42239 @cindex @samp{QTFrame} packet
42240 Select the @var{n}'th tracepoint frame from the buffer, and use the
42241 register and memory contents recorded there to answer subsequent
42242 request packets from @value{GDBN}.
42243
42244 A successful reply from the stub indicates that the stub has found the
42245 requested frame. The response is a series of parts, concatenated
42246 without separators, describing the frame we selected. Each part has
42247 one of the following forms:
42248
42249 @table @samp
42250 @item F @var{f}
42251 The selected frame is number @var{n} in the trace frame buffer;
42252 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42253 was no frame matching the criteria in the request packet.
42254
42255 @item T @var{t}
42256 The selected trace frame records a hit of tracepoint number @var{t};
42257 @var{t} is a hexadecimal number.
42258
42259 @end table
42260
42261 @item QTFrame:pc:@var{addr}
42262 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42263 currently selected frame whose PC is @var{addr};
42264 @var{addr} is a hexadecimal number.
42265
42266 @item QTFrame:tdp:@var{t}
42267 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42268 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42269 is a hexadecimal number.
42270
42271 @item QTFrame:range:@var{start}:@var{end}
42272 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42273 currently selected frame whose PC is between @var{start} (inclusive)
42274 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42275 numbers.
42276
42277 @item QTFrame:outside:@var{start}:@var{end}
42278 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42279 frame @emph{outside} the given range of addresses (exclusive).
42280
42281 @item qTMinFTPILen
42282 @cindex @samp{qTMinFTPILen} packet
42283 This packet requests the minimum length of instruction at which a fast
42284 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42285 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42286 it depends on the target system being able to create trampolines in
42287 the first 64K of memory, which might or might not be possible for that
42288 system. So the reply to this packet will be 4 if it is able to
42289 arrange for that.
42290
42291 Replies:
42292
42293 @table @samp
42294 @item 0
42295 The minimum instruction length is currently unknown.
42296 @item @var{length}
42297 The minimum instruction length is @var{length}, where @var{length}
42298 is a hexadecimal number greater or equal to 1. A reply
42299 of 1 means that a fast tracepoint may be placed on any instruction
42300 regardless of size.
42301 @item E
42302 An error has occurred.
42303 @item @w{}
42304 An empty reply indicates that the request is not supported by the stub.
42305 @end table
42306
42307 @item QTStart
42308 @cindex @samp{QTStart} packet
42309 Begin the tracepoint experiment. Begin collecting data from
42310 tracepoint hits in the trace frame buffer. This packet supports the
42311 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42312 instruction reply packet}).
42313
42314 @item QTStop
42315 @cindex @samp{QTStop} packet
42316 End the tracepoint experiment. Stop collecting trace frames.
42317
42318 @item QTEnable:@var{n}:@var{addr}
42319 @anchor{QTEnable}
42320 @cindex @samp{QTEnable} packet
42321 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42322 experiment. If the tracepoint was previously disabled, then collection
42323 of data from it will resume.
42324
42325 @item QTDisable:@var{n}:@var{addr}
42326 @anchor{QTDisable}
42327 @cindex @samp{QTDisable} packet
42328 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42329 experiment. No more data will be collected from the tracepoint unless
42330 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42331
42332 @item QTinit
42333 @cindex @samp{QTinit} packet
42334 Clear the table of tracepoints, and empty the trace frame buffer.
42335
42336 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
42337 @cindex @samp{QTro} packet
42338 Establish the given ranges of memory as ``transparent''. The stub
42339 will answer requests for these ranges from memory's current contents,
42340 if they were not collected as part of the tracepoint hit.
42341
42342 @value{GDBN} uses this to mark read-only regions of memory, like those
42343 containing program code. Since these areas never change, they should
42344 still have the same contents they did when the tracepoint was hit, so
42345 there's no reason for the stub to refuse to provide their contents.
42346
42347 @item QTDisconnected:@var{value}
42348 @cindex @samp{QTDisconnected} packet
42349 Set the choice to what to do with the tracing run when @value{GDBN}
42350 disconnects from the target. A @var{value} of 1 directs the target to
42351 continue the tracing run, while 0 tells the target to stop tracing if
42352 @value{GDBN} is no longer in the picture.
42353
42354 @item qTStatus
42355 @cindex @samp{qTStatus} packet
42356 Ask the stub if there is a trace experiment running right now.
42357
42358 The reply has the form:
42359
42360 @table @samp
42361
42362 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
42363 @var{running} is a single digit @code{1} if the trace is presently
42364 running, or @code{0} if not. It is followed by semicolon-separated
42365 optional fields that an agent may use to report additional status.
42366
42367 @end table
42368
42369 If the trace is not running, the agent may report any of several
42370 explanations as one of the optional fields:
42371
42372 @table @samp
42373
42374 @item tnotrun:0
42375 No trace has been run yet.
42376
42377 @item tstop[:@var{text}]:0
42378 The trace was stopped by a user-originated stop command. The optional
42379 @var{text} field is a user-supplied string supplied as part of the
42380 stop command (for instance, an explanation of why the trace was
42381 stopped manually). It is hex-encoded.
42382
42383 @item tfull:0
42384 The trace stopped because the trace buffer filled up.
42385
42386 @item tdisconnected:0
42387 The trace stopped because @value{GDBN} disconnected from the target.
42388
42389 @item tpasscount:@var{tpnum}
42390 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42391
42392 @item terror:@var{text}:@var{tpnum}
42393 The trace stopped because tracepoint @var{tpnum} had an error. The
42394 string @var{text} is available to describe the nature of the error
42395 (for instance, a divide by zero in the condition expression); it
42396 is hex encoded.
42397
42398 @item tunknown:0
42399 The trace stopped for some other reason.
42400
42401 @end table
42402
42403 Additional optional fields supply statistical and other information.
42404 Although not required, they are extremely useful for users monitoring
42405 the progress of a trace run. If a trace has stopped, and these
42406 numbers are reported, they must reflect the state of the just-stopped
42407 trace.
42408
42409 @table @samp
42410
42411 @item tframes:@var{n}
42412 The number of trace frames in the buffer.
42413
42414 @item tcreated:@var{n}
42415 The total number of trace frames created during the run. This may
42416 be larger than the trace frame count, if the buffer is circular.
42417
42418 @item tsize:@var{n}
42419 The total size of the trace buffer, in bytes.
42420
42421 @item tfree:@var{n}
42422 The number of bytes still unused in the buffer.
42423
42424 @item circular:@var{n}
42425 The value of the circular trace buffer flag. @code{1} means that the
42426 trace buffer is circular and old trace frames will be discarded if
42427 necessary to make room, @code{0} means that the trace buffer is linear
42428 and may fill up.
42429
42430 @item disconn:@var{n}
42431 The value of the disconnected tracing flag. @code{1} means that
42432 tracing will continue after @value{GDBN} disconnects, @code{0} means
42433 that the trace run will stop.
42434
42435 @end table
42436
42437 @item qTP:@var{tp}:@var{addr}
42438 @cindex tracepoint status, remote request
42439 @cindex @samp{qTP} packet
42440 Ask the stub for the current state of tracepoint number @var{tp} at
42441 address @var{addr}.
42442
42443 Replies:
42444 @table @samp
42445 @item V@var{hits}:@var{usage}
42446 The tracepoint has been hit @var{hits} times so far during the trace
42447 run, and accounts for @var{usage} in the trace buffer. Note that
42448 @code{while-stepping} steps are not counted as separate hits, but the
42449 steps' space consumption is added into the usage number.
42450
42451 @end table
42452
42453 @item qTV:@var{var}
42454 @cindex trace state variable value, remote request
42455 @cindex @samp{qTV} packet
42456 Ask the stub for the value of the trace state variable number @var{var}.
42457
42458 Replies:
42459 @table @samp
42460 @item V@var{value}
42461 The value of the variable is @var{value}. This will be the current
42462 value of the variable if the user is examining a running target, or a
42463 saved value if the variable was collected in the trace frame that the
42464 user is looking at. Note that multiple requests may result in
42465 different reply values, such as when requesting values while the
42466 program is running.
42467
42468 @item U
42469 The value of the variable is unknown. This would occur, for example,
42470 if the user is examining a trace frame in which the requested variable
42471 was not collected.
42472 @end table
42473
42474 @item qTfP
42475 @cindex @samp{qTfP} packet
42476 @itemx qTsP
42477 @cindex @samp{qTsP} packet
42478 These packets request data about tracepoints that are being used by
42479 the target. @value{GDBN} sends @code{qTfP} to get the first piece
42480 of data, and multiple @code{qTsP} to get additional pieces. Replies
42481 to these packets generally take the form of the @code{QTDP} packets
42482 that define tracepoints. (FIXME add detailed syntax)
42483
42484 @item qTfV
42485 @cindex @samp{qTfV} packet
42486 @itemx qTsV
42487 @cindex @samp{qTsV} packet
42488 These packets request data about trace state variables that are on the
42489 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42490 and multiple @code{qTsV} to get additional variables. Replies to
42491 these packets follow the syntax of the @code{QTDV} packets that define
42492 trace state variables.
42493
42494 @item qTfSTM
42495 @itemx qTsSTM
42496 @anchor{qTfSTM}
42497 @anchor{qTsSTM}
42498 @cindex @samp{qTfSTM} packet
42499 @cindex @samp{qTsSTM} packet
42500 These packets request data about static tracepoint markers that exist
42501 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42502 first piece of data, and multiple @code{qTsSTM} to get additional
42503 pieces. Replies to these packets take the following form:
42504
42505 Reply:
42506 @table @samp
42507 @item m @var{address}:@var{id}:@var{extra}
42508 A single marker
42509 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42510 a comma-separated list of markers
42511 @item l
42512 (lower case letter @samp{L}) denotes end of list.
42513 @item E @var{nn}
42514 An error occurred. The error number @var{nn} is given as hex digits.
42515 @item @w{}
42516 An empty reply indicates that the request is not supported by the
42517 stub.
42518 @end table
42519
42520 The @var{address} is encoded in hex;
42521 @var{id} and @var{extra} are strings encoded in hex.
42522
42523 In response to each query, the target will reply with a list of one or
42524 more markers, separated by commas. @value{GDBN} will respond to each
42525 reply with a request for more markers (using the @samp{qs} form of the
42526 query), until the target responds with @samp{l} (lower-case ell, for
42527 @dfn{last}).
42528
42529 @item qTSTMat:@var{address}
42530 @anchor{qTSTMat}
42531 @cindex @samp{qTSTMat} packet
42532 This packets requests data about static tracepoint markers in the
42533 target program at @var{address}. Replies to this packet follow the
42534 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42535 tracepoint markers.
42536
42537 @item QTSave:@var{filename}
42538 @cindex @samp{QTSave} packet
42539 This packet directs the target to save trace data to the file name
42540 @var{filename} in the target's filesystem. The @var{filename} is encoded
42541 as a hex string; the interpretation of the file name (relative vs
42542 absolute, wild cards, etc) is up to the target.
42543
42544 @item qTBuffer:@var{offset},@var{len}
42545 @cindex @samp{qTBuffer} packet
42546 Return up to @var{len} bytes of the current contents of trace buffer,
42547 starting at @var{offset}. The trace buffer is treated as if it were
42548 a contiguous collection of traceframes, as per the trace file format.
42549 The reply consists as many hex-encoded bytes as the target can deliver
42550 in a packet; it is not an error to return fewer than were asked for.
42551 A reply consisting of just @code{l} indicates that no bytes are
42552 available.
42553
42554 @item QTBuffer:circular:@var{value}
42555 This packet directs the target to use a circular trace buffer if
42556 @var{value} is 1, or a linear buffer if the value is 0.
42557
42558 @item QTBuffer:size:@var{size}
42559 @anchor{QTBuffer-size}
42560 @cindex @samp{QTBuffer size} packet
42561 This packet directs the target to make the trace buffer be of size
42562 @var{size} if possible. A value of @code{-1} tells the target to
42563 use whatever size it prefers.
42564
42565 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
42566 @cindex @samp{QTNotes} packet
42567 This packet adds optional textual notes to the trace run. Allowable
42568 types include @code{user}, @code{notes}, and @code{tstop}, the
42569 @var{text} fields are arbitrary strings, hex-encoded.
42570
42571 @end table
42572
42573 @subsection Relocate instruction reply packet
42574 When installing fast tracepoints in memory, the target may need to
42575 relocate the instruction currently at the tracepoint address to a
42576 different address in memory. For most instructions, a simple copy is
42577 enough, but, for example, call instructions that implicitly push the
42578 return address on the stack, and relative branches or other
42579 PC-relative instructions require offset adjustment, so that the effect
42580 of executing the instruction at a different address is the same as if
42581 it had executed in the original location.
42582
42583 In response to several of the tracepoint packets, the target may also
42584 respond with a number of intermediate @samp{qRelocInsn} request
42585 packets before the final result packet, to have @value{GDBN} handle
42586 this relocation operation. If a packet supports this mechanism, its
42587 documentation will explicitly say so. See for example the above
42588 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42589 format of the request is:
42590
42591 @table @samp
42592 @item qRelocInsn:@var{from};@var{to}
42593
42594 This requests @value{GDBN} to copy instruction at address @var{from}
42595 to address @var{to}, possibly adjusted so that executing the
42596 instruction at @var{to} has the same effect as executing it at
42597 @var{from}. @value{GDBN} writes the adjusted instruction to target
42598 memory starting at @var{to}.
42599 @end table
42600
42601 Replies:
42602 @table @samp
42603 @item qRelocInsn:@var{adjusted_size}
42604 Informs the stub the relocation is complete. The @var{adjusted_size} is
42605 the length in bytes of resulting relocated instruction sequence.
42606 @item E @var{NN}
42607 A badly formed request was detected, or an error was encountered while
42608 relocating the instruction.
42609 @end table
42610
42611 @node Host I/O Packets
42612 @section Host I/O Packets
42613 @cindex Host I/O, remote protocol
42614 @cindex file transfer, remote protocol
42615
42616 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42617 operations on the far side of a remote link. For example, Host I/O is
42618 used to upload and download files to a remote target with its own
42619 filesystem. Host I/O uses the same constant values and data structure
42620 layout as the target-initiated File-I/O protocol. However, the
42621 Host I/O packets are structured differently. The target-initiated
42622 protocol relies on target memory to store parameters and buffers.
42623 Host I/O requests are initiated by @value{GDBN}, and the
42624 target's memory is not involved. @xref{File-I/O Remote Protocol
42625 Extension}, for more details on the target-initiated protocol.
42626
42627 The Host I/O request packets all encode a single operation along with
42628 its arguments. They have this format:
42629
42630 @table @samp
42631
42632 @item vFile:@var{operation}: @var{parameter}@dots{}
42633 @var{operation} is the name of the particular request; the target
42634 should compare the entire packet name up to the second colon when checking
42635 for a supported operation. The format of @var{parameter} depends on
42636 the operation. Numbers are always passed in hexadecimal. Negative
42637 numbers have an explicit minus sign (i.e.@: two's complement is not
42638 used). Strings (e.g.@: filenames) are encoded as a series of
42639 hexadecimal bytes. The last argument to a system call may be a
42640 buffer of escaped binary data (@pxref{Binary Data}).
42641
42642 @end table
42643
42644 The valid responses to Host I/O packets are:
42645
42646 @table @samp
42647
42648 @item F @var{result} [, @var{errno}] [; @var{attachment}]
42649 @var{result} is the integer value returned by this operation, usually
42650 non-negative for success and -1 for errors. If an error has occured,
42651 @var{errno} will be included in the result specifying a
42652 value defined by the File-I/O protocol (@pxref{Errno Values}). For
42653 operations which return data, @var{attachment} supplies the data as a
42654 binary buffer. Binary buffers in response packets are escaped in the
42655 normal way (@pxref{Binary Data}). See the individual packet
42656 documentation for the interpretation of @var{result} and
42657 @var{attachment}.
42658
42659 @item @w{}
42660 An empty response indicates that this operation is not recognized.
42661
42662 @end table
42663
42664 These are the supported Host I/O operations:
42665
42666 @table @samp
42667 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
42668 Open a file at @var{filename} and return a file descriptor for it, or
42669 return -1 if an error occurs. The @var{filename} is a string,
42670 @var{flags} is an integer indicating a mask of open flags
42671 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42672 of mode bits to use if the file is created (@pxref{mode_t Values}).
42673 @xref{open}, for details of the open flags and mode values.
42674
42675 @item vFile:close: @var{fd}
42676 Close the open file corresponding to @var{fd} and return 0, or
42677 -1 if an error occurs.
42678
42679 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
42680 Read data from the open file corresponding to @var{fd}. Up to
42681 @var{count} bytes will be read from the file, starting at @var{offset}
42682 relative to the start of the file. The target may read fewer bytes;
42683 common reasons include packet size limits and an end-of-file
42684 condition. The number of bytes read is returned. Zero should only be
42685 returned for a successful read at the end of the file, or if
42686 @var{count} was zero.
42687
42688 The data read should be returned as a binary attachment on success.
42689 If zero bytes were read, the response should include an empty binary
42690 attachment (i.e.@: a trailing semicolon). The return value is the
42691 number of target bytes read; the binary attachment may be longer if
42692 some characters were escaped.
42693
42694 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42695 Write @var{data} (a binary buffer) to the open file corresponding
42696 to @var{fd}. Start the write at @var{offset} from the start of the
42697 file. Unlike many @code{write} system calls, there is no
42698 separate @var{count} argument; the length of @var{data} in the
42699 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
42700 which may be shorter than the length of @var{data}, or -1 if an
42701 error occurred.
42702
42703 @item vFile:fstat: @var{fd}
42704 Get information about the open file corresponding to @var{fd}.
42705 On success the information is returned as a binary attachment
42706 and the return value is the size of this attachment in bytes.
42707 If an error occurs the return value is -1. The format of the
42708 returned binary attachment is as described in @ref{struct stat}.
42709
42710 @item vFile:unlink: @var{filename}
42711 Delete the file at @var{filename} on the target. Return 0,
42712 or -1 if an error occurs. The @var{filename} is a string.
42713
42714 @item vFile:readlink: @var{filename}
42715 Read value of symbolic link @var{filename} on the target. Return
42716 the number of bytes read, or -1 if an error occurs.
42717
42718 The data read should be returned as a binary attachment on success.
42719 If zero bytes were read, the response should include an empty binary
42720 attachment (i.e.@: a trailing semicolon). The return value is the
42721 number of target bytes read; the binary attachment may be longer if
42722 some characters were escaped.
42723
42724 @item vFile:setfs: @var{pid}
42725 Select the filesystem on which @code{vFile} operations with
42726 @var{filename} arguments will operate. This is required for
42727 @value{GDBN} to be able to access files on remote targets where
42728 the remote stub does not share a common filesystem with the
42729 inferior(s).
42730
42731 If @var{pid} is nonzero, select the filesystem as seen by process
42732 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
42733 the remote stub. Return 0 on success, or -1 if an error occurs.
42734 If @code{vFile:setfs:} indicates success, the selected filesystem
42735 remains selected until the next successful @code{vFile:setfs:}
42736 operation.
42737
42738 @end table
42739
42740 @node Interrupts
42741 @section Interrupts
42742 @cindex interrupts (remote protocol)
42743 @anchor{interrupting remote targets}
42744
42745 In all-stop mode, when a program on the remote target is running,
42746 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42747 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42748 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
42749
42750 The precise meaning of @code{BREAK} is defined by the transport
42751 mechanism and may, in fact, be undefined. @value{GDBN} does not
42752 currently define a @code{BREAK} mechanism for any of the network
42753 interfaces except for TCP, in which case @value{GDBN} sends the
42754 @code{telnet} BREAK sequence.
42755
42756 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
42757 transport mechanisms. It is represented by sending the single byte
42758 @code{0x03} without any of the usual packet overhead described in
42759 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42760 transmitted as part of a packet, it is considered to be packet data
42761 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
42762 (@pxref{X packet}), used for binary downloads, may include an unescaped
42763 @code{0x03} as part of its packet.
42764
42765 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42766 When Linux kernel receives this sequence from serial port,
42767 it stops execution and connects to gdb.
42768
42769 In non-stop mode, because packet resumptions are asynchronous
42770 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42771 command to the remote stub, even when the target is running. For that
42772 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42773 packet}) with the usual packet framing instead of the single byte
42774 @code{0x03}.
42775
42776 Stubs are not required to recognize these interrupt mechanisms and the
42777 precise meaning associated with receipt of the interrupt is
42778 implementation defined. If the target supports debugging of multiple
42779 threads and/or processes, it should attempt to interrupt all
42780 currently-executing threads and processes.
42781 If the stub is successful at interrupting the
42782 running program, it should send one of the stop
42783 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42784 of successfully stopping the program in all-stop mode, and a stop reply
42785 for each stopped thread in non-stop mode.
42786 Interrupts received while the
42787 program is stopped are queued and the program will be interrupted when
42788 it is resumed next time.
42789
42790 @node Notification Packets
42791 @section Notification Packets
42792 @cindex notification packets
42793 @cindex packets, notification
42794
42795 The @value{GDBN} remote serial protocol includes @dfn{notifications},
42796 packets that require no acknowledgment. Both the GDB and the stub
42797 may send notifications (although the only notifications defined at
42798 present are sent by the stub). Notifications carry information
42799 without incurring the round-trip latency of an acknowledgment, and so
42800 are useful for low-impact communications where occasional packet loss
42801 is not a problem.
42802
42803 A notification packet has the form @samp{% @var{data} #
42804 @var{checksum}}, where @var{data} is the content of the notification,
42805 and @var{checksum} is a checksum of @var{data}, computed and formatted
42806 as for ordinary @value{GDBN} packets. A notification's @var{data}
42807 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42808 receiving a notification, the recipient sends no @samp{+} or @samp{-}
42809 to acknowledge the notification's receipt or to report its corruption.
42810
42811 Every notification's @var{data} begins with a name, which contains no
42812 colon characters, followed by a colon character.
42813
42814 Recipients should silently ignore corrupted notifications and
42815 notifications they do not understand. Recipients should restart
42816 timeout periods on receipt of a well-formed notification, whether or
42817 not they understand it.
42818
42819 Senders should only send the notifications described here when this
42820 protocol description specifies that they are permitted. In the
42821 future, we may extend the protocol to permit existing notifications in
42822 new contexts; this rule helps older senders avoid confusing newer
42823 recipients.
42824
42825 (Older versions of @value{GDBN} ignore bytes received until they see
42826 the @samp{$} byte that begins an ordinary packet, so new stubs may
42827 transmit notifications without fear of confusing older clients. There
42828 are no notifications defined for @value{GDBN} to send at the moment, but we
42829 assume that most older stubs would ignore them, as well.)
42830
42831 Each notification is comprised of three parts:
42832 @table @samp
42833 @item @var{name}:@var{event}
42834 The notification packet is sent by the side that initiates the
42835 exchange (currently, only the stub does that), with @var{event}
42836 carrying the specific information about the notification, and
42837 @var{name} specifying the name of the notification.
42838 @item @var{ack}
42839 The acknowledge sent by the other side, usually @value{GDBN}, to
42840 acknowledge the exchange and request the event.
42841 @end table
42842
42843 The purpose of an asynchronous notification mechanism is to report to
42844 @value{GDBN} that something interesting happened in the remote stub.
42845
42846 The remote stub may send notification @var{name}:@var{event}
42847 at any time, but @value{GDBN} acknowledges the notification when
42848 appropriate. The notification event is pending before @value{GDBN}
42849 acknowledges. Only one notification at a time may be pending; if
42850 additional events occur before @value{GDBN} has acknowledged the
42851 previous notification, they must be queued by the stub for later
42852 synchronous transmission in response to @var{ack} packets from
42853 @value{GDBN}. Because the notification mechanism is unreliable,
42854 the stub is permitted to resend a notification if it believes
42855 @value{GDBN} may not have received it.
42856
42857 Specifically, notifications may appear when @value{GDBN} is not
42858 otherwise reading input from the stub, or when @value{GDBN} is
42859 expecting to read a normal synchronous response or a
42860 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
42861 Notification packets are distinct from any other communication from
42862 the stub so there is no ambiguity.
42863
42864 After receiving a notification, @value{GDBN} shall acknowledge it by
42865 sending a @var{ack} packet as a regular, synchronous request to the
42866 stub. Such acknowledgment is not required to happen immediately, as
42867 @value{GDBN} is permitted to send other, unrelated packets to the
42868 stub first, which the stub should process normally.
42869
42870 Upon receiving a @var{ack} packet, if the stub has other queued
42871 events to report to @value{GDBN}, it shall respond by sending a
42872 normal @var{event}. @value{GDBN} shall then send another @var{ack}
42873 packet to solicit further responses; again, it is permitted to send
42874 other, unrelated packets as well which the stub should process
42875 normally.
42876
42877 If the stub receives a @var{ack} packet and there are no additional
42878 @var{event} to report, the stub shall return an @samp{OK} response.
42879 At this point, @value{GDBN} has finished processing a notification
42880 and the stub has completed sending any queued events. @value{GDBN}
42881 won't accept any new notifications until the final @samp{OK} is
42882 received . If further notification events occur, the stub shall send
42883 a new notification, @value{GDBN} shall accept the notification, and
42884 the process shall be repeated.
42885
42886 The process of asynchronous notification can be illustrated by the
42887 following example:
42888 @smallexample
42889 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
42890 @code{...}
42891 -> @code{vStopped}
42892 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42893 -> @code{vStopped}
42894 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42895 -> @code{vStopped}
42896 <- @code{OK}
42897 @end smallexample
42898
42899 The following notifications are defined:
42900 @multitable @columnfractions 0.12 0.12 0.38 0.38
42901
42902 @item Notification
42903 @tab Ack
42904 @tab Event
42905 @tab Description
42906
42907 @item Stop
42908 @tab vStopped
42909 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
42910 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42911 for information on how these notifications are acknowledged by
42912 @value{GDBN}.
42913 @tab Report an asynchronous stop event in non-stop mode.
42914
42915 @end multitable
42916
42917 @node Remote Non-Stop
42918 @section Remote Protocol Support for Non-Stop Mode
42919
42920 @value{GDBN}'s remote protocol supports non-stop debugging of
42921 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42922 supports non-stop mode, it should report that to @value{GDBN} by including
42923 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42924
42925 @value{GDBN} typically sends a @samp{QNonStop} packet only when
42926 establishing a new connection with the stub. Entering non-stop mode
42927 does not alter the state of any currently-running threads, but targets
42928 must stop all threads in any already-attached processes when entering
42929 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42930 probe the target state after a mode change.
42931
42932 In non-stop mode, when an attached process encounters an event that
42933 would otherwise be reported with a stop reply, it uses the
42934 asynchronous notification mechanism (@pxref{Notification Packets}) to
42935 inform @value{GDBN}. In contrast to all-stop mode, where all threads
42936 in all processes are stopped when a stop reply is sent, in non-stop
42937 mode only the thread reporting the stop event is stopped. That is,
42938 when reporting a @samp{S} or @samp{T} response to indicate completion
42939 of a step operation, hitting a breakpoint, or a fault, only the
42940 affected thread is stopped; any other still-running threads continue
42941 to run. When reporting a @samp{W} or @samp{X} response, all running
42942 threads belonging to other attached processes continue to run.
42943
42944 In non-stop mode, the target shall respond to the @samp{?} packet as
42945 follows. First, any incomplete stop reply notification/@samp{vStopped}
42946 sequence in progress is abandoned. The target must begin a new
42947 sequence reporting stop events for all stopped threads, whether or not
42948 it has previously reported those events to @value{GDBN}. The first
42949 stop reply is sent as a synchronous reply to the @samp{?} packet, and
42950 subsequent stop replies are sent as responses to @samp{vStopped} packets
42951 using the mechanism described above. The target must not send
42952 asynchronous stop reply notifications until the sequence is complete.
42953 If all threads are running when the target receives the @samp{?} packet,
42954 or if the target is not attached to any process, it shall respond
42955 @samp{OK}.
42956
42957 If the stub supports non-stop mode, it should also support the
42958 @samp{swbreak} stop reason if software breakpoints are supported, and
42959 the @samp{hwbreak} stop reason if hardware breakpoints are supported
42960 (@pxref{swbreak stop reason}). This is because given the asynchronous
42961 nature of non-stop mode, between the time a thread hits a breakpoint
42962 and the time the event is finally processed by @value{GDBN}, the
42963 breakpoint may have already been removed from the target. Due to
42964 this, @value{GDBN} needs to be able to tell whether a trap stop was
42965 caused by a delayed breakpoint event, which should be ignored, as
42966 opposed to a random trap signal, which should be reported to the user.
42967 Note the @samp{swbreak} feature implies that the target is responsible
42968 for adjusting the PC when a software breakpoint triggers, if
42969 necessary, such as on the x86 architecture.
42970
42971 @node Packet Acknowledgment
42972 @section Packet Acknowledgment
42973
42974 @cindex acknowledgment, for @value{GDBN} remote
42975 @cindex packet acknowledgment, for @value{GDBN} remote
42976 By default, when either the host or the target machine receives a packet,
42977 the first response expected is an acknowledgment: either @samp{+} (to indicate
42978 the package was received correctly) or @samp{-} (to request retransmission).
42979 This mechanism allows the @value{GDBN} remote protocol to operate over
42980 unreliable transport mechanisms, such as a serial line.
42981
42982 In cases where the transport mechanism is itself reliable (such as a pipe or
42983 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42984 It may be desirable to disable them in that case to reduce communication
42985 overhead, or for other reasons. This can be accomplished by means of the
42986 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42987
42988 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42989 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
42990 and response format still includes the normal checksum, as described in
42991 @ref{Overview}, but the checksum may be ignored by the receiver.
42992
42993 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
42994 no-acknowledgment mode, it should report that to @value{GDBN}
42995 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
42996 @pxref{qSupported}.
42997 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
42998 disabled via the @code{set remote noack-packet off} command
42999 (@pxref{Remote Configuration}),
43000 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43001 Only then may the stub actually turn off packet acknowledgments.
43002 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43003 response, which can be safely ignored by the stub.
43004
43005 Note that @code{set remote noack-packet} command only affects negotiation
43006 between @value{GDBN} and the stub when subsequent connections are made;
43007 it does not affect the protocol acknowledgment state for any current
43008 connection.
43009 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43010 new connection is established,
43011 there is also no protocol request to re-enable the acknowledgments
43012 for the current connection, once disabled.
43013
43014 @node Examples
43015 @section Examples
43016
43017 Example sequence of a target being re-started. Notice how the restart
43018 does not get any direct output:
43019
43020 @smallexample
43021 -> @code{R00}
43022 <- @code{+}
43023 @emph{target restarts}
43024 -> @code{?}
43025 <- @code{+}
43026 <- @code{T001:1234123412341234}
43027 -> @code{+}
43028 @end smallexample
43029
43030 Example sequence of a target being stepped by a single instruction:
43031
43032 @smallexample
43033 -> @code{G1445@dots{}}
43034 <- @code{+}
43035 -> @code{s}
43036 <- @code{+}
43037 @emph{time passes}
43038 <- @code{T001:1234123412341234}
43039 -> @code{+}
43040 -> @code{g}
43041 <- @code{+}
43042 <- @code{1455@dots{}}
43043 -> @code{+}
43044 @end smallexample
43045
43046 @node File-I/O Remote Protocol Extension
43047 @section File-I/O Remote Protocol Extension
43048 @cindex File-I/O remote protocol extension
43049
43050 @menu
43051 * File-I/O Overview::
43052 * Protocol Basics::
43053 * The F Request Packet::
43054 * The F Reply Packet::
43055 * The Ctrl-C Message::
43056 * Console I/O::
43057 * List of Supported Calls::
43058 * Protocol-specific Representation of Datatypes::
43059 * Constants::
43060 * File-I/O Examples::
43061 @end menu
43062
43063 @node File-I/O Overview
43064 @subsection File-I/O Overview
43065 @cindex file-i/o overview
43066
43067 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
43068 target to use the host's file system and console I/O to perform various
43069 system calls. System calls on the target system are translated into a
43070 remote protocol packet to the host system, which then performs the needed
43071 actions and returns a response packet to the target system.
43072 This simulates file system operations even on targets that lack file systems.
43073
43074 The protocol is defined to be independent of both the host and target systems.
43075 It uses its own internal representation of datatypes and values. Both
43076 @value{GDBN} and the target's @value{GDBN} stub are responsible for
43077 translating the system-dependent value representations into the internal
43078 protocol representations when data is transmitted.
43079
43080 The communication is synchronous. A system call is possible only when
43081 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43082 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
43083 the target is stopped to allow deterministic access to the target's
43084 memory. Therefore File-I/O is not interruptible by target signals. On
43085 the other hand, it is possible to interrupt File-I/O by a user interrupt
43086 (@samp{Ctrl-C}) within @value{GDBN}.
43087
43088 The target's request to perform a host system call does not finish
43089 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43090 after finishing the system call, the target returns to continuing the
43091 previous activity (continue, step). No additional continue or step
43092 request from @value{GDBN} is required.
43093
43094 @smallexample
43095 (@value{GDBP}) continue
43096 <- target requests 'system call X'
43097 target is stopped, @value{GDBN} executes system call
43098 -> @value{GDBN} returns result
43099 ... target continues, @value{GDBN} returns to wait for the target
43100 <- target hits breakpoint and sends a Txx packet
43101 @end smallexample
43102
43103 The protocol only supports I/O on the console and to regular files on
43104 the host file system. Character or block special devices, pipes,
43105 named pipes, sockets or any other communication method on the host
43106 system are not supported by this protocol.
43107
43108 File I/O is not supported in non-stop mode.
43109
43110 @node Protocol Basics
43111 @subsection Protocol Basics
43112 @cindex protocol basics, file-i/o
43113
43114 The File-I/O protocol uses the @code{F} packet as the request as well
43115 as reply packet. Since a File-I/O system call can only occur when
43116 @value{GDBN} is waiting for a response from the continuing or stepping target,
43117 the File-I/O request is a reply that @value{GDBN} has to expect as a result
43118 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43119 This @code{F} packet contains all information needed to allow @value{GDBN}
43120 to call the appropriate host system call:
43121
43122 @itemize @bullet
43123 @item
43124 A unique identifier for the requested system call.
43125
43126 @item
43127 All parameters to the system call. Pointers are given as addresses
43128 in the target memory address space. Pointers to strings are given as
43129 pointer/length pair. Numerical values are given as they are.
43130 Numerical control flags are given in a protocol-specific representation.
43131
43132 @end itemize
43133
43134 At this point, @value{GDBN} has to perform the following actions.
43135
43136 @itemize @bullet
43137 @item
43138 If the parameters include pointer values to data needed as input to a
43139 system call, @value{GDBN} requests this data from the target with a
43140 standard @code{m} packet request. This additional communication has to be
43141 expected by the target implementation and is handled as any other @code{m}
43142 packet.
43143
43144 @item
43145 @value{GDBN} translates all value from protocol representation to host
43146 representation as needed. Datatypes are coerced into the host types.
43147
43148 @item
43149 @value{GDBN} calls the system call.
43150
43151 @item
43152 It then coerces datatypes back to protocol representation.
43153
43154 @item
43155 If the system call is expected to return data in buffer space specified
43156 by pointer parameters to the call, the data is transmitted to the
43157 target using a @code{M} or @code{X} packet. This packet has to be expected
43158 by the target implementation and is handled as any other @code{M} or @code{X}
43159 packet.
43160
43161 @end itemize
43162
43163 Eventually @value{GDBN} replies with another @code{F} packet which contains all
43164 necessary information for the target to continue. This at least contains
43165
43166 @itemize @bullet
43167 @item
43168 Return value.
43169
43170 @item
43171 @code{errno}, if has been changed by the system call.
43172
43173 @item
43174 ``Ctrl-C'' flag.
43175
43176 @end itemize
43177
43178 After having done the needed type and value coercion, the target continues
43179 the latest continue or step action.
43180
43181 @node The F Request Packet
43182 @subsection The @code{F} Request Packet
43183 @cindex file-i/o request packet
43184 @cindex @code{F} request packet
43185
43186 The @code{F} request packet has the following format:
43187
43188 @table @samp
43189 @item F@var{call-id},@var{parameter@dots{}}
43190
43191 @var{call-id} is the identifier to indicate the host system call to be called.
43192 This is just the name of the function.
43193
43194 @var{parameter@dots{}} are the parameters to the system call.
43195 Parameters are hexadecimal integer values, either the actual values in case
43196 of scalar datatypes, pointers to target buffer space in case of compound
43197 datatypes and unspecified memory areas, or pointer/length pairs in case
43198 of string parameters. These are appended to the @var{call-id} as a
43199 comma-delimited list. All values are transmitted in ASCII
43200 string representation, pointer/length pairs separated by a slash.
43201
43202 @end table
43203
43204
43205
43206 @node The F Reply Packet
43207 @subsection The @code{F} Reply Packet
43208 @cindex file-i/o reply packet
43209 @cindex @code{F} reply packet
43210
43211 The @code{F} reply packet has the following format:
43212
43213 @table @samp
43214
43215 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43216
43217 @var{retcode} is the return code of the system call as hexadecimal value.
43218
43219 @var{errno} is the @code{errno} set by the call, in protocol-specific
43220 representation.
43221 This parameter can be omitted if the call was successful.
43222
43223 @var{Ctrl-C flag} is only sent if the user requested a break. In this
43224 case, @var{errno} must be sent as well, even if the call was successful.
43225 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43226
43227 @smallexample
43228 F0,0,C
43229 @end smallexample
43230
43231 @noindent
43232 or, if the call was interrupted before the host call has been performed:
43233
43234 @smallexample
43235 F-1,4,C
43236 @end smallexample
43237
43238 @noindent
43239 assuming 4 is the protocol-specific representation of @code{EINTR}.
43240
43241 @end table
43242
43243
43244 @node The Ctrl-C Message
43245 @subsection The @samp{Ctrl-C} Message
43246 @cindex ctrl-c message, in file-i/o protocol
43247
43248 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43249 reply packet (@pxref{The F Reply Packet}),
43250 the target should behave as if it had
43251 gotten a break message. The meaning for the target is ``system call
43252 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43253 (as with a break message) and return to @value{GDBN} with a @code{T02}
43254 packet.
43255
43256 It's important for the target to know in which
43257 state the system call was interrupted. There are two possible cases:
43258
43259 @itemize @bullet
43260 @item
43261 The system call hasn't been performed on the host yet.
43262
43263 @item
43264 The system call on the host has been finished.
43265
43266 @end itemize
43267
43268 These two states can be distinguished by the target by the value of the
43269 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43270 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43271 on POSIX systems. In any other case, the target may presume that the
43272 system call has been finished --- successfully or not --- and should behave
43273 as if the break message arrived right after the system call.
43274
43275 @value{GDBN} must behave reliably. If the system call has not been called
43276 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43277 @code{errno} in the packet. If the system call on the host has been finished
43278 before the user requests a break, the full action must be finished by
43279 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43280 The @code{F} packet may only be sent when either nothing has happened
43281 or the full action has been completed.
43282
43283 @node Console I/O
43284 @subsection Console I/O
43285 @cindex console i/o as part of file-i/o
43286
43287 By default and if not explicitly closed by the target system, the file
43288 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43289 on the @value{GDBN} console is handled as any other file output operation
43290 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43291 by @value{GDBN} so that after the target read request from file descriptor
43292 0 all following typing is buffered until either one of the following
43293 conditions is met:
43294
43295 @itemize @bullet
43296 @item
43297 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43298 @code{read}
43299 system call is treated as finished.
43300
43301 @item
43302 The user presses @key{RET}. This is treated as end of input with a trailing
43303 newline.
43304
43305 @item
43306 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43307 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43308
43309 @end itemize
43310
43311 If the user has typed more characters than fit in the buffer given to
43312 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43313 either another @code{read(0, @dots{})} is requested by the target, or debugging
43314 is stopped at the user's request.
43315
43316
43317 @node List of Supported Calls
43318 @subsection List of Supported Calls
43319 @cindex list of supported file-i/o calls
43320
43321 @menu
43322 * open::
43323 * close::
43324 * read::
43325 * write::
43326 * lseek::
43327 * rename::
43328 * unlink::
43329 * stat/fstat::
43330 * gettimeofday::
43331 * isatty::
43332 * system::
43333 @end menu
43334
43335 @node open
43336 @unnumberedsubsubsec open
43337 @cindex open, file-i/o system call
43338
43339 @table @asis
43340 @item Synopsis:
43341 @smallexample
43342 int open(const char *pathname, int flags);
43343 int open(const char *pathname, int flags, mode_t mode);
43344 @end smallexample
43345
43346 @item Request:
43347 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43348
43349 @noindent
43350 @var{flags} is the bitwise @code{OR} of the following values:
43351
43352 @table @code
43353 @item O_CREAT
43354 If the file does not exist it will be created. The host
43355 rules apply as far as file ownership and time stamps
43356 are concerned.
43357
43358 @item O_EXCL
43359 When used with @code{O_CREAT}, if the file already exists it is
43360 an error and open() fails.
43361
43362 @item O_TRUNC
43363 If the file already exists and the open mode allows
43364 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43365 truncated to zero length.
43366
43367 @item O_APPEND
43368 The file is opened in append mode.
43369
43370 @item O_RDONLY
43371 The file is opened for reading only.
43372
43373 @item O_WRONLY
43374 The file is opened for writing only.
43375
43376 @item O_RDWR
43377 The file is opened for reading and writing.
43378 @end table
43379
43380 @noindent
43381 Other bits are silently ignored.
43382
43383
43384 @noindent
43385 @var{mode} is the bitwise @code{OR} of the following values:
43386
43387 @table @code
43388 @item S_IRUSR
43389 User has read permission.
43390
43391 @item S_IWUSR
43392 User has write permission.
43393
43394 @item S_IRGRP
43395 Group has read permission.
43396
43397 @item S_IWGRP
43398 Group has write permission.
43399
43400 @item S_IROTH
43401 Others have read permission.
43402
43403 @item S_IWOTH
43404 Others have write permission.
43405 @end table
43406
43407 @noindent
43408 Other bits are silently ignored.
43409
43410
43411 @item Return value:
43412 @code{open} returns the new file descriptor or -1 if an error
43413 occurred.
43414
43415 @item Errors:
43416
43417 @table @code
43418 @item EEXIST
43419 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
43420
43421 @item EISDIR
43422 @var{pathname} refers to a directory.
43423
43424 @item EACCES
43425 The requested access is not allowed.
43426
43427 @item ENAMETOOLONG
43428 @var{pathname} was too long.
43429
43430 @item ENOENT
43431 A directory component in @var{pathname} does not exist.
43432
43433 @item ENODEV
43434 @var{pathname} refers to a device, pipe, named pipe or socket.
43435
43436 @item EROFS
43437 @var{pathname} refers to a file on a read-only filesystem and
43438 write access was requested.
43439
43440 @item EFAULT
43441 @var{pathname} is an invalid pointer value.
43442
43443 @item ENOSPC
43444 No space on device to create the file.
43445
43446 @item EMFILE
43447 The process already has the maximum number of files open.
43448
43449 @item ENFILE
43450 The limit on the total number of files open on the system
43451 has been reached.
43452
43453 @item EINTR
43454 The call was interrupted by the user.
43455 @end table
43456
43457 @end table
43458
43459 @node close
43460 @unnumberedsubsubsec close
43461 @cindex close, file-i/o system call
43462
43463 @table @asis
43464 @item Synopsis:
43465 @smallexample
43466 int close(int fd);
43467 @end smallexample
43468
43469 @item Request:
43470 @samp{Fclose,@var{fd}}
43471
43472 @item Return value:
43473 @code{close} returns zero on success, or -1 if an error occurred.
43474
43475 @item Errors:
43476
43477 @table @code
43478 @item EBADF
43479 @var{fd} isn't a valid open file descriptor.
43480
43481 @item EINTR
43482 The call was interrupted by the user.
43483 @end table
43484
43485 @end table
43486
43487 @node read
43488 @unnumberedsubsubsec read
43489 @cindex read, file-i/o system call
43490
43491 @table @asis
43492 @item Synopsis:
43493 @smallexample
43494 int read(int fd, void *buf, unsigned int count);
43495 @end smallexample
43496
43497 @item Request:
43498 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
43499
43500 @item Return value:
43501 On success, the number of bytes read is returned.
43502 Zero indicates end of file. If count is zero, read
43503 returns zero as well. On error, -1 is returned.
43504
43505 @item Errors:
43506
43507 @table @code
43508 @item EBADF
43509 @var{fd} is not a valid file descriptor or is not open for
43510 reading.
43511
43512 @item EFAULT
43513 @var{bufptr} is an invalid pointer value.
43514
43515 @item EINTR
43516 The call was interrupted by the user.
43517 @end table
43518
43519 @end table
43520
43521 @node write
43522 @unnumberedsubsubsec write
43523 @cindex write, file-i/o system call
43524
43525 @table @asis
43526 @item Synopsis:
43527 @smallexample
43528 int write(int fd, const void *buf, unsigned int count);
43529 @end smallexample
43530
43531 @item Request:
43532 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
43533
43534 @item Return value:
43535 On success, the number of bytes written are returned.
43536 Zero indicates nothing was written. On error, -1
43537 is returned.
43538
43539 @item Errors:
43540
43541 @table @code
43542 @item EBADF
43543 @var{fd} is not a valid file descriptor or is not open for
43544 writing.
43545
43546 @item EFAULT
43547 @var{bufptr} is an invalid pointer value.
43548
43549 @item EFBIG
43550 An attempt was made to write a file that exceeds the
43551 host-specific maximum file size allowed.
43552
43553 @item ENOSPC
43554 No space on device to write the data.
43555
43556 @item EINTR
43557 The call was interrupted by the user.
43558 @end table
43559
43560 @end table
43561
43562 @node lseek
43563 @unnumberedsubsubsec lseek
43564 @cindex lseek, file-i/o system call
43565
43566 @table @asis
43567 @item Synopsis:
43568 @smallexample
43569 long lseek (int fd, long offset, int flag);
43570 @end smallexample
43571
43572 @item Request:
43573 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
43574
43575 @var{flag} is one of:
43576
43577 @table @code
43578 @item SEEK_SET
43579 The offset is set to @var{offset} bytes.
43580
43581 @item SEEK_CUR
43582 The offset is set to its current location plus @var{offset}
43583 bytes.
43584
43585 @item SEEK_END
43586 The offset is set to the size of the file plus @var{offset}
43587 bytes.
43588 @end table
43589
43590 @item Return value:
43591 On success, the resulting unsigned offset in bytes from
43592 the beginning of the file is returned. Otherwise, a
43593 value of -1 is returned.
43594
43595 @item Errors:
43596
43597 @table @code
43598 @item EBADF
43599 @var{fd} is not a valid open file descriptor.
43600
43601 @item ESPIPE
43602 @var{fd} is associated with the @value{GDBN} console.
43603
43604 @item EINVAL
43605 @var{flag} is not a proper value.
43606
43607 @item EINTR
43608 The call was interrupted by the user.
43609 @end table
43610
43611 @end table
43612
43613 @node rename
43614 @unnumberedsubsubsec rename
43615 @cindex rename, file-i/o system call
43616
43617 @table @asis
43618 @item Synopsis:
43619 @smallexample
43620 int rename(const char *oldpath, const char *newpath);
43621 @end smallexample
43622
43623 @item Request:
43624 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
43625
43626 @item Return value:
43627 On success, zero is returned. On error, -1 is returned.
43628
43629 @item Errors:
43630
43631 @table @code
43632 @item EISDIR
43633 @var{newpath} is an existing directory, but @var{oldpath} is not a
43634 directory.
43635
43636 @item EEXIST
43637 @var{newpath} is a non-empty directory.
43638
43639 @item EBUSY
43640 @var{oldpath} or @var{newpath} is a directory that is in use by some
43641 process.
43642
43643 @item EINVAL
43644 An attempt was made to make a directory a subdirectory
43645 of itself.
43646
43647 @item ENOTDIR
43648 A component used as a directory in @var{oldpath} or new
43649 path is not a directory. Or @var{oldpath} is a directory
43650 and @var{newpath} exists but is not a directory.
43651
43652 @item EFAULT
43653 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
43654
43655 @item EACCES
43656 No access to the file or the path of the file.
43657
43658 @item ENAMETOOLONG
43659
43660 @var{oldpath} or @var{newpath} was too long.
43661
43662 @item ENOENT
43663 A directory component in @var{oldpath} or @var{newpath} does not exist.
43664
43665 @item EROFS
43666 The file is on a read-only filesystem.
43667
43668 @item ENOSPC
43669 The device containing the file has no room for the new
43670 directory entry.
43671
43672 @item EINTR
43673 The call was interrupted by the user.
43674 @end table
43675
43676 @end table
43677
43678 @node unlink
43679 @unnumberedsubsubsec unlink
43680 @cindex unlink, file-i/o system call
43681
43682 @table @asis
43683 @item Synopsis:
43684 @smallexample
43685 int unlink(const char *pathname);
43686 @end smallexample
43687
43688 @item Request:
43689 @samp{Funlink,@var{pathnameptr}/@var{len}}
43690
43691 @item Return value:
43692 On success, zero is returned. On error, -1 is returned.
43693
43694 @item Errors:
43695
43696 @table @code
43697 @item EACCES
43698 No access to the file or the path of the file.
43699
43700 @item EPERM
43701 The system does not allow unlinking of directories.
43702
43703 @item EBUSY
43704 The file @var{pathname} cannot be unlinked because it's
43705 being used by another process.
43706
43707 @item EFAULT
43708 @var{pathnameptr} is an invalid pointer value.
43709
43710 @item ENAMETOOLONG
43711 @var{pathname} was too long.
43712
43713 @item ENOENT
43714 A directory component in @var{pathname} does not exist.
43715
43716 @item ENOTDIR
43717 A component of the path is not a directory.
43718
43719 @item EROFS
43720 The file is on a read-only filesystem.
43721
43722 @item EINTR
43723 The call was interrupted by the user.
43724 @end table
43725
43726 @end table
43727
43728 @node stat/fstat
43729 @unnumberedsubsubsec stat/fstat
43730 @cindex fstat, file-i/o system call
43731 @cindex stat, file-i/o system call
43732
43733 @table @asis
43734 @item Synopsis:
43735 @smallexample
43736 int stat(const char *pathname, struct stat *buf);
43737 int fstat(int fd, struct stat *buf);
43738 @end smallexample
43739
43740 @item Request:
43741 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43742 @samp{Ffstat,@var{fd},@var{bufptr}}
43743
43744 @item Return value:
43745 On success, zero is returned. On error, -1 is returned.
43746
43747 @item Errors:
43748
43749 @table @code
43750 @item EBADF
43751 @var{fd} is not a valid open file.
43752
43753 @item ENOENT
43754 A directory component in @var{pathname} does not exist or the
43755 path is an empty string.
43756
43757 @item ENOTDIR
43758 A component of the path is not a directory.
43759
43760 @item EFAULT
43761 @var{pathnameptr} is an invalid pointer value.
43762
43763 @item EACCES
43764 No access to the file or the path of the file.
43765
43766 @item ENAMETOOLONG
43767 @var{pathname} was too long.
43768
43769 @item EINTR
43770 The call was interrupted by the user.
43771 @end table
43772
43773 @end table
43774
43775 @node gettimeofday
43776 @unnumberedsubsubsec gettimeofday
43777 @cindex gettimeofday, file-i/o system call
43778
43779 @table @asis
43780 @item Synopsis:
43781 @smallexample
43782 int gettimeofday(struct timeval *tv, void *tz);
43783 @end smallexample
43784
43785 @item Request:
43786 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
43787
43788 @item Return value:
43789 On success, 0 is returned, -1 otherwise.
43790
43791 @item Errors:
43792
43793 @table @code
43794 @item EINVAL
43795 @var{tz} is a non-NULL pointer.
43796
43797 @item EFAULT
43798 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43799 @end table
43800
43801 @end table
43802
43803 @node isatty
43804 @unnumberedsubsubsec isatty
43805 @cindex isatty, file-i/o system call
43806
43807 @table @asis
43808 @item Synopsis:
43809 @smallexample
43810 int isatty(int fd);
43811 @end smallexample
43812
43813 @item Request:
43814 @samp{Fisatty,@var{fd}}
43815
43816 @item Return value:
43817 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
43818
43819 @item Errors:
43820
43821 @table @code
43822 @item EINTR
43823 The call was interrupted by the user.
43824 @end table
43825
43826 @end table
43827
43828 Note that the @code{isatty} call is treated as a special case: it returns
43829 1 to the target if the file descriptor is attached
43830 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43831 would require implementing @code{ioctl} and would be more complex than
43832 needed.
43833
43834
43835 @node system
43836 @unnumberedsubsubsec system
43837 @cindex system, file-i/o system call
43838
43839 @table @asis
43840 @item Synopsis:
43841 @smallexample
43842 int system(const char *command);
43843 @end smallexample
43844
43845 @item Request:
43846 @samp{Fsystem,@var{commandptr}/@var{len}}
43847
43848 @item Return value:
43849 If @var{len} is zero, the return value indicates whether a shell is
43850 available. A zero return value indicates a shell is not available.
43851 For non-zero @var{len}, the value returned is -1 on error and the
43852 return status of the command otherwise. Only the exit status of the
43853 command is returned, which is extracted from the host's @code{system}
43854 return value by calling @code{WEXITSTATUS(retval)}. In case
43855 @file{/bin/sh} could not be executed, 127 is returned.
43856
43857 @item Errors:
43858
43859 @table @code
43860 @item EINTR
43861 The call was interrupted by the user.
43862 @end table
43863
43864 @end table
43865
43866 @value{GDBN} takes over the full task of calling the necessary host calls
43867 to perform the @code{system} call. The return value of @code{system} on
43868 the host is simplified before it's returned
43869 to the target. Any termination signal information from the child process
43870 is discarded, and the return value consists
43871 entirely of the exit status of the called command.
43872
43873 Due to security concerns, the @code{system} call is by default refused
43874 by @value{GDBN}. The user has to allow this call explicitly with the
43875 @code{set remote system-call-allowed 1} command.
43876
43877 @table @code
43878 @item set remote system-call-allowed
43879 @kindex set remote system-call-allowed
43880 Control whether to allow the @code{system} calls in the File I/O
43881 protocol for the remote target. The default is zero (disabled).
43882
43883 @item show remote system-call-allowed
43884 @kindex show remote system-call-allowed
43885 Show whether the @code{system} calls are allowed in the File I/O
43886 protocol.
43887 @end table
43888
43889 @node Protocol-specific Representation of Datatypes
43890 @subsection Protocol-specific Representation of Datatypes
43891 @cindex protocol-specific representation of datatypes, in file-i/o protocol
43892
43893 @menu
43894 * Integral Datatypes::
43895 * Pointer Values::
43896 * Memory Transfer::
43897 * struct stat::
43898 * struct timeval::
43899 @end menu
43900
43901 @node Integral Datatypes
43902 @unnumberedsubsubsec Integral Datatypes
43903 @cindex integral datatypes, in file-i/o protocol
43904
43905 The integral datatypes used in the system calls are @code{int},
43906 @code{unsigned int}, @code{long}, @code{unsigned long},
43907 @code{mode_t}, and @code{time_t}.
43908
43909 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
43910 implemented as 32 bit values in this protocol.
43911
43912 @code{long} and @code{unsigned long} are implemented as 64 bit types.
43913
43914 @xref{Limits}, for corresponding MIN and MAX values (similar to those
43915 in @file{limits.h}) to allow range checking on host and target.
43916
43917 @code{time_t} datatypes are defined as seconds since the Epoch.
43918
43919 All integral datatypes transferred as part of a memory read or write of a
43920 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43921 byte order.
43922
43923 @node Pointer Values
43924 @unnumberedsubsubsec Pointer Values
43925 @cindex pointer values, in file-i/o protocol
43926
43927 Pointers to target data are transmitted as they are. An exception
43928 is made for pointers to buffers for which the length isn't
43929 transmitted as part of the function call, namely strings. Strings
43930 are transmitted as a pointer/length pair, both as hex values, e.g.@:
43931
43932 @smallexample
43933 @code{1aaf/12}
43934 @end smallexample
43935
43936 @noindent
43937 which is a pointer to data of length 18 bytes at position 0x1aaf.
43938 The length is defined as the full string length in bytes, including
43939 the trailing null byte. For example, the string @code{"hello world"}
43940 at address 0x123456 is transmitted as
43941
43942 @smallexample
43943 @code{123456/d}
43944 @end smallexample
43945
43946 @node Memory Transfer
43947 @unnumberedsubsubsec Memory Transfer
43948 @cindex memory transfer, in file-i/o protocol
43949
43950 Structured data which is transferred using a memory read or write (for
43951 example, a @code{struct stat}) is expected to be in a protocol-specific format
43952 with all scalar multibyte datatypes being big endian. Translation to
43953 this representation needs to be done both by the target before the @code{F}
43954 packet is sent, and by @value{GDBN} before
43955 it transfers memory to the target. Transferred pointers to structured
43956 data should point to the already-coerced data at any time.
43957
43958
43959 @node struct stat
43960 @unnumberedsubsubsec struct stat
43961 @cindex struct stat, in file-i/o protocol
43962
43963 The buffer of type @code{struct stat} used by the target and @value{GDBN}
43964 is defined as follows:
43965
43966 @smallexample
43967 struct stat @{
43968 unsigned int st_dev; /* device */
43969 unsigned int st_ino; /* inode */
43970 mode_t st_mode; /* protection */
43971 unsigned int st_nlink; /* number of hard links */
43972 unsigned int st_uid; /* user ID of owner */
43973 unsigned int st_gid; /* group ID of owner */
43974 unsigned int st_rdev; /* device type (if inode device) */
43975 unsigned long st_size; /* total size, in bytes */
43976 unsigned long st_blksize; /* blocksize for filesystem I/O */
43977 unsigned long st_blocks; /* number of blocks allocated */
43978 time_t st_atime; /* time of last access */
43979 time_t st_mtime; /* time of last modification */
43980 time_t st_ctime; /* time of last change */
43981 @};
43982 @end smallexample
43983
43984 The integral datatypes conform to the definitions given in the
43985 appropriate section (see @ref{Integral Datatypes}, for details) so this
43986 structure is of size 64 bytes.
43987
43988 The values of several fields have a restricted meaning and/or
43989 range of values.
43990
43991 @table @code
43992
43993 @item st_dev
43994 A value of 0 represents a file, 1 the console.
43995
43996 @item st_ino
43997 No valid meaning for the target. Transmitted unchanged.
43998
43999 @item st_mode
44000 Valid mode bits are described in @ref{Constants}. Any other
44001 bits have currently no meaning for the target.
44002
44003 @item st_uid
44004 @itemx st_gid
44005 @itemx st_rdev
44006 No valid meaning for the target. Transmitted unchanged.
44007
44008 @item st_atime
44009 @itemx st_mtime
44010 @itemx st_ctime
44011 These values have a host and file system dependent
44012 accuracy. Especially on Windows hosts, the file system may not
44013 support exact timing values.
44014 @end table
44015
44016 The target gets a @code{struct stat} of the above representation and is
44017 responsible for coercing it to the target representation before
44018 continuing.
44019
44020 Note that due to size differences between the host, target, and protocol
44021 representations of @code{struct stat} members, these members could eventually
44022 get truncated on the target.
44023
44024 @node struct timeval
44025 @unnumberedsubsubsec struct timeval
44026 @cindex struct timeval, in file-i/o protocol
44027
44028 The buffer of type @code{struct timeval} used by the File-I/O protocol
44029 is defined as follows:
44030
44031 @smallexample
44032 struct timeval @{
44033 time_t tv_sec; /* second */
44034 long tv_usec; /* microsecond */
44035 @};
44036 @end smallexample
44037
44038 The integral datatypes conform to the definitions given in the
44039 appropriate section (see @ref{Integral Datatypes}, for details) so this
44040 structure is of size 8 bytes.
44041
44042 @node Constants
44043 @subsection Constants
44044 @cindex constants, in file-i/o protocol
44045
44046 The following values are used for the constants inside of the
44047 protocol. @value{GDBN} and target are responsible for translating these
44048 values before and after the call as needed.
44049
44050 @menu
44051 * Open Flags::
44052 * mode_t Values::
44053 * Errno Values::
44054 * Lseek Flags::
44055 * Limits::
44056 @end menu
44057
44058 @node Open Flags
44059 @unnumberedsubsubsec Open Flags
44060 @cindex open flags, in file-i/o protocol
44061
44062 All values are given in hexadecimal representation.
44063
44064 @smallexample
44065 O_RDONLY 0x0
44066 O_WRONLY 0x1
44067 O_RDWR 0x2
44068 O_APPEND 0x8
44069 O_CREAT 0x200
44070 O_TRUNC 0x400
44071 O_EXCL 0x800
44072 @end smallexample
44073
44074 @node mode_t Values
44075 @unnumberedsubsubsec mode_t Values
44076 @cindex mode_t values, in file-i/o protocol
44077
44078 All values are given in octal representation.
44079
44080 @smallexample
44081 S_IFREG 0100000
44082 S_IFDIR 040000
44083 S_IRUSR 0400
44084 S_IWUSR 0200
44085 S_IXUSR 0100
44086 S_IRGRP 040
44087 S_IWGRP 020
44088 S_IXGRP 010
44089 S_IROTH 04
44090 S_IWOTH 02
44091 S_IXOTH 01
44092 @end smallexample
44093
44094 @node Errno Values
44095 @unnumberedsubsubsec Errno Values
44096 @cindex errno values, in file-i/o protocol
44097
44098 All values are given in decimal representation.
44099
44100 @smallexample
44101 EPERM 1
44102 ENOENT 2
44103 EINTR 4
44104 EBADF 9
44105 EACCES 13
44106 EFAULT 14
44107 EBUSY 16
44108 EEXIST 17
44109 ENODEV 19
44110 ENOTDIR 20
44111 EISDIR 21
44112 EINVAL 22
44113 ENFILE 23
44114 EMFILE 24
44115 EFBIG 27
44116 ENOSPC 28
44117 ESPIPE 29
44118 EROFS 30
44119 ENAMETOOLONG 91
44120 EUNKNOWN 9999
44121 @end smallexample
44122
44123 @code{EUNKNOWN} is used as a fallback error value if a host system returns
44124 any error value not in the list of supported error numbers.
44125
44126 @node Lseek Flags
44127 @unnumberedsubsubsec Lseek Flags
44128 @cindex lseek flags, in file-i/o protocol
44129
44130 @smallexample
44131 SEEK_SET 0
44132 SEEK_CUR 1
44133 SEEK_END 2
44134 @end smallexample
44135
44136 @node Limits
44137 @unnumberedsubsubsec Limits
44138 @cindex limits, in file-i/o protocol
44139
44140 All values are given in decimal representation.
44141
44142 @smallexample
44143 INT_MIN -2147483648
44144 INT_MAX 2147483647
44145 UINT_MAX 4294967295
44146 LONG_MIN -9223372036854775808
44147 LONG_MAX 9223372036854775807
44148 ULONG_MAX 18446744073709551615
44149 @end smallexample
44150
44151 @node File-I/O Examples
44152 @subsection File-I/O Examples
44153 @cindex file-i/o examples
44154
44155 Example sequence of a write call, file descriptor 3, buffer is at target
44156 address 0x1234, 6 bytes should be written:
44157
44158 @smallexample
44159 <- @code{Fwrite,3,1234,6}
44160 @emph{request memory read from target}
44161 -> @code{m1234,6}
44162 <- XXXXXX
44163 @emph{return "6 bytes written"}
44164 -> @code{F6}
44165 @end smallexample
44166
44167 Example sequence of a read call, file descriptor 3, buffer is at target
44168 address 0x1234, 6 bytes should be read:
44169
44170 @smallexample
44171 <- @code{Fread,3,1234,6}
44172 @emph{request memory write to target}
44173 -> @code{X1234,6:XXXXXX}
44174 @emph{return "6 bytes read"}
44175 -> @code{F6}
44176 @end smallexample
44177
44178 Example sequence of a read call, call fails on the host due to invalid
44179 file descriptor (@code{EBADF}):
44180
44181 @smallexample
44182 <- @code{Fread,3,1234,6}
44183 -> @code{F-1,9}
44184 @end smallexample
44185
44186 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44187 host is called:
44188
44189 @smallexample
44190 <- @code{Fread,3,1234,6}
44191 -> @code{F-1,4,C}
44192 <- @code{T02}
44193 @end smallexample
44194
44195 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44196 host is called:
44197
44198 @smallexample
44199 <- @code{Fread,3,1234,6}
44200 -> @code{X1234,6:XXXXXX}
44201 <- @code{T02}
44202 @end smallexample
44203
44204 @node Library List Format
44205 @section Library List Format
44206 @cindex library list format, remote protocol
44207
44208 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44209 same process as your application to manage libraries. In this case,
44210 @value{GDBN} can use the loader's symbol table and normal memory
44211 operations to maintain a list of shared libraries. On other
44212 platforms, the operating system manages loaded libraries.
44213 @value{GDBN} can not retrieve the list of currently loaded libraries
44214 through memory operations, so it uses the @samp{qXfer:libraries:read}
44215 packet (@pxref{qXfer library list read}) instead. The remote stub
44216 queries the target's operating system and reports which libraries
44217 are loaded.
44218
44219 The @samp{qXfer:libraries:read} packet returns an XML document which
44220 lists loaded libraries and their offsets. Each library has an
44221 associated name and one or more segment or section base addresses,
44222 which report where the library was loaded in memory.
44223
44224 For the common case of libraries that are fully linked binaries, the
44225 library should have a list of segments. If the target supports
44226 dynamic linking of a relocatable object file, its library XML element
44227 should instead include a list of allocated sections. The segment or
44228 section bases are start addresses, not relocation offsets; they do not
44229 depend on the library's link-time base addresses.
44230
44231 @value{GDBN} must be linked with the Expat library to support XML
44232 library lists. @xref{Expat}.
44233
44234 A simple memory map, with one loaded library relocated by a single
44235 offset, looks like this:
44236
44237 @smallexample
44238 <library-list>
44239 <library name="/lib/libc.so.6">
44240 <segment address="0x10000000"/>
44241 </library>
44242 </library-list>
44243 @end smallexample
44244
44245 Another simple memory map, with one loaded library with three
44246 allocated sections (.text, .data, .bss), looks like this:
44247
44248 @smallexample
44249 <library-list>
44250 <library name="sharedlib.o">
44251 <section address="0x10000000"/>
44252 <section address="0x20000000"/>
44253 <section address="0x30000000"/>
44254 </library>
44255 </library-list>
44256 @end smallexample
44257
44258 The format of a library list is described by this DTD:
44259
44260 @smallexample
44261 <!-- library-list: Root element with versioning -->
44262 <!ELEMENT library-list (library)*>
44263 <!ATTLIST library-list version CDATA #FIXED "1.0">
44264 <!ELEMENT library (segment*, section*)>
44265 <!ATTLIST library name CDATA #REQUIRED>
44266 <!ELEMENT segment EMPTY>
44267 <!ATTLIST segment address CDATA #REQUIRED>
44268 <!ELEMENT section EMPTY>
44269 <!ATTLIST section address CDATA #REQUIRED>
44270 @end smallexample
44271
44272 In addition, segments and section descriptors cannot be mixed within a
44273 single library element, and you must supply at least one segment or
44274 section for each library.
44275
44276 @node Library List Format for SVR4 Targets
44277 @section Library List Format for SVR4 Targets
44278 @cindex library list format, remote protocol
44279
44280 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44281 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44282 shared libraries. Still a special library list provided by this packet is
44283 more efficient for the @value{GDBN} remote protocol.
44284
44285 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44286 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44287 target, the following parameters are reported:
44288
44289 @itemize @minus
44290 @item
44291 @code{name}, the absolute file name from the @code{l_name} field of
44292 @code{struct link_map}.
44293 @item
44294 @code{lm} with address of @code{struct link_map} used for TLS
44295 (Thread Local Storage) access.
44296 @item
44297 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44298 @code{struct link_map}. For prelinked libraries this is not an absolute
44299 memory address. It is a displacement of absolute memory address against
44300 address the file was prelinked to during the library load.
44301 @item
44302 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44303 @end itemize
44304
44305 Additionally the single @code{main-lm} attribute specifies address of
44306 @code{struct link_map} used for the main executable. This parameter is used
44307 for TLS access and its presence is optional.
44308
44309 @value{GDBN} must be linked with the Expat library to support XML
44310 SVR4 library lists. @xref{Expat}.
44311
44312 A simple memory map, with two loaded libraries (which do not use prelink),
44313 looks like this:
44314
44315 @smallexample
44316 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44317 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44318 l_ld="0xe4eefc"/>
44319 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
44320 l_ld="0x152350"/>
44321 </library-list-svr>
44322 @end smallexample
44323
44324 The format of an SVR4 library list is described by this DTD:
44325
44326 @smallexample
44327 <!-- library-list-svr4: Root element with versioning -->
44328 <!ELEMENT library-list-svr4 (library)*>
44329 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44330 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
44331 <!ELEMENT library EMPTY>
44332 <!ATTLIST library name CDATA #REQUIRED>
44333 <!ATTLIST library lm CDATA #REQUIRED>
44334 <!ATTLIST library l_addr CDATA #REQUIRED>
44335 <!ATTLIST library l_ld CDATA #REQUIRED>
44336 @end smallexample
44337
44338 @node Memory Map Format
44339 @section Memory Map Format
44340 @cindex memory map format
44341
44342 To be able to write into flash memory, @value{GDBN} needs to obtain a
44343 memory map from the target. This section describes the format of the
44344 memory map.
44345
44346 The memory map is obtained using the @samp{qXfer:memory-map:read}
44347 (@pxref{qXfer memory map read}) packet and is an XML document that
44348 lists memory regions.
44349
44350 @value{GDBN} must be linked with the Expat library to support XML
44351 memory maps. @xref{Expat}.
44352
44353 The top-level structure of the document is shown below:
44354
44355 @smallexample
44356 <?xml version="1.0"?>
44357 <!DOCTYPE memory-map
44358 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44359 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44360 <memory-map>
44361 region...
44362 </memory-map>
44363 @end smallexample
44364
44365 Each region can be either:
44366
44367 @itemize
44368
44369 @item
44370 A region of RAM starting at @var{addr} and extending for @var{length}
44371 bytes from there:
44372
44373 @smallexample
44374 <memory type="ram" start="@var{addr}" length="@var{length}"/>
44375 @end smallexample
44376
44377
44378 @item
44379 A region of read-only memory:
44380
44381 @smallexample
44382 <memory type="rom" start="@var{addr}" length="@var{length}"/>
44383 @end smallexample
44384
44385
44386 @item
44387 A region of flash memory, with erasure blocks @var{blocksize}
44388 bytes in length:
44389
44390 @smallexample
44391 <memory type="flash" start="@var{addr}" length="@var{length}">
44392 <property name="blocksize">@var{blocksize}</property>
44393 </memory>
44394 @end smallexample
44395
44396 @end itemize
44397
44398 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44399 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44400 packets to write to addresses in such ranges.
44401
44402 The formal DTD for memory map format is given below:
44403
44404 @smallexample
44405 <!-- ................................................... -->
44406 <!-- Memory Map XML DTD ................................ -->
44407 <!-- File: memory-map.dtd .............................. -->
44408 <!-- .................................... .............. -->
44409 <!-- memory-map.dtd -->
44410 <!-- memory-map: Root element with versioning -->
44411 <!ELEMENT memory-map (memory)*>
44412 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
44413 <!ELEMENT memory (property)*>
44414 <!-- memory: Specifies a memory region,
44415 and its type, or device. -->
44416 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
44417 start CDATA #REQUIRED
44418 length CDATA #REQUIRED>
44419 <!-- property: Generic attribute tag -->
44420 <!ELEMENT property (#PCDATA | property)*>
44421 <!ATTLIST property name (blocksize) #REQUIRED>
44422 @end smallexample
44423
44424 @node Thread List Format
44425 @section Thread List Format
44426 @cindex thread list format
44427
44428 To efficiently update the list of threads and their attributes,
44429 @value{GDBN} issues the @samp{qXfer:threads:read} packet
44430 (@pxref{qXfer threads read}) and obtains the XML document with
44431 the following structure:
44432
44433 @smallexample
44434 <?xml version="1.0"?>
44435 <threads>
44436 <thread id="id" core="0" name="name">
44437 ... description ...
44438 </thread>
44439 </threads>
44440 @end smallexample
44441
44442 Each @samp{thread} element must have the @samp{id} attribute that
44443 identifies the thread (@pxref{thread-id syntax}). The
44444 @samp{core} attribute, if present, specifies which processor core
44445 the thread was last executing on. The @samp{name} attribute, if
44446 present, specifies the human-readable name of the thread. The content
44447 of the of @samp{thread} element is interpreted as human-readable
44448 auxiliary information. The @samp{handle} attribute, if present,
44449 is a hex encoded representation of the thread handle.
44450
44451
44452 @node Traceframe Info Format
44453 @section Traceframe Info Format
44454 @cindex traceframe info format
44455
44456 To be able to know which objects in the inferior can be examined when
44457 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44458 memory ranges, registers and trace state variables that have been
44459 collected in a traceframe.
44460
44461 This list is obtained using the @samp{qXfer:traceframe-info:read}
44462 (@pxref{qXfer traceframe info read}) packet and is an XML document.
44463
44464 @value{GDBN} must be linked with the Expat library to support XML
44465 traceframe info discovery. @xref{Expat}.
44466
44467 The top-level structure of the document is shown below:
44468
44469 @smallexample
44470 <?xml version="1.0"?>
44471 <!DOCTYPE traceframe-info
44472 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44473 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44474 <traceframe-info>
44475 block...
44476 </traceframe-info>
44477 @end smallexample
44478
44479 Each traceframe block can be either:
44480
44481 @itemize
44482
44483 @item
44484 A region of collected memory starting at @var{addr} and extending for
44485 @var{length} bytes from there:
44486
44487 @smallexample
44488 <memory start="@var{addr}" length="@var{length}"/>
44489 @end smallexample
44490
44491 @item
44492 A block indicating trace state variable numbered @var{number} has been
44493 collected:
44494
44495 @smallexample
44496 <tvar id="@var{number}"/>
44497 @end smallexample
44498
44499 @end itemize
44500
44501 The formal DTD for the traceframe info format is given below:
44502
44503 @smallexample
44504 <!ELEMENT traceframe-info (memory | tvar)* >
44505 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44506
44507 <!ELEMENT memory EMPTY>
44508 <!ATTLIST memory start CDATA #REQUIRED
44509 length CDATA #REQUIRED>
44510 <!ELEMENT tvar>
44511 <!ATTLIST tvar id CDATA #REQUIRED>
44512 @end smallexample
44513
44514 @node Branch Trace Format
44515 @section Branch Trace Format
44516 @cindex branch trace format
44517
44518 In order to display the branch trace of an inferior thread,
44519 @value{GDBN} needs to obtain the list of branches. This list is
44520 represented as list of sequential code blocks that are connected via
44521 branches. The code in each block has been executed sequentially.
44522
44523 This list is obtained using the @samp{qXfer:btrace:read}
44524 (@pxref{qXfer btrace read}) packet and is an XML document.
44525
44526 @value{GDBN} must be linked with the Expat library to support XML
44527 traceframe info discovery. @xref{Expat}.
44528
44529 The top-level structure of the document is shown below:
44530
44531 @smallexample
44532 <?xml version="1.0"?>
44533 <!DOCTYPE btrace
44534 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44535 "http://sourceware.org/gdb/gdb-btrace.dtd">
44536 <btrace>
44537 block...
44538 </btrace>
44539 @end smallexample
44540
44541 @itemize
44542
44543 @item
44544 A block of sequentially executed instructions starting at @var{begin}
44545 and ending at @var{end}:
44546
44547 @smallexample
44548 <block begin="@var{begin}" end="@var{end}"/>
44549 @end smallexample
44550
44551 @end itemize
44552
44553 The formal DTD for the branch trace format is given below:
44554
44555 @smallexample
44556 <!ELEMENT btrace (block* | pt) >
44557 <!ATTLIST btrace version CDATA #FIXED "1.0">
44558
44559 <!ELEMENT block EMPTY>
44560 <!ATTLIST block begin CDATA #REQUIRED
44561 end CDATA #REQUIRED>
44562
44563 <!ELEMENT pt (pt-config?, raw?)>
44564
44565 <!ELEMENT pt-config (cpu?)>
44566
44567 <!ELEMENT cpu EMPTY>
44568 <!ATTLIST cpu vendor CDATA #REQUIRED
44569 family CDATA #REQUIRED
44570 model CDATA #REQUIRED
44571 stepping CDATA #REQUIRED>
44572
44573 <!ELEMENT raw (#PCDATA)>
44574 @end smallexample
44575
44576 @node Branch Trace Configuration Format
44577 @section Branch Trace Configuration Format
44578 @cindex branch trace configuration format
44579
44580 For each inferior thread, @value{GDBN} can obtain the branch trace
44581 configuration using the @samp{qXfer:btrace-conf:read}
44582 (@pxref{qXfer btrace-conf read}) packet.
44583
44584 The configuration describes the branch trace format and configuration
44585 settings for that format. The following information is described:
44586
44587 @table @code
44588 @item bts
44589 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44590 @table @code
44591 @item size
44592 The size of the @acronym{BTS} ring buffer in bytes.
44593 @end table
44594 @item pt
44595 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
44596 PT}) format.
44597 @table @code
44598 @item size
44599 The size of the @acronym{Intel PT} ring buffer in bytes.
44600 @end table
44601 @end table
44602
44603 @value{GDBN} must be linked with the Expat library to support XML
44604 branch trace configuration discovery. @xref{Expat}.
44605
44606 The formal DTD for the branch trace configuration format is given below:
44607
44608 @smallexample
44609 <!ELEMENT btrace-conf (bts?, pt?)>
44610 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44611
44612 <!ELEMENT bts EMPTY>
44613 <!ATTLIST bts size CDATA #IMPLIED>
44614
44615 <!ELEMENT pt EMPTY>
44616 <!ATTLIST pt size CDATA #IMPLIED>
44617 @end smallexample
44618
44619 @include agentexpr.texi
44620
44621 @node Target Descriptions
44622 @appendix Target Descriptions
44623 @cindex target descriptions
44624
44625 One of the challenges of using @value{GDBN} to debug embedded systems
44626 is that there are so many minor variants of each processor
44627 architecture in use. It is common practice for vendors to start with
44628 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
44629 and then make changes to adapt it to a particular market niche. Some
44630 architectures have hundreds of variants, available from dozens of
44631 vendors. This leads to a number of problems:
44632
44633 @itemize @bullet
44634 @item
44635 With so many different customized processors, it is difficult for
44636 the @value{GDBN} maintainers to keep up with the changes.
44637 @item
44638 Since individual variants may have short lifetimes or limited
44639 audiences, it may not be worthwhile to carry information about every
44640 variant in the @value{GDBN} source tree.
44641 @item
44642 When @value{GDBN} does support the architecture of the embedded system
44643 at hand, the task of finding the correct architecture name to give the
44644 @command{set architecture} command can be error-prone.
44645 @end itemize
44646
44647 To address these problems, the @value{GDBN} remote protocol allows a
44648 target system to not only identify itself to @value{GDBN}, but to
44649 actually describe its own features. This lets @value{GDBN} support
44650 processor variants it has never seen before --- to the extent that the
44651 descriptions are accurate, and that @value{GDBN} understands them.
44652
44653 @value{GDBN} must be linked with the Expat library to support XML
44654 target descriptions. @xref{Expat}.
44655
44656 @menu
44657 * Retrieving Descriptions:: How descriptions are fetched from a target.
44658 * Target Description Format:: The contents of a target description.
44659 * Predefined Target Types:: Standard types available for target
44660 descriptions.
44661 * Enum Target Types:: How to define enum target types.
44662 * Standard Target Features:: Features @value{GDBN} knows about.
44663 @end menu
44664
44665 @node Retrieving Descriptions
44666 @section Retrieving Descriptions
44667
44668 Target descriptions can be read from the target automatically, or
44669 specified by the user manually. The default behavior is to read the
44670 description from the target. @value{GDBN} retrieves it via the remote
44671 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44672 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44673 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
44674 XML document, of the form described in @ref{Target Description
44675 Format}.
44676
44677 Alternatively, you can specify a file to read for the target description.
44678 If a file is set, the target will not be queried. The commands to
44679 specify a file are:
44680
44681 @table @code
44682 @cindex set tdesc filename
44683 @item set tdesc filename @var{path}
44684 Read the target description from @var{path}.
44685
44686 @cindex unset tdesc filename
44687 @item unset tdesc filename
44688 Do not read the XML target description from a file. @value{GDBN}
44689 will use the description supplied by the current target.
44690
44691 @cindex show tdesc filename
44692 @item show tdesc filename
44693 Show the filename to read for a target description, if any.
44694 @end table
44695
44696
44697 @node Target Description Format
44698 @section Target Description Format
44699 @cindex target descriptions, XML format
44700
44701 A target description annex is an @uref{http://www.w3.org/XML/, XML}
44702 document which complies with the Document Type Definition provided in
44703 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44704 means you can use generally available tools like @command{xmllint} to
44705 check that your feature descriptions are well-formed and valid.
44706 However, to help people unfamiliar with XML write descriptions for
44707 their targets, we also describe the grammar here.
44708
44709 Target descriptions can identify the architecture of the remote target
44710 and (for some architectures) provide information about custom register
44711 sets. They can also identify the OS ABI of the remote target.
44712 @value{GDBN} can use this information to autoconfigure for your
44713 target, or to warn you if you connect to an unsupported target.
44714
44715 Here is a simple target description:
44716
44717 @smallexample
44718 <target version="1.0">
44719 <architecture>i386:x86-64</architecture>
44720 </target>
44721 @end smallexample
44722
44723 @noindent
44724 This minimal description only says that the target uses
44725 the x86-64 architecture.
44726
44727 A target description has the following overall form, with [ ] marking
44728 optional elements and @dots{} marking repeatable elements. The elements
44729 are explained further below.
44730
44731 @smallexample
44732 <?xml version="1.0"?>
44733 <!DOCTYPE target SYSTEM "gdb-target.dtd">
44734 <target version="1.0">
44735 @r{[}@var{architecture}@r{]}
44736 @r{[}@var{osabi}@r{]}
44737 @r{[}@var{compatible}@r{]}
44738 @r{[}@var{feature}@dots{}@r{]}
44739 </target>
44740 @end smallexample
44741
44742 @noindent
44743 The description is generally insensitive to whitespace and line
44744 breaks, under the usual common-sense rules. The XML version
44745 declaration and document type declaration can generally be omitted
44746 (@value{GDBN} does not require them), but specifying them may be
44747 useful for XML validation tools. The @samp{version} attribute for
44748 @samp{<target>} may also be omitted, but we recommend
44749 including it; if future versions of @value{GDBN} use an incompatible
44750 revision of @file{gdb-target.dtd}, they will detect and report
44751 the version mismatch.
44752
44753 @subsection Inclusion
44754 @cindex target descriptions, inclusion
44755 @cindex XInclude
44756 @ifnotinfo
44757 @cindex <xi:include>
44758 @end ifnotinfo
44759
44760 It can sometimes be valuable to split a target description up into
44761 several different annexes, either for organizational purposes, or to
44762 share files between different possible target descriptions. You can
44763 divide a description into multiple files by replacing any element of
44764 the target description with an inclusion directive of the form:
44765
44766 @smallexample
44767 <xi:include href="@var{document}"/>
44768 @end smallexample
44769
44770 @noindent
44771 When @value{GDBN} encounters an element of this form, it will retrieve
44772 the named XML @var{document}, and replace the inclusion directive with
44773 the contents of that document. If the current description was read
44774 using @samp{qXfer}, then so will be the included document;
44775 @var{document} will be interpreted as the name of an annex. If the
44776 current description was read from a file, @value{GDBN} will look for
44777 @var{document} as a file in the same directory where it found the
44778 original description.
44779
44780 @subsection Architecture
44781 @cindex <architecture>
44782
44783 An @samp{<architecture>} element has this form:
44784
44785 @smallexample
44786 <architecture>@var{arch}</architecture>
44787 @end smallexample
44788
44789 @var{arch} is one of the architectures from the set accepted by
44790 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44791
44792 @subsection OS ABI
44793 @cindex @code{<osabi>}
44794
44795 This optional field was introduced in @value{GDBN} version 7.0.
44796 Previous versions of @value{GDBN} ignore it.
44797
44798 An @samp{<osabi>} element has this form:
44799
44800 @smallexample
44801 <osabi>@var{abi-name}</osabi>
44802 @end smallexample
44803
44804 @var{abi-name} is an OS ABI name from the same selection accepted by
44805 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44806
44807 @subsection Compatible Architecture
44808 @cindex @code{<compatible>}
44809
44810 This optional field was introduced in @value{GDBN} version 7.0.
44811 Previous versions of @value{GDBN} ignore it.
44812
44813 A @samp{<compatible>} element has this form:
44814
44815 @smallexample
44816 <compatible>@var{arch}</compatible>
44817 @end smallexample
44818
44819 @var{arch} is one of the architectures from the set accepted by
44820 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44821
44822 A @samp{<compatible>} element is used to specify that the target
44823 is able to run binaries in some other than the main target architecture
44824 given by the @samp{<architecture>} element. For example, on the
44825 Cell Broadband Engine, the main architecture is @code{powerpc:common}
44826 or @code{powerpc:common64}, but the system is able to run binaries
44827 in the @code{spu} architecture as well. The way to describe this
44828 capability with @samp{<compatible>} is as follows:
44829
44830 @smallexample
44831 <architecture>powerpc:common</architecture>
44832 <compatible>spu</compatible>
44833 @end smallexample
44834
44835 @subsection Features
44836 @cindex <feature>
44837
44838 Each @samp{<feature>} describes some logical portion of the target
44839 system. Features are currently used to describe available CPU
44840 registers and the types of their contents. A @samp{<feature>} element
44841 has this form:
44842
44843 @smallexample
44844 <feature name="@var{name}">
44845 @r{[}@var{type}@dots{}@r{]}
44846 @var{reg}@dots{}
44847 </feature>
44848 @end smallexample
44849
44850 @noindent
44851 Each feature's name should be unique within the description. The name
44852 of a feature does not matter unless @value{GDBN} has some special
44853 knowledge of the contents of that feature; if it does, the feature
44854 should have its standard name. @xref{Standard Target Features}.
44855
44856 @subsection Types
44857
44858 Any register's value is a collection of bits which @value{GDBN} must
44859 interpret. The default interpretation is a two's complement integer,
44860 but other types can be requested by name in the register description.
44861 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
44862 Target Types}), and the description can define additional composite
44863 and enum types.
44864
44865 Each type element must have an @samp{id} attribute, which gives
44866 a unique (within the containing @samp{<feature>}) name to the type.
44867 Types must be defined before they are used.
44868
44869 @cindex <vector>
44870 Some targets offer vector registers, which can be treated as arrays
44871 of scalar elements. These types are written as @samp{<vector>} elements,
44872 specifying the array element type, @var{type}, and the number of elements,
44873 @var{count}:
44874
44875 @smallexample
44876 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44877 @end smallexample
44878
44879 @cindex <union>
44880 If a register's value is usefully viewed in multiple ways, define it
44881 with a union type containing the useful representations. The
44882 @samp{<union>} element contains one or more @samp{<field>} elements,
44883 each of which has a @var{name} and a @var{type}:
44884
44885 @smallexample
44886 <union id="@var{id}">
44887 <field name="@var{name}" type="@var{type}"/>
44888 @dots{}
44889 </union>
44890 @end smallexample
44891
44892 @cindex <struct>
44893 @cindex <flags>
44894 If a register's value is composed from several separate values, define
44895 it with either a structure type or a flags type.
44896 A flags type may only contain bitfields.
44897 A structure type may either contain only bitfields or contain no bitfields.
44898 If the value contains only bitfields, its total size in bytes must be
44899 specified.
44900
44901 Non-bitfield values have a @var{name} and @var{type}.
44902
44903 @smallexample
44904 <struct id="@var{id}">
44905 <field name="@var{name}" type="@var{type}"/>
44906 @dots{}
44907 </struct>
44908 @end smallexample
44909
44910 Both @var{name} and @var{type} values are required.
44911 No implicit padding is added.
44912
44913 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
44914
44915 @smallexample
44916 <struct id="@var{id}" size="@var{size}">
44917 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44918 @dots{}
44919 </struct>
44920 @end smallexample
44921
44922 @smallexample
44923 <flags id="@var{id}" size="@var{size}">
44924 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44925 @dots{}
44926 </flags>
44927 @end smallexample
44928
44929 The @var{name} value is required.
44930 Bitfield values may be named with the empty string, @samp{""},
44931 in which case the field is ``filler'' and its value is not printed.
44932 Not all bits need to be specified, so ``filler'' fields are optional.
44933
44934 The @var{start} and @var{end} values are required, and @var{type}
44935 is optional.
44936 The field's @var{start} must be less than or equal to its @var{end},
44937 and zero represents the least significant bit.
44938
44939 The default value of @var{type} is @code{bool} for single bit fields,
44940 and an unsigned integer otherwise.
44941
44942 Which to choose? Structures or flags?
44943
44944 Registers defined with @samp{flags} have these advantages over
44945 defining them with @samp{struct}:
44946
44947 @itemize @bullet
44948 @item
44949 Arithmetic may be performed on them as if they were integers.
44950 @item
44951 They are printed in a more readable fashion.
44952 @end itemize
44953
44954 Registers defined with @samp{struct} have one advantage over
44955 defining them with @samp{flags}:
44956
44957 @itemize @bullet
44958 @item
44959 One can fetch individual fields like in @samp{C}.
44960
44961 @smallexample
44962 (gdb) print $my_struct_reg.field3
44963 $1 = 42
44964 @end smallexample
44965
44966 @end itemize
44967
44968 @subsection Registers
44969 @cindex <reg>
44970
44971 Each register is represented as an element with this form:
44972
44973 @smallexample
44974 <reg name="@var{name}"
44975 bitsize="@var{size}"
44976 @r{[}regnum="@var{num}"@r{]}
44977 @r{[}save-restore="@var{save-restore}"@r{]}
44978 @r{[}type="@var{type}"@r{]}
44979 @r{[}group="@var{group}"@r{]}/>
44980 @end smallexample
44981
44982 @noindent
44983 The components are as follows:
44984
44985 @table @var
44986
44987 @item name
44988 The register's name; it must be unique within the target description.
44989
44990 @item bitsize
44991 The register's size, in bits.
44992
44993 @item regnum
44994 The register's number. If omitted, a register's number is one greater
44995 than that of the previous register (either in the current feature or in
44996 a preceding feature); the first register in the target description
44997 defaults to zero. This register number is used to read or write
44998 the register; e.g.@: it is used in the remote @code{p} and @code{P}
44999 packets, and registers appear in the @code{g} and @code{G} packets
45000 in order of increasing register number.
45001
45002 @item save-restore
45003 Whether the register should be preserved across inferior function
45004 calls; this must be either @code{yes} or @code{no}. The default is
45005 @code{yes}, which is appropriate for most registers except for
45006 some system control registers; this is not related to the target's
45007 ABI.
45008
45009 @item type
45010 The type of the register. It may be a predefined type, a type
45011 defined in the current feature, or one of the special types @code{int}
45012 and @code{float}. @code{int} is an integer type of the correct size
45013 for @var{bitsize}, and @code{float} is a floating point type (in the
45014 architecture's normal floating point format) of the correct size for
45015 @var{bitsize}. The default is @code{int}.
45016
45017 @item group
45018 The register group to which this register belongs. It can be one of the
45019 standard register groups @code{general}, @code{float}, @code{vector} or an
45020 arbitrary string. Group names should be limited to alphanumeric characters.
45021 If a group name is made up of multiple words the words may be separated by
45022 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45023 @var{group} is specified, @value{GDBN} will not display the register in
45024 @code{info registers}.
45025
45026 @end table
45027
45028 @node Predefined Target Types
45029 @section Predefined Target Types
45030 @cindex target descriptions, predefined types
45031
45032 Type definitions in the self-description can build up composite types
45033 from basic building blocks, but can not define fundamental types. Instead,
45034 standard identifiers are provided by @value{GDBN} for the fundamental
45035 types. The currently supported types are:
45036
45037 @table @code
45038
45039 @item bool
45040 Boolean type, occupying a single bit.
45041
45042 @item int8
45043 @itemx int16
45044 @itemx int24
45045 @itemx int32
45046 @itemx int64
45047 @itemx int128
45048 Signed integer types holding the specified number of bits.
45049
45050 @item uint8
45051 @itemx uint16
45052 @itemx uint24
45053 @itemx uint32
45054 @itemx uint64
45055 @itemx uint128
45056 Unsigned integer types holding the specified number of bits.
45057
45058 @item code_ptr
45059 @itemx data_ptr
45060 Pointers to unspecified code and data. The program counter and
45061 any dedicated return address register may be marked as code
45062 pointers; printing a code pointer converts it into a symbolic
45063 address. The stack pointer and any dedicated address registers
45064 may be marked as data pointers.
45065
45066 @item ieee_single
45067 Single precision IEEE floating point.
45068
45069 @item ieee_double
45070 Double precision IEEE floating point.
45071
45072 @item arm_fpa_ext
45073 The 12-byte extended precision format used by ARM FPA registers.
45074
45075 @item i387_ext
45076 The 10-byte extended precision format used by x87 registers.
45077
45078 @item i386_eflags
45079 32bit @sc{eflags} register used by x86.
45080
45081 @item i386_mxcsr
45082 32bit @sc{mxcsr} register used by x86.
45083
45084 @end table
45085
45086 @node Enum Target Types
45087 @section Enum Target Types
45088 @cindex target descriptions, enum types
45089
45090 Enum target types are useful in @samp{struct} and @samp{flags}
45091 register descriptions. @xref{Target Description Format}.
45092
45093 Enum types have a name, size and a list of name/value pairs.
45094
45095 @smallexample
45096 <enum id="@var{id}" size="@var{size}">
45097 <evalue name="@var{name}" value="@var{value}"/>
45098 @dots{}
45099 </enum>
45100 @end smallexample
45101
45102 Enums must be defined before they are used.
45103
45104 @smallexample
45105 <enum id="levels_type" size="4">
45106 <evalue name="low" value="0"/>
45107 <evalue name="high" value="1"/>
45108 </enum>
45109 <flags id="flags_type" size="4">
45110 <field name="X" start="0"/>
45111 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45112 </flags>
45113 <reg name="flags" bitsize="32" type="flags_type"/>
45114 @end smallexample
45115
45116 Given that description, a value of 3 for the @samp{flags} register
45117 would be printed as:
45118
45119 @smallexample
45120 (gdb) info register flags
45121 flags 0x3 [ X LEVEL=high ]
45122 @end smallexample
45123
45124 @node Standard Target Features
45125 @section Standard Target Features
45126 @cindex target descriptions, standard features
45127
45128 A target description must contain either no registers or all the
45129 target's registers. If the description contains no registers, then
45130 @value{GDBN} will assume a default register layout, selected based on
45131 the architecture. If the description contains any registers, the
45132 default layout will not be used; the standard registers must be
45133 described in the target description, in such a way that @value{GDBN}
45134 can recognize them.
45135
45136 This is accomplished by giving specific names to feature elements
45137 which contain standard registers. @value{GDBN} will look for features
45138 with those names and verify that they contain the expected registers;
45139 if any known feature is missing required registers, or if any required
45140 feature is missing, @value{GDBN} will reject the target
45141 description. You can add additional registers to any of the
45142 standard features --- @value{GDBN} will display them just as if
45143 they were added to an unrecognized feature.
45144
45145 This section lists the known features and their expected contents.
45146 Sample XML documents for these features are included in the
45147 @value{GDBN} source tree, in the directory @file{gdb/features}.
45148
45149 Names recognized by @value{GDBN} should include the name of the
45150 company or organization which selected the name, and the overall
45151 architecture to which the feature applies; so e.g.@: the feature
45152 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45153
45154 The names of registers are not case sensitive for the purpose
45155 of recognizing standard features, but @value{GDBN} will only display
45156 registers using the capitalization used in the description.
45157
45158 @menu
45159 * AArch64 Features::
45160 * ARC Features::
45161 * ARM Features::
45162 * i386 Features::
45163 * MicroBlaze Features::
45164 * MIPS Features::
45165 * M68K Features::
45166 * NDS32 Features::
45167 * Nios II Features::
45168 * OpenRISC 1000 Features::
45169 * PowerPC Features::
45170 * RISC-V Features::
45171 * RX Features::
45172 * S/390 and System z Features::
45173 * Sparc Features::
45174 * TIC6x Features::
45175 @end menu
45176
45177
45178 @node AArch64 Features
45179 @subsection AArch64 Features
45180 @cindex target descriptions, AArch64 features
45181
45182 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45183 targets. It should contain registers @samp{x0} through @samp{x30},
45184 @samp{sp}, @samp{pc}, and @samp{cpsr}.
45185
45186 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45187 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45188 and @samp{fpcr}.
45189
45190 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45191 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45192 through @samp{p15}, @samp{ffr} and @samp{vg}.
45193
45194 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45195 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45196
45197 @node ARC Features
45198 @subsection ARC Features
45199 @cindex target descriptions, ARC Features
45200
45201 ARC processors are highly configurable, so even core registers and their number
45202 are not completely predetermined. In addition flags and PC registers which are
45203 important to @value{GDBN} are not ``core'' registers in ARC. It is required
45204 that one of the core registers features is present.
45205 @samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
45206
45207 The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
45208 targets with a normal register file. It should contain registers @samp{r0}
45209 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45210 @samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
45211 and any of extension core registers @samp{r32} through @samp{r59/acch}.
45212 @samp{ilink} and extension core registers are not available to read/write, when
45213 debugging GNU/Linux applications, thus @samp{ilink} is made optional.
45214
45215 The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
45216 ARC HS targets with a reduced register file. It should contain registers
45217 @samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
45218 @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
45219 This feature may contain register @samp{ilink} and any of extension core
45220 registers @samp{r32} through @samp{r59/acch}.
45221
45222 The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
45223 targets with a normal register file. It should contain registers @samp{r0}
45224 through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45225 @samp{lp_count} and @samp{pcl}. This feature may contain registers
45226 @samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45227 through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45228 registers are not available when debugging GNU/Linux applications. The only
45229 difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45230 @samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45231 ARC v2, but @samp{ilink2} is optional on ARCompact.
45232
45233 The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45234 targets. It should contain registers @samp{pc} and @samp{status32}.
45235
45236 @node ARM Features
45237 @subsection ARM Features
45238 @cindex target descriptions, ARM features
45239
45240 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45241 ARM targets.
45242 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45243 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45244
45245 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45246 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45247 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45248 and @samp{xpsr}.
45249
45250 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45251 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45252
45253 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45254 it should contain at least registers @samp{wR0} through @samp{wR15} and
45255 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45256 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45257
45258 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45259 should contain at least registers @samp{d0} through @samp{d15}. If
45260 they are present, @samp{d16} through @samp{d31} should also be included.
45261 @value{GDBN} will synthesize the single-precision registers from
45262 halves of the double-precision registers.
45263
45264 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45265 need to contain registers; it instructs @value{GDBN} to display the
45266 VFP double-precision registers as vectors and to synthesize the
45267 quad-precision registers from pairs of double-precision registers.
45268 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45269 be present and include 32 double-precision registers.
45270
45271 @node i386 Features
45272 @subsection i386 Features
45273 @cindex target descriptions, i386 features
45274
45275 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45276 targets. It should describe the following registers:
45277
45278 @itemize @minus
45279 @item
45280 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45281 @item
45282 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45283 @item
45284 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45285 @samp{fs}, @samp{gs}
45286 @item
45287 @samp{st0} through @samp{st7}
45288 @item
45289 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45290 @samp{foseg}, @samp{fooff} and @samp{fop}
45291 @end itemize
45292
45293 The register sets may be different, depending on the target.
45294
45295 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45296 describe registers:
45297
45298 @itemize @minus
45299 @item
45300 @samp{xmm0} through @samp{xmm7} for i386
45301 @item
45302 @samp{xmm0} through @samp{xmm15} for amd64
45303 @item
45304 @samp{mxcsr}
45305 @end itemize
45306
45307 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45308 @samp{org.gnu.gdb.i386.sse} feature. It should
45309 describe the upper 128 bits of @sc{ymm} registers:
45310
45311 @itemize @minus
45312 @item
45313 @samp{ymm0h} through @samp{ymm7h} for i386
45314 @item
45315 @samp{ymm0h} through @samp{ymm15h} for amd64
45316 @end itemize
45317
45318 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
45319 Memory Protection Extension (MPX). It should describe the following registers:
45320
45321 @itemize @minus
45322 @item
45323 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45324 @item
45325 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45326 @end itemize
45327
45328 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45329 describe a single register, @samp{orig_eax}.
45330
45331 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45332 describe two system registers: @samp{fs_base} and @samp{gs_base}.
45333
45334 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45335 @samp{org.gnu.gdb.i386.avx} feature. It should
45336 describe additional @sc{xmm} registers:
45337
45338 @itemize @minus
45339 @item
45340 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45341 @end itemize
45342
45343 It should describe the upper 128 bits of additional @sc{ymm} registers:
45344
45345 @itemize @minus
45346 @item
45347 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45348 @end itemize
45349
45350 It should
45351 describe the upper 256 bits of @sc{zmm} registers:
45352
45353 @itemize @minus
45354 @item
45355 @samp{zmm0h} through @samp{zmm7h} for i386.
45356 @item
45357 @samp{zmm0h} through @samp{zmm15h} for amd64.
45358 @end itemize
45359
45360 It should
45361 describe the additional @sc{zmm} registers:
45362
45363 @itemize @minus
45364 @item
45365 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45366 @end itemize
45367
45368 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45369 describe a single register, @samp{pkru}. It is a 32-bit register
45370 valid for i386 and amd64.
45371
45372 @node MicroBlaze Features
45373 @subsection MicroBlaze Features
45374 @cindex target descriptions, MicroBlaze features
45375
45376 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45377 targets. It should contain registers @samp{r0} through @samp{r31},
45378 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45379 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45380 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45381
45382 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45383 If present, it should contain registers @samp{rshr} and @samp{rslr}
45384
45385 @node MIPS Features
45386 @subsection @acronym{MIPS} Features
45387 @cindex target descriptions, @acronym{MIPS} features
45388
45389 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
45390 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45391 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45392 on the target.
45393
45394 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45395 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45396 registers. They may be 32-bit or 64-bit depending on the target.
45397
45398 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45399 it may be optional in a future version of @value{GDBN}. It should
45400 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45401 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
45402
45403 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45404 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45405 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45406 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45407
45408 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45409 contain a single register, @samp{restart}, which is used by the
45410 Linux kernel to control restartable syscalls.
45411
45412 @node M68K Features
45413 @subsection M68K Features
45414 @cindex target descriptions, M68K features
45415
45416 @table @code
45417 @item @samp{org.gnu.gdb.m68k.core}
45418 @itemx @samp{org.gnu.gdb.coldfire.core}
45419 @itemx @samp{org.gnu.gdb.fido.core}
45420 One of those features must be always present.
45421 The feature that is present determines which flavor of m68k is
45422 used. The feature that is present should contain registers
45423 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45424 @samp{sp}, @samp{ps} and @samp{pc}.
45425
45426 @item @samp{org.gnu.gdb.coldfire.fp}
45427 This feature is optional. If present, it should contain registers
45428 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45429 @samp{fpiaddr}.
45430
45431 Note that, despite the fact that this feature's name says
45432 @samp{coldfire}, it is used to describe any floating point registers.
45433 The size of the registers must match the main m68k flavor; so, for
45434 example, if the primary feature is reported as @samp{coldfire}, then
45435 64-bit floating point registers are required.
45436 @end table
45437
45438 @node NDS32 Features
45439 @subsection NDS32 Features
45440 @cindex target descriptions, NDS32 features
45441
45442 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45443 targets. It should contain at least registers @samp{r0} through
45444 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45445 and @samp{pc}.
45446
45447 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45448 it should contain 64-bit double-precision floating-point registers
45449 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45450 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45451
45452 @emph{Note:} The first sixteen 64-bit double-precision floating-point
45453 registers are overlapped with the thirty-two 32-bit single-precision
45454 floating-point registers. The 32-bit single-precision registers, if
45455 not being listed explicitly, will be synthesized from halves of the
45456 overlapping 64-bit double-precision registers. Listing 32-bit
45457 single-precision registers explicitly is deprecated, and the
45458 support to it could be totally removed some day.
45459
45460 @node Nios II Features
45461 @subsection Nios II Features
45462 @cindex target descriptions, Nios II features
45463
45464 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45465 targets. It should contain the 32 core registers (@samp{zero},
45466 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45467 @samp{pc}, and the 16 control registers (@samp{status} through
45468 @samp{mpuacc}).
45469
45470 @node OpenRISC 1000 Features
45471 @subsection Openrisc 1000 Features
45472 @cindex target descriptions, OpenRISC 1000 features
45473
45474 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45475 targets. It should contain the 32 general purpose registers (@samp{r0}
45476 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45477
45478 @node PowerPC Features
45479 @subsection PowerPC Features
45480 @cindex target descriptions, PowerPC features
45481
45482 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45483 targets. It should contain registers @samp{r0} through @samp{r31},
45484 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45485 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
45486
45487 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45488 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45489
45490 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
45491 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45492 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45493 through @samp{v31} as aliases for the corresponding @samp{vrX}
45494 registers.
45495
45496 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
45497 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45498 combine these registers with the floating point registers (@samp{f0}
45499 through @samp{f31}) and the altivec registers (@samp{vr0} through
45500 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45501 @samp{vs63}, the set of vector-scalar registers for POWER7.
45502 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45503 @samp{org.gnu.gdb.power.altivec}.
45504
45505 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45506 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45507 @samp{spefscr}. SPE targets should provide 32-bit registers in
45508 @samp{org.gnu.gdb.power.core} and provide the upper halves in
45509 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45510 these to present registers @samp{ev0} through @samp{ev31} to the
45511 user.
45512
45513 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45514 contain the 64-bit register @samp{ppr}.
45515
45516 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45517 contain the 64-bit register @samp{dscr}.
45518
45519 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45520 contain the 64-bit register @samp{tar}.
45521
45522 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45523 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
45524 64-bit wide.
45525
45526 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45527 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45528 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45529 server PMU registers provided by @sc{gnu}/Linux.
45530
45531 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45532 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
45533 64-bit wide.
45534
45535 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45536 contain the checkpointed general-purpose registers @samp{cr0} through
45537 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
45538 @samp{cctr}. These registers may all be either 32-bit or 64-bit
45539 depending on the target. It should also contain the checkpointed
45540 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45541 wide.
45542
45543 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45544 contain the checkpointed 64-bit floating-point registers @samp{cf0}
45545 through @samp{cf31}, as well as the checkpointed 64-bit register
45546 @samp{cfpscr}.
45547
45548 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45549 should contain the checkpointed altivec registers @samp{cvr0} through
45550 @samp{cvr31}, all 128-bit wide. It should also contain the
45551 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45552 wide.
45553
45554 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45555 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45556 will combine these registers with the checkpointed floating point
45557 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45558 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45559 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45560 @samp{cvs63}. Therefore, this feature requires both
45561 @samp{org.gnu.gdb.power.htm.altivec} and
45562 @samp{org.gnu.gdb.power.htm.fpu}.
45563
45564 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45565 contain the 64-bit checkpointed register @samp{cppr}.
45566
45567 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45568 contain the 64-bit checkpointed register @samp{cdscr}.
45569
45570 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45571 contain the 64-bit checkpointed register @samp{ctar}.
45572
45573
45574 @node RISC-V Features
45575 @subsection RISC-V Features
45576 @cindex target descriptions, RISC-V Features
45577
45578 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45579 targets. It should contain the registers @samp{x0} through
45580 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45581 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45582 etc).
45583
45584 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45585 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45586 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45587 architectural register names, or the ABI names can be used.
45588
45589 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45590 it should contain registers that are not backed by real registers on
45591 the target, but are instead virtual, where the register value is
45592 derived from other target state. In many ways these are like
45593 @value{GDBN}s pseudo-registers, except implemented by the target.
45594 Currently the only register expected in this set is the one byte
45595 @samp{priv} register that contains the target's privilege level in the
45596 least significant two bits.
45597
45598 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45599 should contain all of the target's standard CSRs. Standard CSRs are
45600 those defined in the RISC-V specification documents. There is some
45601 overlap between this feature and the fpu feature; the @samp{fflags},
45602 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
45603 expectation is that these registers will be in the fpu feature if the
45604 target has floating point hardware, but can be moved into the csr
45605 feature if the target has the floating point control registers, but no
45606 other floating point hardware.
45607
45608 @node RX Features
45609 @subsection RX Features
45610 @cindex target descriptions, RX Features
45611
45612 The @samp{org.gnu.gdb.rx.core} feature is required for RX
45613 targets. It should contain the registers @samp{r0} through
45614 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45615 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45616
45617 @node S/390 and System z Features
45618 @subsection S/390 and System z Features
45619 @cindex target descriptions, S/390 features
45620 @cindex target descriptions, System z features
45621
45622 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45623 System z targets. It should contain the PSW and the 16 general
45624 registers. In particular, System z targets should provide the 64-bit
45625 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45626 S/390 targets should provide the 32-bit versions of these registers.
45627 A System z target that runs in 31-bit addressing mode should provide
45628 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45629 register's upper halves @samp{r0h} through @samp{r15h}, and their
45630 lower halves @samp{r0l} through @samp{r15l}.
45631
45632 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45633 contain the 64-bit registers @samp{f0} through @samp{f15}, and
45634 @samp{fpc}.
45635
45636 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45637 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45638
45639 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45640 contain the register @samp{orig_r2}, which is 64-bit wide on System z
45641 targets and 32-bit otherwise. In addition, the feature may contain
45642 the @samp{last_break} register, whose width depends on the addressing
45643 mode, as well as the @samp{system_call} register, which is always
45644 32-bit wide.
45645
45646 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45647 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45648 @samp{atia}, and @samp{tr0} through @samp{tr15}.
45649
45650 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
45651 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45652 combined by @value{GDBN} with the floating point registers @samp{f0}
45653 through @samp{f15} to present the 128-bit wide vector registers
45654 @samp{v0} through @samp{v15}. In addition, this feature should
45655 contain the 128-bit wide vector registers @samp{v16} through
45656 @samp{v31}.
45657
45658 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45659 the 64-bit wide guarded-storage-control registers @samp{gsd},
45660 @samp{gssm}, and @samp{gsepla}.
45661
45662 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45663 the 64-bit wide guarded-storage broadcast control registers
45664 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45665
45666 @node Sparc Features
45667 @subsection Sparc Features
45668 @cindex target descriptions, sparc32 features
45669 @cindex target descriptions, sparc64 features
45670 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45671 targets. It should describe the following registers:
45672
45673 @itemize @minus
45674 @item
45675 @samp{g0} through @samp{g7}
45676 @item
45677 @samp{o0} through @samp{o7}
45678 @item
45679 @samp{l0} through @samp{l7}
45680 @item
45681 @samp{i0} through @samp{i7}
45682 @end itemize
45683
45684 They may be 32-bit or 64-bit depending on the target.
45685
45686 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45687 targets. It should describe the following registers:
45688
45689 @itemize @minus
45690 @item
45691 @samp{f0} through @samp{f31}
45692 @item
45693 @samp{f32} through @samp{f62} for sparc64
45694 @end itemize
45695
45696 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45697 targets. It should describe the following registers:
45698
45699 @itemize @minus
45700 @item
45701 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45702 @samp{fsr}, and @samp{csr} for sparc32
45703 @item
45704 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45705 for sparc64
45706 @end itemize
45707
45708 @node TIC6x Features
45709 @subsection TMS320C6x Features
45710 @cindex target descriptions, TIC6x features
45711 @cindex target descriptions, TMS320C6x features
45712 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45713 targets. It should contain registers @samp{A0} through @samp{A15},
45714 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45715
45716 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45717 contain registers @samp{A16} through @samp{A31} and @samp{B16}
45718 through @samp{B31}.
45719
45720 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45721 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45722
45723 @node Operating System Information
45724 @appendix Operating System Information
45725 @cindex operating system information
45726
45727 @menu
45728 * Process list::
45729 @end menu
45730
45731 Users of @value{GDBN} often wish to obtain information about the state of
45732 the operating system running on the target---for example the list of
45733 processes, or the list of open files. This section describes the
45734 mechanism that makes it possible. This mechanism is similar to the
45735 target features mechanism (@pxref{Target Descriptions}), but focuses
45736 on a different aspect of target.
45737
45738 Operating system information is retrieved from the target via the
45739 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45740 read}). The object name in the request should be @samp{osdata}, and
45741 the @var{annex} identifies the data to be fetched.
45742
45743 @node Process list
45744 @appendixsection Process list
45745 @cindex operating system information, process list
45746
45747 When requesting the process list, the @var{annex} field in the
45748 @samp{qXfer} request should be @samp{processes}. The returned data is
45749 an XML document. The formal syntax of this document is defined in
45750 @file{gdb/features/osdata.dtd}.
45751
45752 An example document is:
45753
45754 @smallexample
45755 <?xml version="1.0"?>
45756 <!DOCTYPE target SYSTEM "osdata.dtd">
45757 <osdata type="processes">
45758 <item>
45759 <column name="pid">1</column>
45760 <column name="user">root</column>
45761 <column name="command">/sbin/init</column>
45762 <column name="cores">1,2,3</column>
45763 </item>
45764 </osdata>
45765 @end smallexample
45766
45767 Each item should include a column whose name is @samp{pid}. The value
45768 of that column should identify the process on the target. The
45769 @samp{user} and @samp{command} columns are optional, and will be
45770 displayed by @value{GDBN}. The @samp{cores} column, if present,
45771 should contain a comma-separated list of cores that this process
45772 is running on. Target may provide additional columns,
45773 which @value{GDBN} currently ignores.
45774
45775 @node Trace File Format
45776 @appendix Trace File Format
45777 @cindex trace file format
45778
45779 The trace file comes in three parts: a header, a textual description
45780 section, and a trace frame section with binary data.
45781
45782 The header has the form @code{\x7fTRACE0\n}. The first byte is
45783 @code{0x7f} so as to indicate that the file contains binary data,
45784 while the @code{0} is a version number that may have different values
45785 in the future.
45786
45787 The description section consists of multiple lines of @sc{ascii} text
45788 separated by newline characters (@code{0xa}). The lines may include a
45789 variety of optional descriptive or context-setting information, such
45790 as tracepoint definitions or register set size. @value{GDBN} will
45791 ignore any line that it does not recognize. An empty line marks the end
45792 of this section.
45793
45794 @table @code
45795 @item R @var{size}
45796 Specifies the size of a register block in bytes. This is equal to the
45797 size of a @code{g} packet payload in the remote protocol. @var{size}
45798 is an ascii decimal number. There should be only one such line in
45799 a single trace file.
45800
45801 @item status @var{status}
45802 Trace status. @var{status} has the same format as a @code{qTStatus}
45803 remote packet reply. There should be only one such line in a single trace
45804 file.
45805
45806 @item tp @var{payload}
45807 Tracepoint definition. The @var{payload} has the same format as
45808 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45809 may take multiple lines of definition, corresponding to the multiple
45810 reply packets.
45811
45812 @item tsv @var{payload}
45813 Trace state variable definition. The @var{payload} has the same format as
45814 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45815 may take multiple lines of definition, corresponding to the multiple
45816 reply packets.
45817
45818 @item tdesc @var{payload}
45819 Target description in XML format. The @var{payload} is a single line of
45820 the XML file. All such lines should be concatenated together to get
45821 the original XML file. This file is in the same format as @code{qXfer}
45822 @code{features} payload, and corresponds to the main @code{target.xml}
45823 file. Includes are not allowed.
45824
45825 @end table
45826
45827 The trace frame section consists of a number of consecutive frames.
45828 Each frame begins with a two-byte tracepoint number, followed by a
45829 four-byte size giving the amount of data in the frame. The data in
45830 the frame consists of a number of blocks, each introduced by a
45831 character indicating its type (at least register, memory, and trace
45832 state variable). The data in this section is raw binary, not a
45833 hexadecimal or other encoding; its endianness matches the target's
45834 endianness.
45835
45836 @c FIXME bi-arch may require endianness/arch info in description section
45837
45838 @table @code
45839 @item R @var{bytes}
45840 Register block. The number and ordering of bytes matches that of a
45841 @code{g} packet in the remote protocol. Note that these are the
45842 actual bytes, in target order, not a hexadecimal encoding.
45843
45844 @item M @var{address} @var{length} @var{bytes}...
45845 Memory block. This is a contiguous block of memory, at the 8-byte
45846 address @var{address}, with a 2-byte length @var{length}, followed by
45847 @var{length} bytes.
45848
45849 @item V @var{number} @var{value}
45850 Trace state variable block. This records the 8-byte signed value
45851 @var{value} of trace state variable numbered @var{number}.
45852
45853 @end table
45854
45855 Future enhancements of the trace file format may include additional types
45856 of blocks.
45857
45858 @node Index Section Format
45859 @appendix @code{.gdb_index} section format
45860 @cindex .gdb_index section format
45861 @cindex index section format
45862
45863 This section documents the index section that is created by @code{save
45864 gdb-index} (@pxref{Index Files}). The index section is
45865 DWARF-specific; some knowledge of DWARF is assumed in this
45866 description.
45867
45868 The mapped index file format is designed to be directly
45869 @code{mmap}able on any architecture. In most cases, a datum is
45870 represented using a little-endian 32-bit integer value, called an
45871 @code{offset_type}. Big endian machines must byte-swap the values
45872 before using them. Exceptions to this rule are noted. The data is
45873 laid out such that alignment is always respected.
45874
45875 A mapped index consists of several areas, laid out in order.
45876
45877 @enumerate
45878 @item
45879 The file header. This is a sequence of values, of @code{offset_type}
45880 unless otherwise noted:
45881
45882 @enumerate
45883 @item
45884 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
45885 Version 4 uses a different hashing function from versions 5 and 6.
45886 Version 6 includes symbols for inlined functions, whereas versions 4
45887 and 5 do not. Version 7 adds attributes to the CU indices in the
45888 symbol table. Version 8 specifies that symbols from DWARF type units
45889 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45890 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45891
45892 @value{GDBN} will only read version 4, 5, or 6 indices
45893 by specifying @code{set use-deprecated-index-sections on}.
45894 GDB has a workaround for potentially broken version 7 indices so it is
45895 currently not flagged as deprecated.
45896
45897 @item
45898 The offset, from the start of the file, of the CU list.
45899
45900 @item
45901 The offset, from the start of the file, of the types CU list. Note
45902 that this area can be empty, in which case this offset will be equal
45903 to the next offset.
45904
45905 @item
45906 The offset, from the start of the file, of the address area.
45907
45908 @item
45909 The offset, from the start of the file, of the symbol table.
45910
45911 @item
45912 The offset, from the start of the file, of the constant pool.
45913 @end enumerate
45914
45915 @item
45916 The CU list. This is a sequence of pairs of 64-bit little-endian
45917 values, sorted by the CU offset. The first element in each pair is
45918 the offset of a CU in the @code{.debug_info} section. The second
45919 element in each pair is the length of that CU. References to a CU
45920 elsewhere in the map are done using a CU index, which is just the
45921 0-based index into this table. Note that if there are type CUs, then
45922 conceptually CUs and type CUs form a single list for the purposes of
45923 CU indices.
45924
45925 @item
45926 The types CU list. This is a sequence of triplets of 64-bit
45927 little-endian values. In a triplet, the first value is the CU offset,
45928 the second value is the type offset in the CU, and the third value is
45929 the type signature. The types CU list is not sorted.
45930
45931 @item
45932 The address area. The address area consists of a sequence of address
45933 entries. Each address entry has three elements:
45934
45935 @enumerate
45936 @item
45937 The low address. This is a 64-bit little-endian value.
45938
45939 @item
45940 The high address. This is a 64-bit little-endian value. Like
45941 @code{DW_AT_high_pc}, the value is one byte beyond the end.
45942
45943 @item
45944 The CU index. This is an @code{offset_type} value.
45945 @end enumerate
45946
45947 @item
45948 The symbol table. This is an open-addressed hash table. The size of
45949 the hash table is always a power of 2.
45950
45951 Each slot in the hash table consists of a pair of @code{offset_type}
45952 values. The first value is the offset of the symbol's name in the
45953 constant pool. The second value is the offset of the CU vector in the
45954 constant pool.
45955
45956 If both values are 0, then this slot in the hash table is empty. This
45957 is ok because while 0 is a valid constant pool index, it cannot be a
45958 valid index for both a string and a CU vector.
45959
45960 The hash value for a table entry is computed by applying an
45961 iterative hash function to the symbol's name. Starting with an
45962 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
45963 the string is incorporated into the hash using the formula depending on the
45964 index version:
45965
45966 @table @asis
45967 @item Version 4
45968 The formula is @code{r = r * 67 + c - 113}.
45969
45970 @item Versions 5 to 7
45971 The formula is @code{r = r * 67 + tolower (c) - 113}.
45972 @end table
45973
45974 The terminating @samp{\0} is not incorporated into the hash.
45975
45976 The step size used in the hash table is computed via
45977 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45978 value, and @samp{size} is the size of the hash table. The step size
45979 is used to find the next candidate slot when handling a hash
45980 collision.
45981
45982 The names of C@t{++} symbols in the hash table are canonicalized. We
45983 don't currently have a simple description of the canonicalization
45984 algorithm; if you intend to create new index sections, you must read
45985 the code.
45986
45987 @item
45988 The constant pool. This is simply a bunch of bytes. It is organized
45989 so that alignment is correct: CU vectors are stored first, followed by
45990 strings.
45991
45992 A CU vector in the constant pool is a sequence of @code{offset_type}
45993 values. The first value is the number of CU indices in the vector.
45994 Each subsequent value is the index and symbol attributes of a CU in
45995 the CU list. This element in the hash table is used to indicate which
45996 CUs define the symbol and how the symbol is used.
45997 See below for the format of each CU index+attributes entry.
45998
45999 A string in the constant pool is zero-terminated.
46000 @end enumerate
46001
46002 Attributes were added to CU index values in @code{.gdb_index} version 7.
46003 If a symbol has multiple uses within a CU then there is one
46004 CU index+attributes value for each use.
46005
46006 The format of each CU index+attributes entry is as follows
46007 (bit 0 = LSB):
46008
46009 @table @asis
46010
46011 @item Bits 0-23
46012 This is the index of the CU in the CU list.
46013 @item Bits 24-27
46014 These bits are reserved for future purposes and must be zero.
46015 @item Bits 28-30
46016 The kind of the symbol in the CU.
46017
46018 @table @asis
46019 @item 0
46020 This value is reserved and should not be used.
46021 By reserving zero the full @code{offset_type} value is backwards compatible
46022 with previous versions of the index.
46023 @item 1
46024 The symbol is a type.
46025 @item 2
46026 The symbol is a variable or an enum value.
46027 @item 3
46028 The symbol is a function.
46029 @item 4
46030 Any other kind of symbol.
46031 @item 5,6,7
46032 These values are reserved.
46033 @end table
46034
46035 @item Bit 31
46036 This bit is zero if the value is global and one if it is static.
46037
46038 The determination of whether a symbol is global or static is complicated.
46039 The authorative reference is the file @file{dwarf2read.c} in
46040 @value{GDBN} sources.
46041
46042 @end table
46043
46044 This pseudo-code describes the computation of a symbol's kind and
46045 global/static attributes in the index.
46046
46047 @smallexample
46048 is_external = get_attribute (die, DW_AT_external);
46049 language = get_attribute (cu_die, DW_AT_language);
46050 switch (die->tag)
46051 @{
46052 case DW_TAG_typedef:
46053 case DW_TAG_base_type:
46054 case DW_TAG_subrange_type:
46055 kind = TYPE;
46056 is_static = 1;
46057 break;
46058 case DW_TAG_enumerator:
46059 kind = VARIABLE;
46060 is_static = language != CPLUS;
46061 break;
46062 case DW_TAG_subprogram:
46063 kind = FUNCTION;
46064 is_static = ! (is_external || language == ADA);
46065 break;
46066 case DW_TAG_constant:
46067 kind = VARIABLE;
46068 is_static = ! is_external;
46069 break;
46070 case DW_TAG_variable:
46071 kind = VARIABLE;
46072 is_static = ! is_external;
46073 break;
46074 case DW_TAG_namespace:
46075 kind = TYPE;
46076 is_static = 0;
46077 break;
46078 case DW_TAG_class_type:
46079 case DW_TAG_interface_type:
46080 case DW_TAG_structure_type:
46081 case DW_TAG_union_type:
46082 case DW_TAG_enumeration_type:
46083 kind = TYPE;
46084 is_static = language != CPLUS;
46085 break;
46086 default:
46087 assert (0);
46088 @}
46089 @end smallexample
46090
46091 @node Man Pages
46092 @appendix Manual pages
46093 @cindex Man pages
46094
46095 @menu
46096 * gdb man:: The GNU Debugger man page
46097 * gdbserver man:: Remote Server for the GNU Debugger man page
46098 * gcore man:: Generate a core file of a running program
46099 * gdbinit man:: gdbinit scripts
46100 * gdb-add-index man:: Add index files to speed up GDB
46101 @end menu
46102
46103 @node gdb man
46104 @heading gdb man
46105
46106 @c man title gdb The GNU Debugger
46107
46108 @c man begin SYNOPSIS gdb
46109 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46110 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46111 [@option{-b}@w{ }@var{bps}]
46112 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46113 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46114 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46115 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46116 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46117 @c man end
46118
46119 @c man begin DESCRIPTION gdb
46120 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46121 going on ``inside'' another program while it executes -- or what another
46122 program was doing at the moment it crashed.
46123
46124 @value{GDBN} can do four main kinds of things (plus other things in support of
46125 these) to help you catch bugs in the act:
46126
46127 @itemize @bullet
46128 @item
46129 Start your program, specifying anything that might affect its behavior.
46130
46131 @item
46132 Make your program stop on specified conditions.
46133
46134 @item
46135 Examine what has happened, when your program has stopped.
46136
46137 @item
46138 Change things in your program, so you can experiment with correcting the
46139 effects of one bug and go on to learn about another.
46140 @end itemize
46141
46142 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46143 Modula-2.
46144
46145 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46146 commands from the terminal until you tell it to exit with the @value{GDBN}
46147 command @code{quit}. You can get online help from @value{GDBN} itself
46148 by using the command @code{help}.
46149
46150 You can run @code{gdb} with no arguments or options; but the most
46151 usual way to start @value{GDBN} is with one argument or two, specifying an
46152 executable program as the argument:
46153
46154 @smallexample
46155 gdb program
46156 @end smallexample
46157
46158 You can also start with both an executable program and a core file specified:
46159
46160 @smallexample
46161 gdb program core
46162 @end smallexample
46163
46164 You can, instead, specify a process ID as a second argument or use option
46165 @code{-p}, if you want to debug a running process:
46166
46167 @smallexample
46168 gdb program 1234
46169 gdb -p 1234
46170 @end smallexample
46171
46172 @noindent
46173 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46174 can omit the @var{program} filename.
46175
46176 Here are some of the most frequently needed @value{GDBN} commands:
46177
46178 @c pod2man highlights the right hand side of the @item lines.
46179 @table @env
46180 @item break [@var{file}:]@var{function}
46181 Set a breakpoint at @var{function} (in @var{file}).
46182
46183 @item run [@var{arglist}]
46184 Start your program (with @var{arglist}, if specified).
46185
46186 @item bt
46187 Backtrace: display the program stack.
46188
46189 @item print @var{expr}
46190 Display the value of an expression.
46191
46192 @item c
46193 Continue running your program (after stopping, e.g. at a breakpoint).
46194
46195 @item next
46196 Execute next program line (after stopping); step @emph{over} any
46197 function calls in the line.
46198
46199 @item edit [@var{file}:]@var{function}
46200 look at the program line where it is presently stopped.
46201
46202 @item list [@var{file}:]@var{function}
46203 type the text of the program in the vicinity of where it is presently stopped.
46204
46205 @item step
46206 Execute next program line (after stopping); step @emph{into} any
46207 function calls in the line.
46208
46209 @item help [@var{name}]
46210 Show information about @value{GDBN} command @var{name}, or general information
46211 about using @value{GDBN}.
46212
46213 @item quit
46214 Exit from @value{GDBN}.
46215 @end table
46216
46217 @ifset man
46218 For full details on @value{GDBN},
46219 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46220 by Richard M. Stallman and Roland H. Pesch. The same text is available online
46221 as the @code{gdb} entry in the @code{info} program.
46222 @end ifset
46223 @c man end
46224
46225 @c man begin OPTIONS gdb
46226 Any arguments other than options specify an executable
46227 file and core file (or process ID); that is, the first argument
46228 encountered with no
46229 associated option flag is equivalent to a @option{-se} option, and the second,
46230 if any, is equivalent to a @option{-c} option if it's the name of a file.
46231 Many options have
46232 both long and short forms; both are shown here. The long forms are also
46233 recognized if you truncate them, so long as enough of the option is
46234 present to be unambiguous. (If you prefer, you can flag option
46235 arguments with @option{+} rather than @option{-}, though we illustrate the
46236 more usual convention.)
46237
46238 All the options and command line arguments you give are processed
46239 in sequential order. The order makes a difference when the @option{-x}
46240 option is used.
46241
46242 @table @env
46243 @item -help
46244 @itemx -h
46245 List all options, with brief explanations.
46246
46247 @item -symbols=@var{file}
46248 @itemx -s @var{file}
46249 Read symbol table from file @var{file}.
46250
46251 @item -write
46252 Enable writing into executable and core files.
46253
46254 @item -exec=@var{file}
46255 @itemx -e @var{file}
46256 Use file @var{file} as the executable file to execute when
46257 appropriate, and for examining pure data in conjunction with a core
46258 dump.
46259
46260 @item -se=@var{file}
46261 Read symbol table from file @var{file} and use it as the executable
46262 file.
46263
46264 @item -core=@var{file}
46265 @itemx -c @var{file}
46266 Use file @var{file} as a core dump to examine.
46267
46268 @item -command=@var{file}
46269 @itemx -x @var{file}
46270 Execute @value{GDBN} commands from file @var{file}.
46271
46272 @item -ex @var{command}
46273 Execute given @value{GDBN} @var{command}.
46274
46275 @item -directory=@var{directory}
46276 @itemx -d @var{directory}
46277 Add @var{directory} to the path to search for source files.
46278
46279 @item -nh
46280 Do not execute commands from @file{~/.gdbinit}.
46281
46282 @item -nx
46283 @itemx -n
46284 Do not execute commands from any @file{.gdbinit} initialization files.
46285
46286 @item -quiet
46287 @itemx -q
46288 ``Quiet''. Do not print the introductory and copyright messages. These
46289 messages are also suppressed in batch mode.
46290
46291 @item -batch
46292 Run in batch mode. Exit with status @code{0} after processing all the command
46293 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46294 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46295 commands in the command files.
46296
46297 Batch mode may be useful for running @value{GDBN} as a filter, for example to
46298 download and run a program on another computer; in order to make this
46299 more useful, the message
46300
46301 @smallexample
46302 Program exited normally.
46303 @end smallexample
46304
46305 @noindent
46306 (which is ordinarily issued whenever a program running under @value{GDBN} control
46307 terminates) is not issued when running in batch mode.
46308
46309 @item -cd=@var{directory}
46310 Run @value{GDBN} using @var{directory} as its working directory,
46311 instead of the current directory.
46312
46313 @item -fullname
46314 @itemx -f
46315 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46316 @value{GDBN} to output the full file name and line number in a standard,
46317 recognizable fashion each time a stack frame is displayed (which
46318 includes each time the program stops). This recognizable format looks
46319 like two @samp{\032} characters, followed by the file name, line number
46320 and character position separated by colons, and a newline. The
46321 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46322 characters as a signal to display the source code for the frame.
46323
46324 @item -b @var{bps}
46325 Set the line speed (baud rate or bits per second) of any serial
46326 interface used by @value{GDBN} for remote debugging.
46327
46328 @item -tty=@var{device}
46329 Run using @var{device} for your program's standard input and output.
46330 @end table
46331 @c man end
46332
46333 @c man begin SEEALSO gdb
46334 @ifset man
46335 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46336 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46337 documentation are properly installed at your site, the command
46338
46339 @smallexample
46340 info gdb
46341 @end smallexample
46342
46343 @noindent
46344 should give you access to the complete manual.
46345
46346 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46347 Richard M. Stallman and Roland H. Pesch, July 1991.
46348 @end ifset
46349 @c man end
46350
46351 @node gdbserver man
46352 @heading gdbserver man
46353
46354 @c man title gdbserver Remote Server for the GNU Debugger
46355 @format
46356 @c man begin SYNOPSIS gdbserver
46357 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46358
46359 gdbserver --attach @var{comm} @var{pid}
46360
46361 gdbserver --multi @var{comm}
46362 @c man end
46363 @end format
46364
46365 @c man begin DESCRIPTION gdbserver
46366 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46367 than the one which is running the program being debugged.
46368
46369 @ifclear man
46370 @subheading Usage (server (target) side)
46371 @end ifclear
46372 @ifset man
46373 Usage (server (target) side):
46374 @end ifset
46375
46376 First, you need to have a copy of the program you want to debug put onto
46377 the target system. The program can be stripped to save space if needed, as
46378 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46379 the @value{GDBN} running on the host system.
46380
46381 To use the server, you log on to the target system, and run the @command{gdbserver}
46382 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46383 your program, and (c) its arguments. The general syntax is:
46384
46385 @smallexample
46386 target> gdbserver @var{comm} @var{program} [@var{args} ...]
46387 @end smallexample
46388
46389 For example, using a serial port, you might say:
46390
46391 @smallexample
46392 @ifset man
46393 @c @file would wrap it as F</dev/com1>.
46394 target> gdbserver /dev/com1 emacs foo.txt
46395 @end ifset
46396 @ifclear man
46397 target> gdbserver @file{/dev/com1} emacs foo.txt
46398 @end ifclear
46399 @end smallexample
46400
46401 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46402 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46403 waits patiently for the host @value{GDBN} to communicate with it.
46404
46405 To use a TCP connection, you could say:
46406
46407 @smallexample
46408 target> gdbserver host:2345 emacs foo.txt
46409 @end smallexample
46410
46411 This says pretty much the same thing as the last example, except that we are
46412 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46413 that we are expecting to see a TCP connection from @code{host} to local TCP port
46414 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
46415 want for the port number as long as it does not conflict with any existing TCP
46416 ports on the target system. This same port number must be used in the host
46417 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46418 you chose a port number that conflicts with another service, @command{gdbserver} will
46419 print an error message and exit.
46420
46421 @command{gdbserver} can also attach to running programs.
46422 This is accomplished via the @option{--attach} argument. The syntax is:
46423
46424 @smallexample
46425 target> gdbserver --attach @var{comm} @var{pid}
46426 @end smallexample
46427
46428 @var{pid} is the process ID of a currently running process. It isn't
46429 necessary to point @command{gdbserver} at a binary for the running process.
46430
46431 To start @code{gdbserver} without supplying an initial command to run
46432 or process ID to attach, use the @option{--multi} command line option.
46433 In such case you should connect using @kbd{target extended-remote} to start
46434 the program you want to debug.
46435
46436 @smallexample
46437 target> gdbserver --multi @var{comm}
46438 @end smallexample
46439
46440 @ifclear man
46441 @subheading Usage (host side)
46442 @end ifclear
46443 @ifset man
46444 Usage (host side):
46445 @end ifset
46446
46447 You need an unstripped copy of the target program on your host system, since
46448 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
46449 would, with the target program as the first argument. (You may need to use the
46450 @option{--baud} option if the serial line is running at anything except 9600 baud.)
46451 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
46452 new command you need to know about is @code{target remote}
46453 (or @code{target extended-remote}). Its argument is either
46454 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46455 descriptor. For example:
46456
46457 @smallexample
46458 @ifset man
46459 @c @file would wrap it as F</dev/ttyb>.
46460 (gdb) target remote /dev/ttyb
46461 @end ifset
46462 @ifclear man
46463 (gdb) target remote @file{/dev/ttyb}
46464 @end ifclear
46465 @end smallexample
46466
46467 @noindent
46468 communicates with the server via serial line @file{/dev/ttyb}, and:
46469
46470 @smallexample
46471 (gdb) target remote the-target:2345
46472 @end smallexample
46473
46474 @noindent
46475 communicates via a TCP connection to port 2345 on host `the-target', where
46476 you previously started up @command{gdbserver} with the same port number. Note that for
46477 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46478 command, otherwise you may get an error that looks something like
46479 `Connection refused'.
46480
46481 @command{gdbserver} can also debug multiple inferiors at once,
46482 described in
46483 @ifset man
46484 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46485 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
46486 @end ifset
46487 @ifclear man
46488 @ref{Inferiors Connections and Programs}.
46489 @end ifclear
46490 In such case use the @code{extended-remote} @value{GDBN} command variant:
46491
46492 @smallexample
46493 (gdb) target extended-remote the-target:2345
46494 @end smallexample
46495
46496 The @command{gdbserver} option @option{--multi} may or may not be used in such
46497 case.
46498 @c man end
46499
46500 @c man begin OPTIONS gdbserver
46501 There are three different modes for invoking @command{gdbserver}:
46502
46503 @itemize @bullet
46504
46505 @item
46506 Debug a specific program specified by its program name:
46507
46508 @smallexample
46509 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46510 @end smallexample
46511
46512 The @var{comm} parameter specifies how should the server communicate
46513 with @value{GDBN}; it is either a device name (to use a serial line),
46514 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46515 stdin/stdout of @code{gdbserver}. Specify the name of the program to
46516 debug in @var{prog}. Any remaining arguments will be passed to the
46517 program verbatim. When the program exits, @value{GDBN} will close the
46518 connection, and @code{gdbserver} will exit.
46519
46520 @item
46521 Debug a specific program by specifying the process ID of a running
46522 program:
46523
46524 @smallexample
46525 gdbserver --attach @var{comm} @var{pid}
46526 @end smallexample
46527
46528 The @var{comm} parameter is as described above. Supply the process ID
46529 of a running program in @var{pid}; @value{GDBN} will do everything
46530 else. Like with the previous mode, when the process @var{pid} exits,
46531 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
46532
46533 @item
46534 Multi-process mode -- debug more than one program/process:
46535
46536 @smallexample
46537 gdbserver --multi @var{comm}
46538 @end smallexample
46539
46540 In this mode, @value{GDBN} can instruct @command{gdbserver} which
46541 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46542 close the connection when a process being debugged exits, so you can
46543 debug several processes in the same session.
46544 @end itemize
46545
46546 In each of the modes you may specify these options:
46547
46548 @table @env
46549
46550 @item --help
46551 List all options, with brief explanations.
46552
46553 @item --version
46554 This option causes @command{gdbserver} to print its version number and exit.
46555
46556 @item --attach
46557 @command{gdbserver} will attach to a running program. The syntax is:
46558
46559 @smallexample
46560 target> gdbserver --attach @var{comm} @var{pid}
46561 @end smallexample
46562
46563 @var{pid} is the process ID of a currently running process. It isn't
46564 necessary to point @command{gdbserver} at a binary for the running process.
46565
46566 @item --multi
46567 To start @code{gdbserver} without supplying an initial command to run
46568 or process ID to attach, use this command line option.
46569 Then you can connect using @kbd{target extended-remote} and start
46570 the program you want to debug. The syntax is:
46571
46572 @smallexample
46573 target> gdbserver --multi @var{comm}
46574 @end smallexample
46575
46576 @item --debug
46577 Instruct @code{gdbserver} to display extra status information about the debugging
46578 process.
46579 This option is intended for @code{gdbserver} development and for bug reports to
46580 the developers.
46581
46582 @item --remote-debug
46583 Instruct @code{gdbserver} to display remote protocol debug output.
46584 This option is intended for @code{gdbserver} development and for bug reports to
46585 the developers.
46586
46587 @item --debug-file=@var{filename}
46588 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46589 This option is intended for @code{gdbserver} development and for bug reports to
46590 the developers.
46591
46592 @item --debug-format=option1@r{[},option2,...@r{]}
46593 Instruct @code{gdbserver} to include extra information in each line
46594 of debugging output.
46595 @xref{Other Command-Line Arguments for gdbserver}.
46596
46597 @item --wrapper
46598 Specify a wrapper to launch programs
46599 for debugging. The option should be followed by the name of the
46600 wrapper, then any command-line arguments to pass to the wrapper, then
46601 @kbd{--} indicating the end of the wrapper arguments.
46602
46603 @item --once
46604 By default, @command{gdbserver} keeps the listening TCP port open, so that
46605 additional connections are possible. However, if you start @code{gdbserver}
46606 with the @option{--once} option, it will stop listening for any further
46607 connection attempts after connecting to the first @value{GDBN} session.
46608
46609 @c --disable-packet is not documented for users.
46610
46611 @c --disable-randomization and --no-disable-randomization are superseded by
46612 @c QDisableRandomization.
46613
46614 @end table
46615 @c man end
46616
46617 @c man begin SEEALSO gdbserver
46618 @ifset man
46619 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46620 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46621 documentation are properly installed at your site, the command
46622
46623 @smallexample
46624 info gdb
46625 @end smallexample
46626
46627 should give you access to the complete manual.
46628
46629 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46630 Richard M. Stallman and Roland H. Pesch, July 1991.
46631 @end ifset
46632 @c man end
46633
46634 @node gcore man
46635 @heading gcore
46636
46637 @c man title gcore Generate a core file of a running program
46638
46639 @format
46640 @c man begin SYNOPSIS gcore
46641 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
46642 @c man end
46643 @end format
46644
46645 @c man begin DESCRIPTION gcore
46646 Generate core dumps of one or more running programs with process IDs
46647 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46648 is equivalent to one produced by the kernel when the process crashes
46649 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
46650 limit). However, unlike after a crash, after @command{gcore} finishes
46651 its job the program remains running without any change.
46652 @c man end
46653
46654 @c man begin OPTIONS gcore
46655 @table @env
46656 @item -a
46657 Dump all memory mappings. The actual effect of this option depends on
46658 the Operating System. On @sc{gnu}/Linux, it will disable
46659 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46660 enable @code{dump-excluded-mappings} (@pxref{set
46661 dump-excluded-mappings}).
46662
46663 @item -o @var{prefix}
46664 The optional argument @var{prefix} specifies the prefix to be used
46665 when composing the file names of the core dumps. The file name is
46666 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46667 process ID of the running program being analyzed by @command{gcore}.
46668 If not specified, @var{prefix} defaults to @var{gcore}.
46669 @end table
46670 @c man end
46671
46672 @c man begin SEEALSO gcore
46673 @ifset man
46674 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46675 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46676 documentation are properly installed at your site, the command
46677
46678 @smallexample
46679 info gdb
46680 @end smallexample
46681
46682 @noindent
46683 should give you access to the complete manual.
46684
46685 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46686 Richard M. Stallman and Roland H. Pesch, July 1991.
46687 @end ifset
46688 @c man end
46689
46690 @node gdbinit man
46691 @heading gdbinit
46692
46693 @c man title gdbinit GDB initialization scripts
46694
46695 @format
46696 @c man begin SYNOPSIS gdbinit
46697 @ifset SYSTEM_GDBINIT
46698 @value{SYSTEM_GDBINIT}
46699 @end ifset
46700
46701 @ifset SYSTEM_GDBINIT_DIR
46702 @value{SYSTEM_GDBINIT_DIR}/*
46703 @end ifset
46704
46705 ~/.gdbinit
46706
46707 ./.gdbinit
46708 @c man end
46709 @end format
46710
46711 @c man begin DESCRIPTION gdbinit
46712 These files contain @value{GDBN} commands to automatically execute during
46713 @value{GDBN} startup. The lines of contents are canned sequences of commands,
46714 described in
46715 @ifset man
46716 the @value{GDBN} manual in node @code{Sequences}
46717 -- shell command @code{info -f gdb -n Sequences}.
46718 @end ifset
46719 @ifclear man
46720 @ref{Sequences}.
46721 @end ifclear
46722
46723 Please read more in
46724 @ifset man
46725 the @value{GDBN} manual in node @code{Startup}
46726 -- shell command @code{info -f gdb -n Startup}.
46727 @end ifset
46728 @ifclear man
46729 @ref{Startup}.
46730 @end ifclear
46731
46732 @table @env
46733 @ifset SYSTEM_GDBINIT
46734 @item @value{SYSTEM_GDBINIT}
46735 @end ifset
46736 @ifclear SYSTEM_GDBINIT
46737 @item (not enabled with @code{--with-system-gdbinit} during compilation)
46738 @end ifclear
46739 System-wide initialization file. It is executed unless user specified
46740 @value{GDBN} option @code{-nx} or @code{-n}.
46741 See more in
46742 @ifset man
46743 the @value{GDBN} manual in node @code{System-wide configuration}
46744 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46745 @end ifset
46746 @ifset SYSTEM_GDBINIT_DIR
46747 @item @value{SYSTEM_GDBINIT_DIR}
46748 @end ifset
46749 @ifclear SYSTEM_GDBINIT_DIR
46750 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46751 @end ifclear
46752 System-wide initialization directory. All files in this directory are
46753 executed on startup unless user specified @value{GDBN} option @code{-nx} or
46754 @code{-n}, as long as they have a recognized file extension.
46755 See more in
46756 @ifset man
46757 the @value{GDBN} manual in node @code{System-wide configuration}
46758 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
46759 @end ifset
46760 @ifclear man
46761 @ref{System-wide configuration}.
46762 @end ifclear
46763
46764 @item ~/.gdbinit
46765 User initialization file. It is executed unless user specified
46766 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46767
46768 @item ./.gdbinit
46769 Initialization file for current directory. It may need to be enabled with
46770 @value{GDBN} security command @code{set auto-load local-gdbinit}.
46771 See more in
46772 @ifset man
46773 the @value{GDBN} manual in node @code{Init File in the Current Directory}
46774 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46775 @end ifset
46776 @ifclear man
46777 @ref{Init File in the Current Directory}.
46778 @end ifclear
46779 @end table
46780 @c man end
46781
46782 @c man begin SEEALSO gdbinit
46783 @ifset man
46784 gdb(1), @code{info -f gdb -n Startup}
46785
46786 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46787 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46788 documentation are properly installed at your site, the command
46789
46790 @smallexample
46791 info gdb
46792 @end smallexample
46793
46794 should give you access to the complete manual.
46795
46796 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46797 Richard M. Stallman and Roland H. Pesch, July 1991.
46798 @end ifset
46799 @c man end
46800
46801 @node gdb-add-index man
46802 @heading gdb-add-index
46803 @pindex gdb-add-index
46804 @anchor{gdb-add-index}
46805
46806 @c man title gdb-add-index Add index files to speed up GDB
46807
46808 @c man begin SYNOPSIS gdb-add-index
46809 gdb-add-index @var{filename}
46810 @c man end
46811
46812 @c man begin DESCRIPTION gdb-add-index
46813 When @value{GDBN} finds a symbol file, it scans the symbols in the
46814 file in order to construct an internal symbol table. This lets most
46815 @value{GDBN} operations work quickly--at the cost of a delay early on.
46816 For large programs, this delay can be quite lengthy, so @value{GDBN}
46817 provides a way to build an index, which speeds up startup.
46818
46819 To determine whether a file contains such an index, use the command
46820 @kbd{readelf -S filename}: the index is stored in a section named
46821 @code{.gdb_index}. The index file can only be produced on systems
46822 which use ELF binaries and DWARF debug information (i.e., sections
46823 named @code{.debug_*}).
46824
46825 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46826 in the @env{PATH} environment variable. If you want to use different
46827 versions of these programs, you can specify them through the
46828 @env{GDB} and @env{OBJDUMP} environment variables.
46829
46830 See more in
46831 @ifset man
46832 the @value{GDBN} manual in node @code{Index Files}
46833 -- shell command @kbd{info -f gdb -n "Index Files"}.
46834 @end ifset
46835 @ifclear man
46836 @ref{Index Files}.
46837 @end ifclear
46838 @c man end
46839
46840 @c man begin SEEALSO gdb-add-index
46841 @ifset man
46842 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46843 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46844 documentation are properly installed at your site, the command
46845
46846 @smallexample
46847 info gdb
46848 @end smallexample
46849
46850 should give you access to the complete manual.
46851
46852 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46853 Richard M. Stallman and Roland H. Pesch, July 1991.
46854 @end ifset
46855 @c man end
46856
46857 @include gpl.texi
46858
46859 @node GNU Free Documentation License
46860 @appendix GNU Free Documentation License
46861 @include fdl.texi
46862
46863 @node Concept Index
46864 @unnumbered Concept Index
46865
46866 @printindex cp
46867
46868 @node Command and Variable Index
46869 @unnumbered Command, Variable, and Function Index
46870
46871 @printindex fn
46872
46873 @tex
46874 % I think something like @@colophon should be in texinfo. In the
46875 % meantime:
46876 \long\def\colophon{\hbox to0pt{}\vfill
46877 \centerline{The body of this manual is set in}
46878 \centerline{\fontname\tenrm,}
46879 \centerline{with headings in {\bf\fontname\tenbf}}
46880 \centerline{and examples in {\tt\fontname\tentt}.}
46881 \centerline{{\it\fontname\tenit\/},}
46882 \centerline{{\bf\fontname\tenbf}, and}
46883 \centerline{{\sl\fontname\tensl\/}}
46884 \centerline{are used for emphasis.}\vfill}
46885 \page\colophon
46886 % Blame: doc@@cygnus.com, 1991.
46887 @end tex
46888
46889 @bye
This page took 0.967877 seconds and 3 git commands to generate.