Handle non-ASCII identifiers in Ada
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2022 Free Software Foundation, Inc.
3 @c
4 @c %**start of header
5 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6 @c of @set vars. However, you can override filename with makeinfo -o.
7 @setfilename gdb.info
8 @c
9 @c man begin INCLUDE
10 @include gdb-cfg.texi
11 @c man end
12 @c
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
15 @c %**end of header
16
17 @iftex
18 @c @smallbook
19 @c @cropmarks
20 @end iftex
21
22 @finalout
23 @c To avoid file-name clashes between index.html and Index.html, when
24 @c the manual is produced on a Posix host and then moved to a
25 @c case-insensitive filesystem (e.g., MS-Windows), we separate the
26 @c indices into two: Concept Index and all the rest.
27 @syncodeindex ky fn
28 @syncodeindex tp fn
29
30 @c readline appendices use @vindex, @findex and @ftable,
31 @c annotate.texi and gdbmi use @findex.
32 @syncodeindex vr fn
33
34 @c !!set GDB manual's edition---not the same as GDB version!
35 @c This is updated by GNU Press.
36 @set EDITION Tenth
37
38 @c !!set GDB edit command default editor
39 @set EDITOR /bin/ex
40
41 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
42
43 @c This is a dir.info fragment to support semi-automated addition of
44 @c manuals to an info tree.
45 @dircategory Software development
46 @direntry
47 * Gdb: (gdb). The GNU debugger.
48 * gdbserver: (gdb) Server. The GNU debugging server.
49 @end direntry
50
51 @copying
52 @c man begin COPYRIGHT
53 Copyright @copyright{} 1988-2022 Free Software Foundation, Inc.
54
55 Permission is granted to copy, distribute and/or modify this document
56 under the terms of the GNU Free Documentation License, Version 1.3 or
57 any later version published by the Free Software Foundation; with the
58 Invariant Sections being ``Free Software'' and ``Free Software Needs
59 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60 and with the Back-Cover Texts as in (a) below.
61
62 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63 this GNU Manual. Buying copies from GNU Press supports the FSF in
64 developing GNU and promoting software freedom.''
65 @c man end
66 @end copying
67
68 @ifnottex
69 This file documents the @sc{gnu} debugger @value{GDBN}.
70
71 This is the @value{EDITION} Edition, of @cite{Debugging with
72 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73 @ifset VERSION_PACKAGE
74 @value{VERSION_PACKAGE}
75 @end ifset
76 Version @value{GDBVN}.
77
78 @insertcopying
79 @end ifnottex
80
81 @titlepage
82 @title Debugging with @value{GDBN}
83 @subtitle The @sc{gnu} Source-Level Debugger
84 @sp 1
85 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
86 @ifset VERSION_PACKAGE
87 @sp 1
88 @subtitle @value{VERSION_PACKAGE}
89 @end ifset
90 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
91 @page
92 @tex
93 {\parskip=0pt
94 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
95 \hfill {\it Debugging with @value{GDBN}}\par
96 \hfill \TeX{}info \texinfoversion\par
97 }
98 @end tex
99
100 @vskip 0pt plus 1filll
101 Published by the Free Software Foundation @*
102 51 Franklin Street, Fifth Floor,
103 Boston, MA 02110-1301, USA@*
104 ISBN 978-0-9831592-3-0 @*
105
106 @insertcopying
107 @end titlepage
108 @page
109
110 @ifnottex
111 @node Top, Summary
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, for @value{GDBN}
118 @ifset VERSION_PACKAGE
119 @value{VERSION_PACKAGE}
120 @end ifset
121 Version @value{GDBVN}.
122
123 Copyright (C) 1988-2022 Free Software Foundation, Inc.
124
125 This edition of the GDB manual is dedicated to the memory of Fred
126 Fish. Fred was a long-standing contributor to GDB and to Free
127 software in general. We will miss him.
128
129 @menu
130 * Summary:: Summary of @value{GDBN}
131 * Sample Session:: A sample @value{GDBN} session
132
133 * Invocation:: Getting in and out of @value{GDBN}
134 * Commands:: @value{GDBN} commands
135 * Running:: Running programs under @value{GDBN}
136 * Stopping:: Stopping and continuing
137 * Reverse Execution:: Running programs backward
138 * Process Record and Replay:: Recording inferior's execution and replaying it
139 * Stack:: Examining the stack
140 * Source:: Examining source files
141 * Data:: Examining data
142 * Optimized Code:: Debugging optimized code
143 * Macros:: Preprocessor Macros
144 * Tracepoints:: Debugging remote targets non-intrusively
145 * Overlays:: Debugging programs that use overlays
146
147 * Languages:: Using @value{GDBN} with different languages
148
149 * Symbols:: Examining the symbol table
150 * Altering:: Altering execution
151 * GDB Files:: @value{GDBN} files
152 * Targets:: Specifying a debugging target
153 * Remote Debugging:: Debugging remote programs
154 * Configurations:: Configuration-specific information
155 * Controlling GDB:: Controlling @value{GDBN}
156 * Extending GDB:: Extending @value{GDBN}
157 * Interpreters:: Command Interpreters
158 * TUI:: @value{GDBN} Text User Interface
159 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
160 * GDB/MI:: @value{GDBN}'s Machine Interface.
161 * Annotations:: @value{GDBN}'s annotation interface.
162 * JIT Interface:: Using the JIT debugging interface.
163 * In-Process Agent:: In-Process Agent
164
165 * GDB Bugs:: Reporting bugs in @value{GDBN}
166
167 @ifset SYSTEM_READLINE
168 * Command Line Editing: (rluserman). Command Line Editing
169 * Using History Interactively: (history). Using History Interactively
170 @end ifset
171 @ifclear SYSTEM_READLINE
172 * Command Line Editing:: Command Line Editing
173 * Using History Interactively:: Using History Interactively
174 @end ifclear
175 * In Memoriam:: In Memoriam
176 * Formatting Documentation:: How to format and print @value{GDBN} documentation
177 * Installing GDB:: Installing GDB
178 * Maintenance Commands:: Maintenance Commands
179 * Remote Protocol:: GDB Remote Serial Protocol
180 * Agent Expressions:: The GDB Agent Expression Mechanism
181 * Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
183 * Operating System Information:: Getting additional information from
184 the operating system
185 * Trace File Format:: GDB trace file format
186 * Index Section Format:: .gdb_index section format
187 * Debuginfod:: Download debugging resources with @code{debuginfod}
188 * Man Pages:: Manual pages
189 * Copying:: GNU General Public License says
190 how you can copy and share GDB
191 * GNU Free Documentation License:: The license for this documentation
192 * Concept Index:: Index of @value{GDBN} concepts
193 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
194 functions, and Python data types
195 @end menu
196
197 @end ifnottex
198
199 @contents
200
201 @node Summary
202 @unnumbered Summary of @value{GDBN}
203
204 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
205 going on ``inside'' another program while it executes---or what another
206 program was doing at the moment it crashed.
207
208 @value{GDBN} can do four main kinds of things (plus other things in support of
209 these) to help you catch bugs in the act:
210
211 @itemize @bullet
212 @item
213 Start your program, specifying anything that might affect its behavior.
214
215 @item
216 Make your program stop on specified conditions.
217
218 @item
219 Examine what has happened, when your program has stopped.
220
221 @item
222 Change things in your program, so you can experiment with correcting the
223 effects of one bug and go on to learn about another.
224 @end itemize
225
226 You can use @value{GDBN} to debug programs written in C and C@t{++}.
227 For more information, see @ref{Supported Languages,,Supported Languages}.
228 For more information, see @ref{C,,C and C++}.
229
230 Support for D is partial. For information on D, see
231 @ref{D,,D}.
232
233 @cindex Modula-2
234 Support for Modula-2 is partial. For information on Modula-2, see
235 @ref{Modula-2,,Modula-2}.
236
237 Support for OpenCL C is partial. For information on OpenCL C, see
238 @ref{OpenCL C,,OpenCL C}.
239
240 @cindex Pascal
241 Debugging Pascal programs which use sets, subranges, file variables, or
242 nested functions does not currently work. @value{GDBN} does not support
243 entering expressions, printing values, or similar features using Pascal
244 syntax.
245
246 @cindex Fortran
247 @value{GDBN} can be used to debug programs written in Fortran, although
248 it may be necessary to refer to some variables with a trailing
249 underscore.
250
251 @value{GDBN} can be used to debug programs written in Objective-C,
252 using either the Apple/NeXT or the GNU Objective-C runtime.
253
254 @menu
255 * Free Software:: Freely redistributable software
256 * Free Documentation:: Free Software Needs Free Documentation
257 * Contributors:: Contributors to GDB
258 @end menu
259
260 @node Free Software
261 @unnumberedsec Free Software
262
263 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
264 General Public License
265 (GPL). The GPL gives you the freedom to copy or adapt a licensed
266 program---but every person getting a copy also gets with it the
267 freedom to modify that copy (which means that they must get access to
268 the source code), and the freedom to distribute further copies.
269 Typical software companies use copyrights to limit your freedoms; the
270 Free Software Foundation uses the GPL to preserve these freedoms.
271
272 Fundamentally, the General Public License is a license which says that
273 you have these freedoms and that you cannot take these freedoms away
274 from anyone else.
275
276 @node Free Documentation
277 @unnumberedsec Free Software Needs Free Documentation
278
279 The biggest deficiency in the free software community today is not in
280 the software---it is the lack of good free documentation that we can
281 include with the free software. Many of our most important
282 programs do not come with free reference manuals and free introductory
283 texts. Documentation is an essential part of any software package;
284 when an important free software package does not come with a free
285 manual and a free tutorial, that is a major gap. We have many such
286 gaps today.
287
288 Consider Perl, for instance. The tutorial manuals that people
289 normally use are non-free. How did this come about? Because the
290 authors of those manuals published them with restrictive terms---no
291 copying, no modification, source files not available---which exclude
292 them from the free software world.
293
294 That wasn't the first time this sort of thing happened, and it was far
295 from the last. Many times we have heard a GNU user eagerly describe a
296 manual that he is writing, his intended contribution to the community,
297 only to learn that he had ruined everything by signing a publication
298 contract to make it non-free.
299
300 Free documentation, like free software, is a matter of freedom, not
301 price. The problem with the non-free manual is not that publishers
302 charge a price for printed copies---that in itself is fine. (The Free
303 Software Foundation sells printed copies of manuals, too.) The
304 problem is the restrictions on the use of the manual. Free manuals
305 are available in source code form, and give you permission to copy and
306 modify. Non-free manuals do not allow this.
307
308 The criteria of freedom for a free manual are roughly the same as for
309 free software. Redistribution (including the normal kinds of
310 commercial redistribution) must be permitted, so that the manual can
311 accompany every copy of the program, both on-line and on paper.
312
313 Permission for modification of the technical content is crucial too.
314 When people modify the software, adding or changing features, if they
315 are conscientious they will change the manual too---so they can
316 provide accurate and clear documentation for the modified program. A
317 manual that leaves you no choice but to write a new manual to document
318 a changed version of the program is not really available to our
319 community.
320
321 Some kinds of limits on the way modification is handled are
322 acceptable. For example, requirements to preserve the original
323 author's copyright notice, the distribution terms, or the list of
324 authors, are ok. It is also no problem to require modified versions
325 to include notice that they were modified. Even entire sections that
326 may not be deleted or changed are acceptable, as long as they deal
327 with nontechnical topics (like this one). These kinds of restrictions
328 are acceptable because they don't obstruct the community's normal use
329 of the manual.
330
331 However, it must be possible to modify all the @emph{technical}
332 content of the manual, and then distribute the result in all the usual
333 media, through all the usual channels. Otherwise, the restrictions
334 obstruct the use of the manual, it is not free, and we need another
335 manual to replace it.
336
337 Please spread the word about this issue. Our community continues to
338 lose manuals to proprietary publishing. If we spread the word that
339 free software needs free reference manuals and free tutorials, perhaps
340 the next person who wants to contribute by writing documentation will
341 realize, before it is too late, that only free manuals contribute to
342 the free software community.
343
344 If you are writing documentation, please insist on publishing it under
345 the GNU Free Documentation License or another free documentation
346 license. Remember that this decision requires your approval---you
347 don't have to let the publisher decide. Some commercial publishers
348 will use a free license if you insist, but they will not propose the
349 option; it is up to you to raise the issue and say firmly that this is
350 what you want. If the publisher you are dealing with refuses, please
351 try other publishers. If you're not sure whether a proposed license
352 is free, write to @email{licensing@@gnu.org}.
353
354 You can encourage commercial publishers to sell more free, copylefted
355 manuals and tutorials by buying them, and particularly by buying
356 copies from the publishers that paid for their writing or for major
357 improvements. Meanwhile, try to avoid buying non-free documentation
358 at all. Check the distribution terms of a manual before you buy it,
359 and insist that whoever seeks your business must respect your freedom.
360 Check the history of the book, and try to reward the publishers that
361 have paid or pay the authors to work on it.
362
363 The Free Software Foundation maintains a list of free documentation
364 published by other publishers, at
365 @url{http://www.fsf.org/doc/other-free-books.html}.
366
367 @node Contributors
368 @unnumberedsec Contributors to @value{GDBN}
369
370 Richard Stallman was the original author of @value{GDBN}, and of many
371 other @sc{gnu} programs. Many others have contributed to its
372 development. This section attempts to credit major contributors. One
373 of the virtues of free software is that everyone is free to contribute
374 to it; with regret, we cannot actually acknowledge everyone here. The
375 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
376 blow-by-blow account.
377
378 Changes much prior to version 2.0 are lost in the mists of time.
379
380 @quotation
381 @emph{Plea:} Additions to this section are particularly welcome. If you
382 or your friends (or enemies, to be evenhanded) have been unfairly
383 omitted from this list, we would like to add your names!
384 @end quotation
385
386 So that they may not regard their many labors as thankless, we
387 particularly thank those who shepherded @value{GDBN} through major
388 releases:
389 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
390 Jim Blandy (release 4.18);
391 Jason Molenda (release 4.17);
392 Stan Shebs (release 4.14);
393 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
394 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
395 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
396 Jim Kingdon (releases 3.5, 3.4, and 3.3);
397 and Randy Smith (releases 3.2, 3.1, and 3.0).
398
399 Richard Stallman, assisted at various times by Peter TerMaat, Chris
400 Hanson, and Richard Mlynarik, handled releases through 2.8.
401
402 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
403 in @value{GDBN}, with significant additional contributions from Per
404 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
405 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
406 much general update work leading to release 3.0).
407
408 @value{GDBN} uses the BFD subroutine library to examine multiple
409 object-file formats; BFD was a joint project of David V.
410 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
411
412 David Johnson wrote the original COFF support; Pace Willison did
413 the original support for encapsulated COFF.
414
415 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
416
417 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
418 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
419 support.
420 Jean-Daniel Fekete contributed Sun 386i support.
421 Chris Hanson improved the HP9000 support.
422 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
423 David Johnson contributed Encore Umax support.
424 Jyrki Kuoppala contributed Altos 3068 support.
425 Jeff Law contributed HP PA and SOM support.
426 Keith Packard contributed NS32K support.
427 Doug Rabson contributed Acorn Risc Machine support.
428 Bob Rusk contributed Harris Nighthawk CX-UX support.
429 Chris Smith contributed Convex support (and Fortran debugging).
430 Jonathan Stone contributed Pyramid support.
431 Michael Tiemann contributed SPARC support.
432 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
433 Pace Willison contributed Intel 386 support.
434 Jay Vosburgh contributed Symmetry support.
435 Marko Mlinar contributed OpenRISC 1000 support.
436
437 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
438
439 Rich Schaefer and Peter Schauer helped with support of SunOS shared
440 libraries.
441
442 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
443 about several machine instruction sets.
444
445 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
446 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
447 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
448 and RDI targets, respectively.
449
450 Brian Fox is the author of the readline libraries providing
451 command-line editing and command history.
452
453 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
454 Modula-2 support, and contributed the Languages chapter of this manual.
455
456 Fred Fish wrote most of the support for Unix System Vr4.
457 He also enhanced the command-completion support to cover C@t{++} overloaded
458 symbols.
459
460 Hitachi America (now Renesas America), Ltd. sponsored the support for
461 H8/300, H8/500, and Super-H processors.
462
463 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
464
465 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
466 processors.
467
468 Toshiba sponsored the support for the TX39 Mips processor.
469
470 Matsushita sponsored the support for the MN10200 and MN10300 processors.
471
472 Fujitsu sponsored the support for SPARClite and FR30 processors.
473
474 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
475 watchpoints.
476
477 Michael Snyder added support for tracepoints.
478
479 Stu Grossman wrote gdbserver.
480
481 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
482 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
483
484 The following people at the Hewlett-Packard Company contributed
485 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
486 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
487 compiler, and the Text User Interface (nee Terminal User Interface):
488 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
489 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
490 provided HP-specific information in this manual.
491
492 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
493 Robert Hoehne made significant contributions to the DJGPP port.
494
495 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
496 development since 1991. Cygnus engineers who have worked on @value{GDBN}
497 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
498 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
499 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
500 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
501 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
502 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
503 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
504 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
505 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
506 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
507 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
508 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
509 Zuhn have made contributions both large and small.
510
511 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
512 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
513
514 Jim Blandy added support for preprocessor macros, while working for Red
515 Hat.
516
517 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
518 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
519 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
520 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
521 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
522 with the migration of old architectures to this new framework.
523
524 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
525 unwinder framework, this consisting of a fresh new design featuring
526 frame IDs, independent frame sniffers, and the sentinel frame. Mark
527 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
528 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
529 trad unwinders. The architecture-specific changes, each involving a
530 complete rewrite of the architecture's frame code, were carried out by
531 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
532 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
533 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
534 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
535 Weigand.
536
537 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
538 Tensilica, Inc.@: contributed support for Xtensa processors. Others
539 who have worked on the Xtensa port of @value{GDBN} in the past include
540 Steve Tjiang, John Newlin, and Scott Foehner.
541
542 Michael Eager and staff of Xilinx, Inc., contributed support for the
543 Xilinx MicroBlaze architecture.
544
545 Initial support for the FreeBSD/mips target and native configuration
546 was developed by SRI International and the University of Cambridge
547 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
548 ("CTSRD"), as part of the DARPA CRASH research programme.
549
550 Initial support for the FreeBSD/riscv target and native configuration
551 was developed by SRI International and the University of Cambridge
552 Computer Laboratory (Department of Computer Science and Technology)
553 under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
554 SSITH research programme.
555
556 The original port to the OpenRISC 1000 is believed to be due to
557 Alessandro Forin and Per Bothner. More recent ports have been the work
558 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
559 Stafford Horne.
560
561 Weimin Pan, David Faust and Jose E. Marchesi contributed support for
562 the Linux kernel BPF virtual architecture. This work was sponsored by
563 Oracle.
564
565 @node Sample Session
566 @chapter A Sample @value{GDBN} Session
567
568 You can use this manual at your leisure to read all about @value{GDBN}.
569 However, a handful of commands are enough to get started using the
570 debugger. This chapter illustrates those commands.
571
572 @iftex
573 In this sample session, we emphasize user input like this: @b{input},
574 to make it easier to pick out from the surrounding output.
575 @end iftex
576
577 @c FIXME: this example may not be appropriate for some configs, where
578 @c FIXME...primary interest is in remote use.
579
580 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
581 processor) exhibits the following bug: sometimes, when we change its
582 quote strings from the default, the commands used to capture one macro
583 definition within another stop working. In the following short @code{m4}
584 session, we define a macro @code{foo} which expands to @code{0000}; we
585 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
586 same thing. However, when we change the open quote string to
587 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
588 procedure fails to define a new synonym @code{baz}:
589
590 @smallexample
591 $ @b{cd gnu/m4}
592 $ @b{./m4}
593 @b{define(foo,0000)}
594
595 @b{foo}
596 0000
597 @b{define(bar,defn(`foo'))}
598
599 @b{bar}
600 0000
601 @b{changequote(<QUOTE>,<UNQUOTE>)}
602
603 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
604 @b{baz}
605 @b{Ctrl-d}
606 m4: End of input: 0: fatal error: EOF in string
607 @end smallexample
608
609 @noindent
610 Let us use @value{GDBN} to try to see what is going on.
611
612 @smallexample
613 $ @b{@value{GDBP} m4}
614 @c FIXME: this falsifies the exact text played out, to permit smallbook
615 @c FIXME... format to come out better.
616 @value{GDBN} is free software and you are welcome to distribute copies
617 of it under certain conditions; type "show copying" to see
618 the conditions.
619 There is absolutely no warranty for @value{GDBN}; type "show warranty"
620 for details.
621
622 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
623 (@value{GDBP})
624 @end smallexample
625
626 @noindent
627 @value{GDBN} reads only enough symbol data to know where to find the
628 rest when needed; as a result, the first prompt comes up very quickly.
629 We now tell @value{GDBN} to use a narrower display width than usual, so
630 that examples fit in this manual.
631
632 @smallexample
633 (@value{GDBP}) @b{set width 70}
634 @end smallexample
635
636 @noindent
637 We need to see how the @code{m4} built-in @code{changequote} works.
638 Having looked at the source, we know the relevant subroutine is
639 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
640 @code{break} command.
641
642 @smallexample
643 (@value{GDBP}) @b{break m4_changequote}
644 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
645 @end smallexample
646
647 @noindent
648 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
649 control; as long as control does not reach the @code{m4_changequote}
650 subroutine, the program runs as usual:
651
652 @smallexample
653 (@value{GDBP}) @b{run}
654 Starting program: /work/Editorial/gdb/gnu/m4/m4
655 @b{define(foo,0000)}
656
657 @b{foo}
658 0000
659 @end smallexample
660
661 @noindent
662 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
663 suspends execution of @code{m4}, displaying information about the
664 context where it stops.
665
666 @smallexample
667 @b{changequote(<QUOTE>,<UNQUOTE>)}
668
669 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
670 at builtin.c:879
671 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
672 @end smallexample
673
674 @noindent
675 Now we use the command @code{n} (@code{next}) to advance execution to
676 the next line of the current function.
677
678 @smallexample
679 (@value{GDBP}) @b{n}
680 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
681 : nil,
682 @end smallexample
683
684 @noindent
685 @code{set_quotes} looks like a promising subroutine. We can go into it
686 by using the command @code{s} (@code{step}) instead of @code{next}.
687 @code{step} goes to the next line to be executed in @emph{any}
688 subroutine, so it steps into @code{set_quotes}.
689
690 @smallexample
691 (@value{GDBP}) @b{s}
692 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
693 at input.c:530
694 530 if (lquote != def_lquote)
695 @end smallexample
696
697 @noindent
698 The display that shows the subroutine where @code{m4} is now
699 suspended (and its arguments) is called a stack frame display. It
700 shows a summary of the stack. We can use the @code{backtrace}
701 command (which can also be spelled @code{bt}), to see where we are
702 in the stack as a whole: the @code{backtrace} command displays a
703 stack frame for each active subroutine.
704
705 @smallexample
706 (@value{GDBP}) @b{bt}
707 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
708 at input.c:530
709 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
710 at builtin.c:882
711 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
712 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
713 at macro.c:71
714 #4 0x79dc in expand_input () at macro.c:40
715 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
716 @end smallexample
717
718 @noindent
719 We step through a few more lines to see what happens. The first two
720 times, we can use @samp{s}; the next two times we use @code{n} to avoid
721 falling into the @code{xstrdup} subroutine.
722
723 @smallexample
724 (@value{GDBP}) @b{s}
725 0x3b5c 532 if (rquote != def_rquote)
726 (@value{GDBP}) @b{s}
727 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
728 def_lquote : xstrdup(lq);
729 (@value{GDBP}) @b{n}
730 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
731 : xstrdup(rq);
732 (@value{GDBP}) @b{n}
733 538 len_lquote = strlen(rquote);
734 @end smallexample
735
736 @noindent
737 The last line displayed looks a little odd; we can examine the variables
738 @code{lquote} and @code{rquote} to see if they are in fact the new left
739 and right quotes we specified. We use the command @code{p}
740 (@code{print}) to see their values.
741
742 @smallexample
743 (@value{GDBP}) @b{p lquote}
744 $1 = 0x35d40 "<QUOTE>"
745 (@value{GDBP}) @b{p rquote}
746 $2 = 0x35d50 "<UNQUOTE>"
747 @end smallexample
748
749 @noindent
750 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
751 To look at some context, we can display ten lines of source
752 surrounding the current line with the @code{l} (@code{list}) command.
753
754 @smallexample
755 (@value{GDBP}) @b{l}
756 533 xfree(rquote);
757 534
758 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
759 : xstrdup (lq);
760 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
761 : xstrdup (rq);
762 537
763 538 len_lquote = strlen(rquote);
764 539 len_rquote = strlen(lquote);
765 540 @}
766 541
767 542 void
768 @end smallexample
769
770 @noindent
771 Let us step past the two lines that set @code{len_lquote} and
772 @code{len_rquote}, and then examine the values of those variables.
773
774 @smallexample
775 (@value{GDBP}) @b{n}
776 539 len_rquote = strlen(lquote);
777 (@value{GDBP}) @b{n}
778 540 @}
779 (@value{GDBP}) @b{p len_lquote}
780 $3 = 9
781 (@value{GDBP}) @b{p len_rquote}
782 $4 = 7
783 @end smallexample
784
785 @noindent
786 That certainly looks wrong, assuming @code{len_lquote} and
787 @code{len_rquote} are meant to be the lengths of @code{lquote} and
788 @code{rquote} respectively. We can set them to better values using
789 the @code{p} command, since it can print the value of
790 any expression---and that expression can include subroutine calls and
791 assignments.
792
793 @smallexample
794 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
795 $5 = 7
796 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
797 $6 = 9
798 @end smallexample
799
800 @noindent
801 Is that enough to fix the problem of using the new quotes with the
802 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
803 executing with the @code{c} (@code{continue}) command, and then try the
804 example that caused trouble initially:
805
806 @smallexample
807 (@value{GDBP}) @b{c}
808 Continuing.
809
810 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
811
812 baz
813 0000
814 @end smallexample
815
816 @noindent
817 Success! The new quotes now work just as well as the default ones. The
818 problem seems to have been just the two typos defining the wrong
819 lengths. We allow @code{m4} exit by giving it an EOF as input:
820
821 @smallexample
822 @b{Ctrl-d}
823 Program exited normally.
824 @end smallexample
825
826 @noindent
827 The message @samp{Program exited normally.} is from @value{GDBN}; it
828 indicates @code{m4} has finished executing. We can end our @value{GDBN}
829 session with the @value{GDBN} @code{quit} command.
830
831 @smallexample
832 (@value{GDBP}) @b{quit}
833 @end smallexample
834
835 @node Invocation
836 @chapter Getting In and Out of @value{GDBN}
837
838 This chapter discusses how to start @value{GDBN}, and how to get out of it.
839 The essentials are:
840 @itemize @bullet
841 @item
842 type @samp{@value{GDBP}} to start @value{GDBN}.
843 @item
844 type @kbd{quit}, @kbd{exit} or @kbd{Ctrl-d} to exit.
845 @end itemize
846
847 @menu
848 * Invoking GDB:: How to start @value{GDBN}
849 * Quitting GDB:: How to quit @value{GDBN}
850 * Shell Commands:: How to use shell commands inside @value{GDBN}
851 * Logging Output:: How to log @value{GDBN}'s output to a file
852 @end menu
853
854 @node Invoking GDB
855 @section Invoking @value{GDBN}
856
857 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
858 @value{GDBN} reads commands from the terminal until you tell it to exit.
859
860 You can also run @code{@value{GDBP}} with a variety of arguments and options,
861 to specify more of your debugging environment at the outset.
862
863 The command-line options described here are designed
864 to cover a variety of situations; in some environments, some of these
865 options may effectively be unavailable.
866
867 The most usual way to start @value{GDBN} is with one argument,
868 specifying an executable program:
869
870 @smallexample
871 @value{GDBP} @var{program}
872 @end smallexample
873
874 @noindent
875 You can also start with both an executable program and a core file
876 specified:
877
878 @smallexample
879 @value{GDBP} @var{program} @var{core}
880 @end smallexample
881
882 You can, instead, specify a process ID as a second argument or use option
883 @code{-p}, if you want to debug a running process:
884
885 @smallexample
886 @value{GDBP} @var{program} 1234
887 @value{GDBP} -p 1234
888 @end smallexample
889
890 @noindent
891 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
892 can omit the @var{program} filename.
893
894 Taking advantage of the second command-line argument requires a fairly
895 complete operating system; when you use @value{GDBN} as a remote
896 debugger attached to a bare board, there may not be any notion of
897 ``process'', and there is often no way to get a core dump. @value{GDBN}
898 will warn you if it is unable to attach or to read core dumps.
899
900 You can optionally have @code{@value{GDBP}} pass any arguments after the
901 executable file to the inferior using @code{--args}. This option stops
902 option processing.
903 @smallexample
904 @value{GDBP} --args gcc -O2 -c foo.c
905 @end smallexample
906 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
907 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
908
909 You can run @code{@value{GDBP}} without printing the front material, which describes
910 @value{GDBN}'s non-warranty, by specifying @code{--silent}
911 (or @code{-q}/@code{--quiet}):
912
913 @smallexample
914 @value{GDBP} --silent
915 @end smallexample
916
917 @noindent
918 You can further control how @value{GDBN} starts up by using command-line
919 options. @value{GDBN} itself can remind you of the options available.
920
921 @noindent
922 Type
923
924 @smallexample
925 @value{GDBP} -help
926 @end smallexample
927
928 @noindent
929 to display all available options and briefly describe their use
930 (@samp{@value{GDBP} -h} is a shorter equivalent).
931
932 All options and command line arguments you give are processed
933 in sequential order. The order makes a difference when the
934 @samp{-x} option is used.
935
936
937 @menu
938 * File Options:: Choosing files
939 * Mode Options:: Choosing modes
940 * Startup:: What @value{GDBN} does during startup
941 * Initialization Files:: Initialization Files
942 @end menu
943
944 @node File Options
945 @subsection Choosing Files
946
947 When @value{GDBN} starts, it reads any arguments other than options as
948 specifying an executable file and core file (or process ID). This is
949 the same as if the arguments were specified by the @samp{-se} and
950 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
951 first argument that does not have an associated option flag as
952 equivalent to the @samp{-se} option followed by that argument; and the
953 second argument that does not have an associated option flag, if any, as
954 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
955 If the second argument begins with a decimal digit, @value{GDBN} will
956 first attempt to attach to it as a process, and if that fails, attempt
957 to open it as a corefile. If you have a corefile whose name begins with
958 a digit, you can prevent @value{GDBN} from treating it as a pid by
959 prefixing it with @file{./}, e.g.@: @file{./12345}.
960
961 If @value{GDBN} has not been configured to included core file support,
962 such as for most embedded targets, then it will complain about a second
963 argument and ignore it.
964
965 Many options have both long and short forms; both are shown in the
966 following list. @value{GDBN} also recognizes the long forms if you truncate
967 them, so long as enough of the option is present to be unambiguous.
968 (If you prefer, you can flag option arguments with @samp{--} rather
969 than @samp{-}, though we illustrate the more usual convention.)
970
971 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
972 @c way, both those who look for -foo and --foo in the index, will find
973 @c it.
974
975 @table @code
976 @item -symbols @var{file}
977 @itemx -s @var{file}
978 @cindex @code{--symbols}
979 @cindex @code{-s}
980 Read symbol table from file @var{file}.
981
982 @item -exec @var{file}
983 @itemx -e @var{file}
984 @cindex @code{--exec}
985 @cindex @code{-e}
986 Use file @var{file} as the executable file to execute when appropriate,
987 and for examining pure data in conjunction with a core dump.
988
989 @item -se @var{file}
990 @cindex @code{--se}
991 Read symbol table from file @var{file} and use it as the executable
992 file.
993
994 @item -core @var{file}
995 @itemx -c @var{file}
996 @cindex @code{--core}
997 @cindex @code{-c}
998 Use file @var{file} as a core dump to examine.
999
1000 @item -pid @var{number}
1001 @itemx -p @var{number}
1002 @cindex @code{--pid}
1003 @cindex @code{-p}
1004 Connect to process ID @var{number}, as with the @code{attach} command.
1005
1006 @item -command @var{file}
1007 @itemx -x @var{file}
1008 @cindex @code{--command}
1009 @cindex @code{-x}
1010 Execute commands from file @var{file}. The contents of this file is
1011 evaluated exactly as the @code{source} command would.
1012 @xref{Command Files,, Command files}.
1013
1014 @item -eval-command @var{command}
1015 @itemx -ex @var{command}
1016 @cindex @code{--eval-command}
1017 @cindex @code{-ex}
1018 Execute a single @value{GDBN} command.
1019
1020 This option may be used multiple times to call multiple commands. It may
1021 also be interleaved with @samp{-command} as required.
1022
1023 @smallexample
1024 @value{GDBP} -ex 'target sim' -ex 'load' \
1025 -x setbreakpoints -ex 'run' a.out
1026 @end smallexample
1027
1028 @item -init-command @var{file}
1029 @itemx -ix @var{file}
1030 @cindex @code{--init-command}
1031 @cindex @code{-ix}
1032 Execute commands from file @var{file} before loading the inferior (but
1033 after loading gdbinit files).
1034 @xref{Startup}.
1035
1036 @item -init-eval-command @var{command}
1037 @itemx -iex @var{command}
1038 @cindex @code{--init-eval-command}
1039 @cindex @code{-iex}
1040 Execute a single @value{GDBN} command before loading the inferior (but
1041 after loading gdbinit files).
1042 @xref{Startup}.
1043
1044 @item -early-init-command @var{file}
1045 @itemx -eix @var{file}
1046 @cindex @code{--early-init-command}
1047 @cindex @code{-eix}
1048 Execute commands from @var{file} very early in the initialization
1049 process, before any output is produced. @xref{Startup}.
1050
1051 @item -early-init-eval-command @var{command}
1052 @itemx -eiex @var{command}
1053 @cindex @code{--early-init-eval-command}
1054 @cindex @code{-eiex}
1055 Execute a single @value{GDBN} command very early in the initialization
1056 process, before any output is produced.
1057
1058 @item -directory @var{directory}
1059 @itemx -d @var{directory}
1060 @cindex @code{--directory}
1061 @cindex @code{-d}
1062 Add @var{directory} to the path to search for source and script files.
1063
1064 @item -r
1065 @itemx -readnow
1066 @cindex @code{--readnow}
1067 @cindex @code{-r}
1068 Read each symbol file's entire symbol table immediately, rather than
1069 the default, which is to read it incrementally as it is needed.
1070 This makes startup slower, but makes future operations faster.
1071
1072 @item --readnever
1073 @anchor{--readnever}
1074 @cindex @code{--readnever}, command-line option
1075 Do not read each symbol file's symbolic debug information. This makes
1076 startup faster but at the expense of not being able to perform
1077 symbolic debugging. DWARF unwind information is also not read,
1078 meaning backtraces may become incomplete or inaccurate. One use of
1079 this is when a user simply wants to do the following sequence: attach,
1080 dump core, detach. Loading the debugging information in this case is
1081 an unnecessary cause of delay.
1082 @end table
1083
1084 @node Mode Options
1085 @subsection Choosing Modes
1086
1087 You can run @value{GDBN} in various alternative modes---for example, in
1088 batch mode or quiet mode.
1089
1090 @table @code
1091 @anchor{-nx}
1092 @item -nx
1093 @itemx -n
1094 @cindex @code{--nx}
1095 @cindex @code{-n}
1096 Do not execute commands found in any initialization files
1097 (@pxref{Initialization Files}).
1098
1099 @anchor{-nh}
1100 @item -nh
1101 @cindex @code{--nh}
1102 Do not execute commands found in any home directory initialization
1103 file (@pxref{Initialization Files,,Home directory initialization
1104 file}). The system wide and current directory initialization files
1105 are still loaded.
1106
1107 @item -quiet
1108 @itemx -silent
1109 @itemx -q
1110 @cindex @code{--quiet}
1111 @cindex @code{--silent}
1112 @cindex @code{-q}
1113 ``Quiet''. Do not print the introductory and copyright messages. These
1114 messages are also suppressed in batch mode.
1115
1116 @kindex set startup-quietly
1117 @kindex show startup-quietly
1118 This can also be enabled using @code{set startup-quietly on}. The
1119 default is @code{off}. Use @code{show startup-quietly} to see the
1120 current setting. Place @code{set startup-quietly on} into your early
1121 initialization file (@pxref{Initialization Files,,Initialization
1122 Files}) to have future @value{GDBN} sessions startup quietly.
1123
1124 @item -batch
1125 @cindex @code{--batch}
1126 Run in batch mode. Exit with status @code{0} after processing all the
1127 command files specified with @samp{-x} (and all commands from
1128 initialization files, if not inhibited with @samp{-n}). Exit with
1129 nonzero status if an error occurs in executing the @value{GDBN} commands
1130 in the command files. Batch mode also disables pagination, sets unlimited
1131 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1132 off} were in effect (@pxref{Messages/Warnings}).
1133
1134 Batch mode may be useful for running @value{GDBN} as a filter, for
1135 example to download and run a program on another computer; in order to
1136 make this more useful, the message
1137
1138 @smallexample
1139 Program exited normally.
1140 @end smallexample
1141
1142 @noindent
1143 (which is ordinarily issued whenever a program running under
1144 @value{GDBN} control terminates) is not issued when running in batch
1145 mode.
1146
1147 @item -batch-silent
1148 @cindex @code{--batch-silent}
1149 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1150 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1151 unaffected). This is much quieter than @samp{-silent} and would be useless
1152 for an interactive session.
1153
1154 This is particularly useful when using targets that give @samp{Loading section}
1155 messages, for example.
1156
1157 Note that targets that give their output via @value{GDBN}, as opposed to
1158 writing directly to @code{stdout}, will also be made silent.
1159
1160 @item -return-child-result
1161 @cindex @code{--return-child-result}
1162 The return code from @value{GDBN} will be the return code from the child
1163 process (the process being debugged), with the following exceptions:
1164
1165 @itemize @bullet
1166 @item
1167 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1168 internal error. In this case the exit code is the same as it would have been
1169 without @samp{-return-child-result}.
1170 @item
1171 The user quits with an explicit value. E.g., @samp{quit 1}.
1172 @item
1173 The child process never runs, or is not allowed to terminate, in which case
1174 the exit code will be -1.
1175 @end itemize
1176
1177 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1178 when @value{GDBN} is being used as a remote program loader or simulator
1179 interface.
1180
1181 @item -nowindows
1182 @itemx -nw
1183 @cindex @code{--nowindows}
1184 @cindex @code{-nw}
1185 ``No windows''. If @value{GDBN} comes with a graphical user interface
1186 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1187 interface. If no GUI is available, this option has no effect.
1188
1189 @item -windows
1190 @itemx -w
1191 @cindex @code{--windows}
1192 @cindex @code{-w}
1193 If @value{GDBN} includes a GUI, then this option requires it to be
1194 used if possible.
1195
1196 @item -cd @var{directory}
1197 @cindex @code{--cd}
1198 Run @value{GDBN} using @var{directory} as its working directory,
1199 instead of the current directory.
1200
1201 @item -data-directory @var{directory}
1202 @itemx -D @var{directory}
1203 @cindex @code{--data-directory}
1204 @cindex @code{-D}
1205 Run @value{GDBN} using @var{directory} as its data directory.
1206 The data directory is where @value{GDBN} searches for its
1207 auxiliary files. @xref{Data Files}.
1208
1209 @item -fullname
1210 @itemx -f
1211 @cindex @code{--fullname}
1212 @cindex @code{-f}
1213 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1214 subprocess. It tells @value{GDBN} to output the full file name and line
1215 number in a standard, recognizable fashion each time a stack frame is
1216 displayed (which includes each time your program stops). This
1217 recognizable format looks like two @samp{\032} characters, followed by
1218 the file name, line number and character position separated by colons,
1219 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1220 @samp{\032} characters as a signal to display the source code for the
1221 frame.
1222
1223 @item -annotate @var{level}
1224 @cindex @code{--annotate}
1225 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1226 effect is identical to using @samp{set annotate @var{level}}
1227 (@pxref{Annotations}). The annotation @var{level} controls how much
1228 information @value{GDBN} prints together with its prompt, values of
1229 expressions, source lines, and other types of output. Level 0 is the
1230 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1231 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1232 that control @value{GDBN}, and level 2 has been deprecated.
1233
1234 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1235 (@pxref{GDB/MI}).
1236
1237 @item --args
1238 @cindex @code{--args}
1239 Change interpretation of command line so that arguments following the
1240 executable file are passed as command line arguments to the inferior.
1241 This option stops option processing.
1242
1243 @item -baud @var{bps}
1244 @itemx -b @var{bps}
1245 @cindex @code{--baud}
1246 @cindex @code{-b}
1247 Set the line speed (baud rate or bits per second) of any serial
1248 interface used by @value{GDBN} for remote debugging.
1249
1250 @item -l @var{timeout}
1251 @cindex @code{-l}
1252 Set the timeout (in seconds) of any communication used by @value{GDBN}
1253 for remote debugging.
1254
1255 @item -tty @var{device}
1256 @itemx -t @var{device}
1257 @cindex @code{--tty}
1258 @cindex @code{-t}
1259 Run using @var{device} for your program's standard input and output.
1260 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1261
1262 @c resolve the situation of these eventually
1263 @item -tui
1264 @cindex @code{--tui}
1265 Activate the @dfn{Text User Interface} when starting. The Text User
1266 Interface manages several text windows on the terminal, showing
1267 source, assembly, registers and @value{GDBN} command outputs
1268 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1269 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1270 Using @value{GDBN} under @sc{gnu} Emacs}).
1271
1272 @item -interpreter @var{interp}
1273 @cindex @code{--interpreter}
1274 Use the interpreter @var{interp} for interface with the controlling
1275 program or device. This option is meant to be set by programs which
1276 communicate with @value{GDBN} using it as a back end.
1277 @xref{Interpreters, , Command Interpreters}.
1278
1279 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1280 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1281 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1282 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1283 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1284 interfaces are no longer supported.
1285
1286 @item -write
1287 @cindex @code{--write}
1288 Open the executable and core files for both reading and writing. This
1289 is equivalent to the @samp{set write on} command inside @value{GDBN}
1290 (@pxref{Patching}).
1291
1292 @item -statistics
1293 @cindex @code{--statistics}
1294 This option causes @value{GDBN} to print statistics about time and
1295 memory usage after it completes each command and returns to the prompt.
1296
1297 @item -version
1298 @cindex @code{--version}
1299 This option causes @value{GDBN} to print its version number and
1300 no-warranty blurb, and exit.
1301
1302 @item -configuration
1303 @cindex @code{--configuration}
1304 This option causes @value{GDBN} to print details about its build-time
1305 configuration parameters, and then exit. These details can be
1306 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1307
1308 @end table
1309
1310 @node Startup
1311 @subsection What @value{GDBN} Does During Startup
1312 @cindex @value{GDBN} startup
1313
1314 Here's the description of what @value{GDBN} does during session startup:
1315
1316 @enumerate
1317
1318 @item
1319 Performs minimal setup required to initialize basic internal state.
1320
1321 @item
1322 @cindex early initialization file
1323 Reads commands from the early initialization file (if any) in your
1324 home directory. Only a restricted set of commands can be placed into
1325 an early initialization file, see @ref{Initialization Files}, for
1326 details.
1327
1328 @item
1329 Executes commands and command files specified by the @samp{-eiex} and
1330 @samp{-eix} command line options in their specified order. Only a
1331 restricted set of commands can be used with @samp{-eiex} and
1332 @samp{eix}, see @ref{Initialization Files}, for details.
1333
1334 @item
1335 Sets up the command interpreter as specified by the command line
1336 (@pxref{Mode Options, interpreter}).
1337
1338 @item
1339 @cindex init file
1340 Reads the system wide initialization file and the files from the
1341 system wide initialization directory, @pxref{System Wide Init Files}.
1342
1343 @item
1344 Reads the initialization file (if any) in your home directory and
1345 executes all the commands in that file, @pxref{Home Directory Init
1346 File}.
1347
1348 @anchor{Option -init-eval-command}
1349 @item
1350 Executes commands and command files specified by the @samp{-iex} and
1351 @samp{-ix} options in their specified order. Usually you should use the
1352 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1353 settings before @value{GDBN} init files get executed and before inferior
1354 gets loaded.
1355
1356 @item
1357 Processes command line options and operands.
1358
1359 @item
1360 Reads and executes the commands from the initialization file (if any)
1361 in the current working directory as long as @samp{set auto-load
1362 local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1363 Directory}). This is only done if the current directory is different
1364 from your home directory. Thus, you can have more than one init file,
1365 one generic in your home directory, and another, specific to the
1366 program you are debugging, in the directory where you invoke
1367 @value{GDBN}. @xref{Init File in the Current Directory during
1368 Startup}.
1369
1370 @item
1371 If the command line specified a program to debug, or a process to
1372 attach to, or a core file, @value{GDBN} loads any auto-loaded
1373 scripts provided for the program or for its loaded shared libraries.
1374 @xref{Auto-loading}.
1375
1376 If you wish to disable the auto-loading during startup,
1377 you must do something like the following:
1378
1379 @smallexample
1380 $ gdb -iex "set auto-load python-scripts off" myprogram
1381 @end smallexample
1382
1383 Option @samp{-ex} does not work because the auto-loading is then turned
1384 off too late.
1385
1386 @item
1387 Executes commands and command files specified by the @samp{-ex} and
1388 @samp{-x} options in their specified order. @xref{Command Files}, for
1389 more details about @value{GDBN} command files.
1390
1391 @item
1392 Reads the command history recorded in the @dfn{history file}.
1393 @xref{Command History}, for more details about the command history and the
1394 files where @value{GDBN} records it.
1395 @end enumerate
1396
1397 @node Initialization Files
1398 @subsection Initialization Files
1399 @cindex init file name
1400
1401 During startup (@pxref{Startup}) @value{GDBN} will execute commands
1402 from several initialization files. These initialization files use the
1403 same syntax as @dfn{command files} (@pxref{Command Files}) and are
1404 processed by @value{GDBN} in the same way.
1405
1406 To display the list of initialization files loaded by @value{GDBN} at
1407 startup, in the order they will be loaded, you can use @kbd{gdb
1408 --help}.
1409
1410 @cindex early initialization
1411 The @dfn{early initialization} file is loaded very early in
1412 @value{GDBN}'s initialization process, before the interpreter
1413 (@pxref{Interpreters}) has been initialized, and before the default
1414 target (@pxref{Targets}) is initialized. Only @code{set} or
1415 @code{source} commands should be placed into an early initialization
1416 file, and the only @code{set} commands that can be used are those that
1417 control how @value{GDBN} starts up.
1418
1419 Commands that can be placed into an early initialization file will be
1420 documented as such throughout this manual. Any command that is not
1421 documented as being suitable for an early initialization file should
1422 instead be placed into a general initialization file. Command files
1423 passed to @code{--early-init-command} or @code{-eix} are also early
1424 initialization files, with the same command restrictions. Only
1425 commands that can appear in an early initialization file should be
1426 passed to @code{--early-init-eval-command} or @code{-eiex}.
1427
1428 @cindex general initialization
1429 In contrast, the @dfn{general initialization} files are processed
1430 later, after @value{GDBN} has finished its own internal initialization
1431 process, any valid command can be used in these files.
1432
1433 @cindex initialization file
1434 Throughout the rest of this document the term @dfn{initialization
1435 file} refers to one of the general initialization files, not the early
1436 initialization file. Any discussion of the early initialization file
1437 will specifically mention that it is the early initialization file
1438 being discussed.
1439
1440 As the system wide and home directory initialization files are
1441 processed before most command line options, changes to settings
1442 (e.g.@: @samp{set complaints}) can affect subsequent processing of
1443 command line options and operands.
1444
1445 The following sections describe where @value{GDBN} looks for the early
1446 initialization and initialization files, and the order that the files
1447 are searched for.
1448
1449 @subsubsection Home directory early initialization files
1450
1451 @value{GDBN} initially looks for an early initialization file in the
1452 users home directory@footnote{On DOS/Windows systems, the home
1453 directory is the one pointed to by the @env{HOME} environment
1454 variable.}. There are a number of locations that @value{GDBN} will
1455 search in the home directory, these locations are searched in order
1456 and @value{GDBN} will load the first file that it finds, and
1457 subsequent locations will not be checked.
1458
1459 On non-macOS hosts the locations searched are:
1460 @itemize
1461 @item
1462 The file @file{gdb/gdbearlyinit} within the directory pointed to by the
1463 environment variable @env{XDG_CONFIG_HOME}, if it is defined.
1464 @item
1465 The file @file{.config/gdb/gdbearlyinit} within the directory pointed to
1466 by the environment variable @env{HOME}, if it is defined.
1467 @item
1468 The file @file{.gdbearlyinit} within the directory pointed to by the
1469 environment variable @env{HOME}, if it is defined.
1470 @end itemize
1471
1472 By contrast, on macOS hosts the locations searched are:
1473 @itemize
1474 @item
1475 The file @file{Library/Preferences/gdb/gdbearlyinit} within the
1476 directory pointed to by the environment variable @env{HOME}, if it is
1477 defined.
1478 @item
1479 The file @file{.gdbearlyinit} within the directory pointed to by the
1480 environment variable @env{HOME}, if it is defined.
1481 @end itemize
1482
1483 It is possible to prevent the home directory early initialization file
1484 from being loaded using the @samp{-nx} or @samp{-nh} command line
1485 options, @pxref{Mode Options,,Choosing Modes}.
1486
1487 @anchor{System Wide Init Files}
1488 @subsubsection System wide initialization files
1489
1490 There are two locations that are searched for system wide
1491 initialization files. Both of these locations are always checked:
1492
1493 @table @code
1494
1495 @item @file{system.gdbinit}
1496 This is a single system-wide initialization file. Its location is
1497 specified with the @code{--with-system-gdbinit} configure option
1498 (@pxref{System-wide configuration}). It is loaded first when
1499 @value{GDBN} starts, before command line options have been processed.
1500
1501 @item @file{system.gdbinit.d}
1502 This is the system-wide initialization directory. Its location is
1503 specified with the @code{--with-system-gdbinit-dir} configure option
1504 (@pxref{System-wide configuration}). Files in this directory are
1505 loaded in alphabetical order immediately after @file{system.gdbinit}
1506 (if enabled) when @value{GDBN} starts, before command line options
1507 have been processed. Files need to have a recognized scripting
1508 language extension (@file{.py}/@file{.scm}) or be named with a
1509 @file{.gdb} extension to be interpreted as regular @value{GDBN}
1510 commands. @value{GDBN} will not recurse into any subdirectories of
1511 this directory.
1512
1513 @end table
1514
1515 It is possible to prevent the system wide initialization files from
1516 being loaded using the @samp{-nx} command line option, @pxref{Mode
1517 Options,,Choosing Modes}.
1518
1519 @anchor{Home Directory Init File}
1520 @subsubsection Home directory initialization file
1521 @cindex @file{gdbinit}
1522 @cindex @file{.gdbinit}
1523 @cindex @file{gdb.ini}
1524
1525 After loading the system wide initialization files @value{GDBN} will
1526 look for an initialization file in the users home
1527 directory@footnote{On DOS/Windows systems, the home directory is the
1528 one pointed to by the @env{HOME} environment variable.}. There are a
1529 number of locations that @value{GDBN} will search in the home
1530 directory, these locations are searched in order and @value{GDBN} will
1531 load the first file that it finds, and subsequent locations will not
1532 be checked.
1533
1534 On non-Apple hosts the locations searched are:
1535 @table @file
1536 @item $XDG_CONFIG_HOME/gdb/gdbinit
1537 @item $HOME/.config/gdb/gdbinit
1538 @item $HOME/.gdbinit
1539 @end table
1540
1541 While on Apple hosts the locations searched are:
1542 @table @file
1543 @item $HOME/Library/Preferences/gdb/gdbinit
1544 @item $HOME/.gdbinit
1545 @end table
1546
1547 It is possible to prevent the home directory initialization file from
1548 being loaded using the @samp{-nx} or @samp{-nh} command line options,
1549 @pxref{Mode Options,,Choosing Modes}.
1550
1551 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1552 @file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1553 names imposed by DOS filesystems. The Windows port of @value{GDBN}
1554 uses the standard name, but if it finds a @file{gdb.ini} file in your
1555 home directory, it warns you about that and suggests to rename the
1556 file to the standard name.
1557
1558 @anchor{Init File in the Current Directory during Startup}
1559 @subsubsection Local directory initialization file
1560
1561 @value{GDBN} will check the current directory for a file called
1562 @file{.gdbinit}. It is loaded last, after command line options
1563 other than @samp{-x} and @samp{-ex} have been processed. The command
1564 line options @samp{-x} and @samp{-ex} are processed last, after
1565 @file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1566 Files}.
1567
1568 If the file in the current directory was already loaded as the home
1569 directory initialization file then it will not be loaded a second
1570 time.
1571
1572 It is possible to prevent the local directory initialization file from
1573 being loaded using the @samp{-nx} command line option, @pxref{Mode
1574 Options,,Choosing Modes}.
1575
1576 @node Quitting GDB
1577 @section Quitting @value{GDBN}
1578 @cindex exiting @value{GDBN}
1579 @cindex leaving @value{GDBN}
1580
1581 @table @code
1582 @kindex quit @r{[}@var{expression}@r{]}
1583 @kindex exit @r{[}@var{expression}@r{]}
1584 @kindex q @r{(@code{quit})}
1585 @item quit @r{[}@var{expression}@r{]}
1586 @itemx exit @r{[}@var{expression}@r{]}
1587 @itemx q
1588 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1589 @code{q}), the @code{exit} command, or type an end-of-file
1590 character (usually @kbd{Ctrl-d}). If you do not supply @var{expression},
1591 @value{GDBN} will terminate normally; otherwise it will terminate using
1592 the result of @var{expression} as the error code.
1593 @end table
1594
1595 @cindex interrupt
1596 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1597 terminates the action of any @value{GDBN} command that is in progress and
1598 returns to @value{GDBN} command level. It is safe to type the interrupt
1599 character at any time because @value{GDBN} does not allow it to take effect
1600 until a time when it is safe.
1601
1602 If you have been using @value{GDBN} to control an attached process or
1603 device, you can release it with the @code{detach} command
1604 (@pxref{Attach, ,Debugging an Already-running Process}).
1605
1606 @node Shell Commands
1607 @section Shell Commands
1608
1609 If you need to execute occasional shell commands during your
1610 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1611 just use the @code{shell} command.
1612
1613 @table @code
1614 @kindex shell
1615 @kindex !
1616 @cindex shell escape
1617 @item shell @var{command-string}
1618 @itemx !@var{command-string}
1619 Invoke a standard shell to execute @var{command-string}.
1620 Note that no space is needed between @code{!} and @var{command-string}.
1621 On GNU and Unix systems, the environment variable @env{SHELL}, if it
1622 exists, determines which shell to run. Otherwise @value{GDBN} uses
1623 the default shell (@file{/bin/sh} on GNU and Unix systems,
1624 @file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1625 @end table
1626
1627 The utility @code{make} is often needed in development environments.
1628 You do not have to use the @code{shell} command for this purpose in
1629 @value{GDBN}:
1630
1631 @table @code
1632 @kindex make
1633 @cindex calling make
1634 @item make @var{make-args}
1635 Execute the @code{make} program with the specified
1636 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1637 @end table
1638
1639 @table @code
1640 @kindex pipe
1641 @kindex |
1642 @cindex send the output of a gdb command to a shell command
1643 @anchor{pipe}
1644 @item pipe [@var{command}] | @var{shell_command}
1645 @itemx | [@var{command}] | @var{shell_command}
1646 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1647 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1648 Executes @var{command} and sends its output to @var{shell_command}.
1649 Note that no space is needed around @code{|}.
1650 If no @var{command} is provided, the last command executed is repeated.
1651
1652 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1653 can be used to specify an alternate delimiter string @var{delim} that separates
1654 the @var{command} from the @var{shell_command}.
1655
1656 Example:
1657 @smallexample
1658 @group
1659 (gdb) p var
1660 $1 = @{
1661 black = 144,
1662 red = 233,
1663 green = 377,
1664 blue = 610,
1665 white = 987
1666 @}
1667 @end group
1668 @group
1669 (gdb) pipe p var|wc
1670 7 19 80
1671 (gdb) |p var|wc -l
1672 7
1673 @end group
1674 @group
1675 (gdb) p /x var
1676 $4 = @{
1677 black = 0x90,
1678 red = 0xe9,
1679 green = 0x179,
1680 blue = 0x262,
1681 white = 0x3db
1682 @}
1683 (gdb) ||grep red
1684 red => 0xe9,
1685 @end group
1686 @group
1687 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1688 this contains a PIPE char
1689 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1690 this contains a PIPE char!
1691 (gdb)
1692 @end group
1693 @end smallexample
1694 @end table
1695
1696 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1697 can be used to examine the exit status of the last shell command launched
1698 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1699 @xref{Convenience Vars,, Convenience Variables}.
1700
1701 @node Logging Output
1702 @section Logging Output
1703 @cindex logging @value{GDBN} output
1704 @cindex save @value{GDBN} output to a file
1705
1706 You may want to save the output of @value{GDBN} commands to a file.
1707 There are several commands to control @value{GDBN}'s logging.
1708
1709 @table @code
1710 @kindex set logging enabled
1711 @item set logging enabled [on|off]
1712 Enable or disable logging.
1713 @cindex logging file name
1714 @item set logging file @var{file}
1715 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1716 @item set logging overwrite [on|off]
1717 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1718 you want @code{set logging enabled on} to overwrite the logfile instead.
1719 @item set logging redirect [on|off]
1720 By default, @value{GDBN} output will go to both the terminal and the logfile.
1721 Set @code{redirect} if you want output to go only to the log file.
1722 @item set logging debugredirect [on|off]
1723 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1724 Set @code{debugredirect} if you want debug output to go only to the log file.
1725 @kindex show logging
1726 @item show logging
1727 Show the current values of the logging settings.
1728 @end table
1729
1730 You can also redirect the output of a @value{GDBN} command to a
1731 shell command. @xref{pipe}.
1732 @node Commands
1733 @chapter @value{GDBN} Commands
1734
1735 You can abbreviate a @value{GDBN} command to the first few letters of the command
1736 name, if that abbreviation is unambiguous; and you can repeat certain
1737 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1738 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1739 show you the alternatives available, if there is more than one possibility).
1740
1741 @menu
1742 * Command Syntax:: How to give commands to @value{GDBN}
1743 * Command Settings:: How to change default behavior of commands
1744 * Completion:: Command completion
1745 * Command Options:: Command options
1746 * Help:: How to ask @value{GDBN} for help
1747 @end menu
1748
1749 @node Command Syntax
1750 @section Command Syntax
1751
1752 A @value{GDBN} command is a single line of input. There is no limit on
1753 how long it can be. It starts with a command name, which is followed by
1754 arguments whose meaning depends on the command name. For example, the
1755 command @code{step} accepts an argument which is the number of times to
1756 step, as in @samp{step 5}. You can also use the @code{step} command
1757 with no arguments. Some commands do not allow any arguments.
1758
1759 @cindex abbreviation
1760 @value{GDBN} command names may always be truncated if that abbreviation is
1761 unambiguous. Other possible command abbreviations are listed in the
1762 documentation for individual commands. In some cases, even ambiguous
1763 abbreviations are allowed; for example, @code{s} is specially defined as
1764 equivalent to @code{step} even though there are other commands whose
1765 names start with @code{s}. You can test abbreviations by using them as
1766 arguments to the @code{help} command.
1767
1768 @cindex repeating commands
1769 @kindex RET @r{(repeat last command)}
1770 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1771 repeat the previous command. Certain commands (for example, @code{run})
1772 will not repeat this way; these are commands whose unintentional
1773 repetition might cause trouble and which you are unlikely to want to
1774 repeat. User-defined commands can disable this feature; see
1775 @ref{Define, dont-repeat}.
1776
1777 The @code{list} and @code{x} commands, when you repeat them with
1778 @key{RET}, construct new arguments rather than repeating
1779 exactly as typed. This permits easy scanning of source or memory.
1780
1781 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1782 output, in a way similar to the common utility @code{more}
1783 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1784 @key{RET} too many in this situation, @value{GDBN} disables command
1785 repetition after any command that generates this sort of display.
1786
1787 @kindex # @r{(a comment)}
1788 @cindex comment
1789 Any text from a @kbd{#} to the end of the line is a comment; it does
1790 nothing. This is useful mainly in command files (@pxref{Command
1791 Files,,Command Files}).
1792
1793 @cindex repeating command sequences
1794 @kindex Ctrl-o @r{(operate-and-get-next)}
1795 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1796 commands. This command accepts the current line, like @key{RET}, and
1797 then fetches the next line relative to the current line from the history
1798 for editing.
1799
1800
1801 @node Command Settings
1802 @section Command Settings
1803 @cindex default behavior of commands, changing
1804 @cindex default settings, changing
1805
1806 Many commands change their behavior according to command-specific
1807 variables or settings. These settings can be changed with the
1808 @code{set} subcommands. For example, the @code{print} command
1809 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1810 settings changeable with the commands @code{set print elements
1811 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1812
1813 You can change these settings to your preference in the gdbinit files
1814 loaded at @value{GDBN} startup. @xref{Startup}.
1815
1816 The settings can also be changed interactively during the debugging
1817 session. For example, to change the limit of array elements to print,
1818 you can do the following:
1819 @smallexample
1820 (@value{GDBN}) set print elements 10
1821 (@value{GDBN}) print some_array
1822 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1823 @end smallexample
1824
1825 The above @code{set print elements 10} command changes the number of
1826 elements to print from the default of 200 to 10. If you only intend
1827 this limit of 10 to be used for printing @code{some_array}, then you
1828 must restore the limit back to 200, with @code{set print elements
1829 200}.
1830
1831 Some commands allow overriding settings with command options. For
1832 example, the @code{print} command supports a number of options that
1833 allow overriding relevant global print settings as set by @code{set
1834 print} subcommands. @xref{print options}. The example above could be
1835 rewritten as:
1836 @smallexample
1837 (@value{GDBN}) print -elements 10 -- some_array
1838 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1839 @end smallexample
1840
1841 Alternatively, you can use the @code{with} command to change a setting
1842 temporarily, for the duration of a command invocation.
1843
1844 @table @code
1845 @kindex with command
1846 @kindex w @r{(@code{with})}
1847 @cindex settings
1848 @cindex temporarily change settings
1849 @item with @var{setting} [@var{value}] [-- @var{command}]
1850 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1851 Temporarily set @var{setting} to @var{value} for the duration of
1852 @var{command}.
1853
1854 @var{setting} is any setting you can change with the @code{set}
1855 subcommands. @var{value} is the value to assign to @code{setting}
1856 while running @code{command}.
1857
1858 If no @var{command} is provided, the last command executed is
1859 repeated.
1860
1861 If a @var{command} is provided, it must be preceded by a double dash
1862 (@code{--}) separator. This is required because some settings accept
1863 free-form arguments, such as expressions or filenames.
1864
1865 For example, the command
1866 @smallexample
1867 (@value{GDBN}) with print array on -- print some_array
1868 @end smallexample
1869 @noindent
1870 is equivalent to the following 3 commands:
1871 @smallexample
1872 (@value{GDBN}) set print array on
1873 (@value{GDBN}) print some_array
1874 (@value{GDBN}) set print array off
1875 @end smallexample
1876
1877 The @code{with} command is particularly useful when you want to
1878 override a setting while running user-defined commands, or commands
1879 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1880
1881 @smallexample
1882 (@value{GDBN}) with print pretty on -- my_complex_command
1883 @end smallexample
1884
1885 To change several settings for the same command, you can nest
1886 @code{with} commands. For example, @code{with language ada -- with
1887 print elements 10} temporarily changes the language to Ada and sets a
1888 limit of 10 elements to print for arrays and strings.
1889
1890 @end table
1891
1892 @node Completion
1893 @section Command Completion
1894
1895 @cindex completion
1896 @cindex word completion
1897 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1898 only one possibility; it can also show you what the valid possibilities
1899 are for the next word in a command, at any time. This works for @value{GDBN}
1900 commands, @value{GDBN} subcommands, command options, and the names of symbols
1901 in your program.
1902
1903 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1904 of a word. If there is only one possibility, @value{GDBN} fills in the
1905 word, and waits for you to finish the command (or press @key{RET} to
1906 enter it). For example, if you type
1907
1908 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1909 @c complete accuracy in these examples; space introduced for clarity.
1910 @c If texinfo enhancements make it unnecessary, it would be nice to
1911 @c replace " @key" by "@key" in the following...
1912 @smallexample
1913 (@value{GDBP}) info bre @key{TAB}
1914 @end smallexample
1915
1916 @noindent
1917 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1918 the only @code{info} subcommand beginning with @samp{bre}:
1919
1920 @smallexample
1921 (@value{GDBP}) info breakpoints
1922 @end smallexample
1923
1924 @noindent
1925 You can either press @key{RET} at this point, to run the @code{info
1926 breakpoints} command, or backspace and enter something else, if
1927 @samp{breakpoints} does not look like the command you expected. (If you
1928 were sure you wanted @code{info breakpoints} in the first place, you
1929 might as well just type @key{RET} immediately after @samp{info bre},
1930 to exploit command abbreviations rather than command completion).
1931
1932 If there is more than one possibility for the next word when you press
1933 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1934 characters and try again, or just press @key{TAB} a second time;
1935 @value{GDBN} displays all the possible completions for that word. For
1936 example, you might want to set a breakpoint on a subroutine whose name
1937 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1938 just sounds the bell. Typing @key{TAB} again displays all the
1939 function names in your program that begin with those characters, for
1940 example:
1941
1942 @smallexample
1943 (@value{GDBP}) b make_ @key{TAB}
1944 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1945 make_a_section_from_file make_environ
1946 make_abs_section make_function_type
1947 make_blockvector make_pointer_type
1948 make_cleanup make_reference_type
1949 make_command make_symbol_completion_list
1950 (@value{GDBP}) b make_
1951 @end smallexample
1952
1953 @noindent
1954 After displaying the available possibilities, @value{GDBN} copies your
1955 partial input (@samp{b make_} in the example) so you can finish the
1956 command.
1957
1958 If you just want to see the list of alternatives in the first place, you
1959 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1960 means @kbd{@key{META} ?}. You can type this either by holding down a
1961 key designated as the @key{META} shift on your keyboard (if there is
1962 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1963
1964 If the number of possible completions is large, @value{GDBN} will
1965 print as much of the list as it has collected, as well as a message
1966 indicating that the list may be truncated.
1967
1968 @smallexample
1969 (@value{GDBP}) b m@key{TAB}@key{TAB}
1970 main
1971 <... the rest of the possible completions ...>
1972 *** List may be truncated, max-completions reached. ***
1973 (@value{GDBP}) b m
1974 @end smallexample
1975
1976 @noindent
1977 This behavior can be controlled with the following commands:
1978
1979 @table @code
1980 @kindex set max-completions
1981 @item set max-completions @var{limit}
1982 @itemx set max-completions unlimited
1983 Set the maximum number of completion candidates. @value{GDBN} will
1984 stop looking for more completions once it collects this many candidates.
1985 This is useful when completing on things like function names as collecting
1986 all the possible candidates can be time consuming.
1987 The default value is 200. A value of zero disables tab-completion.
1988 Note that setting either no limit or a very large limit can make
1989 completion slow.
1990 @kindex show max-completions
1991 @item show max-completions
1992 Show the maximum number of candidates that @value{GDBN} will collect and show
1993 during completion.
1994 @end table
1995
1996 @cindex quotes in commands
1997 @cindex completion of quoted strings
1998 Sometimes the string you need, while logically a ``word'', may contain
1999 parentheses or other characters that @value{GDBN} normally excludes from
2000 its notion of a word. To permit word completion to work in this
2001 situation, you may enclose words in @code{'} (single quote marks) in
2002 @value{GDBN} commands.
2003
2004 A likely situation where you might need this is in typing an
2005 expression that involves a C@t{++} symbol name with template
2006 parameters. This is because when completing expressions, GDB treats
2007 the @samp{<} character as word delimiter, assuming that it's the
2008 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
2009 Operators}).
2010
2011 For example, when you want to call a C@t{++} template function
2012 interactively using the @code{print} or @code{call} commands, you may
2013 need to distinguish whether you mean the version of @code{name} that
2014 was specialized for @code{int}, @code{name<int>()}, or the version
2015 that was specialized for @code{float}, @code{name<float>()}. To use
2016 the word-completion facilities in this situation, type a single quote
2017 @code{'} at the beginning of the function name. This alerts
2018 @value{GDBN} that it may need to consider more information than usual
2019 when you press @key{TAB} or @kbd{M-?} to request word completion:
2020
2021 @smallexample
2022 (@value{GDBP}) p 'func< @kbd{M-?}
2023 func<int>() func<float>()
2024 (@value{GDBP}) p 'func<
2025 @end smallexample
2026
2027 When setting breakpoints however (@pxref{Specify Location}), you don't
2028 usually need to type a quote before the function name, because
2029 @value{GDBN} understands that you want to set a breakpoint on a
2030 function:
2031
2032 @smallexample
2033 (@value{GDBP}) b func< @kbd{M-?}
2034 func<int>() func<float>()
2035 (@value{GDBP}) b func<
2036 @end smallexample
2037
2038 This is true even in the case of typing the name of C@t{++} overloaded
2039 functions (multiple definitions of the same function, distinguished by
2040 argument type). For example, when you want to set a breakpoint you
2041 don't need to distinguish whether you mean the version of @code{name}
2042 that takes an @code{int} parameter, @code{name(int)}, or the version
2043 that takes a @code{float} parameter, @code{name(float)}.
2044
2045 @smallexample
2046 (@value{GDBP}) b bubble( @kbd{M-?}
2047 bubble(int) bubble(double)
2048 (@value{GDBP}) b bubble(dou @kbd{M-?}
2049 bubble(double)
2050 @end smallexample
2051
2052 See @ref{quoting names} for a description of other scenarios that
2053 require quoting.
2054
2055 For more information about overloaded functions, see @ref{C Plus Plus
2056 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
2057 overload-resolution off} to disable overload resolution;
2058 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
2059
2060 @cindex completion of structure field names
2061 @cindex structure field name completion
2062 @cindex completion of union field names
2063 @cindex union field name completion
2064 When completing in an expression which looks up a field in a
2065 structure, @value{GDBN} also tries@footnote{The completer can be
2066 confused by certain kinds of invalid expressions. Also, it only
2067 examines the static type of the expression, not the dynamic type.} to
2068 limit completions to the field names available in the type of the
2069 left-hand-side:
2070
2071 @smallexample
2072 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
2073 magic to_fputs to_rewind
2074 to_data to_isatty to_write
2075 to_delete to_put to_write_async_safe
2076 to_flush to_read
2077 @end smallexample
2078
2079 @noindent
2080 This is because the @code{gdb_stdout} is a variable of the type
2081 @code{struct ui_file} that is defined in @value{GDBN} sources as
2082 follows:
2083
2084 @smallexample
2085 struct ui_file
2086 @{
2087 int *magic;
2088 ui_file_flush_ftype *to_flush;
2089 ui_file_write_ftype *to_write;
2090 ui_file_write_async_safe_ftype *to_write_async_safe;
2091 ui_file_fputs_ftype *to_fputs;
2092 ui_file_read_ftype *to_read;
2093 ui_file_delete_ftype *to_delete;
2094 ui_file_isatty_ftype *to_isatty;
2095 ui_file_rewind_ftype *to_rewind;
2096 ui_file_put_ftype *to_put;
2097 void *to_data;
2098 @}
2099 @end smallexample
2100
2101 @node Command Options
2102 @section Command options
2103
2104 @cindex command options
2105 Some commands accept options starting with a leading dash. For
2106 example, @code{print -pretty}. Similarly to command names, you can
2107 abbreviate a @value{GDBN} option to the first few letters of the
2108 option name, if that abbreviation is unambiguous, and you can also use
2109 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2110 in an option (or to show you the alternatives available, if there is
2111 more than one possibility).
2112
2113 @cindex command options, raw input
2114 Some commands take raw input as argument. For example, the print
2115 command processes arbitrary expressions in any of the languages
2116 supported by @value{GDBN}. With such commands, because raw input may
2117 start with a leading dash that would be confused with an option or any
2118 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2119 -pretty} or printing negative @code{p}?), if you specify any command
2120 option, then you must use a double-dash (@code{--}) delimiter to
2121 indicate the end of options.
2122
2123 @cindex command options, boolean
2124
2125 Some options are described as accepting an argument which can be
2126 either @code{on} or @code{off}. These are known as @dfn{boolean
2127 options}. Similarly to boolean settings commands---@code{on} and
2128 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2129 @code{enable} can also be used as ``true'' value, and any of @code{0},
2130 @code{no} and @code{disable} can also be used as ``false'' value. You
2131 can also omit a ``true'' value, as it is implied by default.
2132
2133 For example, these are equivalent:
2134
2135 @smallexample
2136 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2137 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2138 @end smallexample
2139
2140 You can discover the set of options some command accepts by completing
2141 on @code{-} after the command name. For example:
2142
2143 @smallexample
2144 (@value{GDBP}) print -@key{TAB}@key{TAB}
2145 -address -max-depth -pretty -symbol
2146 -array -memory-tag-violations -raw-values -union
2147 -array-indexes -null-stop -repeats -vtbl
2148 -elements -object -static-members
2149 @end smallexample
2150
2151 Completion will in some cases guide you with a suggestion of what kind
2152 of argument an option expects. For example:
2153
2154 @smallexample
2155 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2156 NUMBER unlimited
2157 @end smallexample
2158
2159 Here, the option expects a number (e.g., @code{100}), not literal
2160 @code{NUMBER}. Such metasyntactical arguments are always presented in
2161 uppercase.
2162
2163 (For more on using the @code{print} command, see @ref{Data, ,Examining
2164 Data}.)
2165
2166 @node Help
2167 @section Getting Help
2168 @cindex online documentation
2169 @kindex help
2170
2171 You can always ask @value{GDBN} itself for information on its commands,
2172 using the command @code{help}.
2173
2174 @table @code
2175 @kindex h @r{(@code{help})}
2176 @item help
2177 @itemx h
2178 You can use @code{help} (abbreviated @code{h}) with no arguments to
2179 display a short list of named classes of commands:
2180
2181 @smallexample
2182 (@value{GDBP}) help
2183 List of classes of commands:
2184
2185 aliases -- User-defined aliases of other commands
2186 breakpoints -- Making program stop at certain points
2187 data -- Examining data
2188 files -- Specifying and examining files
2189 internals -- Maintenance commands
2190 obscure -- Obscure features
2191 running -- Running the program
2192 stack -- Examining the stack
2193 status -- Status inquiries
2194 support -- Support facilities
2195 tracepoints -- Tracing of program execution without
2196 stopping the program
2197 user-defined -- User-defined commands
2198
2199 Type "help" followed by a class name for a list of
2200 commands in that class.
2201 Type "help" followed by command name for full
2202 documentation.
2203 Command name abbreviations are allowed if unambiguous.
2204 (@value{GDBP})
2205 @end smallexample
2206 @c the above line break eliminates huge line overfull...
2207
2208 @item help @var{class}
2209 Using one of the general help classes as an argument, you can get a
2210 list of the individual commands in that class. If a command has
2211 aliases, the aliases are given after the command name, separated by
2212 commas. If an alias has default arguments, the full definition of
2213 the alias is given after the first line.
2214 For example, here is the help display for the class @code{status}:
2215
2216 @smallexample
2217 (@value{GDBP}) help status
2218 Status inquiries.
2219
2220 List of commands:
2221
2222 @c Line break in "show" line falsifies real output, but needed
2223 @c to fit in smallbook page size.
2224 info, inf, i -- Generic command for showing things
2225 about the program being debugged
2226 info address, iamain -- Describe where symbol SYM is stored.
2227 alias iamain = info address main
2228 info all-registers -- List of all registers and their contents,
2229 for selected stack frame.
2230 ...
2231 show, info set -- Generic command for showing things
2232 about the debugger
2233
2234 Type "help" followed by command name for full
2235 documentation.
2236 Command name abbreviations are allowed if unambiguous.
2237 (@value{GDBP})
2238 @end smallexample
2239
2240 @item help @var{command}
2241 With a command name as @code{help} argument, @value{GDBN} displays a
2242 short paragraph on how to use that command. If that command has
2243 one or more aliases, @value{GDBN} will display a first line with
2244 the command name and all its aliases separated by commas.
2245 This first line will be followed by the full definition of all aliases
2246 having default arguments.
2247
2248 @kindex apropos
2249 @item apropos [-v] @var{regexp}
2250 The @code{apropos} command searches through all of the @value{GDBN}
2251 commands, and their documentation, for the regular expression specified in
2252 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2253 which stands for @samp{verbose}, indicates to output the full documentation
2254 of the matching commands and highlight the parts of the documentation
2255 matching @var{regexp}. For example:
2256
2257 @smallexample
2258 apropos alias
2259 @end smallexample
2260
2261 @noindent
2262 results in:
2263
2264 @smallexample
2265 @group
2266 alias -- Define a new command that is an alias of an existing command
2267 aliases -- User-defined aliases of other commands
2268 @end group
2269 @end smallexample
2270
2271 @noindent
2272 while
2273
2274 @smallexample
2275 apropos -v cut.*thread apply
2276 @end smallexample
2277
2278 @noindent
2279 results in the below output, where @samp{cut for 'thread apply}
2280 is highlighted if styling is enabled.
2281
2282 @smallexample
2283 @group
2284 taas -- Apply a command to all threads (ignoring errors
2285 and empty output).
2286 Usage: taas COMMAND
2287 shortcut for 'thread apply all -s COMMAND'
2288
2289 tfaas -- Apply a command to all frames of all threads
2290 (ignoring errors and empty output).
2291 Usage: tfaas COMMAND
2292 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2293 @end group
2294 @end smallexample
2295
2296 @kindex complete
2297 @item complete @var{args}
2298 The @code{complete @var{args}} command lists all the possible completions
2299 for the beginning of a command. Use @var{args} to specify the beginning of the
2300 command you want completed. For example:
2301
2302 @smallexample
2303 complete i
2304 @end smallexample
2305
2306 @noindent results in:
2307
2308 @smallexample
2309 @group
2310 if
2311 ignore
2312 info
2313 inspect
2314 @end group
2315 @end smallexample
2316
2317 @noindent This is intended for use by @sc{gnu} Emacs.
2318 @end table
2319
2320 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2321 and @code{show} to inquire about the state of your program, or the state
2322 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2323 manual introduces each of them in the appropriate context. The listings
2324 under @code{info} and under @code{show} in the Command, Variable, and
2325 Function Index point to all the sub-commands. @xref{Command and Variable
2326 Index}.
2327
2328 @c @group
2329 @table @code
2330 @kindex info
2331 @kindex i @r{(@code{info})}
2332 @item info
2333 This command (abbreviated @code{i}) is for describing the state of your
2334 program. For example, you can show the arguments passed to a function
2335 with @code{info args}, list the registers currently in use with @code{info
2336 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2337 You can get a complete list of the @code{info} sub-commands with
2338 @w{@code{help info}}.
2339
2340 @kindex set
2341 @item set
2342 You can assign the result of an expression to an environment variable with
2343 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2344 @code{set prompt $}.
2345
2346 @kindex show
2347 @item show
2348 In contrast to @code{info}, @code{show} is for describing the state of
2349 @value{GDBN} itself.
2350 You can change most of the things you can @code{show}, by using the
2351 related command @code{set}; for example, you can control what number
2352 system is used for displays with @code{set radix}, or simply inquire
2353 which is currently in use with @code{show radix}.
2354
2355 @kindex info set
2356 To display all the settable parameters and their current
2357 values, you can use @code{show} with no arguments; you may also use
2358 @code{info set}. Both commands produce the same display.
2359 @c FIXME: "info set" violates the rule that "info" is for state of
2360 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2361 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2362 @end table
2363 @c @end group
2364
2365 Here are several miscellaneous @code{show} subcommands, all of which are
2366 exceptional in lacking corresponding @code{set} commands:
2367
2368 @table @code
2369 @kindex show version
2370 @cindex @value{GDBN} version number
2371 @item show version
2372 Show what version of @value{GDBN} is running. You should include this
2373 information in @value{GDBN} bug-reports. If multiple versions of
2374 @value{GDBN} are in use at your site, you may need to determine which
2375 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2376 commands are introduced, and old ones may wither away. Also, many
2377 system vendors ship variant versions of @value{GDBN}, and there are
2378 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2379 The version number is the same as the one announced when you start
2380 @value{GDBN}.
2381
2382 @kindex show copying
2383 @kindex info copying
2384 @cindex display @value{GDBN} copyright
2385 @item show copying
2386 @itemx info copying
2387 Display information about permission for copying @value{GDBN}.
2388
2389 @kindex show warranty
2390 @kindex info warranty
2391 @item show warranty
2392 @itemx info warranty
2393 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2394 if your version of @value{GDBN} comes with one.
2395
2396 @kindex show configuration
2397 @item show configuration
2398 Display detailed information about the way @value{GDBN} was configured
2399 when it was built. This displays the optional arguments passed to the
2400 @file{configure} script and also configuration parameters detected
2401 automatically by @command{configure}. When reporting a @value{GDBN}
2402 bug (@pxref{GDB Bugs}), it is important to include this information in
2403 your report.
2404
2405 @end table
2406
2407 @node Running
2408 @chapter Running Programs Under @value{GDBN}
2409
2410 When you run a program under @value{GDBN}, you must first generate
2411 debugging information when you compile it.
2412
2413 You may start @value{GDBN} with its arguments, if any, in an environment
2414 of your choice. If you are doing native debugging, you may redirect
2415 your program's input and output, debug an already running process, or
2416 kill a child process.
2417
2418 @menu
2419 * Compilation:: Compiling for debugging
2420 * Starting:: Starting your program
2421 * Arguments:: Your program's arguments
2422 * Environment:: Your program's environment
2423
2424 * Working Directory:: Your program's working directory
2425 * Input/Output:: Your program's input and output
2426 * Attach:: Debugging an already-running process
2427 * Kill Process:: Killing the child process
2428 * Inferiors Connections and Programs:: Debugging multiple inferiors
2429 connections and programs
2430 * Threads:: Debugging programs with multiple threads
2431 * Forks:: Debugging forks
2432 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2433 @end menu
2434
2435 @node Compilation
2436 @section Compiling for Debugging
2437
2438 In order to debug a program effectively, you need to generate
2439 debugging information when you compile it. This debugging information
2440 is stored in the object file; it describes the data type of each
2441 variable or function and the correspondence between source line numbers
2442 and addresses in the executable code.
2443
2444 To request debugging information, specify the @samp{-g} option when you run
2445 the compiler.
2446
2447 Programs that are to be shipped to your customers are compiled with
2448 optimizations, using the @samp{-O} compiler option. However, some
2449 compilers are unable to handle the @samp{-g} and @samp{-O} options
2450 together. Using those compilers, you cannot generate optimized
2451 executables containing debugging information.
2452
2453 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2454 without @samp{-O}, making it possible to debug optimized code. We
2455 recommend that you @emph{always} use @samp{-g} whenever you compile a
2456 program. You may think your program is correct, but there is no sense
2457 in pushing your luck. For more information, see @ref{Optimized Code}.
2458
2459 Older versions of the @sc{gnu} C compiler permitted a variant option
2460 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2461 format; if your @sc{gnu} C compiler has this option, do not use it.
2462
2463 @value{GDBN} knows about preprocessor macros and can show you their
2464 expansion (@pxref{Macros}). Most compilers do not include information
2465 about preprocessor macros in the debugging information if you specify
2466 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2467 the @sc{gnu} C compiler, provides macro information if you are using
2468 the DWARF debugging format, and specify the option @option{-g3}.
2469
2470 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2471 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2472 information on @value{NGCC} options affecting debug information.
2473
2474 You will have the best debugging experience if you use the latest
2475 version of the DWARF debugging format that your compiler supports.
2476 DWARF is currently the most expressive and best supported debugging
2477 format in @value{GDBN}.
2478
2479 @need 2000
2480 @node Starting
2481 @section Starting your Program
2482 @cindex starting
2483 @cindex running
2484
2485 @table @code
2486 @kindex run
2487 @kindex r @r{(@code{run})}
2488 @item run
2489 @itemx r
2490 Use the @code{run} command to start your program under @value{GDBN}.
2491 You must first specify the program name with an argument to
2492 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2493 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2494 command (@pxref{Files, ,Commands to Specify Files}).
2495
2496 @end table
2497
2498 If you are running your program in an execution environment that
2499 supports processes, @code{run} creates an inferior process and makes
2500 that process run your program. In some environments without processes,
2501 @code{run} jumps to the start of your program. Other targets,
2502 like @samp{remote}, are always running. If you get an error
2503 message like this one:
2504
2505 @smallexample
2506 The "remote" target does not support "run".
2507 Try "help target" or "continue".
2508 @end smallexample
2509
2510 @noindent
2511 then use @code{continue} to run your program. You may need @code{load}
2512 first (@pxref{load}).
2513
2514 The execution of a program is affected by certain information it
2515 receives from its superior. @value{GDBN} provides ways to specify this
2516 information, which you must do @emph{before} starting your program. (You
2517 can change it after starting your program, but such changes only affect
2518 your program the next time you start it.) This information may be
2519 divided into four categories:
2520
2521 @table @asis
2522 @item The @emph{arguments.}
2523 Specify the arguments to give your program as the arguments of the
2524 @code{run} command. If a shell is available on your target, the shell
2525 is used to pass the arguments, so that you may use normal conventions
2526 (such as wildcard expansion or variable substitution) in describing
2527 the arguments.
2528 In Unix systems, you can control which shell is used with the
2529 @env{SHELL} environment variable. If you do not define @env{SHELL},
2530 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2531 use of any shell with the @code{set startup-with-shell} command (see
2532 below for details).
2533
2534 @item The @emph{environment.}
2535 Your program normally inherits its environment from @value{GDBN}, but you can
2536 use the @value{GDBN} commands @code{set environment} and @code{unset
2537 environment} to change parts of the environment that affect
2538 your program. @xref{Environment, ,Your Program's Environment}.
2539
2540 @item The @emph{working directory.}
2541 You can set your program's working directory with the command
2542 @kbd{set cwd}. If you do not set any working directory with this
2543 command, your program will inherit @value{GDBN}'s working directory if
2544 native debugging, or the remote server's working directory if remote
2545 debugging. @xref{Working Directory, ,Your Program's Working
2546 Directory}.
2547
2548 @item The @emph{standard input and output.}
2549 Your program normally uses the same device for standard input and
2550 standard output as @value{GDBN} is using. You can redirect input and output
2551 in the @code{run} command line, or you can use the @code{tty} command to
2552 set a different device for your program.
2553 @xref{Input/Output, ,Your Program's Input and Output}.
2554
2555 @cindex pipes
2556 @emph{Warning:} While input and output redirection work, you cannot use
2557 pipes to pass the output of the program you are debugging to another
2558 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2559 wrong program.
2560 @end table
2561
2562 When you issue the @code{run} command, your program begins to execute
2563 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2564 of how to arrange for your program to stop. Once your program has
2565 stopped, you may call functions in your program, using the @code{print}
2566 or @code{call} commands. @xref{Data, ,Examining Data}.
2567
2568 If the modification time of your symbol file has changed since the last
2569 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2570 table, and reads it again. When it does this, @value{GDBN} tries to retain
2571 your current breakpoints.
2572
2573 @table @code
2574 @kindex start
2575 @item start
2576 @cindex run to main procedure
2577 The name of the main procedure can vary from language to language.
2578 With C or C@t{++}, the main procedure name is always @code{main}, but
2579 other languages such as Ada do not require a specific name for their
2580 main procedure. The debugger provides a convenient way to start the
2581 execution of the program and to stop at the beginning of the main
2582 procedure, depending on the language used.
2583
2584 The @samp{start} command does the equivalent of setting a temporary
2585 breakpoint at the beginning of the main procedure and then invoking
2586 the @samp{run} command.
2587
2588 @cindex elaboration phase
2589 Some programs contain an @dfn{elaboration} phase where some startup code is
2590 executed before the main procedure is called. This depends on the
2591 languages used to write your program. In C@t{++}, for instance,
2592 constructors for static and global objects are executed before
2593 @code{main} is called. It is therefore possible that the debugger stops
2594 before reaching the main procedure. However, the temporary breakpoint
2595 will remain to halt execution.
2596
2597 Specify the arguments to give to your program as arguments to the
2598 @samp{start} command. These arguments will be given verbatim to the
2599 underlying @samp{run} command. Note that the same arguments will be
2600 reused if no argument is provided during subsequent calls to
2601 @samp{start} or @samp{run}.
2602
2603 It is sometimes necessary to debug the program during elaboration. In
2604 these cases, using the @code{start} command would stop the execution
2605 of your program too late, as the program would have already completed
2606 the elaboration phase. Under these circumstances, either insert
2607 breakpoints in your elaboration code before running your program or
2608 use the @code{starti} command.
2609
2610 @kindex starti
2611 @item starti
2612 @cindex run to first instruction
2613 The @samp{starti} command does the equivalent of setting a temporary
2614 breakpoint at the first instruction of a program's execution and then
2615 invoking the @samp{run} command. For programs containing an
2616 elaboration phase, the @code{starti} command will stop execution at
2617 the start of the elaboration phase.
2618
2619 @anchor{set exec-wrapper}
2620 @kindex set exec-wrapper
2621 @item set exec-wrapper @var{wrapper}
2622 @itemx show exec-wrapper
2623 @itemx unset exec-wrapper
2624 When @samp{exec-wrapper} is set, the specified wrapper is used to
2625 launch programs for debugging. @value{GDBN} starts your program
2626 with a shell command of the form @kbd{exec @var{wrapper}
2627 @var{program}}. Quoting is added to @var{program} and its
2628 arguments, but not to @var{wrapper}, so you should add quotes if
2629 appropriate for your shell. The wrapper runs until it executes
2630 your program, and then @value{GDBN} takes control.
2631
2632 You can use any program that eventually calls @code{execve} with
2633 its arguments as a wrapper. Several standard Unix utilities do
2634 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2635 with @code{exec "$@@"} will also work.
2636
2637 For example, you can use @code{env} to pass an environment variable to
2638 the debugged program, without setting the variable in your shell's
2639 environment:
2640
2641 @smallexample
2642 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2643 (@value{GDBP}) run
2644 @end smallexample
2645
2646 This command is available when debugging locally on most targets, excluding
2647 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2648
2649 @kindex set startup-with-shell
2650 @anchor{set startup-with-shell}
2651 @item set startup-with-shell
2652 @itemx set startup-with-shell on
2653 @itemx set startup-with-shell off
2654 @itemx show startup-with-shell
2655 On Unix systems, by default, if a shell is available on your target,
2656 @value{GDBN}) uses it to start your program. Arguments of the
2657 @code{run} command are passed to the shell, which does variable
2658 substitution, expands wildcard characters and performs redirection of
2659 I/O. In some circumstances, it may be useful to disable such use of a
2660 shell, for example, when debugging the shell itself or diagnosing
2661 startup failures such as:
2662
2663 @smallexample
2664 (@value{GDBP}) run
2665 Starting program: ./a.out
2666 During startup program terminated with signal SIGSEGV, Segmentation fault.
2667 @end smallexample
2668
2669 @noindent
2670 which indicates the shell or the wrapper specified with
2671 @samp{exec-wrapper} crashed, not your program. Most often, this is
2672 caused by something odd in your shell's non-interactive mode
2673 initialization file---such as @file{.cshrc} for C-shell,
2674 $@file{.zshenv} for the Z shell, or the file specified in the
2675 @env{BASH_ENV} environment variable for BASH.
2676
2677 @anchor{set auto-connect-native-target}
2678 @kindex set auto-connect-native-target
2679 @item set auto-connect-native-target
2680 @itemx set auto-connect-native-target on
2681 @itemx set auto-connect-native-target off
2682 @itemx show auto-connect-native-target
2683
2684 By default, if the current inferior is not connected to any target yet
2685 (e.g., with @code{target remote}), the @code{run} command starts your
2686 program as a native process under @value{GDBN}, on your local machine.
2687 If you're sure you don't want to debug programs on your local machine,
2688 you can tell @value{GDBN} to not connect to the native target
2689 automatically with the @code{set auto-connect-native-target off}
2690 command.
2691
2692 If @code{on}, which is the default, and if the current inferior is not
2693 connected to a target already, the @code{run} command automaticaly
2694 connects to the native target, if one is available.
2695
2696 If @code{off}, and if the current inferior is not connected to a
2697 target already, the @code{run} command fails with an error:
2698
2699 @smallexample
2700 (@value{GDBP}) run
2701 Don't know how to run. Try "help target".
2702 @end smallexample
2703
2704 If the current inferior is already connected to a target, @value{GDBN}
2705 always uses it with the @code{run} command.
2706
2707 In any case, you can explicitly connect to the native target with the
2708 @code{target native} command. For example,
2709
2710 @smallexample
2711 (@value{GDBP}) set auto-connect-native-target off
2712 (@value{GDBP}) run
2713 Don't know how to run. Try "help target".
2714 (@value{GDBP}) target native
2715 (@value{GDBP}) run
2716 Starting program: ./a.out
2717 [Inferior 1 (process 10421) exited normally]
2718 @end smallexample
2719
2720 In case you connected explicitly to the @code{native} target,
2721 @value{GDBN} remains connected even if all inferiors exit, ready for
2722 the next @code{run} command. Use the @code{disconnect} command to
2723 disconnect.
2724
2725 Examples of other commands that likewise respect the
2726 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2727 proc}, @code{info os}.
2728
2729 @kindex set disable-randomization
2730 @item set disable-randomization
2731 @itemx set disable-randomization on
2732 This option (enabled by default in @value{GDBN}) will turn off the native
2733 randomization of the virtual address space of the started program. This option
2734 is useful for multiple debugging sessions to make the execution better
2735 reproducible and memory addresses reusable across debugging sessions.
2736
2737 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2738 On @sc{gnu}/Linux you can get the same behavior using
2739
2740 @smallexample
2741 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2742 @end smallexample
2743
2744 @item set disable-randomization off
2745 Leave the behavior of the started executable unchanged. Some bugs rear their
2746 ugly heads only when the program is loaded at certain addresses. If your bug
2747 disappears when you run the program under @value{GDBN}, that might be because
2748 @value{GDBN} by default disables the address randomization on platforms, such
2749 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2750 disable-randomization off} to try to reproduce such elusive bugs.
2751
2752 On targets where it is available, virtual address space randomization
2753 protects the programs against certain kinds of security attacks. In these
2754 cases the attacker needs to know the exact location of a concrete executable
2755 code. Randomizing its location makes it impossible to inject jumps misusing
2756 a code at its expected addresses.
2757
2758 Prelinking shared libraries provides a startup performance advantage but it
2759 makes addresses in these libraries predictable for privileged processes by
2760 having just unprivileged access at the target system. Reading the shared
2761 library binary gives enough information for assembling the malicious code
2762 misusing it. Still even a prelinked shared library can get loaded at a new
2763 random address just requiring the regular relocation process during the
2764 startup. Shared libraries not already prelinked are always loaded at
2765 a randomly chosen address.
2766
2767 Position independent executables (PIE) contain position independent code
2768 similar to the shared libraries and therefore such executables get loaded at
2769 a randomly chosen address upon startup. PIE executables always load even
2770 already prelinked shared libraries at a random address. You can build such
2771 executable using @command{gcc -fPIE -pie}.
2772
2773 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2774 (as long as the randomization is enabled).
2775
2776 @item show disable-randomization
2777 Show the current setting of the explicit disable of the native randomization of
2778 the virtual address space of the started program.
2779
2780 @end table
2781
2782 @node Arguments
2783 @section Your Program's Arguments
2784
2785 @cindex arguments (to your program)
2786 The arguments to your program can be specified by the arguments of the
2787 @code{run} command.
2788 They are passed to a shell, which expands wildcard characters and
2789 performs redirection of I/O, and thence to your program. Your
2790 @env{SHELL} environment variable (if it exists) specifies what shell
2791 @value{GDBN} uses. If you do not define @env{SHELL}, @value{GDBN} uses
2792 the default shell (@file{/bin/sh} on Unix).
2793
2794 On non-Unix systems, the program is usually invoked directly by
2795 @value{GDBN}, which emulates I/O redirection via the appropriate system
2796 calls, and the wildcard characters are expanded by the startup code of
2797 the program, not by the shell.
2798
2799 @code{run} with no arguments uses the same arguments used by the previous
2800 @code{run}, or those set by the @code{set args} command.
2801
2802 @table @code
2803 @kindex set args
2804 @item set args
2805 Specify the arguments to be used the next time your program is run. If
2806 @code{set args} has no arguments, @code{run} executes your program
2807 with no arguments. Once you have run your program with arguments,
2808 using @code{set args} before the next @code{run} is the only way to run
2809 it again without arguments.
2810
2811 @kindex show args
2812 @item show args
2813 Show the arguments to give your program when it is started.
2814 @end table
2815
2816 @node Environment
2817 @section Your Program's Environment
2818
2819 @cindex environment (of your program)
2820 The @dfn{environment} consists of a set of environment variables and
2821 their values. Environment variables conventionally record such things as
2822 your user name, your home directory, your terminal type, and your search
2823 path for programs to run. Usually you set up environment variables with
2824 the shell and they are inherited by all the other programs you run. When
2825 debugging, it can be useful to try running your program with a modified
2826 environment without having to start @value{GDBN} over again.
2827
2828 @table @code
2829 @kindex path
2830 @item path @var{directory}
2831 Add @var{directory} to the front of the @env{PATH} environment variable
2832 (the search path for executables) that will be passed to your program.
2833 The value of @env{PATH} used by @value{GDBN} does not change.
2834 You may specify several directory names, separated by whitespace or by a
2835 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2836 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2837 is moved to the front, so it is searched sooner.
2838
2839 You can use the string @samp{$cwd} to refer to whatever is the current
2840 working directory at the time @value{GDBN} searches the path. If you
2841 use @samp{.} instead, it refers to the directory where you executed the
2842 @code{path} command. @value{GDBN} replaces @samp{.} in the
2843 @var{directory} argument (with the current path) before adding
2844 @var{directory} to the search path.
2845 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2846 @c document that, since repeating it would be a no-op.
2847
2848 @kindex show paths
2849 @item show paths
2850 Display the list of search paths for executables (the @env{PATH}
2851 environment variable).
2852
2853 @kindex show environment
2854 @item show environment @r{[}@var{varname}@r{]}
2855 Print the value of environment variable @var{varname} to be given to
2856 your program when it starts. If you do not supply @var{varname},
2857 print the names and values of all environment variables to be given to
2858 your program. You can abbreviate @code{environment} as @code{env}.
2859
2860 @kindex set environment
2861 @anchor{set environment}
2862 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2863 Set environment variable @var{varname} to @var{value}. The value
2864 changes for your program (and the shell @value{GDBN} uses to launch
2865 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2866 values of environment variables are just strings, and any
2867 interpretation is supplied by your program itself. The @var{value}
2868 parameter is optional; if it is eliminated, the variable is set to a
2869 null value.
2870 @c "any string" here does not include leading, trailing
2871 @c blanks. Gnu asks: does anyone care?
2872
2873 For example, this command:
2874
2875 @smallexample
2876 set env USER = foo
2877 @end smallexample
2878
2879 @noindent
2880 tells the debugged program, when subsequently run, that its user is named
2881 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2882 are not actually required.)
2883
2884 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2885 which also inherits the environment set with @code{set environment}.
2886 If necessary, you can avoid that by using the @samp{env} program as a
2887 wrapper instead of using @code{set environment}. @xref{set
2888 exec-wrapper}, for an example doing just that.
2889
2890 Environment variables that are set by the user are also transmitted to
2891 @command{gdbserver} to be used when starting the remote inferior.
2892 @pxref{QEnvironmentHexEncoded}.
2893
2894 @kindex unset environment
2895 @anchor{unset environment}
2896 @item unset environment @var{varname}
2897 Remove variable @var{varname} from the environment to be passed to your
2898 program. This is different from @samp{set env @var{varname} =};
2899 @code{unset environment} removes the variable from the environment,
2900 rather than assigning it an empty value.
2901
2902 Environment variables that are unset by the user are also unset on
2903 @command{gdbserver} when starting the remote inferior.
2904 @pxref{QEnvironmentUnset}.
2905 @end table
2906
2907 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2908 the shell indicated by your @env{SHELL} environment variable if it
2909 exists (or @code{/bin/sh} if not). If your @env{SHELL} variable
2910 names a shell that runs an initialization file when started
2911 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2912 for the Z shell, or the file specified in the @env{BASH_ENV}
2913 environment variable for BASH---any variables you set in that file
2914 affect your program. You may wish to move setting of environment
2915 variables to files that are only run when you sign on, such as
2916 @file{.login} or @file{.profile}.
2917
2918 @node Working Directory
2919 @section Your Program's Working Directory
2920
2921 @cindex working directory (of your program)
2922 Each time you start your program with @code{run}, the inferior will be
2923 initialized with the current working directory specified by the
2924 @kbd{set cwd} command. If no directory has been specified by this
2925 command, then the inferior will inherit @value{GDBN}'s current working
2926 directory as its working directory if native debugging, or it will
2927 inherit the remote server's current working directory if remote
2928 debugging.
2929
2930 @table @code
2931 @kindex set cwd
2932 @cindex change inferior's working directory
2933 @anchor{set cwd command}
2934 @item set cwd @r{[}@var{directory}@r{]}
2935 Set the inferior's working directory to @var{directory}, which will be
2936 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2937 argument has been specified, the command clears the setting and resets
2938 it to an empty state. This setting has no effect on @value{GDBN}'s
2939 working directory, and it only takes effect the next time you start
2940 the inferior. The @file{~} in @var{directory} is a short for the
2941 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2942 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2943 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2944 fallback.
2945
2946 You can also change @value{GDBN}'s current working directory by using
2947 the @code{cd} command.
2948 @xref{cd command}.
2949
2950 @kindex show cwd
2951 @cindex show inferior's working directory
2952 @item show cwd
2953 Show the inferior's working directory. If no directory has been
2954 specified by @kbd{set cwd}, then the default inferior's working
2955 directory is the same as @value{GDBN}'s working directory.
2956
2957 @kindex cd
2958 @cindex change @value{GDBN}'s working directory
2959 @anchor{cd command}
2960 @item cd @r{[}@var{directory}@r{]}
2961 Set the @value{GDBN} working directory to @var{directory}. If not
2962 given, @var{directory} uses @file{'~'}.
2963
2964 The @value{GDBN} working directory serves as a default for the
2965 commands that specify files for @value{GDBN} to operate on.
2966 @xref{Files, ,Commands to Specify Files}.
2967 @xref{set cwd command}.
2968
2969 @kindex pwd
2970 @item pwd
2971 Print the @value{GDBN} working directory.
2972 @end table
2973
2974 It is generally impossible to find the current working directory of
2975 the process being debugged (since a program can change its directory
2976 during its run). If you work on a system where @value{GDBN} supports
2977 the @code{info proc} command (@pxref{Process Information}), you can
2978 use the @code{info proc} command to find out the
2979 current working directory of the debuggee.
2980
2981 @node Input/Output
2982 @section Your Program's Input and Output
2983
2984 @cindex redirection
2985 @cindex i/o
2986 @cindex terminal
2987 By default, the program you run under @value{GDBN} does input and output to
2988 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2989 to its own terminal modes to interact with you, but it records the terminal
2990 modes your program was using and switches back to them when you continue
2991 running your program.
2992
2993 @table @code
2994 @kindex info terminal
2995 @item info terminal
2996 Displays information recorded by @value{GDBN} about the terminal modes your
2997 program is using.
2998 @end table
2999
3000 You can redirect your program's input and/or output using shell
3001 redirection with the @code{run} command. For example,
3002
3003 @smallexample
3004 run > outfile
3005 @end smallexample
3006
3007 @noindent
3008 starts your program, diverting its output to the file @file{outfile}.
3009
3010 @kindex tty
3011 @cindex controlling terminal
3012 Another way to specify where your program should do input and output is
3013 with the @code{tty} command. This command accepts a file name as
3014 argument, and causes this file to be the default for future @code{run}
3015 commands. It also resets the controlling terminal for the child
3016 process, for future @code{run} commands. For example,
3017
3018 @smallexample
3019 tty /dev/ttyb
3020 @end smallexample
3021
3022 @noindent
3023 directs that processes started with subsequent @code{run} commands
3024 default to do input and output on the terminal @file{/dev/ttyb} and have
3025 that as their controlling terminal.
3026
3027 An explicit redirection in @code{run} overrides the @code{tty} command's
3028 effect on the input/output device, but not its effect on the controlling
3029 terminal.
3030
3031 When you use the @code{tty} command or redirect input in the @code{run}
3032 command, only the input @emph{for your program} is affected. The input
3033 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3034 for @code{set inferior-tty}.
3035
3036 @cindex inferior tty
3037 @cindex set inferior controlling terminal
3038 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3039 display the name of the terminal that will be used for future runs of your
3040 program.
3041
3042 @table @code
3043 @item set inferior-tty [ @var{tty} ]
3044 @kindex set inferior-tty
3045 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3046 restores the default behavior, which is to use the same terminal as
3047 @value{GDBN}.
3048
3049 @item show inferior-tty
3050 @kindex show inferior-tty
3051 Show the current tty for the program being debugged.
3052 @end table
3053
3054 @node Attach
3055 @section Debugging an Already-running Process
3056 @kindex attach
3057 @cindex attach
3058
3059 @table @code
3060 @item attach @var{process-id}
3061 This command attaches to a running process---one that was started
3062 outside @value{GDBN}. (@code{info files} shows your active
3063 targets.) The command takes as argument a process ID. The usual way to
3064 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3065 or with the @samp{jobs -l} shell command.
3066
3067 @code{attach} does not repeat if you press @key{RET} a second time after
3068 executing the command.
3069 @end table
3070
3071 To use @code{attach}, your program must be running in an environment
3072 which supports processes; for example, @code{attach} does not work for
3073 programs on bare-board targets that lack an operating system. You must
3074 also have permission to send the process a signal.
3075
3076 When you use @code{attach}, the debugger finds the program running in
3077 the process first by looking in the current working directory, then (if
3078 the program is not found) by using the source file search path
3079 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3080 the @code{file} command to load the program. @xref{Files, ,Commands to
3081 Specify Files}.
3082
3083 @anchor{set exec-file-mismatch}
3084 If the debugger can determine that the executable file running in the
3085 process it is attaching to does not match the current exec-file loaded
3086 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3087 handle the mismatch. @value{GDBN} tries to compare the files by
3088 comparing their build IDs (@pxref{build ID}), if available.
3089
3090 @table @code
3091 @kindex exec-file-mismatch
3092 @cindex set exec-file-mismatch
3093 @item set exec-file-mismatch @samp{ask|warn|off}
3094
3095 Whether to detect mismatch between the current executable file loaded
3096 by @value{GDBN} and the executable file used to start the process. If
3097 @samp{ask}, the default, display a warning and ask the user whether to
3098 load the process executable file; if @samp{warn}, just display a
3099 warning; if @samp{off}, don't attempt to detect a mismatch.
3100 If the user confirms loading the process executable file, then its symbols
3101 will be loaded as well.
3102
3103 @cindex show exec-file-mismatch
3104 @item show exec-file-mismatch
3105 Show the current value of @code{exec-file-mismatch}.
3106
3107 @end table
3108
3109 The first thing @value{GDBN} does after arranging to debug the specified
3110 process is to stop it. You can examine and modify an attached process
3111 with all the @value{GDBN} commands that are ordinarily available when
3112 you start processes with @code{run}. You can insert breakpoints; you
3113 can step and continue; you can modify storage. If you would rather the
3114 process continue running, you may use the @code{continue} command after
3115 attaching @value{GDBN} to the process.
3116
3117 @table @code
3118 @kindex detach
3119 @item detach
3120 When you have finished debugging the attached process, you can use the
3121 @code{detach} command to release it from @value{GDBN} control. Detaching
3122 the process continues its execution. After the @code{detach} command,
3123 that process and @value{GDBN} become completely independent once more, and you
3124 are ready to @code{attach} another process or start one with @code{run}.
3125 @code{detach} does not repeat if you press @key{RET} again after
3126 executing the command.
3127 @end table
3128
3129 If you exit @value{GDBN} while you have an attached process, you detach
3130 that process. If you use the @code{run} command, you kill that process.
3131 By default, @value{GDBN} asks for confirmation if you try to do either of these
3132 things; you can control whether or not you need to confirm by using the
3133 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3134 Messages}).
3135
3136 @node Kill Process
3137 @section Killing the Child Process
3138
3139 @table @code
3140 @kindex kill
3141 @item kill
3142 Kill the child process in which your program is running under @value{GDBN}.
3143 @end table
3144
3145 This command is useful if you wish to debug a core dump instead of a
3146 running process. @value{GDBN} ignores any core dump file while your program
3147 is running.
3148
3149 On some operating systems, a program cannot be executed outside @value{GDBN}
3150 while you have breakpoints set on it inside @value{GDBN}. You can use the
3151 @code{kill} command in this situation to permit running your program
3152 outside the debugger.
3153
3154 The @code{kill} command is also useful if you wish to recompile and
3155 relink your program, since on many systems it is impossible to modify an
3156 executable file while it is running in a process. In this case, when you
3157 next type @code{run}, @value{GDBN} notices that the file has changed, and
3158 reads the symbol table again (while trying to preserve your current
3159 breakpoint settings).
3160
3161 @node Inferiors Connections and Programs
3162 @section Debugging Multiple Inferiors Connections and Programs
3163
3164 @value{GDBN} lets you run and debug multiple programs in a single
3165 session. In addition, @value{GDBN} on some systems may let you run
3166 several programs simultaneously (otherwise you have to exit from one
3167 before starting another). On some systems @value{GDBN} may even let
3168 you debug several programs simultaneously on different remote systems.
3169 In the most general case, you can have multiple threads of execution
3170 in each of multiple processes, launched from multiple executables,
3171 running on different machines.
3172
3173 @cindex inferior
3174 @value{GDBN} represents the state of each program execution with an
3175 object called an @dfn{inferior}. An inferior typically corresponds to
3176 a process, but is more general and applies also to targets that do not
3177 have processes. Inferiors may be created before a process runs, and
3178 may be retained after a process exits. Inferiors have unique
3179 identifiers that are different from process ids. Usually each
3180 inferior will also have its own distinct address space, although some
3181 embedded targets may have several inferiors running in different parts
3182 of a single address space. Each inferior may in turn have multiple
3183 threads running in it.
3184
3185 To find out what inferiors exist at any moment, use @w{@code{info
3186 inferiors}}:
3187
3188 @table @code
3189 @kindex info inferiors [ @var{id}@dots{} ]
3190 @item info inferiors
3191 Print a list of all inferiors currently being managed by @value{GDBN}.
3192 By default all inferiors are printed, but the argument @var{id}@dots{}
3193 -- a space separated list of inferior numbers -- can be used to limit
3194 the display to just the requested inferiors.
3195
3196 @value{GDBN} displays for each inferior (in this order):
3197
3198 @enumerate
3199 @item
3200 the inferior number assigned by @value{GDBN}
3201
3202 @item
3203 the target system's inferior identifier
3204
3205 @item
3206 the target connection the inferior is bound to, including the unique
3207 connection number assigned by @value{GDBN}, and the protocol used by
3208 the connection.
3209
3210 @item
3211 the name of the executable the inferior is running.
3212
3213 @end enumerate
3214
3215 @noindent
3216 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3217 indicates the current inferior.
3218
3219 For example,
3220 @end table
3221 @c end table here to get a little more width for example
3222
3223 @smallexample
3224 (@value{GDBP}) info inferiors
3225 Num Description Connection Executable
3226 * 1 process 3401 1 (native) goodbye
3227 2 process 2307 2 (extended-remote host:10000) hello
3228 @end smallexample
3229
3230 To get informations about the current inferior, use @code{inferior}:
3231
3232 @table @code
3233 @kindex inferior
3234 @item inferior
3235 Shows information about the current inferior.
3236
3237 For example,
3238 @end table
3239 @c end table here to get a little more width for example
3240
3241 @smallexample
3242 (@value{GDBP}) inferior
3243 [Current inferior is 1 [process 3401] (helloworld)]
3244 @end smallexample
3245
3246 To find out what open target connections exist at any moment, use
3247 @w{@code{info connections}}:
3248
3249 @table @code
3250 @kindex info connections [ @var{id}@dots{} ]
3251 @item info connections
3252 Print a list of all open target connections currently being managed by
3253 @value{GDBN}. By default all connections are printed, but the
3254 argument @var{id}@dots{} -- a space separated list of connections
3255 numbers -- can be used to limit the display to just the requested
3256 connections.
3257
3258 @value{GDBN} displays for each connection (in this order):
3259
3260 @enumerate
3261 @item
3262 the connection number assigned by @value{GDBN}.
3263
3264 @item
3265 the protocol used by the connection.
3266
3267 @item
3268 a textual description of the protocol used by the connection.
3269
3270 @end enumerate
3271
3272 @noindent
3273 An asterisk @samp{*} preceding the connection number indicates the
3274 connection of the current inferior.
3275
3276 For example,
3277 @end table
3278 @c end table here to get a little more width for example
3279
3280 @smallexample
3281 (@value{GDBP}) info connections
3282 Num What Description
3283 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3284 2 native Native process
3285 3 core Local core dump file
3286 @end smallexample
3287
3288 To switch focus between inferiors, use the @code{inferior} command:
3289
3290 @table @code
3291 @kindex inferior @var{infno}
3292 @item inferior @var{infno}
3293 Make inferior number @var{infno} the current inferior. The argument
3294 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3295 in the first field of the @samp{info inferiors} display.
3296 @end table
3297
3298 @vindex $_inferior@r{, convenience variable}
3299 The debugger convenience variable @samp{$_inferior} contains the
3300 number of the current inferior. You may find this useful in writing
3301 breakpoint conditional expressions, command scripts, and so forth.
3302 @xref{Convenience Vars,, Convenience Variables}, for general
3303 information on convenience variables.
3304
3305 You can get multiple executables into a debugging session via the
3306 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3307 systems @value{GDBN} can add inferiors to the debug session
3308 automatically by following calls to @code{fork} and @code{exec}. To
3309 remove inferiors from the debugging session use the
3310 @w{@code{remove-inferiors}} command.
3311
3312 @table @code
3313 @kindex add-inferior
3314 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3315 Adds @var{n} inferiors to be run using @var{executable} as the
3316 executable; @var{n} defaults to 1. If no executable is specified,
3317 the inferiors begins empty, with no program. You can still assign or
3318 change the program assigned to the inferior at any time by using the
3319 @code{file} command with the executable name as its argument.
3320
3321 By default, the new inferior begins connected to the same target
3322 connection as the current inferior. For example, if the current
3323 inferior was connected to @code{gdbserver} with @code{target remote},
3324 then the new inferior will be connected to the same @code{gdbserver}
3325 instance. The @samp{-no-connection} option starts the new inferior
3326 with no connection yet. You can then for example use the @code{target
3327 remote} command to connect to some other @code{gdbserver} instance,
3328 use @code{run} to spawn a local program, etc.
3329
3330 @kindex clone-inferior
3331 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3332 Adds @var{n} inferiors ready to execute the same program as inferior
3333 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3334 number of the current inferior. This command copies the values of the
3335 @var{args}, @w{@var{inferior-tty}} and @var{cwd} properties from the
3336 current inferior to the new one. It also propagates changes the user
3337 made to environment variables using the @w{@code{set environment}} and
3338 @w{@code{unset environment}} commands. This is a convenient command
3339 when you want to run another instance of the inferior you are debugging.
3340
3341 @smallexample
3342 (@value{GDBP}) info inferiors
3343 Num Description Connection Executable
3344 * 1 process 29964 1 (native) helloworld
3345 (@value{GDBP}) clone-inferior
3346 Added inferior 2.
3347 1 inferiors added.
3348 (@value{GDBP}) info inferiors
3349 Num Description Connection Executable
3350 * 1 process 29964 1 (native) helloworld
3351 2 <null> 1 (native) helloworld
3352 @end smallexample
3353
3354 You can now simply switch focus to inferior 2 and run it.
3355
3356 @kindex remove-inferiors
3357 @item remove-inferiors @var{infno}@dots{}
3358 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3359 possible to remove an inferior that is running with this command. For
3360 those, use the @code{kill} or @code{detach} command first.
3361
3362 @end table
3363
3364 To quit debugging one of the running inferiors that is not the current
3365 inferior, you can either detach from it by using the @w{@code{detach
3366 inferior}} command (allowing it to run independently), or kill it
3367 using the @w{@code{kill inferiors}} command:
3368
3369 @table @code
3370 @kindex detach inferiors @var{infno}@dots{}
3371 @item detach inferior @var{infno}@dots{}
3372 Detach from the inferior or inferiors identified by @value{GDBN}
3373 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3374 still stays on the list of inferiors shown by @code{info inferiors},
3375 but its Description will show @samp{<null>}.
3376
3377 @kindex kill inferiors @var{infno}@dots{}
3378 @item kill inferiors @var{infno}@dots{}
3379 Kill the inferior or inferiors identified by @value{GDBN} inferior
3380 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3381 stays on the list of inferiors shown by @code{info inferiors}, but its
3382 Description will show @samp{<null>}.
3383 @end table
3384
3385 After the successful completion of a command such as @code{detach},
3386 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3387 a normal process exit, the inferior is still valid and listed with
3388 @code{info inferiors}, ready to be restarted.
3389
3390
3391 To be notified when inferiors are started or exit under @value{GDBN}'s
3392 control use @w{@code{set print inferior-events}}:
3393
3394 @table @code
3395 @kindex set print inferior-events
3396 @cindex print messages on inferior start and exit
3397 @item set print inferior-events
3398 @itemx set print inferior-events on
3399 @itemx set print inferior-events off
3400 The @code{set print inferior-events} command allows you to enable or
3401 disable printing of messages when @value{GDBN} notices that new
3402 inferiors have started or that inferiors have exited or have been
3403 detached. By default, these messages will be printed.
3404
3405 @kindex show print inferior-events
3406 @item show print inferior-events
3407 Show whether messages will be printed when @value{GDBN} detects that
3408 inferiors have started, exited or have been detached.
3409 @end table
3410
3411 Many commands will work the same with multiple programs as with a
3412 single program: e.g., @code{print myglobal} will simply display the
3413 value of @code{myglobal} in the current inferior.
3414
3415
3416 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3417 get more info about the relationship of inferiors, programs, address
3418 spaces in a debug session. You can do that with the @w{@code{maint
3419 info program-spaces}} command.
3420
3421 @table @code
3422 @kindex maint info program-spaces
3423 @item maint info program-spaces
3424 Print a list of all program spaces currently being managed by
3425 @value{GDBN}.
3426
3427 @value{GDBN} displays for each program space (in this order):
3428
3429 @enumerate
3430 @item
3431 the program space number assigned by @value{GDBN}
3432
3433 @item
3434 the name of the executable loaded into the program space, with e.g.,
3435 the @code{file} command.
3436
3437 @end enumerate
3438
3439 @noindent
3440 An asterisk @samp{*} preceding the @value{GDBN} program space number
3441 indicates the current program space.
3442
3443 In addition, below each program space line, @value{GDBN} prints extra
3444 information that isn't suitable to display in tabular form. For
3445 example, the list of inferiors bound to the program space.
3446
3447 @smallexample
3448 (@value{GDBP}) maint info program-spaces
3449 Id Executable
3450 * 1 hello
3451 2 goodbye
3452 Bound inferiors: ID 1 (process 21561)
3453 @end smallexample
3454
3455 Here we can see that no inferior is running the program @code{hello},
3456 while @code{process 21561} is running the program @code{goodbye}. On
3457 some targets, it is possible that multiple inferiors are bound to the
3458 same program space. The most common example is that of debugging both
3459 the parent and child processes of a @code{vfork} call. For example,
3460
3461 @smallexample
3462 (@value{GDBP}) maint info program-spaces
3463 Id Executable
3464 * 1 vfork-test
3465 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3466 @end smallexample
3467
3468 Here, both inferior 2 and inferior 1 are running in the same program
3469 space as a result of inferior 1 having executed a @code{vfork} call.
3470 @end table
3471
3472 @node Threads
3473 @section Debugging Programs with Multiple Threads
3474
3475 @cindex threads of execution
3476 @cindex multiple threads
3477 @cindex switching threads
3478 In some operating systems, such as GNU/Linux and Solaris, a single program
3479 may have more than one @dfn{thread} of execution. The precise semantics
3480 of threads differ from one operating system to another, but in general
3481 the threads of a single program are akin to multiple processes---except
3482 that they share one address space (that is, they can all examine and
3483 modify the same variables). On the other hand, each thread has its own
3484 registers and execution stack, and perhaps private memory.
3485
3486 @value{GDBN} provides these facilities for debugging multi-thread
3487 programs:
3488
3489 @itemize @bullet
3490 @item automatic notification of new threads
3491 @item @samp{thread @var{thread-id}}, a command to switch among threads
3492 @item @samp{info threads}, a command to inquire about existing threads
3493 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3494 a command to apply a command to a list of threads
3495 @item thread-specific breakpoints
3496 @item @samp{set print thread-events}, which controls printing of
3497 messages on thread start and exit.
3498 @item @samp{set libthread-db-search-path @var{path}}, which lets
3499 the user specify which @code{libthread_db} to use if the default choice
3500 isn't compatible with the program.
3501 @end itemize
3502
3503 @cindex focus of debugging
3504 @cindex current thread
3505 The @value{GDBN} thread debugging facility allows you to observe all
3506 threads while your program runs---but whenever @value{GDBN} takes
3507 control, one thread in particular is always the focus of debugging.
3508 This thread is called the @dfn{current thread}. Debugging commands show
3509 program information from the perspective of the current thread.
3510
3511 @cindex @code{New} @var{systag} message
3512 @cindex thread identifier (system)
3513 @c FIXME-implementors!! It would be more helpful if the [New...] message
3514 @c included GDB's numeric thread handle, so you could just go to that
3515 @c thread without first checking `info threads'.
3516 Whenever @value{GDBN} detects a new thread in your program, it displays
3517 the target system's identification for the thread with a message in the
3518 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3519 whose form varies depending on the particular system. For example, on
3520 @sc{gnu}/Linux, you might see
3521
3522 @smallexample
3523 [New Thread 0x41e02940 (LWP 25582)]
3524 @end smallexample
3525
3526 @noindent
3527 when @value{GDBN} notices a new thread. In contrast, on other systems,
3528 the @var{systag} is simply something like @samp{process 368}, with no
3529 further qualifier.
3530
3531 @c FIXME!! (1) Does the [New...] message appear even for the very first
3532 @c thread of a program, or does it only appear for the
3533 @c second---i.e.@: when it becomes obvious we have a multithread
3534 @c program?
3535 @c (2) *Is* there necessarily a first thread always? Or do some
3536 @c multithread systems permit starting a program with multiple
3537 @c threads ab initio?
3538
3539 @anchor{thread numbers}
3540 @cindex thread number, per inferior
3541 @cindex thread identifier (GDB)
3542 For debugging purposes, @value{GDBN} associates its own thread number
3543 ---always a single integer---with each thread of an inferior. This
3544 number is unique between all threads of an inferior, but not unique
3545 between threads of different inferiors.
3546
3547 @cindex qualified thread ID
3548 You can refer to a given thread in an inferior using the qualified
3549 @var{inferior-num}.@var{thread-num} syntax, also known as
3550 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3551 number and @var{thread-num} being the thread number of the given
3552 inferior. For example, thread @code{2.3} refers to thread number 3 of
3553 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3554 then @value{GDBN} infers you're referring to a thread of the current
3555 inferior.
3556
3557 Until you create a second inferior, @value{GDBN} does not show the
3558 @var{inferior-num} part of thread IDs, even though you can always use
3559 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3560 of inferior 1, the initial inferior.
3561
3562 @anchor{thread ID lists}
3563 @cindex thread ID lists
3564 Some commands accept a space-separated @dfn{thread ID list} as
3565 argument. A list element can be:
3566
3567 @enumerate
3568 @item
3569 A thread ID as shown in the first field of the @samp{info threads}
3570 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3571 @samp{1}.
3572
3573 @item
3574 A range of thread numbers, again with or without an inferior
3575 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3576 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3577
3578 @item
3579 All threads of an inferior, specified with a star wildcard, with or
3580 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3581 @samp{1.*}) or @code{*}. The former refers to all threads of the
3582 given inferior, and the latter form without an inferior qualifier
3583 refers to all threads of the current inferior.
3584
3585 @end enumerate
3586
3587 For example, if the current inferior is 1, and inferior 7 has one
3588 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3589 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3590 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3591 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3592 7.1}.
3593
3594
3595 @anchor{global thread numbers}
3596 @cindex global thread number
3597 @cindex global thread identifier (GDB)
3598 In addition to a @emph{per-inferior} number, each thread is also
3599 assigned a unique @emph{global} number, also known as @dfn{global
3600 thread ID}, a single integer. Unlike the thread number component of
3601 the thread ID, no two threads have the same global ID, even when
3602 you're debugging multiple inferiors.
3603
3604 From @value{GDBN}'s perspective, a process always has at least one
3605 thread. In other words, @value{GDBN} assigns a thread number to the
3606 program's ``main thread'' even if the program is not multi-threaded.
3607
3608 @vindex $_thread@r{, convenience variable}
3609 @vindex $_gthread@r{, convenience variable}
3610 The debugger convenience variables @samp{$_thread} and
3611 @samp{$_gthread} contain, respectively, the per-inferior thread number
3612 and the global thread number of the current thread. You may find this
3613 useful in writing breakpoint conditional expressions, command scripts,
3614 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3615 general information on convenience variables.
3616
3617 If @value{GDBN} detects the program is multi-threaded, it augments the
3618 usual message about stopping at a breakpoint with the ID and name of
3619 the thread that hit the breakpoint.
3620
3621 @smallexample
3622 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3623 @end smallexample
3624
3625 Likewise when the program receives a signal:
3626
3627 @smallexample
3628 Thread 1 "main" received signal SIGINT, Interrupt.
3629 @end smallexample
3630
3631 @table @code
3632 @anchor{info_threads}
3633 @kindex info threads
3634 @item info threads @r{[}@var{thread-id-list}@r{]}
3635
3636 Display information about one or more threads. With no arguments
3637 displays information about all threads. You can specify the list of
3638 threads that you want to display using the thread ID list syntax
3639 (@pxref{thread ID lists}).
3640
3641 @value{GDBN} displays for each thread (in this order):
3642
3643 @enumerate
3644 @item
3645 the per-inferior thread number assigned by @value{GDBN}
3646
3647 @item
3648 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3649 option was specified
3650
3651 @item
3652 the target system's thread identifier (@var{systag})
3653
3654 @item
3655 the thread's name, if one is known. A thread can either be named by
3656 the user (see @code{thread name}, below), or, in some cases, by the
3657 program itself.
3658
3659 @item
3660 the current stack frame summary for that thread
3661 @end enumerate
3662
3663 @noindent
3664 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3665 indicates the current thread.
3666
3667 For example,
3668 @end table
3669 @c end table here to get a little more width for example
3670
3671 @smallexample
3672 (@value{GDBP}) info threads
3673 Id Target Id Frame
3674 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3675 2 process 35 thread 23 0x34e5 in sigpause ()
3676 3 process 35 thread 27 0x34e5 in sigpause ()
3677 at threadtest.c:68
3678 @end smallexample
3679
3680 If you're debugging multiple inferiors, @value{GDBN} displays thread
3681 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3682 Otherwise, only @var{thread-num} is shown.
3683
3684 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3685 indicating each thread's global thread ID:
3686
3687 @smallexample
3688 (@value{GDBP}) info threads
3689 Id GId Target Id Frame
3690 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3691 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3692 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3693 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3694 @end smallexample
3695
3696 On Solaris, you can display more information about user threads with a
3697 Solaris-specific command:
3698
3699 @table @code
3700 @item maint info sol-threads
3701 @kindex maint info sol-threads
3702 @cindex thread info (Solaris)
3703 Display info on Solaris user threads.
3704 @end table
3705
3706 @table @code
3707 @kindex thread @var{thread-id}
3708 @item thread @var{thread-id}
3709 Make thread ID @var{thread-id} the current thread. The command
3710 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3711 the first field of the @samp{info threads} display, with or without an
3712 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3713
3714 @value{GDBN} responds by displaying the system identifier of the
3715 thread you selected, and its current stack frame summary:
3716
3717 @smallexample
3718 (@value{GDBP}) thread 2
3719 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3720 #0 some_function (ignore=0x0) at example.c:8
3721 8 printf ("hello\n");
3722 @end smallexample
3723
3724 @noindent
3725 As with the @samp{[New @dots{}]} message, the form of the text after
3726 @samp{Switching to} depends on your system's conventions for identifying
3727 threads.
3728
3729 @anchor{thread apply all}
3730 @kindex thread apply
3731 @cindex apply command to several threads
3732 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3733 The @code{thread apply} command allows you to apply the named
3734 @var{command} to one or more threads. Specify the threads that you
3735 want affected using the thread ID list syntax (@pxref{thread ID
3736 lists}), or specify @code{all} to apply to all threads. To apply a
3737 command to all threads in descending order, type @kbd{thread apply all
3738 @var{command}}. To apply a command to all threads in ascending order,
3739 type @kbd{thread apply all -ascending @var{command}}.
3740
3741 The @var{flag} arguments control what output to produce and how to handle
3742 errors raised when applying @var{command} to a thread. @var{flag}
3743 must start with a @code{-} directly followed by one letter in
3744 @code{qcs}. If several flags are provided, they must be given
3745 individually, such as @code{-c -q}.
3746
3747 By default, @value{GDBN} displays some thread information before the
3748 output produced by @var{command}, and an error raised during the
3749 execution of a @var{command} will abort @code{thread apply}. The
3750 following flags can be used to fine-tune this behavior:
3751
3752 @table @code
3753 @item -c
3754 The flag @code{-c}, which stands for @samp{continue}, causes any
3755 errors in @var{command} to be displayed, and the execution of
3756 @code{thread apply} then continues.
3757 @item -s
3758 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3759 or empty output produced by a @var{command} to be silently ignored.
3760 That is, the execution continues, but the thread information and errors
3761 are not printed.
3762 @item -q
3763 The flag @code{-q} (@samp{quiet}) disables printing the thread
3764 information.
3765 @end table
3766
3767 Flags @code{-c} and @code{-s} cannot be used together.
3768
3769 @kindex taas
3770 @cindex apply command to all threads (ignoring errors and empty output)
3771 @item taas [@var{option}]@dots{} @var{command}
3772 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3773 Applies @var{command} on all threads, ignoring errors and empty output.
3774
3775 The @code{taas} command accepts the same options as the @code{thread
3776 apply all} command. @xref{thread apply all}.
3777
3778 @kindex tfaas
3779 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3780 @item tfaas [@var{option}]@dots{} @var{command}
3781 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3782 Applies @var{command} on all frames of all threads, ignoring errors
3783 and empty output. Note that the flag @code{-s} is specified twice:
3784 The first @code{-s} ensures that @code{thread apply} only shows the thread
3785 information of the threads for which @code{frame apply} produces
3786 some output. The second @code{-s} is needed to ensure that @code{frame
3787 apply} shows the frame information of a frame only if the
3788 @var{command} successfully produced some output.
3789
3790 It can for example be used to print a local variable or a function
3791 argument without knowing the thread or frame where this variable or argument
3792 is, using:
3793 @smallexample
3794 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3795 @end smallexample
3796
3797 The @code{tfaas} command accepts the same options as the @code{frame
3798 apply} command. @xref{Frame Apply,,frame apply}.
3799
3800 @kindex thread name
3801 @cindex name a thread
3802 @item thread name [@var{name}]
3803 This command assigns a name to the current thread. If no argument is
3804 given, any existing user-specified name is removed. The thread name
3805 appears in the @samp{info threads} display.
3806
3807 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3808 determine the name of the thread as given by the OS. On these
3809 systems, a name specified with @samp{thread name} will override the
3810 system-give name, and removing the user-specified name will cause
3811 @value{GDBN} to once again display the system-specified name.
3812
3813 @kindex thread find
3814 @cindex search for a thread
3815 @item thread find [@var{regexp}]
3816 Search for and display thread ids whose name or @var{systag}
3817 matches the supplied regular expression.
3818
3819 As well as being the complement to the @samp{thread name} command,
3820 this command also allows you to identify a thread by its target
3821 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3822 is the LWP id.
3823
3824 @smallexample
3825 (@value{GDBN}) thread find 26688
3826 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3827 (@value{GDBN}) info thread 4
3828 Id Target Id Frame
3829 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3830 @end smallexample
3831
3832 @kindex set print thread-events
3833 @cindex print messages on thread start and exit
3834 @item set print thread-events
3835 @itemx set print thread-events on
3836 @itemx set print thread-events off
3837 The @code{set print thread-events} command allows you to enable or
3838 disable printing of messages when @value{GDBN} notices that new threads have
3839 started or that threads have exited. By default, these messages will
3840 be printed if detection of these events is supported by the target.
3841 Note that these messages cannot be disabled on all targets.
3842
3843 @kindex show print thread-events
3844 @item show print thread-events
3845 Show whether messages will be printed when @value{GDBN} detects that threads
3846 have started and exited.
3847 @end table
3848
3849 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3850 more information about how @value{GDBN} behaves when you stop and start
3851 programs with multiple threads.
3852
3853 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3854 watchpoints in programs with multiple threads.
3855
3856 @anchor{set libthread-db-search-path}
3857 @table @code
3858 @kindex set libthread-db-search-path
3859 @cindex search path for @code{libthread_db}
3860 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3861 If this variable is set, @var{path} is a colon-separated list of
3862 directories @value{GDBN} will use to search for @code{libthread_db}.
3863 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3864 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3865 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3866 macro.
3867
3868 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3869 @code{libthread_db} library to obtain information about threads in the
3870 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3871 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3872 specific thread debugging library loading is enabled
3873 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3874
3875 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3876 refers to the default system directories that are
3877 normally searched for loading shared libraries. The @samp{$sdir} entry
3878 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3879 (@pxref{libthread_db.so.1 file}).
3880
3881 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3882 refers to the directory from which @code{libpthread}
3883 was loaded in the inferior process.
3884
3885 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3886 @value{GDBN} attempts to initialize it with the current inferior process.
3887 If this initialization fails (which could happen because of a version
3888 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3889 will unload @code{libthread_db}, and continue with the next directory.
3890 If none of @code{libthread_db} libraries initialize successfully,
3891 @value{GDBN} will issue a warning and thread debugging will be disabled.
3892
3893 Setting @code{libthread-db-search-path} is currently implemented
3894 only on some platforms.
3895
3896 @kindex show libthread-db-search-path
3897 @item show libthread-db-search-path
3898 Display current libthread_db search path.
3899
3900 @kindex set debug libthread-db
3901 @kindex show debug libthread-db
3902 @cindex debugging @code{libthread_db}
3903 @item set debug libthread-db
3904 @itemx show debug libthread-db
3905 Turns on or off display of @code{libthread_db}-related events.
3906 Use @code{1} to enable, @code{0} to disable.
3907
3908 @kindex set debug threads
3909 @kindex show debug threads
3910 @cindex debugging @code{threads}
3911 @item set debug threads @r{[}on@r{|}off@r{]}
3912 @itemx show debug threads
3913 When @samp{on} @value{GDBN} will print additional messages when
3914 threads are created and deleted.
3915 @end table
3916
3917 @node Forks
3918 @section Debugging Forks
3919
3920 @cindex fork, debugging programs which call
3921 @cindex multiple processes
3922 @cindex processes, multiple
3923 On most systems, @value{GDBN} has no special support for debugging
3924 programs which create additional processes using the @code{fork}
3925 function. When a program forks, @value{GDBN} will continue to debug the
3926 parent process and the child process will run unimpeded. If you have
3927 set a breakpoint in any code which the child then executes, the child
3928 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3929 will cause it to terminate.
3930
3931 However, if you want to debug the child process there is a workaround
3932 which isn't too painful. Put a call to @code{sleep} in the code which
3933 the child process executes after the fork. It may be useful to sleep
3934 only if a certain environment variable is set, or a certain file exists,
3935 so that the delay need not occur when you don't want to run @value{GDBN}
3936 on the child. While the child is sleeping, use the @code{ps} program to
3937 get its process ID. Then tell @value{GDBN} (a new invocation of
3938 @value{GDBN} if you are also debugging the parent process) to attach to
3939 the child process (@pxref{Attach}). From that point on you can debug
3940 the child process just like any other process which you attached to.
3941
3942 On some systems, @value{GDBN} provides support for debugging programs
3943 that create additional processes using the @code{fork} or @code{vfork}
3944 functions. On @sc{gnu}/Linux platforms, this feature is supported
3945 with kernel version 2.5.46 and later.
3946
3947 The fork debugging commands are supported in native mode and when
3948 connected to @code{gdbserver} in either @code{target remote} mode or
3949 @code{target extended-remote} mode.
3950
3951 By default, when a program forks, @value{GDBN} will continue to debug
3952 the parent process and the child process will run unimpeded.
3953
3954 If you want to follow the child process instead of the parent process,
3955 use the command @w{@code{set follow-fork-mode}}.
3956
3957 @table @code
3958 @kindex set follow-fork-mode
3959 @item set follow-fork-mode @var{mode}
3960 Set the debugger response to a program call of @code{fork} or
3961 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3962 process. The @var{mode} argument can be:
3963
3964 @table @code
3965 @item parent
3966 The original process is debugged after a fork. The child process runs
3967 unimpeded. This is the default.
3968
3969 @item child
3970 The new process is debugged after a fork. The parent process runs
3971 unimpeded.
3972
3973 @end table
3974
3975 @kindex show follow-fork-mode
3976 @item show follow-fork-mode
3977 Display the current debugger response to a @code{fork} or @code{vfork} call.
3978 @end table
3979
3980 @cindex debugging multiple processes
3981 On Linux, if you want to debug both the parent and child processes, use the
3982 command @w{@code{set detach-on-fork}}.
3983
3984 @table @code
3985 @kindex set detach-on-fork
3986 @item set detach-on-fork @var{mode}
3987 Tells gdb whether to detach one of the processes after a fork, or
3988 retain debugger control over them both.
3989
3990 @table @code
3991 @item on
3992 The child process (or parent process, depending on the value of
3993 @code{follow-fork-mode}) will be detached and allowed to run
3994 independently. This is the default.
3995
3996 @item off
3997 Both processes will be held under the control of @value{GDBN}.
3998 One process (child or parent, depending on the value of
3999 @code{follow-fork-mode}) is debugged as usual, while the other
4000 is held suspended.
4001
4002 @end table
4003
4004 @kindex show detach-on-fork
4005 @item show detach-on-fork
4006 Show whether detach-on-fork mode is on/off.
4007 @end table
4008
4009 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
4010 will retain control of all forked processes (including nested forks).
4011 You can list the forked processes under the control of @value{GDBN} by
4012 using the @w{@code{info inferiors}} command, and switch from one fork
4013 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
4014 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
4015
4016 To quit debugging one of the forked processes, you can either detach
4017 from it by using the @w{@code{detach inferiors}} command (allowing it
4018 to run independently), or kill it using the @w{@code{kill inferiors}}
4019 command. @xref{Inferiors Connections and Programs, ,Debugging
4020 Multiple Inferiors Connections and Programs}.
4021
4022 If you ask to debug a child process and a @code{vfork} is followed by an
4023 @code{exec}, @value{GDBN} executes the new target up to the first
4024 breakpoint in the new target. If you have a breakpoint set on
4025 @code{main} in your original program, the breakpoint will also be set on
4026 the child process's @code{main}.
4027
4028 On some systems, when a child process is spawned by @code{vfork}, you
4029 cannot debug the child or parent until an @code{exec} call completes.
4030
4031 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
4032 call executes, the new target restarts. To restart the parent
4033 process, use the @code{file} command with the parent executable name
4034 as its argument. By default, after an @code{exec} call executes,
4035 @value{GDBN} discards the symbols of the previous executable image.
4036 You can change this behaviour with the @w{@code{set follow-exec-mode}}
4037 command.
4038
4039 @table @code
4040 @kindex set follow-exec-mode
4041 @item set follow-exec-mode @var{mode}
4042
4043 Set debugger response to a program call of @code{exec}. An
4044 @code{exec} call replaces the program image of a process.
4045
4046 @code{follow-exec-mode} can be:
4047
4048 @table @code
4049 @item new
4050 @value{GDBN} creates a new inferior and rebinds the process to this
4051 new inferior. The program the process was running before the
4052 @code{exec} call can be restarted afterwards by restarting the
4053 original inferior.
4054
4055 For example:
4056
4057 @smallexample
4058 (@value{GDBP}) info inferiors
4059 (gdb) info inferior
4060 Id Description Executable
4061 * 1 <null> prog1
4062 (@value{GDBP}) run
4063 process 12020 is executing new program: prog2
4064 Program exited normally.
4065 (@value{GDBP}) info inferiors
4066 Id Description Executable
4067 1 <null> prog1
4068 * 2 <null> prog2
4069 @end smallexample
4070
4071 @item same
4072 @value{GDBN} keeps the process bound to the same inferior. The new
4073 executable image replaces the previous executable loaded in the
4074 inferior. Restarting the inferior after the @code{exec} call, with
4075 e.g., the @code{run} command, restarts the executable the process was
4076 running after the @code{exec} call. This is the default mode.
4077
4078 For example:
4079
4080 @smallexample
4081 (@value{GDBP}) info inferiors
4082 Id Description Executable
4083 * 1 <null> prog1
4084 (@value{GDBP}) run
4085 process 12020 is executing new program: prog2
4086 Program exited normally.
4087 (@value{GDBP}) info inferiors
4088 Id Description Executable
4089 * 1 <null> prog2
4090 @end smallexample
4091
4092 @end table
4093 @end table
4094
4095 @code{follow-exec-mode} is supported in native mode and
4096 @code{target extended-remote} mode.
4097
4098 You can use the @code{catch} command to make @value{GDBN} stop whenever
4099 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4100 Catchpoints, ,Setting Catchpoints}.
4101
4102 @node Checkpoint/Restart
4103 @section Setting a @emph{Bookmark} to Return to Later
4104
4105 @cindex checkpoint
4106 @cindex restart
4107 @cindex bookmark
4108 @cindex snapshot of a process
4109 @cindex rewind program state
4110
4111 On certain operating systems@footnote{Currently, only
4112 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4113 program's state, called a @dfn{checkpoint}, and come back to it
4114 later.
4115
4116 Returning to a checkpoint effectively undoes everything that has
4117 happened in the program since the @code{checkpoint} was saved. This
4118 includes changes in memory, registers, and even (within some limits)
4119 system state. Effectively, it is like going back in time to the
4120 moment when the checkpoint was saved.
4121
4122 Thus, if you're stepping thru a program and you think you're
4123 getting close to the point where things go wrong, you can save
4124 a checkpoint. Then, if you accidentally go too far and miss
4125 the critical statement, instead of having to restart your program
4126 from the beginning, you can just go back to the checkpoint and
4127 start again from there.
4128
4129 This can be especially useful if it takes a lot of time or
4130 steps to reach the point where you think the bug occurs.
4131
4132 To use the @code{checkpoint}/@code{restart} method of debugging:
4133
4134 @table @code
4135 @kindex checkpoint
4136 @item checkpoint
4137 Save a snapshot of the debugged program's current execution state.
4138 The @code{checkpoint} command takes no arguments, but each checkpoint
4139 is assigned a small integer id, similar to a breakpoint id.
4140
4141 @kindex info checkpoints
4142 @item info checkpoints
4143 List the checkpoints that have been saved in the current debugging
4144 session. For each checkpoint, the following information will be
4145 listed:
4146
4147 @table @code
4148 @item Checkpoint ID
4149 @item Process ID
4150 @item Code Address
4151 @item Source line, or label
4152 @end table
4153
4154 @kindex restart @var{checkpoint-id}
4155 @item restart @var{checkpoint-id}
4156 Restore the program state that was saved as checkpoint number
4157 @var{checkpoint-id}. All program variables, registers, stack frames
4158 etc.@: will be returned to the values that they had when the checkpoint
4159 was saved. In essence, gdb will ``wind back the clock'' to the point
4160 in time when the checkpoint was saved.
4161
4162 Note that breakpoints, @value{GDBN} variables, command history etc.
4163 are not affected by restoring a checkpoint. In general, a checkpoint
4164 only restores things that reside in the program being debugged, not in
4165 the debugger.
4166
4167 @kindex delete checkpoint @var{checkpoint-id}
4168 @item delete checkpoint @var{checkpoint-id}
4169 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4170
4171 @end table
4172
4173 Returning to a previously saved checkpoint will restore the user state
4174 of the program being debugged, plus a significant subset of the system
4175 (OS) state, including file pointers. It won't ``un-write'' data from
4176 a file, but it will rewind the file pointer to the previous location,
4177 so that the previously written data can be overwritten. For files
4178 opened in read mode, the pointer will also be restored so that the
4179 previously read data can be read again.
4180
4181 Of course, characters that have been sent to a printer (or other
4182 external device) cannot be ``snatched back'', and characters received
4183 from eg.@: a serial device can be removed from internal program buffers,
4184 but they cannot be ``pushed back'' into the serial pipeline, ready to
4185 be received again. Similarly, the actual contents of files that have
4186 been changed cannot be restored (at this time).
4187
4188 However, within those constraints, you actually can ``rewind'' your
4189 program to a previously saved point in time, and begin debugging it
4190 again --- and you can change the course of events so as to debug a
4191 different execution path this time.
4192
4193 @cindex checkpoints and process id
4194 Finally, there is one bit of internal program state that will be
4195 different when you return to a checkpoint --- the program's process
4196 id. Each checkpoint will have a unique process id (or @var{pid}),
4197 and each will be different from the program's original @var{pid}.
4198 If your program has saved a local copy of its process id, this could
4199 potentially pose a problem.
4200
4201 @subsection A Non-obvious Benefit of Using Checkpoints
4202
4203 On some systems such as @sc{gnu}/Linux, address space randomization
4204 is performed on new processes for security reasons. This makes it
4205 difficult or impossible to set a breakpoint, or watchpoint, on an
4206 absolute address if you have to restart the program, since the
4207 absolute location of a symbol will change from one execution to the
4208 next.
4209
4210 A checkpoint, however, is an @emph{identical} copy of a process.
4211 Therefore if you create a checkpoint at (eg.@:) the start of main,
4212 and simply return to that checkpoint instead of restarting the
4213 process, you can avoid the effects of address randomization and
4214 your symbols will all stay in the same place.
4215
4216 @node Stopping
4217 @chapter Stopping and Continuing
4218
4219 The principal purposes of using a debugger are so that you can stop your
4220 program before it terminates; or so that, if your program runs into
4221 trouble, you can investigate and find out why.
4222
4223 Inside @value{GDBN}, your program may stop for any of several reasons,
4224 such as a signal, a breakpoint, or reaching a new line after a
4225 @value{GDBN} command such as @code{step}. You may then examine and
4226 change variables, set new breakpoints or remove old ones, and then
4227 continue execution. Usually, the messages shown by @value{GDBN} provide
4228 ample explanation of the status of your program---but you can also
4229 explicitly request this information at any time.
4230
4231 @table @code
4232 @kindex info program
4233 @item info program
4234 Display information about the status of your program: whether it is
4235 running or not, what process it is, and why it stopped.
4236 @end table
4237
4238 @menu
4239 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4240 * Continuing and Stepping:: Resuming execution
4241 * Skipping Over Functions and Files::
4242 Skipping over functions and files
4243 * Signals:: Signals
4244 * Thread Stops:: Stopping and starting multi-thread programs
4245 @end menu
4246
4247 @node Breakpoints
4248 @section Breakpoints, Watchpoints, and Catchpoints
4249
4250 @cindex breakpoints
4251 A @dfn{breakpoint} makes your program stop whenever a certain point in
4252 the program is reached. For each breakpoint, you can add conditions to
4253 control in finer detail whether your program stops. You can set
4254 breakpoints with the @code{break} command and its variants (@pxref{Set
4255 Breaks, ,Setting Breakpoints}), to specify the place where your program
4256 should stop by line number, function name or exact address in the
4257 program.
4258
4259 On some systems, you can set breakpoints in shared libraries before
4260 the executable is run.
4261
4262 @cindex watchpoints
4263 @cindex data breakpoints
4264 @cindex memory tracing
4265 @cindex breakpoint on memory address
4266 @cindex breakpoint on variable modification
4267 A @dfn{watchpoint} is a special breakpoint that stops your program
4268 when the value of an expression changes. The expression may be a value
4269 of a variable, or it could involve values of one or more variables
4270 combined by operators, such as @samp{a + b}. This is sometimes called
4271 @dfn{data breakpoints}. You must use a different command to set
4272 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4273 from that, you can manage a watchpoint like any other breakpoint: you
4274 enable, disable, and delete both breakpoints and watchpoints using the
4275 same commands.
4276
4277 You can arrange to have values from your program displayed automatically
4278 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4279 Automatic Display}.
4280
4281 @cindex catchpoints
4282 @cindex breakpoint on events
4283 A @dfn{catchpoint} is another special breakpoint that stops your program
4284 when a certain kind of event occurs, such as the throwing of a C@t{++}
4285 exception or the loading of a library. As with watchpoints, you use a
4286 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4287 Catchpoints}), but aside from that, you can manage a catchpoint like any
4288 other breakpoint. (To stop when your program receives a signal, use the
4289 @code{handle} command; see @ref{Signals, ,Signals}.)
4290
4291 @cindex breakpoint numbers
4292 @cindex numbers for breakpoints
4293 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4294 catchpoint when you create it; these numbers are successive integers
4295 starting with one. In many of the commands for controlling various
4296 features of breakpoints you use the breakpoint number to say which
4297 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4298 @dfn{disabled}; if disabled, it has no effect on your program until you
4299 enable it again.
4300
4301 @cindex breakpoint ranges
4302 @cindex breakpoint lists
4303 @cindex ranges of breakpoints
4304 @cindex lists of breakpoints
4305 Some @value{GDBN} commands accept a space-separated list of breakpoints
4306 on which to operate. A list element can be either a single breakpoint number,
4307 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4308 When a breakpoint list is given to a command, all breakpoints in that list
4309 are operated on.
4310
4311 @menu
4312 * Set Breaks:: Setting breakpoints
4313 * Set Watchpoints:: Setting watchpoints
4314 * Set Catchpoints:: Setting catchpoints
4315 * Delete Breaks:: Deleting breakpoints
4316 * Disabling:: Disabling breakpoints
4317 * Conditions:: Break conditions
4318 * Break Commands:: Breakpoint command lists
4319 * Dynamic Printf:: Dynamic printf
4320 * Save Breakpoints:: How to save breakpoints in a file
4321 * Static Probe Points:: Listing static probe points
4322 * Error in Breakpoints:: ``Cannot insert breakpoints''
4323 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4324 @end menu
4325
4326 @node Set Breaks
4327 @subsection Setting Breakpoints
4328
4329 @c FIXME LMB what does GDB do if no code on line of breakpt?
4330 @c consider in particular declaration with/without initialization.
4331 @c
4332 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4333
4334 @kindex break
4335 @kindex b @r{(@code{break})}
4336 @vindex $bpnum@r{, convenience variable}
4337 @cindex latest breakpoint
4338 Breakpoints are set with the @code{break} command (abbreviated
4339 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4340 number of the breakpoint you've set most recently; see @ref{Convenience
4341 Vars,, Convenience Variables}, for a discussion of what you can do with
4342 convenience variables.
4343
4344 @table @code
4345 @item break @var{location}
4346 Set a breakpoint at the given @var{location}, which can specify a
4347 function name, a line number, or an address of an instruction.
4348 (@xref{Specify Location}, for a list of all the possible ways to
4349 specify a @var{location}.) The breakpoint will stop your program just
4350 before it executes any of the code in the specified @var{location}.
4351
4352 When using source languages that permit overloading of symbols, such as
4353 C@t{++}, a function name may refer to more than one possible place to break.
4354 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4355 that situation.
4356
4357 It is also possible to insert a breakpoint that will stop the program
4358 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4359 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4360
4361 @item break
4362 When called without any arguments, @code{break} sets a breakpoint at
4363 the next instruction to be executed in the selected stack frame
4364 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4365 innermost, this makes your program stop as soon as control
4366 returns to that frame. This is similar to the effect of a
4367 @code{finish} command in the frame inside the selected frame---except
4368 that @code{finish} does not leave an active breakpoint. If you use
4369 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4370 the next time it reaches the current location; this may be useful
4371 inside loops.
4372
4373 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4374 least one instruction has been executed. If it did not do this, you
4375 would be unable to proceed past a breakpoint without first disabling the
4376 breakpoint. This rule applies whether or not the breakpoint already
4377 existed when your program stopped.
4378
4379 @item break @dots{} if @var{cond}
4380 Set a breakpoint with condition @var{cond}; evaluate the expression
4381 @var{cond} each time the breakpoint is reached, and stop only if the
4382 value is nonzero---that is, if @var{cond} evaluates as true.
4383 @samp{@dots{}} stands for one of the possible arguments described
4384 above (or no argument) specifying where to break. @xref{Conditions,
4385 ,Break Conditions}, for more information on breakpoint conditions.
4386
4387 The breakpoint may be mapped to multiple locations. If the breakpoint
4388 condition @var{cond} is invalid at some but not all of the locations,
4389 the locations for which the condition is invalid are disabled. For
4390 example, @value{GDBN} reports below that two of the three locations
4391 are disabled.
4392
4393 @smallexample
4394 (@value{GDBP}) break func if a == 10
4395 warning: failed to validate condition at location 0x11ce, disabling:
4396 No symbol "a" in current context.
4397 warning: failed to validate condition at location 0x11b6, disabling:
4398 No symbol "a" in current context.
4399 Breakpoint 1 at 0x11b6: func. (3 locations)
4400 @end smallexample
4401
4402 Locations that are disabled because of the condition are denoted by an
4403 uppercase @code{N} in the output of the @code{info breakpoints}
4404 command:
4405
4406 @smallexample
4407 (@value{GDBP}) info breakpoints
4408 Num Type Disp Enb Address What
4409 1 breakpoint keep y <MULTIPLE>
4410 stop only if a == 10
4411 1.1 N* 0x00000000000011b6 in ...
4412 1.2 y 0x00000000000011c2 in ...
4413 1.3 N* 0x00000000000011ce in ...
4414 (*): Breakpoint condition is invalid at this location.
4415 @end smallexample
4416
4417 If the breakpoint condition @var{cond} is invalid in the context of
4418 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4419 define the breakpoint. For example, if variable @code{foo} is an
4420 undefined variable:
4421
4422 @smallexample
4423 (@value{GDBP}) break func if foo
4424 No symbol "foo" in current context.
4425 @end smallexample
4426
4427 @item break @dots{} -force-condition if @var{cond}
4428 There may be cases where the condition @var{cond} is invalid at all
4429 the current locations, but the user knows that it will be valid at a
4430 future location; for example, because of a library load. In such
4431 cases, by using the @code{-force-condition} keyword before @samp{if},
4432 @value{GDBN} can be forced to define the breakpoint with the given
4433 condition expression instead of refusing it.
4434
4435 @smallexample
4436 (@value{GDBP}) break func -force-condition if foo
4437 warning: failed to validate condition at location 1, disabling:
4438 No symbol "foo" in current context.
4439 warning: failed to validate condition at location 2, disabling:
4440 No symbol "foo" in current context.
4441 warning: failed to validate condition at location 3, disabling:
4442 No symbol "foo" in current context.
4443 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4444 @end smallexample
4445
4446 This causes all the present locations where the breakpoint would
4447 otherwise be inserted, to be disabled, as seen in the example above.
4448 However, if there exist locations at which the condition is valid, the
4449 @code{-force-condition} keyword has no effect.
4450
4451 @kindex tbreak
4452 @item tbreak @var{args}
4453 Set a breakpoint enabled only for one stop. The @var{args} are the
4454 same as for the @code{break} command, and the breakpoint is set in the same
4455 way, but the breakpoint is automatically deleted after the first time your
4456 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4457
4458 @kindex hbreak
4459 @cindex hardware breakpoints
4460 @item hbreak @var{args}
4461 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4462 @code{break} command and the breakpoint is set in the same way, but the
4463 breakpoint requires hardware support and some target hardware may not
4464 have this support. The main purpose of this is EPROM/ROM code
4465 debugging, so you can set a breakpoint at an instruction without
4466 changing the instruction. This can be used with the new trap-generation
4467 provided by SPARClite DSU and most x86-based targets. These targets
4468 will generate traps when a program accesses some data or instruction
4469 address that is assigned to the debug registers. However the hardware
4470 breakpoint registers can take a limited number of breakpoints. For
4471 example, on the DSU, only two data breakpoints can be set at a time, and
4472 @value{GDBN} will reject this command if more than two are used. Delete
4473 or disable unused hardware breakpoints before setting new ones
4474 (@pxref{Disabling, ,Disabling Breakpoints}).
4475 @xref{Conditions, ,Break Conditions}.
4476 For remote targets, you can restrict the number of hardware
4477 breakpoints @value{GDBN} will use, see @ref{set remote
4478 hardware-breakpoint-limit}.
4479
4480 @kindex thbreak
4481 @item thbreak @var{args}
4482 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4483 are the same as for the @code{hbreak} command and the breakpoint is set in
4484 the same way. However, like the @code{tbreak} command,
4485 the breakpoint is automatically deleted after the
4486 first time your program stops there. Also, like the @code{hbreak}
4487 command, the breakpoint requires hardware support and some target hardware
4488 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4489 See also @ref{Conditions, ,Break Conditions}.
4490
4491 @kindex rbreak
4492 @cindex regular expression
4493 @cindex breakpoints at functions matching a regexp
4494 @cindex set breakpoints in many functions
4495 @item rbreak @var{regex}
4496 Set breakpoints on all functions matching the regular expression
4497 @var{regex}. This command sets an unconditional breakpoint on all
4498 matches, printing a list of all breakpoints it set. Once these
4499 breakpoints are set, they are treated just like the breakpoints set with
4500 the @code{break} command. You can delete them, disable them, or make
4501 them conditional the same way as any other breakpoint.
4502
4503 In programs using different languages, @value{GDBN} chooses the syntax
4504 to print the list of all breakpoints it sets according to the
4505 @samp{set language} value: using @samp{set language auto}
4506 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4507 language of the breakpoint's function, other values mean to use
4508 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4509
4510 The syntax of the regular expression is the standard one used with tools
4511 like @file{grep}. Note that this is different from the syntax used by
4512 shells, so for instance @code{foo*} matches all functions that include
4513 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4514 @code{.*} leading and trailing the regular expression you supply, so to
4515 match only functions that begin with @code{foo}, use @code{^foo}.
4516
4517 @cindex non-member C@t{++} functions, set breakpoint in
4518 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4519 breakpoints on overloaded functions that are not members of any special
4520 classes.
4521
4522 @cindex set breakpoints on all functions
4523 The @code{rbreak} command can be used to set breakpoints in
4524 @strong{all} the functions in a program, like this:
4525
4526 @smallexample
4527 (@value{GDBP}) rbreak .
4528 @end smallexample
4529
4530 @item rbreak @var{file}:@var{regex}
4531 If @code{rbreak} is called with a filename qualification, it limits
4532 the search for functions matching the given regular expression to the
4533 specified @var{file}. This can be used, for example, to set breakpoints on
4534 every function in a given file:
4535
4536 @smallexample
4537 (@value{GDBP}) rbreak file.c:.
4538 @end smallexample
4539
4540 The colon separating the filename qualifier from the regex may
4541 optionally be surrounded by spaces.
4542
4543 @kindex info breakpoints
4544 @cindex @code{$_} and @code{info breakpoints}
4545 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4546 @itemx info break @r{[}@var{list}@dots{}@r{]}
4547 Print a table of all breakpoints, watchpoints, and catchpoints set and
4548 not deleted. Optional argument @var{n} means print information only
4549 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4550 For each breakpoint, following columns are printed:
4551
4552 @table @emph
4553 @item Breakpoint Numbers
4554 @item Type
4555 Breakpoint, watchpoint, or catchpoint.
4556 @item Disposition
4557 Whether the breakpoint is marked to be disabled or deleted when hit.
4558 @item Enabled or Disabled
4559 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4560 that are not enabled.
4561 @item Address
4562 Where the breakpoint is in your program, as a memory address. For a
4563 pending breakpoint whose address is not yet known, this field will
4564 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4565 library that has the symbol or line referred by breakpoint is loaded.
4566 See below for details. A breakpoint with several locations will
4567 have @samp{<MULTIPLE>} in this field---see below for details.
4568 @item What
4569 Where the breakpoint is in the source for your program, as a file and
4570 line number. For a pending breakpoint, the original string passed to
4571 the breakpoint command will be listed as it cannot be resolved until
4572 the appropriate shared library is loaded in the future.
4573 @end table
4574
4575 @noindent
4576 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4577 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4578 @value{GDBN} on the host's side. If it is ``target'', then the condition
4579 is evaluated by the target. The @code{info break} command shows
4580 the condition on the line following the affected breakpoint, together with
4581 its condition evaluation mode in between parentheses.
4582
4583 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4584 allowed to have a condition specified for it. The condition is not parsed for
4585 validity until a shared library is loaded that allows the pending
4586 breakpoint to resolve to a valid location.
4587
4588 @noindent
4589 @code{info break} with a breakpoint
4590 number @var{n} as argument lists only that breakpoint. The
4591 convenience variable @code{$_} and the default examining-address for
4592 the @code{x} command are set to the address of the last breakpoint
4593 listed (@pxref{Memory, ,Examining Memory}).
4594
4595 @noindent
4596 @code{info break} displays a count of the number of times the breakpoint
4597 has been hit. This is especially useful in conjunction with the
4598 @code{ignore} command. You can ignore a large number of breakpoint
4599 hits, look at the breakpoint info to see how many times the breakpoint
4600 was hit, and then run again, ignoring one less than that number. This
4601 will get you quickly to the last hit of that breakpoint.
4602
4603 @noindent
4604 For a breakpoints with an enable count (xref) greater than 1,
4605 @code{info break} also displays that count.
4606
4607 @end table
4608
4609 @value{GDBN} allows you to set any number of breakpoints at the same place in
4610 your program. There is nothing silly or meaningless about this. When
4611 the breakpoints are conditional, this is even useful
4612 (@pxref{Conditions, ,Break Conditions}).
4613
4614 @cindex multiple locations, breakpoints
4615 @cindex breakpoints, multiple locations
4616 It is possible that a breakpoint corresponds to several locations
4617 in your program. Examples of this situation are:
4618
4619 @itemize @bullet
4620 @item
4621 Multiple functions in the program may have the same name.
4622
4623 @item
4624 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4625 instances of the function body, used in different cases.
4626
4627 @item
4628 For a C@t{++} template function, a given line in the function can
4629 correspond to any number of instantiations.
4630
4631 @item
4632 For an inlined function, a given source line can correspond to
4633 several places where that function is inlined.
4634 @end itemize
4635
4636 In all those cases, @value{GDBN} will insert a breakpoint at all
4637 the relevant locations.
4638
4639 A breakpoint with multiple locations is displayed in the breakpoint
4640 table using several rows---one header row, followed by one row for
4641 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4642 address column. The rows for individual locations contain the actual
4643 addresses for locations, and show the functions to which those
4644 locations belong. The number column for a location is of the form
4645 @var{breakpoint-number}.@var{location-number}.
4646
4647 For example:
4648
4649 @smallexample
4650 Num Type Disp Enb Address What
4651 1 breakpoint keep y <MULTIPLE>
4652 stop only if i==1
4653 breakpoint already hit 1 time
4654 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4655 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4656 @end smallexample
4657
4658 You cannot delete the individual locations from a breakpoint. However,
4659 each location can be individually enabled or disabled by passing
4660 @var{breakpoint-number}.@var{location-number} as argument to the
4661 @code{enable} and @code{disable} commands. It's also possible to
4662 @code{enable} and @code{disable} a range of @var{location-number}
4663 locations using a @var{breakpoint-number} and two @var{location-number}s,
4664 in increasing order, separated by a hyphen, like
4665 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4666 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4667 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4668 all of the locations that belong to that breakpoint.
4669
4670 @cindex pending breakpoints
4671 It's quite common to have a breakpoint inside a shared library.
4672 Shared libraries can be loaded and unloaded explicitly,
4673 and possibly repeatedly, as the program is executed. To support
4674 this use case, @value{GDBN} updates breakpoint locations whenever
4675 any shared library is loaded or unloaded. Typically, you would
4676 set a breakpoint in a shared library at the beginning of your
4677 debugging session, when the library is not loaded, and when the
4678 symbols from the library are not available. When you try to set
4679 breakpoint, @value{GDBN} will ask you if you want to set
4680 a so called @dfn{pending breakpoint}---breakpoint whose address
4681 is not yet resolved.
4682
4683 After the program is run, whenever a new shared library is loaded,
4684 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4685 shared library contains the symbol or line referred to by some
4686 pending breakpoint, that breakpoint is resolved and becomes an
4687 ordinary breakpoint. When a library is unloaded, all breakpoints
4688 that refer to its symbols or source lines become pending again.
4689
4690 This logic works for breakpoints with multiple locations, too. For
4691 example, if you have a breakpoint in a C@t{++} template function, and
4692 a newly loaded shared library has an instantiation of that template,
4693 a new location is added to the list of locations for the breakpoint.
4694
4695 Except for having unresolved address, pending breakpoints do not
4696 differ from regular breakpoints. You can set conditions or commands,
4697 enable and disable them and perform other breakpoint operations.
4698
4699 @value{GDBN} provides some additional commands for controlling what
4700 happens when the @samp{break} command cannot resolve breakpoint
4701 address specification to an address:
4702
4703 @kindex set breakpoint pending
4704 @kindex show breakpoint pending
4705 @table @code
4706 @item set breakpoint pending auto
4707 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4708 location, it queries you whether a pending breakpoint should be created.
4709
4710 @item set breakpoint pending on
4711 This indicates that an unrecognized breakpoint location should automatically
4712 result in a pending breakpoint being created.
4713
4714 @item set breakpoint pending off
4715 This indicates that pending breakpoints are not to be created. Any
4716 unrecognized breakpoint location results in an error. This setting does
4717 not affect any pending breakpoints previously created.
4718
4719 @item show breakpoint pending
4720 Show the current behavior setting for creating pending breakpoints.
4721 @end table
4722
4723 The settings above only affect the @code{break} command and its
4724 variants. Once breakpoint is set, it will be automatically updated
4725 as shared libraries are loaded and unloaded.
4726
4727 @cindex automatic hardware breakpoints
4728 For some targets, @value{GDBN} can automatically decide if hardware or
4729 software breakpoints should be used, depending on whether the
4730 breakpoint address is read-only or read-write. This applies to
4731 breakpoints set with the @code{break} command as well as to internal
4732 breakpoints set by commands like @code{next} and @code{finish}. For
4733 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4734 breakpoints.
4735
4736 You can control this automatic behaviour with the following commands:
4737
4738 @kindex set breakpoint auto-hw
4739 @kindex show breakpoint auto-hw
4740 @table @code
4741 @item set breakpoint auto-hw on
4742 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4743 will try to use the target memory map to decide if software or hardware
4744 breakpoint must be used.
4745
4746 @item set breakpoint auto-hw off
4747 This indicates @value{GDBN} should not automatically select breakpoint
4748 type. If the target provides a memory map, @value{GDBN} will warn when
4749 trying to set software breakpoint at a read-only address.
4750 @end table
4751
4752 @value{GDBN} normally implements breakpoints by replacing the program code
4753 at the breakpoint address with a special instruction, which, when
4754 executed, given control to the debugger. By default, the program
4755 code is so modified only when the program is resumed. As soon as
4756 the program stops, @value{GDBN} restores the original instructions. This
4757 behaviour guards against leaving breakpoints inserted in the
4758 target should gdb abrubptly disconnect. However, with slow remote
4759 targets, inserting and removing breakpoint can reduce the performance.
4760 This behavior can be controlled with the following commands::
4761
4762 @kindex set breakpoint always-inserted
4763 @kindex show breakpoint always-inserted
4764 @table @code
4765 @item set breakpoint always-inserted off
4766 All breakpoints, including newly added by the user, are inserted in
4767 the target only when the target is resumed. All breakpoints are
4768 removed from the target when it stops. This is the default mode.
4769
4770 @item set breakpoint always-inserted on
4771 Causes all breakpoints to be inserted in the target at all times. If
4772 the user adds a new breakpoint, or changes an existing breakpoint, the
4773 breakpoints in the target are updated immediately. A breakpoint is
4774 removed from the target only when breakpoint itself is deleted.
4775 @end table
4776
4777 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4778 when a breakpoint breaks. If the condition is true, then the process being
4779 debugged stops, otherwise the process is resumed.
4780
4781 If the target supports evaluating conditions on its end, @value{GDBN} may
4782 download the breakpoint, together with its conditions, to it.
4783
4784 This feature can be controlled via the following commands:
4785
4786 @kindex set breakpoint condition-evaluation
4787 @kindex show breakpoint condition-evaluation
4788 @table @code
4789 @item set breakpoint condition-evaluation host
4790 This option commands @value{GDBN} to evaluate the breakpoint
4791 conditions on the host's side. Unconditional breakpoints are sent to
4792 the target which in turn receives the triggers and reports them back to GDB
4793 for condition evaluation. This is the standard evaluation mode.
4794
4795 @item set breakpoint condition-evaluation target
4796 This option commands @value{GDBN} to download breakpoint conditions
4797 to the target at the moment of their insertion. The target
4798 is responsible for evaluating the conditional expression and reporting
4799 breakpoint stop events back to @value{GDBN} whenever the condition
4800 is true. Due to limitations of target-side evaluation, some conditions
4801 cannot be evaluated there, e.g., conditions that depend on local data
4802 that is only known to the host. Examples include
4803 conditional expressions involving convenience variables, complex types
4804 that cannot be handled by the agent expression parser and expressions
4805 that are too long to be sent over to the target, specially when the
4806 target is a remote system. In these cases, the conditions will be
4807 evaluated by @value{GDBN}.
4808
4809 @item set breakpoint condition-evaluation auto
4810 This is the default mode. If the target supports evaluating breakpoint
4811 conditions on its end, @value{GDBN} will download breakpoint conditions to
4812 the target (limitations mentioned previously apply). If the target does
4813 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4814 to evaluating all these conditions on the host's side.
4815 @end table
4816
4817
4818 @cindex negative breakpoint numbers
4819 @cindex internal @value{GDBN} breakpoints
4820 @value{GDBN} itself sometimes sets breakpoints in your program for
4821 special purposes, such as proper handling of @code{longjmp} (in C
4822 programs). These internal breakpoints are assigned negative numbers,
4823 starting with @code{-1}; @samp{info breakpoints} does not display them.
4824 You can see these breakpoints with the @value{GDBN} maintenance command
4825 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4826
4827
4828 @node Set Watchpoints
4829 @subsection Setting Watchpoints
4830
4831 @cindex setting watchpoints
4832 You can use a watchpoint to stop execution whenever the value of an
4833 expression changes, without having to predict a particular place where
4834 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4835 The expression may be as simple as the value of a single variable, or
4836 as complex as many variables combined by operators. Examples include:
4837
4838 @itemize @bullet
4839 @item
4840 A reference to the value of a single variable.
4841
4842 @item
4843 An address cast to an appropriate data type. For example,
4844 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4845 address (assuming an @code{int} occupies 4 bytes).
4846
4847 @item
4848 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4849 expression can use any operators valid in the program's native
4850 language (@pxref{Languages}).
4851 @end itemize
4852
4853 You can set a watchpoint on an expression even if the expression can
4854 not be evaluated yet. For instance, you can set a watchpoint on
4855 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4856 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4857 the expression produces a valid value. If the expression becomes
4858 valid in some other way than changing a variable (e.g.@: if the memory
4859 pointed to by @samp{*global_ptr} becomes readable as the result of a
4860 @code{malloc} call), @value{GDBN} may not stop until the next time
4861 the expression changes.
4862
4863 @cindex software watchpoints
4864 @cindex hardware watchpoints
4865 Depending on your system, watchpoints may be implemented in software or
4866 hardware. @value{GDBN} does software watchpointing by single-stepping your
4867 program and testing the variable's value each time, which is hundreds of
4868 times slower than normal execution. (But this may still be worth it, to
4869 catch errors where you have no clue what part of your program is the
4870 culprit.)
4871
4872 On some systems, such as most PowerPC or x86-based targets,
4873 @value{GDBN} includes support for hardware watchpoints, which do not
4874 slow down the running of your program.
4875
4876 @table @code
4877 @kindex watch
4878 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]} @r{[}task @var{task-id}@r{]}
4879 Set a watchpoint for an expression. @value{GDBN} will break when the
4880 expression @var{expr} is written into by the program and its value
4881 changes. The simplest (and the most popular) use of this command is
4882 to watch the value of a single variable:
4883
4884 @smallexample
4885 (@value{GDBP}) watch foo
4886 @end smallexample
4887
4888 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4889 argument, @value{GDBN} breaks only when the thread identified by
4890 @var{thread-id} changes the value of @var{expr}. If any other threads
4891 change the value of @var{expr}, @value{GDBN} will not break. Note
4892 that watchpoints restricted to a single thread in this way only work
4893 with Hardware Watchpoints.
4894
4895 Similarly, if the @code{task} argument is given, then the watchpoint
4896 will be specific to the indicated Ada task (@pxref{Ada Tasks}).
4897
4898 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4899 (see below). The @code{-location} argument tells @value{GDBN} to
4900 instead watch the memory referred to by @var{expr}. In this case,
4901 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4902 and watch the memory at that address. The type of the result is used
4903 to determine the size of the watched memory. If the expression's
4904 result does not have an address, then @value{GDBN} will print an
4905 error.
4906
4907 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4908 of masked watchpoints, if the current architecture supports this
4909 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4910 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4911 to an address to watch. The mask specifies that some bits of an address
4912 (the bits which are reset in the mask) should be ignored when matching
4913 the address accessed by the inferior against the watchpoint address.
4914 Thus, a masked watchpoint watches many addresses simultaneously---those
4915 addresses whose unmasked bits are identical to the unmasked bits in the
4916 watchpoint address. The @code{mask} argument implies @code{-location}.
4917 Examples:
4918
4919 @smallexample
4920 (@value{GDBP}) watch foo mask 0xffff00ff
4921 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4922 @end smallexample
4923
4924 @kindex rwatch
4925 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4926 Set a watchpoint that will break when the value of @var{expr} is read
4927 by the program.
4928
4929 @kindex awatch
4930 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4931 Set a watchpoint that will break when @var{expr} is either read from
4932 or written into by the program.
4933
4934 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4935 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4936 This command prints a list of watchpoints, using the same format as
4937 @code{info break} (@pxref{Set Breaks}).
4938 @end table
4939
4940 If you watch for a change in a numerically entered address you need to
4941 dereference it, as the address itself is just a constant number which will
4942 never change. @value{GDBN} refuses to create a watchpoint that watches
4943 a never-changing value:
4944
4945 @smallexample
4946 (@value{GDBP}) watch 0x600850
4947 Cannot watch constant value 0x600850.
4948 (@value{GDBP}) watch *(int *) 0x600850
4949 Watchpoint 1: *(int *) 6293584
4950 @end smallexample
4951
4952 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4953 watchpoints execute very quickly, and the debugger reports a change in
4954 value at the exact instruction where the change occurs. If @value{GDBN}
4955 cannot set a hardware watchpoint, it sets a software watchpoint, which
4956 executes more slowly and reports the change in value at the next
4957 @emph{statement}, not the instruction, after the change occurs.
4958
4959 @cindex use only software watchpoints
4960 You can force @value{GDBN} to use only software watchpoints with the
4961 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4962 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4963 the underlying system supports them. (Note that hardware-assisted
4964 watchpoints that were set @emph{before} setting
4965 @code{can-use-hw-watchpoints} to zero will still use the hardware
4966 mechanism of watching expression values.)
4967
4968 @table @code
4969 @item set can-use-hw-watchpoints
4970 @kindex set can-use-hw-watchpoints
4971 Set whether or not to use hardware watchpoints.
4972
4973 @item show can-use-hw-watchpoints
4974 @kindex show can-use-hw-watchpoints
4975 Show the current mode of using hardware watchpoints.
4976 @end table
4977
4978 For remote targets, you can restrict the number of hardware
4979 watchpoints @value{GDBN} will use, see @ref{set remote
4980 hardware-breakpoint-limit}.
4981
4982 When you issue the @code{watch} command, @value{GDBN} reports
4983
4984 @smallexample
4985 Hardware watchpoint @var{num}: @var{expr}
4986 @end smallexample
4987
4988 @noindent
4989 if it was able to set a hardware watchpoint.
4990
4991 Currently, the @code{awatch} and @code{rwatch} commands can only set
4992 hardware watchpoints, because accesses to data that don't change the
4993 value of the watched expression cannot be detected without examining
4994 every instruction as it is being executed, and @value{GDBN} does not do
4995 that currently. If @value{GDBN} finds that it is unable to set a
4996 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4997 will print a message like this:
4998
4999 @smallexample
5000 Expression cannot be implemented with read/access watchpoint.
5001 @end smallexample
5002
5003 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
5004 data type of the watched expression is wider than what a hardware
5005 watchpoint on the target machine can handle. For example, some systems
5006 can only watch regions that are up to 4 bytes wide; on such systems you
5007 cannot set hardware watchpoints for an expression that yields a
5008 double-precision floating-point number (which is typically 8 bytes
5009 wide). As a work-around, it might be possible to break the large region
5010 into a series of smaller ones and watch them with separate watchpoints.
5011
5012 If you set too many hardware watchpoints, @value{GDBN} might be unable
5013 to insert all of them when you resume the execution of your program.
5014 Since the precise number of active watchpoints is unknown until such
5015 time as the program is about to be resumed, @value{GDBN} might not be
5016 able to warn you about this when you set the watchpoints, and the
5017 warning will be printed only when the program is resumed:
5018
5019 @smallexample
5020 Hardware watchpoint @var{num}: Could not insert watchpoint
5021 @end smallexample
5022
5023 @noindent
5024 If this happens, delete or disable some of the watchpoints.
5025
5026 Watching complex expressions that reference many variables can also
5027 exhaust the resources available for hardware-assisted watchpoints.
5028 That's because @value{GDBN} needs to watch every variable in the
5029 expression with separately allocated resources.
5030
5031 If you call a function interactively using @code{print} or @code{call},
5032 any watchpoints you have set will be inactive until @value{GDBN} reaches another
5033 kind of breakpoint or the call completes.
5034
5035 @value{GDBN} automatically deletes watchpoints that watch local
5036 (automatic) variables, or expressions that involve such variables, when
5037 they go out of scope, that is, when the execution leaves the block in
5038 which these variables were defined. In particular, when the program
5039 being debugged terminates, @emph{all} local variables go out of scope,
5040 and so only watchpoints that watch global variables remain set. If you
5041 rerun the program, you will need to set all such watchpoints again. One
5042 way of doing that would be to set a code breakpoint at the entry to the
5043 @code{main} function and when it breaks, set all the watchpoints.
5044
5045 @cindex watchpoints and threads
5046 @cindex threads and watchpoints
5047 In multi-threaded programs, watchpoints will detect changes to the
5048 watched expression from every thread.
5049
5050 @quotation
5051 @emph{Warning:} In multi-threaded programs, software watchpoints
5052 have only limited usefulness. If @value{GDBN} creates a software
5053 watchpoint, it can only watch the value of an expression @emph{in a
5054 single thread}. If you are confident that the expression can only
5055 change due to the current thread's activity (and if you are also
5056 confident that no other thread can become current), then you can use
5057 software watchpoints as usual. However, @value{GDBN} may not notice
5058 when a non-current thread's activity changes the expression. (Hardware
5059 watchpoints, in contrast, watch an expression in all threads.)
5060 @end quotation
5061
5062 @xref{set remote hardware-watchpoint-limit}.
5063
5064 @node Set Catchpoints
5065 @subsection Setting Catchpoints
5066 @cindex catchpoints, setting
5067 @cindex exception handlers
5068 @cindex event handling
5069
5070 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5071 kinds of program events, such as C@t{++} exceptions or the loading of a
5072 shared library. Use the @code{catch} command to set a catchpoint.
5073
5074 @table @code
5075 @kindex catch
5076 @item catch @var{event}
5077 Stop when @var{event} occurs. The @var{event} can be any of the following:
5078
5079 @table @code
5080 @item throw @r{[}@var{regexp}@r{]}
5081 @itemx rethrow @r{[}@var{regexp}@r{]}
5082 @itemx catch @r{[}@var{regexp}@r{]}
5083 @kindex catch throw
5084 @kindex catch rethrow
5085 @kindex catch catch
5086 @cindex stop on C@t{++} exceptions
5087 The throwing, re-throwing, or catching of a C@t{++} exception.
5088
5089 If @var{regexp} is given, then only exceptions whose type matches the
5090 regular expression will be caught.
5091
5092 @vindex $_exception@r{, convenience variable}
5093 The convenience variable @code{$_exception} is available at an
5094 exception-related catchpoint, on some systems. This holds the
5095 exception being thrown.
5096
5097 There are currently some limitations to C@t{++} exception handling in
5098 @value{GDBN}:
5099
5100 @itemize @bullet
5101 @item
5102 The support for these commands is system-dependent. Currently, only
5103 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5104 supported.
5105
5106 @item
5107 The regular expression feature and the @code{$_exception} convenience
5108 variable rely on the presence of some SDT probes in @code{libstdc++}.
5109 If these probes are not present, then these features cannot be used.
5110 These probes were first available in the GCC 4.8 release, but whether
5111 or not they are available in your GCC also depends on how it was
5112 built.
5113
5114 @item
5115 The @code{$_exception} convenience variable is only valid at the
5116 instruction at which an exception-related catchpoint is set.
5117
5118 @item
5119 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5120 location in the system library which implements runtime exception
5121 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5122 (@pxref{Selection}) to get to your code.
5123
5124 @item
5125 If you call a function interactively, @value{GDBN} normally returns
5126 control to you when the function has finished executing. If the call
5127 raises an exception, however, the call may bypass the mechanism that
5128 returns control to you and cause your program either to abort or to
5129 simply continue running until it hits a breakpoint, catches a signal
5130 that @value{GDBN} is listening for, or exits. This is the case even if
5131 you set a catchpoint for the exception; catchpoints on exceptions are
5132 disabled within interactive calls. @xref{Calling}, for information on
5133 controlling this with @code{set unwind-on-terminating-exception}.
5134
5135 @item
5136 You cannot raise an exception interactively.
5137
5138 @item
5139 You cannot install an exception handler interactively.
5140 @end itemize
5141
5142 @item exception @r{[}@var{name}@r{]}
5143 @kindex catch exception
5144 @cindex Ada exception catching
5145 @cindex catch Ada exceptions
5146 An Ada exception being raised. If an exception name is specified
5147 at the end of the command (eg @code{catch exception Program_Error}),
5148 the debugger will stop only when this specific exception is raised.
5149 Otherwise, the debugger stops execution when any Ada exception is raised.
5150
5151 When inserting an exception catchpoint on a user-defined exception whose
5152 name is identical to one of the exceptions defined by the language, the
5153 fully qualified name must be used as the exception name. Otherwise,
5154 @value{GDBN} will assume that it should stop on the pre-defined exception
5155 rather than the user-defined one. For instance, assuming an exception
5156 called @code{Constraint_Error} is defined in package @code{Pck}, then
5157 the command to use to catch such exceptions is @kbd{catch exception
5158 Pck.Constraint_Error}.
5159
5160 @vindex $_ada_exception@r{, convenience variable}
5161 The convenience variable @code{$_ada_exception} holds the address of
5162 the exception being thrown. This can be useful when setting a
5163 condition for such a catchpoint.
5164
5165 @item exception unhandled
5166 @kindex catch exception unhandled
5167 An exception that was raised but is not handled by the program. The
5168 convenience variable @code{$_ada_exception} is set as for @code{catch
5169 exception}.
5170
5171 @item handlers @r{[}@var{name}@r{]}
5172 @kindex catch handlers
5173 @cindex Ada exception handlers catching
5174 @cindex catch Ada exceptions when handled
5175 An Ada exception being handled. If an exception name is
5176 specified at the end of the command
5177 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5178 only when this specific exception is handled.
5179 Otherwise, the debugger stops execution when any Ada exception is handled.
5180
5181 When inserting a handlers catchpoint on a user-defined
5182 exception whose name is identical to one of the exceptions
5183 defined by the language, the fully qualified name must be used
5184 as the exception name. Otherwise, @value{GDBN} will assume that it
5185 should stop on the pre-defined exception rather than the
5186 user-defined one. For instance, assuming an exception called
5187 @code{Constraint_Error} is defined in package @code{Pck}, then the
5188 command to use to catch such exceptions handling is
5189 @kbd{catch handlers Pck.Constraint_Error}.
5190
5191 The convenience variable @code{$_ada_exception} is set as for
5192 @code{catch exception}.
5193
5194 @item assert
5195 @kindex catch assert
5196 A failed Ada assertion. Note that the convenience variable
5197 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5198
5199 @item exec
5200 @kindex catch exec
5201 @cindex break on fork/exec
5202 A call to @code{exec}.
5203
5204 @anchor{catch syscall}
5205 @item syscall
5206 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5207 @kindex catch syscall
5208 @cindex break on a system call.
5209 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5210 syscall is a mechanism for application programs to request a service
5211 from the operating system (OS) or one of the OS system services.
5212 @value{GDBN} can catch some or all of the syscalls issued by the
5213 debuggee, and show the related information for each syscall. If no
5214 argument is specified, calls to and returns from all system calls
5215 will be caught.
5216
5217 @var{name} can be any system call name that is valid for the
5218 underlying OS. Just what syscalls are valid depends on the OS. On
5219 GNU and Unix systems, you can find the full list of valid syscall
5220 names on @file{/usr/include/asm/unistd.h}.
5221
5222 @c For MS-Windows, the syscall names and the corresponding numbers
5223 @c can be found, e.g., on this URL:
5224 @c http://www.metasploit.com/users/opcode/syscalls.html
5225 @c but we don't support Windows syscalls yet.
5226
5227 Normally, @value{GDBN} knows in advance which syscalls are valid for
5228 each OS, so you can use the @value{GDBN} command-line completion
5229 facilities (@pxref{Completion,, command completion}) to list the
5230 available choices.
5231
5232 You may also specify the system call numerically. A syscall's
5233 number is the value passed to the OS's syscall dispatcher to
5234 identify the requested service. When you specify the syscall by its
5235 name, @value{GDBN} uses its database of syscalls to convert the name
5236 into the corresponding numeric code, but using the number directly
5237 may be useful if @value{GDBN}'s database does not have the complete
5238 list of syscalls on your system (e.g., because @value{GDBN} lags
5239 behind the OS upgrades).
5240
5241 You may specify a group of related syscalls to be caught at once using
5242 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5243 instance, on some platforms @value{GDBN} allows you to catch all
5244 network related syscalls, by passing the argument @code{group:network}
5245 to @code{catch syscall}. Note that not all syscall groups are
5246 available in every system. You can use the command completion
5247 facilities (@pxref{Completion,, command completion}) to list the
5248 syscall groups available on your environment.
5249
5250 The example below illustrates how this command works if you don't provide
5251 arguments to it:
5252
5253 @smallexample
5254 (@value{GDBP}) catch syscall
5255 Catchpoint 1 (syscall)
5256 (@value{GDBP}) r
5257 Starting program: /tmp/catch-syscall
5258
5259 Catchpoint 1 (call to syscall 'close'), \
5260 0xffffe424 in __kernel_vsyscall ()
5261 (@value{GDBP}) c
5262 Continuing.
5263
5264 Catchpoint 1 (returned from syscall 'close'), \
5265 0xffffe424 in __kernel_vsyscall ()
5266 (@value{GDBP})
5267 @end smallexample
5268
5269 Here is an example of catching a system call by name:
5270
5271 @smallexample
5272 (@value{GDBP}) catch syscall chroot
5273 Catchpoint 1 (syscall 'chroot' [61])
5274 (@value{GDBP}) r
5275 Starting program: /tmp/catch-syscall
5276
5277 Catchpoint 1 (call to syscall 'chroot'), \
5278 0xffffe424 in __kernel_vsyscall ()
5279 (@value{GDBP}) c
5280 Continuing.
5281
5282 Catchpoint 1 (returned from syscall 'chroot'), \
5283 0xffffe424 in __kernel_vsyscall ()
5284 (@value{GDBP})
5285 @end smallexample
5286
5287 An example of specifying a system call numerically. In the case
5288 below, the syscall number has a corresponding entry in the XML
5289 file, so @value{GDBN} finds its name and prints it:
5290
5291 @smallexample
5292 (@value{GDBP}) catch syscall 252
5293 Catchpoint 1 (syscall(s) 'exit_group')
5294 (@value{GDBP}) r
5295 Starting program: /tmp/catch-syscall
5296
5297 Catchpoint 1 (call to syscall 'exit_group'), \
5298 0xffffe424 in __kernel_vsyscall ()
5299 (@value{GDBP}) c
5300 Continuing.
5301
5302 Program exited normally.
5303 (@value{GDBP})
5304 @end smallexample
5305
5306 Here is an example of catching a syscall group:
5307
5308 @smallexample
5309 (@value{GDBP}) catch syscall group:process
5310 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5311 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5312 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5313 (@value{GDBP}) r
5314 Starting program: /tmp/catch-syscall
5315
5316 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5317 from /lib64/ld-linux-x86-64.so.2
5318
5319 (@value{GDBP}) c
5320 Continuing.
5321 @end smallexample
5322
5323 However, there can be situations when there is no corresponding name
5324 in XML file for that syscall number. In this case, @value{GDBN} prints
5325 a warning message saying that it was not able to find the syscall name,
5326 but the catchpoint will be set anyway. See the example below:
5327
5328 @smallexample
5329 (@value{GDBP}) catch syscall 764
5330 warning: The number '764' does not represent a known syscall.
5331 Catchpoint 2 (syscall 764)
5332 (@value{GDBP})
5333 @end smallexample
5334
5335 If you configure @value{GDBN} using the @samp{--without-expat} option,
5336 it will not be able to display syscall names. Also, if your
5337 architecture does not have an XML file describing its system calls,
5338 you will not be able to see the syscall names. It is important to
5339 notice that these two features are used for accessing the syscall
5340 name database. In either case, you will see a warning like this:
5341
5342 @smallexample
5343 (@value{GDBP}) catch syscall
5344 warning: Could not open "syscalls/i386-linux.xml"
5345 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5346 GDB will not be able to display syscall names.
5347 Catchpoint 1 (syscall)
5348 (@value{GDBP})
5349 @end smallexample
5350
5351 Of course, the file name will change depending on your architecture and system.
5352
5353 Still using the example above, you can also try to catch a syscall by its
5354 number. In this case, you would see something like:
5355
5356 @smallexample
5357 (@value{GDBP}) catch syscall 252
5358 Catchpoint 1 (syscall(s) 252)
5359 @end smallexample
5360
5361 Again, in this case @value{GDBN} would not be able to display syscall's names.
5362
5363 @item fork
5364 @kindex catch fork
5365 A call to @code{fork}.
5366
5367 @item vfork
5368 @kindex catch vfork
5369 A call to @code{vfork}.
5370
5371 @item load @r{[}@var{regexp}@r{]}
5372 @itemx unload @r{[}@var{regexp}@r{]}
5373 @kindex catch load
5374 @kindex catch unload
5375 The loading or unloading of a shared library. If @var{regexp} is
5376 given, then the catchpoint will stop only if the regular expression
5377 matches one of the affected libraries.
5378
5379 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5380 @kindex catch signal
5381 The delivery of a signal.
5382
5383 With no arguments, this catchpoint will catch any signal that is not
5384 used internally by @value{GDBN}, specifically, all signals except
5385 @samp{SIGTRAP} and @samp{SIGINT}.
5386
5387 With the argument @samp{all}, all signals, including those used by
5388 @value{GDBN}, will be caught. This argument cannot be used with other
5389 signal names.
5390
5391 Otherwise, the arguments are a list of signal names as given to
5392 @code{handle} (@pxref{Signals}). Only signals specified in this list
5393 will be caught.
5394
5395 One reason that @code{catch signal} can be more useful than
5396 @code{handle} is that you can attach commands and conditions to the
5397 catchpoint.
5398
5399 When a signal is caught by a catchpoint, the signal's @code{stop} and
5400 @code{print} settings, as specified by @code{handle}, are ignored.
5401 However, whether the signal is still delivered to the inferior depends
5402 on the @code{pass} setting; this can be changed in the catchpoint's
5403 commands.
5404
5405 @end table
5406
5407 @item tcatch @var{event}
5408 @kindex tcatch
5409 Set a catchpoint that is enabled only for one stop. The catchpoint is
5410 automatically deleted after the first time the event is caught.
5411
5412 @end table
5413
5414 Use the @code{info break} command to list the current catchpoints.
5415
5416
5417 @node Delete Breaks
5418 @subsection Deleting Breakpoints
5419
5420 @cindex clearing breakpoints, watchpoints, catchpoints
5421 @cindex deleting breakpoints, watchpoints, catchpoints
5422 It is often necessary to eliminate a breakpoint, watchpoint, or
5423 catchpoint once it has done its job and you no longer want your program
5424 to stop there. This is called @dfn{deleting} the breakpoint. A
5425 breakpoint that has been deleted no longer exists; it is forgotten.
5426
5427 With the @code{clear} command you can delete breakpoints according to
5428 where they are in your program. With the @code{delete} command you can
5429 delete individual breakpoints, watchpoints, or catchpoints by specifying
5430 their breakpoint numbers.
5431
5432 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5433 automatically ignores breakpoints on the first instruction to be executed
5434 when you continue execution without changing the execution address.
5435
5436 @table @code
5437 @kindex clear
5438 @item clear
5439 Delete any breakpoints at the next instruction to be executed in the
5440 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5441 the innermost frame is selected, this is a good way to delete a
5442 breakpoint where your program just stopped.
5443
5444 @item clear @var{location}
5445 Delete any breakpoints set at the specified @var{location}.
5446 @xref{Specify Location}, for the various forms of @var{location}; the
5447 most useful ones are listed below:
5448
5449 @table @code
5450 @item clear @var{function}
5451 @itemx clear @var{filename}:@var{function}
5452 Delete any breakpoints set at entry to the named @var{function}.
5453
5454 @item clear @var{linenum}
5455 @itemx clear @var{filename}:@var{linenum}
5456 Delete any breakpoints set at or within the code of the specified
5457 @var{linenum} of the specified @var{filename}.
5458 @end table
5459
5460 @cindex delete breakpoints
5461 @kindex delete
5462 @kindex d @r{(@code{delete})}
5463 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5464 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5465 list specified as argument. If no argument is specified, delete all
5466 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5467 confirm off}). You can abbreviate this command as @code{d}.
5468 @end table
5469
5470 @node Disabling
5471 @subsection Disabling Breakpoints
5472
5473 @cindex enable/disable a breakpoint
5474 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5475 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5476 it had been deleted, but remembers the information on the breakpoint so
5477 that you can @dfn{enable} it again later.
5478
5479 You disable and enable breakpoints, watchpoints, and catchpoints with
5480 the @code{enable} and @code{disable} commands, optionally specifying
5481 one or more breakpoint numbers as arguments. Use @code{info break} to
5482 print a list of all breakpoints, watchpoints, and catchpoints if you
5483 do not know which numbers to use.
5484
5485 Disabling and enabling a breakpoint that has multiple locations
5486 affects all of its locations.
5487
5488 A breakpoint, watchpoint, or catchpoint can have any of several
5489 different states of enablement:
5490
5491 @itemize @bullet
5492 @item
5493 Enabled. The breakpoint stops your program. A breakpoint set
5494 with the @code{break} command starts out in this state.
5495 @item
5496 Disabled. The breakpoint has no effect on your program.
5497 @item
5498 Enabled once. The breakpoint stops your program, but then becomes
5499 disabled.
5500 @item
5501 Enabled for a count. The breakpoint stops your program for the next
5502 N times, then becomes disabled.
5503 @item
5504 Enabled for deletion. The breakpoint stops your program, but
5505 immediately after it does so it is deleted permanently. A breakpoint
5506 set with the @code{tbreak} command starts out in this state.
5507 @end itemize
5508
5509 You can use the following commands to enable or disable breakpoints,
5510 watchpoints, and catchpoints:
5511
5512 @table @code
5513 @kindex disable
5514 @kindex dis @r{(@code{disable})}
5515 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5516 Disable the specified breakpoints---or all breakpoints, if none are
5517 listed. A disabled breakpoint has no effect but is not forgotten. All
5518 options such as ignore-counts, conditions and commands are remembered in
5519 case the breakpoint is enabled again later. You may abbreviate
5520 @code{disable} as @code{dis}.
5521
5522 @kindex enable
5523 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5524 Enable the specified breakpoints (or all defined breakpoints). They
5525 become effective once again in stopping your program.
5526
5527 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5528 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5529 of these breakpoints immediately after stopping your program.
5530
5531 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5532 Enable the specified breakpoints temporarily. @value{GDBN} records
5533 @var{count} with each of the specified breakpoints, and decrements a
5534 breakpoint's count when it is hit. When any count reaches 0,
5535 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5536 count (@pxref{Conditions, ,Break Conditions}), that will be
5537 decremented to 0 before @var{count} is affected.
5538
5539 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5540 Enable the specified breakpoints to work once, then die. @value{GDBN}
5541 deletes any of these breakpoints as soon as your program stops there.
5542 Breakpoints set by the @code{tbreak} command start out in this state.
5543 @end table
5544
5545 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5546 @c confusing: tbreak is also initially enabled.
5547 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5548 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5549 subsequently, they become disabled or enabled only when you use one of
5550 the commands above. (The command @code{until} can set and delete a
5551 breakpoint of its own, but it does not change the state of your other
5552 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5553 Stepping}.)
5554
5555 @node Conditions
5556 @subsection Break Conditions
5557 @cindex conditional breakpoints
5558 @cindex breakpoint conditions
5559
5560 @c FIXME what is scope of break condition expr? Context where wanted?
5561 @c in particular for a watchpoint?
5562 The simplest sort of breakpoint breaks every time your program reaches a
5563 specified place. You can also specify a @dfn{condition} for a
5564 breakpoint. A condition is just a Boolean expression in your
5565 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5566 a condition evaluates the expression each time your program reaches it,
5567 and your program stops only if the condition is @emph{true}.
5568
5569 This is the converse of using assertions for program validation; in that
5570 situation, you want to stop when the assertion is violated---that is,
5571 when the condition is false. In C, if you want to test an assertion expressed
5572 by the condition @var{assert}, you should set the condition
5573 @samp{! @var{assert}} on the appropriate breakpoint.
5574
5575 Conditions are also accepted for watchpoints; you may not need them,
5576 since a watchpoint is inspecting the value of an expression anyhow---but
5577 it might be simpler, say, to just set a watchpoint on a variable name,
5578 and specify a condition that tests whether the new value is an interesting
5579 one.
5580
5581 Break conditions can have side effects, and may even call functions in
5582 your program. This can be useful, for example, to activate functions
5583 that log program progress, or to use your own print functions to
5584 format special data structures. The effects are completely predictable
5585 unless there is another enabled breakpoint at the same address. (In
5586 that case, @value{GDBN} might see the other breakpoint first and stop your
5587 program without checking the condition of this one.) Note that
5588 breakpoint commands are usually more convenient and flexible than break
5589 conditions for the
5590 purpose of performing side effects when a breakpoint is reached
5591 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5592
5593 Breakpoint conditions can also be evaluated on the target's side if
5594 the target supports it. Instead of evaluating the conditions locally,
5595 @value{GDBN} encodes the expression into an agent expression
5596 (@pxref{Agent Expressions}) suitable for execution on the target,
5597 independently of @value{GDBN}. Global variables become raw memory
5598 locations, locals become stack accesses, and so forth.
5599
5600 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5601 when its condition evaluates to true. This mechanism may provide faster
5602 response times depending on the performance characteristics of the target
5603 since it does not need to keep @value{GDBN} informed about
5604 every breakpoint trigger, even those with false conditions.
5605
5606 Break conditions can be specified when a breakpoint is set, by using
5607 @samp{if} in the arguments to the @code{break} command. @xref{Set
5608 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5609 with the @code{condition} command.
5610
5611 You can also use the @code{if} keyword with the @code{watch} command.
5612 The @code{catch} command does not recognize the @code{if} keyword;
5613 @code{condition} is the only way to impose a further condition on a
5614 catchpoint.
5615
5616 @table @code
5617 @kindex condition
5618 @item condition @var{bnum} @var{expression}
5619 Specify @var{expression} as the break condition for breakpoint,
5620 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5621 breakpoint @var{bnum} stops your program only if the value of
5622 @var{expression} is true (nonzero, in C). When you use
5623 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5624 syntactic correctness, and to determine whether symbols in it have
5625 referents in the context of your breakpoint. If @var{expression} uses
5626 symbols not referenced in the context of the breakpoint, @value{GDBN}
5627 prints an error message:
5628
5629 @smallexample
5630 No symbol "foo" in current context.
5631 @end smallexample
5632
5633 @noindent
5634 @value{GDBN} does
5635 not actually evaluate @var{expression} at the time the @code{condition}
5636 command (or a command that sets a breakpoint with a condition, like
5637 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5638
5639 @item condition -force @var{bnum} @var{expression}
5640 When the @code{-force} flag is used, define the condition even if
5641 @var{expression} is invalid at all the current locations of breakpoint
5642 @var{bnum}. This is similar to the @code{-force-condition} option
5643 of the @code{break} command.
5644
5645 @item condition @var{bnum}
5646 Remove the condition from breakpoint number @var{bnum}. It becomes
5647 an ordinary unconditional breakpoint.
5648 @end table
5649
5650 @cindex ignore count (of breakpoint)
5651 A special case of a breakpoint condition is to stop only when the
5652 breakpoint has been reached a certain number of times. This is so
5653 useful that there is a special way to do it, using the @dfn{ignore
5654 count} of the breakpoint. Every breakpoint has an ignore count, which
5655 is an integer. Most of the time, the ignore count is zero, and
5656 therefore has no effect. But if your program reaches a breakpoint whose
5657 ignore count is positive, then instead of stopping, it just decrements
5658 the ignore count by one and continues. As a result, if the ignore count
5659 value is @var{n}, the breakpoint does not stop the next @var{n} times
5660 your program reaches it.
5661
5662 @table @code
5663 @kindex ignore
5664 @item ignore @var{bnum} @var{count}
5665 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5666 The next @var{count} times the breakpoint is reached, your program's
5667 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5668 takes no action.
5669
5670 To make the breakpoint stop the next time it is reached, specify
5671 a count of zero.
5672
5673 When you use @code{continue} to resume execution of your program from a
5674 breakpoint, you can specify an ignore count directly as an argument to
5675 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5676 Stepping,,Continuing and Stepping}.
5677
5678 If a breakpoint has a positive ignore count and a condition, the
5679 condition is not checked. Once the ignore count reaches zero,
5680 @value{GDBN} resumes checking the condition.
5681
5682 You could achieve the effect of the ignore count with a condition such
5683 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5684 is decremented each time. @xref{Convenience Vars, ,Convenience
5685 Variables}.
5686 @end table
5687
5688 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5689
5690
5691 @node Break Commands
5692 @subsection Breakpoint Command Lists
5693
5694 @cindex breakpoint commands
5695 You can give any breakpoint (or watchpoint or catchpoint) a series of
5696 commands to execute when your program stops due to that breakpoint. For
5697 example, you might want to print the values of certain expressions, or
5698 enable other breakpoints.
5699
5700 @table @code
5701 @kindex commands
5702 @kindex end@r{ (breakpoint commands)}
5703 @item commands @r{[}@var{list}@dots{}@r{]}
5704 @itemx @dots{} @var{command-list} @dots{}
5705 @itemx end
5706 Specify a list of commands for the given breakpoints. The commands
5707 themselves appear on the following lines. Type a line containing just
5708 @code{end} to terminate the commands.
5709
5710 To remove all commands from a breakpoint, type @code{commands} and
5711 follow it immediately with @code{end}; that is, give no commands.
5712
5713 With no argument, @code{commands} refers to the last breakpoint,
5714 watchpoint, or catchpoint set (not to the breakpoint most recently
5715 encountered). If the most recent breakpoints were set with a single
5716 command, then the @code{commands} will apply to all the breakpoints
5717 set by that command. This applies to breakpoints set by
5718 @code{rbreak}, and also applies when a single @code{break} command
5719 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5720 Expressions}).
5721 @end table
5722
5723 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5724 disabled within a @var{command-list}.
5725
5726 You can use breakpoint commands to start your program up again. Simply
5727 use the @code{continue} command, or @code{step}, or any other command
5728 that resumes execution.
5729
5730 Any other commands in the command list, after a command that resumes
5731 execution, are ignored. This is because any time you resume execution
5732 (even with a simple @code{next} or @code{step}), you may encounter
5733 another breakpoint---which could have its own command list, leading to
5734 ambiguities about which list to execute.
5735
5736 @kindex silent
5737 If the first command you specify in a command list is @code{silent}, the
5738 usual message about stopping at a breakpoint is not printed. This may
5739 be desirable for breakpoints that are to print a specific message and
5740 then continue. If none of the remaining commands print anything, you
5741 see no sign that the breakpoint was reached. @code{silent} is
5742 meaningful only at the beginning of a breakpoint command list.
5743
5744 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5745 print precisely controlled output, and are often useful in silent
5746 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5747
5748 For example, here is how you could use breakpoint commands to print the
5749 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5750
5751 @smallexample
5752 break foo if x>0
5753 commands
5754 silent
5755 printf "x is %d\n",x
5756 cont
5757 end
5758 @end smallexample
5759
5760 One application for breakpoint commands is to compensate for one bug so
5761 you can test for another. Put a breakpoint just after the erroneous line
5762 of code, give it a condition to detect the case in which something
5763 erroneous has been done, and give it commands to assign correct values
5764 to any variables that need them. End with the @code{continue} command
5765 so that your program does not stop, and start with the @code{silent}
5766 command so that no output is produced. Here is an example:
5767
5768 @smallexample
5769 break 403
5770 commands
5771 silent
5772 set x = y + 4
5773 cont
5774 end
5775 @end smallexample
5776
5777 @node Dynamic Printf
5778 @subsection Dynamic Printf
5779
5780 @cindex dynamic printf
5781 @cindex dprintf
5782 The dynamic printf command @code{dprintf} combines a breakpoint with
5783 formatted printing of your program's data to give you the effect of
5784 inserting @code{printf} calls into your program on-the-fly, without
5785 having to recompile it.
5786
5787 In its most basic form, the output goes to the GDB console. However,
5788 you can set the variable @code{dprintf-style} for alternate handling.
5789 For instance, you can ask to format the output by calling your
5790 program's @code{printf} function. This has the advantage that the
5791 characters go to the program's output device, so they can recorded in
5792 redirects to files and so forth.
5793
5794 If you are doing remote debugging with a stub or agent, you can also
5795 ask to have the printf handled by the remote agent. In addition to
5796 ensuring that the output goes to the remote program's device along
5797 with any other output the program might produce, you can also ask that
5798 the dprintf remain active even after disconnecting from the remote
5799 target. Using the stub/agent is also more efficient, as it can do
5800 everything without needing to communicate with @value{GDBN}.
5801
5802 @table @code
5803 @kindex dprintf
5804 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5805 Whenever execution reaches @var{location}, print the values of one or
5806 more @var{expressions} under the control of the string @var{template}.
5807 To print several values, separate them with commas.
5808
5809 @item set dprintf-style @var{style}
5810 Set the dprintf output to be handled in one of several different
5811 styles enumerated below. A change of style affects all existing
5812 dynamic printfs immediately. (If you need individual control over the
5813 print commands, simply define normal breakpoints with
5814 explicitly-supplied command lists.)
5815
5816 @table @code
5817 @item gdb
5818 @kindex dprintf-style gdb
5819 Handle the output using the @value{GDBN} @code{printf} command.
5820
5821 @item call
5822 @kindex dprintf-style call
5823 Handle the output by calling a function in your program (normally
5824 @code{printf}).
5825
5826 @item agent
5827 @kindex dprintf-style agent
5828 Have the remote debugging agent (such as @code{gdbserver}) handle
5829 the output itself. This style is only available for agents that
5830 support running commands on the target.
5831 @end table
5832
5833 @item set dprintf-function @var{function}
5834 Set the function to call if the dprintf style is @code{call}. By
5835 default its value is @code{printf}. You may set it to any expression.
5836 that @value{GDBN} can evaluate to a function, as per the @code{call}
5837 command.
5838
5839 @item set dprintf-channel @var{channel}
5840 Set a ``channel'' for dprintf. If set to a non-empty value,
5841 @value{GDBN} will evaluate it as an expression and pass the result as
5842 a first argument to the @code{dprintf-function}, in the manner of
5843 @code{fprintf} and similar functions. Otherwise, the dprintf format
5844 string will be the first argument, in the manner of @code{printf}.
5845
5846 As an example, if you wanted @code{dprintf} output to go to a logfile
5847 that is a standard I/O stream assigned to the variable @code{mylog},
5848 you could do the following:
5849
5850 @example
5851 (gdb) set dprintf-style call
5852 (gdb) set dprintf-function fprintf
5853 (gdb) set dprintf-channel mylog
5854 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5855 Dprintf 1 at 0x123456: file main.c, line 25.
5856 (gdb) info break
5857 1 dprintf keep y 0x00123456 in main at main.c:25
5858 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5859 continue
5860 (gdb)
5861 @end example
5862
5863 Note that the @code{info break} displays the dynamic printf commands
5864 as normal breakpoint commands; you can thus easily see the effect of
5865 the variable settings.
5866
5867 @item set disconnected-dprintf on
5868 @itemx set disconnected-dprintf off
5869 @kindex set disconnected-dprintf
5870 Choose whether @code{dprintf} commands should continue to run if
5871 @value{GDBN} has disconnected from the target. This only applies
5872 if the @code{dprintf-style} is @code{agent}.
5873
5874 @item show disconnected-dprintf off
5875 @kindex show disconnected-dprintf
5876 Show the current choice for disconnected @code{dprintf}.
5877
5878 @end table
5879
5880 @value{GDBN} does not check the validity of function and channel,
5881 relying on you to supply values that are meaningful for the contexts
5882 in which they are being used. For instance, the function and channel
5883 may be the values of local variables, but if that is the case, then
5884 all enabled dynamic prints must be at locations within the scope of
5885 those locals. If evaluation fails, @value{GDBN} will report an error.
5886
5887 @node Save Breakpoints
5888 @subsection How to save breakpoints to a file
5889
5890 To save breakpoint definitions to a file use the @w{@code{save
5891 breakpoints}} command.
5892
5893 @table @code
5894 @kindex save breakpoints
5895 @cindex save breakpoints to a file for future sessions
5896 @item save breakpoints [@var{filename}]
5897 This command saves all current breakpoint definitions together with
5898 their commands and ignore counts, into a file @file{@var{filename}}
5899 suitable for use in a later debugging session. This includes all
5900 types of breakpoints (breakpoints, watchpoints, catchpoints,
5901 tracepoints). To read the saved breakpoint definitions, use the
5902 @code{source} command (@pxref{Command Files}). Note that watchpoints
5903 with expressions involving local variables may fail to be recreated
5904 because it may not be possible to access the context where the
5905 watchpoint is valid anymore. Because the saved breakpoint definitions
5906 are simply a sequence of @value{GDBN} commands that recreate the
5907 breakpoints, you can edit the file in your favorite editing program,
5908 and remove the breakpoint definitions you're not interested in, or
5909 that can no longer be recreated.
5910 @end table
5911
5912 @node Static Probe Points
5913 @subsection Static Probe Points
5914
5915 @cindex static probe point, SystemTap
5916 @cindex static probe point, DTrace
5917 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5918 for Statically Defined Tracing, and the probes are designed to have a tiny
5919 runtime code and data footprint, and no dynamic relocations.
5920
5921 Currently, the following types of probes are supported on
5922 ELF-compatible systems:
5923
5924 @itemize @bullet
5925
5926 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5927 @acronym{SDT} probes@footnote{See
5928 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5929 for more information on how to add @code{SystemTap} @acronym{SDT}
5930 probes in your applications.}. @code{SystemTap} probes are usable
5931 from assembly, C and C@t{++} languages@footnote{See
5932 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5933 for a good reference on how the @acronym{SDT} probes are implemented.}.
5934
5935 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5936 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5937 C@t{++} languages.
5938 @end itemize
5939
5940 @cindex semaphores on static probe points
5941 Some @code{SystemTap} probes have an associated semaphore variable;
5942 for instance, this happens automatically if you defined your probe
5943 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5944 @value{GDBN} will automatically enable it when you specify a
5945 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5946 breakpoint at a probe's location by some other method (e.g.,
5947 @code{break file:line}), then @value{GDBN} will not automatically set
5948 the semaphore. @code{DTrace} probes do not support semaphores.
5949
5950 You can examine the available static static probes using @code{info
5951 probes}, with optional arguments:
5952
5953 @table @code
5954 @kindex info probes
5955 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5956 If given, @var{type} is either @code{stap} for listing
5957 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5958 probes. If omitted all probes are listed regardless of their types.
5959
5960 If given, @var{provider} is a regular expression used to match against provider
5961 names when selecting which probes to list. If omitted, probes by all
5962 probes from all providers are listed.
5963
5964 If given, @var{name} is a regular expression to match against probe names
5965 when selecting which probes to list. If omitted, probe names are not
5966 considered when deciding whether to display them.
5967
5968 If given, @var{objfile} is a regular expression used to select which
5969 object files (executable or shared libraries) to examine. If not
5970 given, all object files are considered.
5971
5972 @item info probes all
5973 List the available static probes, from all types.
5974 @end table
5975
5976 @cindex enabling and disabling probes
5977 Some probe points can be enabled and/or disabled. The effect of
5978 enabling or disabling a probe depends on the type of probe being
5979 handled. Some @code{DTrace} probes can be enabled or
5980 disabled, but @code{SystemTap} probes cannot be disabled.
5981
5982 You can enable (or disable) one or more probes using the following
5983 commands, with optional arguments:
5984
5985 @table @code
5986 @kindex enable probes
5987 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5988 If given, @var{provider} is a regular expression used to match against
5989 provider names when selecting which probes to enable. If omitted,
5990 all probes from all providers are enabled.
5991
5992 If given, @var{name} is a regular expression to match against probe
5993 names when selecting which probes to enable. If omitted, probe names
5994 are not considered when deciding whether to enable them.
5995
5996 If given, @var{objfile} is a regular expression used to select which
5997 object files (executable or shared libraries) to examine. If not
5998 given, all object files are considered.
5999
6000 @kindex disable probes
6001 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
6002 See the @code{enable probes} command above for a description of the
6003 optional arguments accepted by this command.
6004 @end table
6005
6006 @vindex $_probe_arg@r{, convenience variable}
6007 A probe may specify up to twelve arguments. These are available at the
6008 point at which the probe is defined---that is, when the current PC is
6009 at the probe's location. The arguments are available using the
6010 convenience variables (@pxref{Convenience Vars})
6011 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
6012 probes each probe argument is an integer of the appropriate size;
6013 types are not preserved. In @code{DTrace} probes types are preserved
6014 provided that they are recognized as such by @value{GDBN}; otherwise
6015 the value of the probe argument will be a long integer. The
6016 convenience variable @code{$_probe_argc} holds the number of arguments
6017 at the current probe point.
6018
6019 These variables are always available, but attempts to access them at
6020 any location other than a probe point will cause @value{GDBN} to give
6021 an error message.
6022
6023
6024 @c @ifclear BARETARGET
6025 @node Error in Breakpoints
6026 @subsection ``Cannot insert breakpoints''
6027
6028 If you request too many active hardware-assisted breakpoints and
6029 watchpoints, you will see this error message:
6030
6031 @c FIXME: the precise wording of this message may change; the relevant
6032 @c source change is not committed yet (Sep 3, 1999).
6033 @smallexample
6034 Stopped; cannot insert breakpoints.
6035 You may have requested too many hardware breakpoints and watchpoints.
6036 @end smallexample
6037
6038 @noindent
6039 This message is printed when you attempt to resume the program, since
6040 only then @value{GDBN} knows exactly how many hardware breakpoints and
6041 watchpoints it needs to insert.
6042
6043 When this message is printed, you need to disable or remove some of the
6044 hardware-assisted breakpoints and watchpoints, and then continue.
6045
6046 @node Breakpoint-related Warnings
6047 @subsection ``Breakpoint address adjusted...''
6048 @cindex breakpoint address adjusted
6049
6050 Some processor architectures place constraints on the addresses at
6051 which breakpoints may be placed. For architectures thus constrained,
6052 @value{GDBN} will attempt to adjust the breakpoint's address to comply
6053 with the constraints dictated by the architecture.
6054
6055 One example of such an architecture is the Fujitsu FR-V. The FR-V is
6056 a VLIW architecture in which a number of RISC-like instructions may be
6057 bundled together for parallel execution. The FR-V architecture
6058 constrains the location of a breakpoint instruction within such a
6059 bundle to the instruction with the lowest address. @value{GDBN}
6060 honors this constraint by adjusting a breakpoint's address to the
6061 first in the bundle.
6062
6063 It is not uncommon for optimized code to have bundles which contain
6064 instructions from different source statements, thus it may happen that
6065 a breakpoint's address will be adjusted from one source statement to
6066 another. Since this adjustment may significantly alter @value{GDBN}'s
6067 breakpoint related behavior from what the user expects, a warning is
6068 printed when the breakpoint is first set and also when the breakpoint
6069 is hit.
6070
6071 A warning like the one below is printed when setting a breakpoint
6072 that's been subject to address adjustment:
6073
6074 @smallexample
6075 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6076 @end smallexample
6077
6078 Such warnings are printed both for user settable and @value{GDBN}'s
6079 internal breakpoints. If you see one of these warnings, you should
6080 verify that a breakpoint set at the adjusted address will have the
6081 desired affect. If not, the breakpoint in question may be removed and
6082 other breakpoints may be set which will have the desired behavior.
6083 E.g., it may be sufficient to place the breakpoint at a later
6084 instruction. A conditional breakpoint may also be useful in some
6085 cases to prevent the breakpoint from triggering too often.
6086
6087 @value{GDBN} will also issue a warning when stopping at one of these
6088 adjusted breakpoints:
6089
6090 @smallexample
6091 warning: Breakpoint 1 address previously adjusted from 0x00010414
6092 to 0x00010410.
6093 @end smallexample
6094
6095 When this warning is encountered, it may be too late to take remedial
6096 action except in cases where the breakpoint is hit earlier or more
6097 frequently than expected.
6098
6099 @node Continuing and Stepping
6100 @section Continuing and Stepping
6101
6102 @cindex stepping
6103 @cindex continuing
6104 @cindex resuming execution
6105 @dfn{Continuing} means resuming program execution until your program
6106 completes normally. In contrast, @dfn{stepping} means executing just
6107 one more ``step'' of your program, where ``step'' may mean either one
6108 line of source code, or one machine instruction (depending on what
6109 particular command you use). Either when continuing or when stepping,
6110 your program may stop even sooner, due to a breakpoint or a signal. (If
6111 it stops due to a signal, you may want to use @code{handle}, or use
6112 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6113 or you may step into the signal's handler (@pxref{stepping and signal
6114 handlers}).)
6115
6116 @table @code
6117 @kindex continue
6118 @kindex c @r{(@code{continue})}
6119 @kindex fg @r{(resume foreground execution)}
6120 @item continue @r{[}@var{ignore-count}@r{]}
6121 @itemx c @r{[}@var{ignore-count}@r{]}
6122 @itemx fg @r{[}@var{ignore-count}@r{]}
6123 Resume program execution, at the address where your program last stopped;
6124 any breakpoints set at that address are bypassed. The optional argument
6125 @var{ignore-count} allows you to specify a further number of times to
6126 ignore a breakpoint at this location; its effect is like that of
6127 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6128
6129 The argument @var{ignore-count} is meaningful only when your program
6130 stopped due to a breakpoint. At other times, the argument to
6131 @code{continue} is ignored.
6132
6133 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6134 debugged program is deemed to be the foreground program) are provided
6135 purely for convenience, and have exactly the same behavior as
6136 @code{continue}.
6137 @end table
6138
6139 To resume execution at a different place, you can use @code{return}
6140 (@pxref{Returning, ,Returning from a Function}) to go back to the
6141 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6142 Different Address}) to go to an arbitrary location in your program.
6143
6144 A typical technique for using stepping is to set a breakpoint
6145 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6146 beginning of the function or the section of your program where a problem
6147 is believed to lie, run your program until it stops at that breakpoint,
6148 and then step through the suspect area, examining the variables that are
6149 interesting, until you see the problem happen.
6150
6151 @table @code
6152 @kindex step
6153 @kindex s @r{(@code{step})}
6154 @item step
6155 Continue running your program until control reaches a different source
6156 line, then stop it and return control to @value{GDBN}. This command is
6157 abbreviated @code{s}.
6158
6159 @quotation
6160 @c "without debugging information" is imprecise; actually "without line
6161 @c numbers in the debugging information". (gcc -g1 has debugging info but
6162 @c not line numbers). But it seems complex to try to make that
6163 @c distinction here.
6164 @emph{Warning:} If you use the @code{step} command while control is
6165 within a function that was compiled without debugging information,
6166 execution proceeds until control reaches a function that does have
6167 debugging information. Likewise, it will not step into a function which
6168 is compiled without debugging information. To step through functions
6169 without debugging information, use the @code{stepi} command, described
6170 below.
6171 @end quotation
6172
6173 The @code{step} command only stops at the first instruction of a source
6174 line. This prevents the multiple stops that could otherwise occur in
6175 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6176 to stop if a function that has debugging information is called within
6177 the line. In other words, @code{step} @emph{steps inside} any functions
6178 called within the line.
6179
6180 Also, the @code{step} command only enters a function if there is line
6181 number information for the function. Otherwise it acts like the
6182 @code{next} command. This avoids problems when using @code{cc -gl}
6183 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6184 was any debugging information about the routine.
6185
6186 @item step @var{count}
6187 Continue running as in @code{step}, but do so @var{count} times. If a
6188 breakpoint is reached, or a signal not related to stepping occurs before
6189 @var{count} steps, stepping stops right away.
6190
6191 @kindex next
6192 @kindex n @r{(@code{next})}
6193 @item next @r{[}@var{count}@r{]}
6194 Continue to the next source line in the current (innermost) stack frame.
6195 This is similar to @code{step}, but function calls that appear within
6196 the line of code are executed without stopping. Execution stops when
6197 control reaches a different line of code at the original stack level
6198 that was executing when you gave the @code{next} command. This command
6199 is abbreviated @code{n}.
6200
6201 An argument @var{count} is a repeat count, as for @code{step}.
6202
6203
6204 @c FIX ME!! Do we delete this, or is there a way it fits in with
6205 @c the following paragraph? --- Vctoria
6206 @c
6207 @c @code{next} within a function that lacks debugging information acts like
6208 @c @code{step}, but any function calls appearing within the code of the
6209 @c function are executed without stopping.
6210
6211 The @code{next} command only stops at the first instruction of a
6212 source line. This prevents multiple stops that could otherwise occur in
6213 @code{switch} statements, @code{for} loops, etc.
6214
6215 @kindex set step-mode
6216 @item set step-mode
6217 @cindex functions without line info, and stepping
6218 @cindex stepping into functions with no line info
6219 @itemx set step-mode on
6220 The @code{set step-mode on} command causes the @code{step} command to
6221 stop at the first instruction of a function which contains no debug line
6222 information rather than stepping over it.
6223
6224 This is useful in cases where you may be interested in inspecting the
6225 machine instructions of a function which has no symbolic info and do not
6226 want @value{GDBN} to automatically skip over this function.
6227
6228 @item set step-mode off
6229 Causes the @code{step} command to step over any functions which contains no
6230 debug information. This is the default.
6231
6232 @item show step-mode
6233 Show whether @value{GDBN} will stop in or step over functions without
6234 source line debug information.
6235
6236 @kindex finish
6237 @kindex fin @r{(@code{finish})}
6238 @item finish
6239 Continue running until just after function in the selected stack frame
6240 returns. Print the returned value (if any). This command can be
6241 abbreviated as @code{fin}.
6242
6243 Contrast this with the @code{return} command (@pxref{Returning,
6244 ,Returning from a Function}).
6245
6246 @kindex set print finish
6247 @kindex show print finish
6248 @item set print finish @r{[}on|off@r{]}
6249 @itemx show print finish
6250 By default the @code{finish} command will show the value that is
6251 returned by the function. This can be disabled using @code{set print
6252 finish off}. When disabled, the value is still entered into the value
6253 history (@pxref{Value History}), but not displayed.
6254
6255 @kindex until
6256 @kindex u @r{(@code{until})}
6257 @cindex run until specified location
6258 @item until
6259 @itemx u
6260 Continue running until a source line past the current line, in the
6261 current stack frame, is reached. This command is used to avoid single
6262 stepping through a loop more than once. It is like the @code{next}
6263 command, except that when @code{until} encounters a jump, it
6264 automatically continues execution until the program counter is greater
6265 than the address of the jump.
6266
6267 This means that when you reach the end of a loop after single stepping
6268 though it, @code{until} makes your program continue execution until it
6269 exits the loop. In contrast, a @code{next} command at the end of a loop
6270 simply steps back to the beginning of the loop, which forces you to step
6271 through the next iteration.
6272
6273 @code{until} always stops your program if it attempts to exit the current
6274 stack frame.
6275
6276 @code{until} may produce somewhat counterintuitive results if the order
6277 of machine code does not match the order of the source lines. For
6278 example, in the following excerpt from a debugging session, the @code{f}
6279 (@code{frame}) command shows that execution is stopped at line
6280 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6281
6282 @smallexample
6283 (@value{GDBP}) f
6284 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6285 206 expand_input();
6286 (@value{GDBP}) until
6287 195 for ( ; argc > 0; NEXTARG) @{
6288 @end smallexample
6289
6290 This happened because, for execution efficiency, the compiler had
6291 generated code for the loop closure test at the end, rather than the
6292 start, of the loop---even though the test in a C @code{for}-loop is
6293 written before the body of the loop. The @code{until} command appeared
6294 to step back to the beginning of the loop when it advanced to this
6295 expression; however, it has not really gone to an earlier
6296 statement---not in terms of the actual machine code.
6297
6298 @code{until} with no argument works by means of single
6299 instruction stepping, and hence is slower than @code{until} with an
6300 argument.
6301
6302 @item until @var{location}
6303 @itemx u @var{location}
6304 Continue running your program until either the specified @var{location} is
6305 reached, or the current stack frame returns. The location is any of
6306 the forms described in @ref{Specify Location}.
6307 This form of the command uses temporary breakpoints, and
6308 hence is quicker than @code{until} without an argument. The specified
6309 location is actually reached only if it is in the current frame. This
6310 implies that @code{until} can be used to skip over recursive function
6311 invocations. For instance in the code below, if the current location is
6312 line @code{96}, issuing @code{until 99} will execute the program up to
6313 line @code{99} in the same invocation of factorial, i.e., after the inner
6314 invocations have returned.
6315
6316 @smallexample
6317 94 int factorial (int value)
6318 95 @{
6319 96 if (value > 1) @{
6320 97 value *= factorial (value - 1);
6321 98 @}
6322 99 return (value);
6323 100 @}
6324 @end smallexample
6325
6326
6327 @kindex advance @var{location}
6328 @item advance @var{location}
6329 Continue running the program up to the given @var{location}. An argument is
6330 required, which should be of one of the forms described in
6331 @ref{Specify Location}.
6332 Execution will also stop upon exit from the current stack
6333 frame. This command is similar to @code{until}, but @code{advance} will
6334 not skip over recursive function calls, and the target location doesn't
6335 have to be in the same frame as the current one.
6336
6337
6338 @kindex stepi
6339 @kindex si @r{(@code{stepi})}
6340 @item stepi
6341 @itemx stepi @var{arg}
6342 @itemx si
6343 Execute one machine instruction, then stop and return to the debugger.
6344
6345 It is often useful to do @samp{display/i $pc} when stepping by machine
6346 instructions. This makes @value{GDBN} automatically display the next
6347 instruction to be executed, each time your program stops. @xref{Auto
6348 Display,, Automatic Display}.
6349
6350 An argument is a repeat count, as in @code{step}.
6351
6352 @need 750
6353 @kindex nexti
6354 @kindex ni @r{(@code{nexti})}
6355 @item nexti
6356 @itemx nexti @var{arg}
6357 @itemx ni
6358 Execute one machine instruction, but if it is a function call,
6359 proceed until the function returns.
6360
6361 An argument is a repeat count, as in @code{next}.
6362
6363 @end table
6364
6365 @anchor{range stepping}
6366 @cindex range stepping
6367 @cindex target-assisted range stepping
6368 By default, and if available, @value{GDBN} makes use of
6369 target-assisted @dfn{range stepping}. In other words, whenever you
6370 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6371 tells the target to step the corresponding range of instruction
6372 addresses instead of issuing multiple single-steps. This speeds up
6373 line stepping, particularly for remote targets. Ideally, there should
6374 be no reason you would want to turn range stepping off. However, it's
6375 possible that a bug in the debug info, a bug in the remote stub (for
6376 remote targets), or even a bug in @value{GDBN} could make line
6377 stepping behave incorrectly when target-assisted range stepping is
6378 enabled. You can use the following command to turn off range stepping
6379 if necessary:
6380
6381 @table @code
6382 @kindex set range-stepping
6383 @kindex show range-stepping
6384 @item set range-stepping
6385 @itemx show range-stepping
6386 Control whether range stepping is enabled.
6387
6388 If @code{on}, and the target supports it, @value{GDBN} tells the
6389 target to step a range of addresses itself, instead of issuing
6390 multiple single-steps. If @code{off}, @value{GDBN} always issues
6391 single-steps, even if range stepping is supported by the target. The
6392 default is @code{on}.
6393
6394 @end table
6395
6396 @node Skipping Over Functions and Files
6397 @section Skipping Over Functions and Files
6398 @cindex skipping over functions and files
6399
6400 The program you are debugging may contain some functions which are
6401 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6402 skip a function, all functions in a file or a particular function in
6403 a particular file when stepping.
6404
6405 For example, consider the following C function:
6406
6407 @smallexample
6408 101 int func()
6409 102 @{
6410 103 foo(boring());
6411 104 bar(boring());
6412 105 @}
6413 @end smallexample
6414
6415 @noindent
6416 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6417 are not interested in stepping through @code{boring}. If you run @code{step}
6418 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6419 step over both @code{foo} and @code{boring}!
6420
6421 One solution is to @code{step} into @code{boring} and use the @code{finish}
6422 command to immediately exit it. But this can become tedious if @code{boring}
6423 is called from many places.
6424
6425 A more flexible solution is to execute @kbd{skip boring}. This instructs
6426 @value{GDBN} never to step into @code{boring}. Now when you execute
6427 @code{step} at line 103, you'll step over @code{boring} and directly into
6428 @code{foo}.
6429
6430 Functions may be skipped by providing either a function name, linespec
6431 (@pxref{Specify Location}), regular expression that matches the function's
6432 name, file name or a @code{glob}-style pattern that matches the file name.
6433
6434 On Posix systems the form of the regular expression is
6435 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6436 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6437 expression is whatever is provided by the @code{regcomp} function of
6438 the underlying system.
6439 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6440 description of @code{glob}-style patterns.
6441
6442 @table @code
6443 @kindex skip
6444 @item skip @r{[}@var{options}@r{]}
6445 The basic form of the @code{skip} command takes zero or more options
6446 that specify what to skip.
6447 The @var{options} argument is any useful combination of the following:
6448
6449 @table @code
6450 @item -file @var{file}
6451 @itemx -fi @var{file}
6452 Functions in @var{file} will be skipped over when stepping.
6453
6454 @item -gfile @var{file-glob-pattern}
6455 @itemx -gfi @var{file-glob-pattern}
6456 @cindex skipping over files via glob-style patterns
6457 Functions in files matching @var{file-glob-pattern} will be skipped
6458 over when stepping.
6459
6460 @smallexample
6461 (gdb) skip -gfi utils/*.c
6462 @end smallexample
6463
6464 @item -function @var{linespec}
6465 @itemx -fu @var{linespec}
6466 Functions named by @var{linespec} or the function containing the line
6467 named by @var{linespec} will be skipped over when stepping.
6468 @xref{Specify Location}.
6469
6470 @item -rfunction @var{regexp}
6471 @itemx -rfu @var{regexp}
6472 @cindex skipping over functions via regular expressions
6473 Functions whose name matches @var{regexp} will be skipped over when stepping.
6474
6475 This form is useful for complex function names.
6476 For example, there is generally no need to step into C@t{++} @code{std::string}
6477 constructors or destructors. Plus with C@t{++} templates it can be hard to
6478 write out the full name of the function, and often it doesn't matter what
6479 the template arguments are. Specifying the function to be skipped as a
6480 regular expression makes this easier.
6481
6482 @smallexample
6483 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6484 @end smallexample
6485
6486 If you want to skip every templated C@t{++} constructor and destructor
6487 in the @code{std} namespace you can do:
6488
6489 @smallexample
6490 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6491 @end smallexample
6492 @end table
6493
6494 If no options are specified, the function you're currently debugging
6495 will be skipped.
6496
6497 @kindex skip function
6498 @item skip function @r{[}@var{linespec}@r{]}
6499 After running this command, the function named by @var{linespec} or the
6500 function containing the line named by @var{linespec} will be skipped over when
6501 stepping. @xref{Specify Location}.
6502
6503 If you do not specify @var{linespec}, the function you're currently debugging
6504 will be skipped.
6505
6506 (If you have a function called @code{file} that you want to skip, use
6507 @kbd{skip function file}.)
6508
6509 @kindex skip file
6510 @item skip file @r{[}@var{filename}@r{]}
6511 After running this command, any function whose source lives in @var{filename}
6512 will be skipped over when stepping.
6513
6514 @smallexample
6515 (gdb) skip file boring.c
6516 File boring.c will be skipped when stepping.
6517 @end smallexample
6518
6519 If you do not specify @var{filename}, functions whose source lives in the file
6520 you're currently debugging will be skipped.
6521 @end table
6522
6523 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6524 These are the commands for managing your list of skips:
6525
6526 @table @code
6527 @kindex info skip
6528 @item info skip @r{[}@var{range}@r{]}
6529 Print details about the specified skip(s). If @var{range} is not specified,
6530 print a table with details about all functions and files marked for skipping.
6531 @code{info skip} prints the following information about each skip:
6532
6533 @table @emph
6534 @item Identifier
6535 A number identifying this skip.
6536 @item Enabled or Disabled
6537 Enabled skips are marked with @samp{y}.
6538 Disabled skips are marked with @samp{n}.
6539 @item Glob
6540 If the file name is a @samp{glob} pattern this is @samp{y}.
6541 Otherwise it is @samp{n}.
6542 @item File
6543 The name or @samp{glob} pattern of the file to be skipped.
6544 If no file is specified this is @samp{<none>}.
6545 @item RE
6546 If the function name is a @samp{regular expression} this is @samp{y}.
6547 Otherwise it is @samp{n}.
6548 @item Function
6549 The name or regular expression of the function to skip.
6550 If no function is specified this is @samp{<none>}.
6551 @end table
6552
6553 @kindex skip delete
6554 @item skip delete @r{[}@var{range}@r{]}
6555 Delete the specified skip(s). If @var{range} is not specified, delete all
6556 skips.
6557
6558 @kindex skip enable
6559 @item skip enable @r{[}@var{range}@r{]}
6560 Enable the specified skip(s). If @var{range} is not specified, enable all
6561 skips.
6562
6563 @kindex skip disable
6564 @item skip disable @r{[}@var{range}@r{]}
6565 Disable the specified skip(s). If @var{range} is not specified, disable all
6566 skips.
6567
6568 @kindex set debug skip
6569 @item set debug skip @r{[}on|off@r{]}
6570 Set whether to print the debug output about skipping files and functions.
6571
6572 @kindex show debug skip
6573 @item show debug skip
6574 Show whether the debug output about skipping files and functions is printed.
6575
6576 @end table
6577
6578 @node Signals
6579 @section Signals
6580 @cindex signals
6581
6582 A signal is an asynchronous event that can happen in a program. The
6583 operating system defines the possible kinds of signals, and gives each
6584 kind a name and a number. For example, in Unix @code{SIGINT} is the
6585 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6586 @code{SIGSEGV} is the signal a program gets from referencing a place in
6587 memory far away from all the areas in use; @code{SIGALRM} occurs when
6588 the alarm clock timer goes off (which happens only if your program has
6589 requested an alarm).
6590
6591 @cindex fatal signals
6592 Some signals, including @code{SIGALRM}, are a normal part of the
6593 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6594 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6595 program has not specified in advance some other way to handle the signal.
6596 @code{SIGINT} does not indicate an error in your program, but it is normally
6597 fatal so it can carry out the purpose of the interrupt: to kill the program.
6598
6599 @value{GDBN} has the ability to detect any occurrence of a signal in your
6600 program. You can tell @value{GDBN} in advance what to do for each kind of
6601 signal.
6602
6603 @cindex handling signals
6604 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6605 @code{SIGALRM} be silently passed to your program
6606 (so as not to interfere with their role in the program's functioning)
6607 but to stop your program immediately whenever an error signal happens.
6608 You can change these settings with the @code{handle} command.
6609
6610 @table @code
6611 @kindex info signals
6612 @kindex info handle
6613 @item info signals
6614 @itemx info handle
6615 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6616 handle each one. You can use this to see the signal numbers of all
6617 the defined types of signals.
6618
6619 @item info signals @var{sig}
6620 Similar, but print information only about the specified signal number.
6621
6622 @code{info handle} is an alias for @code{info signals}.
6623
6624 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6625 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6626 for details about this command.
6627
6628 @kindex handle
6629 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6630 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6631 can be the number of a signal or its name (with or without the
6632 @samp{SIG} at the beginning); a list of signal numbers of the form
6633 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6634 known signals. Optional arguments @var{keywords}, described below,
6635 say what change to make.
6636 @end table
6637
6638 @c @group
6639 The keywords allowed by the @code{handle} command can be abbreviated.
6640 Their full names are:
6641
6642 @table @code
6643 @item nostop
6644 @value{GDBN} should not stop your program when this signal happens. It may
6645 still print a message telling you that the signal has come in.
6646
6647 @item stop
6648 @value{GDBN} should stop your program when this signal happens. This implies
6649 the @code{print} keyword as well.
6650
6651 @item print
6652 @value{GDBN} should print a message when this signal happens.
6653
6654 @item noprint
6655 @value{GDBN} should not mention the occurrence of the signal at all. This
6656 implies the @code{nostop} keyword as well.
6657
6658 @item pass
6659 @itemx noignore
6660 @value{GDBN} should allow your program to see this signal; your program
6661 can handle the signal, or else it may terminate if the signal is fatal
6662 and not handled. @code{pass} and @code{noignore} are synonyms.
6663
6664 @item nopass
6665 @itemx ignore
6666 @value{GDBN} should not allow your program to see this signal.
6667 @code{nopass} and @code{ignore} are synonyms.
6668 @end table
6669 @c @end group
6670
6671 When a signal stops your program, the signal is not visible to the
6672 program until you
6673 continue. Your program sees the signal then, if @code{pass} is in
6674 effect for the signal in question @emph{at that time}. In other words,
6675 after @value{GDBN} reports a signal, you can use the @code{handle}
6676 command with @code{pass} or @code{nopass} to control whether your
6677 program sees that signal when you continue.
6678
6679 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6680 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6681 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6682 erroneous signals.
6683
6684 You can also use the @code{signal} command to prevent your program from
6685 seeing a signal, or cause it to see a signal it normally would not see,
6686 or to give it any signal at any time. For example, if your program stopped
6687 due to some sort of memory reference error, you might store correct
6688 values into the erroneous variables and continue, hoping to see more
6689 execution; but your program would probably terminate immediately as
6690 a result of the fatal signal once it saw the signal. To prevent this,
6691 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6692 Program a Signal}.
6693
6694 @cindex stepping and signal handlers
6695 @anchor{stepping and signal handlers}
6696
6697 @value{GDBN} optimizes for stepping the mainline code. If a signal
6698 that has @code{handle nostop} and @code{handle pass} set arrives while
6699 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6700 in progress, @value{GDBN} lets the signal handler run and then resumes
6701 stepping the mainline code once the signal handler returns. In other
6702 words, @value{GDBN} steps over the signal handler. This prevents
6703 signals that you've specified as not interesting (with @code{handle
6704 nostop}) from changing the focus of debugging unexpectedly. Note that
6705 the signal handler itself may still hit a breakpoint, stop for another
6706 signal that has @code{handle stop} in effect, or for any other event
6707 that normally results in stopping the stepping command sooner. Also
6708 note that @value{GDBN} still informs you that the program received a
6709 signal if @code{handle print} is set.
6710
6711 @anchor{stepping into signal handlers}
6712
6713 If you set @code{handle pass} for a signal, and your program sets up a
6714 handler for it, then issuing a stepping command, such as @code{step}
6715 or @code{stepi}, when your program is stopped due to the signal will
6716 step @emph{into} the signal handler (if the target supports that).
6717
6718 Likewise, if you use the @code{queue-signal} command to queue a signal
6719 to be delivered to the current thread when execution of the thread
6720 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6721 stepping command will step into the signal handler.
6722
6723 Here's an example, using @code{stepi} to step to the first instruction
6724 of @code{SIGUSR1}'s handler:
6725
6726 @smallexample
6727 (@value{GDBP}) handle SIGUSR1
6728 Signal Stop Print Pass to program Description
6729 SIGUSR1 Yes Yes Yes User defined signal 1
6730 (@value{GDBP}) c
6731 Continuing.
6732
6733 Program received signal SIGUSR1, User defined signal 1.
6734 main () sigusr1.c:28
6735 28 p = 0;
6736 (@value{GDBP}) si
6737 sigusr1_handler () at sigusr1.c:9
6738 9 @{
6739 @end smallexample
6740
6741 The same, but using @code{queue-signal} instead of waiting for the
6742 program to receive the signal first:
6743
6744 @smallexample
6745 (@value{GDBP}) n
6746 28 p = 0;
6747 (@value{GDBP}) queue-signal SIGUSR1
6748 (@value{GDBP}) si
6749 sigusr1_handler () at sigusr1.c:9
6750 9 @{
6751 (@value{GDBP})
6752 @end smallexample
6753
6754 @cindex extra signal information
6755 @anchor{extra signal information}
6756
6757 On some targets, @value{GDBN} can inspect extra signal information
6758 associated with the intercepted signal, before it is actually
6759 delivered to the program being debugged. This information is exported
6760 by the convenience variable @code{$_siginfo}, and consists of data
6761 that is passed by the kernel to the signal handler at the time of the
6762 receipt of a signal. The data type of the information itself is
6763 target dependent. You can see the data type using the @code{ptype
6764 $_siginfo} command. On Unix systems, it typically corresponds to the
6765 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6766 system header.
6767
6768 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6769 referenced address that raised a segmentation fault.
6770
6771 @smallexample
6772 @group
6773 (@value{GDBP}) continue
6774 Program received signal SIGSEGV, Segmentation fault.
6775 0x0000000000400766 in main ()
6776 69 *(int *)p = 0;
6777 (@value{GDBP}) ptype $_siginfo
6778 type = struct @{
6779 int si_signo;
6780 int si_errno;
6781 int si_code;
6782 union @{
6783 int _pad[28];
6784 struct @{...@} _kill;
6785 struct @{...@} _timer;
6786 struct @{...@} _rt;
6787 struct @{...@} _sigchld;
6788 struct @{...@} _sigfault;
6789 struct @{...@} _sigpoll;
6790 @} _sifields;
6791 @}
6792 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6793 type = struct @{
6794 void *si_addr;
6795 @}
6796 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6797 $1 = (void *) 0x7ffff7ff7000
6798 @end group
6799 @end smallexample
6800
6801 Depending on target support, @code{$_siginfo} may also be writable.
6802
6803 @cindex Intel MPX boundary violations
6804 @cindex boundary violations, Intel MPX
6805 On some targets, a @code{SIGSEGV} can be caused by a boundary
6806 violation, i.e., accessing an address outside of the allowed range.
6807 In those cases @value{GDBN} may displays additional information,
6808 depending on how @value{GDBN} has been told to handle the signal.
6809 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6810 kind: "Upper" or "Lower", the memory address accessed and the
6811 bounds, while with @code{handle nostop SIGSEGV} no additional
6812 information is displayed.
6813
6814 The usual output of a segfault is:
6815 @smallexample
6816 Program received signal SIGSEGV, Segmentation fault
6817 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6818 68 value = *(p + len);
6819 @end smallexample
6820
6821 While a bound violation is presented as:
6822 @smallexample
6823 Program received signal SIGSEGV, Segmentation fault
6824 Upper bound violation while accessing address 0x7fffffffc3b3
6825 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6826 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6827 68 value = *(p + len);
6828 @end smallexample
6829
6830 @node Thread Stops
6831 @section Stopping and Starting Multi-thread Programs
6832
6833 @cindex stopped threads
6834 @cindex threads, stopped
6835
6836 @cindex continuing threads
6837 @cindex threads, continuing
6838
6839 @value{GDBN} supports debugging programs with multiple threads
6840 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6841 are two modes of controlling execution of your program within the
6842 debugger. In the default mode, referred to as @dfn{all-stop mode},
6843 when any thread in your program stops (for example, at a breakpoint
6844 or while being stepped), all other threads in the program are also stopped by
6845 @value{GDBN}. On some targets, @value{GDBN} also supports
6846 @dfn{non-stop mode}, in which other threads can continue to run freely while
6847 you examine the stopped thread in the debugger.
6848
6849 @menu
6850 * All-Stop Mode:: All threads stop when GDB takes control
6851 * Non-Stop Mode:: Other threads continue to execute
6852 * Background Execution:: Running your program asynchronously
6853 * Thread-Specific Breakpoints:: Controlling breakpoints
6854 * Interrupted System Calls:: GDB may interfere with system calls
6855 * Observer Mode:: GDB does not alter program behavior
6856 @end menu
6857
6858 @node All-Stop Mode
6859 @subsection All-Stop Mode
6860
6861 @cindex all-stop mode
6862
6863 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6864 @emph{all} threads of execution stop, not just the current thread. This
6865 allows you to examine the overall state of the program, including
6866 switching between threads, without worrying that things may change
6867 underfoot.
6868
6869 Conversely, whenever you restart the program, @emph{all} threads start
6870 executing. @emph{This is true even when single-stepping} with commands
6871 like @code{step} or @code{next}.
6872
6873 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6874 Since thread scheduling is up to your debugging target's operating
6875 system (not controlled by @value{GDBN}), other threads may
6876 execute more than one statement while the current thread completes a
6877 single step. Moreover, in general other threads stop in the middle of a
6878 statement, rather than at a clean statement boundary, when the program
6879 stops.
6880
6881 You might even find your program stopped in another thread after
6882 continuing or even single-stepping. This happens whenever some other
6883 thread runs into a breakpoint, a signal, or an exception before the
6884 first thread completes whatever you requested.
6885
6886 @cindex automatic thread selection
6887 @cindex switching threads automatically
6888 @cindex threads, automatic switching
6889 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6890 signal, it automatically selects the thread where that breakpoint or
6891 signal happened. @value{GDBN} alerts you to the context switch with a
6892 message such as @samp{[Switching to Thread @var{n}]} to identify the
6893 thread.
6894
6895 On some OSes, you can modify @value{GDBN}'s default behavior by
6896 locking the OS scheduler to allow only a single thread to run.
6897
6898 @table @code
6899 @item set scheduler-locking @var{mode}
6900 @cindex scheduler locking mode
6901 @cindex lock scheduler
6902 Set the scheduler locking mode. It applies to normal execution,
6903 record mode, and replay mode. If it is @code{off}, then there is no
6904 locking and any thread may run at any time. If @code{on}, then only
6905 the current thread may run when the inferior is resumed. The
6906 @code{step} mode optimizes for single-stepping; it prevents other
6907 threads from preempting the current thread while you are stepping, so
6908 that the focus of debugging does not change unexpectedly. Other
6909 threads never get a chance to run when you step, and they are
6910 completely free to run when you use commands like @samp{continue},
6911 @samp{until}, or @samp{finish}. However, unless another thread hits a
6912 breakpoint during its timeslice, @value{GDBN} does not change the
6913 current thread away from the thread that you are debugging. The
6914 @code{replay} mode behaves like @code{off} in record mode and like
6915 @code{on} in replay mode.
6916
6917 @item show scheduler-locking
6918 Display the current scheduler locking mode.
6919 @end table
6920
6921 @cindex resume threads of multiple processes simultaneously
6922 By default, when you issue one of the execution commands such as
6923 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6924 threads of the current inferior to run. For example, if @value{GDBN}
6925 is attached to two inferiors, each with two threads, the
6926 @code{continue} command resumes only the two threads of the current
6927 inferior. This is useful, for example, when you debug a program that
6928 forks and you want to hold the parent stopped (so that, for instance,
6929 it doesn't run to exit), while you debug the child. In other
6930 situations, you may not be interested in inspecting the current state
6931 of any of the processes @value{GDBN} is attached to, and you may want
6932 to resume them all until some breakpoint is hit. In the latter case,
6933 you can instruct @value{GDBN} to allow all threads of all the
6934 inferiors to run with the @w{@code{set schedule-multiple}} command.
6935
6936 @table @code
6937 @kindex set schedule-multiple
6938 @item set schedule-multiple
6939 Set the mode for allowing threads of multiple processes to be resumed
6940 when an execution command is issued. When @code{on}, all threads of
6941 all processes are allowed to run. When @code{off}, only the threads
6942 of the current process are resumed. The default is @code{off}. The
6943 @code{scheduler-locking} mode takes precedence when set to @code{on},
6944 or while you are stepping and set to @code{step}.
6945
6946 @item show schedule-multiple
6947 Display the current mode for resuming the execution of threads of
6948 multiple processes.
6949 @end table
6950
6951 @node Non-Stop Mode
6952 @subsection Non-Stop Mode
6953
6954 @cindex non-stop mode
6955
6956 @c This section is really only a place-holder, and needs to be expanded
6957 @c with more details.
6958
6959 For some multi-threaded targets, @value{GDBN} supports an optional
6960 mode of operation in which you can examine stopped program threads in
6961 the debugger while other threads continue to execute freely. This
6962 minimizes intrusion when debugging live systems, such as programs
6963 where some threads have real-time constraints or must continue to
6964 respond to external events. This is referred to as @dfn{non-stop} mode.
6965
6966 In non-stop mode, when a thread stops to report a debugging event,
6967 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6968 threads as well, in contrast to the all-stop mode behavior. Additionally,
6969 execution commands such as @code{continue} and @code{step} apply by default
6970 only to the current thread in non-stop mode, rather than all threads as
6971 in all-stop mode. This allows you to control threads explicitly in
6972 ways that are not possible in all-stop mode --- for example, stepping
6973 one thread while allowing others to run freely, stepping
6974 one thread while holding all others stopped, or stepping several threads
6975 independently and simultaneously.
6976
6977 To enter non-stop mode, use this sequence of commands before you run
6978 or attach to your program:
6979
6980 @smallexample
6981 # If using the CLI, pagination breaks non-stop.
6982 set pagination off
6983
6984 # Finally, turn it on!
6985 set non-stop on
6986 @end smallexample
6987
6988 You can use these commands to manipulate the non-stop mode setting:
6989
6990 @table @code
6991 @kindex set non-stop
6992 @item set non-stop on
6993 Enable selection of non-stop mode.
6994 @item set non-stop off
6995 Disable selection of non-stop mode.
6996 @kindex show non-stop
6997 @item show non-stop
6998 Show the current non-stop enablement setting.
6999 @end table
7000
7001 Note these commands only reflect whether non-stop mode is enabled,
7002 not whether the currently-executing program is being run in non-stop mode.
7003 In particular, the @code{set non-stop} preference is only consulted when
7004 @value{GDBN} starts or connects to the target program, and it is generally
7005 not possible to switch modes once debugging has started. Furthermore,
7006 since not all targets support non-stop mode, even when you have enabled
7007 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
7008 default.
7009
7010 In non-stop mode, all execution commands apply only to the current thread
7011 by default. That is, @code{continue} only continues one thread.
7012 To continue all threads, issue @code{continue -a} or @code{c -a}.
7013
7014 You can use @value{GDBN}'s background execution commands
7015 (@pxref{Background Execution}) to run some threads in the background
7016 while you continue to examine or step others from @value{GDBN}.
7017 The MI execution commands (@pxref{GDB/MI Program Execution}) are
7018 always executed asynchronously in non-stop mode.
7019
7020 Suspending execution is done with the @code{interrupt} command when
7021 running in the background, or @kbd{Ctrl-c} during foreground execution.
7022 In all-stop mode, this stops the whole process;
7023 but in non-stop mode the interrupt applies only to the current thread.
7024 To stop the whole program, use @code{interrupt -a}.
7025
7026 Other execution commands do not currently support the @code{-a} option.
7027
7028 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
7029 that thread current, as it does in all-stop mode. This is because the
7030 thread stop notifications are asynchronous with respect to @value{GDBN}'s
7031 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
7032 changed to a different thread just as you entered a command to operate on the
7033 previously current thread.
7034
7035 @node Background Execution
7036 @subsection Background Execution
7037
7038 @cindex foreground execution
7039 @cindex background execution
7040 @cindex asynchronous execution
7041 @cindex execution, foreground, background and asynchronous
7042
7043 @value{GDBN}'s execution commands have two variants: the normal
7044 foreground (synchronous) behavior, and a background
7045 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
7046 the program to report that some thread has stopped before prompting for
7047 another command. In background execution, @value{GDBN} immediately gives
7048 a command prompt so that you can issue other commands while your program runs.
7049
7050 If the target doesn't support async mode, @value{GDBN} issues an error
7051 message if you attempt to use the background execution commands.
7052
7053 @cindex @code{&}, background execution of commands
7054 To specify background execution, add a @code{&} to the command. For example,
7055 the background form of the @code{continue} command is @code{continue&}, or
7056 just @code{c&}. The execution commands that accept background execution
7057 are:
7058
7059 @table @code
7060 @kindex run&
7061 @item run
7062 @xref{Starting, , Starting your Program}.
7063
7064 @item attach
7065 @kindex attach&
7066 @xref{Attach, , Debugging an Already-running Process}.
7067
7068 @item step
7069 @kindex step&
7070 @xref{Continuing and Stepping, step}.
7071
7072 @item stepi
7073 @kindex stepi&
7074 @xref{Continuing and Stepping, stepi}.
7075
7076 @item next
7077 @kindex next&
7078 @xref{Continuing and Stepping, next}.
7079
7080 @item nexti
7081 @kindex nexti&
7082 @xref{Continuing and Stepping, nexti}.
7083
7084 @item continue
7085 @kindex continue&
7086 @xref{Continuing and Stepping, continue}.
7087
7088 @item finish
7089 @kindex finish&
7090 @xref{Continuing and Stepping, finish}.
7091
7092 @item until
7093 @kindex until&
7094 @xref{Continuing and Stepping, until}.
7095
7096 @end table
7097
7098 Background execution is especially useful in conjunction with non-stop
7099 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7100 However, you can also use these commands in the normal all-stop mode with
7101 the restriction that you cannot issue another execution command until the
7102 previous one finishes. Examples of commands that are valid in all-stop
7103 mode while the program is running include @code{help} and @code{info break}.
7104
7105 You can interrupt your program while it is running in the background by
7106 using the @code{interrupt} command.
7107
7108 @table @code
7109 @kindex interrupt
7110 @item interrupt
7111 @itemx interrupt -a
7112
7113 Suspend execution of the running program. In all-stop mode,
7114 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7115 only the current thread. To stop the whole program in non-stop mode,
7116 use @code{interrupt -a}.
7117 @end table
7118
7119 @node Thread-Specific Breakpoints
7120 @subsection Thread-Specific Breakpoints
7121
7122 When your program has multiple threads (@pxref{Threads,, Debugging
7123 Programs with Multiple Threads}), you can choose whether to set
7124 breakpoints on all threads, or on a particular thread.
7125
7126 @table @code
7127 @cindex breakpoints and threads
7128 @cindex thread breakpoints
7129 @kindex break @dots{} thread @var{thread-id}
7130 @item break @var{location} thread @var{thread-id}
7131 @itemx break @var{location} thread @var{thread-id} if @dots{}
7132 @var{location} specifies source lines; there are several ways of
7133 writing them (@pxref{Specify Location}), but the effect is always to
7134 specify some source line.
7135
7136 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7137 to specify that you only want @value{GDBN} to stop the program when a
7138 particular thread reaches this breakpoint. The @var{thread-id} specifier
7139 is one of the thread identifiers assigned by @value{GDBN}, shown
7140 in the first column of the @samp{info threads} display.
7141
7142 If you do not specify @samp{thread @var{thread-id}} when you set a
7143 breakpoint, the breakpoint applies to @emph{all} threads of your
7144 program.
7145
7146 You can use the @code{thread} qualifier on conditional breakpoints as
7147 well; in this case, place @samp{thread @var{thread-id}} before or
7148 after the breakpoint condition, like this:
7149
7150 @smallexample
7151 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7152 @end smallexample
7153
7154 @end table
7155
7156 Thread-specific breakpoints are automatically deleted when
7157 @value{GDBN} detects the corresponding thread is no longer in the
7158 thread list. For example:
7159
7160 @smallexample
7161 (@value{GDBP}) c
7162 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7163 @end smallexample
7164
7165 There are several ways for a thread to disappear, such as a regular
7166 thread exit, but also when you detach from the process with the
7167 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7168 Process}), or if @value{GDBN} loses the remote connection
7169 (@pxref{Remote Debugging}), etc. Note that with some targets,
7170 @value{GDBN} is only able to detect a thread has exited when the user
7171 explictly asks for the thread list with the @code{info threads}
7172 command.
7173
7174 @node Interrupted System Calls
7175 @subsection Interrupted System Calls
7176
7177 @cindex thread breakpoints and system calls
7178 @cindex system calls and thread breakpoints
7179 @cindex premature return from system calls
7180 There is an unfortunate side effect when using @value{GDBN} to debug
7181 multi-threaded programs. If one thread stops for a
7182 breakpoint, or for some other reason, and another thread is blocked in a
7183 system call, then the system call may return prematurely. This is a
7184 consequence of the interaction between multiple threads and the signals
7185 that @value{GDBN} uses to implement breakpoints and other events that
7186 stop execution.
7187
7188 To handle this problem, your program should check the return value of
7189 each system call and react appropriately. This is good programming
7190 style anyways.
7191
7192 For example, do not write code like this:
7193
7194 @smallexample
7195 sleep (10);
7196 @end smallexample
7197
7198 The call to @code{sleep} will return early if a different thread stops
7199 at a breakpoint or for some other reason.
7200
7201 Instead, write this:
7202
7203 @smallexample
7204 int unslept = 10;
7205 while (unslept > 0)
7206 unslept = sleep (unslept);
7207 @end smallexample
7208
7209 A system call is allowed to return early, so the system is still
7210 conforming to its specification. But @value{GDBN} does cause your
7211 multi-threaded program to behave differently than it would without
7212 @value{GDBN}.
7213
7214 Also, @value{GDBN} uses internal breakpoints in the thread library to
7215 monitor certain events such as thread creation and thread destruction.
7216 When such an event happens, a system call in another thread may return
7217 prematurely, even though your program does not appear to stop.
7218
7219 @node Observer Mode
7220 @subsection Observer Mode
7221
7222 If you want to build on non-stop mode and observe program behavior
7223 without any chance of disruption by @value{GDBN}, you can set
7224 variables to disable all of the debugger's attempts to modify state,
7225 whether by writing memory, inserting breakpoints, etc. These operate
7226 at a low level, intercepting operations from all commands.
7227
7228 When all of these are set to @code{off}, then @value{GDBN} is said to
7229 be @dfn{observer mode}. As a convenience, the variable
7230 @code{observer} can be set to disable these, plus enable non-stop
7231 mode.
7232
7233 Note that @value{GDBN} will not prevent you from making nonsensical
7234 combinations of these settings. For instance, if you have enabled
7235 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7236 then breakpoints that work by writing trap instructions into the code
7237 stream will still not be able to be placed.
7238
7239 @table @code
7240
7241 @kindex observer
7242 @item set observer on
7243 @itemx set observer off
7244 When set to @code{on}, this disables all the permission variables
7245 below (except for @code{insert-fast-tracepoints}), plus enables
7246 non-stop debugging. Setting this to @code{off} switches back to
7247 normal debugging, though remaining in non-stop mode.
7248
7249 @item show observer
7250 Show whether observer mode is on or off.
7251
7252 @kindex may-write-registers
7253 @item set may-write-registers on
7254 @itemx set may-write-registers off
7255 This controls whether @value{GDBN} will attempt to alter the values of
7256 registers, such as with assignment expressions in @code{print}, or the
7257 @code{jump} command. It defaults to @code{on}.
7258
7259 @item show may-write-registers
7260 Show the current permission to write registers.
7261
7262 @kindex may-write-memory
7263 @item set may-write-memory on
7264 @itemx set may-write-memory off
7265 This controls whether @value{GDBN} will attempt to alter the contents
7266 of memory, such as with assignment expressions in @code{print}. It
7267 defaults to @code{on}.
7268
7269 @item show may-write-memory
7270 Show the current permission to write memory.
7271
7272 @kindex may-insert-breakpoints
7273 @item set may-insert-breakpoints on
7274 @itemx set may-insert-breakpoints off
7275 This controls whether @value{GDBN} will attempt to insert breakpoints.
7276 This affects all breakpoints, including internal breakpoints defined
7277 by @value{GDBN}. It defaults to @code{on}.
7278
7279 @item show may-insert-breakpoints
7280 Show the current permission to insert breakpoints.
7281
7282 @kindex may-insert-tracepoints
7283 @item set may-insert-tracepoints on
7284 @itemx set may-insert-tracepoints off
7285 This controls whether @value{GDBN} will attempt to insert (regular)
7286 tracepoints at the beginning of a tracing experiment. It affects only
7287 non-fast tracepoints, fast tracepoints being under the control of
7288 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7289
7290 @item show may-insert-tracepoints
7291 Show the current permission to insert tracepoints.
7292
7293 @kindex may-insert-fast-tracepoints
7294 @item set may-insert-fast-tracepoints on
7295 @itemx set may-insert-fast-tracepoints off
7296 This controls whether @value{GDBN} will attempt to insert fast
7297 tracepoints at the beginning of a tracing experiment. It affects only
7298 fast tracepoints, regular (non-fast) tracepoints being under the
7299 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7300
7301 @item show may-insert-fast-tracepoints
7302 Show the current permission to insert fast tracepoints.
7303
7304 @kindex may-interrupt
7305 @item set may-interrupt on
7306 @itemx set may-interrupt off
7307 This controls whether @value{GDBN} will attempt to interrupt or stop
7308 program execution. When this variable is @code{off}, the
7309 @code{interrupt} command will have no effect, nor will
7310 @kbd{Ctrl-c}. It defaults to @code{on}.
7311
7312 @item show may-interrupt
7313 Show the current permission to interrupt or stop the program.
7314
7315 @end table
7316
7317 @node Reverse Execution
7318 @chapter Running programs backward
7319 @cindex reverse execution
7320 @cindex running programs backward
7321
7322 When you are debugging a program, it is not unusual to realize that
7323 you have gone too far, and some event of interest has already happened.
7324 If the target environment supports it, @value{GDBN} can allow you to
7325 ``rewind'' the program by running it backward.
7326
7327 A target environment that supports reverse execution should be able
7328 to ``undo'' the changes in machine state that have taken place as the
7329 program was executing normally. Variables, registers etc.@: should
7330 revert to their previous values. Obviously this requires a great
7331 deal of sophistication on the part of the target environment; not
7332 all target environments can support reverse execution.
7333
7334 When a program is executed in reverse, the instructions that
7335 have most recently been executed are ``un-executed'', in reverse
7336 order. The program counter runs backward, following the previous
7337 thread of execution in reverse. As each instruction is ``un-executed'',
7338 the values of memory and/or registers that were changed by that
7339 instruction are reverted to their previous states. After executing
7340 a piece of source code in reverse, all side effects of that code
7341 should be ``undone'', and all variables should be returned to their
7342 prior values@footnote{
7343 Note that some side effects are easier to undo than others. For instance,
7344 memory and registers are relatively easy, but device I/O is hard. Some
7345 targets may be able undo things like device I/O, and some may not.
7346
7347 The contract between @value{GDBN} and the reverse executing target
7348 requires only that the target do something reasonable when
7349 @value{GDBN} tells it to execute backwards, and then report the
7350 results back to @value{GDBN}. Whatever the target reports back to
7351 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7352 assumes that the memory and registers that the target reports are in a
7353 consistent state, but @value{GDBN} accepts whatever it is given.
7354 }.
7355
7356 On some platforms, @value{GDBN} has built-in support for reverse
7357 execution, activated with the @code{record} or @code{record btrace}
7358 commands. @xref{Process Record and Replay}. Some remote targets,
7359 typically full system emulators, support reverse execution directly
7360 without requiring any special command.
7361
7362 If you are debugging in a target environment that supports
7363 reverse execution, @value{GDBN} provides the following commands.
7364
7365 @table @code
7366 @kindex reverse-continue
7367 @kindex rc @r{(@code{reverse-continue})}
7368 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7369 @itemx rc @r{[}@var{ignore-count}@r{]}
7370 Beginning at the point where your program last stopped, start executing
7371 in reverse. Reverse execution will stop for breakpoints and synchronous
7372 exceptions (signals), just like normal execution. Behavior of
7373 asynchronous signals depends on the target environment.
7374
7375 @kindex reverse-step
7376 @kindex rs @r{(@code{step})}
7377 @item reverse-step @r{[}@var{count}@r{]}
7378 Run the program backward until control reaches the start of a
7379 different source line; then stop it, and return control to @value{GDBN}.
7380
7381 Like the @code{step} command, @code{reverse-step} will only stop
7382 at the beginning of a source line. It ``un-executes'' the previously
7383 executed source line. If the previous source line included calls to
7384 debuggable functions, @code{reverse-step} will step (backward) into
7385 the called function, stopping at the beginning of the @emph{last}
7386 statement in the called function (typically a return statement).
7387
7388 Also, as with the @code{step} command, if non-debuggable functions are
7389 called, @code{reverse-step} will run thru them backward without stopping.
7390
7391 @kindex reverse-stepi
7392 @kindex rsi @r{(@code{reverse-stepi})}
7393 @item reverse-stepi @r{[}@var{count}@r{]}
7394 Reverse-execute one machine instruction. Note that the instruction
7395 to be reverse-executed is @emph{not} the one pointed to by the program
7396 counter, but the instruction executed prior to that one. For instance,
7397 if the last instruction was a jump, @code{reverse-stepi} will take you
7398 back from the destination of the jump to the jump instruction itself.
7399
7400 @kindex reverse-next
7401 @kindex rn @r{(@code{reverse-next})}
7402 @item reverse-next @r{[}@var{count}@r{]}
7403 Run backward to the beginning of the previous line executed in
7404 the current (innermost) stack frame. If the line contains function
7405 calls, they will be ``un-executed'' without stopping. Starting from
7406 the first line of a function, @code{reverse-next} will take you back
7407 to the caller of that function, @emph{before} the function was called,
7408 just as the normal @code{next} command would take you from the last
7409 line of a function back to its return to its caller
7410 @footnote{Unless the code is too heavily optimized.}.
7411
7412 @kindex reverse-nexti
7413 @kindex rni @r{(@code{reverse-nexti})}
7414 @item reverse-nexti @r{[}@var{count}@r{]}
7415 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7416 in reverse, except that called functions are ``un-executed'' atomically.
7417 That is, if the previously executed instruction was a return from
7418 another function, @code{reverse-nexti} will continue to execute
7419 in reverse until the call to that function (from the current stack
7420 frame) is reached.
7421
7422 @kindex reverse-finish
7423 @item reverse-finish
7424 Just as the @code{finish} command takes you to the point where the
7425 current function returns, @code{reverse-finish} takes you to the point
7426 where it was called. Instead of ending up at the end of the current
7427 function invocation, you end up at the beginning.
7428
7429 @kindex set exec-direction
7430 @item set exec-direction
7431 Set the direction of target execution.
7432 @item set exec-direction reverse
7433 @cindex execute forward or backward in time
7434 @value{GDBN} will perform all execution commands in reverse, until the
7435 exec-direction mode is changed to ``forward''. Affected commands include
7436 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7437 command cannot be used in reverse mode.
7438 @item set exec-direction forward
7439 @value{GDBN} will perform all execution commands in the normal fashion.
7440 This is the default.
7441 @end table
7442
7443
7444 @node Process Record and Replay
7445 @chapter Recording Inferior's Execution and Replaying It
7446 @cindex process record and replay
7447 @cindex recording inferior's execution and replaying it
7448
7449 On some platforms, @value{GDBN} provides a special @dfn{process record
7450 and replay} target that can record a log of the process execution, and
7451 replay it later with both forward and reverse execution commands.
7452
7453 @cindex replay mode
7454 When this target is in use, if the execution log includes the record
7455 for the next instruction, @value{GDBN} will debug in @dfn{replay
7456 mode}. In the replay mode, the inferior does not really execute code
7457 instructions. Instead, all the events that normally happen during
7458 code execution are taken from the execution log. While code is not
7459 really executed in replay mode, the values of registers (including the
7460 program counter register) and the memory of the inferior are still
7461 changed as they normally would. Their contents are taken from the
7462 execution log.
7463
7464 @cindex record mode
7465 If the record for the next instruction is not in the execution log,
7466 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7467 inferior executes normally, and @value{GDBN} records the execution log
7468 for future replay.
7469
7470 The process record and replay target supports reverse execution
7471 (@pxref{Reverse Execution}), even if the platform on which the
7472 inferior runs does not. However, the reverse execution is limited in
7473 this case by the range of the instructions recorded in the execution
7474 log. In other words, reverse execution on platforms that don't
7475 support it directly can only be done in the replay mode.
7476
7477 When debugging in the reverse direction, @value{GDBN} will work in
7478 replay mode as long as the execution log includes the record for the
7479 previous instruction; otherwise, it will work in record mode, if the
7480 platform supports reverse execution, or stop if not.
7481
7482 Currently, process record and replay is supported on ARM, Aarch64,
7483 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7484 GNU/Linux. Process record and replay can be used both when native
7485 debugging, and when remote debugging via @code{gdbserver}.
7486
7487 For architecture environments that support process record and replay,
7488 @value{GDBN} provides the following commands:
7489
7490 @table @code
7491 @kindex target record
7492 @kindex target record-full
7493 @kindex target record-btrace
7494 @kindex record
7495 @kindex record full
7496 @kindex record btrace
7497 @kindex record btrace bts
7498 @kindex record btrace pt
7499 @kindex record bts
7500 @kindex record pt
7501 @kindex rec
7502 @kindex rec full
7503 @kindex rec btrace
7504 @kindex rec btrace bts
7505 @kindex rec btrace pt
7506 @kindex rec bts
7507 @kindex rec pt
7508 @item record @var{method}
7509 This command starts the process record and replay target. The
7510 recording method can be specified as parameter. Without a parameter
7511 the command uses the @code{full} recording method. The following
7512 recording methods are available:
7513
7514 @table @code
7515 @item full
7516 Full record/replay recording using @value{GDBN}'s software record and
7517 replay implementation. This method allows replaying and reverse
7518 execution.
7519
7520 @item btrace @var{format}
7521 Hardware-supported instruction recording, supported on Intel
7522 processors. This method does not record data. Further, the data is
7523 collected in a ring buffer so old data will be overwritten when the
7524 buffer is full. It allows limited reverse execution. Variables and
7525 registers are not available during reverse execution. In remote
7526 debugging, recording continues on disconnect. Recorded data can be
7527 inspected after reconnecting. The recording may be stopped using
7528 @code{record stop}.
7529
7530 The recording format can be specified as parameter. Without a parameter
7531 the command chooses the recording format. The following recording
7532 formats are available:
7533
7534 @table @code
7535 @item bts
7536 @cindex branch trace store
7537 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7538 this format, the processor stores a from/to record for each executed
7539 branch in the btrace ring buffer.
7540
7541 @item pt
7542 @cindex Intel Processor Trace
7543 Use the @dfn{Intel Processor Trace} recording format. In this
7544 format, the processor stores the execution trace in a compressed form
7545 that is afterwards decoded by @value{GDBN}.
7546
7547 The trace can be recorded with very low overhead. The compressed
7548 trace format also allows small trace buffers to already contain a big
7549 number of instructions compared to @acronym{BTS}.
7550
7551 Decoding the recorded execution trace, on the other hand, is more
7552 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7553 increased number of instructions to process. You should increase the
7554 buffer-size with care.
7555 @end table
7556
7557 Not all recording formats may be available on all processors.
7558 @end table
7559
7560 The process record and replay target can only debug a process that is
7561 already running. Therefore, you need first to start the process with
7562 the @kbd{run} or @kbd{start} commands, and then start the recording
7563 with the @kbd{record @var{method}} command.
7564
7565 @cindex displaced stepping, and process record and replay
7566 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7567 will be automatically disabled when process record and replay target
7568 is started. That's because the process record and replay target
7569 doesn't support displaced stepping.
7570
7571 @cindex non-stop mode, and process record and replay
7572 @cindex asynchronous execution, and process record and replay
7573 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7574 the asynchronous execution mode (@pxref{Background Execution}), not
7575 all recording methods are available. The @code{full} recording method
7576 does not support these two modes.
7577
7578 @kindex record stop
7579 @kindex rec s
7580 @item record stop
7581 Stop the process record and replay target. When process record and
7582 replay target stops, the entire execution log will be deleted and the
7583 inferior will either be terminated, or will remain in its final state.
7584
7585 When you stop the process record and replay target in record mode (at
7586 the end of the execution log), the inferior will be stopped at the
7587 next instruction that would have been recorded. In other words, if
7588 you record for a while and then stop recording, the inferior process
7589 will be left in the same state as if the recording never happened.
7590
7591 On the other hand, if the process record and replay target is stopped
7592 while in replay mode (that is, not at the end of the execution log,
7593 but at some earlier point), the inferior process will become ``live''
7594 at that earlier state, and it will then be possible to continue the
7595 usual ``live'' debugging of the process from that state.
7596
7597 When the inferior process exits, or @value{GDBN} detaches from it,
7598 process record and replay target will automatically stop itself.
7599
7600 @kindex record goto
7601 @item record goto
7602 Go to a specific location in the execution log. There are several
7603 ways to specify the location to go to:
7604
7605 @table @code
7606 @item record goto begin
7607 @itemx record goto start
7608 Go to the beginning of the execution log.
7609
7610 @item record goto end
7611 Go to the end of the execution log.
7612
7613 @item record goto @var{n}
7614 Go to instruction number @var{n} in the execution log.
7615 @end table
7616
7617 @kindex record save
7618 @item record save @var{filename}
7619 Save the execution log to a file @file{@var{filename}}.
7620 Default filename is @file{gdb_record.@var{process_id}}, where
7621 @var{process_id} is the process ID of the inferior.
7622
7623 This command may not be available for all recording methods.
7624
7625 @kindex record restore
7626 @item record restore @var{filename}
7627 Restore the execution log from a file @file{@var{filename}}.
7628 File must have been created with @code{record save}.
7629
7630 @kindex set record full
7631 @item set record full insn-number-max @var{limit}
7632 @itemx set record full insn-number-max unlimited
7633 Set the limit of instructions to be recorded for the @code{full}
7634 recording method. Default value is 200000.
7635
7636 If @var{limit} is a positive number, then @value{GDBN} will start
7637 deleting instructions from the log once the number of the record
7638 instructions becomes greater than @var{limit}. For every new recorded
7639 instruction, @value{GDBN} will delete the earliest recorded
7640 instruction to keep the number of recorded instructions at the limit.
7641 (Since deleting recorded instructions loses information, @value{GDBN}
7642 lets you control what happens when the limit is reached, by means of
7643 the @code{stop-at-limit} option, described below.)
7644
7645 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7646 delete recorded instructions from the execution log. The number of
7647 recorded instructions is limited only by the available memory.
7648
7649 @kindex show record full
7650 @item show record full insn-number-max
7651 Show the limit of instructions to be recorded with the @code{full}
7652 recording method.
7653
7654 @item set record full stop-at-limit
7655 Control the behavior of the @code{full} recording method when the
7656 number of recorded instructions reaches the limit. If ON (the
7657 default), @value{GDBN} will stop when the limit is reached for the
7658 first time and ask you whether you want to stop the inferior or
7659 continue running it and recording the execution log. If you decide
7660 to continue recording, each new recorded instruction will cause the
7661 oldest one to be deleted.
7662
7663 If this option is OFF, @value{GDBN} will automatically delete the
7664 oldest record to make room for each new one, without asking.
7665
7666 @item show record full stop-at-limit
7667 Show the current setting of @code{stop-at-limit}.
7668
7669 @item set record full memory-query
7670 Control the behavior when @value{GDBN} is unable to record memory
7671 changes caused by an instruction for the @code{full} recording method.
7672 If ON, @value{GDBN} will query whether to stop the inferior in that
7673 case.
7674
7675 If this option is OFF (the default), @value{GDBN} will automatically
7676 ignore the effect of such instructions on memory. Later, when
7677 @value{GDBN} replays this execution log, it will mark the log of this
7678 instruction as not accessible, and it will not affect the replay
7679 results.
7680
7681 @item show record full memory-query
7682 Show the current setting of @code{memory-query}.
7683
7684 @kindex set record btrace
7685 The @code{btrace} record target does not trace data. As a
7686 convenience, when replaying, @value{GDBN} reads read-only memory off
7687 the live program directly, assuming that the addresses of the
7688 read-only areas don't change. This for example makes it possible to
7689 disassemble code while replaying, but not to print variables.
7690 In some cases, being able to inspect variables might be useful.
7691 You can use the following command for that:
7692
7693 @item set record btrace replay-memory-access
7694 Control the behavior of the @code{btrace} recording method when
7695 accessing memory during replay. If @code{read-only} (the default),
7696 @value{GDBN} will only allow accesses to read-only memory.
7697 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7698 and to read-write memory. Beware that the accessed memory corresponds
7699 to the live target and not necessarily to the current replay
7700 position.
7701
7702 @item set record btrace cpu @var{identifier}
7703 Set the processor to be used for enabling workarounds for processor
7704 errata when decoding the trace.
7705
7706 Processor errata are defects in processor operation, caused by its
7707 design or manufacture. They can cause a trace not to match the
7708 specification. This, in turn, may cause trace decode to fail.
7709 @value{GDBN} can detect erroneous trace packets and correct them, thus
7710 avoiding the decoding failures. These corrections are known as
7711 @dfn{errata workarounds}, and are enabled based on the processor on
7712 which the trace was recorded.
7713
7714 By default, @value{GDBN} attempts to detect the processor
7715 automatically, and apply the necessary workarounds for it. However,
7716 you may need to specify the processor if @value{GDBN} does not yet
7717 support it. This command allows you to do that, and also allows to
7718 disable the workarounds.
7719
7720 The argument @var{identifier} identifies the @sc{cpu} and is of the
7721 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7722 there are two special identifiers, @code{none} and @code{auto}
7723 (default).
7724
7725 The following vendor identifiers and corresponding processor
7726 identifiers are currently supported:
7727
7728 @multitable @columnfractions .1 .9
7729
7730 @item @code{intel}
7731 @tab @var{family}/@var{model}[/@var{stepping}]
7732
7733 @end multitable
7734
7735 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7736 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7737
7738 If @var{identifier} is @code{auto}, enable errata workarounds for the
7739 processor on which the trace was recorded. If @var{identifier} is
7740 @code{none}, errata workarounds are disabled.
7741
7742 For example, when using an old @value{GDBN} on a new system, decode
7743 may fail because @value{GDBN} does not support the new processor. It
7744 often suffices to specify an older processor that @value{GDBN}
7745 supports.
7746
7747 @smallexample
7748 (gdb) info record
7749 Active record target: record-btrace
7750 Recording format: Intel Processor Trace.
7751 Buffer size: 16kB.
7752 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7753 (gdb) set record btrace cpu intel:6/158
7754 (gdb) info record
7755 Active record target: record-btrace
7756 Recording format: Intel Processor Trace.
7757 Buffer size: 16kB.
7758 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7759 @end smallexample
7760
7761 @kindex show record btrace
7762 @item show record btrace replay-memory-access
7763 Show the current setting of @code{replay-memory-access}.
7764
7765 @item show record btrace cpu
7766 Show the processor to be used for enabling trace decode errata
7767 workarounds.
7768
7769 @kindex set record btrace bts
7770 @item set record btrace bts buffer-size @var{size}
7771 @itemx set record btrace bts buffer-size unlimited
7772 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7773 format. Default is 64KB.
7774
7775 If @var{size} is a positive number, then @value{GDBN} will try to
7776 allocate a buffer of at least @var{size} bytes for each new thread
7777 that uses the btrace recording method and the @acronym{BTS} format.
7778 The actually obtained buffer size may differ from the requested
7779 @var{size}. Use the @code{info record} command to see the actual
7780 buffer size for each thread that uses the btrace recording method and
7781 the @acronym{BTS} format.
7782
7783 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7784 allocate a buffer of 4MB.
7785
7786 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7787 also need longer to process the branch trace data before it can be used.
7788
7789 @item show record btrace bts buffer-size @var{size}
7790 Show the current setting of the requested ring buffer size for branch
7791 tracing in @acronym{BTS} format.
7792
7793 @kindex set record btrace pt
7794 @item set record btrace pt buffer-size @var{size}
7795 @itemx set record btrace pt buffer-size unlimited
7796 Set the requested ring buffer size for branch tracing in Intel
7797 Processor Trace format. Default is 16KB.
7798
7799 If @var{size} is a positive number, then @value{GDBN} will try to
7800 allocate a buffer of at least @var{size} bytes for each new thread
7801 that uses the btrace recording method and the Intel Processor Trace
7802 format. The actually obtained buffer size may differ from the
7803 requested @var{size}. Use the @code{info record} command to see the
7804 actual buffer size for each thread.
7805
7806 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7807 allocate a buffer of 4MB.
7808
7809 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7810 also need longer to process the branch trace data before it can be used.
7811
7812 @item show record btrace pt buffer-size @var{size}
7813 Show the current setting of the requested ring buffer size for branch
7814 tracing in Intel Processor Trace format.
7815
7816 @kindex info record
7817 @item info record
7818 Show various statistics about the recording depending on the recording
7819 method:
7820
7821 @table @code
7822 @item full
7823 For the @code{full} recording method, it shows the state of process
7824 record and its in-memory execution log buffer, including:
7825
7826 @itemize @bullet
7827 @item
7828 Whether in record mode or replay mode.
7829 @item
7830 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7831 @item
7832 Highest recorded instruction number.
7833 @item
7834 Current instruction about to be replayed (if in replay mode).
7835 @item
7836 Number of instructions contained in the execution log.
7837 @item
7838 Maximum number of instructions that may be contained in the execution log.
7839 @end itemize
7840
7841 @item btrace
7842 For the @code{btrace} recording method, it shows:
7843
7844 @itemize @bullet
7845 @item
7846 Recording format.
7847 @item
7848 Number of instructions that have been recorded.
7849 @item
7850 Number of blocks of sequential control-flow formed by the recorded
7851 instructions.
7852 @item
7853 Whether in record mode or replay mode.
7854 @end itemize
7855
7856 For the @code{bts} recording format, it also shows:
7857 @itemize @bullet
7858 @item
7859 Size of the perf ring buffer.
7860 @end itemize
7861
7862 For the @code{pt} recording format, it also shows:
7863 @itemize @bullet
7864 @item
7865 Size of the perf ring buffer.
7866 @end itemize
7867 @end table
7868
7869 @kindex record delete
7870 @kindex rec del
7871 @item record delete
7872 When record target runs in replay mode (``in the past''), delete the
7873 subsequent execution log and begin to record a new execution log starting
7874 from the current address. This means you will abandon the previously
7875 recorded ``future'' and begin recording a new ``future''.
7876
7877 @kindex record instruction-history
7878 @kindex rec instruction-history
7879 @item record instruction-history
7880 Disassembles instructions from the recorded execution log. By
7881 default, ten instructions are disassembled. This can be changed using
7882 the @code{set record instruction-history-size} command. Instructions
7883 are printed in execution order.
7884
7885 It can also print mixed source+disassembly if you specify the the
7886 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7887 as well as in symbolic form by specifying the @code{/r} modifier.
7888
7889 The current position marker is printed for the instruction at the
7890 current program counter value. This instruction can appear multiple
7891 times in the trace and the current position marker will be printed
7892 every time. To omit the current position marker, specify the
7893 @code{/p} modifier.
7894
7895 To better align the printed instructions when the trace contains
7896 instructions from more than one function, the function name may be
7897 omitted by specifying the @code{/f} modifier.
7898
7899 Speculatively executed instructions are prefixed with @samp{?}. This
7900 feature is not available for all recording formats.
7901
7902 There are several ways to specify what part of the execution log to
7903 disassemble:
7904
7905 @table @code
7906 @item record instruction-history @var{insn}
7907 Disassembles ten instructions starting from instruction number
7908 @var{insn}.
7909
7910 @item record instruction-history @var{insn}, +/-@var{n}
7911 Disassembles @var{n} instructions around instruction number
7912 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7913 @var{n} instructions after instruction number @var{insn}. If
7914 @var{n} is preceded with @code{-}, disassembles @var{n}
7915 instructions before instruction number @var{insn}.
7916
7917 @item record instruction-history
7918 Disassembles ten more instructions after the last disassembly.
7919
7920 @item record instruction-history -
7921 Disassembles ten more instructions before the last disassembly.
7922
7923 @item record instruction-history @var{begin}, @var{end}
7924 Disassembles instructions beginning with instruction number
7925 @var{begin} until instruction number @var{end}. The instruction
7926 number @var{end} is included.
7927 @end table
7928
7929 This command may not be available for all recording methods.
7930
7931 @kindex set record
7932 @item set record instruction-history-size @var{size}
7933 @itemx set record instruction-history-size unlimited
7934 Define how many instructions to disassemble in the @code{record
7935 instruction-history} command. The default value is 10.
7936 A @var{size} of @code{unlimited} means unlimited instructions.
7937
7938 @kindex show record
7939 @item show record instruction-history-size
7940 Show how many instructions to disassemble in the @code{record
7941 instruction-history} command.
7942
7943 @kindex record function-call-history
7944 @kindex rec function-call-history
7945 @item record function-call-history
7946 Prints the execution history at function granularity. For each sequence
7947 of instructions that belong to the same function, it prints the name of
7948 that function, the source lines for this instruction sequence (if the
7949 @code{/l} modifier is specified), and the instructions numbers that form
7950 the sequence (if the @code{/i} modifier is specified). The function names
7951 are indented to reflect the call stack depth if the @code{/c} modifier is
7952 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be given
7953 together.
7954
7955 @smallexample
7956 (@value{GDBP}) @b{list 1, 10}
7957 1 void foo (void)
7958 2 @{
7959 3 @}
7960 4
7961 5 void bar (void)
7962 6 @{
7963 7 ...
7964 8 foo ();
7965 9 ...
7966 10 @}
7967 (@value{GDBP}) @b{record function-call-history /ilc}
7968 1 bar inst 1,4 at foo.c:6,8
7969 2 foo inst 5,10 at foo.c:2,3
7970 3 bar inst 11,13 at foo.c:9,10
7971 @end smallexample
7972
7973 By default, ten functions are printed. This can be changed using the
7974 @code{set record function-call-history-size} command. Functions are
7975 printed in execution order. There are several ways to specify what
7976 to print:
7977
7978 @table @code
7979 @item record function-call-history @var{func}
7980 Prints ten functions starting from function number @var{func}.
7981
7982 @item record function-call-history @var{func}, +/-@var{n}
7983 Prints @var{n} functions around function number @var{func}. If
7984 @var{n} is preceded with @code{+}, prints @var{n} functions after
7985 function number @var{func}. If @var{n} is preceded with @code{-},
7986 prints @var{n} functions before function number @var{func}.
7987
7988 @item record function-call-history
7989 Prints ten more functions after the last ten-function print.
7990
7991 @item record function-call-history -
7992 Prints ten more functions before the last ten-function print.
7993
7994 @item record function-call-history @var{begin}, @var{end}
7995 Prints functions beginning with function number @var{begin} until
7996 function number @var{end}. The function number @var{end} is included.
7997 @end table
7998
7999 This command may not be available for all recording methods.
8000
8001 @item set record function-call-history-size @var{size}
8002 @itemx set record function-call-history-size unlimited
8003 Define how many functions to print in the
8004 @code{record function-call-history} command. The default value is 10.
8005 A size of @code{unlimited} means unlimited functions.
8006
8007 @item show record function-call-history-size
8008 Show how many functions to print in the
8009 @code{record function-call-history} command.
8010 @end table
8011
8012
8013 @node Stack
8014 @chapter Examining the Stack
8015
8016 When your program has stopped, the first thing you need to know is where it
8017 stopped and how it got there.
8018
8019 @cindex call stack
8020 Each time your program performs a function call, information about the call
8021 is generated.
8022 That information includes the location of the call in your program,
8023 the arguments of the call,
8024 and the local variables of the function being called.
8025 The information is saved in a block of data called a @dfn{stack frame}.
8026 The stack frames are allocated in a region of memory called the @dfn{call
8027 stack}.
8028
8029 When your program stops, the @value{GDBN} commands for examining the
8030 stack allow you to see all of this information.
8031
8032 @cindex selected frame
8033 One of the stack frames is @dfn{selected} by @value{GDBN} and many
8034 @value{GDBN} commands refer implicitly to the selected frame. In
8035 particular, whenever you ask @value{GDBN} for the value of a variable in
8036 your program, the value is found in the selected frame. There are
8037 special @value{GDBN} commands to select whichever frame you are
8038 interested in. @xref{Selection, ,Selecting a Frame}.
8039
8040 When your program stops, @value{GDBN} automatically selects the
8041 currently executing frame and describes it briefly, similar to the
8042 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
8043
8044 @menu
8045 * Frames:: Stack frames
8046 * Backtrace:: Backtraces
8047 * Selection:: Selecting a frame
8048 * Frame Info:: Information on a frame
8049 * Frame Apply:: Applying a command to several frames
8050 * Frame Filter Management:: Managing frame filters
8051
8052 @end menu
8053
8054 @node Frames
8055 @section Stack Frames
8056
8057 @cindex frame, definition
8058 @cindex stack frame
8059 The call stack is divided up into contiguous pieces called @dfn{stack
8060 frames}, or @dfn{frames} for short; each frame is the data associated
8061 with one call to one function. The frame contains the arguments given
8062 to the function, the function's local variables, and the address at
8063 which the function is executing.
8064
8065 @cindex initial frame
8066 @cindex outermost frame
8067 @cindex innermost frame
8068 When your program is started, the stack has only one frame, that of the
8069 function @code{main}. This is called the @dfn{initial} frame or the
8070 @dfn{outermost} frame. Each time a function is called, a new frame is
8071 made. Each time a function returns, the frame for that function invocation
8072 is eliminated. If a function is recursive, there can be many frames for
8073 the same function. The frame for the function in which execution is
8074 actually occurring is called the @dfn{innermost} frame. This is the most
8075 recently created of all the stack frames that still exist.
8076
8077 @cindex frame pointer
8078 Inside your program, stack frames are identified by their addresses. A
8079 stack frame consists of many bytes, each of which has its own address; each
8080 kind of computer has a convention for choosing one byte whose
8081 address serves as the address of the frame. Usually this address is kept
8082 in a register called the @dfn{frame pointer register}
8083 (@pxref{Registers, $fp}) while execution is going on in that frame.
8084
8085 @cindex frame level
8086 @cindex frame number
8087 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8088 number that is zero for the innermost frame, one for the frame that
8089 called it, and so on upward. These level numbers give you a way of
8090 designating stack frames in @value{GDBN} commands. The terms
8091 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8092 describe this number.
8093
8094 @c The -fomit-frame-pointer below perennially causes hbox overflow
8095 @c underflow problems.
8096 @cindex frameless execution
8097 Some compilers provide a way to compile functions so that they operate
8098 without stack frames. (For example, the @value{NGCC} option
8099 @smallexample
8100 @samp{-fomit-frame-pointer}
8101 @end smallexample
8102 generates functions without a frame.)
8103 This is occasionally done with heavily used library functions to save
8104 the frame setup time. @value{GDBN} has limited facilities for dealing
8105 with these function invocations. If the innermost function invocation
8106 has no stack frame, @value{GDBN} nevertheless regards it as though
8107 it had a separate frame, which is numbered zero as usual, allowing
8108 correct tracing of the function call chain. However, @value{GDBN} has
8109 no provision for frameless functions elsewhere in the stack.
8110
8111 @node Backtrace
8112 @section Backtraces
8113
8114 @cindex traceback
8115 @cindex call stack traces
8116 A backtrace is a summary of how your program got where it is. It shows one
8117 line per frame, for many frames, starting with the currently executing
8118 frame (frame zero), followed by its caller (frame one), and on up the
8119 stack.
8120
8121 @anchor{backtrace-command}
8122 @kindex backtrace
8123 @kindex bt @r{(@code{backtrace})}
8124 To print a backtrace of the entire stack, use the @code{backtrace}
8125 command, or its alias @code{bt}. This command will print one line per
8126 frame for frames in the stack. By default, all stack frames are
8127 printed. You can stop the backtrace at any time by typing the system
8128 interrupt character, normally @kbd{Ctrl-c}.
8129
8130 @table @code
8131 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8132 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8133 Print the backtrace of the entire stack.
8134
8135 The optional @var{count} can be one of the following:
8136
8137 @table @code
8138 @item @var{n}
8139 @itemx @var{n}
8140 Print only the innermost @var{n} frames, where @var{n} is a positive
8141 number.
8142
8143 @item -@var{n}
8144 @itemx -@var{n}
8145 Print only the outermost @var{n} frames, where @var{n} is a positive
8146 number.
8147 @end table
8148
8149 Options:
8150
8151 @table @code
8152 @item -full
8153 Print the values of the local variables also. This can be combined
8154 with the optional @var{count} to limit the number of frames shown.
8155
8156 @item -no-filters
8157 Do not run Python frame filters on this backtrace. @xref{Frame
8158 Filter API}, for more information. Additionally use @ref{disable
8159 frame-filter all} to turn off all frame filters. This is only
8160 relevant when @value{GDBN} has been configured with @code{Python}
8161 support.
8162
8163 @item -hide
8164 A Python frame filter might decide to ``elide'' some frames. Normally
8165 such elided frames are still printed, but they are indented relative
8166 to the filtered frames that cause them to be elided. The @code{-hide}
8167 option causes elided frames to not be printed at all.
8168 @end table
8169
8170 The @code{backtrace} command also supports a number of options that
8171 allow overriding relevant global print settings as set by @code{set
8172 backtrace} and @code{set print} subcommands:
8173
8174 @table @code
8175 @item -past-main [@code{on}|@code{off}]
8176 Set whether backtraces should continue past @code{main}. Related setting:
8177 @ref{set backtrace past-main}.
8178
8179 @item -past-entry [@code{on}|@code{off}]
8180 Set whether backtraces should continue past the entry point of a program.
8181 Related setting: @ref{set backtrace past-entry}.
8182
8183 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8184 Set printing of function arguments at function entry.
8185 Related setting: @ref{set print entry-values}.
8186
8187 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8188 Set printing of non-scalar frame arguments.
8189 Related setting: @ref{set print frame-arguments}.
8190
8191 @item -raw-frame-arguments [@code{on}|@code{off}]
8192 Set whether to print frame arguments in raw form.
8193 Related setting: @ref{set print raw-frame-arguments}.
8194
8195 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8196 Set printing of frame information.
8197 Related setting: @ref{set print frame-info}.
8198 @end table
8199
8200 The optional @var{qualifier} is maintained for backward compatibility.
8201 It can be one of the following:
8202
8203 @table @code
8204 @item full
8205 Equivalent to the @code{-full} option.
8206
8207 @item no-filters
8208 Equivalent to the @code{-no-filters} option.
8209
8210 @item hide
8211 Equivalent to the @code{-hide} option.
8212 @end table
8213
8214 @end table
8215
8216 @kindex where
8217 @kindex info stack
8218 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8219 are additional aliases for @code{backtrace}.
8220
8221 @cindex multiple threads, backtrace
8222 In a multi-threaded program, @value{GDBN} by default shows the
8223 backtrace only for the current thread. To display the backtrace for
8224 several or all of the threads, use the command @code{thread apply}
8225 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8226 apply all backtrace}, @value{GDBN} will display the backtrace for all
8227 the threads; this is handy when you debug a core dump of a
8228 multi-threaded program.
8229
8230 Each line in the backtrace shows the frame number and the function name.
8231 The program counter value is also shown---unless you use @code{set
8232 print address off}. The backtrace also shows the source file name and
8233 line number, as well as the arguments to the function. The program
8234 counter value is omitted if it is at the beginning of the code for that
8235 line number.
8236
8237 Here is an example of a backtrace. It was made with the command
8238 @samp{bt 3}, so it shows the innermost three frames.
8239
8240 @smallexample
8241 @group
8242 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8243 at builtin.c:993
8244 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8245 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8246 at macro.c:71
8247 (More stack frames follow...)
8248 @end group
8249 @end smallexample
8250
8251 @noindent
8252 The display for frame zero does not begin with a program counter
8253 value, indicating that your program has stopped at the beginning of the
8254 code for line @code{993} of @code{builtin.c}.
8255
8256 @noindent
8257 The value of parameter @code{data} in frame 1 has been replaced by
8258 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8259 only if it is a scalar (integer, pointer, enumeration, etc). See command
8260 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8261 on how to configure the way function parameter values are printed.
8262 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8263 what frame information is printed.
8264
8265 @cindex optimized out, in backtrace
8266 @cindex function call arguments, optimized out
8267 If your program was compiled with optimizations, some compilers will
8268 optimize away arguments passed to functions if those arguments are
8269 never used after the call. Such optimizations generate code that
8270 passes arguments through registers, but doesn't store those arguments
8271 in the stack frame. @value{GDBN} has no way of displaying such
8272 arguments in stack frames other than the innermost one. Here's what
8273 such a backtrace might look like:
8274
8275 @smallexample
8276 @group
8277 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8278 at builtin.c:993
8279 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8280 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8281 at macro.c:71
8282 (More stack frames follow...)
8283 @end group
8284 @end smallexample
8285
8286 @noindent
8287 The values of arguments that were not saved in their stack frames are
8288 shown as @samp{<optimized out>}.
8289
8290 If you need to display the values of such optimized-out arguments,
8291 either deduce that from other variables whose values depend on the one
8292 you are interested in, or recompile without optimizations.
8293
8294 @cindex backtrace beyond @code{main} function
8295 @cindex program entry point
8296 @cindex startup code, and backtrace
8297 Most programs have a standard user entry point---a place where system
8298 libraries and startup code transition into user code. For C this is
8299 @code{main}@footnote{
8300 Note that embedded programs (the so-called ``free-standing''
8301 environment) are not required to have a @code{main} function as the
8302 entry point. They could even have multiple entry points.}.
8303 When @value{GDBN} finds the entry function in a backtrace
8304 it will terminate the backtrace, to avoid tracing into highly
8305 system-specific (and generally uninteresting) code.
8306
8307 If you need to examine the startup code, or limit the number of levels
8308 in a backtrace, you can change this behavior:
8309
8310 @table @code
8311 @item set backtrace past-main
8312 @itemx set backtrace past-main on
8313 @anchor{set backtrace past-main}
8314 @kindex set backtrace
8315 Backtraces will continue past the user entry point.
8316
8317 @item set backtrace past-main off
8318 Backtraces will stop when they encounter the user entry point. This is the
8319 default.
8320
8321 @item show backtrace past-main
8322 @kindex show backtrace
8323 Display the current user entry point backtrace policy.
8324
8325 @item set backtrace past-entry
8326 @itemx set backtrace past-entry on
8327 @anchor{set backtrace past-entry}
8328 Backtraces will continue past the internal entry point of an application.
8329 This entry point is encoded by the linker when the application is built,
8330 and is likely before the user entry point @code{main} (or equivalent) is called.
8331
8332 @item set backtrace past-entry off
8333 Backtraces will stop when they encounter the internal entry point of an
8334 application. This is the default.
8335
8336 @item show backtrace past-entry
8337 Display the current internal entry point backtrace policy.
8338
8339 @item set backtrace limit @var{n}
8340 @itemx set backtrace limit 0
8341 @itemx set backtrace limit unlimited
8342 @anchor{set backtrace limit}
8343 @cindex backtrace limit
8344 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8345 or zero means unlimited levels.
8346
8347 @item show backtrace limit
8348 Display the current limit on backtrace levels.
8349 @end table
8350
8351 You can control how file names are displayed.
8352
8353 @table @code
8354 @item set filename-display
8355 @itemx set filename-display relative
8356 @cindex filename-display
8357 Display file names relative to the compilation directory. This is the default.
8358
8359 @item set filename-display basename
8360 Display only basename of a filename.
8361
8362 @item set filename-display absolute
8363 Display an absolute filename.
8364
8365 @item show filename-display
8366 Show the current way to display filenames.
8367 @end table
8368
8369 @node Selection
8370 @section Selecting a Frame
8371
8372 Most commands for examining the stack and other data in your program work on
8373 whichever stack frame is selected at the moment. Here are the commands for
8374 selecting a stack frame; all of them finish by printing a brief description
8375 of the stack frame just selected.
8376
8377 @table @code
8378 @kindex frame@r{, selecting}
8379 @kindex f @r{(@code{frame})}
8380 @item frame @r{[} @var{frame-selection-spec} @r{]}
8381 @item f @r{[} @var{frame-selection-spec} @r{]}
8382 The @command{frame} command allows different stack frames to be
8383 selected. The @var{frame-selection-spec} can be any of the following:
8384
8385 @table @code
8386 @kindex frame level
8387 @item @var{num}
8388 @item level @var{num}
8389 Select frame level @var{num}. Recall that frame zero is the innermost
8390 (currently executing) frame, frame one is the frame that called the
8391 innermost one, and so on. The highest level frame is usually the one
8392 for @code{main}.
8393
8394 As this is the most common method of navigating the frame stack, the
8395 string @command{level} can be omitted. For example, the following two
8396 commands are equivalent:
8397
8398 @smallexample
8399 (@value{GDBP}) frame 3
8400 (@value{GDBP}) frame level 3
8401 @end smallexample
8402
8403 @kindex frame address
8404 @item address @var{stack-address}
8405 Select the frame with stack address @var{stack-address}. The
8406 @var{stack-address} for a frame can be seen in the output of
8407 @command{info frame}, for example:
8408
8409 @smallexample
8410 (gdb) info frame
8411 Stack level 1, frame at 0x7fffffffda30:
8412 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8413 tail call frame, caller of frame at 0x7fffffffda30
8414 source language c++.
8415 Arglist at unknown address.
8416 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8417 @end smallexample
8418
8419 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8420 indicated by the line:
8421
8422 @smallexample
8423 Stack level 1, frame at 0x7fffffffda30:
8424 @end smallexample
8425
8426 @kindex frame function
8427 @item function @var{function-name}
8428 Select the stack frame for function @var{function-name}. If there are
8429 multiple stack frames for function @var{function-name} then the inner
8430 most stack frame is selected.
8431
8432 @kindex frame view
8433 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8434 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8435 viewed has stack address @var{stack-addr}, and optionally, a program
8436 counter address of @var{pc-addr}.
8437
8438 This is useful mainly if the chaining of stack frames has been
8439 damaged by a bug, making it impossible for @value{GDBN} to assign
8440 numbers properly to all frames. In addition, this can be useful
8441 when your program has multiple stacks and switches between them.
8442
8443 When viewing a frame outside the current backtrace using
8444 @command{frame view} then you can always return to the original
8445 stack using one of the previous stack frame selection instructions,
8446 for example @command{frame level 0}.
8447
8448 @end table
8449
8450 @kindex up
8451 @item up @var{n}
8452 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8453 numbers @var{n}, this advances toward the outermost frame, to higher
8454 frame numbers, to frames that have existed longer.
8455
8456 @kindex down
8457 @kindex do @r{(@code{down})}
8458 @item down @var{n}
8459 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8460 positive numbers @var{n}, this advances toward the innermost frame, to
8461 lower frame numbers, to frames that were created more recently.
8462 You may abbreviate @code{down} as @code{do}.
8463 @end table
8464
8465 All of these commands end by printing two lines of output describing the
8466 frame. The first line shows the frame number, the function name, the
8467 arguments, and the source file and line number of execution in that
8468 frame. The second line shows the text of that source line.
8469
8470 @need 1000
8471 For example:
8472
8473 @smallexample
8474 @group
8475 (@value{GDBP}) up
8476 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8477 at env.c:10
8478 10 read_input_file (argv[i]);
8479 @end group
8480 @end smallexample
8481
8482 After such a printout, the @code{list} command with no arguments
8483 prints ten lines centered on the point of execution in the frame.
8484 You can also edit the program at the point of execution with your favorite
8485 editing program by typing @code{edit}.
8486 @xref{List, ,Printing Source Lines},
8487 for details.
8488
8489 @table @code
8490 @kindex select-frame
8491 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8492 The @code{select-frame} command is a variant of @code{frame} that does
8493 not display the new frame after selecting it. This command is
8494 intended primarily for use in @value{GDBN} command scripts, where the
8495 output might be unnecessary and distracting. The
8496 @var{frame-selection-spec} is as for the @command{frame} command
8497 described in @ref{Selection, ,Selecting a Frame}.
8498
8499 @kindex down-silently
8500 @kindex up-silently
8501 @item up-silently @var{n}
8502 @itemx down-silently @var{n}
8503 These two commands are variants of @code{up} and @code{down},
8504 respectively; they differ in that they do their work silently, without
8505 causing display of the new frame. They are intended primarily for use
8506 in @value{GDBN} command scripts, where the output might be unnecessary and
8507 distracting.
8508 @end table
8509
8510 @node Frame Info
8511 @section Information About a Frame
8512
8513 There are several other commands to print information about the selected
8514 stack frame.
8515
8516 @table @code
8517 @item frame
8518 @itemx f
8519 When used without any argument, this command does not change which
8520 frame is selected, but prints a brief description of the currently
8521 selected stack frame. It can be abbreviated @code{f}. With an
8522 argument, this command is used to select a stack frame.
8523 @xref{Selection, ,Selecting a Frame}.
8524
8525 @kindex info frame
8526 @kindex info f @r{(@code{info frame})}
8527 @item info frame
8528 @itemx info f
8529 This command prints a verbose description of the selected stack frame,
8530 including:
8531
8532 @itemize @bullet
8533 @item
8534 the address of the frame
8535 @item
8536 the address of the next frame down (called by this frame)
8537 @item
8538 the address of the next frame up (caller of this frame)
8539 @item
8540 the language in which the source code corresponding to this frame is written
8541 @item
8542 the address of the frame's arguments
8543 @item
8544 the address of the frame's local variables
8545 @item
8546 the program counter saved in it (the address of execution in the caller frame)
8547 @item
8548 which registers were saved in the frame
8549 @end itemize
8550
8551 @noindent The verbose description is useful when
8552 something has gone wrong that has made the stack format fail to fit
8553 the usual conventions.
8554
8555 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8556 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8557 Print a verbose description of the frame selected by
8558 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8559 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8560 a Frame}). The selected frame remains unchanged by this command.
8561
8562 @kindex info args
8563 @item info args [-q]
8564 Print the arguments of the selected frame, each on a separate line.
8565
8566 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8567 printing header information and messages explaining why no argument
8568 have been printed.
8569
8570 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8571 Like @kbd{info args}, but only print the arguments selected
8572 with the provided regexp(s).
8573
8574 If @var{regexp} is provided, print only the arguments whose names
8575 match the regular expression @var{regexp}.
8576
8577 If @var{type_regexp} is provided, print only the arguments whose
8578 types, as printed by the @code{whatis} command, match
8579 the regular expression @var{type_regexp}.
8580 If @var{type_regexp} contains space(s), it should be enclosed in
8581 quote characters. If needed, use backslash to escape the meaning
8582 of special characters or quotes.
8583
8584 If both @var{regexp} and @var{type_regexp} are provided, an argument
8585 is printed only if its name matches @var{regexp} and its type matches
8586 @var{type_regexp}.
8587
8588 @item info locals [-q]
8589 @kindex info locals
8590 Print the local variables of the selected frame, each on a separate
8591 line. These are all variables (declared either static or automatic)
8592 accessible at the point of execution of the selected frame.
8593
8594 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8595 printing header information and messages explaining why no local variables
8596 have been printed.
8597
8598 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8599 Like @kbd{info locals}, but only print the local variables selected
8600 with the provided regexp(s).
8601
8602 If @var{regexp} is provided, print only the local variables whose names
8603 match the regular expression @var{regexp}.
8604
8605 If @var{type_regexp} is provided, print only the local variables whose
8606 types, as printed by the @code{whatis} command, match
8607 the regular expression @var{type_regexp}.
8608 If @var{type_regexp} contains space(s), it should be enclosed in
8609 quote characters. If needed, use backslash to escape the meaning
8610 of special characters or quotes.
8611
8612 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8613 is printed only if its name matches @var{regexp} and its type matches
8614 @var{type_regexp}.
8615
8616 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8617 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8618 For example, your program might use Resource Acquisition Is
8619 Initialization types (RAII) such as @code{lock_something_t}: each
8620 local variable of type @code{lock_something_t} automatically places a
8621 lock that is destroyed when the variable goes out of scope. You can
8622 then list all acquired locks in your program by doing
8623 @smallexample
8624 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8625 @end smallexample
8626 @noindent
8627 or the equivalent shorter form
8628 @smallexample
8629 tfaas i lo -q -t lock_something_t
8630 @end smallexample
8631
8632 @end table
8633
8634 @node Frame Apply
8635 @section Applying a Command to Several Frames.
8636 @kindex frame apply
8637 @cindex apply command to several frames
8638 @table @code
8639 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8640 The @code{frame apply} command allows you to apply the named
8641 @var{command} to one or more frames.
8642
8643 @table @code
8644 @item @code{all}
8645 Specify @code{all} to apply @var{command} to all frames.
8646
8647 @item @var{count}
8648 Use @var{count} to apply @var{command} to the innermost @var{count}
8649 frames, where @var{count} is a positive number.
8650
8651 @item @var{-count}
8652 Use @var{-count} to apply @var{command} to the outermost @var{count}
8653 frames, where @var{count} is a positive number.
8654
8655 @item @code{level}
8656 Use @code{level} to apply @var{command} to the set of frames identified
8657 by the @var{level} list. @var{level} is a frame level or a range of frame
8658 levels as @var{level1}-@var{level2}. The frame level is the number shown
8659 in the first field of the @samp{backtrace} command output.
8660 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8661 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8662
8663 @end table
8664
8665 Note that the frames on which @code{frame apply} applies a command are
8666 also influenced by the @code{set backtrace} settings such as @code{set
8667 backtrace past-main} and @code{set backtrace limit N}.
8668 @xref{Backtrace,,Backtraces}.
8669
8670 The @code{frame apply} command also supports a number of options that
8671 allow overriding relevant @code{set backtrace} settings:
8672
8673 @table @code
8674 @item -past-main [@code{on}|@code{off}]
8675 Whether backtraces should continue past @code{main}.
8676 Related setting: @ref{set backtrace past-main}.
8677
8678 @item -past-entry [@code{on}|@code{off}]
8679 Whether backtraces should continue past the entry point of a program.
8680 Related setting: @ref{set backtrace past-entry}.
8681 @end table
8682
8683 By default, @value{GDBN} displays some frame information before the
8684 output produced by @var{command}, and an error raised during the
8685 execution of a @var{command} will abort @code{frame apply}. The
8686 following options can be used to fine-tune these behaviors:
8687
8688 @table @code
8689 @item -c
8690 The flag @code{-c}, which stands for @samp{continue}, causes any
8691 errors in @var{command} to be displayed, and the execution of
8692 @code{frame apply} then continues.
8693 @item -s
8694 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8695 or empty output produced by a @var{command} to be silently ignored.
8696 That is, the execution continues, but the frame information and errors
8697 are not printed.
8698 @item -q
8699 The flag @code{-q} (@samp{quiet}) disables printing the frame
8700 information.
8701 @end table
8702
8703 The following example shows how the flags @code{-c} and @code{-s} are
8704 working when applying the command @code{p j} to all frames, where
8705 variable @code{j} can only be successfully printed in the outermost
8706 @code{#1 main} frame.
8707
8708 @smallexample
8709 @group
8710 (gdb) frame apply all p j
8711 #0 some_function (i=5) at fun.c:4
8712 No symbol "j" in current context.
8713 (gdb) frame apply all -c p j
8714 #0 some_function (i=5) at fun.c:4
8715 No symbol "j" in current context.
8716 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8717 $1 = 5
8718 (gdb) frame apply all -s p j
8719 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8720 $2 = 5
8721 (gdb)
8722 @end group
8723 @end smallexample
8724
8725 By default, @samp{frame apply}, prints the frame location
8726 information before the command output:
8727
8728 @smallexample
8729 @group
8730 (gdb) frame apply all p $sp
8731 #0 some_function (i=5) at fun.c:4
8732 $4 = (void *) 0xffffd1e0
8733 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8734 $5 = (void *) 0xffffd1f0
8735 (gdb)
8736 @end group
8737 @end smallexample
8738
8739 If the flag @code{-q} is given, no frame information is printed:
8740 @smallexample
8741 @group
8742 (gdb) frame apply all -q p $sp
8743 $12 = (void *) 0xffffd1e0
8744 $13 = (void *) 0xffffd1f0
8745 (gdb)
8746 @end group
8747 @end smallexample
8748
8749 @end table
8750
8751 @table @code
8752
8753 @kindex faas
8754 @cindex apply a command to all frames (ignoring errors and empty output)
8755 @item faas @var{command}
8756 Shortcut for @code{frame apply all -s @var{command}}.
8757 Applies @var{command} on all frames, ignoring errors and empty output.
8758
8759 It can for example be used to print a local variable or a function
8760 argument without knowing the frame where this variable or argument
8761 is, using:
8762 @smallexample
8763 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8764 @end smallexample
8765
8766 The @code{faas} command accepts the same options as the @code{frame
8767 apply} command. @xref{Frame Apply,,frame apply}.
8768
8769 Note that the command @code{tfaas @var{command}} applies @var{command}
8770 on all frames of all threads. See @xref{Threads,,Threads}.
8771 @end table
8772
8773
8774 @node Frame Filter Management
8775 @section Management of Frame Filters.
8776 @cindex managing frame filters
8777
8778 Frame filters are Python based utilities to manage and decorate the
8779 output of frames. @xref{Frame Filter API}, for further information.
8780
8781 Managing frame filters is performed by several commands available
8782 within @value{GDBN}, detailed here.
8783
8784 @table @code
8785 @kindex info frame-filter
8786 @item info frame-filter
8787 Print a list of installed frame filters from all dictionaries, showing
8788 their name, priority and enabled status.
8789
8790 @kindex disable frame-filter
8791 @anchor{disable frame-filter all}
8792 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8793 Disable a frame filter in the dictionary matching
8794 @var{filter-dictionary} and @var{filter-name}. The
8795 @var{filter-dictionary} may be @code{all}, @code{global},
8796 @code{progspace}, or the name of the object file where the frame filter
8797 dictionary resides. When @code{all} is specified, all frame filters
8798 across all dictionaries are disabled. The @var{filter-name} is the name
8799 of the frame filter and is used when @code{all} is not the option for
8800 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8801 may be enabled again later.
8802
8803 @kindex enable frame-filter
8804 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8805 Enable a frame filter in the dictionary matching
8806 @var{filter-dictionary} and @var{filter-name}. The
8807 @var{filter-dictionary} may be @code{all}, @code{global},
8808 @code{progspace} or the name of the object file where the frame filter
8809 dictionary resides. When @code{all} is specified, all frame filters across
8810 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8811 filter and is used when @code{all} is not the option for
8812 @var{filter-dictionary}.
8813
8814 Example:
8815
8816 @smallexample
8817 (gdb) info frame-filter
8818
8819 global frame-filters:
8820 Priority Enabled Name
8821 1000 No PrimaryFunctionFilter
8822 100 Yes Reverse
8823
8824 progspace /build/test frame-filters:
8825 Priority Enabled Name
8826 100 Yes ProgspaceFilter
8827
8828 objfile /build/test frame-filters:
8829 Priority Enabled Name
8830 999 Yes BuildProgramFilter
8831
8832 (gdb) disable frame-filter /build/test BuildProgramFilter
8833 (gdb) info frame-filter
8834
8835 global frame-filters:
8836 Priority Enabled Name
8837 1000 No PrimaryFunctionFilter
8838 100 Yes Reverse
8839
8840 progspace /build/test frame-filters:
8841 Priority Enabled Name
8842 100 Yes ProgspaceFilter
8843
8844 objfile /build/test frame-filters:
8845 Priority Enabled Name
8846 999 No BuildProgramFilter
8847
8848 (gdb) enable frame-filter global PrimaryFunctionFilter
8849 (gdb) info frame-filter
8850
8851 global frame-filters:
8852 Priority Enabled Name
8853 1000 Yes PrimaryFunctionFilter
8854 100 Yes Reverse
8855
8856 progspace /build/test frame-filters:
8857 Priority Enabled Name
8858 100 Yes ProgspaceFilter
8859
8860 objfile /build/test frame-filters:
8861 Priority Enabled Name
8862 999 No BuildProgramFilter
8863 @end smallexample
8864
8865 @kindex set frame-filter priority
8866 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8867 Set the @var{priority} of a frame filter in the dictionary matching
8868 @var{filter-dictionary}, and the frame filter name matching
8869 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8870 @code{progspace} or the name of the object file where the frame filter
8871 dictionary resides. The @var{priority} is an integer.
8872
8873 @kindex show frame-filter priority
8874 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8875 Show the @var{priority} of a frame filter in the dictionary matching
8876 @var{filter-dictionary}, and the frame filter name matching
8877 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8878 @code{progspace} or the name of the object file where the frame filter
8879 dictionary resides.
8880
8881 Example:
8882
8883 @smallexample
8884 (gdb) info frame-filter
8885
8886 global frame-filters:
8887 Priority Enabled Name
8888 1000 Yes PrimaryFunctionFilter
8889 100 Yes Reverse
8890
8891 progspace /build/test frame-filters:
8892 Priority Enabled Name
8893 100 Yes ProgspaceFilter
8894
8895 objfile /build/test frame-filters:
8896 Priority Enabled Name
8897 999 No BuildProgramFilter
8898
8899 (gdb) set frame-filter priority global Reverse 50
8900 (gdb) info frame-filter
8901
8902 global frame-filters:
8903 Priority Enabled Name
8904 1000 Yes PrimaryFunctionFilter
8905 50 Yes Reverse
8906
8907 progspace /build/test frame-filters:
8908 Priority Enabled Name
8909 100 Yes ProgspaceFilter
8910
8911 objfile /build/test frame-filters:
8912 Priority Enabled Name
8913 999 No BuildProgramFilter
8914 @end smallexample
8915 @end table
8916
8917 @node Source
8918 @chapter Examining Source Files
8919
8920 @value{GDBN} can print parts of your program's source, since the debugging
8921 information recorded in the program tells @value{GDBN} what source files were
8922 used to build it. When your program stops, @value{GDBN} spontaneously prints
8923 the line where it stopped. Likewise, when you select a stack frame
8924 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8925 execution in that frame has stopped. You can print other portions of
8926 source files by explicit command.
8927
8928 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8929 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8930 @value{GDBN} under @sc{gnu} Emacs}.
8931
8932 @menu
8933 * List:: Printing source lines
8934 * Specify Location:: How to specify code locations
8935 * Edit:: Editing source files
8936 * Search:: Searching source files
8937 * Source Path:: Specifying source directories
8938 * Machine Code:: Source and machine code
8939 * Disable Reading Source:: Disable Reading Source Code
8940 @end menu
8941
8942 @node List
8943 @section Printing Source Lines
8944
8945 @kindex list
8946 @kindex l @r{(@code{list})}
8947 To print lines from a source file, use the @code{list} command
8948 (abbreviated @code{l}). By default, ten lines are printed.
8949 There are several ways to specify what part of the file you want to
8950 print; see @ref{Specify Location}, for the full list.
8951
8952 Here are the forms of the @code{list} command most commonly used:
8953
8954 @table @code
8955 @item list @var{linenum}
8956 Print lines centered around line number @var{linenum} in the
8957 current source file.
8958
8959 @item list @var{function}
8960 Print lines centered around the beginning of function
8961 @var{function}.
8962
8963 @item list
8964 Print more lines. If the last lines printed were printed with a
8965 @code{list} command, this prints lines following the last lines
8966 printed; however, if the last line printed was a solitary line printed
8967 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8968 Stack}), this prints lines centered around that line.
8969
8970 @item list -
8971 Print lines just before the lines last printed.
8972 @end table
8973
8974 @cindex @code{list}, how many lines to display
8975 By default, @value{GDBN} prints ten source lines with any of these forms of
8976 the @code{list} command. You can change this using @code{set listsize}:
8977
8978 @table @code
8979 @kindex set listsize
8980 @item set listsize @var{count}
8981 @itemx set listsize unlimited
8982 Make the @code{list} command display @var{count} source lines (unless
8983 the @code{list} argument explicitly specifies some other number).
8984 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8985
8986 @kindex show listsize
8987 @item show listsize
8988 Display the number of lines that @code{list} prints.
8989 @end table
8990
8991 Repeating a @code{list} command with @key{RET} discards the argument,
8992 so it is equivalent to typing just @code{list}. This is more useful
8993 than listing the same lines again. An exception is made for an
8994 argument of @samp{-}; that argument is preserved in repetition so that
8995 each repetition moves up in the source file.
8996
8997 In general, the @code{list} command expects you to supply zero, one or two
8998 @dfn{locations}. Locations specify source lines; there are several ways
8999 of writing them (@pxref{Specify Location}), but the effect is always
9000 to specify some source line.
9001
9002 Here is a complete description of the possible arguments for @code{list}:
9003
9004 @table @code
9005 @item list @var{location}
9006 Print lines centered around the line specified by @var{location}.
9007
9008 @item list @var{first},@var{last}
9009 Print lines from @var{first} to @var{last}. Both arguments are
9010 locations. When a @code{list} command has two locations, and the
9011 source file of the second location is omitted, this refers to
9012 the same source file as the first location.
9013
9014 @item list ,@var{last}
9015 Print lines ending with @var{last}.
9016
9017 @item list @var{first},
9018 Print lines starting with @var{first}.
9019
9020 @item list +
9021 Print lines just after the lines last printed.
9022
9023 @item list -
9024 Print lines just before the lines last printed.
9025
9026 @item list
9027 As described in the preceding table.
9028 @end table
9029
9030 @node Specify Location
9031 @section Specifying a Location
9032 @cindex specifying location
9033 @cindex location
9034 @cindex source location
9035
9036 Several @value{GDBN} commands accept arguments that specify a location
9037 of your program's code. Since @value{GDBN} is a source-level
9038 debugger, a location usually specifies some line in the source code.
9039 Locations may be specified using three different formats:
9040 linespec locations, explicit locations, or address locations.
9041
9042 @menu
9043 * Linespec Locations:: Linespec locations
9044 * Explicit Locations:: Explicit locations
9045 * Address Locations:: Address locations
9046 @end menu
9047
9048 @node Linespec Locations
9049 @subsection Linespec Locations
9050 @cindex linespec locations
9051
9052 A @dfn{linespec} is a colon-separated list of source location parameters such
9053 as file name, function name, etc. Here are all the different ways of
9054 specifying a linespec:
9055
9056 @table @code
9057 @item @var{linenum}
9058 Specifies the line number @var{linenum} of the current source file.
9059
9060 @item -@var{offset}
9061 @itemx +@var{offset}
9062 Specifies the line @var{offset} lines before or after the @dfn{current
9063 line}. For the @code{list} command, the current line is the last one
9064 printed; for the breakpoint commands, this is the line at which
9065 execution stopped in the currently selected @dfn{stack frame}
9066 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9067 used as the second of the two linespecs in a @code{list} command,
9068 this specifies the line @var{offset} lines up or down from the first
9069 linespec.
9070
9071 @item @var{filename}:@var{linenum}
9072 Specifies the line @var{linenum} in the source file @var{filename}.
9073 If @var{filename} is a relative file name, then it will match any
9074 source file name with the same trailing components. For example, if
9075 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9076 name of @file{/build/trunk/gcc/expr.c}, but not
9077 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9078
9079 @item @var{function}
9080 Specifies the line that begins the body of the function @var{function}.
9081 For example, in C, this is the line with the open brace.
9082
9083 By default, in C@t{++} and Ada, @var{function} is interpreted as
9084 specifying all functions named @var{function} in all scopes. For
9085 C@t{++}, this means in all namespaces and classes. For Ada, this
9086 means in all packages.
9087
9088 For example, assuming a program with C@t{++} symbols named
9089 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9090 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9091
9092 Commands that accept a linespec let you override this with the
9093 @code{-qualified} option. For example, @w{@kbd{break -qualified
9094 func}} sets a breakpoint on a free-function named @code{func} ignoring
9095 any C@t{++} class methods and namespace functions called @code{func}.
9096
9097 @xref{Explicit Locations}.
9098
9099 @item @var{function}:@var{label}
9100 Specifies the line where @var{label} appears in @var{function}.
9101
9102 @item @var{filename}:@var{function}
9103 Specifies the line that begins the body of the function @var{function}
9104 in the file @var{filename}. You only need the file name with a
9105 function name to avoid ambiguity when there are identically named
9106 functions in different source files.
9107
9108 @item @var{label}
9109 Specifies the line at which the label named @var{label} appears
9110 in the function corresponding to the currently selected stack frame.
9111 If there is no current selected stack frame (for instance, if the inferior
9112 is not running), then @value{GDBN} will not search for a label.
9113
9114 @cindex breakpoint at static probe point
9115 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9116 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9117 applications to embed static probes. @xref{Static Probe Points}, for more
9118 information on finding and using static probes. This form of linespec
9119 specifies the location of such a static probe.
9120
9121 If @var{objfile} is given, only probes coming from that shared library
9122 or executable matching @var{objfile} as a regular expression are considered.
9123 If @var{provider} is given, then only probes from that provider are considered.
9124 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9125 each one of those probes.
9126 @end table
9127
9128 @node Explicit Locations
9129 @subsection Explicit Locations
9130 @cindex explicit locations
9131
9132 @dfn{Explicit locations} allow the user to directly specify the source
9133 location's parameters using option-value pairs.
9134
9135 Explicit locations are useful when several functions, labels, or
9136 file names have the same name (base name for files) in the program's
9137 sources. In these cases, explicit locations point to the source
9138 line you meant more accurately and unambiguously. Also, using
9139 explicit locations might be faster in large programs.
9140
9141 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9142 defined in the file named @file{foo} or the label @code{bar} in a function
9143 named @code{foo}. @value{GDBN} must search either the file system or
9144 the symbol table to know.
9145
9146 The list of valid explicit location options is summarized in the
9147 following table:
9148
9149 @table @code
9150 @item -source @var{filename}
9151 The value specifies the source file name. To differentiate between
9152 files with the same base name, prepend as many directories as is necessary
9153 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9154 @value{GDBN} will use the first file it finds with the given base
9155 name. This option requires the use of either @code{-function} or @code{-line}.
9156
9157 @item -function @var{function}
9158 The value specifies the name of a function. Operations
9159 on function locations unmodified by other options (such as @code{-label}
9160 or @code{-line}) refer to the line that begins the body of the function.
9161 In C, for example, this is the line with the open brace.
9162
9163 By default, in C@t{++} and Ada, @var{function} is interpreted as
9164 specifying all functions named @var{function} in all scopes. For
9165 C@t{++}, this means in all namespaces and classes. For Ada, this
9166 means in all packages.
9167
9168 For example, assuming a program with C@t{++} symbols named
9169 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9170 -function func}} and @w{@kbd{break -function B::func}} set a
9171 breakpoint on both symbols.
9172
9173 You can use the @kbd{-qualified} flag to override this (see below).
9174
9175 @item -qualified
9176
9177 This flag makes @value{GDBN} interpret a function name specified with
9178 @kbd{-function} as a complete fully-qualified name.
9179
9180 For example, assuming a C@t{++} program with symbols named
9181 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9182 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9183
9184 (Note: the @kbd{-qualified} option can precede a linespec as well
9185 (@pxref{Linespec Locations}), so the particular example above could be
9186 simplified as @w{@kbd{break -qualified B::func}}.)
9187
9188 @item -label @var{label}
9189 The value specifies the name of a label. When the function
9190 name is not specified, the label is searched in the function of the currently
9191 selected stack frame.
9192
9193 @item -line @var{number}
9194 The value specifies a line offset for the location. The offset may either
9195 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9196 the command. When specified without any other options, the line offset is
9197 relative to the current line.
9198 @end table
9199
9200 Explicit location options may be abbreviated by omitting any non-unique
9201 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9202
9203 @node Address Locations
9204 @subsection Address Locations
9205 @cindex address locations
9206
9207 @dfn{Address locations} indicate a specific program address. They have
9208 the generalized form *@var{address}.
9209
9210 For line-oriented commands, such as @code{list} and @code{edit}, this
9211 specifies a source line that contains @var{address}. For @code{break} and
9212 other breakpoint-oriented commands, this can be used to set breakpoints in
9213 parts of your program which do not have debugging information or
9214 source files.
9215
9216 Here @var{address} may be any expression valid in the current working
9217 language (@pxref{Languages, working language}) that specifies a code
9218 address. In addition, as a convenience, @value{GDBN} extends the
9219 semantics of expressions used in locations to cover several situations
9220 that frequently occur during debugging. Here are the various forms
9221 of @var{address}:
9222
9223 @table @code
9224 @item @var{expression}
9225 Any expression valid in the current working language.
9226
9227 @item @var{funcaddr}
9228 An address of a function or procedure derived from its name. In C,
9229 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9230 simply the function's name @var{function} (and actually a special case
9231 of a valid expression). In Pascal and Modula-2, this is
9232 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9233 (although the Pascal form also works).
9234
9235 This form specifies the address of the function's first instruction,
9236 before the stack frame and arguments have been set up.
9237
9238 @item '@var{filename}':@var{funcaddr}
9239 Like @var{funcaddr} above, but also specifies the name of the source
9240 file explicitly. This is useful if the name of the function does not
9241 specify the function unambiguously, e.g., if there are several
9242 functions with identical names in different source files.
9243 @end table
9244
9245 @node Edit
9246 @section Editing Source Files
9247 @cindex editing source files
9248
9249 @kindex edit
9250 @kindex e @r{(@code{edit})}
9251 To edit the lines in a source file, use the @code{edit} command.
9252 The editing program of your choice
9253 is invoked with the current line set to
9254 the active line in the program.
9255 Alternatively, there are several ways to specify what part of the file you
9256 want to print if you want to see other parts of the program:
9257
9258 @table @code
9259 @item edit @var{location}
9260 Edit the source file specified by @code{location}. Editing starts at
9261 that @var{location}, e.g., at the specified source line of the
9262 specified file. @xref{Specify Location}, for all the possible forms
9263 of the @var{location} argument; here are the forms of the @code{edit}
9264 command most commonly used:
9265
9266 @table @code
9267 @item edit @var{number}
9268 Edit the current source file with @var{number} as the active line number.
9269
9270 @item edit @var{function}
9271 Edit the file containing @var{function} at the beginning of its definition.
9272 @end table
9273
9274 @end table
9275
9276 @subsection Choosing your Editor
9277 You can customize @value{GDBN} to use any editor you want
9278 @footnote{
9279 The only restriction is that your editor (say @code{ex}), recognizes the
9280 following command-line syntax:
9281 @smallexample
9282 ex +@var{number} file
9283 @end smallexample
9284 The optional numeric value +@var{number} specifies the number of the line in
9285 the file where to start editing.}.
9286 By default, it is @file{@value{EDITOR}}, but you can change this
9287 by setting the environment variable @env{EDITOR} before using
9288 @value{GDBN}. For example, to configure @value{GDBN} to use the
9289 @code{vi} editor, you could use these commands with the @code{sh} shell:
9290 @smallexample
9291 EDITOR=/usr/bin/vi
9292 export EDITOR
9293 gdb @dots{}
9294 @end smallexample
9295 or in the @code{csh} shell,
9296 @smallexample
9297 setenv EDITOR /usr/bin/vi
9298 gdb @dots{}
9299 @end smallexample
9300
9301 @node Search
9302 @section Searching Source Files
9303 @cindex searching source files
9304
9305 There are two commands for searching through the current source file for a
9306 regular expression.
9307
9308 @table @code
9309 @kindex search
9310 @kindex forward-search
9311 @kindex fo @r{(@code{forward-search})}
9312 @item forward-search @var{regexp}
9313 @itemx search @var{regexp}
9314 The command @samp{forward-search @var{regexp}} checks each line,
9315 starting with the one following the last line listed, for a match for
9316 @var{regexp}. It lists the line that is found. You can use the
9317 synonym @samp{search @var{regexp}} or abbreviate the command name as
9318 @code{fo}.
9319
9320 @kindex reverse-search
9321 @item reverse-search @var{regexp}
9322 The command @samp{reverse-search @var{regexp}} checks each line, starting
9323 with the one before the last line listed and going backward, for a match
9324 for @var{regexp}. It lists the line that is found. You can abbreviate
9325 this command as @code{rev}.
9326 @end table
9327
9328 @node Source Path
9329 @section Specifying Source Directories
9330
9331 @cindex source path
9332 @cindex directories for source files
9333 Executable programs sometimes do not record the directories of the source
9334 files from which they were compiled, just the names. Even when they do,
9335 the directories could be moved between the compilation and your debugging
9336 session. @value{GDBN} has a list of directories to search for source files;
9337 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9338 it tries all the directories in the list, in the order they are present
9339 in the list, until it finds a file with the desired name.
9340
9341 For example, suppose an executable references the file
9342 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9343 directory, and the @dfn{source path} is @file{/mnt/cross}.
9344 @value{GDBN} would look for the source file in the following
9345 locations:
9346
9347 @enumerate
9348
9349 @item @file{/usr/src/foo-1.0/lib/foo.c}
9350 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9351 @item @file{/mnt/cross/foo.c}
9352
9353 @end enumerate
9354
9355 If the source file is not present at any of the above locations then
9356 an error is printed. @value{GDBN} does not look up the parts of the
9357 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9358 Likewise, the subdirectories of the source path are not searched: if
9359 the source path is @file{/mnt/cross}, and the binary refers to
9360 @file{foo.c}, @value{GDBN} would not find it under
9361 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9362
9363 Plain file names, relative file names with leading directories, file
9364 names containing dots, etc.@: are all treated as described above,
9365 except that non-absolute file names are not looked up literally. If
9366 the @dfn{source path} is @file{/mnt/cross}, the source file is
9367 recorded as @file{../lib/foo.c}, and no compilation directory is
9368 recorded, then @value{GDBN} will search in the following locations:
9369
9370 @enumerate
9371
9372 @item @file{/mnt/cross/../lib/foo.c}
9373 @item @file{/mnt/cross/foo.c}
9374
9375 @end enumerate
9376
9377 @kindex cdir
9378 @kindex cwd
9379 @vindex $cdir@r{, convenience variable}
9380 @vindex $cwd@r{, convenience variable}
9381 @cindex compilation directory
9382 @cindex current directory
9383 @cindex working directory
9384 @cindex directory, current
9385 @cindex directory, compilation
9386 The @dfn{source path} will always include two special entries
9387 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9388 (if one is recorded) and the current working directory respectively.
9389
9390 @samp{$cdir} causes @value{GDBN} to search within the compilation
9391 directory, if one is recorded in the debug information. If no
9392 compilation directory is recorded in the debug information then
9393 @samp{$cdir} is ignored.
9394
9395 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9396 current working directory as it changes during your @value{GDBN}
9397 session, while the latter is immediately expanded to the current
9398 directory at the time you add an entry to the source path.
9399
9400 If a compilation directory is recorded in the debug information, and
9401 @value{GDBN} has not found the source file after the first search
9402 using @dfn{source path}, then @value{GDBN} will combine the
9403 compilation directory and the filename, and then search for the source
9404 file again using the @dfn{source path}.
9405
9406 For example, if the executable records the source file as
9407 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9408 recorded as @file{/project/build}, and the @dfn{source path} is
9409 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9410 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9411 search for the source file in the following locations:
9412
9413 @enumerate
9414
9415 @item @file{/usr/src/foo-1.0/lib/foo.c}
9416 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9417 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9418 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9419 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9420 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9421 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9422 @item @file{/mnt/cross/foo.c}
9423 @item @file{/project/build/foo.c}
9424 @item @file{/home/user/foo.c}
9425
9426 @end enumerate
9427
9428 If the file name in the previous example had been recorded in the
9429 executable as a relative path rather than an absolute path, then the
9430 first look up would not have occurred, but all of the remaining steps
9431 would be similar.
9432
9433 When searching for source files on MS-DOS and MS-Windows, where
9434 absolute paths start with a drive letter (e.g.@:
9435 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9436 from the file name before appending it to a search directory from
9437 @dfn{source path}; for instance if the executable references the
9438 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9439 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9440 locations for the source file:
9441
9442 @enumerate
9443
9444 @item @file{C:/project/foo.c}
9445 @item @file{D:/mnt/cross/project/foo.c}
9446 @item @file{D:/mnt/cross/foo.c}
9447
9448 @end enumerate
9449
9450 Note that the executable search path is @emph{not} used to locate the
9451 source files.
9452
9453 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9454 any information it has cached about where source files are found and where
9455 each line is in the file.
9456
9457 @kindex directory
9458 @kindex dir
9459 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9460 and @samp{$cwd}, in that order.
9461 To add other directories, use the @code{directory} command.
9462
9463 The search path is used to find both program source files and @value{GDBN}
9464 script files (read using the @samp{-command} option and @samp{source} command).
9465
9466 In addition to the source path, @value{GDBN} provides a set of commands
9467 that manage a list of source path substitution rules. A @dfn{substitution
9468 rule} specifies how to rewrite source directories stored in the program's
9469 debug information in case the sources were moved to a different
9470 directory between compilation and debugging. A rule is made of
9471 two strings, the first specifying what needs to be rewritten in
9472 the path, and the second specifying how it should be rewritten.
9473 In @ref{set substitute-path}, we name these two parts @var{from} and
9474 @var{to} respectively. @value{GDBN} does a simple string replacement
9475 of @var{from} with @var{to} at the start of the directory part of the
9476 source file name, and uses that result instead of the original file
9477 name to look up the sources.
9478
9479 Using the previous example, suppose the @file{foo-1.0} tree has been
9480 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9481 @value{GDBN} to replace @file{/usr/src} in all source path names with
9482 @file{/mnt/cross}. The first lookup will then be
9483 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9484 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9485 substitution rule, use the @code{set substitute-path} command
9486 (@pxref{set substitute-path}).
9487
9488 To avoid unexpected substitution results, a rule is applied only if the
9489 @var{from} part of the directory name ends at a directory separator.
9490 For instance, a rule substituting @file{/usr/source} into
9491 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9492 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9493 is applied only at the beginning of the directory name, this rule will
9494 not be applied to @file{/root/usr/source/baz.c} either.
9495
9496 In many cases, you can achieve the same result using the @code{directory}
9497 command. However, @code{set substitute-path} can be more efficient in
9498 the case where the sources are organized in a complex tree with multiple
9499 subdirectories. With the @code{directory} command, you need to add each
9500 subdirectory of your project. If you moved the entire tree while
9501 preserving its internal organization, then @code{set substitute-path}
9502 allows you to direct the debugger to all the sources with one single
9503 command.
9504
9505 @code{set substitute-path} is also more than just a shortcut command.
9506 The source path is only used if the file at the original location no
9507 longer exists. On the other hand, @code{set substitute-path} modifies
9508 the debugger behavior to look at the rewritten location instead. So, if
9509 for any reason a source file that is not relevant to your executable is
9510 located at the original location, a substitution rule is the only
9511 method available to point @value{GDBN} at the new location.
9512
9513 @cindex @samp{--with-relocated-sources}
9514 @cindex default source path substitution
9515 You can configure a default source path substitution rule by
9516 configuring @value{GDBN} with the
9517 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9518 should be the name of a directory under @value{GDBN}'s configured
9519 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9520 directory names in debug information under @var{dir} will be adjusted
9521 automatically if the installed @value{GDBN} is moved to a new
9522 location. This is useful if @value{GDBN}, libraries or executables
9523 with debug information and corresponding source code are being moved
9524 together.
9525
9526 @table @code
9527 @item directory @var{dirname} @dots{}
9528 @item dir @var{dirname} @dots{}
9529 Add directory @var{dirname} to the front of the source path. Several
9530 directory names may be given to this command, separated by @samp{:}
9531 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9532 part of absolute file names) or
9533 whitespace. You may specify a directory that is already in the source
9534 path; this moves it forward, so @value{GDBN} searches it sooner.
9535
9536 The special strings @samp{$cdir} (to refer to the compilation
9537 directory, if one is recorded), and @samp{$cwd} (to refer to the
9538 current working directory) can also be included in the list of
9539 directories @var{dirname}. Though these will already be in the source
9540 path they will be moved forward in the list so @value{GDBN} searches
9541 them sooner.
9542
9543 @item directory
9544 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9545
9546 @c RET-repeat for @code{directory} is explicitly disabled, but since
9547 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9548
9549 @item set directories @var{path-list}
9550 @kindex set directories
9551 Set the source path to @var{path-list}.
9552 @samp{$cdir:$cwd} are added if missing.
9553
9554 @item show directories
9555 @kindex show directories
9556 Print the source path: show which directories it contains.
9557
9558 @anchor{set substitute-path}
9559 @item set substitute-path @var{from} @var{to}
9560 @kindex set substitute-path
9561 Define a source path substitution rule, and add it at the end of the
9562 current list of existing substitution rules. If a rule with the same
9563 @var{from} was already defined, then the old rule is also deleted.
9564
9565 For example, if the file @file{/foo/bar/baz.c} was moved to
9566 @file{/mnt/cross/baz.c}, then the command
9567
9568 @smallexample
9569 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9570 @end smallexample
9571
9572 @noindent
9573 will tell @value{GDBN} to replace @samp{/foo/bar} with
9574 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9575 @file{baz.c} even though it was moved.
9576
9577 In the case when more than one substitution rule have been defined,
9578 the rules are evaluated one by one in the order where they have been
9579 defined. The first one matching, if any, is selected to perform
9580 the substitution.
9581
9582 For instance, if we had entered the following commands:
9583
9584 @smallexample
9585 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9586 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9587 @end smallexample
9588
9589 @noindent
9590 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9591 @file{/mnt/include/defs.h} by using the first rule. However, it would
9592 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9593 @file{/mnt/src/lib/foo.c}.
9594
9595
9596 @item unset substitute-path [path]
9597 @kindex unset substitute-path
9598 If a path is specified, search the current list of substitution rules
9599 for a rule that would rewrite that path. Delete that rule if found.
9600 A warning is emitted by the debugger if no rule could be found.
9601
9602 If no path is specified, then all substitution rules are deleted.
9603
9604 @item show substitute-path [path]
9605 @kindex show substitute-path
9606 If a path is specified, then print the source path substitution rule
9607 which would rewrite that path, if any.
9608
9609 If no path is specified, then print all existing source path substitution
9610 rules.
9611
9612 @end table
9613
9614 If your source path is cluttered with directories that are no longer of
9615 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9616 versions of source. You can correct the situation as follows:
9617
9618 @enumerate
9619 @item
9620 Use @code{directory} with no argument to reset the source path to its default value.
9621
9622 @item
9623 Use @code{directory} with suitable arguments to reinstall the
9624 directories you want in the source path. You can add all the
9625 directories in one command.
9626 @end enumerate
9627
9628 @node Machine Code
9629 @section Source and Machine Code
9630 @cindex source line and its code address
9631
9632 You can use the command @code{info line} to map source lines to program
9633 addresses (and vice versa), and the command @code{disassemble} to display
9634 a range of addresses as machine instructions. You can use the command
9635 @code{set disassemble-next-line} to set whether to disassemble next
9636 source line when execution stops. When run under @sc{gnu} Emacs
9637 mode, the @code{info line} command causes the arrow to point to the
9638 line specified. Also, @code{info line} prints addresses in symbolic form as
9639 well as hex.
9640
9641 @table @code
9642 @kindex info line
9643 @item info line
9644 @itemx info line @var{location}
9645 Print the starting and ending addresses of the compiled code for
9646 source line @var{location}. You can specify source lines in any of
9647 the ways documented in @ref{Specify Location}. With no @var{location}
9648 information about the current source line is printed.
9649 @end table
9650
9651 For example, we can use @code{info line} to discover the location of
9652 the object code for the first line of function
9653 @code{m4_changequote}:
9654
9655 @smallexample
9656 (@value{GDBP}) info line m4_changequote
9657 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9658 ends at 0x6350 <m4_changequote+4>.
9659 @end smallexample
9660
9661 @noindent
9662 @cindex code address and its source line
9663 We can also inquire (using @code{*@var{addr}} as the form for
9664 @var{location}) what source line covers a particular address:
9665 @smallexample
9666 (@value{GDBP}) info line *0x63ff
9667 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9668 ends at 0x6404 <m4_changequote+184>.
9669 @end smallexample
9670
9671 @cindex @code{$_} and @code{info line}
9672 @cindex @code{x} command, default address
9673 @kindex x@r{(examine), and} info line
9674 After @code{info line}, the default address for the @code{x} command
9675 is changed to the starting address of the line, so that @samp{x/i} is
9676 sufficient to begin examining the machine code (@pxref{Memory,
9677 ,Examining Memory}). Also, this address is saved as the value of the
9678 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9679 Variables}).
9680
9681 @cindex info line, repeated calls
9682 After @code{info line}, using @code{info line} again without
9683 specifying a location will display information about the next source
9684 line.
9685
9686 @table @code
9687 @kindex disassemble
9688 @cindex assembly instructions
9689 @cindex instructions, assembly
9690 @cindex machine instructions
9691 @cindex listing machine instructions
9692 @item disassemble
9693 @itemx disassemble /m
9694 @itemx disassemble /s
9695 @itemx disassemble /r
9696 This specialized command dumps a range of memory as machine
9697 instructions. It can also print mixed source+disassembly by specifying
9698 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9699 as well as in symbolic form by specifying the @code{/r} modifier.
9700 The default memory range is the function surrounding the
9701 program counter of the selected frame. A single argument to this
9702 command is a program counter value; @value{GDBN} dumps the function
9703 surrounding this value. When two arguments are given, they should
9704 be separated by a comma, possibly surrounded by whitespace. The
9705 arguments specify a range of addresses to dump, in one of two forms:
9706
9707 @table @code
9708 @item @var{start},@var{end}
9709 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9710 @item @var{start},+@var{length}
9711 the addresses from @var{start} (inclusive) to
9712 @code{@var{start}+@var{length}} (exclusive).
9713 @end table
9714
9715 @noindent
9716 When 2 arguments are specified, the name of the function is also
9717 printed (since there could be several functions in the given range).
9718
9719 The argument(s) can be any expression yielding a numeric value, such as
9720 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9721
9722 If the range of memory being disassembled contains current program counter,
9723 the instruction at that location is shown with a @code{=>} marker.
9724 @end table
9725
9726 The following example shows the disassembly of a range of addresses of
9727 HP PA-RISC 2.0 code:
9728
9729 @smallexample
9730 (@value{GDBP}) disas 0x32c4, 0x32e4
9731 Dump of assembler code from 0x32c4 to 0x32e4:
9732 0x32c4 <main+204>: addil 0,dp
9733 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9734 0x32cc <main+212>: ldil 0x3000,r31
9735 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9736 0x32d4 <main+220>: ldo 0(r31),rp
9737 0x32d8 <main+224>: addil -0x800,dp
9738 0x32dc <main+228>: ldo 0x588(r1),r26
9739 0x32e0 <main+232>: ldil 0x3000,r31
9740 End of assembler dump.
9741 @end smallexample
9742
9743 Here is an example showing mixed source+assembly for Intel x86
9744 with @code{/m} or @code{/s}, when the program is stopped just after
9745 function prologue in a non-optimized function with no inline code.
9746
9747 @smallexample
9748 (@value{GDBP}) disas /m main
9749 Dump of assembler code for function main:
9750 5 @{
9751 0x08048330 <+0>: push %ebp
9752 0x08048331 <+1>: mov %esp,%ebp
9753 0x08048333 <+3>: sub $0x8,%esp
9754 0x08048336 <+6>: and $0xfffffff0,%esp
9755 0x08048339 <+9>: sub $0x10,%esp
9756
9757 6 printf ("Hello.\n");
9758 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9759 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9760
9761 7 return 0;
9762 8 @}
9763 0x08048348 <+24>: mov $0x0,%eax
9764 0x0804834d <+29>: leave
9765 0x0804834e <+30>: ret
9766
9767 End of assembler dump.
9768 @end smallexample
9769
9770 The @code{/m} option is deprecated as its output is not useful when
9771 there is either inlined code or re-ordered code.
9772 The @code{/s} option is the preferred choice.
9773 Here is an example for AMD x86-64 showing the difference between
9774 @code{/m} output and @code{/s} output.
9775 This example has one inline function defined in a header file,
9776 and the code is compiled with @samp{-O2} optimization.
9777 Note how the @code{/m} output is missing the disassembly of
9778 several instructions that are present in the @code{/s} output.
9779
9780 @file{foo.h}:
9781
9782 @smallexample
9783 int
9784 foo (int a)
9785 @{
9786 if (a < 0)
9787 return a * 2;
9788 if (a == 0)
9789 return 1;
9790 return a + 10;
9791 @}
9792 @end smallexample
9793
9794 @file{foo.c}:
9795
9796 @smallexample
9797 #include "foo.h"
9798 volatile int x, y;
9799 int
9800 main ()
9801 @{
9802 x = foo (y);
9803 return 0;
9804 @}
9805 @end smallexample
9806
9807 @smallexample
9808 (@value{GDBP}) disas /m main
9809 Dump of assembler code for function main:
9810 5 @{
9811
9812 6 x = foo (y);
9813 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9814 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9815
9816 7 return 0;
9817 8 @}
9818 0x000000000040041d <+29>: xor %eax,%eax
9819 0x000000000040041f <+31>: retq
9820 0x0000000000400420 <+32>: add %eax,%eax
9821 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9822
9823 End of assembler dump.
9824 (@value{GDBP}) disas /s main
9825 Dump of assembler code for function main:
9826 foo.c:
9827 5 @{
9828 6 x = foo (y);
9829 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9830
9831 foo.h:
9832 4 if (a < 0)
9833 0x0000000000400406 <+6>: test %eax,%eax
9834 0x0000000000400408 <+8>: js 0x400420 <main+32>
9835
9836 6 if (a == 0)
9837 7 return 1;
9838 8 return a + 10;
9839 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9840 0x000000000040040d <+13>: test %eax,%eax
9841 0x000000000040040f <+15>: mov $0x1,%eax
9842 0x0000000000400414 <+20>: cmovne %edx,%eax
9843
9844 foo.c:
9845 6 x = foo (y);
9846 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9847
9848 7 return 0;
9849 8 @}
9850 0x000000000040041d <+29>: xor %eax,%eax
9851 0x000000000040041f <+31>: retq
9852
9853 foo.h:
9854 5 return a * 2;
9855 0x0000000000400420 <+32>: add %eax,%eax
9856 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9857 End of assembler dump.
9858 @end smallexample
9859
9860 Here is another example showing raw instructions in hex for AMD x86-64,
9861
9862 @smallexample
9863 (gdb) disas /r 0x400281,+10
9864 Dump of assembler code from 0x400281 to 0x40028b:
9865 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9866 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9867 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9868 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9869 End of assembler dump.
9870 @end smallexample
9871
9872 Addresses cannot be specified as a location (@pxref{Specify Location}).
9873 So, for example, if you want to disassemble function @code{bar}
9874 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9875 and not @samp{disassemble foo.c:bar}.
9876
9877 Some architectures have more than one commonly-used set of instruction
9878 mnemonics or other syntax.
9879
9880 For programs that were dynamically linked and use shared libraries,
9881 instructions that call functions or branch to locations in the shared
9882 libraries might show a seemingly bogus location---it's actually a
9883 location of the relocation table. On some architectures, @value{GDBN}
9884 might be able to resolve these to actual function names.
9885
9886 @table @code
9887 @kindex set disassembler-options
9888 @cindex disassembler options
9889 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9890 This command controls the passing of target specific information to
9891 the disassembler. For a list of valid options, please refer to the
9892 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9893 manual and/or the output of @kbd{objdump --help}
9894 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9895 The default value is the empty string.
9896
9897 If it is necessary to specify more than one disassembler option, then
9898 multiple options can be placed together into a comma separated list.
9899 Currently this command is only supported on targets ARC, ARM, MIPS,
9900 PowerPC and S/390.
9901
9902 @kindex show disassembler-options
9903 @item show disassembler-options
9904 Show the current setting of the disassembler options.
9905 @end table
9906
9907 @table @code
9908 @kindex set disassembly-flavor
9909 @cindex Intel disassembly flavor
9910 @cindex AT&T disassembly flavor
9911 @item set disassembly-flavor @var{instruction-set}
9912 Select the instruction set to use when disassembling the
9913 program via the @code{disassemble} or @code{x/i} commands.
9914
9915 Currently this command is only defined for the Intel x86 family. You
9916 can set @var{instruction-set} to either @code{intel} or @code{att}.
9917 The default is @code{att}, the AT&T flavor used by default by Unix
9918 assemblers for x86-based targets.
9919
9920 @kindex show disassembly-flavor
9921 @item show disassembly-flavor
9922 Show the current setting of the disassembly flavor.
9923 @end table
9924
9925 @table @code
9926 @kindex set disassemble-next-line
9927 @kindex show disassemble-next-line
9928 @item set disassemble-next-line
9929 @itemx show disassemble-next-line
9930 Control whether or not @value{GDBN} will disassemble the next source
9931 line or instruction when execution stops. If ON, @value{GDBN} will
9932 display disassembly of the next source line when execution of the
9933 program being debugged stops. This is @emph{in addition} to
9934 displaying the source line itself, which @value{GDBN} always does if
9935 possible. If the next source line cannot be displayed for some reason
9936 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9937 info in the debug info), @value{GDBN} will display disassembly of the
9938 next @emph{instruction} instead of showing the next source line. If
9939 AUTO, @value{GDBN} will display disassembly of next instruction only
9940 if the source line cannot be displayed. This setting causes
9941 @value{GDBN} to display some feedback when you step through a function
9942 with no line info or whose source file is unavailable. The default is
9943 OFF, which means never display the disassembly of the next line or
9944 instruction.
9945 @end table
9946
9947 @node Disable Reading Source
9948 @section Disable Reading Source Code
9949 @cindex source code, disable access
9950
9951 In some cases it can be desirable to prevent @value{GDBN} from
9952 accessing source code files. One case where this might be desirable
9953 is if the source code files are located over a slow network
9954 connection.
9955
9956 The following command can be used to control whether @value{GDBN}
9957 should access source code files or not:
9958
9959 @table @code
9960 @kindex set source open
9961 @kindex show source open
9962 @item set source open @r{[}on@r{|}off@r{]}
9963 @itemx show source open
9964 When this option is @code{on}, which is the default, @value{GDBN} will
9965 access source code files when needed, for example to print source
9966 lines when @value{GDBN} stops, or in response to the @code{list}
9967 command.
9968
9969 When this option is @code{off}, @value{GDBN} will not access source
9970 code files.
9971 @end table
9972
9973 @node Data
9974 @chapter Examining Data
9975
9976 @cindex printing data
9977 @cindex examining data
9978 @kindex print
9979 @kindex inspect
9980 The usual way to examine data in your program is with the @code{print}
9981 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9982 evaluates and prints the value of an expression of the language your
9983 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9984 Different Languages}). It may also print the expression using a
9985 Python-based pretty-printer (@pxref{Pretty Printing}).
9986
9987 @table @code
9988 @item print [[@var{options}] --] @var{expr}
9989 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9990 @var{expr} is an expression (in the source language). By default the
9991 value of @var{expr} is printed in a format appropriate to its data type;
9992 you can choose a different format by specifying @samp{/@var{f}}, where
9993 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9994 Formats}.
9995
9996 @anchor{print options}
9997 The @code{print} command supports a number of options that allow
9998 overriding relevant global print settings as set by @code{set print}
9999 subcommands:
10000
10001 @table @code
10002 @item -address [@code{on}|@code{off}]
10003 Set printing of addresses.
10004 Related setting: @ref{set print address}.
10005
10006 @item -array [@code{on}|@code{off}]
10007 Pretty formatting of arrays.
10008 Related setting: @ref{set print array}.
10009
10010 @item -array-indexes [@code{on}|@code{off}]
10011 Set printing of array indexes.
10012 Related setting: @ref{set print array-indexes}.
10013
10014 @item -elements @var{number-of-elements}|@code{unlimited}
10015 Set limit on string chars or array elements to print. The value
10016 @code{unlimited} causes there to be no limit. Related setting:
10017 @ref{set print elements}.
10018
10019 @item -max-depth @var{depth}|@code{unlimited}
10020 Set the threshold after which nested structures are replaced with
10021 ellipsis. Related setting: @ref{set print max-depth}.
10022
10023 @item -memory-tag-violations [@code{on}|@code{off}]
10024 Set printing of additional information about memory tag violations.
10025 @xref{set print memory-tag-violations}.
10026
10027 @item -null-stop [@code{on}|@code{off}]
10028 Set printing of char arrays to stop at first null char. Related
10029 setting: @ref{set print null-stop}.
10030
10031 @item -object [@code{on}|@code{off}]
10032 Set printing C@t{++} virtual function tables. Related setting:
10033 @ref{set print object}.
10034
10035 @item -pretty [@code{on}|@code{off}]
10036 Set pretty formatting of structures. Related setting: @ref{set print
10037 pretty}.
10038
10039 @item -raw-values [@code{on}|@code{off}]
10040 Set whether to print values in raw form, bypassing any
10041 pretty-printers for that value. Related setting: @ref{set print
10042 raw-values}.
10043
10044 @item -repeats @var{number-of-repeats}|@code{unlimited}
10045 Set threshold for repeated print elements. @code{unlimited} causes
10046 all elements to be individually printed. Related setting: @ref{set
10047 print repeats}.
10048
10049 @item -static-members [@code{on}|@code{off}]
10050 Set printing C@t{++} static members. Related setting: @ref{set print
10051 static-members}.
10052
10053 @item -symbol [@code{on}|@code{off}]
10054 Set printing of symbol names when printing pointers. Related setting:
10055 @ref{set print symbol}.
10056
10057 @item -union [@code{on}|@code{off}]
10058 Set printing of unions interior to structures. Related setting:
10059 @ref{set print union}.
10060
10061 @item -vtbl [@code{on}|@code{off}]
10062 Set printing of C++ virtual function tables. Related setting:
10063 @ref{set print vtbl}.
10064 @end table
10065
10066 Because the @code{print} command accepts arbitrary expressions which
10067 may look like options (including abbreviations), if you specify any
10068 command option, then you must use a double dash (@code{--}) to mark
10069 the end of option processing.
10070
10071 For example, this prints the value of the @code{-p} expression:
10072
10073 @smallexample
10074 (@value{GDBP}) print -p
10075 @end smallexample
10076
10077 While this repeats the last value in the value history (see below)
10078 with the @code{-pretty} option in effect:
10079
10080 @smallexample
10081 (@value{GDBP}) print -p --
10082 @end smallexample
10083
10084 Here is an example including both on option and an expression:
10085
10086 @smallexample
10087 @group
10088 (@value{GDBP}) print -pretty -- *myptr
10089 $1 = @{
10090 next = 0x0,
10091 flags = @{
10092 sweet = 1,
10093 sour = 1
10094 @},
10095 meat = 0x54 "Pork"
10096 @}
10097 @end group
10098 @end smallexample
10099
10100 @item print [@var{options}]
10101 @itemx print [@var{options}] /@var{f}
10102 @cindex reprint the last value
10103 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10104 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10105 conveniently inspect the same value in an alternative format.
10106 @end table
10107
10108 If the architecture supports memory tagging, the @code{print} command will
10109 display pointer/memory tag mismatches if what is being printed is a pointer
10110 or reference type. @xref{Memory Tagging}.
10111
10112 A more low-level way of examining data is with the @code{x} command.
10113 It examines data in memory at a specified address and prints it in a
10114 specified format. @xref{Memory, ,Examining Memory}.
10115
10116 If you are interested in information about types, or about how the
10117 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
10118 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10119 Table}.
10120
10121 @cindex exploring hierarchical data structures
10122 @kindex explore
10123 Another way of examining values of expressions and type information is
10124 through the Python extension command @code{explore} (available only if
10125 the @value{GDBN} build is configured with @code{--with-python}). It
10126 offers an interactive way to start at the highest level (or, the most
10127 abstract level) of the data type of an expression (or, the data type
10128 itself) and explore all the way down to leaf scalar values/fields
10129 embedded in the higher level data types.
10130
10131 @table @code
10132 @item explore @var{arg}
10133 @var{arg} is either an expression (in the source language), or a type
10134 visible in the current context of the program being debugged.
10135 @end table
10136
10137 The working of the @code{explore} command can be illustrated with an
10138 example. If a data type @code{struct ComplexStruct} is defined in your
10139 C program as
10140
10141 @smallexample
10142 struct SimpleStruct
10143 @{
10144 int i;
10145 double d;
10146 @};
10147
10148 struct ComplexStruct
10149 @{
10150 struct SimpleStruct *ss_p;
10151 int arr[10];
10152 @};
10153 @end smallexample
10154
10155 @noindent
10156 followed by variable declarations as
10157
10158 @smallexample
10159 struct SimpleStruct ss = @{ 10, 1.11 @};
10160 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10161 @end smallexample
10162
10163 @noindent
10164 then, the value of the variable @code{cs} can be explored using the
10165 @code{explore} command as follows.
10166
10167 @smallexample
10168 (gdb) explore cs
10169 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10170 the following fields:
10171
10172 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10173 arr = <Enter 1 to explore this field of type `int [10]'>
10174
10175 Enter the field number of choice:
10176 @end smallexample
10177
10178 @noindent
10179 Since the fields of @code{cs} are not scalar values, you are being
10180 prompted to chose the field you want to explore. Let's say you choose
10181 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10182 pointer, you will be asked if it is pointing to a single value. From
10183 the declaration of @code{cs} above, it is indeed pointing to a single
10184 value, hence you enter @code{y}. If you enter @code{n}, then you will
10185 be asked if it were pointing to an array of values, in which case this
10186 field will be explored as if it were an array.
10187
10188 @smallexample
10189 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10190 Continue exploring it as a pointer to a single value [y/n]: y
10191 The value of `*(cs.ss_p)' is a struct/class of type `struct
10192 SimpleStruct' with the following fields:
10193
10194 i = 10 .. (Value of type `int')
10195 d = 1.1100000000000001 .. (Value of type `double')
10196
10197 Press enter to return to parent value:
10198 @end smallexample
10199
10200 @noindent
10201 If the field @code{arr} of @code{cs} was chosen for exploration by
10202 entering @code{1} earlier, then since it is as array, you will be
10203 prompted to enter the index of the element in the array that you want
10204 to explore.
10205
10206 @smallexample
10207 `cs.arr' is an array of `int'.
10208 Enter the index of the element you want to explore in `cs.arr': 5
10209
10210 `(cs.arr)[5]' is a scalar value of type `int'.
10211
10212 (cs.arr)[5] = 4
10213
10214 Press enter to return to parent value:
10215 @end smallexample
10216
10217 In general, at any stage of exploration, you can go deeper towards the
10218 leaf values by responding to the prompts appropriately, or hit the
10219 return key to return to the enclosing data structure (the @i{higher}
10220 level data structure).
10221
10222 Similar to exploring values, you can use the @code{explore} command to
10223 explore types. Instead of specifying a value (which is typically a
10224 variable name or an expression valid in the current context of the
10225 program being debugged), you specify a type name. If you consider the
10226 same example as above, your can explore the type
10227 @code{struct ComplexStruct} by passing the argument
10228 @code{struct ComplexStruct} to the @code{explore} command.
10229
10230 @smallexample
10231 (gdb) explore struct ComplexStruct
10232 @end smallexample
10233
10234 @noindent
10235 By responding to the prompts appropriately in the subsequent interactive
10236 session, you can explore the type @code{struct ComplexStruct} in a
10237 manner similar to how the value @code{cs} was explored in the above
10238 example.
10239
10240 The @code{explore} command also has two sub-commands,
10241 @code{explore value} and @code{explore type}. The former sub-command is
10242 a way to explicitly specify that value exploration of the argument is
10243 being invoked, while the latter is a way to explicitly specify that type
10244 exploration of the argument is being invoked.
10245
10246 @table @code
10247 @item explore value @var{expr}
10248 @cindex explore value
10249 This sub-command of @code{explore} explores the value of the
10250 expression @var{expr} (if @var{expr} is an expression valid in the
10251 current context of the program being debugged). The behavior of this
10252 command is identical to that of the behavior of the @code{explore}
10253 command being passed the argument @var{expr}.
10254
10255 @item explore type @var{arg}
10256 @cindex explore type
10257 This sub-command of @code{explore} explores the type of @var{arg} (if
10258 @var{arg} is a type visible in the current context of program being
10259 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10260 is an expression valid in the current context of the program being
10261 debugged). If @var{arg} is a type, then the behavior of this command is
10262 identical to that of the @code{explore} command being passed the
10263 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10264 this command will be identical to that of the @code{explore} command
10265 being passed the type of @var{arg} as the argument.
10266 @end table
10267
10268 @menu
10269 * Expressions:: Expressions
10270 * Ambiguous Expressions:: Ambiguous Expressions
10271 * Variables:: Program variables
10272 * Arrays:: Artificial arrays
10273 * Output Formats:: Output formats
10274 * Memory:: Examining memory
10275 * Memory Tagging:: Memory Tagging
10276 * Auto Display:: Automatic display
10277 * Print Settings:: Print settings
10278 * Pretty Printing:: Python pretty printing
10279 * Value History:: Value history
10280 * Convenience Vars:: Convenience variables
10281 * Convenience Funs:: Convenience functions
10282 * Registers:: Registers
10283 * Floating Point Hardware:: Floating point hardware
10284 * Vector Unit:: Vector Unit
10285 * OS Information:: Auxiliary data provided by operating system
10286 * Memory Region Attributes:: Memory region attributes
10287 * Dump/Restore Files:: Copy between memory and a file
10288 * Core File Generation:: Cause a program dump its core
10289 * Character Sets:: Debugging programs that use a different
10290 character set than GDB does
10291 * Caching Target Data:: Data caching for targets
10292 * Searching Memory:: Searching memory for a sequence of bytes
10293 * Value Sizes:: Managing memory allocated for values
10294 @end menu
10295
10296 @node Expressions
10297 @section Expressions
10298
10299 @cindex expressions
10300 @code{print} and many other @value{GDBN} commands accept an expression and
10301 compute its value. Any kind of constant, variable or operator defined
10302 by the programming language you are using is valid in an expression in
10303 @value{GDBN}. This includes conditional expressions, function calls,
10304 casts, and string constants. It also includes preprocessor macros, if
10305 you compiled your program to include this information; see
10306 @ref{Compilation}.
10307
10308 @cindex arrays in expressions
10309 @value{GDBN} supports array constants in expressions input by
10310 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10311 you can use the command @code{print @{1, 2, 3@}} to create an array
10312 of three integers. If you pass an array to a function or assign it
10313 to a program variable, @value{GDBN} copies the array to memory that
10314 is @code{malloc}ed in the target program.
10315
10316 Because C is so widespread, most of the expressions shown in examples in
10317 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10318 Languages}, for information on how to use expressions in other
10319 languages.
10320
10321 In this section, we discuss operators that you can use in @value{GDBN}
10322 expressions regardless of your programming language.
10323
10324 @cindex casts, in expressions
10325 Casts are supported in all languages, not just in C, because it is so
10326 useful to cast a number into a pointer in order to examine a structure
10327 at that address in memory.
10328 @c FIXME: casts supported---Mod2 true?
10329
10330 @value{GDBN} supports these operators, in addition to those common
10331 to programming languages:
10332
10333 @table @code
10334 @item @@
10335 @samp{@@} is a binary operator for treating parts of memory as arrays.
10336 @xref{Arrays, ,Artificial Arrays}, for more information.
10337
10338 @item ::
10339 @samp{::} allows you to specify a variable in terms of the file or
10340 function where it is defined. @xref{Variables, ,Program Variables}.
10341
10342 @cindex @{@var{type}@}
10343 @cindex type casting memory
10344 @cindex memory, viewing as typed object
10345 @cindex casts, to view memory
10346 @item @{@var{type}@} @var{addr}
10347 Refers to an object of type @var{type} stored at address @var{addr} in
10348 memory. The address @var{addr} may be any expression whose value is
10349 an integer or pointer (but parentheses are required around binary
10350 operators, just as in a cast). This construct is allowed regardless
10351 of what kind of data is normally supposed to reside at @var{addr}.
10352 @end table
10353
10354 @node Ambiguous Expressions
10355 @section Ambiguous Expressions
10356 @cindex ambiguous expressions
10357
10358 Expressions can sometimes contain some ambiguous elements. For instance,
10359 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10360 a single function name to be defined several times, for application in
10361 different contexts. This is called @dfn{overloading}. Another example
10362 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10363 templates and is typically instantiated several times, resulting in
10364 the same function name being defined in different contexts.
10365
10366 In some cases and depending on the language, it is possible to adjust
10367 the expression to remove the ambiguity. For instance in C@t{++}, you
10368 can specify the signature of the function you want to break on, as in
10369 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10370 qualified name of your function often makes the expression unambiguous
10371 as well.
10372
10373 When an ambiguity that needs to be resolved is detected, the debugger
10374 has the capability to display a menu of numbered choices for each
10375 possibility, and then waits for the selection with the prompt @samp{>}.
10376 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10377 aborts the current command. If the command in which the expression was
10378 used allows more than one choice to be selected, the next option in the
10379 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10380 choices.
10381
10382 For example, the following session excerpt shows an attempt to set a
10383 breakpoint at the overloaded symbol @code{String::after}.
10384 We choose three particular definitions of that function name:
10385
10386 @c FIXME! This is likely to change to show arg type lists, at least
10387 @smallexample
10388 @group
10389 (@value{GDBP}) b String::after
10390 [0] cancel
10391 [1] all
10392 [2] file:String.cc; line number:867
10393 [3] file:String.cc; line number:860
10394 [4] file:String.cc; line number:875
10395 [5] file:String.cc; line number:853
10396 [6] file:String.cc; line number:846
10397 [7] file:String.cc; line number:735
10398 > 2 4 6
10399 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10400 Breakpoint 2 at 0xb344: file String.cc, line 875.
10401 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10402 Multiple breakpoints were set.
10403 Use the "delete" command to delete unwanted
10404 breakpoints.
10405 (@value{GDBP})
10406 @end group
10407 @end smallexample
10408
10409 @table @code
10410 @kindex set multiple-symbols
10411 @item set multiple-symbols @var{mode}
10412 @cindex multiple-symbols menu
10413
10414 This option allows you to adjust the debugger behavior when an expression
10415 is ambiguous.
10416
10417 By default, @var{mode} is set to @code{all}. If the command with which
10418 the expression is used allows more than one choice, then @value{GDBN}
10419 automatically selects all possible choices. For instance, inserting
10420 a breakpoint on a function using an ambiguous name results in a breakpoint
10421 inserted on each possible match. However, if a unique choice must be made,
10422 then @value{GDBN} uses the menu to help you disambiguate the expression.
10423 For instance, printing the address of an overloaded function will result
10424 in the use of the menu.
10425
10426 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10427 when an ambiguity is detected.
10428
10429 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10430 an error due to the ambiguity and the command is aborted.
10431
10432 @kindex show multiple-symbols
10433 @item show multiple-symbols
10434 Show the current value of the @code{multiple-symbols} setting.
10435 @end table
10436
10437 @node Variables
10438 @section Program Variables
10439
10440 The most common kind of expression to use is the name of a variable
10441 in your program.
10442
10443 Variables in expressions are understood in the selected stack frame
10444 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10445
10446 @itemize @bullet
10447 @item
10448 global (or file-static)
10449 @end itemize
10450
10451 @noindent or
10452
10453 @itemize @bullet
10454 @item
10455 visible according to the scope rules of the
10456 programming language from the point of execution in that frame
10457 @end itemize
10458
10459 @noindent This means that in the function
10460
10461 @smallexample
10462 foo (a)
10463 int a;
10464 @{
10465 bar (a);
10466 @{
10467 int b = test ();
10468 bar (b);
10469 @}
10470 @}
10471 @end smallexample
10472
10473 @noindent
10474 you can examine and use the variable @code{a} whenever your program is
10475 executing within the function @code{foo}, but you can only use or
10476 examine the variable @code{b} while your program is executing inside
10477 the block where @code{b} is declared.
10478
10479 @cindex variable name conflict
10480 There is an exception: you can refer to a variable or function whose
10481 scope is a single source file even if the current execution point is not
10482 in this file. But it is possible to have more than one such variable or
10483 function with the same name (in different source files). If that
10484 happens, referring to that name has unpredictable effects. If you wish,
10485 you can specify a static variable in a particular function or file by
10486 using the colon-colon (@code{::}) notation:
10487
10488 @cindex colon-colon, context for variables/functions
10489 @ifnotinfo
10490 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10491 @cindex @code{::}, context for variables/functions
10492 @end ifnotinfo
10493 @smallexample
10494 @var{file}::@var{variable}
10495 @var{function}::@var{variable}
10496 @end smallexample
10497
10498 @noindent
10499 Here @var{file} or @var{function} is the name of the context for the
10500 static @var{variable}. In the case of file names, you can use quotes to
10501 make sure @value{GDBN} parses the file name as a single word---for example,
10502 to print a global value of @code{x} defined in @file{f2.c}:
10503
10504 @smallexample
10505 (@value{GDBP}) p 'f2.c'::x
10506 @end smallexample
10507
10508 The @code{::} notation is normally used for referring to
10509 static variables, since you typically disambiguate uses of local variables
10510 in functions by selecting the appropriate frame and using the
10511 simple name of the variable. However, you may also use this notation
10512 to refer to local variables in frames enclosing the selected frame:
10513
10514 @smallexample
10515 void
10516 foo (int a)
10517 @{
10518 if (a < 10)
10519 bar (a);
10520 else
10521 process (a); /* Stop here */
10522 @}
10523
10524 int
10525 bar (int a)
10526 @{
10527 foo (a + 5);
10528 @}
10529 @end smallexample
10530
10531 @noindent
10532 For example, if there is a breakpoint at the commented line,
10533 here is what you might see
10534 when the program stops after executing the call @code{bar(0)}:
10535
10536 @smallexample
10537 (@value{GDBP}) p a
10538 $1 = 10
10539 (@value{GDBP}) p bar::a
10540 $2 = 5
10541 (@value{GDBP}) up 2
10542 #2 0x080483d0 in foo (a=5) at foobar.c:12
10543 (@value{GDBP}) p a
10544 $3 = 5
10545 (@value{GDBP}) p bar::a
10546 $4 = 0
10547 @end smallexample
10548
10549 @cindex C@t{++} scope resolution
10550 These uses of @samp{::} are very rarely in conflict with the very
10551 similar use of the same notation in C@t{++}. When they are in
10552 conflict, the C@t{++} meaning takes precedence; however, this can be
10553 overridden by quoting the file or function name with single quotes.
10554
10555 For example, suppose the program is stopped in a method of a class
10556 that has a field named @code{includefile}, and there is also an
10557 include file named @file{includefile} that defines a variable,
10558 @code{some_global}.
10559
10560 @smallexample
10561 (@value{GDBP}) p includefile
10562 $1 = 23
10563 (@value{GDBP}) p includefile::some_global
10564 A syntax error in expression, near `'.
10565 (@value{GDBP}) p 'includefile'::some_global
10566 $2 = 27
10567 @end smallexample
10568
10569 @cindex wrong values
10570 @cindex variable values, wrong
10571 @cindex function entry/exit, wrong values of variables
10572 @cindex optimized code, wrong values of variables
10573 @quotation
10574 @emph{Warning:} Occasionally, a local variable may appear to have the
10575 wrong value at certain points in a function---just after entry to a new
10576 scope, and just before exit.
10577 @end quotation
10578 You may see this problem when you are stepping by machine instructions.
10579 This is because, on most machines, it takes more than one instruction to
10580 set up a stack frame (including local variable definitions); if you are
10581 stepping by machine instructions, variables may appear to have the wrong
10582 values until the stack frame is completely built. On exit, it usually
10583 also takes more than one machine instruction to destroy a stack frame;
10584 after you begin stepping through that group of instructions, local
10585 variable definitions may be gone.
10586
10587 This may also happen when the compiler does significant optimizations.
10588 To be sure of always seeing accurate values, turn off all optimization
10589 when compiling.
10590
10591 @cindex ``No symbol "foo" in current context''
10592 Another possible effect of compiler optimizations is to optimize
10593 unused variables out of existence, or assign variables to registers (as
10594 opposed to memory addresses). Depending on the support for such cases
10595 offered by the debug info format used by the compiler, @value{GDBN}
10596 might not be able to display values for such local variables. If that
10597 happens, @value{GDBN} will print a message like this:
10598
10599 @smallexample
10600 No symbol "foo" in current context.
10601 @end smallexample
10602
10603 To solve such problems, either recompile without optimizations, or use a
10604 different debug info format, if the compiler supports several such
10605 formats. @xref{Compilation}, for more information on choosing compiler
10606 options. @xref{C, ,C and C@t{++}}, for more information about debug
10607 info formats that are best suited to C@t{++} programs.
10608
10609 If you ask to print an object whose contents are unknown to
10610 @value{GDBN}, e.g., because its data type is not completely specified
10611 by the debug information, @value{GDBN} will say @samp{<incomplete
10612 type>}. @xref{Symbols, incomplete type}, for more about this.
10613
10614 @cindex no debug info variables
10615 If you try to examine or use the value of a (global) variable for
10616 which @value{GDBN} has no type information, e.g., because the program
10617 includes no debug information, @value{GDBN} displays an error message.
10618 @xref{Symbols, unknown type}, for more about unknown types. If you
10619 cast the variable to its declared type, @value{GDBN} gets the
10620 variable's value using the cast-to type as the variable's type. For
10621 example, in a C program:
10622
10623 @smallexample
10624 (@value{GDBP}) p var
10625 'var' has unknown type; cast it to its declared type
10626 (@value{GDBP}) p (float) var
10627 $1 = 3.14
10628 @end smallexample
10629
10630 If you append @kbd{@@entry} string to a function parameter name you get its
10631 value at the time the function got called. If the value is not available an
10632 error message is printed. Entry values are available only with some compilers.
10633 Entry values are normally also printed at the function parameter list according
10634 to @ref{set print entry-values}.
10635
10636 @smallexample
10637 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10638 29 i++;
10639 (gdb) next
10640 30 e (i);
10641 (gdb) print i
10642 $1 = 31
10643 (gdb) print i@@entry
10644 $2 = 30
10645 @end smallexample
10646
10647 Strings are identified as arrays of @code{char} values without specified
10648 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10649 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10650 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10651 defines literal string type @code{"char"} as @code{char} without a sign.
10652 For program code
10653
10654 @smallexample
10655 char var0[] = "A";
10656 signed char var1[] = "A";
10657 @end smallexample
10658
10659 You get during debugging
10660 @smallexample
10661 (gdb) print var0
10662 $1 = "A"
10663 (gdb) print var1
10664 $2 = @{65 'A', 0 '\0'@}
10665 @end smallexample
10666
10667 @node Arrays
10668 @section Artificial Arrays
10669
10670 @cindex artificial array
10671 @cindex arrays
10672 @kindex @@@r{, referencing memory as an array}
10673 It is often useful to print out several successive objects of the
10674 same type in memory; a section of an array, or an array of
10675 dynamically determined size for which only a pointer exists in the
10676 program.
10677
10678 You can do this by referring to a contiguous span of memory as an
10679 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10680 operand of @samp{@@} should be the first element of the desired array
10681 and be an individual object. The right operand should be the desired length
10682 of the array. The result is an array value whose elements are all of
10683 the type of the left argument. The first element is actually the left
10684 argument; the second element comes from bytes of memory immediately
10685 following those that hold the first element, and so on. Here is an
10686 example. If a program says
10687
10688 @smallexample
10689 int *array = (int *) malloc (len * sizeof (int));
10690 @end smallexample
10691
10692 @noindent
10693 you can print the contents of @code{array} with
10694
10695 @smallexample
10696 p *array@@len
10697 @end smallexample
10698
10699 The left operand of @samp{@@} must reside in memory. Array values made
10700 with @samp{@@} in this way behave just like other arrays in terms of
10701 subscripting, and are coerced to pointers when used in expressions.
10702 Artificial arrays most often appear in expressions via the value history
10703 (@pxref{Value History, ,Value History}), after printing one out.
10704
10705 Another way to create an artificial array is to use a cast.
10706 This re-interprets a value as if it were an array.
10707 The value need not be in memory:
10708 @smallexample
10709 (@value{GDBP}) p/x (short[2])0x12345678
10710 $1 = @{0x1234, 0x5678@}
10711 @end smallexample
10712
10713 As a convenience, if you leave the array length out (as in
10714 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10715 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10716 @smallexample
10717 (@value{GDBP}) p/x (short[])0x12345678
10718 $2 = @{0x1234, 0x5678@}
10719 @end smallexample
10720
10721 Sometimes the artificial array mechanism is not quite enough; in
10722 moderately complex data structures, the elements of interest may not
10723 actually be adjacent---for example, if you are interested in the values
10724 of pointers in an array. One useful work-around in this situation is
10725 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10726 Variables}) as a counter in an expression that prints the first
10727 interesting value, and then repeat that expression via @key{RET}. For
10728 instance, suppose you have an array @code{dtab} of pointers to
10729 structures, and you are interested in the values of a field @code{fv}
10730 in each structure. Here is an example of what you might type:
10731
10732 @smallexample
10733 set $i = 0
10734 p dtab[$i++]->fv
10735 @key{RET}
10736 @key{RET}
10737 @dots{}
10738 @end smallexample
10739
10740 @node Output Formats
10741 @section Output Formats
10742
10743 @cindex formatted output
10744 @cindex output formats
10745 By default, @value{GDBN} prints a value according to its data type. Sometimes
10746 this is not what you want. For example, you might want to print a number
10747 in hex, or a pointer in decimal. Or you might want to view data in memory
10748 at a certain address as a character string or as an instruction. To do
10749 these things, specify an @dfn{output format} when you print a value.
10750
10751 The simplest use of output formats is to say how to print a value
10752 already computed. This is done by starting the arguments of the
10753 @code{print} command with a slash and a format letter. The format
10754 letters supported are:
10755
10756 @table @code
10757 @item x
10758 Regard the bits of the value as an integer, and print the integer in
10759 hexadecimal.
10760
10761 @item d
10762 Print as integer in signed decimal.
10763
10764 @item u
10765 Print as integer in unsigned decimal.
10766
10767 @item o
10768 Print as integer in octal.
10769
10770 @item t
10771 Print as integer in binary. The letter @samp{t} stands for ``two''.
10772 @footnote{@samp{b} cannot be used because these format letters are also
10773 used with the @code{x} command, where @samp{b} stands for ``byte'';
10774 see @ref{Memory,,Examining Memory}.}
10775
10776 @item a
10777 @cindex unknown address, locating
10778 @cindex locate address
10779 Print as an address, both absolute in hexadecimal and as an offset from
10780 the nearest preceding symbol. You can use this format used to discover
10781 where (in what function) an unknown address is located:
10782
10783 @smallexample
10784 (@value{GDBP}) p/a 0x54320
10785 $3 = 0x54320 <_initialize_vx+396>
10786 @end smallexample
10787
10788 @noindent
10789 The command @code{info symbol 0x54320} yields similar results.
10790 @xref{Symbols, info symbol}.
10791
10792 @item c
10793 Regard as an integer and print it as a character constant. This
10794 prints both the numerical value and its character representation. The
10795 character representation is replaced with the octal escape @samp{\nnn}
10796 for characters outside the 7-bit @sc{ascii} range.
10797
10798 Without this format, @value{GDBN} displays @code{char},
10799 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10800 constants. Single-byte members of vectors are displayed as integer
10801 data.
10802
10803 @item f
10804 Regard the bits of the value as a floating point number and print
10805 using typical floating point syntax.
10806
10807 @item s
10808 @cindex printing strings
10809 @cindex printing byte arrays
10810 Regard as a string, if possible. With this format, pointers to single-byte
10811 data are displayed as null-terminated strings and arrays of single-byte data
10812 are displayed as fixed-length strings. Other values are displayed in their
10813 natural types.
10814
10815 Without this format, @value{GDBN} displays pointers to and arrays of
10816 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10817 strings. Single-byte members of a vector are displayed as an integer
10818 array.
10819
10820 @item z
10821 Like @samp{x} formatting, the value is treated as an integer and
10822 printed as hexadecimal, but leading zeros are printed to pad the value
10823 to the size of the integer type.
10824
10825 @item r
10826 @cindex raw printing
10827 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10828 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10829 Printing}). This typically results in a higher-level display of the
10830 value's contents. The @samp{r} format bypasses any Python
10831 pretty-printer which might exist.
10832 @end table
10833
10834 For example, to print the program counter in hex (@pxref{Registers}), type
10835
10836 @smallexample
10837 p/x $pc
10838 @end smallexample
10839
10840 @noindent
10841 Note that no space is required before the slash; this is because command
10842 names in @value{GDBN} cannot contain a slash.
10843
10844 To reprint the last value in the value history with a different format,
10845 you can use the @code{print} command with just a format and no
10846 expression. For example, @samp{p/x} reprints the last value in hex.
10847
10848 @node Memory
10849 @section Examining Memory
10850
10851 You can use the command @code{x} (for ``examine'') to examine memory in
10852 any of several formats, independently of your program's data types.
10853
10854 @cindex examining memory
10855 @table @code
10856 @kindex x @r{(examine memory)}
10857 @item x/@var{nfu} @var{addr}
10858 @itemx x @var{addr}
10859 @itemx x
10860 Use the @code{x} command to examine memory.
10861 @end table
10862
10863 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10864 much memory to display and how to format it; @var{addr} is an
10865 expression giving the address where you want to start displaying memory.
10866 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10867 Several commands set convenient defaults for @var{addr}.
10868
10869 @table @r
10870 @item @var{n}, the repeat count
10871 The repeat count is a decimal integer; the default is 1. It specifies
10872 how much memory (counting by units @var{u}) to display. If a negative
10873 number is specified, memory is examined backward from @var{addr}.
10874 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10875 @c 4.1.2.
10876
10877 @item @var{f}, the display format
10878 The display format is one of the formats used by @code{print}
10879 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10880 @samp{f}, @samp{s}), @samp{i} (for machine instructions) and
10881 @samp{m} (for displaying memory tags).
10882 The default is @samp{x} (hexadecimal) initially. The default changes
10883 each time you use either @code{x} or @code{print}.
10884
10885 @item @var{u}, the unit size
10886 The unit size is any of
10887
10888 @table @code
10889 @item b
10890 Bytes.
10891 @item h
10892 Halfwords (two bytes).
10893 @item w
10894 Words (four bytes). This is the initial default.
10895 @item g
10896 Giant words (eight bytes).
10897 @end table
10898
10899 Each time you specify a unit size with @code{x}, that size becomes the
10900 default unit the next time you use @code{x}. For the @samp{i} format,
10901 the unit size is ignored and is normally not written. For the @samp{s} format,
10902 the unit size defaults to @samp{b}, unless it is explicitly given.
10903 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10904 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10905 Note that the results depend on the programming language of the
10906 current compilation unit. If the language is C, the @samp{s}
10907 modifier will use the UTF-16 encoding while @samp{w} will use
10908 UTF-32. The encoding is set by the programming language and cannot
10909 be altered.
10910
10911 @item @var{addr}, starting display address
10912 @var{addr} is the address where you want @value{GDBN} to begin displaying
10913 memory. The expression need not have a pointer value (though it may);
10914 it is always interpreted as an integer address of a byte of memory.
10915 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10916 @var{addr} is usually just after the last address examined---but several
10917 other commands also set the default address: @code{info breakpoints} (to
10918 the address of the last breakpoint listed), @code{info line} (to the
10919 starting address of a line), and @code{print} (if you use it to display
10920 a value from memory).
10921 @end table
10922
10923 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10924 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10925 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10926 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10927 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10928
10929 You can also specify a negative repeat count to examine memory backward
10930 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10931 halfwords (@code{h}) at @code{0x5431a}, @code{0x5431c}, and @code{0x5431e}.
10932
10933 Since the letters indicating unit sizes are all distinct from the
10934 letters specifying output formats, you do not have to remember whether
10935 unit size or format comes first; either order works. The output
10936 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10937 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10938
10939 Even though the unit size @var{u} is ignored for the formats @samp{s}
10940 and @samp{i}, you might still want to use a count @var{n}; for example,
10941 @samp{3i} specifies that you want to see three machine instructions,
10942 including any operands. For convenience, especially when used with
10943 the @code{display} command, the @samp{i} format also prints branch delay
10944 slot instructions, if any, beyond the count specified, which immediately
10945 follow the last instruction that is within the count. The command
10946 @code{disassemble} gives an alternative way of inspecting machine
10947 instructions; see @ref{Machine Code,,Source and Machine Code}.
10948
10949 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10950 the command displays null-terminated strings or instructions before the given
10951 address as many as the absolute value of the given number. For the @samp{i}
10952 format, we use line number information in the debug info to accurately locate
10953 instruction boundaries while disassembling backward. If line info is not
10954 available, the command stops examining memory with an error message.
10955
10956 All the defaults for the arguments to @code{x} are designed to make it
10957 easy to continue scanning memory with minimal specifications each time
10958 you use @code{x}. For example, after you have inspected three machine
10959 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10960 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10961 the repeat count @var{n} is used again; the other arguments default as
10962 for successive uses of @code{x}.
10963
10964 When examining machine instructions, the instruction at current program
10965 counter is shown with a @code{=>} marker. For example:
10966
10967 @smallexample
10968 (@value{GDBP}) x/5i $pc-6
10969 0x804837f <main+11>: mov %esp,%ebp
10970 0x8048381 <main+13>: push %ecx
10971 0x8048382 <main+14>: sub $0x4,%esp
10972 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10973 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10974 @end smallexample
10975
10976 If the architecture supports memory tagging, the tags can be displayed by
10977 using @samp{m}. @xref{Memory Tagging}.
10978
10979 The information will be displayed once per granule size
10980 (the amount of bytes a particular memory tag covers). For example, AArch64
10981 has a granule size of 16 bytes, so it will display a tag every 16 bytes.
10982
10983 Due to the way @value{GDBN} prints information with the @code{x} command (not
10984 aligned to a particular boundary), the tag information will refer to the
10985 initial address displayed on a particular line. If a memory tag boundary
10986 is crossed in the middle of a line displayed by the @code{x} command, it
10987 will be displayed on the next line.
10988
10989 The @samp{m} format doesn't affect any other specified formats that were
10990 passed to the @code{x} command.
10991
10992 @cindex @code{$_}, @code{$__}, and value history
10993 The addresses and contents printed by the @code{x} command are not saved
10994 in the value history because there is often too much of them and they
10995 would get in the way. Instead, @value{GDBN} makes these values available for
10996 subsequent use in expressions as values of the convenience variables
10997 @code{$_} and @code{$__}. After an @code{x} command, the last address
10998 examined is available for use in expressions in the convenience variable
10999 @code{$_}. The contents of that address, as examined, are available in
11000 the convenience variable @code{$__}.
11001
11002 If the @code{x} command has a repeat count, the address and contents saved
11003 are from the last memory unit printed; this is not the same as the last
11004 address printed if several units were printed on the last line of output.
11005
11006 @anchor{addressable memory unit}
11007 @cindex addressable memory unit
11008 Most targets have an addressable memory unit size of 8 bits. This means
11009 that to each memory address are associated 8 bits of data. Some
11010 targets, however, have other addressable memory unit sizes.
11011 Within @value{GDBN} and this document, the term
11012 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
11013 when explicitly referring to a chunk of data of that size. The word
11014 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
11015 the addressable memory unit size of the target. For most systems,
11016 addressable memory unit is a synonym of byte.
11017
11018 @cindex remote memory comparison
11019 @cindex target memory comparison
11020 @cindex verify remote memory image
11021 @cindex verify target memory image
11022 When you are debugging a program running on a remote target machine
11023 (@pxref{Remote Debugging}), you may wish to verify the program's image
11024 in the remote machine's memory against the executable file you
11025 downloaded to the target. Or, on any target, you may want to check
11026 whether the program has corrupted its own read-only sections. The
11027 @code{compare-sections} command is provided for such situations.
11028
11029 @table @code
11030 @kindex compare-sections
11031 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
11032 Compare the data of a loadable section @var{section-name} in the
11033 executable file of the program being debugged with the same section in
11034 the target machine's memory, and report any mismatches. With no
11035 arguments, compares all loadable sections. With an argument of
11036 @code{-r}, compares all loadable read-only sections.
11037
11038 Note: for remote targets, this command can be accelerated if the
11039 target supports computing the CRC checksum of a block of memory
11040 (@pxref{qCRC packet}).
11041 @end table
11042
11043 @node Memory Tagging
11044 @section Memory Tagging
11045
11046 Memory tagging is a memory protection technology that uses a pair of tags to
11047 validate memory accesses through pointers. The tags are integer values
11048 usually comprised of a few bits, depending on the architecture.
11049
11050 There are two types of tags that are used in this setup: logical and
11051 allocation. A logical tag is stored in the pointers themselves, usually at the
11052 higher bits of the pointers. An allocation tag is the tag associated
11053 with particular ranges of memory in the physical address space, against which
11054 the logical tags from pointers are compared.
11055
11056 The pointer tag (logical tag) must match the memory tag (allocation tag)
11057 for the memory access to be valid. If the logical tag does not match the
11058 allocation tag, that will raise a memory violation.
11059
11060 Allocation tags cover multiple contiguous bytes of physical memory. This
11061 range of bytes is called a memory tag granule and is architecture-specific.
11062 For example, AArch64 has a tag granule of 16 bytes, meaning each allocation
11063 tag spans 16 bytes of memory.
11064
11065 If the underlying architecture supports memory tagging, like AArch64 MTE
11066 or SPARC ADI do, @value{GDBN} can make use of it to validate pointers
11067 against memory allocation tags.
11068
11069 The @code{print} (@pxref{Data}) and @code{x} (@pxref{Memory}) commands will
11070 display tag information when appropriate, and a command prefix of
11071 @code{memory-tag} gives access to the various memory tagging commands.
11072
11073 The @code{memory-tag} commands are the following:
11074
11075 @table @code
11076 @kindex memory-tag print-logical-tag
11077 @item memory-tag print-logical-tag @var{pointer_expression}
11078 Print the logical tag stored in @var{pointer_expression}.
11079 @kindex memory-tag with-logical-tag
11080 @item memory-tag with-logical-tag @var{pointer_expression} @var{tag_bytes}
11081 Print the pointer given by @var{pointer_expression}, augmented with a logical
11082 tag of @var{tag_bytes}.
11083 @kindex memory-tag print-allocation-tag
11084 @item memory-tag print-allocation-tag @var{address_expression}
11085 Print the allocation tag associated with the memory address given by
11086 @var{address_expression}.
11087 @kindex memory-tag setatag
11088 @item memory-tag setatag @var{starting_address} @var{length} @var{tag_bytes}
11089 Set the allocation tag(s) for memory range @r{[}@var{starting_address},
11090 @var{starting_address} + @var{length}@r{)} to @var{tag_bytes}.
11091 @kindex memory-tag check
11092 @item memory-tag check @var{pointer_expression}
11093 Check if the logical tag in the pointer given by @var{pointer_expression}
11094 matches the allocation tag for the memory referenced by the pointer.
11095
11096 This essentially emulates the hardware validation that is done when tagged
11097 memory is accessed through a pointer, but does not cause a memory fault as
11098 it would during hardware validation.
11099
11100 It can be used to inspect potential memory tagging violations in the running
11101 process, before any faults get triggered.
11102 @end table
11103
11104 @node Auto Display
11105 @section Automatic Display
11106 @cindex automatic display
11107 @cindex display of expressions
11108
11109 If you find that you want to print the value of an expression frequently
11110 (to see how it changes), you might want to add it to the @dfn{automatic
11111 display list} so that @value{GDBN} prints its value each time your program stops.
11112 Each expression added to the list is given a number to identify it;
11113 to remove an expression from the list, you specify that number.
11114 The automatic display looks like this:
11115
11116 @smallexample
11117 2: foo = 38
11118 3: bar[5] = (struct hack *) 0x3804
11119 @end smallexample
11120
11121 @noindent
11122 This display shows item numbers, expressions and their current values. As with
11123 displays you request manually using @code{x} or @code{print}, you can
11124 specify the output format you prefer; in fact, @code{display} decides
11125 whether to use @code{print} or @code{x} depending your format
11126 specification---it uses @code{x} if you specify either the @samp{i}
11127 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
11128
11129 @table @code
11130 @kindex display
11131 @item display @var{expr}
11132 Add the expression @var{expr} to the list of expressions to display
11133 each time your program stops. @xref{Expressions, ,Expressions}.
11134
11135 @code{display} does not repeat if you press @key{RET} again after using it.
11136
11137 @item display/@var{fmt} @var{expr}
11138 For @var{fmt} specifying only a display format and not a size or
11139 count, add the expression @var{expr} to the auto-display list but
11140 arrange to display it each time in the specified format @var{fmt}.
11141 @xref{Output Formats,,Output Formats}.
11142
11143 @item display/@var{fmt} @var{addr}
11144 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
11145 number of units, add the expression @var{addr} as a memory address to
11146 be examined each time your program stops. Examining means in effect
11147 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
11148 @end table
11149
11150 For example, @samp{display/i $pc} can be helpful, to see the machine
11151 instruction about to be executed each time execution stops (@samp{$pc}
11152 is a common name for the program counter; @pxref{Registers, ,Registers}).
11153
11154 @table @code
11155 @kindex delete display
11156 @kindex undisplay
11157 @item undisplay @var{dnums}@dots{}
11158 @itemx delete display @var{dnums}@dots{}
11159 Remove items from the list of expressions to display. Specify the
11160 numbers of the displays that you want affected with the command
11161 argument @var{dnums}. It can be a single display number, one of the
11162 numbers shown in the first field of the @samp{info display} display;
11163 or it could be a range of display numbers, as in @code{2-4}.
11164
11165 @code{undisplay} does not repeat if you press @key{RET} after using it.
11166 (Otherwise you would just get the error @samp{No display number @dots{}}.)
11167
11168 @kindex disable display
11169 @item disable display @var{dnums}@dots{}
11170 Disable the display of item numbers @var{dnums}. A disabled display
11171 item is not printed automatically, but is not forgotten. It may be
11172 enabled again later. Specify the numbers of the displays that you
11173 want affected with the command argument @var{dnums}. It can be a
11174 single display number, one of the numbers shown in the first field of
11175 the @samp{info display} display; or it could be a range of display
11176 numbers, as in @code{2-4}.
11177
11178 @kindex enable display
11179 @item enable display @var{dnums}@dots{}
11180 Enable display of item numbers @var{dnums}. It becomes effective once
11181 again in auto display of its expression, until you specify otherwise.
11182 Specify the numbers of the displays that you want affected with the
11183 command argument @var{dnums}. It can be a single display number, one
11184 of the numbers shown in the first field of the @samp{info display}
11185 display; or it could be a range of display numbers, as in @code{2-4}.
11186
11187 @item display
11188 Display the current values of the expressions on the list, just as is
11189 done when your program stops.
11190
11191 @kindex info display
11192 @item info display
11193 Print the list of expressions previously set up to display
11194 automatically, each one with its item number, but without showing the
11195 values. This includes disabled expressions, which are marked as such.
11196 It also includes expressions which would not be displayed right now
11197 because they refer to automatic variables not currently available.
11198 @end table
11199
11200 @cindex display disabled out of scope
11201 If a display expression refers to local variables, then it does not make
11202 sense outside the lexical context for which it was set up. Such an
11203 expression is disabled when execution enters a context where one of its
11204 variables is not defined. For example, if you give the command
11205 @code{display last_char} while inside a function with an argument
11206 @code{last_char}, @value{GDBN} displays this argument while your program
11207 continues to stop inside that function. When it stops elsewhere---where
11208 there is no variable @code{last_char}---the display is disabled
11209 automatically. The next time your program stops where @code{last_char}
11210 is meaningful, you can enable the display expression once again.
11211
11212 @node Print Settings
11213 @section Print Settings
11214
11215 @cindex format options
11216 @cindex print settings
11217 @value{GDBN} provides the following ways to control how arrays, structures,
11218 and symbols are printed.
11219
11220 @noindent
11221 These settings are useful for debugging programs in any language:
11222
11223 @table @code
11224 @kindex set print
11225 @anchor{set print address}
11226 @item set print address
11227 @itemx set print address on
11228 @cindex print/don't print memory addresses
11229 @value{GDBN} prints memory addresses showing the location of stack
11230 traces, structure values, pointer values, breakpoints, and so forth,
11231 even when it also displays the contents of those addresses. The default
11232 is @code{on}. For example, this is what a stack frame display looks like with
11233 @code{set print address on}:
11234
11235 @smallexample
11236 @group
11237 (@value{GDBP}) f
11238 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11239 at input.c:530
11240 530 if (lquote != def_lquote)
11241 @end group
11242 @end smallexample
11243
11244 @item set print address off
11245 Do not print addresses when displaying their contents. For example,
11246 this is the same stack frame displayed with @code{set print address off}:
11247
11248 @smallexample
11249 @group
11250 (@value{GDBP}) set print addr off
11251 (@value{GDBP}) f
11252 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11253 530 if (lquote != def_lquote)
11254 @end group
11255 @end smallexample
11256
11257 You can use @samp{set print address off} to eliminate all machine
11258 dependent displays from the @value{GDBN} interface. For example, with
11259 @code{print address off}, you should get the same text for backtraces on
11260 all machines---whether or not they involve pointer arguments.
11261
11262 @kindex show print
11263 @item show print address
11264 Show whether or not addresses are to be printed.
11265 @end table
11266
11267 When @value{GDBN} prints a symbolic address, it normally prints the
11268 closest earlier symbol plus an offset. If that symbol does not uniquely
11269 identify the address (for example, it is a name whose scope is a single
11270 source file), you may need to clarify. One way to do this is with
11271 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11272 you can set @value{GDBN} to print the source file and line number when
11273 it prints a symbolic address:
11274
11275 @table @code
11276 @item set print symbol-filename on
11277 @cindex source file and line of a symbol
11278 @cindex symbol, source file and line
11279 Tell @value{GDBN} to print the source file name and line number of a
11280 symbol in the symbolic form of an address.
11281
11282 @item set print symbol-filename off
11283 Do not print source file name and line number of a symbol. This is the
11284 default.
11285
11286 @item show print symbol-filename
11287 Show whether or not @value{GDBN} will print the source file name and
11288 line number of a symbol in the symbolic form of an address.
11289 @end table
11290
11291 Another situation where it is helpful to show symbol filenames and line
11292 numbers is when disassembling code; @value{GDBN} shows you the line
11293 number and source file that corresponds to each instruction.
11294
11295 Also, you may wish to see the symbolic form only if the address being
11296 printed is reasonably close to the closest earlier symbol:
11297
11298 @table @code
11299 @item set print max-symbolic-offset @var{max-offset}
11300 @itemx set print max-symbolic-offset unlimited
11301 @cindex maximum value for offset of closest symbol
11302 Tell @value{GDBN} to only display the symbolic form of an address if the
11303 offset between the closest earlier symbol and the address is less than
11304 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11305 to always print the symbolic form of an address if any symbol precedes
11306 it. Zero is equivalent to @code{unlimited}.
11307
11308 @item show print max-symbolic-offset
11309 Ask how large the maximum offset is that @value{GDBN} prints in a
11310 symbolic address.
11311 @end table
11312
11313 @cindex wild pointer, interpreting
11314 @cindex pointer, finding referent
11315 If you have a pointer and you are not sure where it points, try
11316 @samp{set print symbol-filename on}. Then you can determine the name
11317 and source file location of the variable where it points, using
11318 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11319 For example, here @value{GDBN} shows that a variable @code{ptt} points
11320 at another variable @code{t}, defined in @file{hi2.c}:
11321
11322 @smallexample
11323 (@value{GDBP}) set print symbol-filename on
11324 (@value{GDBP}) p/a ptt
11325 $4 = 0xe008 <t in hi2.c>
11326 @end smallexample
11327
11328 @quotation
11329 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11330 does not show the symbol name and filename of the referent, even with
11331 the appropriate @code{set print} options turned on.
11332 @end quotation
11333
11334 You can also enable @samp{/a}-like formatting all the time using
11335 @samp{set print symbol on}:
11336
11337 @anchor{set print symbol}
11338 @table @code
11339 @item set print symbol on
11340 Tell @value{GDBN} to print the symbol corresponding to an address, if
11341 one exists.
11342
11343 @item set print symbol off
11344 Tell @value{GDBN} not to print the symbol corresponding to an
11345 address. In this mode, @value{GDBN} will still print the symbol
11346 corresponding to pointers to functions. This is the default.
11347
11348 @item show print symbol
11349 Show whether @value{GDBN} will display the symbol corresponding to an
11350 address.
11351 @end table
11352
11353 Other settings control how different kinds of objects are printed:
11354
11355 @table @code
11356 @anchor{set print array}
11357 @item set print array
11358 @itemx set print array on
11359 @cindex pretty print arrays
11360 Pretty print arrays. This format is more convenient to read,
11361 but uses more space. The default is off.
11362
11363 @item set print array off
11364 Return to compressed format for arrays.
11365
11366 @item show print array
11367 Show whether compressed or pretty format is selected for displaying
11368 arrays.
11369
11370 @cindex print array indexes
11371 @anchor{set print array-indexes}
11372 @item set print array-indexes
11373 @itemx set print array-indexes on
11374 Print the index of each element when displaying arrays. May be more
11375 convenient to locate a given element in the array or quickly find the
11376 index of a given element in that printed array. The default is off.
11377
11378 @item set print array-indexes off
11379 Stop printing element indexes when displaying arrays.
11380
11381 @item show print array-indexes
11382 Show whether the index of each element is printed when displaying
11383 arrays.
11384
11385 @anchor{set print elements}
11386 @item set print elements @var{number-of-elements}
11387 @itemx set print elements unlimited
11388 @cindex number of array elements to print
11389 @cindex limit on number of printed array elements
11390 Set a limit on how many elements of an array @value{GDBN} will print.
11391 If @value{GDBN} is printing a large array, it stops printing after it has
11392 printed the number of elements set by the @code{set print elements} command.
11393 This limit also applies to the display of strings.
11394 When @value{GDBN} starts, this limit is set to 200.
11395 Setting @var{number-of-elements} to @code{unlimited} or zero means
11396 that the number of elements to print is unlimited.
11397
11398 @item show print elements
11399 Display the number of elements of a large array that @value{GDBN} will print.
11400
11401 @anchor{set print frame-arguments}
11402 @item set print frame-arguments @var{value}
11403 @kindex set print frame-arguments
11404 @cindex printing frame argument values
11405 @cindex print all frame argument values
11406 @cindex print frame argument values for scalars only
11407 @cindex do not print frame arguments
11408 This command allows to control how the values of arguments are printed
11409 when the debugger prints a frame (@pxref{Frames}). The possible
11410 values are:
11411
11412 @table @code
11413 @item all
11414 The values of all arguments are printed.
11415
11416 @item scalars
11417 Print the value of an argument only if it is a scalar. The value of more
11418 complex arguments such as arrays, structures, unions, etc, is replaced
11419 by @code{@dots{}}. This is the default. Here is an example where
11420 only scalar arguments are shown:
11421
11422 @smallexample
11423 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11424 at frame-args.c:23
11425 @end smallexample
11426
11427 @item none
11428 None of the argument values are printed. Instead, the value of each argument
11429 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11430
11431 @smallexample
11432 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11433 at frame-args.c:23
11434 @end smallexample
11435
11436 @item presence
11437 Only the presence of arguments is indicated by @code{@dots{}}.
11438 The @code{@dots{}} are not printed for function without any arguments.
11439 None of the argument names and values are printed.
11440 In this case, the example above now becomes:
11441
11442 @smallexample
11443 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11444 @end smallexample
11445
11446 @end table
11447
11448 By default, only scalar arguments are printed. This command can be used
11449 to configure the debugger to print the value of all arguments, regardless
11450 of their type. However, it is often advantageous to not print the value
11451 of more complex parameters. For instance, it reduces the amount of
11452 information printed in each frame, making the backtrace more readable.
11453 Also, it improves performance when displaying Ada frames, because
11454 the computation of large arguments can sometimes be CPU-intensive,
11455 especially in large applications. Setting @code{print frame-arguments}
11456 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11457 this computation, thus speeding up the display of each Ada frame.
11458
11459 @item show print frame-arguments
11460 Show how the value of arguments should be displayed when printing a frame.
11461
11462 @anchor{set print raw-frame-arguments}
11463 @item set print raw-frame-arguments on
11464 Print frame arguments in raw, non pretty-printed, form.
11465
11466 @item set print raw-frame-arguments off
11467 Print frame arguments in pretty-printed form, if there is a pretty-printer
11468 for the value (@pxref{Pretty Printing}),
11469 otherwise print the value in raw form.
11470 This is the default.
11471
11472 @item show print raw-frame-arguments
11473 Show whether to print frame arguments in raw form.
11474
11475 @anchor{set print entry-values}
11476 @item set print entry-values @var{value}
11477 @kindex set print entry-values
11478 Set printing of frame argument values at function entry. In some cases
11479 @value{GDBN} can determine the value of function argument which was passed by
11480 the function caller, even if the value was modified inside the called function
11481 and therefore is different. With optimized code, the current value could be
11482 unavailable, but the entry value may still be known.
11483
11484 The default value is @code{default} (see below for its description). Older
11485 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11486 this feature will behave in the @code{default} setting the same way as with the
11487 @code{no} setting.
11488
11489 This functionality is currently supported only by DWARF 2 debugging format and
11490 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11491 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11492 this information.
11493
11494 The @var{value} parameter can be one of the following:
11495
11496 @table @code
11497 @item no
11498 Print only actual parameter values, never print values from function entry
11499 point.
11500 @smallexample
11501 #0 equal (val=5)
11502 #0 different (val=6)
11503 #0 lost (val=<optimized out>)
11504 #0 born (val=10)
11505 #0 invalid (val=<optimized out>)
11506 @end smallexample
11507
11508 @item only
11509 Print only parameter values from function entry point. The actual parameter
11510 values are never printed.
11511 @smallexample
11512 #0 equal (val@@entry=5)
11513 #0 different (val@@entry=5)
11514 #0 lost (val@@entry=5)
11515 #0 born (val@@entry=<optimized out>)
11516 #0 invalid (val@@entry=<optimized out>)
11517 @end smallexample
11518
11519 @item preferred
11520 Print only parameter values from function entry point. If value from function
11521 entry point is not known while the actual value is known, print the actual
11522 value for such parameter.
11523 @smallexample
11524 #0 equal (val@@entry=5)
11525 #0 different (val@@entry=5)
11526 #0 lost (val@@entry=5)
11527 #0 born (val=10)
11528 #0 invalid (val@@entry=<optimized out>)
11529 @end smallexample
11530
11531 @item if-needed
11532 Print actual parameter values. If actual parameter value is not known while
11533 value from function entry point is known, print the entry point value for such
11534 parameter.
11535 @smallexample
11536 #0 equal (val=5)
11537 #0 different (val=6)
11538 #0 lost (val@@entry=5)
11539 #0 born (val=10)
11540 #0 invalid (val=<optimized out>)
11541 @end smallexample
11542
11543 @item both
11544 Always print both the actual parameter value and its value from function entry
11545 point, even if values of one or both are not available due to compiler
11546 optimizations.
11547 @smallexample
11548 #0 equal (val=5, val@@entry=5)
11549 #0 different (val=6, val@@entry=5)
11550 #0 lost (val=<optimized out>, val@@entry=5)
11551 #0 born (val=10, val@@entry=<optimized out>)
11552 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11553 @end smallexample
11554
11555 @item compact
11556 Print the actual parameter value if it is known and also its value from
11557 function entry point if it is known. If neither is known, print for the actual
11558 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11559 values are known and identical, print the shortened
11560 @code{param=param@@entry=VALUE} notation.
11561 @smallexample
11562 #0 equal (val=val@@entry=5)
11563 #0 different (val=6, val@@entry=5)
11564 #0 lost (val@@entry=5)
11565 #0 born (val=10)
11566 #0 invalid (val=<optimized out>)
11567 @end smallexample
11568
11569 @item default
11570 Always print the actual parameter value. Print also its value from function
11571 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11572 if both values are known and identical, print the shortened
11573 @code{param=param@@entry=VALUE} notation.
11574 @smallexample
11575 #0 equal (val=val@@entry=5)
11576 #0 different (val=6, val@@entry=5)
11577 #0 lost (val=<optimized out>, val@@entry=5)
11578 #0 born (val=10)
11579 #0 invalid (val=<optimized out>)
11580 @end smallexample
11581 @end table
11582
11583 For analysis messages on possible failures of frame argument values at function
11584 entry resolution see @ref{set debug entry-values}.
11585
11586 @item show print entry-values
11587 Show the method being used for printing of frame argument values at function
11588 entry.
11589
11590 @anchor{set print frame-info}
11591 @item set print frame-info @var{value}
11592 @kindex set print frame-info
11593 @cindex printing frame information
11594 @cindex frame information, printing
11595 This command allows to control the information printed when
11596 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11597 for a general explanation about frames and frame information.
11598 Note that some other settings (such as @code{set print frame-arguments}
11599 and @code{set print address}) are also influencing if and how some frame
11600 information is displayed. In particular, the frame program counter is never
11601 printed if @code{set print address} is off.
11602
11603 The possible values for @code{set print frame-info} are:
11604 @table @code
11605 @item short-location
11606 Print the frame level, the program counter (if not at the
11607 beginning of the location source line), the function, the function
11608 arguments.
11609 @item location
11610 Same as @code{short-location} but also print the source file and source line
11611 number.
11612 @item location-and-address
11613 Same as @code{location} but print the program counter even if located at the
11614 beginning of the location source line.
11615 @item source-line
11616 Print the program counter (if not at the beginning of the location
11617 source line), the line number and the source line.
11618 @item source-and-location
11619 Print what @code{location} and @code{source-line} are printing.
11620 @item auto
11621 The information printed for a frame is decided automatically
11622 by the @value{GDBN} command that prints a frame.
11623 For example, @code{frame} prints the information printed by
11624 @code{source-and-location} while @code{stepi} will switch between
11625 @code{source-line} and @code{source-and-location} depending on the program
11626 counter.
11627 The default value is @code{auto}.
11628 @end table
11629
11630 @anchor{set print repeats}
11631 @item set print repeats @var{number-of-repeats}
11632 @itemx set print repeats unlimited
11633 @cindex repeated array elements
11634 Set the threshold for suppressing display of repeated array
11635 elements. When the number of consecutive identical elements of an
11636 array exceeds the threshold, @value{GDBN} prints the string
11637 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11638 identical repetitions, instead of displaying the identical elements
11639 themselves. Setting the threshold to @code{unlimited} or zero will
11640 cause all elements to be individually printed. The default threshold
11641 is 10.
11642
11643 @item show print repeats
11644 Display the current threshold for printing repeated identical
11645 elements.
11646
11647 @anchor{set print max-depth}
11648 @item set print max-depth @var{depth}
11649 @item set print max-depth unlimited
11650 @cindex printing nested structures
11651 Set the threshold after which nested structures are replaced with
11652 ellipsis, this can make visualising deeply nested structures easier.
11653
11654 For example, given this C code
11655
11656 @smallexample
11657 typedef struct s1 @{ int a; @} s1;
11658 typedef struct s2 @{ s1 b; @} s2;
11659 typedef struct s3 @{ s2 c; @} s3;
11660 typedef struct s4 @{ s3 d; @} s4;
11661
11662 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11663 @end smallexample
11664
11665 The following table shows how different values of @var{depth} will
11666 effect how @code{var} is printed by @value{GDBN}:
11667
11668 @multitable @columnfractions .3 .7
11669 @headitem @var{depth} setting @tab Result of @samp{p var}
11670 @item unlimited
11671 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11672 @item @code{0}
11673 @tab @code{$1 = @{...@}}
11674 @item @code{1}
11675 @tab @code{$1 = @{d = @{...@}@}}
11676 @item @code{2}
11677 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11678 @item @code{3}
11679 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11680 @item @code{4}
11681 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11682 @end multitable
11683
11684 To see the contents of structures that have been hidden the user can
11685 either increase the print max-depth, or they can print the elements of
11686 the structure that are visible, for example
11687
11688 @smallexample
11689 (gdb) set print max-depth 2
11690 (gdb) p var
11691 $1 = @{d = @{c = @{...@}@}@}
11692 (gdb) p var.d
11693 $2 = @{c = @{b = @{...@}@}@}
11694 (gdb) p var.d.c
11695 $3 = @{b = @{a = 3@}@}
11696 @end smallexample
11697
11698 The pattern used to replace nested structures varies based on
11699 language, for most languages @code{@{...@}} is used, but Fortran uses
11700 @code{(...)}.
11701
11702 @item show print max-depth
11703 Display the current threshold after which nested structures are
11704 replaces with ellipsis.
11705
11706 @anchor{set print memory-tag-violations}
11707 @cindex printing memory tag violation information
11708 @item set print memory-tag-violations
11709 @itemx set print memory-tag-violations on
11710 Cause @value{GDBN} to display additional information about memory tag violations
11711 when printing pointers and addresses.
11712
11713 @item set print memory-tag-violations off
11714 Stop printing memory tag violation information.
11715
11716 @item show print memory-tag-violations
11717 Show whether memory tag violation information is displayed when printing
11718 pointers and addresses.
11719
11720 @anchor{set print null-stop}
11721 @item set print null-stop
11722 @cindex @sc{null} elements in arrays
11723 Cause @value{GDBN} to stop printing the characters of an array when the first
11724 @sc{null} is encountered. This is useful when large arrays actually
11725 contain only short strings.
11726 The default is off.
11727
11728 @item show print null-stop
11729 Show whether @value{GDBN} stops printing an array on the first
11730 @sc{null} character.
11731
11732 @anchor{set print pretty}
11733 @item set print pretty on
11734 @cindex print structures in indented form
11735 @cindex indentation in structure display
11736 Cause @value{GDBN} to print structures in an indented format with one member
11737 per line, like this:
11738
11739 @smallexample
11740 @group
11741 $1 = @{
11742 next = 0x0,
11743 flags = @{
11744 sweet = 1,
11745 sour = 1
11746 @},
11747 meat = 0x54 "Pork"
11748 @}
11749 @end group
11750 @end smallexample
11751
11752 @item set print pretty off
11753 Cause @value{GDBN} to print structures in a compact format, like this:
11754
11755 @smallexample
11756 @group
11757 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11758 meat = 0x54 "Pork"@}
11759 @end group
11760 @end smallexample
11761
11762 @noindent
11763 This is the default format.
11764
11765 @item show print pretty
11766 Show which format @value{GDBN} is using to print structures.
11767
11768 @anchor{set print raw-values}
11769 @item set print raw-values on
11770 Print values in raw form, without applying the pretty
11771 printers for the value.
11772
11773 @item set print raw-values off
11774 Print values in pretty-printed form, if there is a pretty-printer
11775 for the value (@pxref{Pretty Printing}),
11776 otherwise print the value in raw form.
11777
11778 The default setting is ``off''.
11779
11780 @item show print raw-values
11781 Show whether to print values in raw form.
11782
11783 @item set print sevenbit-strings on
11784 @cindex eight-bit characters in strings
11785 @cindex octal escapes in strings
11786 Print using only seven-bit characters; if this option is set,
11787 @value{GDBN} displays any eight-bit characters (in strings or
11788 character values) using the notation @code{\}@var{nnn}. This setting is
11789 best if you are working in English (@sc{ascii}) and you use the
11790 high-order bit of characters as a marker or ``meta'' bit.
11791
11792 @item set print sevenbit-strings off
11793 Print full eight-bit characters. This allows the use of more
11794 international character sets, and is the default.
11795
11796 @item show print sevenbit-strings
11797 Show whether or not @value{GDBN} is printing only seven-bit characters.
11798
11799 @anchor{set print union}
11800 @item set print union on
11801 @cindex unions in structures, printing
11802 Tell @value{GDBN} to print unions which are contained in structures
11803 and other unions. This is the default setting.
11804
11805 @item set print union off
11806 Tell @value{GDBN} not to print unions which are contained in
11807 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11808 instead.
11809
11810 @item show print union
11811 Ask @value{GDBN} whether or not it will print unions which are contained in
11812 structures and other unions.
11813
11814 For example, given the declarations
11815
11816 @smallexample
11817 typedef enum @{Tree, Bug@} Species;
11818 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11819 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11820 Bug_forms;
11821
11822 struct thing @{
11823 Species it;
11824 union @{
11825 Tree_forms tree;
11826 Bug_forms bug;
11827 @} form;
11828 @};
11829
11830 struct thing foo = @{Tree, @{Acorn@}@};
11831 @end smallexample
11832
11833 @noindent
11834 with @code{set print union on} in effect @samp{p foo} would print
11835
11836 @smallexample
11837 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11838 @end smallexample
11839
11840 @noindent
11841 and with @code{set print union off} in effect it would print
11842
11843 @smallexample
11844 $1 = @{it = Tree, form = @{...@}@}
11845 @end smallexample
11846
11847 @noindent
11848 @code{set print union} affects programs written in C-like languages
11849 and in Pascal.
11850 @end table
11851
11852 @need 1000
11853 @noindent
11854 These settings are of interest when debugging C@t{++} programs:
11855
11856 @table @code
11857 @cindex demangling C@t{++} names
11858 @item set print demangle
11859 @itemx set print demangle on
11860 Print C@t{++} names in their source form rather than in the encoded
11861 (``mangled'') form passed to the assembler and linker for type-safe
11862 linkage. The default is on.
11863
11864 @item show print demangle
11865 Show whether C@t{++} names are printed in mangled or demangled form.
11866
11867 @item set print asm-demangle
11868 @itemx set print asm-demangle on
11869 Print C@t{++} names in their source form rather than their mangled form, even
11870 in assembler code printouts such as instruction disassemblies.
11871 The default is off.
11872
11873 @item show print asm-demangle
11874 Show whether C@t{++} names in assembly listings are printed in mangled
11875 or demangled form.
11876
11877 @cindex C@t{++} symbol decoding style
11878 @cindex symbol decoding style, C@t{++}
11879 @kindex set demangle-style
11880 @item set demangle-style @var{style}
11881 Choose among several encoding schemes used by different compilers to represent
11882 C@t{++} names. If you omit @var{style}, you will see a list of possible
11883 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11884 decoding style by inspecting your program.
11885
11886 @item show demangle-style
11887 Display the encoding style currently in use for decoding C@t{++} symbols.
11888
11889 @anchor{set print object}
11890 @item set print object
11891 @itemx set print object on
11892 @cindex derived type of an object, printing
11893 @cindex display derived types
11894 When displaying a pointer to an object, identify the @emph{actual}
11895 (derived) type of the object rather than the @emph{declared} type, using
11896 the virtual function table. Note that the virtual function table is
11897 required---this feature can only work for objects that have run-time
11898 type identification; a single virtual method in the object's declared
11899 type is sufficient. Note that this setting is also taken into account when
11900 working with variable objects via MI (@pxref{GDB/MI}).
11901
11902 @item set print object off
11903 Display only the declared type of objects, without reference to the
11904 virtual function table. This is the default setting.
11905
11906 @item show print object
11907 Show whether actual, or declared, object types are displayed.
11908
11909 @anchor{set print static-members}
11910 @item set print static-members
11911 @itemx set print static-members on
11912 @cindex static members of C@t{++} objects
11913 Print static members when displaying a C@t{++} object. The default is on.
11914
11915 @item set print static-members off
11916 Do not print static members when displaying a C@t{++} object.
11917
11918 @item show print static-members
11919 Show whether C@t{++} static members are printed or not.
11920
11921 @item set print pascal_static-members
11922 @itemx set print pascal_static-members on
11923 @cindex static members of Pascal objects
11924 @cindex Pascal objects, static members display
11925 Print static members when displaying a Pascal object. The default is on.
11926
11927 @item set print pascal_static-members off
11928 Do not print static members when displaying a Pascal object.
11929
11930 @item show print pascal_static-members
11931 Show whether Pascal static members are printed or not.
11932
11933 @c These don't work with HP ANSI C++ yet.
11934 @anchor{set print vtbl}
11935 @item set print vtbl
11936 @itemx set print vtbl on
11937 @cindex pretty print C@t{++} virtual function tables
11938 @cindex virtual functions (C@t{++}) display
11939 @cindex VTBL display
11940 Pretty print C@t{++} virtual function tables. The default is off.
11941 (The @code{vtbl} commands do not work on programs compiled with the HP
11942 ANSI C@t{++} compiler (@code{aCC}).)
11943
11944 @item set print vtbl off
11945 Do not pretty print C@t{++} virtual function tables.
11946
11947 @item show print vtbl
11948 Show whether C@t{++} virtual function tables are pretty printed, or not.
11949 @end table
11950
11951 @node Pretty Printing
11952 @section Pretty Printing
11953
11954 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11955 Python code. It greatly simplifies the display of complex objects. This
11956 mechanism works for both MI and the CLI.
11957
11958 @menu
11959 * Pretty-Printer Introduction:: Introduction to pretty-printers
11960 * Pretty-Printer Example:: An example pretty-printer
11961 * Pretty-Printer Commands:: Pretty-printer commands
11962 @end menu
11963
11964 @node Pretty-Printer Introduction
11965 @subsection Pretty-Printer Introduction
11966
11967 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11968 registered for the value. If there is then @value{GDBN} invokes the
11969 pretty-printer to print the value. Otherwise the value is printed normally.
11970
11971 Pretty-printers are normally named. This makes them easy to manage.
11972 The @samp{info pretty-printer} command will list all the installed
11973 pretty-printers with their names.
11974 If a pretty-printer can handle multiple data types, then its
11975 @dfn{subprinters} are the printers for the individual data types.
11976 Each such subprinter has its own name.
11977 The format of the name is @var{printer-name};@var{subprinter-name}.
11978
11979 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11980 Typically they are automatically loaded and registered when the corresponding
11981 debug information is loaded, thus making them available without having to
11982 do anything special.
11983
11984 There are three places where a pretty-printer can be registered.
11985
11986 @itemize @bullet
11987 @item
11988 Pretty-printers registered globally are available when debugging
11989 all inferiors.
11990
11991 @item
11992 Pretty-printers registered with a program space are available only
11993 when debugging that program.
11994 @xref{Progspaces In Python}, for more details on program spaces in Python.
11995
11996 @item
11997 Pretty-printers registered with an objfile are loaded and unloaded
11998 with the corresponding objfile (e.g., shared library).
11999 @xref{Objfiles In Python}, for more details on objfiles in Python.
12000 @end itemize
12001
12002 @xref{Selecting Pretty-Printers}, for further information on how
12003 pretty-printers are selected,
12004
12005 @xref{Writing a Pretty-Printer}, for implementing pretty printers
12006 for new types.
12007
12008 @node Pretty-Printer Example
12009 @subsection Pretty-Printer Example
12010
12011 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
12012
12013 @smallexample
12014 (@value{GDBP}) print s
12015 $1 = @{
12016 static npos = 4294967295,
12017 _M_dataplus = @{
12018 <std::allocator<char>> = @{
12019 <__gnu_cxx::new_allocator<char>> = @{
12020 <No data fields>@}, <No data fields>
12021 @},
12022 members of std::basic_string<char, std::char_traits<char>,
12023 std::allocator<char> >::_Alloc_hider:
12024 _M_p = 0x804a014 "abcd"
12025 @}
12026 @}
12027 @end smallexample
12028
12029 With a pretty-printer for @code{std::string} only the contents are printed:
12030
12031 @smallexample
12032 (@value{GDBP}) print s
12033 $2 = "abcd"
12034 @end smallexample
12035
12036 @node Pretty-Printer Commands
12037 @subsection Pretty-Printer Commands
12038 @cindex pretty-printer commands
12039
12040 @table @code
12041 @kindex info pretty-printer
12042 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12043 Print the list of installed pretty-printers.
12044 This includes disabled pretty-printers, which are marked as such.
12045
12046 @var{object-regexp} is a regular expression matching the objects
12047 whose pretty-printers to list.
12048 Objects can be @code{global}, the program space's file
12049 (@pxref{Progspaces In Python}),
12050 and the object files within that program space (@pxref{Objfiles In Python}).
12051 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
12052 looks up a printer from these three objects.
12053
12054 @var{name-regexp} is a regular expression matching the name of the printers
12055 to list.
12056
12057 @kindex disable pretty-printer
12058 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12059 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12060 A disabled pretty-printer is not forgotten, it may be enabled again later.
12061
12062 @kindex enable pretty-printer
12063 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12064 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12065 @end table
12066
12067 Example:
12068
12069 Suppose we have three pretty-printers installed: one from library1.so
12070 named @code{foo} that prints objects of type @code{foo}, and
12071 another from library2.so named @code{bar} that prints two types of objects,
12072 @code{bar1} and @code{bar2}.
12073
12074 @smallexample
12075 (gdb) info pretty-printer
12076 library1.so:
12077 foo
12078 library2.so:
12079 bar
12080 bar1
12081 bar2
12082 (gdb) info pretty-printer library2
12083 library2.so:
12084 bar
12085 bar1
12086 bar2
12087 (gdb) disable pretty-printer library1
12088 1 printer disabled
12089 2 of 3 printers enabled
12090 (gdb) info pretty-printer
12091 library1.so:
12092 foo [disabled]
12093 library2.so:
12094 bar
12095 bar1
12096 bar2
12097 (gdb) disable pretty-printer library2 bar;bar1
12098 1 printer disabled
12099 1 of 3 printers enabled
12100 (gdb) info pretty-printer library2
12101 library1.so:
12102 foo [disabled]
12103 library2.so:
12104 bar
12105 bar1 [disabled]
12106 bar2
12107 (gdb) disable pretty-printer library2 bar
12108 1 printer disabled
12109 0 of 3 printers enabled
12110 (gdb) info pretty-printer library2
12111 library1.so:
12112 foo [disabled]
12113 library2.so:
12114 bar [disabled]
12115 bar1 [disabled]
12116 bar2
12117 @end smallexample
12118
12119 Note that for @code{bar} the entire printer can be disabled,
12120 as can each individual subprinter.
12121
12122 Printing values and frame arguments is done by default using
12123 the enabled pretty printers.
12124
12125 The print option @code{-raw-values} and @value{GDBN} setting
12126 @code{set print raw-values} (@pxref{set print raw-values}) can be
12127 used to print values without applying the enabled pretty printers.
12128
12129 Similarly, the backtrace option @code{-raw-frame-arguments} and
12130 @value{GDBN} setting @code{set print raw-frame-arguments}
12131 (@pxref{set print raw-frame-arguments}) can be used to ignore the
12132 enabled pretty printers when printing frame argument values.
12133
12134 @node Value History
12135 @section Value History
12136
12137 @cindex value history
12138 @cindex history of values printed by @value{GDBN}
12139 Values printed by the @code{print} command are saved in the @value{GDBN}
12140 @dfn{value history}. This allows you to refer to them in other expressions.
12141 Values are kept until the symbol table is re-read or discarded
12142 (for example with the @code{file} or @code{symbol-file} commands).
12143 When the symbol table changes, the value history is discarded,
12144 since the values may contain pointers back to the types defined in the
12145 symbol table.
12146
12147 @cindex @code{$}
12148 @cindex @code{$$}
12149 @cindex history number
12150 The values printed are given @dfn{history numbers} by which you can
12151 refer to them. These are successive integers starting with one.
12152 @code{print} shows you the history number assigned to a value by
12153 printing @samp{$@var{num} = } before the value; here @var{num} is the
12154 history number.
12155
12156 To refer to any previous value, use @samp{$} followed by the value's
12157 history number. The way @code{print} labels its output is designed to
12158 remind you of this. Just @code{$} refers to the most recent value in
12159 the history, and @code{$$} refers to the value before that.
12160 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
12161 is the value just prior to @code{$$}, @code{$$1} is equivalent to
12162 @code{$$}, and @code{$$0} is equivalent to @code{$}.
12163
12164 For example, suppose you have just printed a pointer to a structure and
12165 want to see the contents of the structure. It suffices to type
12166
12167 @smallexample
12168 p *$
12169 @end smallexample
12170
12171 If you have a chain of structures where the component @code{next} points
12172 to the next one, you can print the contents of the next one with this:
12173
12174 @smallexample
12175 p *$.next
12176 @end smallexample
12177
12178 @noindent
12179 You can print successive links in the chain by repeating this
12180 command---which you can do by just typing @key{RET}.
12181
12182 Note that the history records values, not expressions. If the value of
12183 @code{x} is 4 and you type these commands:
12184
12185 @smallexample
12186 print x
12187 set x=5
12188 @end smallexample
12189
12190 @noindent
12191 then the value recorded in the value history by the @code{print} command
12192 remains 4 even though the value of @code{x} has changed.
12193
12194 @table @code
12195 @kindex show values
12196 @item show values
12197 Print the last ten values in the value history, with their item numbers.
12198 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12199 values} does not change the history.
12200
12201 @item show values @var{n}
12202 Print ten history values centered on history item number @var{n}.
12203
12204 @item show values +
12205 Print ten history values just after the values last printed. If no more
12206 values are available, @code{show values +} produces no display.
12207 @end table
12208
12209 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12210 same effect as @samp{show values +}.
12211
12212 @node Convenience Vars
12213 @section Convenience Variables
12214
12215 @cindex convenience variables
12216 @cindex user-defined variables
12217 @value{GDBN} provides @dfn{convenience variables} that you can use within
12218 @value{GDBN} to hold on to a value and refer to it later. These variables
12219 exist entirely within @value{GDBN}; they are not part of your program, and
12220 setting a convenience variable has no direct effect on further execution
12221 of your program. That is why you can use them freely.
12222
12223 Convenience variables are prefixed with @samp{$}. Any name preceded by
12224 @samp{$} can be used for a convenience variable, unless it is one of
12225 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12226 (Value history references, in contrast, are @emph{numbers} preceded
12227 by @samp{$}. @xref{Value History, ,Value History}.)
12228
12229 You can save a value in a convenience variable with an assignment
12230 expression, just as you would set a variable in your program.
12231 For example:
12232
12233 @smallexample
12234 set $foo = *object_ptr
12235 @end smallexample
12236
12237 @noindent
12238 would save in @code{$foo} the value contained in the object pointed to by
12239 @code{object_ptr}.
12240
12241 Using a convenience variable for the first time creates it, but its
12242 value is @code{void} until you assign a new value. You can alter the
12243 value with another assignment at any time.
12244
12245 Convenience variables have no fixed types. You can assign a convenience
12246 variable any type of value, including structures and arrays, even if
12247 that variable already has a value of a different type. The convenience
12248 variable, when used as an expression, has the type of its current value.
12249
12250 @table @code
12251 @kindex show convenience
12252 @cindex show all user variables and functions
12253 @item show convenience
12254 Print a list of convenience variables used so far, and their values,
12255 as well as a list of the convenience functions.
12256 Abbreviated @code{show conv}.
12257
12258 @kindex init-if-undefined
12259 @cindex convenience variables, initializing
12260 @item init-if-undefined $@var{variable} = @var{expression}
12261 Set a convenience variable if it has not already been set. This is useful
12262 for user-defined commands that keep some state. It is similar, in concept,
12263 to using local static variables with initializers in C (except that
12264 convenience variables are global). It can also be used to allow users to
12265 override default values used in a command script.
12266
12267 If the variable is already defined then the expression is not evaluated so
12268 any side-effects do not occur.
12269 @end table
12270
12271 One of the ways to use a convenience variable is as a counter to be
12272 incremented or a pointer to be advanced. For example, to print
12273 a field from successive elements of an array of structures:
12274
12275 @smallexample
12276 set $i = 0
12277 print bar[$i++]->contents
12278 @end smallexample
12279
12280 @noindent
12281 Repeat that command by typing @key{RET}.
12282
12283 Some convenience variables are created automatically by @value{GDBN} and given
12284 values likely to be useful.
12285
12286 @table @code
12287 @vindex $_@r{, convenience variable}
12288 @item $_
12289 The variable @code{$_} is automatically set by the @code{x} command to
12290 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12291 commands which provide a default address for @code{x} to examine also
12292 set @code{$_} to that address; these commands include @code{info line}
12293 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12294 except when set by the @code{x} command, in which case it is a pointer
12295 to the type of @code{$__}.
12296
12297 @vindex $__@r{, convenience variable}
12298 @item $__
12299 The variable @code{$__} is automatically set by the @code{x} command
12300 to the value found in the last address examined. Its type is chosen
12301 to match the format in which the data was printed.
12302
12303 @item $_exitcode
12304 @vindex $_exitcode@r{, convenience variable}
12305 When the program being debugged terminates normally, @value{GDBN}
12306 automatically sets this variable to the exit code of the program, and
12307 resets @code{$_exitsignal} to @code{void}.
12308
12309 @item $_exitsignal
12310 @vindex $_exitsignal@r{, convenience variable}
12311 When the program being debugged dies due to an uncaught signal,
12312 @value{GDBN} automatically sets this variable to that signal's number,
12313 and resets @code{$_exitcode} to @code{void}.
12314
12315 To distinguish between whether the program being debugged has exited
12316 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12317 @code{$_exitsignal} is not @code{void}), the convenience function
12318 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12319 Functions}). For example, considering the following source code:
12320
12321 @smallexample
12322 #include <signal.h>
12323
12324 int
12325 main (int argc, char *argv[])
12326 @{
12327 raise (SIGALRM);
12328 return 0;
12329 @}
12330 @end smallexample
12331
12332 A valid way of telling whether the program being debugged has exited
12333 or signalled would be:
12334
12335 @smallexample
12336 (@value{GDBP}) define has_exited_or_signalled
12337 Type commands for definition of ``has_exited_or_signalled''.
12338 End with a line saying just ``end''.
12339 >if $_isvoid ($_exitsignal)
12340 >echo The program has exited\n
12341 >else
12342 >echo The program has signalled\n
12343 >end
12344 >end
12345 (@value{GDBP}) run
12346 Starting program:
12347
12348 Program terminated with signal SIGALRM, Alarm clock.
12349 The program no longer exists.
12350 (@value{GDBP}) has_exited_or_signalled
12351 The program has signalled
12352 @end smallexample
12353
12354 As can be seen, @value{GDBN} correctly informs that the program being
12355 debugged has signalled, since it calls @code{raise} and raises a
12356 @code{SIGALRM} signal. If the program being debugged had not called
12357 @code{raise}, then @value{GDBN} would report a normal exit:
12358
12359 @smallexample
12360 (@value{GDBP}) has_exited_or_signalled
12361 The program has exited
12362 @end smallexample
12363
12364 @item $_exception
12365 The variable @code{$_exception} is set to the exception object being
12366 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12367
12368 @item $_ada_exception
12369 The variable @code{$_ada_exception} is set to the address of the
12370 exception being caught or thrown at an Ada exception-related
12371 catchpoint. @xref{Set Catchpoints}.
12372
12373 @item $_probe_argc
12374 @itemx $_probe_arg0@dots{}$_probe_arg11
12375 Arguments to a static probe. @xref{Static Probe Points}.
12376
12377 @item $_sdata
12378 @vindex $_sdata@r{, inspect, convenience variable}
12379 The variable @code{$_sdata} contains extra collected static tracepoint
12380 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12381 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12382 if extra static tracepoint data has not been collected.
12383
12384 @item $_siginfo
12385 @vindex $_siginfo@r{, convenience variable}
12386 The variable @code{$_siginfo} contains extra signal information
12387 (@pxref{extra signal information}). Note that @code{$_siginfo}
12388 could be empty, if the application has not yet received any signals.
12389 For example, it will be empty before you execute the @code{run} command.
12390
12391 @item $_tlb
12392 @vindex $_tlb@r{, convenience variable}
12393 The variable @code{$_tlb} is automatically set when debugging
12394 applications running on MS-Windows in native mode or connected to
12395 gdbserver that supports the @code{qGetTIBAddr} request.
12396 @xref{General Query Packets}.
12397 This variable contains the address of the thread information block.
12398
12399 @item $_inferior
12400 The number of the current inferior. @xref{Inferiors Connections and
12401 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12402
12403 @item $_thread
12404 The thread number of the current thread. @xref{thread numbers}.
12405
12406 @item $_gthread
12407 The global number of the current thread. @xref{global thread numbers}.
12408
12409 @item $_gdb_major
12410 @itemx $_gdb_minor
12411 @vindex $_gdb_major@r{, convenience variable}
12412 @vindex $_gdb_minor@r{, convenience variable}
12413 The major and minor version numbers of the running @value{GDBN}.
12414 Development snapshots and pretest versions have their minor version
12415 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12416 the value 12 for @code{$_gdb_minor}. These variables allow you to
12417 write scripts that work with different versions of @value{GDBN}
12418 without errors caused by features unavailable in some of those
12419 versions.
12420
12421 @item $_shell_exitcode
12422 @itemx $_shell_exitsignal
12423 @vindex $_shell_exitcode@r{, convenience variable}
12424 @vindex $_shell_exitsignal@r{, convenience variable}
12425 @cindex shell command, exit code
12426 @cindex shell command, exit signal
12427 @cindex exit status of shell commands
12428 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12429 shell commands. When a launched command terminates, @value{GDBN}
12430 automatically maintains the variables @code{$_shell_exitcode}
12431 and @code{$_shell_exitsignal} according to the exit status of the last
12432 launched command. These variables are set and used similarly to
12433 the variables @code{$_exitcode} and @code{$_exitsignal}.
12434
12435 @end table
12436
12437 @node Convenience Funs
12438 @section Convenience Functions
12439
12440 @cindex convenience functions
12441 @value{GDBN} also supplies some @dfn{convenience functions}. These
12442 have a syntax similar to convenience variables. A convenience
12443 function can be used in an expression just like an ordinary function;
12444 however, a convenience function is implemented internally to
12445 @value{GDBN}.
12446
12447 These functions do not require @value{GDBN} to be configured with
12448 @code{Python} support, which means that they are always available.
12449
12450 @table @code
12451
12452 @item $_isvoid (@var{expr})
12453 @findex $_isvoid@r{, convenience function}
12454 Return one if the expression @var{expr} is @code{void}. Otherwise it
12455 returns zero.
12456
12457 A @code{void} expression is an expression where the type of the result
12458 is @code{void}. For example, you can examine a convenience variable
12459 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12460 it is @code{void}:
12461
12462 @smallexample
12463 (@value{GDBP}) print $_exitcode
12464 $1 = void
12465 (@value{GDBP}) print $_isvoid ($_exitcode)
12466 $2 = 1
12467 (@value{GDBP}) run
12468 Starting program: ./a.out
12469 [Inferior 1 (process 29572) exited normally]
12470 (@value{GDBP}) print $_exitcode
12471 $3 = 0
12472 (@value{GDBP}) print $_isvoid ($_exitcode)
12473 $4 = 0
12474 @end smallexample
12475
12476 In the example above, we used @code{$_isvoid} to check whether
12477 @code{$_exitcode} is @code{void} before and after the execution of the
12478 program being debugged. Before the execution there is no exit code to
12479 be examined, therefore @code{$_exitcode} is @code{void}. After the
12480 execution the program being debugged returned zero, therefore
12481 @code{$_exitcode} is zero, which means that it is not @code{void}
12482 anymore.
12483
12484 The @code{void} expression can also be a call of a function from the
12485 program being debugged. For example, given the following function:
12486
12487 @smallexample
12488 void
12489 foo (void)
12490 @{
12491 @}
12492 @end smallexample
12493
12494 The result of calling it inside @value{GDBN} is @code{void}:
12495
12496 @smallexample
12497 (@value{GDBP}) print foo ()
12498 $1 = void
12499 (@value{GDBP}) print $_isvoid (foo ())
12500 $2 = 1
12501 (@value{GDBP}) set $v = foo ()
12502 (@value{GDBP}) print $v
12503 $3 = void
12504 (@value{GDBP}) print $_isvoid ($v)
12505 $4 = 1
12506 @end smallexample
12507
12508 @item $_gdb_setting_str (@var{setting})
12509 @findex $_gdb_setting_str@r{, convenience function}
12510 Return the value of the @value{GDBN} @var{setting} as a string.
12511 @var{setting} is any setting that can be used in a @code{set} or
12512 @code{show} command (@pxref{Controlling GDB}).
12513
12514 @smallexample
12515 (@value{GDBP}) show print frame-arguments
12516 Printing of non-scalar frame arguments is "scalars".
12517 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12518 $1 = "scalars"
12519 (@value{GDBP}) p $_gdb_setting_str("height")
12520 $2 = "30"
12521 (@value{GDBP})
12522 @end smallexample
12523
12524 @item $_gdb_setting (@var{setting})
12525 @findex $_gdb_setting@r{, convenience function}
12526 Return the value of the @value{GDBN} @var{setting}.
12527 The type of the returned value depends on the setting.
12528
12529 The value type for boolean and auto boolean settings is @code{int}.
12530 The boolean values @code{off} and @code{on} are converted to
12531 the integer values @code{0} and @code{1}. The value @code{auto} is
12532 converted to the value @code{-1}.
12533
12534 The value type for integer settings is either @code{unsigned int}
12535 or @code{int}, depending on the setting.
12536
12537 Some integer settings accept an @code{unlimited} value.
12538 Depending on the setting, the @code{set} command also accepts
12539 the value @code{0} or the value @code{@minus{}1} as a synonym for
12540 @code{unlimited}.
12541 For example, @code{set height unlimited} is equivalent to
12542 @code{set height 0}.
12543
12544 Some other settings that accept the @code{unlimited} value
12545 use the value @code{0} to literally mean zero.
12546 For example, @code{set history size 0} indicates to not
12547 record any @value{GDBN} commands in the command history.
12548 For such settings, @code{@minus{}1} is the synonym
12549 for @code{unlimited}.
12550
12551 See the documentation of the corresponding @code{set} command for
12552 the numerical value equivalent to @code{unlimited}.
12553
12554 The @code{$_gdb_setting} function converts the unlimited value
12555 to a @code{0} or a @code{@minus{}1} value according to what the
12556 @code{set} command uses.
12557
12558 @smallexample
12559 @group
12560 (@value{GDBP}) p $_gdb_setting_str("height")
12561 $1 = "30"
12562 (@value{GDBP}) p $_gdb_setting("height")
12563 $2 = 30
12564 (@value{GDBP}) set height unlimited
12565 (@value{GDBP}) p $_gdb_setting_str("height")
12566 $3 = "unlimited"
12567 (@value{GDBP}) p $_gdb_setting("height")
12568 $4 = 0
12569 @end group
12570 @group
12571 (@value{GDBP}) p $_gdb_setting_str("history size")
12572 $5 = "unlimited"
12573 (@value{GDBP}) p $_gdb_setting("history size")
12574 $6 = -1
12575 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12576 $7 = "auto"
12577 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12578 $8 = -1
12579 (@value{GDBP})
12580 @end group
12581 @end smallexample
12582
12583 Other setting types (enum, filename, optional filename, string, string noescape)
12584 are returned as string values.
12585
12586
12587 @item $_gdb_maint_setting_str (@var{setting})
12588 @findex $_gdb_maint_setting_str@r{, convenience function}
12589 Like the @code{$_gdb_setting_str} function, but works with
12590 @code{maintenance set} variables.
12591
12592 @item $_gdb_maint_setting (@var{setting})
12593 @findex $_gdb_maint_setting@r{, convenience function}
12594 Like the @code{$_gdb_setting} function, but works with
12595 @code{maintenance set} variables.
12596
12597 @end table
12598
12599 The following functions require @value{GDBN} to be configured with
12600 @code{Python} support.
12601
12602 @table @code
12603
12604 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12605 @findex $_memeq@r{, convenience function}
12606 Returns one if the @var{length} bytes at the addresses given by
12607 @var{buf1} and @var{buf2} are equal.
12608 Otherwise it returns zero.
12609
12610 @item $_regex(@var{str}, @var{regex})
12611 @findex $_regex@r{, convenience function}
12612 Returns one if the string @var{str} matches the regular expression
12613 @var{regex}. Otherwise it returns zero.
12614 The syntax of the regular expression is that specified by @code{Python}'s
12615 regular expression support.
12616
12617 @item $_streq(@var{str1}, @var{str2})
12618 @findex $_streq@r{, convenience function}
12619 Returns one if the strings @var{str1} and @var{str2} are equal.
12620 Otherwise it returns zero.
12621
12622 @item $_strlen(@var{str})
12623 @findex $_strlen@r{, convenience function}
12624 Returns the length of string @var{str}.
12625
12626 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12627 @findex $_caller_is@r{, convenience function}
12628 Returns one if the calling function's name is equal to @var{name}.
12629 Otherwise it returns zero.
12630
12631 If the optional argument @var{number_of_frames} is provided,
12632 it is the number of frames up in the stack to look.
12633 The default is 1.
12634
12635 Example:
12636
12637 @smallexample
12638 (gdb) backtrace
12639 #0 bottom_func ()
12640 at testsuite/gdb.python/py-caller-is.c:21
12641 #1 0x00000000004005a0 in middle_func ()
12642 at testsuite/gdb.python/py-caller-is.c:27
12643 #2 0x00000000004005ab in top_func ()
12644 at testsuite/gdb.python/py-caller-is.c:33
12645 #3 0x00000000004005b6 in main ()
12646 at testsuite/gdb.python/py-caller-is.c:39
12647 (gdb) print $_caller_is ("middle_func")
12648 $1 = 1
12649 (gdb) print $_caller_is ("top_func", 2)
12650 $1 = 1
12651 @end smallexample
12652
12653 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12654 @findex $_caller_matches@r{, convenience function}
12655 Returns one if the calling function's name matches the regular expression
12656 @var{regexp}. Otherwise it returns zero.
12657
12658 If the optional argument @var{number_of_frames} is provided,
12659 it is the number of frames up in the stack to look.
12660 The default is 1.
12661
12662 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12663 @findex $_any_caller_is@r{, convenience function}
12664 Returns one if any calling function's name is equal to @var{name}.
12665 Otherwise it returns zero.
12666
12667 If the optional argument @var{number_of_frames} is provided,
12668 it is the number of frames up in the stack to look.
12669 The default is 1.
12670
12671 This function differs from @code{$_caller_is} in that this function
12672 checks all stack frames from the immediate caller to the frame specified
12673 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12674 frame specified by @var{number_of_frames}.
12675
12676 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12677 @findex $_any_caller_matches@r{, convenience function}
12678 Returns one if any calling function's name matches the regular expression
12679 @var{regexp}. Otherwise it returns zero.
12680
12681 If the optional argument @var{number_of_frames} is provided,
12682 it is the number of frames up in the stack to look.
12683 The default is 1.
12684
12685 This function differs from @code{$_caller_matches} in that this function
12686 checks all stack frames from the immediate caller to the frame specified
12687 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12688 frame specified by @var{number_of_frames}.
12689
12690 @item $_as_string(@var{value})
12691 @findex $_as_string@r{, convenience function}
12692 Return the string representation of @var{value}.
12693
12694 This function is useful to obtain the textual label (enumerator) of an
12695 enumeration value. For example, assuming the variable @var{node} is of
12696 an enumerated type:
12697
12698 @smallexample
12699 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12700 Visiting node of type NODE_INTEGER
12701 @end smallexample
12702
12703 @item $_cimag(@var{value})
12704 @itemx $_creal(@var{value})
12705 @findex $_cimag@r{, convenience function}
12706 @findex $_creal@r{, convenience function}
12707 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12708 the complex number @var{value}.
12709
12710 The type of the imaginary or real part depends on the type of the
12711 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12712 will return an imaginary part of type @code{float}.
12713
12714 @end table
12715
12716 @value{GDBN} provides the ability to list and get help on
12717 convenience functions.
12718
12719 @table @code
12720 @item help function
12721 @kindex help function
12722 @cindex show all convenience functions
12723 Print a list of all convenience functions.
12724 @end table
12725
12726 @node Registers
12727 @section Registers
12728
12729 @cindex registers
12730 You can refer to machine register contents, in expressions, as variables
12731 with names starting with @samp{$}. The names of registers are different
12732 for each machine; use @code{info registers} to see the names used on
12733 your machine.
12734
12735 @table @code
12736 @kindex info registers
12737 @item info registers
12738 Print the names and values of all registers except floating-point
12739 and vector registers (in the selected stack frame).
12740
12741 @kindex info all-registers
12742 @cindex floating point registers
12743 @item info all-registers
12744 Print the names and values of all registers, including floating-point
12745 and vector registers (in the selected stack frame).
12746
12747 @anchor{info_registers_reggroup}
12748 @item info registers @var{reggroup} @dots{}
12749 Print the name and value of the registers in each of the specified
12750 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12751 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12752
12753 @item info registers @var{regname} @dots{}
12754 Print the @dfn{relativized} value of each specified register @var{regname}.
12755 As discussed in detail below, register values are normally relative to
12756 the selected stack frame. The @var{regname} may be any register name valid on
12757 the machine you are using, with or without the initial @samp{$}.
12758 @end table
12759
12760 @anchor{standard registers}
12761 @cindex stack pointer register
12762 @cindex program counter register
12763 @cindex process status register
12764 @cindex frame pointer register
12765 @cindex standard registers
12766 @value{GDBN} has four ``standard'' register names that are available (in
12767 expressions) on most machines---whenever they do not conflict with an
12768 architecture's canonical mnemonics for registers. The register names
12769 @code{$pc} and @code{$sp} are used for the program counter register and
12770 the stack pointer. @code{$fp} is used for a register that contains a
12771 pointer to the current stack frame, and @code{$ps} is used for a
12772 register that contains the processor status. For example,
12773 you could print the program counter in hex with
12774
12775 @smallexample
12776 p/x $pc
12777 @end smallexample
12778
12779 @noindent
12780 or print the instruction to be executed next with
12781
12782 @smallexample
12783 x/i $pc
12784 @end smallexample
12785
12786 @noindent
12787 or add four to the stack pointer@footnote{This is a way of removing
12788 one word from the stack, on machines where stacks grow downward in
12789 memory (most machines, nowadays). This assumes that the innermost
12790 stack frame is selected; setting @code{$sp} is not allowed when other
12791 stack frames are selected. To pop entire frames off the stack,
12792 regardless of machine architecture, use @code{return};
12793 see @ref{Returning, ,Returning from a Function}.} with
12794
12795 @smallexample
12796 set $sp += 4
12797 @end smallexample
12798
12799 Whenever possible, these four standard register names are available on
12800 your machine even though the machine has different canonical mnemonics,
12801 so long as there is no conflict. The @code{info registers} command
12802 shows the canonical names. For example, on the SPARC, @code{info
12803 registers} displays the processor status register as @code{$psr} but you
12804 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12805 is an alias for the @sc{eflags} register.
12806
12807 @value{GDBN} always considers the contents of an ordinary register as an
12808 integer when the register is examined in this way. Some machines have
12809 special registers which can hold nothing but floating point; these
12810 registers are considered to have floating point values. There is no way
12811 to refer to the contents of an ordinary register as floating point value
12812 (although you can @emph{print} it as a floating point value with
12813 @samp{print/f $@var{regname}}).
12814
12815 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12816 means that the data format in which the register contents are saved by
12817 the operating system is not the same one that your program normally
12818 sees. For example, the registers of the 68881 floating point
12819 coprocessor are always saved in ``extended'' (raw) format, but all C
12820 programs expect to work with ``double'' (virtual) format. In such
12821 cases, @value{GDBN} normally works with the virtual format only (the format
12822 that makes sense for your program), but the @code{info registers} command
12823 prints the data in both formats.
12824
12825 @cindex SSE registers (x86)
12826 @cindex MMX registers (x86)
12827 Some machines have special registers whose contents can be interpreted
12828 in several different ways. For example, modern x86-based machines
12829 have SSE and MMX registers that can hold several values packed
12830 together in several different formats. @value{GDBN} refers to such
12831 registers in @code{struct} notation:
12832
12833 @smallexample
12834 (@value{GDBP}) print $xmm1
12835 $1 = @{
12836 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12837 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12838 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12839 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12840 v4_int32 = @{0, 20657912, 11, 13@},
12841 v2_int64 = @{88725056443645952, 55834574859@},
12842 uint128 = 0x0000000d0000000b013b36f800000000
12843 @}
12844 @end smallexample
12845
12846 @noindent
12847 To set values of such registers, you need to tell @value{GDBN} which
12848 view of the register you wish to change, as if you were assigning
12849 value to a @code{struct} member:
12850
12851 @smallexample
12852 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12853 @end smallexample
12854
12855 Normally, register values are relative to the selected stack frame
12856 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12857 value that the register would contain if all stack frames farther in
12858 were exited and their saved registers restored. In order to see the
12859 true contents of hardware registers, you must select the innermost
12860 frame (with @samp{frame 0}).
12861
12862 @cindex caller-saved registers
12863 @cindex call-clobbered registers
12864 @cindex volatile registers
12865 @cindex <not saved> values
12866 Usually ABIs reserve some registers as not needed to be saved by the
12867 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12868 registers). It may therefore not be possible for @value{GDBN} to know
12869 the value a register had before the call (in other words, in the outer
12870 frame), if the register value has since been changed by the callee.
12871 @value{GDBN} tries to deduce where the inner frame saved
12872 (``callee-saved'') registers, from the debug info, unwind info, or the
12873 machine code generated by your compiler. If some register is not
12874 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12875 its own knowledge of the ABI, or because the debug/unwind info
12876 explicitly says the register's value is undefined), @value{GDBN}
12877 displays @w{@samp{<not saved>}} as the register's value. With targets
12878 that @value{GDBN} has no knowledge of the register saving convention,
12879 if a register was not saved by the callee, then its value and location
12880 in the outer frame are assumed to be the same of the inner frame.
12881 This is usually harmless, because if the register is call-clobbered,
12882 the caller either does not care what is in the register after the
12883 call, or has code to restore the value that it does care about. Note,
12884 however, that if you change such a register in the outer frame, you
12885 may also be affecting the inner frame. Also, the more ``outer'' the
12886 frame is you're looking at, the more likely a call-clobbered
12887 register's value is to be wrong, in the sense that it doesn't actually
12888 represent the value the register had just before the call.
12889
12890 @node Floating Point Hardware
12891 @section Floating Point Hardware
12892 @cindex floating point
12893
12894 Depending on the configuration, @value{GDBN} may be able to give
12895 you more information about the status of the floating point hardware.
12896
12897 @table @code
12898 @kindex info float
12899 @item info float
12900 Display hardware-dependent information about the floating
12901 point unit. The exact contents and layout vary depending on the
12902 floating point chip. Currently, @samp{info float} is supported on
12903 the ARM and x86 machines.
12904 @end table
12905
12906 @node Vector Unit
12907 @section Vector Unit
12908 @cindex vector unit
12909
12910 Depending on the configuration, @value{GDBN} may be able to give you
12911 more information about the status of the vector unit.
12912
12913 @table @code
12914 @kindex info vector
12915 @item info vector
12916 Display information about the vector unit. The exact contents and
12917 layout vary depending on the hardware.
12918 @end table
12919
12920 @node OS Information
12921 @section Operating System Auxiliary Information
12922 @cindex OS information
12923
12924 @value{GDBN} provides interfaces to useful OS facilities that can help
12925 you debug your program.
12926
12927 @cindex auxiliary vector
12928 @cindex vector, auxiliary
12929 Some operating systems supply an @dfn{auxiliary vector} to programs at
12930 startup. This is akin to the arguments and environment that you
12931 specify for a program, but contains a system-dependent variety of
12932 binary values that tell system libraries important details about the
12933 hardware, operating system, and process. Each value's purpose is
12934 identified by an integer tag; the meanings are well-known but system-specific.
12935 Depending on the configuration and operating system facilities,
12936 @value{GDBN} may be able to show you this information. For remote
12937 targets, this functionality may further depend on the remote stub's
12938 support of the @samp{qXfer:auxv:read} packet, see
12939 @ref{qXfer auxiliary vector read}.
12940
12941 @table @code
12942 @kindex info auxv
12943 @item info auxv
12944 Display the auxiliary vector of the inferior, which can be either a
12945 live process or a core dump file. @value{GDBN} prints each tag value
12946 numerically, and also shows names and text descriptions for recognized
12947 tags. Some values in the vector are numbers, some bit masks, and some
12948 pointers to strings or other data. @value{GDBN} displays each value in the
12949 most appropriate form for a recognized tag, and in hexadecimal for
12950 an unrecognized tag.
12951 @end table
12952
12953 On some targets, @value{GDBN} can access operating system-specific
12954 information and show it to you. The types of information available
12955 will differ depending on the type of operating system running on the
12956 target. The mechanism used to fetch the data is described in
12957 @ref{Operating System Information}. For remote targets, this
12958 functionality depends on the remote stub's support of the
12959 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12960
12961 @table @code
12962 @kindex info os
12963 @item info os @var{infotype}
12964
12965 Display OS information of the requested type.
12966
12967 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12968
12969 @anchor{linux info os infotypes}
12970 @table @code
12971 @kindex info os cpus
12972 @item cpus
12973 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12974 the available fields from /proc/cpuinfo. For each supported architecture
12975 different fields are available. Two common entries are processor which gives
12976 CPU number and bogomips; a system constant that is calculated during
12977 kernel initialization.
12978
12979 @kindex info os files
12980 @item files
12981 Display the list of open file descriptors on the target. For each
12982 file descriptor, @value{GDBN} prints the identifier of the process
12983 owning the descriptor, the command of the owning process, the value
12984 of the descriptor, and the target of the descriptor.
12985
12986 @kindex info os modules
12987 @item modules
12988 Display the list of all loaded kernel modules on the target. For each
12989 module, @value{GDBN} prints the module name, the size of the module in
12990 bytes, the number of times the module is used, the dependencies of the
12991 module, the status of the module, and the address of the loaded module
12992 in memory.
12993
12994 @kindex info os msg
12995 @item msg
12996 Display the list of all System V message queues on the target. For each
12997 message queue, @value{GDBN} prints the message queue key, the message
12998 queue identifier, the access permissions, the current number of bytes
12999 on the queue, the current number of messages on the queue, the processes
13000 that last sent and received a message on the queue, the user and group
13001 of the owner and creator of the message queue, the times at which a
13002 message was last sent and received on the queue, and the time at which
13003 the message queue was last changed.
13004
13005 @kindex info os processes
13006 @item processes
13007 Display the list of processes on the target. For each process,
13008 @value{GDBN} prints the process identifier, the name of the user, the
13009 command corresponding to the process, and the list of processor cores
13010 that the process is currently running on. (To understand what these
13011 properties mean, for this and the following info types, please consult
13012 the general @sc{gnu}/Linux documentation.)
13013
13014 @kindex info os procgroups
13015 @item procgroups
13016 Display the list of process groups on the target. For each process,
13017 @value{GDBN} prints the identifier of the process group that it belongs
13018 to, the command corresponding to the process group leader, the process
13019 identifier, and the command line of the process. The list is sorted
13020 first by the process group identifier, then by the process identifier,
13021 so that processes belonging to the same process group are grouped together
13022 and the process group leader is listed first.
13023
13024 @kindex info os semaphores
13025 @item semaphores
13026 Display the list of all System V semaphore sets on the target. For each
13027 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
13028 set identifier, the access permissions, the number of semaphores in the
13029 set, the user and group of the owner and creator of the semaphore set,
13030 and the times at which the semaphore set was operated upon and changed.
13031
13032 @kindex info os shm
13033 @item shm
13034 Display the list of all System V shared-memory regions on the target.
13035 For each shared-memory region, @value{GDBN} prints the region key,
13036 the shared-memory identifier, the access permissions, the size of the
13037 region, the process that created the region, the process that last
13038 attached to or detached from the region, the current number of live
13039 attaches to the region, and the times at which the region was last
13040 attached to, detach from, and changed.
13041
13042 @kindex info os sockets
13043 @item sockets
13044 Display the list of Internet-domain sockets on the target. For each
13045 socket, @value{GDBN} prints the address and port of the local and
13046 remote endpoints, the current state of the connection, the creator of
13047 the socket, the IP address family of the socket, and the type of the
13048 connection.
13049
13050 @kindex info os threads
13051 @item threads
13052 Display the list of threads running on the target. For each thread,
13053 @value{GDBN} prints the identifier of the process that the thread
13054 belongs to, the command of the process, the thread identifier, and the
13055 processor core that it is currently running on. The main thread of a
13056 process is not listed.
13057 @end table
13058
13059 @item info os
13060 If @var{infotype} is omitted, then list the possible values for
13061 @var{infotype} and the kind of OS information available for each
13062 @var{infotype}. If the target does not return a list of possible
13063 types, this command will report an error.
13064 @end table
13065
13066 @node Memory Region Attributes
13067 @section Memory Region Attributes
13068 @cindex memory region attributes
13069
13070 @dfn{Memory region attributes} allow you to describe special handling
13071 required by regions of your target's memory. @value{GDBN} uses
13072 attributes to determine whether to allow certain types of memory
13073 accesses; whether to use specific width accesses; and whether to cache
13074 target memory. By default the description of memory regions is
13075 fetched from the target (if the current target supports this), but the
13076 user can override the fetched regions.
13077
13078 Defined memory regions can be individually enabled and disabled. When a
13079 memory region is disabled, @value{GDBN} uses the default attributes when
13080 accessing memory in that region. Similarly, if no memory regions have
13081 been defined, @value{GDBN} uses the default attributes when accessing
13082 all memory.
13083
13084 When a memory region is defined, it is given a number to identify it;
13085 to enable, disable, or remove a memory region, you specify that number.
13086
13087 @table @code
13088 @kindex mem
13089 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
13090 Define a memory region bounded by @var{lower} and @var{upper} with
13091 attributes @var{attributes}@dots{}, and add it to the list of regions
13092 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
13093 case: it is treated as the target's maximum memory address.
13094 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
13095
13096 @item mem auto
13097 Discard any user changes to the memory regions and use target-supplied
13098 regions, if available, or no regions if the target does not support.
13099
13100 @kindex delete mem
13101 @item delete mem @var{nums}@dots{}
13102 Remove memory regions @var{nums}@dots{} from the list of regions
13103 monitored by @value{GDBN}.
13104
13105 @kindex disable mem
13106 @item disable mem @var{nums}@dots{}
13107 Disable monitoring of memory regions @var{nums}@dots{}.
13108 A disabled memory region is not forgotten.
13109 It may be enabled again later.
13110
13111 @kindex enable mem
13112 @item enable mem @var{nums}@dots{}
13113 Enable monitoring of memory regions @var{nums}@dots{}.
13114
13115 @kindex info mem
13116 @item info mem
13117 Print a table of all defined memory regions, with the following columns
13118 for each region:
13119
13120 @table @emph
13121 @item Memory Region Number
13122 @item Enabled or Disabled.
13123 Enabled memory regions are marked with @samp{y}.
13124 Disabled memory regions are marked with @samp{n}.
13125
13126 @item Lo Address
13127 The address defining the inclusive lower bound of the memory region.
13128
13129 @item Hi Address
13130 The address defining the exclusive upper bound of the memory region.
13131
13132 @item Attributes
13133 The list of attributes set for this memory region.
13134 @end table
13135 @end table
13136
13137
13138 @subsection Attributes
13139
13140 @subsubsection Memory Access Mode
13141 The access mode attributes set whether @value{GDBN} may make read or
13142 write accesses to a memory region.
13143
13144 While these attributes prevent @value{GDBN} from performing invalid
13145 memory accesses, they do nothing to prevent the target system, I/O DMA,
13146 etc.@: from accessing memory.
13147
13148 @table @code
13149 @item ro
13150 Memory is read only.
13151 @item wo
13152 Memory is write only.
13153 @item rw
13154 Memory is read/write. This is the default.
13155 @end table
13156
13157 @subsubsection Memory Access Size
13158 The access size attribute tells @value{GDBN} to use specific sized
13159 accesses in the memory region. Often memory mapped device registers
13160 require specific sized accesses. If no access size attribute is
13161 specified, @value{GDBN} may use accesses of any size.
13162
13163 @table @code
13164 @item 8
13165 Use 8 bit memory accesses.
13166 @item 16
13167 Use 16 bit memory accesses.
13168 @item 32
13169 Use 32 bit memory accesses.
13170 @item 64
13171 Use 64 bit memory accesses.
13172 @end table
13173
13174 @c @subsubsection Hardware/Software Breakpoints
13175 @c The hardware/software breakpoint attributes set whether @value{GDBN}
13176 @c will use hardware or software breakpoints for the internal breakpoints
13177 @c used by the step, next, finish, until, etc. commands.
13178 @c
13179 @c @table @code
13180 @c @item hwbreak
13181 @c Always use hardware breakpoints
13182 @c @item swbreak (default)
13183 @c @end table
13184
13185 @subsubsection Data Cache
13186 The data cache attributes set whether @value{GDBN} will cache target
13187 memory. While this generally improves performance by reducing debug
13188 protocol overhead, it can lead to incorrect results because @value{GDBN}
13189 does not know about volatile variables or memory mapped device
13190 registers.
13191
13192 @table @code
13193 @item cache
13194 Enable @value{GDBN} to cache target memory.
13195 @item nocache
13196 Disable @value{GDBN} from caching target memory. This is the default.
13197 @end table
13198
13199 @subsection Memory Access Checking
13200 @value{GDBN} can be instructed to refuse accesses to memory that is
13201 not explicitly described. This can be useful if accessing such
13202 regions has undesired effects for a specific target, or to provide
13203 better error checking. The following commands control this behaviour.
13204
13205 @table @code
13206 @kindex set mem inaccessible-by-default
13207 @item set mem inaccessible-by-default [on|off]
13208 If @code{on} is specified, make @value{GDBN} treat memory not
13209 explicitly described by the memory ranges as non-existent and refuse accesses
13210 to such memory. The checks are only performed if there's at least one
13211 memory range defined. If @code{off} is specified, make @value{GDBN}
13212 treat the memory not explicitly described by the memory ranges as RAM.
13213 The default value is @code{on}.
13214 @kindex show mem inaccessible-by-default
13215 @item show mem inaccessible-by-default
13216 Show the current handling of accesses to unknown memory.
13217 @end table
13218
13219
13220 @c @subsubsection Memory Write Verification
13221 @c The memory write verification attributes set whether @value{GDBN}
13222 @c will re-reads data after each write to verify the write was successful.
13223 @c
13224 @c @table @code
13225 @c @item verify
13226 @c @item noverify (default)
13227 @c @end table
13228
13229 @node Dump/Restore Files
13230 @section Copy Between Memory and a File
13231 @cindex dump/restore files
13232 @cindex append data to a file
13233 @cindex dump data to a file
13234 @cindex restore data from a file
13235
13236 You can use the commands @code{dump}, @code{append}, and
13237 @code{restore} to copy data between target memory and a file. The
13238 @code{dump} and @code{append} commands write data to a file, and the
13239 @code{restore} command reads data from a file back into the inferior's
13240 memory. Files may be in binary, Motorola S-record, Intel hex,
13241 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13242 append to binary files, and cannot read from Verilog Hex files.
13243
13244 @table @code
13245
13246 @kindex dump
13247 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13248 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13249 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13250 or the value of @var{expr}, to @var{filename} in the given format.
13251
13252 The @var{format} parameter may be any one of:
13253 @table @code
13254 @item binary
13255 Raw binary form.
13256 @item ihex
13257 Intel hex format.
13258 @item srec
13259 Motorola S-record format.
13260 @item tekhex
13261 Tektronix Hex format.
13262 @item verilog
13263 Verilog Hex format.
13264 @end table
13265
13266 @value{GDBN} uses the same definitions of these formats as the
13267 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13268 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13269 form.
13270
13271 @kindex append
13272 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13273 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13274 Append the contents of memory from @var{start_addr} to @var{end_addr},
13275 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13276 (@value{GDBN} can only append data to files in raw binary form.)
13277
13278 @kindex restore
13279 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13280 Restore the contents of file @var{filename} into memory. The
13281 @code{restore} command can automatically recognize any known @sc{bfd}
13282 file format, except for raw binary. To restore a raw binary file you
13283 must specify the optional keyword @code{binary} after the filename.
13284
13285 If @var{bias} is non-zero, its value will be added to the addresses
13286 contained in the file. Binary files always start at address zero, so
13287 they will be restored at address @var{bias}. Other bfd files have
13288 a built-in location; they will be restored at offset @var{bias}
13289 from that location.
13290
13291 If @var{start} and/or @var{end} are non-zero, then only data between
13292 file offset @var{start} and file offset @var{end} will be restored.
13293 These offsets are relative to the addresses in the file, before
13294 the @var{bias} argument is applied.
13295
13296 @end table
13297
13298 @node Core File Generation
13299 @section How to Produce a Core File from Your Program
13300 @cindex dump core from inferior
13301
13302 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13303 image of a running process and its process status (register values
13304 etc.). Its primary use is post-mortem debugging of a program that
13305 crashed while it ran outside a debugger. A program that crashes
13306 automatically produces a core file, unless this feature is disabled by
13307 the user. @xref{Files}, for information on invoking @value{GDBN} in
13308 the post-mortem debugging mode.
13309
13310 Occasionally, you may wish to produce a core file of the program you
13311 are debugging in order to preserve a snapshot of its state.
13312 @value{GDBN} has a special command for that.
13313
13314 @table @code
13315 @kindex gcore
13316 @kindex generate-core-file
13317 @item generate-core-file [@var{file}]
13318 @itemx gcore [@var{file}]
13319 Produce a core dump of the inferior process. The optional argument
13320 @var{file} specifies the file name where to put the core dump. If not
13321 specified, the file name defaults to @file{core.@var{pid}}, where
13322 @var{pid} is the inferior process ID.
13323
13324 Note that this command is implemented only for some systems (as of
13325 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13326
13327 On @sc{gnu}/Linux, this command can take into account the value of the
13328 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13329 dump (@pxref{set use-coredump-filter}), and by default honors the
13330 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13331 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13332
13333 @kindex set use-coredump-filter
13334 @anchor{set use-coredump-filter}
13335 @item set use-coredump-filter on
13336 @itemx set use-coredump-filter off
13337 Enable or disable the use of the file
13338 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13339 files. This file is used by the Linux kernel to decide what types of
13340 memory mappings will be dumped or ignored when generating a core dump
13341 file. @var{pid} is the process ID of a currently running process.
13342
13343 To make use of this feature, you have to write in the
13344 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13345 which is a bit mask representing the memory mapping types. If a bit
13346 is set in the bit mask, then the memory mappings of the corresponding
13347 types will be dumped; otherwise, they will be ignored. This
13348 configuration is inherited by child processes. For more information
13349 about the bits that can be set in the
13350 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13351 manpage of @code{core(5)}.
13352
13353 By default, this option is @code{on}. If this option is turned
13354 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13355 and instead uses the same default value as the Linux kernel in order
13356 to decide which pages will be dumped in the core dump file. This
13357 value is currently @code{0x33}, which means that bits @code{0}
13358 (anonymous private mappings), @code{1} (anonymous shared mappings),
13359 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13360 This will cause these memory mappings to be dumped automatically.
13361
13362 @kindex set dump-excluded-mappings
13363 @anchor{set dump-excluded-mappings}
13364 @item set dump-excluded-mappings on
13365 @itemx set dump-excluded-mappings off
13366 If @code{on} is specified, @value{GDBN} will dump memory mappings
13367 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13368 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13369
13370 The default value is @code{off}.
13371 @end table
13372
13373 @node Character Sets
13374 @section Character Sets
13375 @cindex character sets
13376 @cindex charset
13377 @cindex translating between character sets
13378 @cindex host character set
13379 @cindex target character set
13380
13381 If the program you are debugging uses a different character set to
13382 represent characters and strings than the one @value{GDBN} uses itself,
13383 @value{GDBN} can automatically translate between the character sets for
13384 you. The character set @value{GDBN} uses we call the @dfn{host
13385 character set}; the one the inferior program uses we call the
13386 @dfn{target character set}.
13387
13388 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13389 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13390 remote protocol (@pxref{Remote Debugging}) to debug a program
13391 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13392 then the host character set is Latin-1, and the target character set is
13393 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13394 target-charset EBCDIC-US}, then @value{GDBN} translates between
13395 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13396 character and string literals in expressions.
13397
13398 @value{GDBN} has no way to automatically recognize which character set
13399 the inferior program uses; you must tell it, using the @code{set
13400 target-charset} command, described below.
13401
13402 Here are the commands for controlling @value{GDBN}'s character set
13403 support:
13404
13405 @table @code
13406 @item set target-charset @var{charset}
13407 @kindex set target-charset
13408 Set the current target character set to @var{charset}. To display the
13409 list of supported target character sets, type
13410 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13411
13412 @item set host-charset @var{charset}
13413 @kindex set host-charset
13414 Set the current host character set to @var{charset}.
13415
13416 By default, @value{GDBN} uses a host character set appropriate to the
13417 system it is running on; you can override that default using the
13418 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13419 automatically determine the appropriate host character set. In this
13420 case, @value{GDBN} uses @samp{UTF-8}.
13421
13422 @value{GDBN} can only use certain character sets as its host character
13423 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13424 @value{GDBN} will list the host character sets it supports.
13425
13426 @item set charset @var{charset}
13427 @kindex set charset
13428 Set the current host and target character sets to @var{charset}. As
13429 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13430 @value{GDBN} will list the names of the character sets that can be used
13431 for both host and target.
13432
13433 @item show charset
13434 @kindex show charset
13435 Show the names of the current host and target character sets.
13436
13437 @item show host-charset
13438 @kindex show host-charset
13439 Show the name of the current host character set.
13440
13441 @item show target-charset
13442 @kindex show target-charset
13443 Show the name of the current target character set.
13444
13445 @item set target-wide-charset @var{charset}
13446 @kindex set target-wide-charset
13447 Set the current target's wide character set to @var{charset}. This is
13448 the character set used by the target's @code{wchar_t} type. To
13449 display the list of supported wide character sets, type
13450 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13451
13452 @item show target-wide-charset
13453 @kindex show target-wide-charset
13454 Show the name of the current target's wide character set.
13455 @end table
13456
13457 Here is an example of @value{GDBN}'s character set support in action.
13458 Assume that the following source code has been placed in the file
13459 @file{charset-test.c}:
13460
13461 @smallexample
13462 #include <stdio.h>
13463
13464 char ascii_hello[]
13465 = @{72, 101, 108, 108, 111, 44, 32, 119,
13466 111, 114, 108, 100, 33, 10, 0@};
13467 char ibm1047_hello[]
13468 = @{200, 133, 147, 147, 150, 107, 64, 166,
13469 150, 153, 147, 132, 90, 37, 0@};
13470
13471 main ()
13472 @{
13473 printf ("Hello, world!\n");
13474 @}
13475 @end smallexample
13476
13477 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13478 containing the string @samp{Hello, world!} followed by a newline,
13479 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13480
13481 We compile the program, and invoke the debugger on it:
13482
13483 @smallexample
13484 $ gcc -g charset-test.c -o charset-test
13485 $ gdb -nw charset-test
13486 GNU gdb 2001-12-19-cvs
13487 Copyright 2001 Free Software Foundation, Inc.
13488 @dots{}
13489 (@value{GDBP})
13490 @end smallexample
13491
13492 We can use the @code{show charset} command to see what character sets
13493 @value{GDBN} is currently using to interpret and display characters and
13494 strings:
13495
13496 @smallexample
13497 (@value{GDBP}) show charset
13498 The current host and target character set is `ISO-8859-1'.
13499 (@value{GDBP})
13500 @end smallexample
13501
13502 For the sake of printing this manual, let's use @sc{ascii} as our
13503 initial character set:
13504 @smallexample
13505 (@value{GDBP}) set charset ASCII
13506 (@value{GDBP}) show charset
13507 The current host and target character set is `ASCII'.
13508 (@value{GDBP})
13509 @end smallexample
13510
13511 Let's assume that @sc{ascii} is indeed the correct character set for our
13512 host system --- in other words, let's assume that if @value{GDBN} prints
13513 characters using the @sc{ascii} character set, our terminal will display
13514 them properly. Since our current target character set is also
13515 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13516
13517 @smallexample
13518 (@value{GDBP}) print ascii_hello
13519 $1 = 0x401698 "Hello, world!\n"
13520 (@value{GDBP}) print ascii_hello[0]
13521 $2 = 72 'H'
13522 (@value{GDBP})
13523 @end smallexample
13524
13525 @value{GDBN} uses the target character set for character and string
13526 literals you use in expressions:
13527
13528 @smallexample
13529 (@value{GDBP}) print '+'
13530 $3 = 43 '+'
13531 (@value{GDBP})
13532 @end smallexample
13533
13534 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13535 character.
13536
13537 @value{GDBN} relies on the user to tell it which character set the
13538 target program uses. If we print @code{ibm1047_hello} while our target
13539 character set is still @sc{ascii}, we get jibberish:
13540
13541 @smallexample
13542 (@value{GDBP}) print ibm1047_hello
13543 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13544 (@value{GDBP}) print ibm1047_hello[0]
13545 $5 = 200 '\310'
13546 (@value{GDBP})
13547 @end smallexample
13548
13549 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13550 @value{GDBN} tells us the character sets it supports:
13551
13552 @smallexample
13553 (@value{GDBP}) set target-charset
13554 ASCII EBCDIC-US IBM1047 ISO-8859-1
13555 (@value{GDBP}) set target-charset
13556 @end smallexample
13557
13558 We can select @sc{ibm1047} as our target character set, and examine the
13559 program's strings again. Now the @sc{ascii} string is wrong, but
13560 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13561 target character set, @sc{ibm1047}, to the host character set,
13562 @sc{ascii}, and they display correctly:
13563
13564 @smallexample
13565 (@value{GDBP}) set target-charset IBM1047
13566 (@value{GDBP}) show charset
13567 The current host character set is `ASCII'.
13568 The current target character set is `IBM1047'.
13569 (@value{GDBP}) print ascii_hello
13570 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13571 (@value{GDBP}) print ascii_hello[0]
13572 $7 = 72 '\110'
13573 (@value{GDBP}) print ibm1047_hello
13574 $8 = 0x4016a8 "Hello, world!\n"
13575 (@value{GDBP}) print ibm1047_hello[0]
13576 $9 = 200 'H'
13577 (@value{GDBP})
13578 @end smallexample
13579
13580 As above, @value{GDBN} uses the target character set for character and
13581 string literals you use in expressions:
13582
13583 @smallexample
13584 (@value{GDBP}) print '+'
13585 $10 = 78 '+'
13586 (@value{GDBP})
13587 @end smallexample
13588
13589 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13590 character.
13591
13592 @node Caching Target Data
13593 @section Caching Data of Targets
13594 @cindex caching data of targets
13595
13596 @value{GDBN} caches data exchanged between the debugger and a target.
13597 Each cache is associated with the address space of the inferior.
13598 @xref{Inferiors Connections and Programs}, about inferior and address space.
13599 Such caching generally improves performance in remote debugging
13600 (@pxref{Remote Debugging}), because it reduces the overhead of the
13601 remote protocol by bundling memory reads and writes into large chunks.
13602 Unfortunately, simply caching everything would lead to incorrect results,
13603 since @value{GDBN} does not necessarily know anything about volatile
13604 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13605 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13606 is executing.
13607 Therefore, by default, @value{GDBN} only caches data
13608 known to be on the stack@footnote{In non-stop mode, it is moderately
13609 rare for a running thread to modify the stack of a stopped thread
13610 in a way that would interfere with a backtrace, and caching of
13611 stack reads provides a significant speed up of remote backtraces.} or
13612 in the code segment.
13613 Other regions of memory can be explicitly marked as
13614 cacheable; @pxref{Memory Region Attributes}.
13615
13616 @table @code
13617 @kindex set remotecache
13618 @item set remotecache on
13619 @itemx set remotecache off
13620 This option no longer does anything; it exists for compatibility
13621 with old scripts.
13622
13623 @kindex show remotecache
13624 @item show remotecache
13625 Show the current state of the obsolete remotecache flag.
13626
13627 @kindex set stack-cache
13628 @item set stack-cache on
13629 @itemx set stack-cache off
13630 Enable or disable caching of stack accesses. When @code{on}, use
13631 caching. By default, this option is @code{on}.
13632
13633 @kindex show stack-cache
13634 @item show stack-cache
13635 Show the current state of data caching for memory accesses.
13636
13637 @kindex set code-cache
13638 @item set code-cache on
13639 @itemx set code-cache off
13640 Enable or disable caching of code segment accesses. When @code{on},
13641 use caching. By default, this option is @code{on}. This improves
13642 performance of disassembly in remote debugging.
13643
13644 @kindex show code-cache
13645 @item show code-cache
13646 Show the current state of target memory cache for code segment
13647 accesses.
13648
13649 @kindex info dcache
13650 @item info dcache @r{[}line@r{]}
13651 Print the information about the performance of data cache of the
13652 current inferior's address space. The information displayed
13653 includes the dcache width and depth, and for each cache line, its
13654 number, address, and how many times it was referenced. This
13655 command is useful for debugging the data cache operation.
13656
13657 If a line number is specified, the contents of that line will be
13658 printed in hex.
13659
13660 @item set dcache size @var{size}
13661 @cindex dcache size
13662 @kindex set dcache size
13663 Set maximum number of entries in dcache (dcache depth above).
13664
13665 @item set dcache line-size @var{line-size}
13666 @cindex dcache line-size
13667 @kindex set dcache line-size
13668 Set number of bytes each dcache entry caches (dcache width above).
13669 Must be a power of 2.
13670
13671 @item show dcache size
13672 @kindex show dcache size
13673 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13674
13675 @item show dcache line-size
13676 @kindex show dcache line-size
13677 Show default size of dcache lines.
13678
13679 @item maint flush dcache
13680 @cindex dcache, flushing
13681 @kindex maint flush dcache
13682 Flush the contents (if any) of the dcache. This maintainer command is
13683 useful when debugging the dcache implementation.
13684
13685 @end table
13686
13687 @node Searching Memory
13688 @section Search Memory
13689 @cindex searching memory
13690
13691 Memory can be searched for a particular sequence of bytes with the
13692 @code{find} command.
13693
13694 @table @code
13695 @kindex find
13696 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13697 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13698 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13699 etc. The search begins at address @var{start_addr} and continues for either
13700 @var{len} bytes or through to @var{end_addr} inclusive.
13701 @end table
13702
13703 @var{s} and @var{n} are optional parameters.
13704 They may be specified in either order, apart or together.
13705
13706 @table @r
13707 @item @var{s}, search query size
13708 The size of each search query value.
13709
13710 @table @code
13711 @item b
13712 bytes
13713 @item h
13714 halfwords (two bytes)
13715 @item w
13716 words (four bytes)
13717 @item g
13718 giant words (eight bytes)
13719 @end table
13720
13721 All values are interpreted in the current language.
13722 This means, for example, that if the current source language is C/C@t{++}
13723 then searching for the string ``hello'' includes the trailing '\0'.
13724 The null terminator can be removed from searching by using casts,
13725 e.g.: @samp{@{char[5]@}"hello"}.
13726
13727 If the value size is not specified, it is taken from the
13728 value's type in the current language.
13729 This is useful when one wants to specify the search
13730 pattern as a mixture of types.
13731 Note that this means, for example, that in the case of C-like languages
13732 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13733 which is typically four bytes.
13734
13735 @item @var{n}, maximum number of finds
13736 The maximum number of matches to print. The default is to print all finds.
13737 @end table
13738
13739 You can use strings as search values. Quote them with double-quotes
13740 (@code{"}).
13741 The string value is copied into the search pattern byte by byte,
13742 regardless of the endianness of the target and the size specification.
13743
13744 The address of each match found is printed as well as a count of the
13745 number of matches found.
13746
13747 The address of the last value found is stored in convenience variable
13748 @samp{$_}.
13749 A count of the number of matches is stored in @samp{$numfound}.
13750
13751 For example, if stopped at the @code{printf} in this function:
13752
13753 @smallexample
13754 void
13755 hello ()
13756 @{
13757 static char hello[] = "hello-hello";
13758 static struct @{ char c; short s; int i; @}
13759 __attribute__ ((packed)) mixed
13760 = @{ 'c', 0x1234, 0x87654321 @};
13761 printf ("%s\n", hello);
13762 @}
13763 @end smallexample
13764
13765 @noindent
13766 you get during debugging:
13767
13768 @smallexample
13769 (gdb) find &hello[0], +sizeof(hello), "hello"
13770 0x804956d <hello.1620+6>
13771 1 pattern found
13772 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13773 0x8049567 <hello.1620>
13774 0x804956d <hello.1620+6>
13775 2 patterns found.
13776 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13777 0x8049567 <hello.1620>
13778 0x804956d <hello.1620+6>
13779 2 patterns found.
13780 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13781 0x8049567 <hello.1620>
13782 1 pattern found
13783 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13784 0x8049560 <mixed.1625>
13785 1 pattern found
13786 (gdb) print $numfound
13787 $1 = 1
13788 (gdb) print $_
13789 $2 = (void *) 0x8049560
13790 @end smallexample
13791
13792 @node Value Sizes
13793 @section Value Sizes
13794
13795 Whenever @value{GDBN} prints a value memory will be allocated within
13796 @value{GDBN} to hold the contents of the value. It is possible in
13797 some languages with dynamic typing systems, that an invalid program
13798 may indicate a value that is incorrectly large, this in turn may cause
13799 @value{GDBN} to try and allocate an overly large amount of memory.
13800
13801 @table @code
13802 @kindex set max-value-size
13803 @item set max-value-size @var{bytes}
13804 @itemx set max-value-size unlimited
13805 Set the maximum size of memory that @value{GDBN} will allocate for the
13806 contents of a value to @var{bytes}, trying to display a value that
13807 requires more memory than that will result in an error.
13808
13809 Setting this variable does not effect values that have already been
13810 allocated within @value{GDBN}, only future allocations.
13811
13812 There's a minimum size that @code{max-value-size} can be set to in
13813 order that @value{GDBN} can still operate correctly, this minimum is
13814 currently 16 bytes.
13815
13816 The limit applies to the results of some subexpressions as well as to
13817 complete expressions. For example, an expression denoting a simple
13818 integer component, such as @code{x.y.z}, may fail if the size of
13819 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13820 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13821 @var{A} is an array variable with non-constant size, will generally
13822 succeed regardless of the bounds on @var{A}, as long as the component
13823 size is less than @var{bytes}.
13824
13825 The default value of @code{max-value-size} is currently 64k.
13826
13827 @kindex show max-value-size
13828 @item show max-value-size
13829 Show the maximum size of memory, in bytes, that @value{GDBN} will
13830 allocate for the contents of a value.
13831 @end table
13832
13833 @node Optimized Code
13834 @chapter Debugging Optimized Code
13835 @cindex optimized code, debugging
13836 @cindex debugging optimized code
13837
13838 Almost all compilers support optimization. With optimization
13839 disabled, the compiler generates assembly code that corresponds
13840 directly to your source code, in a simplistic way. As the compiler
13841 applies more powerful optimizations, the generated assembly code
13842 diverges from your original source code. With help from debugging
13843 information generated by the compiler, @value{GDBN} can map from
13844 the running program back to constructs from your original source.
13845
13846 @value{GDBN} is more accurate with optimization disabled. If you
13847 can recompile without optimization, it is easier to follow the
13848 progress of your program during debugging. But, there are many cases
13849 where you may need to debug an optimized version.
13850
13851 When you debug a program compiled with @samp{-g -O}, remember that the
13852 optimizer has rearranged your code; the debugger shows you what is
13853 really there. Do not be too surprised when the execution path does not
13854 exactly match your source file! An extreme example: if you define a
13855 variable, but never use it, @value{GDBN} never sees that
13856 variable---because the compiler optimizes it out of existence.
13857
13858 Some things do not work as well with @samp{-g -O} as with just
13859 @samp{-g}, particularly on machines with instruction scheduling. If in
13860 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13861 please report it to us as a bug (including a test case!).
13862 @xref{Variables}, for more information about debugging optimized code.
13863
13864 @menu
13865 * Inline Functions:: How @value{GDBN} presents inlining
13866 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13867 @end menu
13868
13869 @node Inline Functions
13870 @section Inline Functions
13871 @cindex inline functions, debugging
13872
13873 @dfn{Inlining} is an optimization that inserts a copy of the function
13874 body directly at each call site, instead of jumping to a shared
13875 routine. @value{GDBN} displays inlined functions just like
13876 non-inlined functions. They appear in backtraces. You can view their
13877 arguments and local variables, step into them with @code{step}, skip
13878 them with @code{next}, and escape from them with @code{finish}.
13879 You can check whether a function was inlined by using the
13880 @code{info frame} command.
13881
13882 For @value{GDBN} to support inlined functions, the compiler must
13883 record information about inlining in the debug information ---
13884 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13885 other compilers do also. @value{GDBN} only supports inlined functions
13886 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13887 do not emit two required attributes (@samp{DW_AT_call_file} and
13888 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13889 function calls with earlier versions of @value{NGCC}. It instead
13890 displays the arguments and local variables of inlined functions as
13891 local variables in the caller.
13892
13893 The body of an inlined function is directly included at its call site;
13894 unlike a non-inlined function, there are no instructions devoted to
13895 the call. @value{GDBN} still pretends that the call site and the
13896 start of the inlined function are different instructions. Stepping to
13897 the call site shows the call site, and then stepping again shows
13898 the first line of the inlined function, even though no additional
13899 instructions are executed.
13900
13901 This makes source-level debugging much clearer; you can see both the
13902 context of the call and then the effect of the call. Only stepping by
13903 a single instruction using @code{stepi} or @code{nexti} does not do
13904 this; single instruction steps always show the inlined body.
13905
13906 There are some ways that @value{GDBN} does not pretend that inlined
13907 function calls are the same as normal calls:
13908
13909 @itemize @bullet
13910 @item
13911 Setting breakpoints at the call site of an inlined function may not
13912 work, because the call site does not contain any code. @value{GDBN}
13913 may incorrectly move the breakpoint to the next line of the enclosing
13914 function, after the call. This limitation will be removed in a future
13915 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13916 or inside the inlined function instead.
13917
13918 @item
13919 @value{GDBN} cannot locate the return value of inlined calls after
13920 using the @code{finish} command. This is a limitation of compiler-generated
13921 debugging information; after @code{finish}, you can step to the next line
13922 and print a variable where your program stored the return value.
13923
13924 @end itemize
13925
13926 @node Tail Call Frames
13927 @section Tail Call Frames
13928 @cindex tail call frames, debugging
13929
13930 Function @code{B} can call function @code{C} in its very last statement. In
13931 unoptimized compilation the call of @code{C} is immediately followed by return
13932 instruction at the end of @code{B} code. Optimizing compiler may replace the
13933 call and return in function @code{B} into one jump to function @code{C}
13934 instead. Such use of a jump instruction is called @dfn{tail call}.
13935
13936 During execution of function @code{C}, there will be no indication in the
13937 function call stack frames that it was tail-called from @code{B}. If function
13938 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13939 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13940 some cases @value{GDBN} can determine that @code{C} was tail-called from
13941 @code{B}, and it will then create fictitious call frame for that, with the
13942 return address set up as if @code{B} called @code{C} normally.
13943
13944 This functionality is currently supported only by DWARF 2 debugging format and
13945 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13946 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13947 this information.
13948
13949 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13950 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13951
13952 @smallexample
13953 (gdb) x/i $pc - 2
13954 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13955 (gdb) info frame
13956 Stack level 1, frame at 0x7fffffffda30:
13957 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13958 tail call frame, caller of frame at 0x7fffffffda30
13959 source language c++.
13960 Arglist at unknown address.
13961 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13962 @end smallexample
13963
13964 The detection of all the possible code path executions can find them ambiguous.
13965 There is no execution history stored (possible @ref{Reverse Execution} is never
13966 used for this purpose) and the last known caller could have reached the known
13967 callee by multiple different jump sequences. In such case @value{GDBN} still
13968 tries to show at least all the unambiguous top tail callers and all the
13969 unambiguous bottom tail calees, if any.
13970
13971 @table @code
13972 @anchor{set debug entry-values}
13973 @item set debug entry-values
13974 @kindex set debug entry-values
13975 When set to on, enables printing of analysis messages for both frame argument
13976 values at function entry and tail calls. It will show all the possible valid
13977 tail calls code paths it has considered. It will also print the intersection
13978 of them with the final unambiguous (possibly partial or even empty) code path
13979 result.
13980
13981 @item show debug entry-values
13982 @kindex show debug entry-values
13983 Show the current state of analysis messages printing for both frame argument
13984 values at function entry and tail calls.
13985 @end table
13986
13987 The analysis messages for tail calls can for example show why the virtual tail
13988 call frame for function @code{c} has not been recognized (due to the indirect
13989 reference by variable @code{x}):
13990
13991 @smallexample
13992 static void __attribute__((noinline, noclone)) c (void);
13993 void (*x) (void) = c;
13994 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13995 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13996 int main (void) @{ x (); return 0; @}
13997
13998 Breakpoint 1, DW_OP_entry_value resolving cannot find
13999 DW_TAG_call_site 0x40039a in main
14000 a () at t.c:3
14001 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
14002 (gdb) bt
14003 #0 a () at t.c:3
14004 #1 0x000000000040039a in main () at t.c:5
14005 @end smallexample
14006
14007 Another possibility is an ambiguous virtual tail call frames resolution:
14008
14009 @smallexample
14010 int i;
14011 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
14012 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
14013 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
14014 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
14015 static void __attribute__((noinline, noclone)) b (void)
14016 @{ if (i) c (); else e (); @}
14017 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
14018 int main (void) @{ a (); return 0; @}
14019
14020 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
14021 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
14022 tailcall: reduced: 0x4004d2(a) |
14023 (gdb) bt
14024 #0 f () at t.c:2
14025 #1 0x00000000004004d2 in a () at t.c:8
14026 #2 0x0000000000400395 in main () at t.c:9
14027 @end smallexample
14028
14029 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
14030 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
14031
14032 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
14033 @ifset HAVE_MAKEINFO_CLICK
14034 @set ARROW @click{}
14035 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
14036 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
14037 @end ifset
14038 @ifclear HAVE_MAKEINFO_CLICK
14039 @set ARROW ->
14040 @set CALLSEQ1B @value{CALLSEQ1A}
14041 @set CALLSEQ2B @value{CALLSEQ2A}
14042 @end ifclear
14043
14044 Frames #0 and #2 are real, #1 is a virtual tail call frame.
14045 The code can have possible execution paths @value{CALLSEQ1B} or
14046 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
14047
14048 @code{initial:} state shows some random possible calling sequence @value{GDBN}
14049 has found. It then finds another possible calling sequence - that one is
14050 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
14051 printed as the @code{reduced:} calling sequence. That one could have many
14052 further @code{compare:} and @code{reduced:} statements as long as there remain
14053 any non-ambiguous sequence entries.
14054
14055 For the frame of function @code{b} in both cases there are different possible
14056 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
14057 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
14058 therefore this one is displayed to the user while the ambiguous frames are
14059 omitted.
14060
14061 There can be also reasons why printing of frame argument values at function
14062 entry may fail:
14063
14064 @smallexample
14065 int v;
14066 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
14067 static void __attribute__((noinline, noclone)) a (int i);
14068 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
14069 static void __attribute__((noinline, noclone)) a (int i)
14070 @{ if (i) b (i - 1); else c (0); @}
14071 int main (void) @{ a (5); return 0; @}
14072
14073 (gdb) bt
14074 #0 c (i=i@@entry=0) at t.c:2
14075 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
14076 function "a" at 0x400420 can call itself via tail calls
14077 i=<optimized out>) at t.c:6
14078 #2 0x000000000040036e in main () at t.c:7
14079 @end smallexample
14080
14081 @value{GDBN} cannot find out from the inferior state if and how many times did
14082 function @code{a} call itself (via function @code{b}) as these calls would be
14083 tail calls. Such tail calls would modify the @code{i} variable, therefore
14084 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
14085 prints @code{<optimized out>} instead.
14086
14087 @node Macros
14088 @chapter C Preprocessor Macros
14089
14090 Some languages, such as C and C@t{++}, provide a way to define and invoke
14091 ``preprocessor macros'' which expand into strings of tokens.
14092 @value{GDBN} can evaluate expressions containing macro invocations, show
14093 the result of macro expansion, and show a macro's definition, including
14094 where it was defined.
14095
14096 You may need to compile your program specially to provide @value{GDBN}
14097 with information about preprocessor macros. Most compilers do not
14098 include macros in their debugging information, even when you compile
14099 with the @option{-g} flag. @xref{Compilation}.
14100
14101 A program may define a macro at one point, remove that definition later,
14102 and then provide a different definition after that. Thus, at different
14103 points in the program, a macro may have different definitions, or have
14104 no definition at all. If there is a current stack frame, @value{GDBN}
14105 uses the macros in scope at that frame's source code line. Otherwise,
14106 @value{GDBN} uses the macros in scope at the current listing location;
14107 see @ref{List}.
14108
14109 Whenever @value{GDBN} evaluates an expression, it always expands any
14110 macro invocations present in the expression. @value{GDBN} also provides
14111 the following commands for working with macros explicitly.
14112
14113 @table @code
14114
14115 @kindex macro expand
14116 @cindex macro expansion, showing the results of preprocessor
14117 @cindex preprocessor macro expansion, showing the results of
14118 @cindex expanding preprocessor macros
14119 @item macro expand @var{expression}
14120 @itemx macro exp @var{expression}
14121 Show the results of expanding all preprocessor macro invocations in
14122 @var{expression}. Since @value{GDBN} simply expands macros, but does
14123 not parse the result, @var{expression} need not be a valid expression;
14124 it can be any string of tokens.
14125
14126 @kindex macro exp1
14127 @item macro expand-once @var{expression}
14128 @itemx macro exp1 @var{expression}
14129 @cindex expand macro once
14130 @i{(This command is not yet implemented.)} Show the results of
14131 expanding those preprocessor macro invocations that appear explicitly in
14132 @var{expression}. Macro invocations appearing in that expansion are
14133 left unchanged. This command allows you to see the effect of a
14134 particular macro more clearly, without being confused by further
14135 expansions. Since @value{GDBN} simply expands macros, but does not
14136 parse the result, @var{expression} need not be a valid expression; it
14137 can be any string of tokens.
14138
14139 @kindex info macro
14140 @cindex macro definition, showing
14141 @cindex definition of a macro, showing
14142 @cindex macros, from debug info
14143 @item info macro [-a|-all] [--] @var{macro}
14144 Show the current definition or all definitions of the named @var{macro},
14145 and describe the source location or compiler command-line where that
14146 definition was established. The optional double dash is to signify the end of
14147 argument processing and the beginning of @var{macro} for non C-like macros where
14148 the macro may begin with a hyphen.
14149
14150 @kindex info macros
14151 @item info macros @var{location}
14152 Show all macro definitions that are in effect at the location specified
14153 by @var{location}, and describe the source location or compiler
14154 command-line where those definitions were established.
14155
14156 @kindex macro define
14157 @cindex user-defined macros
14158 @cindex defining macros interactively
14159 @cindex macros, user-defined
14160 @item macro define @var{macro} @var{replacement-list}
14161 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
14162 Introduce a definition for a preprocessor macro named @var{macro},
14163 invocations of which are replaced by the tokens given in
14164 @var{replacement-list}. The first form of this command defines an
14165 ``object-like'' macro, which takes no arguments; the second form
14166 defines a ``function-like'' macro, which takes the arguments given in
14167 @var{arglist}.
14168
14169 A definition introduced by this command is in scope in every
14170 expression evaluated in @value{GDBN}, until it is removed with the
14171 @code{macro undef} command, described below. The definition overrides
14172 all definitions for @var{macro} present in the program being debugged,
14173 as well as any previous user-supplied definition.
14174
14175 @kindex macro undef
14176 @item macro undef @var{macro}
14177 Remove any user-supplied definition for the macro named @var{macro}.
14178 This command only affects definitions provided with the @code{macro
14179 define} command, described above; it cannot remove definitions present
14180 in the program being debugged.
14181
14182 @kindex macro list
14183 @item macro list
14184 List all the macros defined using the @code{macro define} command.
14185 @end table
14186
14187 @cindex macros, example of debugging with
14188 Here is a transcript showing the above commands in action. First, we
14189 show our source files:
14190
14191 @smallexample
14192 $ cat sample.c
14193 #include <stdio.h>
14194 #include "sample.h"
14195
14196 #define M 42
14197 #define ADD(x) (M + x)
14198
14199 main ()
14200 @{
14201 #define N 28
14202 printf ("Hello, world!\n");
14203 #undef N
14204 printf ("We're so creative.\n");
14205 #define N 1729
14206 printf ("Goodbye, world!\n");
14207 @}
14208 $ cat sample.h
14209 #define Q <
14210 $
14211 @end smallexample
14212
14213 Now, we compile the program using the @sc{gnu} C compiler,
14214 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14215 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14216 and @option{-gdwarf-4}; we recommend always choosing the most recent
14217 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14218 includes information about preprocessor macros in the debugging
14219 information.
14220
14221 @smallexample
14222 $ gcc -gdwarf-2 -g3 sample.c -o sample
14223 $
14224 @end smallexample
14225
14226 Now, we start @value{GDBN} on our sample program:
14227
14228 @smallexample
14229 $ gdb -nw sample
14230 GNU gdb 2002-05-06-cvs
14231 Copyright 2002 Free Software Foundation, Inc.
14232 GDB is free software, @dots{}
14233 (@value{GDBP})
14234 @end smallexample
14235
14236 We can expand macros and examine their definitions, even when the
14237 program is not running. @value{GDBN} uses the current listing position
14238 to decide which macro definitions are in scope:
14239
14240 @smallexample
14241 (@value{GDBP}) list main
14242 3
14243 4 #define M 42
14244 5 #define ADD(x) (M + x)
14245 6
14246 7 main ()
14247 8 @{
14248 9 #define N 28
14249 10 printf ("Hello, world!\n");
14250 11 #undef N
14251 12 printf ("We're so creative.\n");
14252 (@value{GDBP}) info macro ADD
14253 Defined at /home/jimb/gdb/macros/play/sample.c:5
14254 #define ADD(x) (M + x)
14255 (@value{GDBP}) info macro Q
14256 Defined at /home/jimb/gdb/macros/play/sample.h:1
14257 included at /home/jimb/gdb/macros/play/sample.c:2
14258 #define Q <
14259 (@value{GDBP}) macro expand ADD(1)
14260 expands to: (42 + 1)
14261 (@value{GDBP}) macro expand-once ADD(1)
14262 expands to: once (M + 1)
14263 (@value{GDBP})
14264 @end smallexample
14265
14266 In the example above, note that @code{macro expand-once} expands only
14267 the macro invocation explicit in the original text --- the invocation of
14268 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14269 which was introduced by @code{ADD}.
14270
14271 Once the program is running, @value{GDBN} uses the macro definitions in
14272 force at the source line of the current stack frame:
14273
14274 @smallexample
14275 (@value{GDBP}) break main
14276 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14277 (@value{GDBP}) run
14278 Starting program: /home/jimb/gdb/macros/play/sample
14279
14280 Breakpoint 1, main () at sample.c:10
14281 10 printf ("Hello, world!\n");
14282 (@value{GDBP})
14283 @end smallexample
14284
14285 At line 10, the definition of the macro @code{N} at line 9 is in force:
14286
14287 @smallexample
14288 (@value{GDBP}) info macro N
14289 Defined at /home/jimb/gdb/macros/play/sample.c:9
14290 #define N 28
14291 (@value{GDBP}) macro expand N Q M
14292 expands to: 28 < 42
14293 (@value{GDBP}) print N Q M
14294 $1 = 1
14295 (@value{GDBP})
14296 @end smallexample
14297
14298 As we step over directives that remove @code{N}'s definition, and then
14299 give it a new definition, @value{GDBN} finds the definition (or lack
14300 thereof) in force at each point:
14301
14302 @smallexample
14303 (@value{GDBP}) next
14304 Hello, world!
14305 12 printf ("We're so creative.\n");
14306 (@value{GDBP}) info macro N
14307 The symbol `N' has no definition as a C/C++ preprocessor macro
14308 at /home/jimb/gdb/macros/play/sample.c:12
14309 (@value{GDBP}) next
14310 We're so creative.
14311 14 printf ("Goodbye, world!\n");
14312 (@value{GDBP}) info macro N
14313 Defined at /home/jimb/gdb/macros/play/sample.c:13
14314 #define N 1729
14315 (@value{GDBP}) macro expand N Q M
14316 expands to: 1729 < 42
14317 (@value{GDBP}) print N Q M
14318 $2 = 0
14319 (@value{GDBP})
14320 @end smallexample
14321
14322 In addition to source files, macros can be defined on the compilation command
14323 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14324 such a way, @value{GDBN} displays the location of their definition as line zero
14325 of the source file submitted to the compiler.
14326
14327 @smallexample
14328 (@value{GDBP}) info macro __STDC__
14329 Defined at /home/jimb/gdb/macros/play/sample.c:0
14330 -D__STDC__=1
14331 (@value{GDBP})
14332 @end smallexample
14333
14334
14335 @node Tracepoints
14336 @chapter Tracepoints
14337 @c This chapter is based on the documentation written by Michael
14338 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14339
14340 @cindex tracepoints
14341 In some applications, it is not feasible for the debugger to interrupt
14342 the program's execution long enough for the developer to learn
14343 anything helpful about its behavior. If the program's correctness
14344 depends on its real-time behavior, delays introduced by a debugger
14345 might cause the program to change its behavior drastically, or perhaps
14346 fail, even when the code itself is correct. It is useful to be able
14347 to observe the program's behavior without interrupting it.
14348
14349 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14350 specify locations in the program, called @dfn{tracepoints}, and
14351 arbitrary expressions to evaluate when those tracepoints are reached.
14352 Later, using the @code{tfind} command, you can examine the values
14353 those expressions had when the program hit the tracepoints. The
14354 expressions may also denote objects in memory---structures or arrays,
14355 for example---whose values @value{GDBN} should record; while visiting
14356 a particular tracepoint, you may inspect those objects as if they were
14357 in memory at that moment. However, because @value{GDBN} records these
14358 values without interacting with you, it can do so quickly and
14359 unobtrusively, hopefully not disturbing the program's behavior.
14360
14361 The tracepoint facility is currently available only for remote
14362 targets. @xref{Targets}. In addition, your remote target must know
14363 how to collect trace data. This functionality is implemented in the
14364 remote stub; however, none of the stubs distributed with @value{GDBN}
14365 support tracepoints as of this writing. The format of the remote
14366 packets used to implement tracepoints are described in @ref{Tracepoint
14367 Packets}.
14368
14369 It is also possible to get trace data from a file, in a manner reminiscent
14370 of corefiles; you specify the filename, and use @code{tfind} to search
14371 through the file. @xref{Trace Files}, for more details.
14372
14373 This chapter describes the tracepoint commands and features.
14374
14375 @menu
14376 * Set Tracepoints::
14377 * Analyze Collected Data::
14378 * Tracepoint Variables::
14379 * Trace Files::
14380 @end menu
14381
14382 @node Set Tracepoints
14383 @section Commands to Set Tracepoints
14384
14385 Before running such a @dfn{trace experiment}, an arbitrary number of
14386 tracepoints can be set. A tracepoint is actually a special type of
14387 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14388 standard breakpoint commands. For instance, as with breakpoints,
14389 tracepoint numbers are successive integers starting from one, and many
14390 of the commands associated with tracepoints take the tracepoint number
14391 as their argument, to identify which tracepoint to work on.
14392
14393 For each tracepoint, you can specify, in advance, some arbitrary set
14394 of data that you want the target to collect in the trace buffer when
14395 it hits that tracepoint. The collected data can include registers,
14396 local variables, or global data. Later, you can use @value{GDBN}
14397 commands to examine the values these data had at the time the
14398 tracepoint was hit.
14399
14400 Tracepoints do not support every breakpoint feature. Ignore counts on
14401 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14402 commands when they are hit. Tracepoints may not be thread-specific
14403 either.
14404
14405 @cindex fast tracepoints
14406 Some targets may support @dfn{fast tracepoints}, which are inserted in
14407 a different way (such as with a jump instead of a trap), that is
14408 faster but possibly restricted in where they may be installed.
14409
14410 @cindex static tracepoints
14411 @cindex markers, static tracepoints
14412 @cindex probing markers, static tracepoints
14413 Regular and fast tracepoints are dynamic tracing facilities, meaning
14414 that they can be used to insert tracepoints at (almost) any location
14415 in the target. Some targets may also support controlling @dfn{static
14416 tracepoints} from @value{GDBN}. With static tracing, a set of
14417 instrumentation points, also known as @dfn{markers}, are embedded in
14418 the target program, and can be activated or deactivated by name or
14419 address. These are usually placed at locations which facilitate
14420 investigating what the target is actually doing. @value{GDBN}'s
14421 support for static tracing includes being able to list instrumentation
14422 points, and attach them with @value{GDBN} defined high level
14423 tracepoints that expose the whole range of convenience of
14424 @value{GDBN}'s tracepoints support. Namely, support for collecting
14425 registers values and values of global or local (to the instrumentation
14426 point) variables; tracepoint conditions and trace state variables.
14427 The act of installing a @value{GDBN} static tracepoint on an
14428 instrumentation point, or marker, is referred to as @dfn{probing} a
14429 static tracepoint marker.
14430
14431 @code{gdbserver} supports tracepoints on some target systems.
14432 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14433
14434 This section describes commands to set tracepoints and associated
14435 conditions and actions.
14436
14437 @menu
14438 * Create and Delete Tracepoints::
14439 * Enable and Disable Tracepoints::
14440 * Tracepoint Passcounts::
14441 * Tracepoint Conditions::
14442 * Trace State Variables::
14443 * Tracepoint Actions::
14444 * Listing Tracepoints::
14445 * Listing Static Tracepoint Markers::
14446 * Starting and Stopping Trace Experiments::
14447 * Tracepoint Restrictions::
14448 @end menu
14449
14450 @node Create and Delete Tracepoints
14451 @subsection Create and Delete Tracepoints
14452
14453 @table @code
14454 @cindex set tracepoint
14455 @kindex trace
14456 @item trace @var{location}
14457 The @code{trace} command is very similar to the @code{break} command.
14458 Its argument @var{location} can be any valid location.
14459 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14460 which is a point in the target program where the debugger will briefly stop,
14461 collect some data, and then allow the program to continue. Setting a tracepoint
14462 or changing its actions takes effect immediately if the remote stub
14463 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14464 in tracing}).
14465 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14466 these changes don't take effect until the next @code{tstart}
14467 command, and once a trace experiment is running, further changes will
14468 not have any effect until the next trace experiment starts. In addition,
14469 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14470 address is not yet resolved. (This is similar to pending breakpoints.)
14471 Pending tracepoints are not downloaded to the target and not installed
14472 until they are resolved. The resolution of pending tracepoints requires
14473 @value{GDBN} support---when debugging with the remote target, and
14474 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14475 tracing}), pending tracepoints can not be resolved (and downloaded to
14476 the remote stub) while @value{GDBN} is disconnected.
14477
14478 Here are some examples of using the @code{trace} command:
14479
14480 @smallexample
14481 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14482
14483 (@value{GDBP}) @b{trace +2} // 2 lines forward
14484
14485 (@value{GDBP}) @b{trace my_function} // first source line of function
14486
14487 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14488
14489 (@value{GDBP}) @b{trace *0x2117c4} // an address
14490 @end smallexample
14491
14492 @noindent
14493 You can abbreviate @code{trace} as @code{tr}.
14494
14495 @item trace @var{location} if @var{cond}
14496 Set a tracepoint with condition @var{cond}; evaluate the expression
14497 @var{cond} each time the tracepoint is reached, and collect data only
14498 if the value is nonzero---that is, if @var{cond} evaluates as true.
14499 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14500 information on tracepoint conditions.
14501
14502 @item ftrace @var{location} [ if @var{cond} ]
14503 @cindex set fast tracepoint
14504 @cindex fast tracepoints, setting
14505 @kindex ftrace
14506 The @code{ftrace} command sets a fast tracepoint. For targets that
14507 support them, fast tracepoints will use a more efficient but possibly
14508 less general technique to trigger data collection, such as a jump
14509 instruction instead of a trap, or some sort of hardware support. It
14510 may not be possible to create a fast tracepoint at the desired
14511 location, in which case the command will exit with an explanatory
14512 message.
14513
14514 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14515 @code{trace}.
14516
14517 On 32-bit x86-architecture systems, fast tracepoints normally need to
14518 be placed at an instruction that is 5 bytes or longer, but can be
14519 placed at 4-byte instructions if the low 64K of memory of the target
14520 program is available to install trampolines. Some Unix-type systems,
14521 such as @sc{gnu}/Linux, exclude low addresses from the program's
14522 address space; but for instance with the Linux kernel it is possible
14523 to let @value{GDBN} use this area by doing a @command{sysctl} command
14524 to set the @code{mmap_min_addr} kernel parameter, as in
14525
14526 @example
14527 sudo sysctl -w vm.mmap_min_addr=32768
14528 @end example
14529
14530 @noindent
14531 which sets the low address to 32K, which leaves plenty of room for
14532 trampolines. The minimum address should be set to a page boundary.
14533
14534 @item strace @var{location} [ if @var{cond} ]
14535 @cindex set static tracepoint
14536 @cindex static tracepoints, setting
14537 @cindex probe static tracepoint marker
14538 @kindex strace
14539 The @code{strace} command sets a static tracepoint. For targets that
14540 support it, setting a static tracepoint probes a static
14541 instrumentation point, or marker, found at @var{location}. It may not
14542 be possible to set a static tracepoint at the desired location, in
14543 which case the command will exit with an explanatory message.
14544
14545 @value{GDBN} handles arguments to @code{strace} exactly as for
14546 @code{trace}, with the addition that the user can also specify
14547 @code{-m @var{marker}} as @var{location}. This probes the marker
14548 identified by the @var{marker} string identifier. This identifier
14549 depends on the static tracepoint backend library your program is
14550 using. You can find all the marker identifiers in the @samp{ID} field
14551 of the @code{info static-tracepoint-markers} command output.
14552 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14553 Markers}. For example, in the following small program using the UST
14554 tracing engine:
14555
14556 @smallexample
14557 main ()
14558 @{
14559 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14560 @}
14561 @end smallexample
14562
14563 @noindent
14564 the marker id is composed of joining the first two arguments to the
14565 @code{trace_mark} call with a slash, which translates to:
14566
14567 @smallexample
14568 (@value{GDBP}) info static-tracepoint-markers
14569 Cnt Enb ID Address What
14570 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14571 Data: "str %s"
14572 [etc...]
14573 @end smallexample
14574
14575 @noindent
14576 so you may probe the marker above with:
14577
14578 @smallexample
14579 (@value{GDBP}) strace -m ust/bar33
14580 @end smallexample
14581
14582 Static tracepoints accept an extra collect action --- @code{collect
14583 $_sdata}. This collects arbitrary user data passed in the probe point
14584 call to the tracing library. In the UST example above, you'll see
14585 that the third argument to @code{trace_mark} is a printf-like format
14586 string. The user data is then the result of running that formatting
14587 string against the following arguments. Note that @code{info
14588 static-tracepoint-markers} command output lists that format string in
14589 the @samp{Data:} field.
14590
14591 You can inspect this data when analyzing the trace buffer, by printing
14592 the $_sdata variable like any other variable available to
14593 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14594
14595 @vindex $tpnum
14596 @cindex last tracepoint number
14597 @cindex recent tracepoint number
14598 @cindex tracepoint number
14599 The convenience variable @code{$tpnum} records the tracepoint number
14600 of the most recently set tracepoint.
14601
14602 @kindex delete tracepoint
14603 @cindex tracepoint deletion
14604 @item delete tracepoint @r{[}@var{num}@r{]}
14605 Permanently delete one or more tracepoints. With no argument, the
14606 default is to delete all tracepoints. Note that the regular
14607 @code{delete} command can remove tracepoints also.
14608
14609 Examples:
14610
14611 @smallexample
14612 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14613
14614 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14615 @end smallexample
14616
14617 @noindent
14618 You can abbreviate this command as @code{del tr}.
14619 @end table
14620
14621 @node Enable and Disable Tracepoints
14622 @subsection Enable and Disable Tracepoints
14623
14624 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14625
14626 @table @code
14627 @kindex disable tracepoint
14628 @item disable tracepoint @r{[}@var{num}@r{]}
14629 Disable tracepoint @var{num}, or all tracepoints if no argument
14630 @var{num} is given. A disabled tracepoint will have no effect during
14631 a trace experiment, but it is not forgotten. You can re-enable
14632 a disabled tracepoint using the @code{enable tracepoint} command.
14633 If the command is issued during a trace experiment and the debug target
14634 has support for disabling tracepoints during a trace experiment, then the
14635 change will be effective immediately. Otherwise, it will be applied to the
14636 next trace experiment.
14637
14638 @kindex enable tracepoint
14639 @item enable tracepoint @r{[}@var{num}@r{]}
14640 Enable tracepoint @var{num}, or all tracepoints. If this command is
14641 issued during a trace experiment and the debug target supports enabling
14642 tracepoints during a trace experiment, then the enabled tracepoints will
14643 become effective immediately. Otherwise, they will become effective the
14644 next time a trace experiment is run.
14645 @end table
14646
14647 @node Tracepoint Passcounts
14648 @subsection Tracepoint Passcounts
14649
14650 @table @code
14651 @kindex passcount
14652 @cindex tracepoint pass count
14653 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14654 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14655 automatically stop a trace experiment. If a tracepoint's passcount is
14656 @var{n}, then the trace experiment will be automatically stopped on
14657 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14658 @var{num} is not specified, the @code{passcount} command sets the
14659 passcount of the most recently defined tracepoint. If no passcount is
14660 given, the trace experiment will run until stopped explicitly by the
14661 user.
14662
14663 Examples:
14664
14665 @smallexample
14666 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14667 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14668
14669 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14670 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14671 (@value{GDBP}) @b{trace foo}
14672 (@value{GDBP}) @b{pass 3}
14673 (@value{GDBP}) @b{trace bar}
14674 (@value{GDBP}) @b{pass 2}
14675 (@value{GDBP}) @b{trace baz}
14676 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14677 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14678 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14679 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14680 @end smallexample
14681 @end table
14682
14683 @node Tracepoint Conditions
14684 @subsection Tracepoint Conditions
14685 @cindex conditional tracepoints
14686 @cindex tracepoint conditions
14687
14688 The simplest sort of tracepoint collects data every time your program
14689 reaches a specified place. You can also specify a @dfn{condition} for
14690 a tracepoint. A condition is just a Boolean expression in your
14691 programming language (@pxref{Expressions, ,Expressions}). A
14692 tracepoint with a condition evaluates the expression each time your
14693 program reaches it, and data collection happens only if the condition
14694 is true.
14695
14696 Tracepoint conditions can be specified when a tracepoint is set, by
14697 using @samp{if} in the arguments to the @code{trace} command.
14698 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14699 also be set or changed at any time with the @code{condition} command,
14700 just as with breakpoints.
14701
14702 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14703 the conditional expression itself. Instead, @value{GDBN} encodes the
14704 expression into an agent expression (@pxref{Agent Expressions})
14705 suitable for execution on the target, independently of @value{GDBN}.
14706 Global variables become raw memory locations, locals become stack
14707 accesses, and so forth.
14708
14709 For instance, suppose you have a function that is usually called
14710 frequently, but should not be called after an error has occurred. You
14711 could use the following tracepoint command to collect data about calls
14712 of that function that happen while the error code is propagating
14713 through the program; an unconditional tracepoint could end up
14714 collecting thousands of useless trace frames that you would have to
14715 search through.
14716
14717 @smallexample
14718 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14719 @end smallexample
14720
14721 @node Trace State Variables
14722 @subsection Trace State Variables
14723 @cindex trace state variables
14724
14725 A @dfn{trace state variable} is a special type of variable that is
14726 created and managed by target-side code. The syntax is the same as
14727 that for GDB's convenience variables (a string prefixed with ``$''),
14728 but they are stored on the target. They must be created explicitly,
14729 using a @code{tvariable} command. They are always 64-bit signed
14730 integers.
14731
14732 Trace state variables are remembered by @value{GDBN}, and downloaded
14733 to the target along with tracepoint information when the trace
14734 experiment starts. There are no intrinsic limits on the number of
14735 trace state variables, beyond memory limitations of the target.
14736
14737 @cindex convenience variables, and trace state variables
14738 Although trace state variables are managed by the target, you can use
14739 them in print commands and expressions as if they were convenience
14740 variables; @value{GDBN} will get the current value from the target
14741 while the trace experiment is running. Trace state variables share
14742 the same namespace as other ``$'' variables, which means that you
14743 cannot have trace state variables with names like @code{$23} or
14744 @code{$pc}, nor can you have a trace state variable and a convenience
14745 variable with the same name.
14746
14747 @table @code
14748
14749 @item tvariable $@var{name} [ = @var{expression} ]
14750 @kindex tvariable
14751 The @code{tvariable} command creates a new trace state variable named
14752 @code{$@var{name}}, and optionally gives it an initial value of
14753 @var{expression}. The @var{expression} is evaluated when this command is
14754 entered; the result will be converted to an integer if possible,
14755 otherwise @value{GDBN} will report an error. A subsequent
14756 @code{tvariable} command specifying the same name does not create a
14757 variable, but instead assigns the supplied initial value to the
14758 existing variable of that name, overwriting any previous initial
14759 value. The default initial value is 0.
14760
14761 @item info tvariables
14762 @kindex info tvariables
14763 List all the trace state variables along with their initial values.
14764 Their current values may also be displayed, if the trace experiment is
14765 currently running.
14766
14767 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14768 @kindex delete tvariable
14769 Delete the given trace state variables, or all of them if no arguments
14770 are specified.
14771
14772 @end table
14773
14774 @node Tracepoint Actions
14775 @subsection Tracepoint Action Lists
14776
14777 @table @code
14778 @kindex actions
14779 @cindex tracepoint actions
14780 @item actions @r{[}@var{num}@r{]}
14781 This command will prompt for a list of actions to be taken when the
14782 tracepoint is hit. If the tracepoint number @var{num} is not
14783 specified, this command sets the actions for the one that was most
14784 recently defined (so that you can define a tracepoint and then say
14785 @code{actions} without bothering about its number). You specify the
14786 actions themselves on the following lines, one action at a time, and
14787 terminate the actions list with a line containing just @code{end}. So
14788 far, the only defined actions are @code{collect}, @code{teval}, and
14789 @code{while-stepping}.
14790
14791 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14792 Commands, ,Breakpoint Command Lists}), except that only the defined
14793 actions are allowed; any other @value{GDBN} command is rejected.
14794
14795 @cindex remove actions from a tracepoint
14796 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14797 and follow it immediately with @samp{end}.
14798
14799 @smallexample
14800 (@value{GDBP}) @b{collect @var{data}} // collect some data
14801
14802 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14803
14804 (@value{GDBP}) @b{end} // signals the end of actions.
14805 @end smallexample
14806
14807 In the following example, the action list begins with @code{collect}
14808 commands indicating the things to be collected when the tracepoint is
14809 hit. Then, in order to single-step and collect additional data
14810 following the tracepoint, a @code{while-stepping} command is used,
14811 followed by the list of things to be collected after each step in a
14812 sequence of single steps. The @code{while-stepping} command is
14813 terminated by its own separate @code{end} command. Lastly, the action
14814 list is terminated by an @code{end} command.
14815
14816 @smallexample
14817 (@value{GDBP}) @b{trace foo}
14818 (@value{GDBP}) @b{actions}
14819 Enter actions for tracepoint 1, one per line:
14820 > collect bar,baz
14821 > collect $regs
14822 > while-stepping 12
14823 > collect $pc, arr[i]
14824 > end
14825 end
14826 @end smallexample
14827
14828 @kindex collect @r{(tracepoints)}
14829 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14830 Collect values of the given expressions when the tracepoint is hit.
14831 This command accepts a comma-separated list of any valid expressions.
14832 In addition to global, static, or local variables, the following
14833 special arguments are supported:
14834
14835 @table @code
14836 @item $regs
14837 Collect all registers.
14838
14839 @item $args
14840 Collect all function arguments.
14841
14842 @item $locals
14843 Collect all local variables.
14844
14845 @item $_ret
14846 Collect the return address. This is helpful if you want to see more
14847 of a backtrace.
14848
14849 @emph{Note:} The return address location can not always be reliably
14850 determined up front, and the wrong address / registers may end up
14851 collected instead. On some architectures the reliability is higher
14852 for tracepoints at function entry, while on others it's the opposite.
14853 When this happens, backtracing will stop because the return address is
14854 found unavailable (unless another collect rule happened to match it).
14855
14856 @item $_probe_argc
14857 Collects the number of arguments from the static probe at which the
14858 tracepoint is located.
14859 @xref{Static Probe Points}.
14860
14861 @item $_probe_arg@var{n}
14862 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14863 from the static probe at which the tracepoint is located.
14864 @xref{Static Probe Points}.
14865
14866 @item $_sdata
14867 @vindex $_sdata@r{, collect}
14868 Collect static tracepoint marker specific data. Only available for
14869 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14870 Lists}. On the UST static tracepoints library backend, an
14871 instrumentation point resembles a @code{printf} function call. The
14872 tracing library is able to collect user specified data formatted to a
14873 character string using the format provided by the programmer that
14874 instrumented the program. Other backends have similar mechanisms.
14875 Here's an example of a UST marker call:
14876
14877 @smallexample
14878 const char master_name[] = "$your_name";
14879 trace_mark(channel1, marker1, "hello %s", master_name)
14880 @end smallexample
14881
14882 In this case, collecting @code{$_sdata} collects the string
14883 @samp{hello $yourname}. When analyzing the trace buffer, you can
14884 inspect @samp{$_sdata} like any other variable available to
14885 @value{GDBN}.
14886 @end table
14887
14888 You can give several consecutive @code{collect} commands, each one
14889 with a single argument, or one @code{collect} command with several
14890 arguments separated by commas; the effect is the same.
14891
14892 The optional @var{mods} changes the usual handling of the arguments.
14893 @code{s} requests that pointers to chars be handled as strings, in
14894 particular collecting the contents of the memory being pointed at, up
14895 to the first zero. The upper bound is by default the value of the
14896 @code{print elements} variable; if @code{s} is followed by a decimal
14897 number, that is the upper bound instead. So for instance
14898 @samp{collect/s25 mystr} collects as many as 25 characters at
14899 @samp{mystr}.
14900
14901 The command @code{info scope} (@pxref{Symbols, info scope}) is
14902 particularly useful for figuring out what data to collect.
14903
14904 @kindex teval @r{(tracepoints)}
14905 @item teval @var{expr1}, @var{expr2}, @dots{}
14906 Evaluate the given expressions when the tracepoint is hit. This
14907 command accepts a comma-separated list of expressions. The results
14908 are discarded, so this is mainly useful for assigning values to trace
14909 state variables (@pxref{Trace State Variables}) without adding those
14910 values to the trace buffer, as would be the case if the @code{collect}
14911 action were used.
14912
14913 @kindex while-stepping @r{(tracepoints)}
14914 @item while-stepping @var{n}
14915 Perform @var{n} single-step instruction traces after the tracepoint,
14916 collecting new data after each step. The @code{while-stepping}
14917 command is followed by the list of what to collect while stepping
14918 (followed by its own @code{end} command):
14919
14920 @smallexample
14921 > while-stepping 12
14922 > collect $regs, myglobal
14923 > end
14924 >
14925 @end smallexample
14926
14927 @noindent
14928 Note that @code{$pc} is not automatically collected by
14929 @code{while-stepping}; you need to explicitly collect that register if
14930 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14931 @code{stepping}.
14932
14933 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14934 @kindex set default-collect
14935 @cindex default collection action
14936 This variable is a list of expressions to collect at each tracepoint
14937 hit. It is effectively an additional @code{collect} action prepended
14938 to every tracepoint action list. The expressions are parsed
14939 individually for each tracepoint, so for instance a variable named
14940 @code{xyz} may be interpreted as a global for one tracepoint, and a
14941 local for another, as appropriate to the tracepoint's location.
14942
14943 @item show default-collect
14944 @kindex show default-collect
14945 Show the list of expressions that are collected by default at each
14946 tracepoint hit.
14947
14948 @end table
14949
14950 @node Listing Tracepoints
14951 @subsection Listing Tracepoints
14952
14953 @table @code
14954 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14955 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14956 @cindex information about tracepoints
14957 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14958 Display information about the tracepoint @var{num}. If you don't
14959 specify a tracepoint number, displays information about all the
14960 tracepoints defined so far. The format is similar to that used for
14961 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14962 command, simply restricting itself to tracepoints.
14963
14964 A tracepoint's listing may include additional information specific to
14965 tracing:
14966
14967 @itemize @bullet
14968 @item
14969 its passcount as given by the @code{passcount @var{n}} command
14970
14971 @item
14972 the state about installed on target of each location
14973 @end itemize
14974
14975 @smallexample
14976 (@value{GDBP}) @b{info trace}
14977 Num Type Disp Enb Address What
14978 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14979 while-stepping 20
14980 collect globfoo, $regs
14981 end
14982 collect globfoo2
14983 end
14984 pass count 1200
14985 2 tracepoint keep y <MULTIPLE>
14986 collect $eip
14987 2.1 y 0x0804859c in func4 at change-loc.h:35
14988 installed on target
14989 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14990 installed on target
14991 2.3 y <PENDING> set_tracepoint
14992 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14993 not installed on target
14994 (@value{GDBP})
14995 @end smallexample
14996
14997 @noindent
14998 This command can be abbreviated @code{info tp}.
14999 @end table
15000
15001 @node Listing Static Tracepoint Markers
15002 @subsection Listing Static Tracepoint Markers
15003
15004 @table @code
15005 @kindex info static-tracepoint-markers
15006 @cindex information about static tracepoint markers
15007 @item info static-tracepoint-markers
15008 Display information about all static tracepoint markers defined in the
15009 program.
15010
15011 For each marker, the following columns are printed:
15012
15013 @table @emph
15014 @item Count
15015 An incrementing counter, output to help readability. This is not a
15016 stable identifier.
15017 @item ID
15018 The marker ID, as reported by the target.
15019 @item Enabled or Disabled
15020 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
15021 that are not enabled.
15022 @item Address
15023 Where the marker is in your program, as a memory address.
15024 @item What
15025 Where the marker is in the source for your program, as a file and line
15026 number. If the debug information included in the program does not
15027 allow @value{GDBN} to locate the source of the marker, this column
15028 will be left blank.
15029 @end table
15030
15031 @noindent
15032 In addition, the following information may be printed for each marker:
15033
15034 @table @emph
15035 @item Data
15036 User data passed to the tracing library by the marker call. In the
15037 UST backend, this is the format string passed as argument to the
15038 marker call.
15039 @item Static tracepoints probing the marker
15040 The list of static tracepoints attached to the marker.
15041 @end table
15042
15043 @smallexample
15044 (@value{GDBP}) info static-tracepoint-markers
15045 Cnt ID Enb Address What
15046 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
15047 Data: number1 %d number2 %d
15048 Probed by static tracepoints: #2
15049 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
15050 Data: str %s
15051 (@value{GDBP})
15052 @end smallexample
15053 @end table
15054
15055 @node Starting and Stopping Trace Experiments
15056 @subsection Starting and Stopping Trace Experiments
15057
15058 @table @code
15059 @kindex tstart [ @var{notes} ]
15060 @cindex start a new trace experiment
15061 @cindex collected data discarded
15062 @item tstart
15063 This command starts the trace experiment, and begins collecting data.
15064 It has the side effect of discarding all the data collected in the
15065 trace buffer during the previous trace experiment. If any arguments
15066 are supplied, they are taken as a note and stored with the trace
15067 experiment's state. The notes may be arbitrary text, and are
15068 especially useful with disconnected tracing in a multi-user context;
15069 the notes can explain what the trace is doing, supply user contact
15070 information, and so forth.
15071
15072 @kindex tstop [ @var{notes} ]
15073 @cindex stop a running trace experiment
15074 @item tstop
15075 This command stops the trace experiment. If any arguments are
15076 supplied, they are recorded with the experiment as a note. This is
15077 useful if you are stopping a trace started by someone else, for
15078 instance if the trace is interfering with the system's behavior and
15079 needs to be stopped quickly.
15080
15081 @strong{Note}: a trace experiment and data collection may stop
15082 automatically if any tracepoint's passcount is reached
15083 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
15084
15085 @kindex tstatus
15086 @cindex status of trace data collection
15087 @cindex trace experiment, status of
15088 @item tstatus
15089 This command displays the status of the current trace data
15090 collection.
15091 @end table
15092
15093 Here is an example of the commands we described so far:
15094
15095 @smallexample
15096 (@value{GDBP}) @b{trace gdb_c_test}
15097 (@value{GDBP}) @b{actions}
15098 Enter actions for tracepoint #1, one per line.
15099 > collect $regs,$locals,$args
15100 > while-stepping 11
15101 > collect $regs
15102 > end
15103 > end
15104 (@value{GDBP}) @b{tstart}
15105 [time passes @dots{}]
15106 (@value{GDBP}) @b{tstop}
15107 @end smallexample
15108
15109 @anchor{disconnected tracing}
15110 @cindex disconnected tracing
15111 You can choose to continue running the trace experiment even if
15112 @value{GDBN} disconnects from the target, voluntarily or
15113 involuntarily. For commands such as @code{detach}, the debugger will
15114 ask what you want to do with the trace. But for unexpected
15115 terminations (@value{GDBN} crash, network outage), it would be
15116 unfortunate to lose hard-won trace data, so the variable
15117 @code{disconnected-tracing} lets you decide whether the trace should
15118 continue running without @value{GDBN}.
15119
15120 @table @code
15121 @item set disconnected-tracing on
15122 @itemx set disconnected-tracing off
15123 @kindex set disconnected-tracing
15124 Choose whether a tracing run should continue to run if @value{GDBN}
15125 has disconnected from the target. Note that @code{detach} or
15126 @code{quit} will ask you directly what to do about a running trace no
15127 matter what this variable's setting, so the variable is mainly useful
15128 for handling unexpected situations, such as loss of the network.
15129
15130 @item show disconnected-tracing
15131 @kindex show disconnected-tracing
15132 Show the current choice for disconnected tracing.
15133
15134 @end table
15135
15136 When you reconnect to the target, the trace experiment may or may not
15137 still be running; it might have filled the trace buffer in the
15138 meantime, or stopped for one of the other reasons. If it is running,
15139 it will continue after reconnection.
15140
15141 Upon reconnection, the target will upload information about the
15142 tracepoints in effect. @value{GDBN} will then compare that
15143 information to the set of tracepoints currently defined, and attempt
15144 to match them up, allowing for the possibility that the numbers may
15145 have changed due to creation and deletion in the meantime. If one of
15146 the target's tracepoints does not match any in @value{GDBN}, the
15147 debugger will create a new tracepoint, so that you have a number with
15148 which to specify that tracepoint. This matching-up process is
15149 necessarily heuristic, and it may result in useless tracepoints being
15150 created; you may simply delete them if they are of no use.
15151
15152 @cindex circular trace buffer
15153 If your target agent supports a @dfn{circular trace buffer}, then you
15154 can run a trace experiment indefinitely without filling the trace
15155 buffer; when space runs out, the agent deletes already-collected trace
15156 frames, oldest first, until there is enough room to continue
15157 collecting. This is especially useful if your tracepoints are being
15158 hit too often, and your trace gets terminated prematurely because the
15159 buffer is full. To ask for a circular trace buffer, simply set
15160 @samp{circular-trace-buffer} to on. You can set this at any time,
15161 including during tracing; if the agent can do it, it will change
15162 buffer handling on the fly, otherwise it will not take effect until
15163 the next run.
15164
15165 @table @code
15166 @item set circular-trace-buffer on
15167 @itemx set circular-trace-buffer off
15168 @kindex set circular-trace-buffer
15169 Choose whether a tracing run should use a linear or circular buffer
15170 for trace data. A linear buffer will not lose any trace data, but may
15171 fill up prematurely, while a circular buffer will discard old trace
15172 data, but it will have always room for the latest tracepoint hits.
15173
15174 @item show circular-trace-buffer
15175 @kindex show circular-trace-buffer
15176 Show the current choice for the trace buffer. Note that this may not
15177 match the agent's current buffer handling, nor is it guaranteed to
15178 match the setting that might have been in effect during a past run,
15179 for instance if you are looking at frames from a trace file.
15180
15181 @end table
15182
15183 @table @code
15184 @item set trace-buffer-size @var{n}
15185 @itemx set trace-buffer-size unlimited
15186 @kindex set trace-buffer-size
15187 Request that the target use a trace buffer of @var{n} bytes. Not all
15188 targets will honor the request; they may have a compiled-in size for
15189 the trace buffer, or some other limitation. Set to a value of
15190 @code{unlimited} or @code{-1} to let the target use whatever size it
15191 likes. This is also the default.
15192
15193 @item show trace-buffer-size
15194 @kindex show trace-buffer-size
15195 Show the current requested size for the trace buffer. Note that this
15196 will only match the actual size if the target supports size-setting,
15197 and was able to handle the requested size. For instance, if the
15198 target can only change buffer size between runs, this variable will
15199 not reflect the change until the next run starts. Use @code{tstatus}
15200 to get a report of the actual buffer size.
15201 @end table
15202
15203 @table @code
15204 @item set trace-user @var{text}
15205 @kindex set trace-user
15206
15207 @item show trace-user
15208 @kindex show trace-user
15209
15210 @item set trace-notes @var{text}
15211 @kindex set trace-notes
15212 Set the trace run's notes.
15213
15214 @item show trace-notes
15215 @kindex show trace-notes
15216 Show the trace run's notes.
15217
15218 @item set trace-stop-notes @var{text}
15219 @kindex set trace-stop-notes
15220 Set the trace run's stop notes. The handling of the note is as for
15221 @code{tstop} arguments; the set command is convenient way to fix a
15222 stop note that is mistaken or incomplete.
15223
15224 @item show trace-stop-notes
15225 @kindex show trace-stop-notes
15226 Show the trace run's stop notes.
15227
15228 @end table
15229
15230 @node Tracepoint Restrictions
15231 @subsection Tracepoint Restrictions
15232
15233 @cindex tracepoint restrictions
15234 There are a number of restrictions on the use of tracepoints. As
15235 described above, tracepoint data gathering occurs on the target
15236 without interaction from @value{GDBN}. Thus the full capabilities of
15237 the debugger are not available during data gathering, and then at data
15238 examination time, you will be limited by only having what was
15239 collected. The following items describe some common problems, but it
15240 is not exhaustive, and you may run into additional difficulties not
15241 mentioned here.
15242
15243 @itemize @bullet
15244
15245 @item
15246 Tracepoint expressions are intended to gather objects (lvalues). Thus
15247 the full flexibility of GDB's expression evaluator is not available.
15248 You cannot call functions, cast objects to aggregate types, access
15249 convenience variables or modify values (except by assignment to trace
15250 state variables). Some language features may implicitly call
15251 functions (for instance Objective-C fields with accessors), and therefore
15252 cannot be collected either.
15253
15254 @item
15255 Collection of local variables, either individually or in bulk with
15256 @code{$locals} or @code{$args}, during @code{while-stepping} may
15257 behave erratically. The stepping action may enter a new scope (for
15258 instance by stepping into a function), or the location of the variable
15259 may change (for instance it is loaded into a register). The
15260 tracepoint data recorded uses the location information for the
15261 variables that is correct for the tracepoint location. When the
15262 tracepoint is created, it is not possible, in general, to determine
15263 where the steps of a @code{while-stepping} sequence will advance the
15264 program---particularly if a conditional branch is stepped.
15265
15266 @item
15267 Collection of an incompletely-initialized or partially-destroyed object
15268 may result in something that @value{GDBN} cannot display, or displays
15269 in a misleading way.
15270
15271 @item
15272 When @value{GDBN} displays a pointer to character it automatically
15273 dereferences the pointer to also display characters of the string
15274 being pointed to. However, collecting the pointer during tracing does
15275 not automatically collect the string. You need to explicitly
15276 dereference the pointer and provide size information if you want to
15277 collect not only the pointer, but the memory pointed to. For example,
15278 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15279 by @code{ptr}.
15280
15281 @item
15282 It is not possible to collect a complete stack backtrace at a
15283 tracepoint. Instead, you may collect the registers and a few hundred
15284 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15285 (adjust to use the name of the actual stack pointer register on your
15286 target architecture, and the amount of stack you wish to capture).
15287 Then the @code{backtrace} command will show a partial backtrace when
15288 using a trace frame. The number of stack frames that can be examined
15289 depends on the sizes of the frames in the collected stack. Note that
15290 if you ask for a block so large that it goes past the bottom of the
15291 stack, the target agent may report an error trying to read from an
15292 invalid address.
15293
15294 @item
15295 If you do not collect registers at a tracepoint, @value{GDBN} can
15296 infer that the value of @code{$pc} must be the same as the address of
15297 the tracepoint and use that when you are looking at a trace frame
15298 for that tracepoint. However, this cannot work if the tracepoint has
15299 multiple locations (for instance if it was set in a function that was
15300 inlined), or if it has a @code{while-stepping} loop. In those cases
15301 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15302 it to zero.
15303
15304 @end itemize
15305
15306 @node Analyze Collected Data
15307 @section Using the Collected Data
15308
15309 After the tracepoint experiment ends, you use @value{GDBN} commands
15310 for examining the trace data. The basic idea is that each tracepoint
15311 collects a trace @dfn{snapshot} every time it is hit and another
15312 snapshot every time it single-steps. All these snapshots are
15313 consecutively numbered from zero and go into a buffer, and you can
15314 examine them later. The way you examine them is to @dfn{focus} on a
15315 specific trace snapshot. When the remote stub is focused on a trace
15316 snapshot, it will respond to all @value{GDBN} requests for memory and
15317 registers by reading from the buffer which belongs to that snapshot,
15318 rather than from @emph{real} memory or registers of the program being
15319 debugged. This means that @strong{all} @value{GDBN} commands
15320 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15321 behave as if we were currently debugging the program state as it was
15322 when the tracepoint occurred. Any requests for data that are not in
15323 the buffer will fail.
15324
15325 @menu
15326 * tfind:: How to select a trace snapshot
15327 * tdump:: How to display all data for a snapshot
15328 * save tracepoints:: How to save tracepoints for a future run
15329 @end menu
15330
15331 @node tfind
15332 @subsection @code{tfind @var{n}}
15333
15334 @kindex tfind
15335 @cindex select trace snapshot
15336 @cindex find trace snapshot
15337 The basic command for selecting a trace snapshot from the buffer is
15338 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15339 counting from zero. If no argument @var{n} is given, the next
15340 snapshot is selected.
15341
15342 Here are the various forms of using the @code{tfind} command.
15343
15344 @table @code
15345 @item tfind start
15346 Find the first snapshot in the buffer. This is a synonym for
15347 @code{tfind 0} (since 0 is the number of the first snapshot).
15348
15349 @item tfind none
15350 Stop debugging trace snapshots, resume @emph{live} debugging.
15351
15352 @item tfind end
15353 Same as @samp{tfind none}.
15354
15355 @item tfind
15356 No argument means find the next trace snapshot or find the first
15357 one if no trace snapshot is selected.
15358
15359 @item tfind -
15360 Find the previous trace snapshot before the current one. This permits
15361 retracing earlier steps.
15362
15363 @item tfind tracepoint @var{num}
15364 Find the next snapshot associated with tracepoint @var{num}. Search
15365 proceeds forward from the last examined trace snapshot. If no
15366 argument @var{num} is given, it means find the next snapshot collected
15367 for the same tracepoint as the current snapshot.
15368
15369 @item tfind pc @var{addr}
15370 Find the next snapshot associated with the value @var{addr} of the
15371 program counter. Search proceeds forward from the last examined trace
15372 snapshot. If no argument @var{addr} is given, it means find the next
15373 snapshot with the same value of PC as the current snapshot.
15374
15375 @item tfind outside @var{addr1}, @var{addr2}
15376 Find the next snapshot whose PC is outside the given range of
15377 addresses (exclusive).
15378
15379 @item tfind range @var{addr1}, @var{addr2}
15380 Find the next snapshot whose PC is between @var{addr1} and
15381 @var{addr2} (inclusive).
15382
15383 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15384 Find the next snapshot associated with the source line @var{n}. If
15385 the optional argument @var{file} is given, refer to line @var{n} in
15386 that source file. Search proceeds forward from the last examined
15387 trace snapshot. If no argument @var{n} is given, it means find the
15388 next line other than the one currently being examined; thus saying
15389 @code{tfind line} repeatedly can appear to have the same effect as
15390 stepping from line to line in a @emph{live} debugging session.
15391 @end table
15392
15393 The default arguments for the @code{tfind} commands are specifically
15394 designed to make it easy to scan through the trace buffer. For
15395 instance, @code{tfind} with no argument selects the next trace
15396 snapshot, and @code{tfind -} with no argument selects the previous
15397 trace snapshot. So, by giving one @code{tfind} command, and then
15398 simply hitting @key{RET} repeatedly you can examine all the trace
15399 snapshots in order. Or, by saying @code{tfind -} and then hitting
15400 @key{RET} repeatedly you can examine the snapshots in reverse order.
15401 The @code{tfind line} command with no argument selects the snapshot
15402 for the next source line executed. The @code{tfind pc} command with
15403 no argument selects the next snapshot with the same program counter
15404 (PC) as the current frame. The @code{tfind tracepoint} command with
15405 no argument selects the next trace snapshot collected by the same
15406 tracepoint as the current one.
15407
15408 In addition to letting you scan through the trace buffer manually,
15409 these commands make it easy to construct @value{GDBN} scripts that
15410 scan through the trace buffer and print out whatever collected data
15411 you are interested in. Thus, if we want to examine the PC, FP, and SP
15412 registers from each trace frame in the buffer, we can say this:
15413
15414 @smallexample
15415 (@value{GDBP}) @b{tfind start}
15416 (@value{GDBP}) @b{while ($trace_frame != -1)}
15417 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15418 $trace_frame, $pc, $sp, $fp
15419 > tfind
15420 > end
15421
15422 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15423 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15424 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15425 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15426 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15427 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15428 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15429 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15430 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15431 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15432 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15433 @end smallexample
15434
15435 Or, if we want to examine the variable @code{X} at each source line in
15436 the buffer:
15437
15438 @smallexample
15439 (@value{GDBP}) @b{tfind start}
15440 (@value{GDBP}) @b{while ($trace_frame != -1)}
15441 > printf "Frame %d, X == %d\n", $trace_frame, X
15442 > tfind line
15443 > end
15444
15445 Frame 0, X = 1
15446 Frame 7, X = 2
15447 Frame 13, X = 255
15448 @end smallexample
15449
15450 @node tdump
15451 @subsection @code{tdump}
15452 @kindex tdump
15453 @cindex dump all data collected at tracepoint
15454 @cindex tracepoint data, display
15455
15456 This command takes no arguments. It prints all the data collected at
15457 the current trace snapshot.
15458
15459 @smallexample
15460 (@value{GDBP}) @b{trace 444}
15461 (@value{GDBP}) @b{actions}
15462 Enter actions for tracepoint #2, one per line:
15463 > collect $regs, $locals, $args, gdb_long_test
15464 > end
15465
15466 (@value{GDBP}) @b{tstart}
15467
15468 (@value{GDBP}) @b{tfind line 444}
15469 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15470 at gdb_test.c:444
15471 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15472
15473 (@value{GDBP}) @b{tdump}
15474 Data collected at tracepoint 2, trace frame 1:
15475 d0 0xc4aa0085 -995491707
15476 d1 0x18 24
15477 d2 0x80 128
15478 d3 0x33 51
15479 d4 0x71aea3d 119204413
15480 d5 0x22 34
15481 d6 0xe0 224
15482 d7 0x380035 3670069
15483 a0 0x19e24a 1696330
15484 a1 0x3000668 50333288
15485 a2 0x100 256
15486 a3 0x322000 3284992
15487 a4 0x3000698 50333336
15488 a5 0x1ad3cc 1758156
15489 fp 0x30bf3c 0x30bf3c
15490 sp 0x30bf34 0x30bf34
15491 ps 0x0 0
15492 pc 0x20b2c8 0x20b2c8
15493 fpcontrol 0x0 0
15494 fpstatus 0x0 0
15495 fpiaddr 0x0 0
15496 p = 0x20e5b4 "gdb-test"
15497 p1 = (void *) 0x11
15498 p2 = (void *) 0x22
15499 p3 = (void *) 0x33
15500 p4 = (void *) 0x44
15501 p5 = (void *) 0x55
15502 p6 = (void *) 0x66
15503 gdb_long_test = 17 '\021'
15504
15505 (@value{GDBP})
15506 @end smallexample
15507
15508 @code{tdump} works by scanning the tracepoint's current collection
15509 actions and printing the value of each expression listed. So
15510 @code{tdump} can fail, if after a run, you change the tracepoint's
15511 actions to mention variables that were not collected during the run.
15512
15513 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15514 uses the collected value of @code{$pc} to distinguish between trace
15515 frames that were collected at the tracepoint hit, and frames that were
15516 collected while stepping. This allows it to correctly choose whether
15517 to display the basic list of collections, or the collections from the
15518 body of the while-stepping loop. However, if @code{$pc} was not collected,
15519 then @code{tdump} will always attempt to dump using the basic collection
15520 list, and may fail if a while-stepping frame does not include all the
15521 same data that is collected at the tracepoint hit.
15522 @c This is getting pretty arcane, example would be good.
15523
15524 @node save tracepoints
15525 @subsection @code{save tracepoints @var{filename}}
15526 @kindex save tracepoints
15527 @kindex save-tracepoints
15528 @cindex save tracepoints for future sessions
15529
15530 This command saves all current tracepoint definitions together with
15531 their actions and passcounts, into a file @file{@var{filename}}
15532 suitable for use in a later debugging session. To read the saved
15533 tracepoint definitions, use the @code{source} command (@pxref{Command
15534 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15535 alias for @w{@code{save tracepoints}}
15536
15537 @node Tracepoint Variables
15538 @section Convenience Variables for Tracepoints
15539 @cindex tracepoint variables
15540 @cindex convenience variables for tracepoints
15541
15542 @table @code
15543 @vindex $trace_frame
15544 @item (int) $trace_frame
15545 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15546 snapshot is selected.
15547
15548 @vindex $tracepoint
15549 @item (int) $tracepoint
15550 The tracepoint for the current trace snapshot.
15551
15552 @vindex $trace_line
15553 @item (int) $trace_line
15554 The line number for the current trace snapshot.
15555
15556 @vindex $trace_file
15557 @item (char []) $trace_file
15558 The source file for the current trace snapshot.
15559
15560 @vindex $trace_func
15561 @item (char []) $trace_func
15562 The name of the function containing @code{$tracepoint}.
15563 @end table
15564
15565 Note: @code{$trace_file} is not suitable for use in @code{printf},
15566 use @code{output} instead.
15567
15568 Here's a simple example of using these convenience variables for
15569 stepping through all the trace snapshots and printing some of their
15570 data. Note that these are not the same as trace state variables,
15571 which are managed by the target.
15572
15573 @smallexample
15574 (@value{GDBP}) @b{tfind start}
15575
15576 (@value{GDBP}) @b{while $trace_frame != -1}
15577 > output $trace_file
15578 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15579 > tfind
15580 > end
15581 @end smallexample
15582
15583 @node Trace Files
15584 @section Using Trace Files
15585 @cindex trace files
15586
15587 In some situations, the target running a trace experiment may no
15588 longer be available; perhaps it crashed, or the hardware was needed
15589 for a different activity. To handle these cases, you can arrange to
15590 dump the trace data into a file, and later use that file as a source
15591 of trace data, via the @code{target tfile} command.
15592
15593 @table @code
15594
15595 @kindex tsave
15596 @item tsave [ -r ] @var{filename}
15597 @itemx tsave [-ctf] @var{dirname}
15598 Save the trace data to @var{filename}. By default, this command
15599 assumes that @var{filename} refers to the host filesystem, so if
15600 necessary @value{GDBN} will copy raw trace data up from the target and
15601 then save it. If the target supports it, you can also supply the
15602 optional argument @code{-r} (``remote'') to direct the target to save
15603 the data directly into @var{filename} in its own filesystem, which may be
15604 more efficient if the trace buffer is very large. (Note, however, that
15605 @code{target tfile} can only read from files accessible to the host.)
15606 By default, this command will save trace frame in tfile format.
15607 You can supply the optional argument @code{-ctf} to save data in CTF
15608 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15609 that can be shared by multiple debugging and tracing tools. Please go to
15610 @indicateurl{http://www.efficios.com/ctf} to get more information.
15611
15612 @kindex target tfile
15613 @kindex tfile
15614 @kindex target ctf
15615 @kindex ctf
15616 @item target tfile @var{filename}
15617 @itemx target ctf @var{dirname}
15618 Use the file named @var{filename} or directory named @var{dirname} as
15619 a source of trace data. Commands that examine data work as they do with
15620 a live target, but it is not possible to run any new trace experiments.
15621 @code{tstatus} will report the state of the trace run at the moment
15622 the data was saved, as well as the current trace frame you are examining.
15623 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15624 the host.
15625
15626 @smallexample
15627 (@value{GDBP}) target ctf ctf.ctf
15628 (@value{GDBP}) tfind
15629 Found trace frame 0, tracepoint 2
15630 39 ++a; /* set tracepoint 1 here */
15631 (@value{GDBP}) tdump
15632 Data collected at tracepoint 2, trace frame 0:
15633 i = 0
15634 a = 0
15635 b = 1 '\001'
15636 c = @{"123", "456", "789", "123", "456", "789"@}
15637 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15638 (@value{GDBP}) p b
15639 $1 = 1
15640 @end smallexample
15641
15642 @end table
15643
15644 @node Overlays
15645 @chapter Debugging Programs That Use Overlays
15646 @cindex overlays
15647
15648 If your program is too large to fit completely in your target system's
15649 memory, you can sometimes use @dfn{overlays} to work around this
15650 problem. @value{GDBN} provides some support for debugging programs that
15651 use overlays.
15652
15653 @menu
15654 * How Overlays Work:: A general explanation of overlays.
15655 * Overlay Commands:: Managing overlays in @value{GDBN}.
15656 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15657 mapped by asking the inferior.
15658 * Overlay Sample Program:: A sample program using overlays.
15659 @end menu
15660
15661 @node How Overlays Work
15662 @section How Overlays Work
15663 @cindex mapped overlays
15664 @cindex unmapped overlays
15665 @cindex load address, overlay's
15666 @cindex mapped address
15667 @cindex overlay area
15668
15669 Suppose you have a computer whose instruction address space is only 64
15670 kilobytes long, but which has much more memory which can be accessed by
15671 other means: special instructions, segment registers, or memory
15672 management hardware, for example. Suppose further that you want to
15673 adapt a program which is larger than 64 kilobytes to run on this system.
15674
15675 One solution is to identify modules of your program which are relatively
15676 independent, and need not call each other directly; call these modules
15677 @dfn{overlays}. Separate the overlays from the main program, and place
15678 their machine code in the larger memory. Place your main program in
15679 instruction memory, but leave at least enough space there to hold the
15680 largest overlay as well.
15681
15682 Now, to call a function located in an overlay, you must first copy that
15683 overlay's machine code from the large memory into the space set aside
15684 for it in the instruction memory, and then jump to its entry point
15685 there.
15686
15687 @c NB: In the below the mapped area's size is greater or equal to the
15688 @c size of all overlays. This is intentional to remind the developer
15689 @c that overlays don't necessarily need to be the same size.
15690
15691 @smallexample
15692 @group
15693 Data Instruction Larger
15694 Address Space Address Space Address Space
15695 +-----------+ +-----------+ +-----------+
15696 | | | | | |
15697 +-----------+ +-----------+ +-----------+<-- overlay 1
15698 | program | | main | .----| overlay 1 | load address
15699 | variables | | program | | +-----------+
15700 | and heap | | | | | |
15701 +-----------+ | | | +-----------+<-- overlay 2
15702 | | +-----------+ | | | load address
15703 +-----------+ | | | .-| overlay 2 |
15704 | | | | | |
15705 mapped --->+-----------+ | | +-----------+
15706 address | | | | | |
15707 | overlay | <-' | | |
15708 | area | <---' +-----------+<-- overlay 3
15709 | | <---. | | load address
15710 +-----------+ `--| overlay 3 |
15711 | | | |
15712 +-----------+ | |
15713 +-----------+
15714 | |
15715 +-----------+
15716
15717 @anchor{A code overlay}A code overlay
15718 @end group
15719 @end smallexample
15720
15721 The diagram (@pxref{A code overlay}) shows a system with separate data
15722 and instruction address spaces. To map an overlay, the program copies
15723 its code from the larger address space to the instruction address space.
15724 Since the overlays shown here all use the same mapped address, only one
15725 may be mapped at a time. For a system with a single address space for
15726 data and instructions, the diagram would be similar, except that the
15727 program variables and heap would share an address space with the main
15728 program and the overlay area.
15729
15730 An overlay loaded into instruction memory and ready for use is called a
15731 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15732 instruction memory. An overlay not present (or only partially present)
15733 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15734 is its address in the larger memory. The mapped address is also called
15735 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15736 called the @dfn{load memory address}, or @dfn{LMA}.
15737
15738 Unfortunately, overlays are not a completely transparent way to adapt a
15739 program to limited instruction memory. They introduce a new set of
15740 global constraints you must keep in mind as you design your program:
15741
15742 @itemize @bullet
15743
15744 @item
15745 Before calling or returning to a function in an overlay, your program
15746 must make sure that overlay is actually mapped. Otherwise, the call or
15747 return will transfer control to the right address, but in the wrong
15748 overlay, and your program will probably crash.
15749
15750 @item
15751 If the process of mapping an overlay is expensive on your system, you
15752 will need to choose your overlays carefully to minimize their effect on
15753 your program's performance.
15754
15755 @item
15756 The executable file you load onto your system must contain each
15757 overlay's instructions, appearing at the overlay's load address, not its
15758 mapped address. However, each overlay's instructions must be relocated
15759 and its symbols defined as if the overlay were at its mapped address.
15760 You can use GNU linker scripts to specify different load and relocation
15761 addresses for pieces of your program; see @ref{Overlay Description,,,
15762 ld.info, Using ld: the GNU linker}.
15763
15764 @item
15765 The procedure for loading executable files onto your system must be able
15766 to load their contents into the larger address space as well as the
15767 instruction and data spaces.
15768
15769 @end itemize
15770
15771 The overlay system described above is rather simple, and could be
15772 improved in many ways:
15773
15774 @itemize @bullet
15775
15776 @item
15777 If your system has suitable bank switch registers or memory management
15778 hardware, you could use those facilities to make an overlay's load area
15779 contents simply appear at their mapped address in instruction space.
15780 This would probably be faster than copying the overlay to its mapped
15781 area in the usual way.
15782
15783 @item
15784 If your overlays are small enough, you could set aside more than one
15785 overlay area, and have more than one overlay mapped at a time.
15786
15787 @item
15788 You can use overlays to manage data, as well as instructions. In
15789 general, data overlays are even less transparent to your design than
15790 code overlays: whereas code overlays only require care when you call or
15791 return to functions, data overlays require care every time you access
15792 the data. Also, if you change the contents of a data overlay, you
15793 must copy its contents back out to its load address before you can copy a
15794 different data overlay into the same mapped area.
15795
15796 @end itemize
15797
15798
15799 @node Overlay Commands
15800 @section Overlay Commands
15801
15802 To use @value{GDBN}'s overlay support, each overlay in your program must
15803 correspond to a separate section of the executable file. The section's
15804 virtual memory address and load memory address must be the overlay's
15805 mapped and load addresses. Identifying overlays with sections allows
15806 @value{GDBN} to determine the appropriate address of a function or
15807 variable, depending on whether the overlay is mapped or not.
15808
15809 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15810 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15811
15812 @table @code
15813 @item overlay off
15814 @kindex overlay
15815 Disable @value{GDBN}'s overlay support. When overlay support is
15816 disabled, @value{GDBN} assumes that all functions and variables are
15817 always present at their mapped addresses. By default, @value{GDBN}'s
15818 overlay support is disabled.
15819
15820 @item overlay manual
15821 @cindex manual overlay debugging
15822 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15823 relies on you to tell it which overlays are mapped, and which are not,
15824 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15825 commands described below.
15826
15827 @item overlay map-overlay @var{overlay}
15828 @itemx overlay map @var{overlay}
15829 @cindex map an overlay
15830 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15831 be the name of the object file section containing the overlay. When an
15832 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15833 functions and variables at their mapped addresses. @value{GDBN} assumes
15834 that any other overlays whose mapped ranges overlap that of
15835 @var{overlay} are now unmapped.
15836
15837 @item overlay unmap-overlay @var{overlay}
15838 @itemx overlay unmap @var{overlay}
15839 @cindex unmap an overlay
15840 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15841 must be the name of the object file section containing the overlay.
15842 When an overlay is unmapped, @value{GDBN} assumes it can find the
15843 overlay's functions and variables at their load addresses.
15844
15845 @item overlay auto
15846 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15847 consults a data structure the overlay manager maintains in the inferior
15848 to see which overlays are mapped. For details, see @ref{Automatic
15849 Overlay Debugging}.
15850
15851 @item overlay load-target
15852 @itemx overlay load
15853 @cindex reloading the overlay table
15854 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15855 re-reads the table @value{GDBN} automatically each time the inferior
15856 stops, so this command should only be necessary if you have changed the
15857 overlay mapping yourself using @value{GDBN}. This command is only
15858 useful when using automatic overlay debugging.
15859
15860 @item overlay list-overlays
15861 @itemx overlay list
15862 @cindex listing mapped overlays
15863 Display a list of the overlays currently mapped, along with their mapped
15864 addresses, load addresses, and sizes.
15865
15866 @end table
15867
15868 Normally, when @value{GDBN} prints a code address, it includes the name
15869 of the function the address falls in:
15870
15871 @smallexample
15872 (@value{GDBP}) print main
15873 $3 = @{int ()@} 0x11a0 <main>
15874 @end smallexample
15875 @noindent
15876 When overlay debugging is enabled, @value{GDBN} recognizes code in
15877 unmapped overlays, and prints the names of unmapped functions with
15878 asterisks around them. For example, if @code{foo} is a function in an
15879 unmapped overlay, @value{GDBN} prints it this way:
15880
15881 @smallexample
15882 (@value{GDBP}) overlay list
15883 No sections are mapped.
15884 (@value{GDBP}) print foo
15885 $5 = @{int (int)@} 0x100000 <*foo*>
15886 @end smallexample
15887 @noindent
15888 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15889 name normally:
15890
15891 @smallexample
15892 (@value{GDBP}) overlay list
15893 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15894 mapped at 0x1016 - 0x104a
15895 (@value{GDBP}) print foo
15896 $6 = @{int (int)@} 0x1016 <foo>
15897 @end smallexample
15898
15899 When overlay debugging is enabled, @value{GDBN} can find the correct
15900 address for functions and variables in an overlay, whether or not the
15901 overlay is mapped. This allows most @value{GDBN} commands, like
15902 @code{break} and @code{disassemble}, to work normally, even on unmapped
15903 code. However, @value{GDBN}'s breakpoint support has some limitations:
15904
15905 @itemize @bullet
15906 @item
15907 @cindex breakpoints in overlays
15908 @cindex overlays, setting breakpoints in
15909 You can set breakpoints in functions in unmapped overlays, as long as
15910 @value{GDBN} can write to the overlay at its load address.
15911 @item
15912 @value{GDBN} can not set hardware or simulator-based breakpoints in
15913 unmapped overlays. However, if you set a breakpoint at the end of your
15914 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15915 you are using manual overlay management), @value{GDBN} will re-set its
15916 breakpoints properly.
15917 @end itemize
15918
15919
15920 @node Automatic Overlay Debugging
15921 @section Automatic Overlay Debugging
15922 @cindex automatic overlay debugging
15923
15924 @value{GDBN} can automatically track which overlays are mapped and which
15925 are not, given some simple co-operation from the overlay manager in the
15926 inferior. If you enable automatic overlay debugging with the
15927 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15928 looks in the inferior's memory for certain variables describing the
15929 current state of the overlays.
15930
15931 Here are the variables your overlay manager must define to support
15932 @value{GDBN}'s automatic overlay debugging:
15933
15934 @table @asis
15935
15936 @item @code{_ovly_table}:
15937 This variable must be an array of the following structures:
15938
15939 @smallexample
15940 struct
15941 @{
15942 /* The overlay's mapped address. */
15943 unsigned long vma;
15944
15945 /* The size of the overlay, in bytes. */
15946 unsigned long size;
15947
15948 /* The overlay's load address. */
15949 unsigned long lma;
15950
15951 /* Non-zero if the overlay is currently mapped;
15952 zero otherwise. */
15953 unsigned long mapped;
15954 @}
15955 @end smallexample
15956
15957 @item @code{_novlys}:
15958 This variable must be a four-byte signed integer, holding the total
15959 number of elements in @code{_ovly_table}.
15960
15961 @end table
15962
15963 To decide whether a particular overlay is mapped or not, @value{GDBN}
15964 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15965 @code{lma} members equal the VMA and LMA of the overlay's section in the
15966 executable file. When @value{GDBN} finds a matching entry, it consults
15967 the entry's @code{mapped} member to determine whether the overlay is
15968 currently mapped.
15969
15970 In addition, your overlay manager may define a function called
15971 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15972 will silently set a breakpoint there. If the overlay manager then
15973 calls this function whenever it has changed the overlay table, this
15974 will enable @value{GDBN} to accurately keep track of which overlays
15975 are in program memory, and update any breakpoints that may be set
15976 in overlays. This will allow breakpoints to work even if the
15977 overlays are kept in ROM or other non-writable memory while they
15978 are not being executed.
15979
15980 @node Overlay Sample Program
15981 @section Overlay Sample Program
15982 @cindex overlay example program
15983
15984 When linking a program which uses overlays, you must place the overlays
15985 at their load addresses, while relocating them to run at their mapped
15986 addresses. To do this, you must write a linker script (@pxref{Overlay
15987 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15988 since linker scripts are specific to a particular host system, target
15989 architecture, and target memory layout, this manual cannot provide
15990 portable sample code demonstrating @value{GDBN}'s overlay support.
15991
15992 However, the @value{GDBN} source distribution does contain an overlaid
15993 program, with linker scripts for a few systems, as part of its test
15994 suite. The program consists of the following files from
15995 @file{gdb/testsuite/gdb.base}:
15996
15997 @table @file
15998 @item overlays.c
15999 The main program file.
16000 @item ovlymgr.c
16001 A simple overlay manager, used by @file{overlays.c}.
16002 @item foo.c
16003 @itemx bar.c
16004 @itemx baz.c
16005 @itemx grbx.c
16006 Overlay modules, loaded and used by @file{overlays.c}.
16007 @item d10v.ld
16008 @itemx m32r.ld
16009 Linker scripts for linking the test program on the @code{d10v-elf}
16010 and @code{m32r-elf} targets.
16011 @end table
16012
16013 You can build the test program using the @code{d10v-elf} GCC
16014 cross-compiler like this:
16015
16016 @smallexample
16017 $ d10v-elf-gcc -g -c overlays.c
16018 $ d10v-elf-gcc -g -c ovlymgr.c
16019 $ d10v-elf-gcc -g -c foo.c
16020 $ d10v-elf-gcc -g -c bar.c
16021 $ d10v-elf-gcc -g -c baz.c
16022 $ d10v-elf-gcc -g -c grbx.c
16023 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
16024 baz.o grbx.o -Wl,-Td10v.ld -o overlays
16025 @end smallexample
16026
16027 The build process is identical for any other architecture, except that
16028 you must substitute the appropriate compiler and linker script for the
16029 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
16030
16031
16032 @node Languages
16033 @chapter Using @value{GDBN} with Different Languages
16034 @cindex languages
16035
16036 Although programming languages generally have common aspects, they are
16037 rarely expressed in the same manner. For instance, in ANSI C,
16038 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
16039 Modula-2, it is accomplished by @code{p^}. Values can also be
16040 represented (and displayed) differently. Hex numbers in C appear as
16041 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
16042
16043 @cindex working language
16044 Language-specific information is built into @value{GDBN} for some languages,
16045 allowing you to express operations like the above in your program's
16046 native language, and allowing @value{GDBN} to output values in a manner
16047 consistent with the syntax of your program's native language. The
16048 language you use to build expressions is called the @dfn{working
16049 language}.
16050
16051 @menu
16052 * Setting:: Switching between source languages
16053 * Show:: Displaying the language
16054 * Checks:: Type and range checks
16055 * Supported Languages:: Supported languages
16056 * Unsupported Languages:: Unsupported languages
16057 @end menu
16058
16059 @node Setting
16060 @section Switching Between Source Languages
16061
16062 There are two ways to control the working language---either have @value{GDBN}
16063 set it automatically, or select it manually yourself. You can use the
16064 @code{set language} command for either purpose. On startup, @value{GDBN}
16065 defaults to setting the language automatically. The working language is
16066 used to determine how expressions you type are interpreted, how values
16067 are printed, etc.
16068
16069 In addition to the working language, every source file that
16070 @value{GDBN} knows about has its own working language. For some object
16071 file formats, the compiler might indicate which language a particular
16072 source file is in. However, most of the time @value{GDBN} infers the
16073 language from the name of the file. The language of a source file
16074 controls whether C@t{++} names are demangled---this way @code{backtrace} can
16075 show each frame appropriately for its own language. There is no way to
16076 set the language of a source file from within @value{GDBN}, but you can
16077 set the language associated with a filename extension. @xref{Show, ,
16078 Displaying the Language}.
16079
16080 This is most commonly a problem when you use a program, such
16081 as @code{cfront} or @code{f2c}, that generates C but is written in
16082 another language. In that case, make the
16083 program use @code{#line} directives in its C output; that way
16084 @value{GDBN} will know the correct language of the source code of the original
16085 program, and will display that source code, not the generated C code.
16086
16087 @menu
16088 * Filenames:: Filename extensions and languages.
16089 * Manually:: Setting the working language manually
16090 * Automatically:: Having @value{GDBN} infer the source language
16091 @end menu
16092
16093 @node Filenames
16094 @subsection List of Filename Extensions and Languages
16095
16096 If a source file name ends in one of the following extensions, then
16097 @value{GDBN} infers that its language is the one indicated.
16098
16099 @table @file
16100 @item .ada
16101 @itemx .ads
16102 @itemx .adb
16103 @itemx .a
16104 Ada source file.
16105
16106 @item .c
16107 C source file
16108
16109 @item .C
16110 @itemx .cc
16111 @itemx .cp
16112 @itemx .cpp
16113 @itemx .cxx
16114 @itemx .c++
16115 C@t{++} source file
16116
16117 @item .d
16118 D source file
16119
16120 @item .m
16121 Objective-C source file
16122
16123 @item .f
16124 @itemx .F
16125 Fortran source file
16126
16127 @item .mod
16128 Modula-2 source file
16129
16130 @item .s
16131 @itemx .S
16132 Assembler source file. This actually behaves almost like C, but
16133 @value{GDBN} does not skip over function prologues when stepping.
16134 @end table
16135
16136 In addition, you may set the language associated with a filename
16137 extension. @xref{Show, , Displaying the Language}.
16138
16139 @node Manually
16140 @subsection Setting the Working Language
16141
16142 If you allow @value{GDBN} to set the language automatically,
16143 expressions are interpreted the same way in your debugging session and
16144 your program.
16145
16146 @kindex set language
16147 If you wish, you may set the language manually. To do this, issue the
16148 command @samp{set language @var{lang}}, where @var{lang} is the name of
16149 a language, such as
16150 @code{c} or @code{modula-2}.
16151 For a list of the supported languages, type @samp{set language}.
16152
16153 Setting the language manually prevents @value{GDBN} from updating the working
16154 language automatically. This can lead to confusion if you try
16155 to debug a program when the working language is not the same as the
16156 source language, when an expression is acceptable to both
16157 languages---but means different things. For instance, if the current
16158 source file were written in C, and @value{GDBN} was parsing Modula-2, a
16159 command such as:
16160
16161 @smallexample
16162 print a = b + c
16163 @end smallexample
16164
16165 @noindent
16166 might not have the effect you intended. In C, this means to add
16167 @code{b} and @code{c} and place the result in @code{a}. The result
16168 printed would be the value of @code{a}. In Modula-2, this means to compare
16169 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
16170
16171 @node Automatically
16172 @subsection Having @value{GDBN} Infer the Source Language
16173
16174 To have @value{GDBN} set the working language automatically, use
16175 @samp{set language local} or @samp{set language auto}. @value{GDBN}
16176 then infers the working language. That is, when your program stops in a
16177 frame (usually by encountering a breakpoint), @value{GDBN} sets the
16178 working language to the language recorded for the function in that
16179 frame. If the language for a frame is unknown (that is, if the function
16180 or block corresponding to the frame was defined in a source file that
16181 does not have a recognized extension), the current working language is
16182 not changed, and @value{GDBN} issues a warning.
16183
16184 This may not seem necessary for most programs, which are written
16185 entirely in one source language. However, program modules and libraries
16186 written in one source language can be used by a main program written in
16187 a different source language. Using @samp{set language auto} in this
16188 case frees you from having to set the working language manually.
16189
16190 @node Show
16191 @section Displaying the Language
16192
16193 The following commands help you find out which language is the
16194 working language, and also what language source files were written in.
16195
16196 @table @code
16197 @item show language
16198 @anchor{show language}
16199 @kindex show language
16200 Display the current working language. This is the
16201 language you can use with commands such as @code{print} to
16202 build and compute expressions that may involve variables in your program.
16203
16204 @item info frame
16205 @kindex info frame@r{, show the source language}
16206 Display the source language for this frame. This language becomes the
16207 working language if you use an identifier from this frame.
16208 @xref{Frame Info, ,Information about a Frame}, to identify the other
16209 information listed here.
16210
16211 @item info source
16212 @kindex info source@r{, show the source language}
16213 Display the source language of this source file.
16214 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16215 information listed here.
16216 @end table
16217
16218 In unusual circumstances, you may have source files with extensions
16219 not in the standard list. You can then set the extension associated
16220 with a language explicitly:
16221
16222 @table @code
16223 @item set extension-language @var{ext} @var{language}
16224 @kindex set extension-language
16225 Tell @value{GDBN} that source files with extension @var{ext} are to be
16226 assumed as written in the source language @var{language}.
16227
16228 @item info extensions
16229 @kindex info extensions
16230 List all the filename extensions and the associated languages.
16231 @end table
16232
16233 @node Checks
16234 @section Type and Range Checking
16235
16236 Some languages are designed to guard you against making seemingly common
16237 errors through a series of compile- and run-time checks. These include
16238 checking the type of arguments to functions and operators and making
16239 sure mathematical overflows are caught at run time. Checks such as
16240 these help to ensure a program's correctness once it has been compiled
16241 by eliminating type mismatches and providing active checks for range
16242 errors when your program is running.
16243
16244 By default @value{GDBN} checks for these errors according to the
16245 rules of the current source language. Although @value{GDBN} does not check
16246 the statements in your program, it can check expressions entered directly
16247 into @value{GDBN} for evaluation via the @code{print} command, for example.
16248
16249 @menu
16250 * Type Checking:: An overview of type checking
16251 * Range Checking:: An overview of range checking
16252 @end menu
16253
16254 @cindex type checking
16255 @cindex checks, type
16256 @node Type Checking
16257 @subsection An Overview of Type Checking
16258
16259 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16260 arguments to operators and functions have to be of the correct type,
16261 otherwise an error occurs. These checks prevent type mismatch
16262 errors from ever causing any run-time problems. For example,
16263
16264 @smallexample
16265 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16266
16267 (@value{GDBP}) print obj.my_method (0)
16268 $1 = 2
16269 @exdent but
16270 (@value{GDBP}) print obj.my_method (0x1234)
16271 Cannot resolve method klass::my_method to any overloaded instance
16272 @end smallexample
16273
16274 The second example fails because in C@t{++} the integer constant
16275 @samp{0x1234} is not type-compatible with the pointer parameter type.
16276
16277 For the expressions you use in @value{GDBN} commands, you can tell
16278 @value{GDBN} to not enforce strict type checking or
16279 to treat any mismatches as errors and abandon the expression;
16280 When type checking is disabled, @value{GDBN} successfully evaluates
16281 expressions like the second example above.
16282
16283 Even if type checking is off, there may be other reasons
16284 related to type that prevent @value{GDBN} from evaluating an expression.
16285 For instance, @value{GDBN} does not know how to add an @code{int} and
16286 a @code{struct foo}. These particular type errors have nothing to do
16287 with the language in use and usually arise from expressions which make
16288 little sense to evaluate anyway.
16289
16290 @value{GDBN} provides some additional commands for controlling type checking:
16291
16292 @kindex set check type
16293 @kindex show check type
16294 @table @code
16295 @item set check type on
16296 @itemx set check type off
16297 Set strict type checking on or off. If any type mismatches occur in
16298 evaluating an expression while type checking is on, @value{GDBN} prints a
16299 message and aborts evaluation of the expression.
16300
16301 @item show check type
16302 Show the current setting of type checking and whether @value{GDBN}
16303 is enforcing strict type checking rules.
16304 @end table
16305
16306 @cindex range checking
16307 @cindex checks, range
16308 @node Range Checking
16309 @subsection An Overview of Range Checking
16310
16311 In some languages (such as Modula-2), it is an error to exceed the
16312 bounds of a type; this is enforced with run-time checks. Such range
16313 checking is meant to ensure program correctness by making sure
16314 computations do not overflow, or indices on an array element access do
16315 not exceed the bounds of the array.
16316
16317 For expressions you use in @value{GDBN} commands, you can tell
16318 @value{GDBN} to treat range errors in one of three ways: ignore them,
16319 always treat them as errors and abandon the expression, or issue
16320 warnings but evaluate the expression anyway.
16321
16322 A range error can result from numerical overflow, from exceeding an
16323 array index bound, or when you type a constant that is not a member
16324 of any type. Some languages, however, do not treat overflows as an
16325 error. In many implementations of C, mathematical overflow causes the
16326 result to ``wrap around'' to lower values---for example, if @var{m} is
16327 the largest integer value, and @var{s} is the smallest, then
16328
16329 @smallexample
16330 @var{m} + 1 @result{} @var{s}
16331 @end smallexample
16332
16333 This, too, is specific to individual languages, and in some cases
16334 specific to individual compilers or machines. @xref{Supported Languages, ,
16335 Supported Languages}, for further details on specific languages.
16336
16337 @value{GDBN} provides some additional commands for controlling the range checker:
16338
16339 @kindex set check range
16340 @kindex show check range
16341 @table @code
16342 @item set check range auto
16343 Set range checking on or off based on the current working language.
16344 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16345 each language.
16346
16347 @item set check range on
16348 @itemx set check range off
16349 Set range checking on or off, overriding the default setting for the
16350 current working language. A warning is issued if the setting does not
16351 match the language default. If a range error occurs and range checking is on,
16352 then a message is printed and evaluation of the expression is aborted.
16353
16354 @item set check range warn
16355 Output messages when the @value{GDBN} range checker detects a range error,
16356 but attempt to evaluate the expression anyway. Evaluating the
16357 expression may still be impossible for other reasons, such as accessing
16358 memory that the process does not own (a typical example from many Unix
16359 systems).
16360
16361 @item show check range
16362 Show the current setting of the range checker, and whether or not it is
16363 being set automatically by @value{GDBN}.
16364 @end table
16365
16366 @node Supported Languages
16367 @section Supported Languages
16368
16369 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16370 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16371 @c This is false ...
16372 Some @value{GDBN} features may be used in expressions regardless of the
16373 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16374 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16375 ,Expressions}) can be used with the constructs of any supported
16376 language.
16377
16378 The following sections detail to what degree each source language is
16379 supported by @value{GDBN}. These sections are not meant to be language
16380 tutorials or references, but serve only as a reference guide to what the
16381 @value{GDBN} expression parser accepts, and what input and output
16382 formats should look like for different languages. There are many good
16383 books written on each of these languages; please look to these for a
16384 language reference or tutorial.
16385
16386 @menu
16387 * C:: C and C@t{++}
16388 * D:: D
16389 * Go:: Go
16390 * Objective-C:: Objective-C
16391 * OpenCL C:: OpenCL C
16392 * Fortran:: Fortran
16393 * Pascal:: Pascal
16394 * Rust:: Rust
16395 * Modula-2:: Modula-2
16396 * Ada:: Ada
16397 @end menu
16398
16399 @node C
16400 @subsection C and C@t{++}
16401
16402 @cindex C and C@t{++}
16403 @cindex expressions in C or C@t{++}
16404
16405 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16406 to both languages. Whenever this is the case, we discuss those languages
16407 together.
16408
16409 @cindex C@t{++}
16410 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16411 @cindex @sc{gnu} C@t{++}
16412 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16413 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16414 effectively, you must compile your C@t{++} programs with a supported
16415 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16416 compiler (@code{aCC}).
16417
16418 @menu
16419 * C Operators:: C and C@t{++} operators
16420 * C Constants:: C and C@t{++} constants
16421 * C Plus Plus Expressions:: C@t{++} expressions
16422 * C Defaults:: Default settings for C and C@t{++}
16423 * C Checks:: C and C@t{++} type and range checks
16424 * Debugging C:: @value{GDBN} and C
16425 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16426 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16427 @end menu
16428
16429 @node C Operators
16430 @subsubsection C and C@t{++} Operators
16431
16432 @cindex C and C@t{++} operators
16433
16434 Operators must be defined on values of specific types. For instance,
16435 @code{+} is defined on numbers, but not on structures. Operators are
16436 often defined on groups of types.
16437
16438 For the purposes of C and C@t{++}, the following definitions hold:
16439
16440 @itemize @bullet
16441
16442 @item
16443 @emph{Integral types} include @code{int} with any of its storage-class
16444 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16445
16446 @item
16447 @emph{Floating-point types} include @code{float}, @code{double}, and
16448 @code{long double} (if supported by the target platform).
16449
16450 @item
16451 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16452
16453 @item
16454 @emph{Scalar types} include all of the above.
16455
16456 @end itemize
16457
16458 @noindent
16459 The following operators are supported. They are listed here
16460 in order of increasing precedence:
16461
16462 @table @code
16463 @item ,
16464 The comma or sequencing operator. Expressions in a comma-separated list
16465 are evaluated from left to right, with the result of the entire
16466 expression being the last expression evaluated.
16467
16468 @item =
16469 Assignment. The value of an assignment expression is the value
16470 assigned. Defined on scalar types.
16471
16472 @item @var{op}=
16473 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16474 and translated to @w{@code{@var{a} = @var{a op b}}}.
16475 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16476 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16477 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16478
16479 @item ?:
16480 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16481 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16482 should be of an integral type.
16483
16484 @item ||
16485 Logical @sc{or}. Defined on integral types.
16486
16487 @item &&
16488 Logical @sc{and}. Defined on integral types.
16489
16490 @item |
16491 Bitwise @sc{or}. Defined on integral types.
16492
16493 @item ^
16494 Bitwise exclusive-@sc{or}. Defined on integral types.
16495
16496 @item &
16497 Bitwise @sc{and}. Defined on integral types.
16498
16499 @item ==@r{, }!=
16500 Equality and inequality. Defined on scalar types. The value of these
16501 expressions is 0 for false and non-zero for true.
16502
16503 @item <@r{, }>@r{, }<=@r{, }>=
16504 Less than, greater than, less than or equal, greater than or equal.
16505 Defined on scalar types. The value of these expressions is 0 for false
16506 and non-zero for true.
16507
16508 @item <<@r{, }>>
16509 left shift, and right shift. Defined on integral types.
16510
16511 @item @@
16512 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16513
16514 @item +@r{, }-
16515 Addition and subtraction. Defined on integral types, floating-point types and
16516 pointer types.
16517
16518 @item *@r{, }/@r{, }%
16519 Multiplication, division, and modulus. Multiplication and division are
16520 defined on integral and floating-point types. Modulus is defined on
16521 integral types.
16522
16523 @item ++@r{, }--
16524 Increment and decrement. When appearing before a variable, the
16525 operation is performed before the variable is used in an expression;
16526 when appearing after it, the variable's value is used before the
16527 operation takes place.
16528
16529 @item *
16530 Pointer dereferencing. Defined on pointer types. Same precedence as
16531 @code{++}.
16532
16533 @item &
16534 Address operator. Defined on variables. Same precedence as @code{++}.
16535
16536 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16537 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16538 to examine the address
16539 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16540 stored.
16541
16542 @item -
16543 Negative. Defined on integral and floating-point types. Same
16544 precedence as @code{++}.
16545
16546 @item !
16547 Logical negation. Defined on integral types. Same precedence as
16548 @code{++}.
16549
16550 @item ~
16551 Bitwise complement operator. Defined on integral types. Same precedence as
16552 @code{++}.
16553
16554
16555 @item .@r{, }->
16556 Structure member, and pointer-to-structure member. For convenience,
16557 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16558 pointer based on the stored type information.
16559 Defined on @code{struct} and @code{union} data.
16560
16561 @item .*@r{, }->*
16562 Dereferences of pointers to members.
16563
16564 @item []
16565 Array indexing. @code{@var{a}[@var{i}]} is defined as
16566 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16567
16568 @item ()
16569 Function parameter list. Same precedence as @code{->}.
16570
16571 @item ::
16572 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16573 and @code{class} types.
16574
16575 @item ::
16576 Doubled colons also represent the @value{GDBN} scope operator
16577 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16578 above.
16579 @end table
16580
16581 If an operator is redefined in the user code, @value{GDBN} usually
16582 attempts to invoke the redefined version instead of using the operator's
16583 predefined meaning.
16584
16585 @node C Constants
16586 @subsubsection C and C@t{++} Constants
16587
16588 @cindex C and C@t{++} constants
16589
16590 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16591 following ways:
16592
16593 @itemize @bullet
16594 @item
16595 Integer constants are a sequence of digits. Octal constants are
16596 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16597 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16598 @samp{l}, specifying that the constant should be treated as a
16599 @code{long} value.
16600
16601 @item
16602 Floating point constants are a sequence of digits, followed by a decimal
16603 point, followed by a sequence of digits, and optionally followed by an
16604 exponent. An exponent is of the form:
16605 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16606 sequence of digits. The @samp{+} is optional for positive exponents.
16607 A floating-point constant may also end with a letter @samp{f} or
16608 @samp{F}, specifying that the constant should be treated as being of
16609 the @code{float} (as opposed to the default @code{double}) type; or with
16610 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16611 constant.
16612
16613 @item
16614 Enumerated constants consist of enumerated identifiers, or their
16615 integral equivalents.
16616
16617 @item
16618 Character constants are a single character surrounded by single quotes
16619 (@code{'}), or a number---the ordinal value of the corresponding character
16620 (usually its @sc{ascii} value). Within quotes, the single character may
16621 be represented by a letter or by @dfn{escape sequences}, which are of
16622 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16623 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16624 @samp{@var{x}} is a predefined special character---for example,
16625 @samp{\n} for newline.
16626
16627 Wide character constants can be written by prefixing a character
16628 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16629 form of @samp{x}. The target wide character set is used when
16630 computing the value of this constant (@pxref{Character Sets}).
16631
16632 @item
16633 String constants are a sequence of character constants surrounded by
16634 double quotes (@code{"}). Any valid character constant (as described
16635 above) may appear. Double quotes within the string must be preceded by
16636 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16637 characters.
16638
16639 Wide string constants can be written by prefixing a string constant
16640 with @samp{L}, as in C. The target wide character set is used when
16641 computing the value of this constant (@pxref{Character Sets}).
16642
16643 @item
16644 Pointer constants are an integral value. You can also write pointers
16645 to constants using the C operator @samp{&}.
16646
16647 @item
16648 Array constants are comma-separated lists surrounded by braces @samp{@{}
16649 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16650 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16651 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16652 @end itemize
16653
16654 @node C Plus Plus Expressions
16655 @subsubsection C@t{++} Expressions
16656
16657 @cindex expressions in C@t{++}
16658 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16659
16660 @cindex debugging C@t{++} programs
16661 @cindex C@t{++} compilers
16662 @cindex debug formats and C@t{++}
16663 @cindex @value{NGCC} and C@t{++}
16664 @quotation
16665 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16666 the proper compiler and the proper debug format. Currently,
16667 @value{GDBN} works best when debugging C@t{++} code that is compiled
16668 with the most recent version of @value{NGCC} possible. The DWARF
16669 debugging format is preferred; @value{NGCC} defaults to this on most
16670 popular platforms. Other compilers and/or debug formats are likely to
16671 work badly or not at all when using @value{GDBN} to debug C@t{++}
16672 code. @xref{Compilation}.
16673 @end quotation
16674
16675 @enumerate
16676
16677 @cindex member functions
16678 @item
16679 Member function calls are allowed; you can use expressions like
16680
16681 @smallexample
16682 count = aml->GetOriginal(x, y)
16683 @end smallexample
16684
16685 @vindex this@r{, inside C@t{++} member functions}
16686 @cindex namespace in C@t{++}
16687 @item
16688 While a member function is active (in the selected stack frame), your
16689 expressions have the same namespace available as the member function;
16690 that is, @value{GDBN} allows implicit references to the class instance
16691 pointer @code{this} following the same rules as C@t{++}. @code{using}
16692 declarations in the current scope are also respected by @value{GDBN}.
16693
16694 @cindex call overloaded functions
16695 @cindex overloaded functions, calling
16696 @cindex type conversions in C@t{++}
16697 @item
16698 You can call overloaded functions; @value{GDBN} resolves the function
16699 call to the right definition, with some restrictions. @value{GDBN} does not
16700 perform overload resolution involving user-defined type conversions,
16701 calls to constructors, or instantiations of templates that do not exist
16702 in the program. It also cannot handle ellipsis argument lists or
16703 default arguments.
16704
16705 It does perform integral conversions and promotions, floating-point
16706 promotions, arithmetic conversions, pointer conversions, conversions of
16707 class objects to base classes, and standard conversions such as those of
16708 functions or arrays to pointers; it requires an exact match on the
16709 number of function arguments.
16710
16711 Overload resolution is always performed, unless you have specified
16712 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16713 ,@value{GDBN} Features for C@t{++}}.
16714
16715 You must specify @code{set overload-resolution off} in order to use an
16716 explicit function signature to call an overloaded function, as in
16717 @smallexample
16718 p 'foo(char,int)'('x', 13)
16719 @end smallexample
16720
16721 The @value{GDBN} command-completion facility can simplify this;
16722 see @ref{Completion, ,Command Completion}.
16723
16724 @cindex reference declarations
16725 @item
16726 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16727 references; you can use them in expressions just as you do in C@t{++}
16728 source---they are automatically dereferenced.
16729
16730 In the parameter list shown when @value{GDBN} displays a frame, the values of
16731 reference variables are not displayed (unlike other variables); this
16732 avoids clutter, since references are often used for large structures.
16733 The @emph{address} of a reference variable is always shown, unless
16734 you have specified @samp{set print address off}.
16735
16736 @item
16737 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16738 expressions can use it just as expressions in your program do. Since
16739 one scope may be defined in another, you can use @code{::} repeatedly if
16740 necessary, for example in an expression like
16741 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16742 resolving name scope by reference to source files, in both C and C@t{++}
16743 debugging (@pxref{Variables, ,Program Variables}).
16744
16745 @item
16746 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16747 specification.
16748 @end enumerate
16749
16750 @node C Defaults
16751 @subsubsection C and C@t{++} Defaults
16752
16753 @cindex C and C@t{++} defaults
16754
16755 If you allow @value{GDBN} to set range checking automatically, it
16756 defaults to @code{off} whenever the working language changes to
16757 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16758 selects the working language.
16759
16760 If you allow @value{GDBN} to set the language automatically, it
16761 recognizes source files whose names end with @file{.c}, @file{.C}, or
16762 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16763 these files, it sets the working language to C or C@t{++}.
16764 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16765 for further details.
16766
16767 @node C Checks
16768 @subsubsection C and C@t{++} Type and Range Checks
16769
16770 @cindex C and C@t{++} checks
16771
16772 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16773 checking is used. However, if you turn type checking off, @value{GDBN}
16774 will allow certain non-standard conversions, such as promoting integer
16775 constants to pointers.
16776
16777 Range checking, if turned on, is done on mathematical operations. Array
16778 indices are not checked, since they are often used to index a pointer
16779 that is not itself an array.
16780
16781 @node Debugging C
16782 @subsubsection @value{GDBN} and C
16783
16784 The @code{set print union} and @code{show print union} commands apply to
16785 the @code{union} type. When set to @samp{on}, any @code{union} that is
16786 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16787 appears as @samp{@{...@}}.
16788
16789 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16790 with pointers and a memory allocation function. @xref{Expressions,
16791 ,Expressions}.
16792
16793 @node Debugging C Plus Plus
16794 @subsubsection @value{GDBN} Features for C@t{++}
16795
16796 @cindex commands for C@t{++}
16797
16798 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16799 designed specifically for use with C@t{++}. Here is a summary:
16800
16801 @table @code
16802 @cindex break in overloaded functions
16803 @item @r{breakpoint menus}
16804 When you want a breakpoint in a function whose name is overloaded,
16805 @value{GDBN} has the capability to display a menu of possible breakpoint
16806 locations to help you specify which function definition you want.
16807 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16808
16809 @cindex overloading in C@t{++}
16810 @item rbreak @var{regex}
16811 Setting breakpoints using regular expressions is helpful for setting
16812 breakpoints on overloaded functions that are not members of any special
16813 classes.
16814 @xref{Set Breaks, ,Setting Breakpoints}.
16815
16816 @cindex C@t{++} exception handling
16817 @item catch throw
16818 @itemx catch rethrow
16819 @itemx catch catch
16820 Debug C@t{++} exception handling using these commands. @xref{Set
16821 Catchpoints, , Setting Catchpoints}.
16822
16823 @cindex inheritance
16824 @item ptype @var{typename}
16825 Print inheritance relationships as well as other information for type
16826 @var{typename}.
16827 @xref{Symbols, ,Examining the Symbol Table}.
16828
16829 @item info vtbl @var{expression}.
16830 The @code{info vtbl} command can be used to display the virtual
16831 method tables of the object computed by @var{expression}. This shows
16832 one entry per virtual table; there may be multiple virtual tables when
16833 multiple inheritance is in use.
16834
16835 @cindex C@t{++} demangling
16836 @item demangle @var{name}
16837 Demangle @var{name}.
16838 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16839
16840 @cindex C@t{++} symbol display
16841 @item set print demangle
16842 @itemx show print demangle
16843 @itemx set print asm-demangle
16844 @itemx show print asm-demangle
16845 Control whether C@t{++} symbols display in their source form, both when
16846 displaying code as C@t{++} source and when displaying disassemblies.
16847 @xref{Print Settings, ,Print Settings}.
16848
16849 @item set print object
16850 @itemx show print object
16851 Choose whether to print derived (actual) or declared types of objects.
16852 @xref{Print Settings, ,Print Settings}.
16853
16854 @item set print vtbl
16855 @itemx show print vtbl
16856 Control the format for printing virtual function tables.
16857 @xref{Print Settings, ,Print Settings}.
16858 (The @code{vtbl} commands do not work on programs compiled with the HP
16859 ANSI C@t{++} compiler (@code{aCC}).)
16860
16861 @kindex set overload-resolution
16862 @cindex overloaded functions, overload resolution
16863 @item set overload-resolution on
16864 Enable overload resolution for C@t{++} expression evaluation. The default
16865 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16866 and searches for a function whose signature matches the argument types,
16867 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16868 Expressions, ,C@t{++} Expressions}, for details).
16869 If it cannot find a match, it emits a message.
16870
16871 @item set overload-resolution off
16872 Disable overload resolution for C@t{++} expression evaluation. For
16873 overloaded functions that are not class member functions, @value{GDBN}
16874 chooses the first function of the specified name that it finds in the
16875 symbol table, whether or not its arguments are of the correct type. For
16876 overloaded functions that are class member functions, @value{GDBN}
16877 searches for a function whose signature @emph{exactly} matches the
16878 argument types.
16879
16880 @kindex show overload-resolution
16881 @item show overload-resolution
16882 Show the current setting of overload resolution.
16883
16884 @item @r{Overloaded symbol names}
16885 You can specify a particular definition of an overloaded symbol, using
16886 the same notation that is used to declare such symbols in C@t{++}: type
16887 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16888 also use the @value{GDBN} command-line word completion facilities to list the
16889 available choices, or to finish the type list for you.
16890 @xref{Completion,, Command Completion}, for details on how to do this.
16891
16892 @item @r{Breakpoints in template functions}
16893
16894 Similar to how overloaded symbols are handled, @value{GDBN} will ignore
16895 template parameter lists when it encounters a symbol which includes a
16896 C@t{++} template. This permits setting breakpoints on families of template functions
16897 or functions whose parameters include template types.
16898
16899 The @kbd{-qualified} flag may be used to override this behavior, causing
16900 @value{GDBN} to search for a specific function or type.
16901
16902 The @value{GDBN} command-line word completion facility also understands
16903 template parameters and may be used to list available choices or finish
16904 template parameter lists for you. @xref{Completion,, Command Completion}, for
16905 details on how to do this.
16906
16907 @item @r{Breakpoints in functions with ABI tags}
16908
16909 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16910 correspond to changes in the ABI of a type, function, or variable that
16911 would not otherwise be reflected in a mangled name. See
16912 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16913 for more detail.
16914
16915 The ABI tags are visible in C@t{++} demangled names. For example, a
16916 function that returns a std::string:
16917
16918 @smallexample
16919 std::string function(int);
16920 @end smallexample
16921
16922 @noindent
16923 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16924 tag, and @value{GDBN} displays the symbol like this:
16925
16926 @smallexample
16927 function[abi:cxx11](int)
16928 @end smallexample
16929
16930 You can set a breakpoint on such functions simply as if they had no
16931 tag. For example:
16932
16933 @smallexample
16934 (gdb) b function(int)
16935 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16936 (gdb) info breakpoints
16937 Num Type Disp Enb Address What
16938 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16939 at main.cc:10
16940 @end smallexample
16941
16942 On the rare occasion you need to disambiguate between different ABI
16943 tags, you can do so by simply including the ABI tag in the function
16944 name, like:
16945
16946 @smallexample
16947 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16948 @end smallexample
16949 @end table
16950
16951 @node Decimal Floating Point
16952 @subsubsection Decimal Floating Point format
16953 @cindex decimal floating point format
16954
16955 @value{GDBN} can examine, set and perform computations with numbers in
16956 decimal floating point format, which in the C language correspond to the
16957 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16958 specified by the extension to support decimal floating-point arithmetic.
16959
16960 There are two encodings in use, depending on the architecture: BID (Binary
16961 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16962 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16963 configured target.
16964
16965 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16966 to manipulate decimal floating point numbers, it is not possible to convert
16967 (using a cast, for example) integers wider than 32-bit to decimal float.
16968
16969 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16970 point computations, error checking in decimal float operations ignores
16971 underflow, overflow and divide by zero exceptions.
16972
16973 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16974 to inspect @code{_Decimal128} values stored in floating point registers.
16975 See @ref{PowerPC,,PowerPC} for more details.
16976
16977 @node D
16978 @subsection D
16979
16980 @cindex D
16981 @value{GDBN} can be used to debug programs written in D and compiled with
16982 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16983 specific feature --- dynamic arrays.
16984
16985 @node Go
16986 @subsection Go
16987
16988 @cindex Go (programming language)
16989 @value{GDBN} can be used to debug programs written in Go and compiled with
16990 @file{gccgo} or @file{6g} compilers.
16991
16992 Here is a summary of the Go-specific features and restrictions:
16993
16994 @table @code
16995 @cindex current Go package
16996 @item The current Go package
16997 The name of the current package does not need to be specified when
16998 specifying global variables and functions.
16999
17000 For example, given the program:
17001
17002 @example
17003 package main
17004 var myglob = "Shall we?"
17005 func main () @{
17006 // ...
17007 @}
17008 @end example
17009
17010 When stopped inside @code{main} either of these work:
17011
17012 @example
17013 (gdb) p myglob
17014 (gdb) p main.myglob
17015 @end example
17016
17017 @cindex builtin Go types
17018 @item Builtin Go types
17019 The @code{string} type is recognized by @value{GDBN} and is printed
17020 as a string.
17021
17022 @cindex builtin Go functions
17023 @item Builtin Go functions
17024 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
17025 function and handles it internally.
17026
17027 @cindex restrictions on Go expressions
17028 @item Restrictions on Go expressions
17029 All Go operators are supported except @code{&^}.
17030 The Go @code{_} ``blank identifier'' is not supported.
17031 Automatic dereferencing of pointers is not supported.
17032 @end table
17033
17034 @node Objective-C
17035 @subsection Objective-C
17036
17037 @cindex Objective-C
17038 This section provides information about some commands and command
17039 options that are useful for debugging Objective-C code. See also
17040 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
17041 few more commands specific to Objective-C support.
17042
17043 @menu
17044 * Method Names in Commands::
17045 * The Print Command with Objective-C::
17046 @end menu
17047
17048 @node Method Names in Commands
17049 @subsubsection Method Names in Commands
17050
17051 The following commands have been extended to accept Objective-C method
17052 names as line specifications:
17053
17054 @kindex clear@r{, and Objective-C}
17055 @kindex break@r{, and Objective-C}
17056 @kindex info line@r{, and Objective-C}
17057 @kindex jump@r{, and Objective-C}
17058 @kindex list@r{, and Objective-C}
17059 @itemize
17060 @item @code{clear}
17061 @item @code{break}
17062 @item @code{info line}
17063 @item @code{jump}
17064 @item @code{list}
17065 @end itemize
17066
17067 A fully qualified Objective-C method name is specified as
17068
17069 @smallexample
17070 -[@var{Class} @var{methodName}]
17071 @end smallexample
17072
17073 where the minus sign is used to indicate an instance method and a
17074 plus sign (not shown) is used to indicate a class method. The class
17075 name @var{Class} and method name @var{methodName} are enclosed in
17076 brackets, similar to the way messages are specified in Objective-C
17077 source code. For example, to set a breakpoint at the @code{create}
17078 instance method of class @code{Fruit} in the program currently being
17079 debugged, enter:
17080
17081 @smallexample
17082 break -[Fruit create]
17083 @end smallexample
17084
17085 To list ten program lines around the @code{initialize} class method,
17086 enter:
17087
17088 @smallexample
17089 list +[NSText initialize]
17090 @end smallexample
17091
17092 In the current version of @value{GDBN}, the plus or minus sign is
17093 required. In future versions of @value{GDBN}, the plus or minus
17094 sign will be optional, but you can use it to narrow the search. It
17095 is also possible to specify just a method name:
17096
17097 @smallexample
17098 break create
17099 @end smallexample
17100
17101 You must specify the complete method name, including any colons. If
17102 your program's source files contain more than one @code{create} method,
17103 you'll be presented with a numbered list of classes that implement that
17104 method. Indicate your choice by number, or type @samp{0} to exit if
17105 none apply.
17106
17107 As another example, to clear a breakpoint established at the
17108 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
17109
17110 @smallexample
17111 clear -[NSWindow makeKeyAndOrderFront:]
17112 @end smallexample
17113
17114 @node The Print Command with Objective-C
17115 @subsubsection The Print Command With Objective-C
17116 @cindex Objective-C, print objects
17117 @kindex print-object
17118 @kindex po @r{(@code{print-object})}
17119
17120 The print command has also been extended to accept methods. For example:
17121
17122 @smallexample
17123 print -[@var{object} hash]
17124 @end smallexample
17125
17126 @cindex print an Objective-C object description
17127 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
17128 @noindent
17129 will tell @value{GDBN} to send the @code{hash} message to @var{object}
17130 and print the result. Also, an additional command has been added,
17131 @code{print-object} or @code{po} for short, which is meant to print
17132 the description of an object. However, this command may only work
17133 with certain Objective-C libraries that have a particular hook
17134 function, @code{_NSPrintForDebugger}, defined.
17135
17136 @node OpenCL C
17137 @subsection OpenCL C
17138
17139 @cindex OpenCL C
17140 This section provides information about @value{GDBN}s OpenCL C support.
17141
17142 @menu
17143 * OpenCL C Datatypes::
17144 * OpenCL C Expressions::
17145 * OpenCL C Operators::
17146 @end menu
17147
17148 @node OpenCL C Datatypes
17149 @subsubsection OpenCL C Datatypes
17150
17151 @cindex OpenCL C Datatypes
17152 @value{GDBN} supports the builtin scalar and vector datatypes specified
17153 by OpenCL 1.1. In addition the half- and double-precision floating point
17154 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
17155 extensions are also known to @value{GDBN}.
17156
17157 @node OpenCL C Expressions
17158 @subsubsection OpenCL C Expressions
17159
17160 @cindex OpenCL C Expressions
17161 @value{GDBN} supports accesses to vector components including the access as
17162 lvalue where possible. Since OpenCL C is based on C99 most C expressions
17163 supported by @value{GDBN} can be used as well.
17164
17165 @node OpenCL C Operators
17166 @subsubsection OpenCL C Operators
17167
17168 @cindex OpenCL C Operators
17169 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
17170 vector data types.
17171
17172 @node Fortran
17173 @subsection Fortran
17174 @cindex Fortran-specific support in @value{GDBN}
17175
17176 @value{GDBN} can be used to debug programs written in Fortran, but it
17177 currently supports only the features of Fortran 77 language.
17178
17179 @cindex trailing underscore, in Fortran symbols
17180 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
17181 among them) append an underscore to the names of variables and
17182 functions. When you debug programs compiled by those compilers, you
17183 will need to refer to variables and functions with a trailing
17184 underscore.
17185
17186 @menu
17187 * Fortran Operators:: Fortran operators and expressions
17188 * Fortran Defaults:: Default settings for Fortran
17189 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
17190 @end menu
17191
17192 @node Fortran Operators
17193 @subsubsection Fortran Operators and Expressions
17194
17195 @cindex Fortran operators and expressions
17196
17197 Operators must be defined on values of specific types. For instance,
17198 @code{+} is defined on numbers, but not on characters or other non-
17199 arithmetic types. Operators are often defined on groups of types.
17200
17201 @table @code
17202 @item **
17203 The exponentiation operator. It raises the first operand to the power
17204 of the second one.
17205
17206 @item :
17207 The range operator. Normally used in the form of array(low:high) to
17208 represent a section of array.
17209
17210 @item %
17211 The access component operator. Normally used to access elements in derived
17212 types. Also suitable for unions. As unions aren't part of regular Fortran,
17213 this can only happen when accessing a register that uses a gdbarch-defined
17214 union type.
17215 @item ::
17216 The scope operator. Normally used to access variables in modules or
17217 to set breakpoints on subroutines nested in modules or in other
17218 subroutines (internal subroutines).
17219 @end table
17220
17221 @node Fortran Defaults
17222 @subsubsection Fortran Defaults
17223
17224 @cindex Fortran Defaults
17225
17226 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17227 default uses case-insensitive matches for Fortran symbols. You can
17228 change that with the @samp{set case-insensitive} command, see
17229 @ref{Symbols}, for the details.
17230
17231 @node Special Fortran Commands
17232 @subsubsection Special Fortran Commands
17233
17234 @cindex Special Fortran commands
17235
17236 @value{GDBN} has some commands to support Fortran-specific features,
17237 such as displaying common blocks.
17238
17239 @table @code
17240 @cindex @code{COMMON} blocks, Fortran
17241 @kindex info common
17242 @item info common @r{[}@var{common-name}@r{]}
17243 This command prints the values contained in the Fortran @code{COMMON}
17244 block whose name is @var{common-name}. With no argument, the names of
17245 all @code{COMMON} blocks visible at the current program location are
17246 printed.
17247 @cindex arrays slices (Fortran)
17248 @kindex set fortran repack-array-slices
17249 @kindex show fortran repack-array-slices
17250 @item set fortran repack-array-slices [on|off]
17251 @item show fortran repack-array-slices
17252 When taking a slice from an array, a Fortran compiler can choose to
17253 either produce an array descriptor that describes the slice in place,
17254 or it may repack the slice, copying the elements of the slice into a
17255 new region of memory.
17256
17257 When this setting is on, then @value{GDBN} will also repack array
17258 slices in some situations. When this setting is off, then
17259 @value{GDBN} will create array descriptors for slices that reference
17260 the original data in place.
17261
17262 @value{GDBN} will never repack an array slice if the data for the
17263 slice is contiguous within the original array.
17264
17265 @value{GDBN} will always repack string slices if the data for the
17266 slice is non-contiguous within the original string as @value{GDBN}
17267 does not support printing non-contiguous strings.
17268
17269 The default for this setting is @code{off}.
17270 @end table
17271
17272 @node Pascal
17273 @subsection Pascal
17274
17275 @cindex Pascal support in @value{GDBN}, limitations
17276 Debugging Pascal programs which use sets, subranges, file variables, or
17277 nested functions does not currently work. @value{GDBN} does not support
17278 entering expressions, printing values, or similar features using Pascal
17279 syntax.
17280
17281 The Pascal-specific command @code{set print pascal_static-members}
17282 controls whether static members of Pascal objects are displayed.
17283 @xref{Print Settings, pascal_static-members}.
17284
17285 @node Rust
17286 @subsection Rust
17287
17288 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17289 Programming Language}. Type- and value-printing, and expression
17290 parsing, are reasonably complete. However, there are a few
17291 peculiarities and holes to be aware of.
17292
17293 @itemize @bullet
17294 @item
17295 Linespecs (@pxref{Specify Location}) are never relative to the current
17296 crate. Instead, they act as if there were a global namespace of
17297 crates, somewhat similar to the way @code{extern crate} behaves.
17298
17299 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17300 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17301 to set a breakpoint in a function named @samp{f} in a crate named
17302 @samp{B}.
17303
17304 As a consequence of this approach, linespecs also cannot refer to
17305 items using @samp{self::} or @samp{super::}.
17306
17307 @item
17308 Because @value{GDBN} implements Rust name-lookup semantics in
17309 expressions, it will sometimes prepend the current crate to a name.
17310 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17311 @samp{K}, then @code{print ::x::y} will try to find the symbol
17312 @samp{K::x::y}.
17313
17314 However, since it is useful to be able to refer to other crates when
17315 debugging, @value{GDBN} provides the @code{extern} extension to
17316 circumvent this. To use the extension, just put @code{extern} before
17317 a path expression to refer to the otherwise unavailable ``global''
17318 scope.
17319
17320 In the above example, if you wanted to refer to the symbol @samp{y} in
17321 the crate @samp{x}, you would use @code{print extern x::y}.
17322
17323 @item
17324 The Rust expression evaluator does not support ``statement-like''
17325 expressions such as @code{if} or @code{match}, or lambda expressions.
17326
17327 @item
17328 Tuple expressions are not implemented.
17329
17330 @item
17331 The Rust expression evaluator does not currently implement the
17332 @code{Drop} trait. Objects that may be created by the evaluator will
17333 never be destroyed.
17334
17335 @item
17336 @value{GDBN} does not implement type inference for generics. In order
17337 to call generic functions or otherwise refer to generic items, you
17338 will have to specify the type parameters manually.
17339
17340 @item
17341 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17342 cases this does not cause any problems. However, in an expression
17343 context, completing a generic function name will give syntactically
17344 invalid results. This happens because Rust requires the @samp{::}
17345 operator between the function name and its generic arguments. For
17346 example, @value{GDBN} might provide a completion like
17347 @code{crate::f<u32>}, where the parser would require
17348 @code{crate::f::<u32>}.
17349
17350 @item
17351 As of this writing, the Rust compiler (version 1.8) has a few holes in
17352 the debugging information it generates. These holes prevent certain
17353 features from being implemented by @value{GDBN}:
17354 @itemize @bullet
17355
17356 @item
17357 Method calls cannot be made via traits.
17358
17359 @item
17360 Operator overloading is not implemented.
17361
17362 @item
17363 When debugging in a monomorphized function, you cannot use the generic
17364 type names.
17365
17366 @item
17367 The type @code{Self} is not available.
17368
17369 @item
17370 @code{use} statements are not available, so some names may not be
17371 available in the crate.
17372 @end itemize
17373 @end itemize
17374
17375 @node Modula-2
17376 @subsection Modula-2
17377
17378 @cindex Modula-2, @value{GDBN} support
17379
17380 The extensions made to @value{GDBN} to support Modula-2 only support
17381 output from the @sc{gnu} Modula-2 compiler (which is currently being
17382 developed). Other Modula-2 compilers are not currently supported, and
17383 attempting to debug executables produced by them is most likely
17384 to give an error as @value{GDBN} reads in the executable's symbol
17385 table.
17386
17387 @cindex expressions in Modula-2
17388 @menu
17389 * M2 Operators:: Built-in operators
17390 * Built-In Func/Proc:: Built-in functions and procedures
17391 * M2 Constants:: Modula-2 constants
17392 * M2 Types:: Modula-2 types
17393 * M2 Defaults:: Default settings for Modula-2
17394 * Deviations:: Deviations from standard Modula-2
17395 * M2 Checks:: Modula-2 type and range checks
17396 * M2 Scope:: The scope operators @code{::} and @code{.}
17397 * GDB/M2:: @value{GDBN} and Modula-2
17398 @end menu
17399
17400 @node M2 Operators
17401 @subsubsection Operators
17402 @cindex Modula-2 operators
17403
17404 Operators must be defined on values of specific types. For instance,
17405 @code{+} is defined on numbers, but not on structures. Operators are
17406 often defined on groups of types. For the purposes of Modula-2, the
17407 following definitions hold:
17408
17409 @itemize @bullet
17410
17411 @item
17412 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17413 their subranges.
17414
17415 @item
17416 @emph{Character types} consist of @code{CHAR} and its subranges.
17417
17418 @item
17419 @emph{Floating-point types} consist of @code{REAL}.
17420
17421 @item
17422 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17423 @var{type}}.
17424
17425 @item
17426 @emph{Scalar types} consist of all of the above.
17427
17428 @item
17429 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17430
17431 @item
17432 @emph{Boolean types} consist of @code{BOOLEAN}.
17433 @end itemize
17434
17435 @noindent
17436 The following operators are supported, and appear in order of
17437 increasing precedence:
17438
17439 @table @code
17440 @item ,
17441 Function argument or array index separator.
17442
17443 @item :=
17444 Assignment. The value of @var{var} @code{:=} @var{value} is
17445 @var{value}.
17446
17447 @item <@r{, }>
17448 Less than, greater than on integral, floating-point, or enumerated
17449 types.
17450
17451 @item <=@r{, }>=
17452 Less than or equal to, greater than or equal to
17453 on integral, floating-point and enumerated types, or set inclusion on
17454 set types. Same precedence as @code{<}.
17455
17456 @item =@r{, }<>@r{, }#
17457 Equality and two ways of expressing inequality, valid on scalar types.
17458 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17459 available for inequality, since @code{#} conflicts with the script
17460 comment character.
17461
17462 @item IN
17463 Set membership. Defined on set types and the types of their members.
17464 Same precedence as @code{<}.
17465
17466 @item OR
17467 Boolean disjunction. Defined on boolean types.
17468
17469 @item AND@r{, }&
17470 Boolean conjunction. Defined on boolean types.
17471
17472 @item @@
17473 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17474
17475 @item +@r{, }-
17476 Addition and subtraction on integral and floating-point types, or union
17477 and difference on set types.
17478
17479 @item *
17480 Multiplication on integral and floating-point types, or set intersection
17481 on set types.
17482
17483 @item /
17484 Division on floating-point types, or symmetric set difference on set
17485 types. Same precedence as @code{*}.
17486
17487 @item DIV@r{, }MOD
17488 Integer division and remainder. Defined on integral types. Same
17489 precedence as @code{*}.
17490
17491 @item -
17492 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17493
17494 @item ^
17495 Pointer dereferencing. Defined on pointer types.
17496
17497 @item NOT
17498 Boolean negation. Defined on boolean types. Same precedence as
17499 @code{^}.
17500
17501 @item .
17502 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17503 precedence as @code{^}.
17504
17505 @item []
17506 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17507
17508 @item ()
17509 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17510 as @code{^}.
17511
17512 @item ::@r{, }.
17513 @value{GDBN} and Modula-2 scope operators.
17514 @end table
17515
17516 @quotation
17517 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17518 treats the use of the operator @code{IN}, or the use of operators
17519 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17520 @code{<=}, and @code{>=} on sets as an error.
17521 @end quotation
17522
17523
17524 @node Built-In Func/Proc
17525 @subsubsection Built-in Functions and Procedures
17526 @cindex Modula-2 built-ins
17527
17528 Modula-2 also makes available several built-in procedures and functions.
17529 In describing these, the following metavariables are used:
17530
17531 @table @var
17532
17533 @item a
17534 represents an @code{ARRAY} variable.
17535
17536 @item c
17537 represents a @code{CHAR} constant or variable.
17538
17539 @item i
17540 represents a variable or constant of integral type.
17541
17542 @item m
17543 represents an identifier that belongs to a set. Generally used in the
17544 same function with the metavariable @var{s}. The type of @var{s} should
17545 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17546
17547 @item n
17548 represents a variable or constant of integral or floating-point type.
17549
17550 @item r
17551 represents a variable or constant of floating-point type.
17552
17553 @item t
17554 represents a type.
17555
17556 @item v
17557 represents a variable.
17558
17559 @item x
17560 represents a variable or constant of one of many types. See the
17561 explanation of the function for details.
17562 @end table
17563
17564 All Modula-2 built-in procedures also return a result, described below.
17565
17566 @table @code
17567 @item ABS(@var{n})
17568 Returns the absolute value of @var{n}.
17569
17570 @item CAP(@var{c})
17571 If @var{c} is a lower case letter, it returns its upper case
17572 equivalent, otherwise it returns its argument.
17573
17574 @item CHR(@var{i})
17575 Returns the character whose ordinal value is @var{i}.
17576
17577 @item DEC(@var{v})
17578 Decrements the value in the variable @var{v} by one. Returns the new value.
17579
17580 @item DEC(@var{v},@var{i})
17581 Decrements the value in the variable @var{v} by @var{i}. Returns the
17582 new value.
17583
17584 @item EXCL(@var{m},@var{s})
17585 Removes the element @var{m} from the set @var{s}. Returns the new
17586 set.
17587
17588 @item FLOAT(@var{i})
17589 Returns the floating point equivalent of the integer @var{i}.
17590
17591 @item HIGH(@var{a})
17592 Returns the index of the last member of @var{a}.
17593
17594 @item INC(@var{v})
17595 Increments the value in the variable @var{v} by one. Returns the new value.
17596
17597 @item INC(@var{v},@var{i})
17598 Increments the value in the variable @var{v} by @var{i}. Returns the
17599 new value.
17600
17601 @item INCL(@var{m},@var{s})
17602 Adds the element @var{m} to the set @var{s} if it is not already
17603 there. Returns the new set.
17604
17605 @item MAX(@var{t})
17606 Returns the maximum value of the type @var{t}.
17607
17608 @item MIN(@var{t})
17609 Returns the minimum value of the type @var{t}.
17610
17611 @item ODD(@var{i})
17612 Returns boolean TRUE if @var{i} is an odd number.
17613
17614 @item ORD(@var{x})
17615 Returns the ordinal value of its argument. For example, the ordinal
17616 value of a character is its @sc{ascii} value (on machines supporting
17617 the @sc{ascii} character set). The argument @var{x} must be of an
17618 ordered type, which include integral, character and enumerated types.
17619
17620 @item SIZE(@var{x})
17621 Returns the size of its argument. The argument @var{x} can be a
17622 variable or a type.
17623
17624 @item TRUNC(@var{r})
17625 Returns the integral part of @var{r}.
17626
17627 @item TSIZE(@var{x})
17628 Returns the size of its argument. The argument @var{x} can be a
17629 variable or a type.
17630
17631 @item VAL(@var{t},@var{i})
17632 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17633 @end table
17634
17635 @quotation
17636 @emph{Warning:} Sets and their operations are not yet supported, so
17637 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17638 an error.
17639 @end quotation
17640
17641 @cindex Modula-2 constants
17642 @node M2 Constants
17643 @subsubsection Constants
17644
17645 @value{GDBN} allows you to express the constants of Modula-2 in the following
17646 ways:
17647
17648 @itemize @bullet
17649
17650 @item
17651 Integer constants are simply a sequence of digits. When used in an
17652 expression, a constant is interpreted to be type-compatible with the
17653 rest of the expression. Hexadecimal integers are specified by a
17654 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17655
17656 @item
17657 Floating point constants appear as a sequence of digits, followed by a
17658 decimal point and another sequence of digits. An optional exponent can
17659 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17660 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17661 digits of the floating point constant must be valid decimal (base 10)
17662 digits.
17663
17664 @item
17665 Character constants consist of a single character enclosed by a pair of
17666 like quotes, either single (@code{'}) or double (@code{"}). They may
17667 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17668 followed by a @samp{C}.
17669
17670 @item
17671 String constants consist of a sequence of characters enclosed by a
17672 pair of like quotes, either single (@code{'}) or double (@code{"}).
17673 Escape sequences in the style of C are also allowed. @xref{C
17674 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17675 sequences.
17676
17677 @item
17678 Enumerated constants consist of an enumerated identifier.
17679
17680 @item
17681 Boolean constants consist of the identifiers @code{TRUE} and
17682 @code{FALSE}.
17683
17684 @item
17685 Pointer constants consist of integral values only.
17686
17687 @item
17688 Set constants are not yet supported.
17689 @end itemize
17690
17691 @node M2 Types
17692 @subsubsection Modula-2 Types
17693 @cindex Modula-2 types
17694
17695 Currently @value{GDBN} can print the following data types in Modula-2
17696 syntax: array types, record types, set types, pointer types, procedure
17697 types, enumerated types, subrange types and base types. You can also
17698 print the contents of variables declared using these type.
17699 This section gives a number of simple source code examples together with
17700 sample @value{GDBN} sessions.
17701
17702 The first example contains the following section of code:
17703
17704 @smallexample
17705 VAR
17706 s: SET OF CHAR ;
17707 r: [20..40] ;
17708 @end smallexample
17709
17710 @noindent
17711 and you can request @value{GDBN} to interrogate the type and value of
17712 @code{r} and @code{s}.
17713
17714 @smallexample
17715 (@value{GDBP}) print s
17716 @{'A'..'C', 'Z'@}
17717 (@value{GDBP}) ptype s
17718 SET OF CHAR
17719 (@value{GDBP}) print r
17720 21
17721 (@value{GDBP}) ptype r
17722 [20..40]
17723 @end smallexample
17724
17725 @noindent
17726 Likewise if your source code declares @code{s} as:
17727
17728 @smallexample
17729 VAR
17730 s: SET ['A'..'Z'] ;
17731 @end smallexample
17732
17733 @noindent
17734 then you may query the type of @code{s} by:
17735
17736 @smallexample
17737 (@value{GDBP}) ptype s
17738 type = SET ['A'..'Z']
17739 @end smallexample
17740
17741 @noindent
17742 Note that at present you cannot interactively manipulate set
17743 expressions using the debugger.
17744
17745 The following example shows how you might declare an array in Modula-2
17746 and how you can interact with @value{GDBN} to print its type and contents:
17747
17748 @smallexample
17749 VAR
17750 s: ARRAY [-10..10] OF CHAR ;
17751 @end smallexample
17752
17753 @smallexample
17754 (@value{GDBP}) ptype s
17755 ARRAY [-10..10] OF CHAR
17756 @end smallexample
17757
17758 Note that the array handling is not yet complete and although the type
17759 is printed correctly, expression handling still assumes that all
17760 arrays have a lower bound of zero and not @code{-10} as in the example
17761 above.
17762
17763 Here are some more type related Modula-2 examples:
17764
17765 @smallexample
17766 TYPE
17767 colour = (blue, red, yellow, green) ;
17768 t = [blue..yellow] ;
17769 VAR
17770 s: t ;
17771 BEGIN
17772 s := blue ;
17773 @end smallexample
17774
17775 @noindent
17776 The @value{GDBN} interaction shows how you can query the data type
17777 and value of a variable.
17778
17779 @smallexample
17780 (@value{GDBP}) print s
17781 $1 = blue
17782 (@value{GDBP}) ptype t
17783 type = [blue..yellow]
17784 @end smallexample
17785
17786 @noindent
17787 In this example a Modula-2 array is declared and its contents
17788 displayed. Observe that the contents are written in the same way as
17789 their @code{C} counterparts.
17790
17791 @smallexample
17792 VAR
17793 s: ARRAY [1..5] OF CARDINAL ;
17794 BEGIN
17795 s[1] := 1 ;
17796 @end smallexample
17797
17798 @smallexample
17799 (@value{GDBP}) print s
17800 $1 = @{1, 0, 0, 0, 0@}
17801 (@value{GDBP}) ptype s
17802 type = ARRAY [1..5] OF CARDINAL
17803 @end smallexample
17804
17805 The Modula-2 language interface to @value{GDBN} also understands
17806 pointer types as shown in this example:
17807
17808 @smallexample
17809 VAR
17810 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17811 BEGIN
17812 NEW(s) ;
17813 s^[1] := 1 ;
17814 @end smallexample
17815
17816 @noindent
17817 and you can request that @value{GDBN} describes the type of @code{s}.
17818
17819 @smallexample
17820 (@value{GDBP}) ptype s
17821 type = POINTER TO ARRAY [1..5] OF CARDINAL
17822 @end smallexample
17823
17824 @value{GDBN} handles compound types as we can see in this example.
17825 Here we combine array types, record types, pointer types and subrange
17826 types:
17827
17828 @smallexample
17829 TYPE
17830 foo = RECORD
17831 f1: CARDINAL ;
17832 f2: CHAR ;
17833 f3: myarray ;
17834 END ;
17835
17836 myarray = ARRAY myrange OF CARDINAL ;
17837 myrange = [-2..2] ;
17838 VAR
17839 s: POINTER TO ARRAY myrange OF foo ;
17840 @end smallexample
17841
17842 @noindent
17843 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17844 below.
17845
17846 @smallexample
17847 (@value{GDBP}) ptype s
17848 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17849 f1 : CARDINAL;
17850 f2 : CHAR;
17851 f3 : ARRAY [-2..2] OF CARDINAL;
17852 END
17853 @end smallexample
17854
17855 @node M2 Defaults
17856 @subsubsection Modula-2 Defaults
17857 @cindex Modula-2 defaults
17858
17859 If type and range checking are set automatically by @value{GDBN}, they
17860 both default to @code{on} whenever the working language changes to
17861 Modula-2. This happens regardless of whether you or @value{GDBN}
17862 selected the working language.
17863
17864 If you allow @value{GDBN} to set the language automatically, then entering
17865 code compiled from a file whose name ends with @file{.mod} sets the
17866 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17867 Infer the Source Language}, for further details.
17868
17869 @node Deviations
17870 @subsubsection Deviations from Standard Modula-2
17871 @cindex Modula-2, deviations from
17872
17873 A few changes have been made to make Modula-2 programs easier to debug.
17874 This is done primarily via loosening its type strictness:
17875
17876 @itemize @bullet
17877 @item
17878 Unlike in standard Modula-2, pointer constants can be formed by
17879 integers. This allows you to modify pointer variables during
17880 debugging. (In standard Modula-2, the actual address contained in a
17881 pointer variable is hidden from you; it can only be modified
17882 through direct assignment to another pointer variable or expression that
17883 returned a pointer.)
17884
17885 @item
17886 C escape sequences can be used in strings and characters to represent
17887 non-printable characters. @value{GDBN} prints out strings with these
17888 escape sequences embedded. Single non-printable characters are
17889 printed using the @samp{CHR(@var{nnn})} format.
17890
17891 @item
17892 The assignment operator (@code{:=}) returns the value of its right-hand
17893 argument.
17894
17895 @item
17896 All built-in procedures both modify @emph{and} return their argument.
17897 @end itemize
17898
17899 @node M2 Checks
17900 @subsubsection Modula-2 Type and Range Checks
17901 @cindex Modula-2 checks
17902
17903 @quotation
17904 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17905 range checking.
17906 @end quotation
17907 @c FIXME remove warning when type/range checks added
17908
17909 @value{GDBN} considers two Modula-2 variables type equivalent if:
17910
17911 @itemize @bullet
17912 @item
17913 They are of types that have been declared equivalent via a @code{TYPE
17914 @var{t1} = @var{t2}} statement
17915
17916 @item
17917 They have been declared on the same line. (Note: This is true of the
17918 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17919 @end itemize
17920
17921 As long as type checking is enabled, any attempt to combine variables
17922 whose types are not equivalent is an error.
17923
17924 Range checking is done on all mathematical operations, assignment, array
17925 index bounds, and all built-in functions and procedures.
17926
17927 @node M2 Scope
17928 @subsubsection The Scope Operators @code{::} and @code{.}
17929 @cindex scope
17930 @cindex @code{.}, Modula-2 scope operator
17931 @cindex colon, doubled as scope operator
17932 @ifinfo
17933 @vindex colon-colon@r{, in Modula-2}
17934 @c Info cannot handle :: but TeX can.
17935 @end ifinfo
17936 @ifnotinfo
17937 @vindex ::@r{, in Modula-2}
17938 @end ifnotinfo
17939
17940 There are a few subtle differences between the Modula-2 scope operator
17941 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17942 similar syntax:
17943
17944 @smallexample
17945
17946 @var{module} . @var{id}
17947 @var{scope} :: @var{id}
17948 @end smallexample
17949
17950 @noindent
17951 where @var{scope} is the name of a module or a procedure,
17952 @var{module} the name of a module, and @var{id} is any declared
17953 identifier within your program, except another module.
17954
17955 Using the @code{::} operator makes @value{GDBN} search the scope
17956 specified by @var{scope} for the identifier @var{id}. If it is not
17957 found in the specified scope, then @value{GDBN} searches all scopes
17958 enclosing the one specified by @var{scope}.
17959
17960 Using the @code{.} operator makes @value{GDBN} search the current scope for
17961 the identifier specified by @var{id} that was imported from the
17962 definition module specified by @var{module}. With this operator, it is
17963 an error if the identifier @var{id} was not imported from definition
17964 module @var{module}, or if @var{id} is not an identifier in
17965 @var{module}.
17966
17967 @node GDB/M2
17968 @subsubsection @value{GDBN} and Modula-2
17969
17970 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17971 Five subcommands of @code{set print} and @code{show print} apply
17972 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17973 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17974 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17975 analogue in Modula-2.
17976
17977 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17978 with any language, is not useful with Modula-2. Its
17979 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17980 created in Modula-2 as they can in C or C@t{++}. However, because an
17981 address can be specified by an integral constant, the construct
17982 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17983
17984 @cindex @code{#} in Modula-2
17985 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17986 interpreted as the beginning of a comment. Use @code{<>} instead.
17987
17988 @node Ada
17989 @subsection Ada
17990 @cindex Ada
17991
17992 The extensions made to @value{GDBN} for Ada only support
17993 output from the @sc{gnu} Ada (GNAT) compiler.
17994 Other Ada compilers are not currently supported, and
17995 attempting to debug executables produced by them is most likely
17996 to be difficult.
17997
17998
17999 @cindex expressions in Ada
18000 @menu
18001 * Ada Mode Intro:: General remarks on the Ada syntax
18002 and semantics supported by Ada mode
18003 in @value{GDBN}.
18004 * Omissions from Ada:: Restrictions on the Ada expression syntax.
18005 * Additions to Ada:: Extensions of the Ada expression syntax.
18006 * Overloading support for Ada:: Support for expressions involving overloaded
18007 subprograms.
18008 * Stopping Before Main Program:: Debugging the program during elaboration.
18009 * Ada Exceptions:: Ada Exceptions
18010 * Ada Tasks:: Listing and setting breakpoints in tasks.
18011 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
18012 * Ravenscar Profile:: Tasking Support when using the Ravenscar
18013 Profile
18014 * Ada Settings:: New settable GDB parameters for Ada.
18015 * Ada Source Character Set:: Character set of Ada source files.
18016 * Ada Glitches:: Known peculiarities of Ada mode.
18017 @end menu
18018
18019 @node Ada Mode Intro
18020 @subsubsection Introduction
18021 @cindex Ada mode, general
18022
18023 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
18024 syntax, with some extensions.
18025 The philosophy behind the design of this subset is
18026
18027 @itemize @bullet
18028 @item
18029 That @value{GDBN} should provide basic literals and access to operations for
18030 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
18031 leaving more sophisticated computations to subprograms written into the
18032 program (which therefore may be called from @value{GDBN}).
18033
18034 @item
18035 That type safety and strict adherence to Ada language restrictions
18036 are not particularly important to the @value{GDBN} user.
18037
18038 @item
18039 That brevity is important to the @value{GDBN} user.
18040 @end itemize
18041
18042 Thus, for brevity, the debugger acts as if all names declared in
18043 user-written packages are directly visible, even if they are not visible
18044 according to Ada rules, thus making it unnecessary to fully qualify most
18045 names with their packages, regardless of context. Where this causes
18046 ambiguity, @value{GDBN} asks the user's intent.
18047
18048 The debugger will start in Ada mode if it detects an Ada main program.
18049 As for other languages, it will enter Ada mode when stopped in a program that
18050 was translated from an Ada source file.
18051
18052 While in Ada mode, you may use `@t{--}' for comments. This is useful
18053 mostly for documenting command files. The standard @value{GDBN} comment
18054 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
18055 middle (to allow based literals).
18056
18057 @node Omissions from Ada
18058 @subsubsection Omissions from Ada
18059 @cindex Ada, omissions from
18060
18061 Here are the notable omissions from the subset:
18062
18063 @itemize @bullet
18064 @item
18065 Only a subset of the attributes are supported:
18066
18067 @itemize @minus
18068 @item
18069 @t{'First}, @t{'Last}, and @t{'Length}
18070 on array objects (not on types and subtypes).
18071
18072 @item
18073 @t{'Min} and @t{'Max}.
18074
18075 @item
18076 @t{'Pos} and @t{'Val}.
18077
18078 @item
18079 @t{'Tag}.
18080
18081 @item
18082 @t{'Range} on array objects (not subtypes), but only as the right
18083 operand of the membership (@code{in}) operator.
18084
18085 @item
18086 @t{'Access}, @t{'Unchecked_Access}, and
18087 @t{'Unrestricted_Access} (a GNAT extension).
18088
18089 @item
18090 @t{'Address}.
18091 @end itemize
18092
18093 @item
18094 The names in
18095 @code{Characters.Latin_1} are not available and
18096 concatenation is not implemented. Thus, escape characters in strings are
18097 not currently available.
18098
18099 @item
18100 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
18101 equality of representations. They will generally work correctly
18102 for strings and arrays whose elements have integer or enumeration types.
18103 They may not work correctly for arrays whose element
18104 types have user-defined equality, for arrays of real values
18105 (in particular, IEEE-conformant floating point, because of negative
18106 zeroes and NaNs), and for arrays whose elements contain unused bits with
18107 indeterminate values.
18108
18109 @item
18110 The other component-by-component array operations (@code{and}, @code{or},
18111 @code{xor}, @code{not}, and relational tests other than equality)
18112 are not implemented.
18113
18114 @item
18115 @cindex array aggregates (Ada)
18116 @cindex record aggregates (Ada)
18117 @cindex aggregates (Ada)
18118 There is limited support for array and record aggregates. They are
18119 permitted only on the right sides of assignments, as in these examples:
18120
18121 @smallexample
18122 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
18123 (@value{GDBP}) set An_Array := (1, others => 0)
18124 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
18125 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
18126 (@value{GDBP}) set A_Record := (1, "Peter", True);
18127 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
18128 @end smallexample
18129
18130 Changing a
18131 discriminant's value by assigning an aggregate has an
18132 undefined effect if that discriminant is used within the record.
18133 However, you can first modify discriminants by directly assigning to
18134 them (which normally would not be allowed in Ada), and then performing an
18135 aggregate assignment. For example, given a variable @code{A_Rec}
18136 declared to have a type such as:
18137
18138 @smallexample
18139 type Rec (Len : Small_Integer := 0) is record
18140 Id : Integer;
18141 Vals : IntArray (1 .. Len);
18142 end record;
18143 @end smallexample
18144
18145 you can assign a value with a different size of @code{Vals} with two
18146 assignments:
18147
18148 @smallexample
18149 (@value{GDBP}) set A_Rec.Len := 4
18150 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
18151 @end smallexample
18152
18153 As this example also illustrates, @value{GDBN} is very loose about the usual
18154 rules concerning aggregates. You may leave out some of the
18155 components of an array or record aggregate (such as the @code{Len}
18156 component in the assignment to @code{A_Rec} above); they will retain their
18157 original values upon assignment. You may freely use dynamic values as
18158 indices in component associations. You may even use overlapping or
18159 redundant component associations, although which component values are
18160 assigned in such cases is not defined.
18161
18162 @item
18163 Calls to dispatching subprograms are not implemented.
18164
18165 @item
18166 The overloading algorithm is much more limited (i.e., less selective)
18167 than that of real Ada. It makes only limited use of the context in
18168 which a subexpression appears to resolve its meaning, and it is much
18169 looser in its rules for allowing type matches. As a result, some
18170 function calls will be ambiguous, and the user will be asked to choose
18171 the proper resolution.
18172
18173 @item
18174 The @code{new} operator is not implemented.
18175
18176 @item
18177 Entry calls are not implemented.
18178
18179 @item
18180 Aside from printing, arithmetic operations on the native VAX floating-point
18181 formats are not supported.
18182
18183 @item
18184 It is not possible to slice a packed array.
18185
18186 @item
18187 The names @code{True} and @code{False}, when not part of a qualified name,
18188 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
18189 context.
18190 Should your program
18191 redefine these names in a package or procedure (at best a dubious practice),
18192 you will have to use fully qualified names to access their new definitions.
18193 @end itemize
18194
18195 @node Additions to Ada
18196 @subsubsection Additions to Ada
18197 @cindex Ada, deviations from
18198
18199 As it does for other languages, @value{GDBN} makes certain generic
18200 extensions to Ada (@pxref{Expressions}):
18201
18202 @itemize @bullet
18203 @item
18204 If the expression @var{E} is a variable residing in memory (typically
18205 a local variable or array element) and @var{N} is a positive integer,
18206 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18207 @var{N}-1 adjacent variables following it in memory as an array. In
18208 Ada, this operator is generally not necessary, since its prime use is
18209 in displaying parts of an array, and slicing will usually do this in
18210 Ada. However, there are occasional uses when debugging programs in
18211 which certain debugging information has been optimized away.
18212
18213 @item
18214 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18215 appears in function or file @var{B}.'' When @var{B} is a file name,
18216 you must typically surround it in single quotes.
18217
18218 @item
18219 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18220 @var{type} that appears at address @var{addr}.''
18221
18222 @item
18223 A name starting with @samp{$} is a convenience variable
18224 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18225 @end itemize
18226
18227 In addition, @value{GDBN} provides a few other shortcuts and outright
18228 additions specific to Ada:
18229
18230 @itemize @bullet
18231 @item
18232 The assignment statement is allowed as an expression, returning
18233 its right-hand operand as its value. Thus, you may enter
18234
18235 @smallexample
18236 (@value{GDBP}) set x := y + 3
18237 (@value{GDBP}) print A(tmp := y + 1)
18238 @end smallexample
18239
18240 @item
18241 The semicolon is allowed as an ``operator,'' returning as its value
18242 the value of its right-hand operand.
18243 This allows, for example,
18244 complex conditional breaks:
18245
18246 @smallexample
18247 (@value{GDBP}) break f
18248 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18249 @end smallexample
18250
18251 @item
18252 Rather than use catenation and symbolic character names to introduce special
18253 characters into strings, one may instead use a special bracket notation,
18254 which is also used to print strings. A sequence of characters of the form
18255 @samp{["@var{XX}"]} within a string or character literal denotes the
18256 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18257 sequence of characters @samp{["""]} also denotes a single quotation mark
18258 in strings. For example,
18259 @smallexample
18260 "One line.["0a"]Next line.["0a"]"
18261 @end smallexample
18262 @noindent
18263 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18264 after each period.
18265
18266 @item
18267 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18268 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18269 to write
18270
18271 @smallexample
18272 (@value{GDBP}) print 'max(x, y)
18273 @end smallexample
18274
18275 @item
18276 When printing arrays, @value{GDBN} uses positional notation when the
18277 array has a lower bound of 1, and uses a modified named notation otherwise.
18278 For example, a one-dimensional array of three integers with a lower bound
18279 of 3 might print as
18280
18281 @smallexample
18282 (3 => 10, 17, 1)
18283 @end smallexample
18284
18285 @noindent
18286 That is, in contrast to valid Ada, only the first component has a @code{=>}
18287 clause.
18288
18289 @item
18290 You may abbreviate attributes in expressions with any unique,
18291 multi-character subsequence of
18292 their names (an exact match gets preference).
18293 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18294 in place of @t{a'length}.
18295
18296 @item
18297 @cindex quoting Ada internal identifiers
18298 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18299 to lower case. The GNAT compiler uses upper-case characters for
18300 some of its internal identifiers, which are normally of no interest to users.
18301 For the rare occasions when you actually have to look at them,
18302 enclose them in angle brackets to avoid the lower-case mapping.
18303 For example,
18304 @smallexample
18305 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18306 @end smallexample
18307
18308 @item
18309 Printing an object of class-wide type or dereferencing an
18310 access-to-class-wide value will display all the components of the object's
18311 specific type (as indicated by its run-time tag). Likewise, component
18312 selection on such a value will operate on the specific type of the
18313 object.
18314
18315 @end itemize
18316
18317 @node Overloading support for Ada
18318 @subsubsection Overloading support for Ada
18319 @cindex overloading, Ada
18320
18321 The debugger supports limited overloading. Given a subprogram call in which
18322 the function symbol has multiple definitions, it will use the number of
18323 actual parameters and some information about their types to attempt to narrow
18324 the set of definitions. It also makes very limited use of context, preferring
18325 procedures to functions in the context of the @code{call} command, and
18326 functions to procedures elsewhere.
18327
18328 If, after narrowing, the set of matching definitions still contains more than
18329 one definition, @value{GDBN} will display a menu to query which one it should
18330 use, for instance:
18331
18332 @smallexample
18333 (@value{GDBP}) print f(1)
18334 Multiple matches for f
18335 [0] cancel
18336 [1] foo.f (integer) return boolean at foo.adb:23
18337 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18338 >
18339 @end smallexample
18340
18341 In this case, just select one menu entry either to cancel expression evaluation
18342 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18343 instance (type the corresponding number and press @key{RET}).
18344
18345 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18346 case:
18347
18348 @table @code
18349
18350 @kindex set ada print-signatures
18351 @item set ada print-signatures
18352 Control whether parameter types and return types are displayed in overloads
18353 selection menus. It is @code{on} by default.
18354 @xref{Overloading support for Ada}.
18355
18356 @kindex show ada print-signatures
18357 @item show ada print-signatures
18358 Show the current setting for displaying parameter types and return types in
18359 overloads selection menu.
18360 @xref{Overloading support for Ada}.
18361
18362 @end table
18363
18364 @node Stopping Before Main Program
18365 @subsubsection Stopping at the Very Beginning
18366
18367 @cindex breakpointing Ada elaboration code
18368 It is sometimes necessary to debug the program during elaboration, and
18369 before reaching the main procedure.
18370 As defined in the Ada Reference
18371 Manual, the elaboration code is invoked from a procedure called
18372 @code{adainit}. To run your program up to the beginning of
18373 elaboration, simply use the following two commands:
18374 @code{tbreak adainit} and @code{run}.
18375
18376 @node Ada Exceptions
18377 @subsubsection Ada Exceptions
18378
18379 A command is provided to list all Ada exceptions:
18380
18381 @table @code
18382 @kindex info exceptions
18383 @item info exceptions
18384 @itemx info exceptions @var{regexp}
18385 The @code{info exceptions} command allows you to list all Ada exceptions
18386 defined within the program being debugged, as well as their addresses.
18387 With a regular expression, @var{regexp}, as argument, only those exceptions
18388 whose names match @var{regexp} are listed.
18389 @end table
18390
18391 Below is a small example, showing how the command can be used, first
18392 without argument, and next with a regular expression passed as an
18393 argument.
18394
18395 @smallexample
18396 (@value{GDBP}) info exceptions
18397 All defined Ada exceptions:
18398 constraint_error: 0x613da0
18399 program_error: 0x613d20
18400 storage_error: 0x613ce0
18401 tasking_error: 0x613ca0
18402 const.aint_global_e: 0x613b00
18403 (@value{GDBP}) info exceptions const.aint
18404 All Ada exceptions matching regular expression "const.aint":
18405 constraint_error: 0x613da0
18406 const.aint_global_e: 0x613b00
18407 @end smallexample
18408
18409 It is also possible to ask @value{GDBN} to stop your program's execution
18410 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18411
18412 @node Ada Tasks
18413 @subsubsection Extensions for Ada Tasks
18414 @cindex Ada, tasking
18415
18416 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18417 @value{GDBN} provides the following task-related commands:
18418
18419 @table @code
18420 @kindex info tasks
18421 @item info tasks
18422 This command shows a list of current Ada tasks, as in the following example:
18423
18424
18425 @smallexample
18426 @iftex
18427 @leftskip=0.5cm
18428 @end iftex
18429 (@value{GDBP}) info tasks
18430 ID TID P-ID Pri State Name
18431 1 8088000 0 15 Child Activation Wait main_task
18432 2 80a4000 1 15 Accept Statement b
18433 3 809a800 1 15 Child Activation Wait a
18434 * 4 80ae800 3 15 Runnable c
18435
18436 @end smallexample
18437
18438 @noindent
18439 In this listing, the asterisk before the last task indicates it to be the
18440 task currently being inspected.
18441
18442 @table @asis
18443 @item ID
18444 Represents @value{GDBN}'s internal task number.
18445
18446 @item TID
18447 The Ada task ID.
18448
18449 @item P-ID
18450 The parent's task ID (@value{GDBN}'s internal task number).
18451
18452 @item Pri
18453 The base priority of the task.
18454
18455 @item State
18456 Current state of the task.
18457
18458 @table @code
18459 @item Unactivated
18460 The task has been created but has not been activated. It cannot be
18461 executing.
18462
18463 @item Runnable
18464 The task is not blocked for any reason known to Ada. (It may be waiting
18465 for a mutex, though.) It is conceptually "executing" in normal mode.
18466
18467 @item Terminated
18468 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18469 that were waiting on terminate alternatives have been awakened and have
18470 terminated themselves.
18471
18472 @item Child Activation Wait
18473 The task is waiting for created tasks to complete activation.
18474
18475 @item Accept Statement
18476 The task is waiting on an accept or selective wait statement.
18477
18478 @item Waiting on entry call
18479 The task is waiting on an entry call.
18480
18481 @item Async Select Wait
18482 The task is waiting to start the abortable part of an asynchronous
18483 select statement.
18484
18485 @item Delay Sleep
18486 The task is waiting on a select statement with only a delay
18487 alternative open.
18488
18489 @item Child Termination Wait
18490 The task is sleeping having completed a master within itself, and is
18491 waiting for the tasks dependent on that master to become terminated or
18492 waiting on a terminate Phase.
18493
18494 @item Wait Child in Term Alt
18495 The task is sleeping waiting for tasks on terminate alternatives to
18496 finish terminating.
18497
18498 @item Accepting RV with @var{taskno}
18499 The task is accepting a rendez-vous with the task @var{taskno}.
18500 @end table
18501
18502 @item Name
18503 Name of the task in the program.
18504
18505 @end table
18506
18507 @kindex info task @var{taskno}
18508 @item info task @var{taskno}
18509 This command shows detailed informations on the specified task, as in
18510 the following example:
18511 @smallexample
18512 @iftex
18513 @leftskip=0.5cm
18514 @end iftex
18515 (@value{GDBP}) info tasks
18516 ID TID P-ID Pri State Name
18517 1 8077880 0 15 Child Activation Wait main_task
18518 * 2 807c468 1 15 Runnable task_1
18519 (@value{GDBP}) info task 2
18520 Ada Task: 0x807c468
18521 Name: "task_1"
18522 Thread: 0
18523 LWP: 0x1fac
18524 Parent: 1 ("main_task")
18525 Base Priority: 15
18526 State: Runnable
18527 @end smallexample
18528
18529 @item task
18530 @kindex task@r{ (Ada)}
18531 @cindex current Ada task ID
18532 This command prints the ID and name of the current task.
18533
18534 @smallexample
18535 @iftex
18536 @leftskip=0.5cm
18537 @end iftex
18538 (@value{GDBP}) info tasks
18539 ID TID P-ID Pri State Name
18540 1 8077870 0 15 Child Activation Wait main_task
18541 * 2 807c458 1 15 Runnable some_task
18542 (@value{GDBP}) task
18543 [Current task is 2 "some_task"]
18544 @end smallexample
18545
18546 @item task @var{taskno}
18547 @cindex Ada task switching
18548 This command is like the @code{thread @var{thread-id}}
18549 command (@pxref{Threads}). It switches the context of debugging
18550 from the current task to the given task.
18551
18552 @smallexample
18553 @iftex
18554 @leftskip=0.5cm
18555 @end iftex
18556 (@value{GDBP}) info tasks
18557 ID TID P-ID Pri State Name
18558 1 8077870 0 15 Child Activation Wait main_task
18559 * 2 807c458 1 15 Runnable some_task
18560 (@value{GDBP}) task 1
18561 [Switching to task 1 "main_task"]
18562 #0 0x8067726 in pthread_cond_wait ()
18563 (@value{GDBP}) bt
18564 #0 0x8067726 in pthread_cond_wait ()
18565 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18566 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18567 #3 0x806153e in system.tasking.stages.activate_tasks ()
18568 #4 0x804aacc in un () at un.adb:5
18569 @end smallexample
18570
18571 @item task apply [@var{task-id-list} | all] [@var{flag}]@dots{} @var{command}
18572 The @code{task apply} command is the Ada tasking analogue of
18573 @code{thread apply} (@pxref{Threads}). It allows you to apply the
18574 named @var{command} to one or more tasks. Specify the tasks that you
18575 want affected using a list of task IDs, or specify @code{all} to apply
18576 to all tasks.
18577
18578 The @var{flag} arguments control what output to produce and how to
18579 handle errors raised when applying @var{command} to a task.
18580 @var{flag} must start with a @code{-} directly followed by one letter
18581 in @code{qcs}. If several flags are provided, they must be given
18582 individually, such as @code{-c -q}.
18583
18584 By default, @value{GDBN} displays some task information before the
18585 output produced by @var{command}, and an error raised during the
18586 execution of a @var{command} will abort @code{task apply}. The
18587 following flags can be used to fine-tune this behavior:
18588
18589 @table @code
18590 @item -c
18591 The flag @code{-c}, which stands for @samp{continue}, causes any
18592 errors in @var{command} to be displayed, and the execution of
18593 @code{task apply} then continues.
18594 @item -s
18595 The flag @code{-s}, which stands for @samp{silent}, causes any errors
18596 or empty output produced by a @var{command} to be silently ignored.
18597 That is, the execution continues, but the task information and errors
18598 are not printed.
18599 @item -q
18600 The flag @code{-q} (@samp{quiet}) disables printing the task
18601 information.
18602 @end table
18603
18604 Flags @code{-c} and @code{-s} cannot be used together.
18605
18606 @item break @var{location} task @var{taskno}
18607 @itemx break @var{location} task @var{taskno} if @dots{}
18608 @cindex breakpoints and tasks, in Ada
18609 @cindex task breakpoints, in Ada
18610 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18611 These commands are like the @code{break @dots{} thread @dots{}}
18612 command (@pxref{Thread Stops}). The
18613 @var{location} argument specifies source lines, as described
18614 in @ref{Specify Location}.
18615
18616 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18617 to specify that you only want @value{GDBN} to stop the program when a
18618 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18619 numeric task identifiers assigned by @value{GDBN}, shown in the first
18620 column of the @samp{info tasks} display.
18621
18622 If you do not specify @samp{task @var{taskno}} when you set a
18623 breakpoint, the breakpoint applies to @emph{all} tasks of your
18624 program.
18625
18626 You can use the @code{task} qualifier on conditional breakpoints as
18627 well; in this case, place @samp{task @var{taskno}} before the
18628 breakpoint condition (before the @code{if}).
18629
18630 For example,
18631
18632 @smallexample
18633 @iftex
18634 @leftskip=0.5cm
18635 @end iftex
18636 (@value{GDBP}) info tasks
18637 ID TID P-ID Pri State Name
18638 1 140022020 0 15 Child Activation Wait main_task
18639 2 140045060 1 15 Accept/Select Wait t2
18640 3 140044840 1 15 Runnable t1
18641 * 4 140056040 1 15 Runnable t3
18642 (@value{GDBP}) b 15 task 2
18643 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18644 (@value{GDBP}) cont
18645 Continuing.
18646 task # 1 running
18647 task # 2 running
18648
18649 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18650 15 flush;
18651 (@value{GDBP}) info tasks
18652 ID TID P-ID Pri State Name
18653 1 140022020 0 15 Child Activation Wait main_task
18654 * 2 140045060 1 15 Runnable t2
18655 3 140044840 1 15 Runnable t1
18656 4 140056040 1 15 Delay Sleep t3
18657 @end smallexample
18658 @end table
18659
18660 @node Ada Tasks and Core Files
18661 @subsubsection Tasking Support when Debugging Core Files
18662 @cindex Ada tasking and core file debugging
18663
18664 When inspecting a core file, as opposed to debugging a live program,
18665 tasking support may be limited or even unavailable, depending on
18666 the platform being used.
18667 For instance, on x86-linux, the list of tasks is available, but task
18668 switching is not supported.
18669
18670 On certain platforms, the debugger needs to perform some
18671 memory writes in order to provide Ada tasking support. When inspecting
18672 a core file, this means that the core file must be opened with read-write
18673 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18674 Under these circumstances, you should make a backup copy of the core
18675 file before inspecting it with @value{GDBN}.
18676
18677 @node Ravenscar Profile
18678 @subsubsection Tasking Support when using the Ravenscar Profile
18679 @cindex Ravenscar Profile
18680
18681 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18682 specifically designed for systems with safety-critical real-time
18683 requirements.
18684
18685 @table @code
18686 @kindex set ravenscar task-switching on
18687 @cindex task switching with program using Ravenscar Profile
18688 @item set ravenscar task-switching on
18689 Allows task switching when debugging a program that uses the Ravenscar
18690 Profile. This is the default.
18691
18692 @kindex set ravenscar task-switching off
18693 @item set ravenscar task-switching off
18694 Turn off task switching when debugging a program that uses the Ravenscar
18695 Profile. This is mostly intended to disable the code that adds support
18696 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18697 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18698 To be effective, this command should be run before the program is started.
18699
18700 @kindex show ravenscar task-switching
18701 @item show ravenscar task-switching
18702 Show whether it is possible to switch from task to task in a program
18703 using the Ravenscar Profile.
18704
18705 @end table
18706
18707 @cindex Ravenscar thread
18708 When Ravenscar task-switching is enabled, Ravenscar tasks are
18709 announced by @value{GDBN} as if they were threads:
18710
18711 @smallexample
18712 (gdb) continue
18713 [New Ravenscar Thread 0x2b8f0]
18714 @end smallexample
18715
18716 Both Ravenscar tasks and the underlying CPU threads will show up in
18717 the output of @code{info threads}:
18718
18719 @smallexample
18720 (gdb) info threads
18721 Id Target Id Frame
18722 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18723 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18724 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18725 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18726 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18727 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18728 @end smallexample
18729
18730 One known limitation of the Ravenscar support in @value{GDBN} is that
18731 it isn't currently possible to single-step through the runtime
18732 initialization sequence. If you need to debug this code, you should
18733 use @code{set ravenscar task-switching off}.
18734
18735 @node Ada Settings
18736 @subsubsection Ada Settings
18737 @cindex Ada settings
18738
18739 @table @code
18740 @kindex set varsize-limit
18741 @item set varsize-limit @var{size}
18742 Prevent @value{GDBN} from attempting to evaluate objects whose size
18743 is above the given limit (@var{size}) when those sizes are computed
18744 from run-time quantities. This is typically the case when the object
18745 has a variable size, such as an array whose bounds are not known at
18746 compile time for example. Setting @var{size} to @code{unlimited}
18747 removes the size limitation. By default, the limit is about 65KB.
18748
18749 The purpose of having such a limit is to prevent @value{GDBN} from
18750 trying to grab enormous chunks of virtual memory when asked to evaluate
18751 a quantity whose bounds have been corrupted or have not yet been fully
18752 initialized. The limit applies to the results of some subexpressions
18753 as well as to complete expressions. For example, an expression denoting
18754 a simple integer component, such as @code{x.y.z}, may fail if the size of
18755 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18756 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18757 @code{A} is an array variable with non-constant size, will generally
18758 succeed regardless of the bounds on @code{A}, as long as the component
18759 size is less than @var{size}.
18760
18761 @kindex show varsize-limit
18762 @item show varsize-limit
18763 Show the limit on types whose size is determined by run-time quantities.
18764 @end table
18765
18766 @node Ada Source Character Set
18767 @subsubsection Ada Source Character Set
18768 @cindex Ada, source character set
18769
18770 The GNAT compiler supports a number of character sets for source
18771 files. @xref{Character Set Control, , Character Set Control,
18772 gnat_ugn}. @value{GDBN} includes support for this as well.
18773
18774 @table @code
18775 @item set ada source-charset @var{charset}
18776 @kindex set ada source-charset
18777 Set the source character set for Ada. The character set must be
18778 supported by GNAT. Because this setting affects the decoding of
18779 symbols coming from the debug information in your program, the setting
18780 should be set as early as possible. The default is @code{ISO-8859-1},
18781 because that is also GNAT's default.
18782
18783 @item show ada source-charset
18784 @kindex show ada source-charset
18785 Show the current source character set for Ada.
18786 @end table
18787
18788 @node Ada Glitches
18789 @subsubsection Known Peculiarities of Ada Mode
18790 @cindex Ada, problems
18791
18792 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18793 we know of several problems with and limitations of Ada mode in
18794 @value{GDBN},
18795 some of which will be fixed with planned future releases of the debugger
18796 and the GNU Ada compiler.
18797
18798 @itemize @bullet
18799 @item
18800 Static constants that the compiler chooses not to materialize as objects in
18801 storage are invisible to the debugger.
18802
18803 @item
18804 Named parameter associations in function argument lists are ignored (the
18805 argument lists are treated as positional).
18806
18807 @item
18808 Many useful library packages are currently invisible to the debugger.
18809
18810 @item
18811 Fixed-point arithmetic, conversions, input, and output is carried out using
18812 floating-point arithmetic, and may give results that only approximate those on
18813 the host machine.
18814
18815 @item
18816 The GNAT compiler never generates the prefix @code{Standard} for any of
18817 the standard symbols defined by the Ada language. @value{GDBN} knows about
18818 this: it will strip the prefix from names when you use it, and will never
18819 look for a name you have so qualified among local symbols, nor match against
18820 symbols in other packages or subprograms. If you have
18821 defined entities anywhere in your program other than parameters and
18822 local variables whose simple names match names in @code{Standard},
18823 GNAT's lack of qualification here can cause confusion. When this happens,
18824 you can usually resolve the confusion
18825 by qualifying the problematic names with package
18826 @code{Standard} explicitly.
18827 @end itemize
18828
18829 Older versions of the compiler sometimes generate erroneous debugging
18830 information, resulting in the debugger incorrectly printing the value
18831 of affected entities. In some cases, the debugger is able to work
18832 around an issue automatically. In other cases, the debugger is able
18833 to work around the issue, but the work-around has to be specifically
18834 enabled.
18835
18836 @kindex set ada trust-PAD-over-XVS
18837 @kindex show ada trust-PAD-over-XVS
18838 @table @code
18839
18840 @item set ada trust-PAD-over-XVS on
18841 Configure GDB to strictly follow the GNAT encoding when computing the
18842 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18843 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18844 a complete description of the encoding used by the GNAT compiler).
18845 This is the default.
18846
18847 @item set ada trust-PAD-over-XVS off
18848 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18849 sometimes prints the wrong value for certain entities, changing @code{ada
18850 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18851 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18852 @code{off}, but this incurs a slight performance penalty, so it is
18853 recommended to leave this setting to @code{on} unless necessary.
18854
18855 @end table
18856
18857 @cindex GNAT descriptive types
18858 @cindex GNAT encoding
18859 Internally, the debugger also relies on the compiler following a number
18860 of conventions known as the @samp{GNAT Encoding}, all documented in
18861 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18862 how the debugging information should be generated for certain types.
18863 In particular, this convention makes use of @dfn{descriptive types},
18864 which are artificial types generated purely to help the debugger.
18865
18866 These encodings were defined at a time when the debugging information
18867 format used was not powerful enough to describe some of the more complex
18868 types available in Ada. Since DWARF allows us to express nearly all
18869 Ada features, the long-term goal is to slowly replace these descriptive
18870 types by their pure DWARF equivalent. To facilitate that transition,
18871 a new maintenance option is available to force the debugger to ignore
18872 those descriptive types. It allows the user to quickly evaluate how
18873 well @value{GDBN} works without them.
18874
18875 @table @code
18876
18877 @kindex maint ada set ignore-descriptive-types
18878 @item maintenance ada set ignore-descriptive-types [on|off]
18879 Control whether the debugger should ignore descriptive types.
18880 The default is not to ignore descriptives types (@code{off}).
18881
18882 @kindex maint ada show ignore-descriptive-types
18883 @item maintenance ada show ignore-descriptive-types
18884 Show if descriptive types are ignored by @value{GDBN}.
18885
18886 @end table
18887
18888 @node Unsupported Languages
18889 @section Unsupported Languages
18890
18891 @cindex unsupported languages
18892 @cindex minimal language
18893 In addition to the other fully-supported programming languages,
18894 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18895 It does not represent a real programming language, but provides a set
18896 of capabilities close to what the C or assembly languages provide.
18897 This should allow most simple operations to be performed while debugging
18898 an application that uses a language currently not supported by @value{GDBN}.
18899
18900 If the language is set to @code{auto}, @value{GDBN} will automatically
18901 select this language if the current frame corresponds to an unsupported
18902 language.
18903
18904 @node Symbols
18905 @chapter Examining the Symbol Table
18906
18907 The commands described in this chapter allow you to inquire about the
18908 symbols (names of variables, functions and types) defined in your
18909 program. This information is inherent in the text of your program and
18910 does not change as your program executes. @value{GDBN} finds it in your
18911 program's symbol table, in the file indicated when you started @value{GDBN}
18912 (@pxref{File Options, ,Choosing Files}), or by one of the
18913 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18914
18915 @cindex symbol names
18916 @cindex names of symbols
18917 @cindex quoting names
18918 @anchor{quoting names}
18919 Occasionally, you may need to refer to symbols that contain unusual
18920 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18921 most frequent case is in referring to static variables in other
18922 source files (@pxref{Variables,,Program Variables}). File names
18923 are recorded in object files as debugging symbols, but @value{GDBN} would
18924 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18925 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18926 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18927
18928 @smallexample
18929 p 'foo.c'::x
18930 @end smallexample
18931
18932 @noindent
18933 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18934
18935 @table @code
18936 @cindex case-insensitive symbol names
18937 @cindex case sensitivity in symbol names
18938 @kindex set case-sensitive
18939 @item set case-sensitive on
18940 @itemx set case-sensitive off
18941 @itemx set case-sensitive auto
18942 Normally, when @value{GDBN} looks up symbols, it matches their names
18943 with case sensitivity determined by the current source language.
18944 Occasionally, you may wish to control that. The command @code{set
18945 case-sensitive} lets you do that by specifying @code{on} for
18946 case-sensitive matches or @code{off} for case-insensitive ones. If
18947 you specify @code{auto}, case sensitivity is reset to the default
18948 suitable for the source language. The default is case-sensitive
18949 matches for all languages except for Fortran, for which the default is
18950 case-insensitive matches.
18951
18952 @kindex show case-sensitive
18953 @item show case-sensitive
18954 This command shows the current setting of case sensitivity for symbols
18955 lookups.
18956
18957 @kindex set print type methods
18958 @item set print type methods
18959 @itemx set print type methods on
18960 @itemx set print type methods off
18961 Normally, when @value{GDBN} prints a class, it displays any methods
18962 declared in that class. You can control this behavior either by
18963 passing the appropriate flag to @code{ptype}, or using @command{set
18964 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18965 display the methods; this is the default. Specifying @code{off} will
18966 cause @value{GDBN} to omit the methods.
18967
18968 @kindex show print type methods
18969 @item show print type methods
18970 This command shows the current setting of method display when printing
18971 classes.
18972
18973 @kindex set print type nested-type-limit
18974 @item set print type nested-type-limit @var{limit}
18975 @itemx set print type nested-type-limit unlimited
18976 Set the limit of displayed nested types that the type printer will
18977 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18978 nested definitions. By default, the type printer will not show any nested
18979 types defined in classes.
18980
18981 @kindex show print type nested-type-limit
18982 @item show print type nested-type-limit
18983 This command shows the current display limit of nested types when
18984 printing classes.
18985
18986 @kindex set print type typedefs
18987 @item set print type typedefs
18988 @itemx set print type typedefs on
18989 @itemx set print type typedefs off
18990
18991 Normally, when @value{GDBN} prints a class, it displays any typedefs
18992 defined in that class. You can control this behavior either by
18993 passing the appropriate flag to @code{ptype}, or using @command{set
18994 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18995 display the typedef definitions; this is the default. Specifying
18996 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18997 Note that this controls whether the typedef definition itself is
18998 printed, not whether typedef names are substituted when printing other
18999 types.
19000
19001 @kindex show print type typedefs
19002 @item show print type typedefs
19003 This command shows the current setting of typedef display when
19004 printing classes.
19005
19006 @kindex set print type hex
19007 @item set print type hex
19008 @itemx set print type hex on
19009 @itemx set print type hex off
19010
19011 When @value{GDBN} prints sizes and offsets of struct members, it can use
19012 either the decimal or hexadecimal notation. You can select one or the
19013 other either by passing the appropriate flag to @code{ptype}, or by using
19014 the @command{set print type hex} command.
19015
19016 @kindex show print type hex
19017 @item show print type hex
19018 This command shows whether the sizes and offsets of struct members are
19019 printed in decimal or hexadecimal notation.
19020
19021 @kindex info address
19022 @cindex address of a symbol
19023 @item info address @var{symbol}
19024 Describe where the data for @var{symbol} is stored. For a register
19025 variable, this says which register it is kept in. For a non-register
19026 local variable, this prints the stack-frame offset at which the variable
19027 is always stored.
19028
19029 Note the contrast with @samp{print &@var{symbol}}, which does not work
19030 at all for a register variable, and for a stack local variable prints
19031 the exact address of the current instantiation of the variable.
19032
19033 @kindex info symbol
19034 @cindex symbol from address
19035 @cindex closest symbol and offset for an address
19036 @item info symbol @var{addr}
19037 Print the name of a symbol which is stored at the address @var{addr}.
19038 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
19039 nearest symbol and an offset from it:
19040
19041 @smallexample
19042 (@value{GDBP}) info symbol 0x54320
19043 _initialize_vx + 396 in section .text
19044 @end smallexample
19045
19046 @noindent
19047 This is the opposite of the @code{info address} command. You can use
19048 it to find out the name of a variable or a function given its address.
19049
19050 For dynamically linked executables, the name of executable or shared
19051 library containing the symbol is also printed:
19052
19053 @smallexample
19054 (@value{GDBP}) info symbol 0x400225
19055 _start + 5 in section .text of /tmp/a.out
19056 (@value{GDBP}) info symbol 0x2aaaac2811cf
19057 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
19058 @end smallexample
19059
19060 @kindex demangle
19061 @cindex demangle
19062 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
19063 Demangle @var{name}.
19064 If @var{language} is provided it is the name of the language to demangle
19065 @var{name} in. Otherwise @var{name} is demangled in the current language.
19066
19067 The @samp{--} option specifies the end of options,
19068 and is useful when @var{name} begins with a dash.
19069
19070 The parameter @code{demangle-style} specifies how to interpret the kind
19071 of mangling used. @xref{Print Settings}.
19072
19073 @kindex whatis
19074 @item whatis[/@var{flags}] [@var{arg}]
19075 Print the data type of @var{arg}, which can be either an expression
19076 or a name of a data type. With no argument, print the data type of
19077 @code{$}, the last value in the value history.
19078
19079 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
19080 is not actually evaluated, and any side-effecting operations (such as
19081 assignments or function calls) inside it do not take place.
19082
19083 If @var{arg} is a variable or an expression, @code{whatis} prints its
19084 literal type as it is used in the source code. If the type was
19085 defined using a @code{typedef}, @code{whatis} will @emph{not} print
19086 the data type underlying the @code{typedef}. If the type of the
19087 variable or the expression is a compound data type, such as
19088 @code{struct} or @code{class}, @code{whatis} never prints their
19089 fields or methods. It just prints the @code{struct}/@code{class}
19090 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
19091 such a compound data type, use @code{ptype}.
19092
19093 If @var{arg} is a type name that was defined using @code{typedef},
19094 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
19095 Unrolling means that @code{whatis} will show the underlying type used
19096 in the @code{typedef} declaration of @var{arg}. However, if that
19097 underlying type is also a @code{typedef}, @code{whatis} will not
19098 unroll it.
19099
19100 For C code, the type names may also have the form @samp{class
19101 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
19102 @var{union-tag}} or @samp{enum @var{enum-tag}}.
19103
19104 @var{flags} can be used to modify how the type is displayed.
19105 Available flags are:
19106
19107 @table @code
19108 @item r
19109 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
19110 parameters and typedefs defined in a class when printing the class'
19111 members. The @code{/r} flag disables this.
19112
19113 @item m
19114 Do not print methods defined in the class.
19115
19116 @item M
19117 Print methods defined in the class. This is the default, but the flag
19118 exists in case you change the default with @command{set print type methods}.
19119
19120 @item t
19121 Do not print typedefs defined in the class. Note that this controls
19122 whether the typedef definition itself is printed, not whether typedef
19123 names are substituted when printing other types.
19124
19125 @item T
19126 Print typedefs defined in the class. This is the default, but the flag
19127 exists in case you change the default with @command{set print type typedefs}.
19128
19129 @item o
19130 Print the offsets and sizes of fields in a struct, similar to what the
19131 @command{pahole} tool does. This option implies the @code{/tm} flags.
19132
19133 @item x
19134 Use hexadecimal notation when printing offsets and sizes of fields in a
19135 struct.
19136
19137 @item d
19138 Use decimal notation when printing offsets and sizes of fields in a
19139 struct.
19140
19141 For example, given the following declarations:
19142
19143 @smallexample
19144 struct tuv
19145 @{
19146 int a1;
19147 char *a2;
19148 int a3;
19149 @};
19150
19151 struct xyz
19152 @{
19153 int f1;
19154 char f2;
19155 void *f3;
19156 struct tuv f4;
19157 @};
19158
19159 union qwe
19160 @{
19161 struct tuv fff1;
19162 struct xyz fff2;
19163 @};
19164
19165 struct tyu
19166 @{
19167 int a1 : 1;
19168 int a2 : 3;
19169 int a3 : 23;
19170 char a4 : 2;
19171 int64_t a5;
19172 int a6 : 5;
19173 int64_t a7 : 3;
19174 @};
19175 @end smallexample
19176
19177 Issuing a @kbd{ptype /o struct tuv} command would print:
19178
19179 @smallexample
19180 (@value{GDBP}) ptype /o struct tuv
19181 /* offset | size */ type = struct tuv @{
19182 /* 0 | 4 */ int a1;
19183 /* XXX 4-byte hole */
19184 /* 8 | 8 */ char *a2;
19185 /* 16 | 4 */ int a3;
19186
19187 /* total size (bytes): 24 */
19188 @}
19189 @end smallexample
19190
19191 Notice the format of the first column of comments. There, you can
19192 find two parts separated by the @samp{|} character: the @emph{offset},
19193 which indicates where the field is located inside the struct, in
19194 bytes, and the @emph{size} of the field. Another interesting line is
19195 the marker of a @emph{hole} in the struct, indicating that it may be
19196 possible to pack the struct and make it use less space by reorganizing
19197 its fields.
19198
19199 It is also possible to print offsets inside an union:
19200
19201 @smallexample
19202 (@value{GDBP}) ptype /o union qwe
19203 /* offset | size */ type = union qwe @{
19204 /* 24 */ struct tuv @{
19205 /* 0 | 4 */ int a1;
19206 /* XXX 4-byte hole */
19207 /* 8 | 8 */ char *a2;
19208 /* 16 | 4 */ int a3;
19209
19210 /* total size (bytes): 24 */
19211 @} fff1;
19212 /* 40 */ struct xyz @{
19213 /* 0 | 4 */ int f1;
19214 /* 4 | 1 */ char f2;
19215 /* XXX 3-byte hole */
19216 /* 8 | 8 */ void *f3;
19217 /* 16 | 24 */ struct tuv @{
19218 /* 16 | 4 */ int a1;
19219 /* XXX 4-byte hole */
19220 /* 24 | 8 */ char *a2;
19221 /* 32 | 4 */ int a3;
19222
19223 /* total size (bytes): 24 */
19224 @} f4;
19225
19226 /* total size (bytes): 40 */
19227 @} fff2;
19228
19229 /* total size (bytes): 40 */
19230 @}
19231 @end smallexample
19232
19233 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
19234 same space (because we are dealing with an union), the offset is not
19235 printed for them. However, you can still examine the offset of each
19236 of these structures' fields.
19237
19238 Another useful scenario is printing the offsets of a struct containing
19239 bitfields:
19240
19241 @smallexample
19242 (@value{GDBP}) ptype /o struct tyu
19243 /* offset | size */ type = struct tyu @{
19244 /* 0:31 | 4 */ int a1 : 1;
19245 /* 0:28 | 4 */ int a2 : 3;
19246 /* 0: 5 | 4 */ int a3 : 23;
19247 /* 3: 3 | 1 */ signed char a4 : 2;
19248 /* XXX 3-bit hole */
19249 /* XXX 4-byte hole */
19250 /* 8 | 8 */ int64_t a5;
19251 /* 16: 0 | 4 */ int a6 : 5;
19252 /* 16: 5 | 8 */ int64_t a7 : 3;
19253 /* XXX 7-byte padding */
19254
19255 /* total size (bytes): 24 */
19256 @}
19257 @end smallexample
19258
19259 Note how the offset information is now extended to also include the
19260 first bit of the bitfield.
19261 @end table
19262
19263 @kindex ptype
19264 @item ptype[/@var{flags}] [@var{arg}]
19265 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
19266 detailed description of the type, instead of just the name of the type.
19267 @xref{Expressions, ,Expressions}.
19268
19269 Contrary to @code{whatis}, @code{ptype} always unrolls any
19270 @code{typedef}s in its argument declaration, whether the argument is
19271 a variable, expression, or a data type. This means that @code{ptype}
19272 of a variable or an expression will not print literally its type as
19273 present in the source code---use @code{whatis} for that. @code{typedef}s at
19274 the pointer or reference targets are also unrolled. Only @code{typedef}s of
19275 fields, methods and inner @code{class typedef}s of @code{struct}s,
19276 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
19277
19278 For example, for this variable declaration:
19279
19280 @smallexample
19281 typedef double real_t;
19282 struct complex @{ real_t real; double imag; @};
19283 typedef struct complex complex_t;
19284 complex_t var;
19285 real_t *real_pointer_var;
19286 @end smallexample
19287
19288 @noindent
19289 the two commands give this output:
19290
19291 @smallexample
19292 @group
19293 (@value{GDBP}) whatis var
19294 type = complex_t
19295 (@value{GDBP}) ptype var
19296 type = struct complex @{
19297 real_t real;
19298 double imag;
19299 @}
19300 (@value{GDBP}) whatis complex_t
19301 type = struct complex
19302 (@value{GDBP}) whatis struct complex
19303 type = struct complex
19304 (@value{GDBP}) ptype struct complex
19305 type = struct complex @{
19306 real_t real;
19307 double imag;
19308 @}
19309 (@value{GDBP}) whatis real_pointer_var
19310 type = real_t *
19311 (@value{GDBP}) ptype real_pointer_var
19312 type = double *
19313 @end group
19314 @end smallexample
19315
19316 @noindent
19317 As with @code{whatis}, using @code{ptype} without an argument refers to
19318 the type of @code{$}, the last value in the value history.
19319
19320 @cindex incomplete type
19321 Sometimes, programs use opaque data types or incomplete specifications
19322 of complex data structure. If the debug information included in the
19323 program does not allow @value{GDBN} to display a full declaration of
19324 the data type, it will say @samp{<incomplete type>}. For example,
19325 given these declarations:
19326
19327 @smallexample
19328 struct foo;
19329 struct foo *fooptr;
19330 @end smallexample
19331
19332 @noindent
19333 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19334
19335 @smallexample
19336 (@value{GDBP}) ptype foo
19337 $1 = <incomplete type>
19338 @end smallexample
19339
19340 @noindent
19341 ``Incomplete type'' is C terminology for data types that are not
19342 completely specified.
19343
19344 @cindex unknown type
19345 Othertimes, information about a variable's type is completely absent
19346 from the debug information included in the program. This most often
19347 happens when the program or library where the variable is defined
19348 includes no debug information at all. @value{GDBN} knows the variable
19349 exists from inspecting the linker/loader symbol table (e.g., the ELF
19350 dynamic symbol table), but such symbols do not contain type
19351 information. Inspecting the type of a (global) variable for which
19352 @value{GDBN} has no type information shows:
19353
19354 @smallexample
19355 (@value{GDBP}) ptype var
19356 type = <data variable, no debug info>
19357 @end smallexample
19358
19359 @xref{Variables, no debug info variables}, for how to print the values
19360 of such variables.
19361
19362 @kindex info types
19363 @item info types [-q] [@var{regexp}]
19364 Print a brief description of all types whose names match the regular
19365 expression @var{regexp} (or all types in your program, if you supply
19366 no argument). Each complete typename is matched as though it were a
19367 complete line; thus, @samp{i type value} gives information on all
19368 types in your program whose names include the string @code{value}, but
19369 @samp{i type ^value$} gives information only on types whose complete
19370 name is @code{value}.
19371
19372 In programs using different languages, @value{GDBN} chooses the syntax
19373 to print the type description according to the
19374 @samp{set language} value: using @samp{set language auto}
19375 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19376 language of the type, other values mean to use
19377 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19378
19379 This command differs from @code{ptype} in two ways: first, like
19380 @code{whatis}, it does not print a detailed description; second, it
19381 lists all source files and line numbers where a type is defined.
19382
19383 The output from @samp{into types} is proceeded with a header line
19384 describing what types are being listed. The optional flag @samp{-q},
19385 which stands for @samp{quiet}, disables printing this header
19386 information.
19387
19388 @kindex info type-printers
19389 @item info type-printers
19390 Versions of @value{GDBN} that ship with Python scripting enabled may
19391 have ``type printers'' available. When using @command{ptype} or
19392 @command{whatis}, these printers are consulted when the name of a type
19393 is needed. @xref{Type Printing API}, for more information on writing
19394 type printers.
19395
19396 @code{info type-printers} displays all the available type printers.
19397
19398 @kindex enable type-printer
19399 @kindex disable type-printer
19400 @item enable type-printer @var{name}@dots{}
19401 @item disable type-printer @var{name}@dots{}
19402 These commands can be used to enable or disable type printers.
19403
19404 @kindex info scope
19405 @cindex local variables
19406 @item info scope @var{location}
19407 List all the variables local to a particular scope. This command
19408 accepts a @var{location} argument---a function name, a source line, or
19409 an address preceded by a @samp{*}, and prints all the variables local
19410 to the scope defined by that location. (@xref{Specify Location}, for
19411 details about supported forms of @var{location}.) For example:
19412
19413 @smallexample
19414 (@value{GDBP}) @b{info scope command_line_handler}
19415 Scope for command_line_handler:
19416 Symbol rl is an argument at stack/frame offset 8, length 4.
19417 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19418 Symbol linelength is in static storage at address 0x150a1c, length 4.
19419 Symbol p is a local variable in register $esi, length 4.
19420 Symbol p1 is a local variable in register $ebx, length 4.
19421 Symbol nline is a local variable in register $edx, length 4.
19422 Symbol repeat is a local variable at frame offset -8, length 4.
19423 @end smallexample
19424
19425 @noindent
19426 This command is especially useful for determining what data to collect
19427 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19428 collect}.
19429
19430 @kindex info source
19431 @item info source
19432 Show information about the current source file---that is, the source file for
19433 the function containing the current point of execution:
19434 @itemize @bullet
19435 @item
19436 the name of the source file, and the directory containing it,
19437 @item
19438 the directory it was compiled in,
19439 @item
19440 its length, in lines,
19441 @item
19442 which programming language it is written in,
19443 @item
19444 if the debug information provides it, the program that compiled the file
19445 (which may include, e.g., the compiler version and command line arguments),
19446 @item
19447 whether the executable includes debugging information for that file, and
19448 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19449 @item
19450 whether the debugging information includes information about
19451 preprocessor macros.
19452 @end itemize
19453
19454
19455 @kindex info sources
19456 @item info sources @r{[}-dirname | -basename@r{]} @r{[}--@r{]} @r{[}@var{regexp}@r{]}
19457
19458
19459 With no options @samp{info sources} prints the names of all source
19460 files in your program for which there is debugging information. The
19461 source files are presented based on a list of object files
19462 (executables and libraries) currently loaded into @value{GDBN}. For
19463 each object file all of the associated source files are listed.
19464
19465 Each source file will only be printed once for each object file, but a
19466 single source file can be repeated in the output if it is part of
19467 multiple object files.
19468
19469 If the optional @var{regexp} is provided, then only source files that
19470 match the regular expression will be printed. The matching is
19471 case-sensitive, except on operating systems that have case-insensitive
19472 filesystem (e.g., MS-Windows). @samp{--} can be used before
19473 @var{regexp} to prevent @value{GDBN} interpreting @var{regexp} as a
19474 command option (e.g. if @var{regexp} starts with @samp{-}).
19475
19476 By default, the @var{regexp} is used to match anywhere in the
19477 filename. If @code{-dirname}, only files having a dirname matching
19478 @var{regexp} are shown. If @code{-basename}, only files having a
19479 basename matching @var{regexp} are shown.
19480
19481 It is possible that an object file may be printed in the list with no
19482 associated source files. This can happen when either no source files
19483 match @var{regexp}, or, the object file was compiled without debug
19484 information and so @value{GDBN} is unable to find any source file
19485 names.
19486
19487 @kindex info functions
19488 @item info functions [-q] [-n]
19489 Print the names and data types of all defined functions.
19490 Similarly to @samp{info types}, this command groups its output by source
19491 files and annotates each function definition with its source line
19492 number.
19493
19494 In programs using different languages, @value{GDBN} chooses the syntax
19495 to print the function name and type according to the
19496 @samp{set language} value: using @samp{set language auto}
19497 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19498 language of the function, other values mean to use
19499 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19500
19501 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19502 results. A non-debugging symbol is a symbol that comes from the
19503 executable's symbol table, not from the debug information (for
19504 example, DWARF) associated with the executable.
19505
19506 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19507 printing header information and messages explaining why no functions
19508 have been printed.
19509
19510 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19511 Like @samp{info functions}, but only print the names and data types
19512 of the functions selected with the provided regexp(s).
19513
19514 If @var{regexp} is provided, print only the functions whose names
19515 match the regular expression @var{regexp}.
19516 Thus, @samp{info fun step} finds all functions whose
19517 names include @code{step}; @samp{info fun ^step} finds those whose names
19518 start with @code{step}. If a function name contains characters that
19519 conflict with the regular expression language (e.g.@:
19520 @samp{operator*()}), they may be quoted with a backslash.
19521
19522 If @var{type_regexp} is provided, print only the functions whose
19523 types, as printed by the @code{whatis} command, match
19524 the regular expression @var{type_regexp}.
19525 If @var{type_regexp} contains space(s), it should be enclosed in
19526 quote characters. If needed, use backslash to escape the meaning
19527 of special characters or quotes.
19528 Thus, @samp{info fun -t '^int ('} finds the functions that return
19529 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19530 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19531 finds the functions whose names start with @code{step} and that return
19532 int.
19533
19534 If both @var{regexp} and @var{type_regexp} are provided, a function
19535 is printed only if its name matches @var{regexp} and its type matches
19536 @var{type_regexp}.
19537
19538
19539 @kindex info variables
19540 @item info variables [-q] [-n]
19541 Print the names and data types of all variables that are defined
19542 outside of functions (i.e.@: excluding local variables).
19543 The printed variables are grouped by source files and annotated with
19544 their respective source line numbers.
19545
19546 In programs using different languages, @value{GDBN} chooses the syntax
19547 to print the variable name and type according to the
19548 @samp{set language} value: using @samp{set language auto}
19549 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19550 language of the variable, other values mean to use
19551 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19552
19553 The @samp{-n} flag excludes non-debugging symbols from the results.
19554
19555 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19556 printing header information and messages explaining why no variables
19557 have been printed.
19558
19559 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19560 Like @kbd{info variables}, but only print the variables selected
19561 with the provided regexp(s).
19562
19563 If @var{regexp} is provided, print only the variables whose names
19564 match the regular expression @var{regexp}.
19565
19566 If @var{type_regexp} is provided, print only the variables whose
19567 types, as printed by the @code{whatis} command, match
19568 the regular expression @var{type_regexp}.
19569 If @var{type_regexp} contains space(s), it should be enclosed in
19570 quote characters. If needed, use backslash to escape the meaning
19571 of special characters or quotes.
19572
19573 If both @var{regexp} and @var{type_regexp} are provided, an argument
19574 is printed only if its name matches @var{regexp} and its type matches
19575 @var{type_regexp}.
19576
19577 @kindex info modules
19578 @cindex modules
19579 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19580 List all Fortran modules in the program, or all modules matching the
19581 optional regular expression @var{regexp}.
19582
19583 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19584 printing header information and messages explaining why no modules
19585 have been printed.
19586
19587 @kindex info module
19588 @cindex Fortran modules, information about
19589 @cindex functions and variables by Fortran module
19590 @cindex module functions and variables
19591 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19592 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19593 List all functions or variables within all Fortran modules. The set
19594 of functions or variables listed can be limited by providing some or
19595 all of the optional regular expressions. If @var{module-regexp} is
19596 provided, then only Fortran modules matching @var{module-regexp} will
19597 be searched. Only functions or variables whose type matches the
19598 optional regular expression @var{type-regexp} will be listed. And
19599 only functions or variables whose name matches the optional regular
19600 expression @var{regexp} will be listed.
19601
19602 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19603 printing header information and messages explaining why no functions
19604 or variables have been printed.
19605
19606 @kindex info classes
19607 @cindex Objective-C, classes and selectors
19608 @item info classes
19609 @itemx info classes @var{regexp}
19610 Display all Objective-C classes in your program, or
19611 (with the @var{regexp} argument) all those matching a particular regular
19612 expression.
19613
19614 @kindex info selectors
19615 @item info selectors
19616 @itemx info selectors @var{regexp}
19617 Display all Objective-C selectors in your program, or
19618 (with the @var{regexp} argument) all those matching a particular regular
19619 expression.
19620
19621 @ignore
19622 This was never implemented.
19623 @kindex info methods
19624 @item info methods
19625 @itemx info methods @var{regexp}
19626 The @code{info methods} command permits the user to examine all defined
19627 methods within C@t{++} program, or (with the @var{regexp} argument) a
19628 specific set of methods found in the various C@t{++} classes. Many
19629 C@t{++} classes provide a large number of methods. Thus, the output
19630 from the @code{ptype} command can be overwhelming and hard to use. The
19631 @code{info-methods} command filters the methods, printing only those
19632 which match the regular-expression @var{regexp}.
19633 @end ignore
19634
19635 @cindex opaque data types
19636 @kindex set opaque-type-resolution
19637 @item set opaque-type-resolution on
19638 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19639 declared as a pointer to a @code{struct}, @code{class}, or
19640 @code{union}---for example, @code{struct MyType *}---that is used in one
19641 source file although the full declaration of @code{struct MyType} is in
19642 another source file. The default is on.
19643
19644 A change in the setting of this subcommand will not take effect until
19645 the next time symbols for a file are loaded.
19646
19647 @item set opaque-type-resolution off
19648 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19649 is printed as follows:
19650 @smallexample
19651 @{<no data fields>@}
19652 @end smallexample
19653
19654 @kindex show opaque-type-resolution
19655 @item show opaque-type-resolution
19656 Show whether opaque types are resolved or not.
19657
19658 @kindex set print symbol-loading
19659 @cindex print messages when symbols are loaded
19660 @item set print symbol-loading
19661 @itemx set print symbol-loading full
19662 @itemx set print symbol-loading brief
19663 @itemx set print symbol-loading off
19664 The @code{set print symbol-loading} command allows you to control the
19665 printing of messages when @value{GDBN} loads symbol information.
19666 By default a message is printed for the executable and one for each
19667 shared library, and normally this is what you want. However, when
19668 debugging apps with large numbers of shared libraries these messages
19669 can be annoying.
19670 When set to @code{brief} a message is printed for each executable,
19671 and when @value{GDBN} loads a collection of shared libraries at once
19672 it will only print one message regardless of the number of shared
19673 libraries. When set to @code{off} no messages are printed.
19674
19675 @kindex show print symbol-loading
19676 @item show print symbol-loading
19677 Show whether messages will be printed when a @value{GDBN} command
19678 entered from the keyboard causes symbol information to be loaded.
19679
19680 @kindex maint print symbols
19681 @cindex symbol dump
19682 @kindex maint print psymbols
19683 @cindex partial symbol dump
19684 @kindex maint print msymbols
19685 @cindex minimal symbol dump
19686 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19687 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19688 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19689 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19690 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19691 Write a dump of debugging symbol data into the file @var{filename} or
19692 the terminal if @var{filename} is unspecified.
19693 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19694 that objfile.
19695 If @code{-pc @var{address}} is specified, only dump symbols for the file
19696 with code at that address. Note that @var{address} may be a symbol like
19697 @code{main}.
19698 If @code{-source @var{source}} is specified, only dump symbols for that
19699 source file.
19700
19701 These commands are used to debug the @value{GDBN} symbol-reading code.
19702 These commands do not modify internal @value{GDBN} state, therefore
19703 @samp{maint print symbols} will only print symbols for already expanded symbol
19704 tables.
19705 You can use the command @code{info sources} to find out which files these are.
19706 If you use @samp{maint print psymbols} instead, the dump shows information
19707 about symbols that @value{GDBN} only knows partially---that is, symbols
19708 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19709 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19710 ``ELF symbols''.
19711
19712 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19713 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19714
19715 @kindex maint info symtabs
19716 @kindex maint info psymtabs
19717 @cindex listing @value{GDBN}'s internal symbol tables
19718 @cindex symbol tables, listing @value{GDBN}'s internal
19719 @cindex full symbol tables, listing @value{GDBN}'s internal
19720 @cindex partial symbol tables, listing @value{GDBN}'s internal
19721 @item maint info symtabs @r{[} @var{regexp} @r{]}
19722 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19723
19724 List the @code{struct symtab} or @code{struct partial_symtab}
19725 structures whose names match @var{regexp}. If @var{regexp} is not
19726 given, list them all. The output includes expressions which you can
19727 copy into a @value{GDBN} debugging this one to examine a particular
19728 structure in more detail. For example:
19729
19730 @smallexample
19731 (@value{GDBP}) maint info psymtabs dwarf2read
19732 @{ objfile /home/gnu/build/gdb/gdb
19733 ((struct objfile *) 0x82e69d0)
19734 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19735 ((struct partial_symtab *) 0x8474b10)
19736 readin no
19737 fullname (null)
19738 text addresses 0x814d3c8 -- 0x8158074
19739 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19740 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19741 dependencies (none)
19742 @}
19743 @}
19744 (@value{GDBP}) maint info symtabs
19745 (@value{GDBP})
19746 @end smallexample
19747 @noindent
19748 We see that there is one partial symbol table whose filename contains
19749 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19750 and we see that @value{GDBN} has not read in any symtabs yet at all.
19751 If we set a breakpoint on a function, that will cause @value{GDBN} to
19752 read the symtab for the compilation unit containing that function:
19753
19754 @smallexample
19755 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19756 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19757 line 1574.
19758 (@value{GDBP}) maint info symtabs
19759 @{ objfile /home/gnu/build/gdb/gdb
19760 ((struct objfile *) 0x82e69d0)
19761 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19762 ((struct symtab *) 0x86c1f38)
19763 dirname (null)
19764 fullname (null)
19765 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19766 linetable ((struct linetable *) 0x8370fa0)
19767 debugformat DWARF 2
19768 @}
19769 @}
19770 (@value{GDBP})
19771 @end smallexample
19772
19773 @kindex maint info line-table
19774 @cindex listing @value{GDBN}'s internal line tables
19775 @cindex line tables, listing @value{GDBN}'s internal
19776 @item maint info line-table @r{[} @var{regexp} @r{]}
19777
19778 List the @code{struct linetable} from all @code{struct symtab}
19779 instances whose name matches @var{regexp}. If @var{regexp} is not
19780 given, list the @code{struct linetable} from all @code{struct symtab}.
19781
19782 @kindex maint set symbol-cache-size
19783 @cindex symbol cache size
19784 @item maint set symbol-cache-size @var{size}
19785 Set the size of the symbol cache to @var{size}.
19786 The default size is intended to be good enough for debugging
19787 most applications. This option exists to allow for experimenting
19788 with different sizes.
19789
19790 @kindex maint show symbol-cache-size
19791 @item maint show symbol-cache-size
19792 Show the size of the symbol cache.
19793
19794 @kindex maint print symbol-cache
19795 @cindex symbol cache, printing its contents
19796 @item maint print symbol-cache
19797 Print the contents of the symbol cache.
19798 This is useful when debugging symbol cache issues.
19799
19800 @kindex maint print symbol-cache-statistics
19801 @cindex symbol cache, printing usage statistics
19802 @item maint print symbol-cache-statistics
19803 Print symbol cache usage statistics.
19804 This helps determine how well the cache is being utilized.
19805
19806 @kindex maint flush symbol-cache
19807 @kindex maint flush-symbol-cache
19808 @cindex symbol cache, flushing
19809 @item maint flush symbol-cache
19810 @itemx maint flush-symbol-cache
19811 Flush the contents of the symbol cache, all entries are removed. This
19812 command is useful when debugging the symbol cache. It is also useful
19813 when collecting performance data. The command @code{maint
19814 flush-symbol-cache} is deprecated in favor of @code{maint flush
19815 symbol-cache}..
19816
19817 @end table
19818
19819 @node Altering
19820 @chapter Altering Execution
19821
19822 Once you think you have found an error in your program, you might want to
19823 find out for certain whether correcting the apparent error would lead to
19824 correct results in the rest of the run. You can find the answer by
19825 experiment, using the @value{GDBN} features for altering execution of the
19826 program.
19827
19828 For example, you can store new values into variables or memory
19829 locations, give your program a signal, restart it at a different
19830 address, or even return prematurely from a function.
19831
19832 @menu
19833 * Assignment:: Assignment to variables
19834 * Jumping:: Continuing at a different address
19835 * Signaling:: Giving your program a signal
19836 * Returning:: Returning from a function
19837 * Calling:: Calling your program's functions
19838 * Patching:: Patching your program
19839 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19840 @end menu
19841
19842 @node Assignment
19843 @section Assignment to Variables
19844
19845 @cindex assignment
19846 @cindex setting variables
19847 To alter the value of a variable, evaluate an assignment expression.
19848 @xref{Expressions, ,Expressions}. For example,
19849
19850 @smallexample
19851 print x=4
19852 @end smallexample
19853
19854 @noindent
19855 stores the value 4 into the variable @code{x}, and then prints the
19856 value of the assignment expression (which is 4).
19857 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19858 information on operators in supported languages.
19859
19860 @kindex set variable
19861 @cindex variables, setting
19862 If you are not interested in seeing the value of the assignment, use the
19863 @code{set} command instead of the @code{print} command. @code{set} is
19864 really the same as @code{print} except that the expression's value is
19865 not printed and is not put in the value history (@pxref{Value History,
19866 ,Value History}). The expression is evaluated only for its effects.
19867
19868 If the beginning of the argument string of the @code{set} command
19869 appears identical to a @code{set} subcommand, use the @code{set
19870 variable} command instead of just @code{set}. This command is identical
19871 to @code{set} except for its lack of subcommands. For example, if your
19872 program has a variable @code{width}, you get an error if you try to set
19873 a new value with just @samp{set width=13}, because @value{GDBN} has the
19874 command @code{set width}:
19875
19876 @smallexample
19877 (@value{GDBP}) whatis width
19878 type = double
19879 (@value{GDBP}) p width
19880 $4 = 13
19881 (@value{GDBP}) set width=47
19882 Invalid syntax in expression.
19883 @end smallexample
19884
19885 @noindent
19886 The invalid expression, of course, is @samp{=47}. In
19887 order to actually set the program's variable @code{width}, use
19888
19889 @smallexample
19890 (@value{GDBP}) set var width=47
19891 @end smallexample
19892
19893 Because the @code{set} command has many subcommands that can conflict
19894 with the names of program variables, it is a good idea to use the
19895 @code{set variable} command instead of just @code{set}. For example, if
19896 your program has a variable @code{g}, you run into problems if you try
19897 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19898 the command @code{set gnutarget}, abbreviated @code{set g}:
19899
19900 @smallexample
19901 @group
19902 (@value{GDBP}) whatis g
19903 type = double
19904 (@value{GDBP}) p g
19905 $1 = 1
19906 (@value{GDBP}) set g=4
19907 (@value{GDBP}) p g
19908 $2 = 1
19909 (@value{GDBP}) r
19910 The program being debugged has been started already.
19911 Start it from the beginning? (y or n) y
19912 Starting program: /home/smith/cc_progs/a.out
19913 "/home/smith/cc_progs/a.out": can't open to read symbols:
19914 Invalid bfd target.
19915 (@value{GDBP}) show g
19916 The current BFD target is "=4".
19917 @end group
19918 @end smallexample
19919
19920 @noindent
19921 The program variable @code{g} did not change, and you silently set the
19922 @code{gnutarget} to an invalid value. In order to set the variable
19923 @code{g}, use
19924
19925 @smallexample
19926 (@value{GDBP}) set var g=4
19927 @end smallexample
19928
19929 @value{GDBN} allows more implicit conversions in assignments than C; you can
19930 freely store an integer value into a pointer variable or vice versa,
19931 and you can convert any structure to any other structure that is the
19932 same length or shorter.
19933 @comment FIXME: how do structs align/pad in these conversions?
19934 @comment /doc@cygnus.com 18dec1990
19935
19936 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19937 construct to generate a value of specified type at a specified address
19938 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19939 to memory location @code{0x83040} as an integer (which implies a certain size
19940 and representation in memory), and
19941
19942 @smallexample
19943 set @{int@}0x83040 = 4
19944 @end smallexample
19945
19946 @noindent
19947 stores the value 4 into that memory location.
19948
19949 @node Jumping
19950 @section Continuing at a Different Address
19951
19952 Ordinarily, when you continue your program, you do so at the place where
19953 it stopped, with the @code{continue} command. You can instead continue at
19954 an address of your own choosing, with the following commands:
19955
19956 @table @code
19957 @kindex jump
19958 @kindex j @r{(@code{jump})}
19959 @item jump @var{location}
19960 @itemx j @var{location}
19961 Resume execution at @var{location}. Execution stops again immediately
19962 if there is a breakpoint there. @xref{Specify Location}, for a description
19963 of the different forms of @var{location}. It is common
19964 practice to use the @code{tbreak} command in conjunction with
19965 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19966
19967 The @code{jump} command does not change the current stack frame, or
19968 the stack pointer, or the contents of any memory location or any
19969 register other than the program counter. If @var{location} is in
19970 a different function from the one currently executing, the results may
19971 be bizarre if the two functions expect different patterns of arguments or
19972 of local variables. For this reason, the @code{jump} command requests
19973 confirmation if the specified line is not in the function currently
19974 executing. However, even bizarre results are predictable if you are
19975 well acquainted with the machine-language code of your program.
19976 @end table
19977
19978 On many systems, you can get much the same effect as the @code{jump}
19979 command by storing a new value into the register @code{$pc}. The
19980 difference is that this does not start your program running; it only
19981 changes the address of where it @emph{will} run when you continue. For
19982 example,
19983
19984 @smallexample
19985 set $pc = 0x485
19986 @end smallexample
19987
19988 @noindent
19989 makes the next @code{continue} command or stepping command execute at
19990 address @code{0x485}, rather than at the address where your program stopped.
19991 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19992
19993 The most common occasion to use the @code{jump} command is to back
19994 up---perhaps with more breakpoints set---over a portion of a program
19995 that has already executed, in order to examine its execution in more
19996 detail.
19997
19998 @c @group
19999 @node Signaling
20000 @section Giving your Program a Signal
20001 @cindex deliver a signal to a program
20002
20003 @table @code
20004 @kindex signal
20005 @item signal @var{signal}
20006 Resume execution where your program is stopped, but immediately give it the
20007 signal @var{signal}. The @var{signal} can be the name or the number of a
20008 signal. For example, on many systems @code{signal 2} and @code{signal
20009 SIGINT} are both ways of sending an interrupt signal.
20010
20011 Alternatively, if @var{signal} is zero, continue execution without
20012 giving a signal. This is useful when your program stopped on account of
20013 a signal and would ordinarily see the signal when resumed with the
20014 @code{continue} command; @samp{signal 0} causes it to resume without a
20015 signal.
20016
20017 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
20018 delivered to the currently selected thread, not the thread that last
20019 reported a stop. This includes the situation where a thread was
20020 stopped due to a signal. So if you want to continue execution
20021 suppressing the signal that stopped a thread, you should select that
20022 same thread before issuing the @samp{signal 0} command. If you issue
20023 the @samp{signal 0} command with another thread as the selected one,
20024 @value{GDBN} detects that and asks for confirmation.
20025
20026 Invoking the @code{signal} command is not the same as invoking the
20027 @code{kill} utility from the shell. Sending a signal with @code{kill}
20028 causes @value{GDBN} to decide what to do with the signal depending on
20029 the signal handling tables (@pxref{Signals}). The @code{signal} command
20030 passes the signal directly to your program.
20031
20032 @code{signal} does not repeat when you press @key{RET} a second time
20033 after executing the command.
20034
20035 @kindex queue-signal
20036 @item queue-signal @var{signal}
20037 Queue @var{signal} to be delivered immediately to the current thread
20038 when execution of the thread resumes. The @var{signal} can be the name or
20039 the number of a signal. For example, on many systems @code{signal 2} and
20040 @code{signal SIGINT} are both ways of sending an interrupt signal.
20041 The handling of the signal must be set to pass the signal to the program,
20042 otherwise @value{GDBN} will report an error.
20043 You can control the handling of signals from @value{GDBN} with the
20044 @code{handle} command (@pxref{Signals}).
20045
20046 Alternatively, if @var{signal} is zero, any currently queued signal
20047 for the current thread is discarded and when execution resumes no signal
20048 will be delivered. This is useful when your program stopped on account
20049 of a signal and would ordinarily see the signal when resumed with the
20050 @code{continue} command.
20051
20052 This command differs from the @code{signal} command in that the signal
20053 is just queued, execution is not resumed. And @code{queue-signal} cannot
20054 be used to pass a signal whose handling state has been set to @code{nopass}
20055 (@pxref{Signals}).
20056 @end table
20057 @c @end group
20058
20059 @xref{stepping into signal handlers}, for information on how stepping
20060 commands behave when the thread has a signal queued.
20061
20062 @node Returning
20063 @section Returning from a Function
20064
20065 @table @code
20066 @cindex returning from a function
20067 @kindex return
20068 @item return
20069 @itemx return @var{expression}
20070 You can cancel execution of a function call with the @code{return}
20071 command. If you give an
20072 @var{expression} argument, its value is used as the function's return
20073 value.
20074 @end table
20075
20076 When you use @code{return}, @value{GDBN} discards the selected stack frame
20077 (and all frames within it). You can think of this as making the
20078 discarded frame return prematurely. If you wish to specify a value to
20079 be returned, give that value as the argument to @code{return}.
20080
20081 This pops the selected stack frame (@pxref{Selection, ,Selecting a
20082 Frame}), and any other frames inside of it, leaving its caller as the
20083 innermost remaining frame. That frame becomes selected. The
20084 specified value is stored in the registers used for returning values
20085 of functions.
20086
20087 The @code{return} command does not resume execution; it leaves the
20088 program stopped in the state that would exist if the function had just
20089 returned. In contrast, the @code{finish} command (@pxref{Continuing
20090 and Stepping, ,Continuing and Stepping}) resumes execution until the
20091 selected stack frame returns naturally.
20092
20093 @value{GDBN} needs to know how the @var{expression} argument should be set for
20094 the inferior. The concrete registers assignment depends on the OS ABI and the
20095 type being returned by the selected stack frame. For example it is common for
20096 OS ABI to return floating point values in FPU registers while integer values in
20097 CPU registers. Still some ABIs return even floating point values in CPU
20098 registers. Larger integer widths (such as @code{long long int}) also have
20099 specific placement rules. @value{GDBN} already knows the OS ABI from its
20100 current target so it needs to find out also the type being returned to make the
20101 assignment into the right register(s).
20102
20103 Normally, the selected stack frame has debug info. @value{GDBN} will always
20104 use the debug info instead of the implicit type of @var{expression} when the
20105 debug info is available. For example, if you type @kbd{return -1}, and the
20106 function in the current stack frame is declared to return a @code{long long
20107 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
20108 into a @code{long long int}:
20109
20110 @smallexample
20111 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
20112 29 return 31;
20113 (@value{GDBP}) return -1
20114 Make func return now? (y or n) y
20115 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
20116 43 printf ("result=%lld\n", func ());
20117 (@value{GDBP})
20118 @end smallexample
20119
20120 However, if the selected stack frame does not have a debug info, e.g., if the
20121 function was compiled without debug info, @value{GDBN} has to find out the type
20122 to return from user. Specifying a different type by mistake may set the value
20123 in different inferior registers than the caller code expects. For example,
20124 typing @kbd{return -1} with its implicit type @code{int} would set only a part
20125 of a @code{long long int} result for a debug info less function (on 32-bit
20126 architectures). Therefore the user is required to specify the return type by
20127 an appropriate cast explicitly:
20128
20129 @smallexample
20130 Breakpoint 2, 0x0040050b in func ()
20131 (@value{GDBP}) return -1
20132 Return value type not available for selected stack frame.
20133 Please use an explicit cast of the value to return.
20134 (@value{GDBP}) return (long long int) -1
20135 Make selected stack frame return now? (y or n) y
20136 #0 0x00400526 in main ()
20137 (@value{GDBP})
20138 @end smallexample
20139
20140 @node Calling
20141 @section Calling Program Functions
20142
20143 @table @code
20144 @cindex calling functions
20145 @cindex inferior functions, calling
20146 @item print @var{expr}
20147 Evaluate the expression @var{expr} and display the resulting value.
20148 The expression may include calls to functions in the program being
20149 debugged.
20150
20151 @kindex call
20152 @item call @var{expr}
20153 Evaluate the expression @var{expr} without displaying @code{void}
20154 returned values.
20155
20156 You can use this variant of the @code{print} command if you want to
20157 execute a function from your program that does not return anything
20158 (a.k.a.@: @dfn{a void function}), but without cluttering the output
20159 with @code{void} returned values that @value{GDBN} will otherwise
20160 print. If the result is not void, it is printed and saved in the
20161 value history.
20162 @end table
20163
20164 It is possible for the function you call via the @code{print} or
20165 @code{call} command to generate a signal (e.g., if there's a bug in
20166 the function, or if you passed it incorrect arguments). What happens
20167 in that case is controlled by the @code{set unwindonsignal} command.
20168
20169 Similarly, with a C@t{++} program it is possible for the function you
20170 call via the @code{print} or @code{call} command to generate an
20171 exception that is not handled due to the constraints of the dummy
20172 frame. In this case, any exception that is raised in the frame, but has
20173 an out-of-frame exception handler will not be found. GDB builds a
20174 dummy-frame for the inferior function call, and the unwinder cannot
20175 seek for exception handlers outside of this dummy-frame. What happens
20176 in that case is controlled by the
20177 @code{set unwind-on-terminating-exception} command.
20178
20179 @table @code
20180 @item set unwindonsignal
20181 @kindex set unwindonsignal
20182 @cindex unwind stack in called functions
20183 @cindex call dummy stack unwinding
20184 Set unwinding of the stack if a signal is received while in a function
20185 that @value{GDBN} called in the program being debugged. If set to on,
20186 @value{GDBN} unwinds the stack it created for the call and restores
20187 the context to what it was before the call. If set to off (the
20188 default), @value{GDBN} stops in the frame where the signal was
20189 received.
20190
20191 @item show unwindonsignal
20192 @kindex show unwindonsignal
20193 Show the current setting of stack unwinding in the functions called by
20194 @value{GDBN}.
20195
20196 @item set unwind-on-terminating-exception
20197 @kindex set unwind-on-terminating-exception
20198 @cindex unwind stack in called functions with unhandled exceptions
20199 @cindex call dummy stack unwinding on unhandled exception.
20200 Set unwinding of the stack if a C@t{++} exception is raised, but left
20201 unhandled while in a function that @value{GDBN} called in the program being
20202 debugged. If set to on (the default), @value{GDBN} unwinds the stack
20203 it created for the call and restores the context to what it was before
20204 the call. If set to off, @value{GDBN} the exception is delivered to
20205 the default C@t{++} exception handler and the inferior terminated.
20206
20207 @item show unwind-on-terminating-exception
20208 @kindex show unwind-on-terminating-exception
20209 Show the current setting of stack unwinding in the functions called by
20210 @value{GDBN}.
20211
20212 @item set may-call-functions
20213 @kindex set may-call-functions
20214 @cindex disabling calling functions in the program
20215 @cindex calling functions in the program, disabling
20216 Set permission to call functions in the program.
20217 This controls whether @value{GDBN} will attempt to call functions in
20218 the program, such as with expressions in the @code{print} command. It
20219 defaults to @code{on}.
20220
20221 To call a function in the program, @value{GDBN} has to temporarily
20222 modify the state of the inferior. This has potentially undesired side
20223 effects. Also, having @value{GDBN} call nested functions is likely to
20224 be erroneous and may even crash the program being debugged. You can
20225 avoid such hazards by forbidding @value{GDBN} from calling functions
20226 in the program being debugged. If calling functions in the program
20227 is forbidden, GDB will throw an error when a command (such as printing
20228 an expression) starts a function call in the program.
20229
20230 @item show may-call-functions
20231 @kindex show may-call-functions
20232 Show permission to call functions in the program.
20233
20234 @end table
20235
20236 @subsection Calling functions with no debug info
20237
20238 @cindex no debug info functions
20239 Sometimes, a function you wish to call is missing debug information.
20240 In such case, @value{GDBN} does not know the type of the function,
20241 including the types of the function's parameters. To avoid calling
20242 the inferior function incorrectly, which could result in the called
20243 function functioning erroneously and even crash, @value{GDBN} refuses
20244 to call the function unless you tell it the type of the function.
20245
20246 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
20247 to do that. The simplest is to cast the call to the function's
20248 declared return type. For example:
20249
20250 @smallexample
20251 (@value{GDBP}) p getenv ("PATH")
20252 'getenv' has unknown return type; cast the call to its declared return type
20253 (@value{GDBP}) p (char *) getenv ("PATH")
20254 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
20255 @end smallexample
20256
20257 Casting the return type of a no-debug function is equivalent to
20258 casting the function to a pointer to a prototyped function that has a
20259 prototype that matches the types of the passed-in arguments, and
20260 calling that. I.e., the call above is equivalent to:
20261
20262 @smallexample
20263 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
20264 @end smallexample
20265
20266 @noindent
20267 and given this prototyped C or C++ function with float parameters:
20268
20269 @smallexample
20270 float multiply (float v1, float v2) @{ return v1 * v2; @}
20271 @end smallexample
20272
20273 @noindent
20274 these calls are equivalent:
20275
20276 @smallexample
20277 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
20278 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
20279 @end smallexample
20280
20281 If the function you wish to call is declared as unprototyped (i.e.@:
20282 old K&R style), you must use the cast-to-function-pointer syntax, so
20283 that @value{GDBN} knows that it needs to apply default argument
20284 promotions (promote float arguments to double). @xref{ABI, float
20285 promotion}. For example, given this unprototyped C function with
20286 float parameters, and no debug info:
20287
20288 @smallexample
20289 float
20290 multiply_noproto (v1, v2)
20291 float v1, v2;
20292 @{
20293 return v1 * v2;
20294 @}
20295 @end smallexample
20296
20297 @noindent
20298 you call it like this:
20299
20300 @smallexample
20301 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20302 @end smallexample
20303
20304 @node Patching
20305 @section Patching Programs
20306
20307 @cindex patching binaries
20308 @cindex writing into executables
20309 @cindex writing into corefiles
20310
20311 By default, @value{GDBN} opens the file containing your program's
20312 executable code (or the corefile) read-only. This prevents accidental
20313 alterations to machine code; but it also prevents you from intentionally
20314 patching your program's binary.
20315
20316 If you'd like to be able to patch the binary, you can specify that
20317 explicitly with the @code{set write} command. For example, you might
20318 want to turn on internal debugging flags, or even to make emergency
20319 repairs.
20320
20321 @table @code
20322 @kindex set write
20323 @item set write on
20324 @itemx set write off
20325 If you specify @samp{set write on}, @value{GDBN} opens executable and
20326 core files for both reading and writing; if you specify @kbd{set write
20327 off} (the default), @value{GDBN} opens them read-only.
20328
20329 If you have already loaded a file, you must load it again (using the
20330 @code{exec-file} or @code{core-file} command) after changing @code{set
20331 write}, for your new setting to take effect.
20332
20333 @item show write
20334 @kindex show write
20335 Display whether executable files and core files are opened for writing
20336 as well as reading.
20337 @end table
20338
20339 @node Compiling and Injecting Code
20340 @section Compiling and injecting code in @value{GDBN}
20341 @cindex injecting code
20342 @cindex writing into executables
20343 @cindex compiling code
20344
20345 @value{GDBN} supports on-demand compilation and code injection into
20346 programs running under @value{GDBN}. GCC 5.0 or higher built with
20347 @file{libcc1.so} must be installed for this functionality to be enabled.
20348 This functionality is implemented with the following commands.
20349
20350 @table @code
20351 @kindex compile code
20352 @item compile code @var{source-code}
20353 @itemx compile code -raw @var{--} @var{source-code}
20354 Compile @var{source-code} with the compiler language found as the current
20355 language in @value{GDBN} (@pxref{Languages}). If compilation and
20356 injection is not supported with the current language specified in
20357 @value{GDBN}, or the compiler does not support this feature, an error
20358 message will be printed. If @var{source-code} compiles and links
20359 successfully, @value{GDBN} will load the object-code emitted,
20360 and execute it within the context of the currently selected inferior.
20361 It is important to note that the compiled code is executed immediately.
20362 After execution, the compiled code is removed from @value{GDBN} and any
20363 new types or variables you have defined will be deleted.
20364
20365 The command allows you to specify @var{source-code} in two ways.
20366 The simplest method is to provide a single line of code to the command.
20367 E.g.:
20368
20369 @smallexample
20370 compile code printf ("hello world\n");
20371 @end smallexample
20372
20373 If you specify options on the command line as well as source code, they
20374 may conflict. The @samp{--} delimiter can be used to separate options
20375 from actual source code. E.g.:
20376
20377 @smallexample
20378 compile code -r -- printf ("hello world\n");
20379 @end smallexample
20380
20381 Alternatively you can enter source code as multiple lines of text. To
20382 enter this mode, invoke the @samp{compile code} command without any text
20383 following the command. This will start the multiple-line editor and
20384 allow you to type as many lines of source code as required. When you
20385 have completed typing, enter @samp{end} on its own line to exit the
20386 editor.
20387
20388 @smallexample
20389 compile code
20390 >printf ("hello\n");
20391 >printf ("world\n");
20392 >end
20393 @end smallexample
20394
20395 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20396 provided @var{source-code} in a callable scope. In this case, you must
20397 specify the entry point of the code by defining a function named
20398 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20399 inferior. Using @samp{-raw} option may be needed for example when
20400 @var{source-code} requires @samp{#include} lines which may conflict with
20401 inferior symbols otherwise.
20402
20403 @kindex compile file
20404 @item compile file @var{filename}
20405 @itemx compile file -raw @var{filename}
20406 Like @code{compile code}, but take the source code from @var{filename}.
20407
20408 @smallexample
20409 compile file /home/user/example.c
20410 @end smallexample
20411 @end table
20412
20413 @table @code
20414 @item compile print [[@var{options}] --] @var{expr}
20415 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
20416 Compile and execute @var{expr} with the compiler language found as the
20417 current language in @value{GDBN} (@pxref{Languages}). By default the
20418 value of @var{expr} is printed in a format appropriate to its data type;
20419 you can choose a different format by specifying @samp{/@var{f}}, where
20420 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
20421 Formats}. The @code{compile print} command accepts the same options
20422 as the @code{print} command; see @ref{print options}.
20423
20424 @item compile print [[@var{options}] --]
20425 @itemx compile print [[@var{options}] --] /@var{f}
20426 @cindex reprint the last value
20427 Alternatively you can enter the expression (source code producing it) as
20428 multiple lines of text. To enter this mode, invoke the @samp{compile print}
20429 command without any text following the command. This will start the
20430 multiple-line editor.
20431 @end table
20432
20433 @noindent
20434 The process of compiling and injecting the code can be inspected using:
20435
20436 @table @code
20437 @anchor{set debug compile}
20438 @item set debug compile
20439 @cindex compile command debugging info
20440 Turns on or off display of @value{GDBN} process of compiling and
20441 injecting the code. The default is off.
20442
20443 @item show debug compile
20444 Displays the current state of displaying @value{GDBN} process of
20445 compiling and injecting the code.
20446
20447 @anchor{set debug compile-cplus-types}
20448 @item set debug compile-cplus-types
20449 @cindex compile C@t{++} type conversion
20450 Turns on or off the display of C@t{++} type conversion debugging information.
20451 The default is off.
20452
20453 @item show debug compile-cplus-types
20454 Displays the current state of displaying debugging information for
20455 C@t{++} type conversion.
20456 @end table
20457
20458 @subsection Compilation options for the @code{compile} command
20459
20460 @value{GDBN} needs to specify the right compilation options for the code
20461 to be injected, in part to make its ABI compatible with the inferior
20462 and in part to make the injected code compatible with @value{GDBN}'s
20463 injecting process.
20464
20465 @noindent
20466 The options used, in increasing precedence:
20467
20468 @table @asis
20469 @item target architecture and OS options (@code{gdbarch})
20470 These options depend on target processor type and target operating
20471 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20472 (@code{-m64}) compilation option.
20473
20474 @item compilation options recorded in the target
20475 @value{NGCC} (since version 4.7) stores the options used for compilation
20476 into @code{DW_AT_producer} part of DWARF debugging information according
20477 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20478 explicitly specify @code{-g} during inferior compilation otherwise
20479 @value{NGCC} produces no DWARF. This feature is only relevant for
20480 platforms where @code{-g} produces DWARF by default, otherwise one may
20481 try to enforce DWARF by using @code{-gdwarf-4}.
20482
20483 @item compilation options set by @code{set compile-args}
20484 @end table
20485
20486 @noindent
20487 You can override compilation options using the following command:
20488
20489 @table @code
20490 @item set compile-args
20491 @cindex compile command options override
20492 Set compilation options used for compiling and injecting code with the
20493 @code{compile} commands. These options override any conflicting ones
20494 from the target architecture and/or options stored during inferior
20495 compilation.
20496
20497 @item show compile-args
20498 Displays the current state of compilation options override.
20499 This does not show all the options actually used during compilation,
20500 use @ref{set debug compile} for that.
20501 @end table
20502
20503 @subsection Caveats when using the @code{compile} command
20504
20505 There are a few caveats to keep in mind when using the @code{compile}
20506 command. As the caveats are different per language, the table below
20507 highlights specific issues on a per language basis.
20508
20509 @table @asis
20510 @item C code examples and caveats
20511 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20512 attempt to compile the source code with a @samp{C} compiler. The source
20513 code provided to the @code{compile} command will have much the same
20514 access to variables and types as it normally would if it were part of
20515 the program currently being debugged in @value{GDBN}.
20516
20517 Below is a sample program that forms the basis of the examples that
20518 follow. This program has been compiled and loaded into @value{GDBN},
20519 much like any other normal debugging session.
20520
20521 @smallexample
20522 void function1 (void)
20523 @{
20524 int i = 42;
20525 printf ("function 1\n");
20526 @}
20527
20528 void function2 (void)
20529 @{
20530 int j = 12;
20531 function1 ();
20532 @}
20533
20534 int main(void)
20535 @{
20536 int k = 6;
20537 int *p;
20538 function2 ();
20539 return 0;
20540 @}
20541 @end smallexample
20542
20543 For the purposes of the examples in this section, the program above has
20544 been compiled, loaded into @value{GDBN}, stopped at the function
20545 @code{main}, and @value{GDBN} is awaiting input from the user.
20546
20547 To access variables and types for any program in @value{GDBN}, the
20548 program must be compiled and packaged with debug information. The
20549 @code{compile} command is not an exception to this rule. Without debug
20550 information, you can still use the @code{compile} command, but you will
20551 be very limited in what variables and types you can access.
20552
20553 So with that in mind, the example above has been compiled with debug
20554 information enabled. The @code{compile} command will have access to
20555 all variables and types (except those that may have been optimized
20556 out). Currently, as @value{GDBN} has stopped the program in the
20557 @code{main} function, the @code{compile} command would have access to
20558 the variable @code{k}. You could invoke the @code{compile} command
20559 and type some source code to set the value of @code{k}. You can also
20560 read it, or do anything with that variable you would normally do in
20561 @code{C}. Be aware that changes to inferior variables in the
20562 @code{compile} command are persistent. In the following example:
20563
20564 @smallexample
20565 compile code k = 3;
20566 @end smallexample
20567
20568 @noindent
20569 the variable @code{k} is now 3. It will retain that value until
20570 something else in the example program changes it, or another
20571 @code{compile} command changes it.
20572
20573 Normal scope and access rules apply to source code compiled and
20574 injected by the @code{compile} command. In the example, the variables
20575 @code{j} and @code{k} are not accessible yet, because the program is
20576 currently stopped in the @code{main} function, where these variables
20577 are not in scope. Therefore, the following command
20578
20579 @smallexample
20580 compile code j = 3;
20581 @end smallexample
20582
20583 @noindent
20584 will result in a compilation error message.
20585
20586 Once the program is continued, execution will bring these variables in
20587 scope, and they will become accessible; then the code you specify via
20588 the @code{compile} command will be able to access them.
20589
20590 You can create variables and types with the @code{compile} command as
20591 part of your source code. Variables and types that are created as part
20592 of the @code{compile} command are not visible to the rest of the program for
20593 the duration of its run. This example is valid:
20594
20595 @smallexample
20596 compile code int ff = 5; printf ("ff is %d\n", ff);
20597 @end smallexample
20598
20599 However, if you were to type the following into @value{GDBN} after that
20600 command has completed:
20601
20602 @smallexample
20603 compile code printf ("ff is %d\n'', ff);
20604 @end smallexample
20605
20606 @noindent
20607 a compiler error would be raised as the variable @code{ff} no longer
20608 exists. Object code generated and injected by the @code{compile}
20609 command is removed when its execution ends. Caution is advised
20610 when assigning to program variables values of variables created by the
20611 code submitted to the @code{compile} command. This example is valid:
20612
20613 @smallexample
20614 compile code int ff = 5; k = ff;
20615 @end smallexample
20616
20617 The value of the variable @code{ff} is assigned to @code{k}. The variable
20618 @code{k} does not require the existence of @code{ff} to maintain the value
20619 it has been assigned. However, pointers require particular care in
20620 assignment. If the source code compiled with the @code{compile} command
20621 changed the address of a pointer in the example program, perhaps to a
20622 variable created in the @code{compile} command, that pointer would point
20623 to an invalid location when the command exits. The following example
20624 would likely cause issues with your debugged program:
20625
20626 @smallexample
20627 compile code int ff = 5; p = &ff;
20628 @end smallexample
20629
20630 In this example, @code{p} would point to @code{ff} when the
20631 @code{compile} command is executing the source code provided to it.
20632 However, as variables in the (example) program persist with their
20633 assigned values, the variable @code{p} would point to an invalid
20634 location when the command exists. A general rule should be followed
20635 in that you should either assign @code{NULL} to any assigned pointers,
20636 or restore a valid location to the pointer before the command exits.
20637
20638 Similar caution must be exercised with any structs, unions, and typedefs
20639 defined in @code{compile} command. Types defined in the @code{compile}
20640 command will no longer be available in the next @code{compile} command.
20641 Therefore, if you cast a variable to a type defined in the
20642 @code{compile} command, care must be taken to ensure that any future
20643 need to resolve the type can be achieved.
20644
20645 @smallexample
20646 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20647 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20648 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20649 Compilation failed.
20650 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20651 42
20652 @end smallexample
20653
20654 Variables that have been optimized away by the compiler are not
20655 accessible to the code submitted to the @code{compile} command.
20656 Access to those variables will generate a compiler error which @value{GDBN}
20657 will print to the console.
20658 @end table
20659
20660 @subsection Compiler search for the @code{compile} command
20661
20662 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20663 which may not be obvious for remote targets of different architecture
20664 than where @value{GDBN} is running. Environment variable @env{PATH} on
20665 @value{GDBN} host is searched for @value{NGCC} binary matching the
20666 target architecture and operating system. This search can be overriden
20667 by @code{set compile-gcc} @value{GDBN} command below. @env{PATH} is
20668 taken from shell that executed @value{GDBN}, it is not the value set by
20669 @value{GDBN} command @code{set environment}). @xref{Environment}.
20670
20671
20672 Specifically @env{PATH} is searched for binaries matching regular expression
20673 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20674 debugged. @var{arch} is processor name --- multiarch is supported, so for
20675 example both @code{i386} and @code{x86_64} targets look for pattern
20676 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20677 for pattern @code{s390x?}. @var{os} is currently supported only for
20678 pattern @code{linux(-gnu)?}.
20679
20680 On Posix hosts the compiler driver @value{GDBN} needs to find also
20681 shared library @file{libcc1.so} from the compiler. It is searched in
20682 default shared library search path (overridable with usual environment
20683 variable @env{LD_LIBRARY_PATH}), unrelated to @env{PATH} or @code{set
20684 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20685 according to the installation of the found compiler --- as possibly
20686 specified by the @code{set compile-gcc} command.
20687
20688 @table @code
20689 @item set compile-gcc
20690 @cindex compile command driver filename override
20691 Set compilation command used for compiling and injecting code with the
20692 @code{compile} commands. If this option is not set (it is set to
20693 an empty string), the search described above will occur --- that is the
20694 default.
20695
20696 @item show compile-gcc
20697 Displays the current compile command @value{NGCC} driver filename.
20698 If set, it is the main command @command{gcc}, found usually for example
20699 under name @file{x86_64-linux-gnu-gcc}.
20700 @end table
20701
20702 @node GDB Files
20703 @chapter @value{GDBN} Files
20704
20705 @value{GDBN} needs to know the file name of the program to be debugged,
20706 both in order to read its symbol table and in order to start your
20707 program. To debug a core dump of a previous run, you must also tell
20708 @value{GDBN} the name of the core dump file.
20709
20710 @menu
20711 * Files:: Commands to specify files
20712 * File Caching:: Information about @value{GDBN}'s file caching
20713 * Separate Debug Files:: Debugging information in separate files
20714 * MiniDebugInfo:: Debugging information in a special section
20715 * Index Files:: Index files speed up GDB
20716 * Symbol Errors:: Errors reading symbol files
20717 * Data Files:: GDB data files
20718 @end menu
20719
20720 @node Files
20721 @section Commands to Specify Files
20722
20723 @cindex symbol table
20724 @cindex core dump file
20725
20726 You may want to specify executable and core dump file names. The usual
20727 way to do this is at start-up time, using the arguments to
20728 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20729 Out of @value{GDBN}}).
20730
20731 Occasionally it is necessary to change to a different file during a
20732 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20733 specify a file you want to use. Or you are debugging a remote target
20734 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20735 Program}). In these situations the @value{GDBN} commands to specify
20736 new files are useful.
20737
20738 @table @code
20739 @cindex executable file
20740 @kindex file
20741 @item file @var{filename}
20742 Use @var{filename} as the program to be debugged. It is read for its
20743 symbols and for the contents of pure memory. It is also the program
20744 executed when you use the @code{run} command. If you do not specify a
20745 directory and the file is not found in the @value{GDBN} working directory,
20746 @value{GDBN} uses the environment variable @env{PATH} as a list of
20747 directories to search, just as the shell does when looking for a program
20748 to run. You can change the value of this variable, for both @value{GDBN}
20749 and your program, using the @code{path} command.
20750
20751 @cindex unlinked object files
20752 @cindex patching object files
20753 You can load unlinked object @file{.o} files into @value{GDBN} using
20754 the @code{file} command. You will not be able to ``run'' an object
20755 file, but you can disassemble functions and inspect variables. Also,
20756 if the underlying BFD functionality supports it, you could use
20757 @kbd{gdb -write} to patch object files using this technique. Note
20758 that @value{GDBN} can neither interpret nor modify relocations in this
20759 case, so branches and some initialized variables will appear to go to
20760 the wrong place. But this feature is still handy from time to time.
20761
20762 @item file
20763 @code{file} with no argument makes @value{GDBN} discard any information it
20764 has on both executable file and the symbol table.
20765
20766 @kindex exec-file
20767 @item exec-file @r{[} @var{filename} @r{]}
20768 Specify that the program to be run (but not the symbol table) is found
20769 in @var{filename}. @value{GDBN} searches the environment variable @env{PATH}
20770 if necessary to locate your program. Omitting @var{filename} means to
20771 discard information on the executable file.
20772
20773 @kindex symbol-file
20774 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20775 Read symbol table information from file @var{filename}. @env{PATH} is
20776 searched when necessary. Use the @code{file} command to get both symbol
20777 table and program to run from the same file.
20778
20779 If an optional @var{offset} is specified, it is added to the start
20780 address of each section in the symbol file. This is useful if the
20781 program is relocated at runtime, such as the Linux kernel with kASLR
20782 enabled.
20783
20784 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20785 program's symbol table.
20786
20787 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20788 some breakpoints and auto-display expressions. This is because they may
20789 contain pointers to the internal data recording symbols and data types,
20790 which are part of the old symbol table data being discarded inside
20791 @value{GDBN}.
20792
20793 @code{symbol-file} does not repeat if you press @key{RET} again after
20794 executing it once.
20795
20796 When @value{GDBN} is configured for a particular environment, it
20797 understands debugging information in whatever format is the standard
20798 generated for that environment; you may use either a @sc{gnu} compiler, or
20799 other compilers that adhere to the local conventions.
20800 Best results are usually obtained from @sc{gnu} compilers; for example,
20801 using @code{@value{NGCC}} you can generate debugging information for
20802 optimized code.
20803
20804 For most kinds of object files, with the exception of old SVR3 systems
20805 using COFF, the @code{symbol-file} command does not normally read the
20806 symbol table in full right away. Instead, it scans the symbol table
20807 quickly to find which source files and which symbols are present. The
20808 details are read later, one source file at a time, as they are needed.
20809
20810 The purpose of this two-stage reading strategy is to make @value{GDBN}
20811 start up faster. For the most part, it is invisible except for
20812 occasional pauses while the symbol table details for a particular source
20813 file are being read. (The @code{set verbose} command can turn these
20814 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20815 Warnings and Messages}.)
20816
20817 We have not implemented the two-stage strategy for COFF yet. When the
20818 symbol table is stored in COFF format, @code{symbol-file} reads the
20819 symbol table data in full right away. Note that ``stabs-in-COFF''
20820 still does the two-stage strategy, since the debug info is actually
20821 in stabs format.
20822
20823 @kindex readnow
20824 @cindex reading symbols immediately
20825 @cindex symbols, reading immediately
20826 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20827 @itemx file @r{[} -readnow @r{]} @var{filename}
20828 You can override the @value{GDBN} two-stage strategy for reading symbol
20829 tables by using the @samp{-readnow} option with any of the commands that
20830 load symbol table information, if you want to be sure @value{GDBN} has the
20831 entire symbol table available.
20832
20833 @cindex @code{-readnever}, option for symbol-file command
20834 @cindex never read symbols
20835 @cindex symbols, never read
20836 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20837 @itemx file @r{[} -readnever @r{]} @var{filename}
20838 You can instruct @value{GDBN} to never read the symbolic information
20839 contained in @var{filename} by using the @samp{-readnever} option.
20840 @xref{--readnever}.
20841
20842 @c FIXME: for now no mention of directories, since this seems to be in
20843 @c flux. 13mar1992 status is that in theory GDB would look either in
20844 @c current dir or in same dir as myprog; but issues like competing
20845 @c GDB's, or clutter in system dirs, mean that in practice right now
20846 @c only current dir is used. FFish says maybe a special GDB hierarchy
20847 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20848 @c files.
20849
20850 @kindex core-file
20851 @item core-file @r{[}@var{filename}@r{]}
20852 @itemx core
20853 Specify the whereabouts of a core dump file to be used as the ``contents
20854 of memory''. Traditionally, core files contain only some parts of the
20855 address space of the process that generated them; @value{GDBN} can access the
20856 executable file itself for other parts.
20857
20858 @code{core-file} with no argument specifies that no core file is
20859 to be used.
20860
20861 Note that the core file is ignored when your program is actually running
20862 under @value{GDBN}. So, if you have been running your program and you
20863 wish to debug a core file instead, you must kill the subprocess in which
20864 the program is running. To do this, use the @code{kill} command
20865 (@pxref{Kill Process, ,Killing the Child Process}).
20866
20867 @kindex add-symbol-file
20868 @cindex dynamic linking
20869 @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{]}
20870 The @code{add-symbol-file} command reads additional symbol table
20871 information from the file @var{filename}. You would use this command
20872 when @var{filename} has been dynamically loaded (by some other means)
20873 into the program that is running. The @var{textaddress} parameter gives
20874 the memory address at which the file's text section has been loaded.
20875 You can additionally specify the base address of other sections using
20876 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20877 If a section is omitted, @value{GDBN} will use its default addresses
20878 as found in @var{filename}. Any @var{address} or @var{textaddress}
20879 can be given as an expression.
20880
20881 If an optional @var{offset} is specified, it is added to the start
20882 address of each section, except those for which the address was
20883 specified explicitly.
20884
20885 The symbol table of the file @var{filename} is added to the symbol table
20886 originally read with the @code{symbol-file} command. You can use the
20887 @code{add-symbol-file} command any number of times; the new symbol data
20888 thus read is kept in addition to the old.
20889
20890 Changes can be reverted using the command @code{remove-symbol-file}.
20891
20892 @cindex relocatable object files, reading symbols from
20893 @cindex object files, relocatable, reading symbols from
20894 @cindex reading symbols from relocatable object files
20895 @cindex symbols, reading from relocatable object files
20896 @cindex @file{.o} files, reading symbols from
20897 Although @var{filename} is typically a shared library file, an
20898 executable file, or some other object file which has been fully
20899 relocated for loading into a process, you can also load symbolic
20900 information from relocatable @file{.o} files, as long as:
20901
20902 @itemize @bullet
20903 @item
20904 the file's symbolic information refers only to linker symbols defined in
20905 that file, not to symbols defined by other object files,
20906 @item
20907 every section the file's symbolic information refers to has actually
20908 been loaded into the inferior, as it appears in the file, and
20909 @item
20910 you can determine the address at which every section was loaded, and
20911 provide these to the @code{add-symbol-file} command.
20912 @end itemize
20913
20914 @noindent
20915 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20916 relocatable files into an already running program; such systems
20917 typically make the requirements above easy to meet. However, it's
20918 important to recognize that many native systems use complex link
20919 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20920 assembly, for example) that make the requirements difficult to meet. In
20921 general, one cannot assume that using @code{add-symbol-file} to read a
20922 relocatable object file's symbolic information will have the same effect
20923 as linking the relocatable object file into the program in the normal
20924 way.
20925
20926 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20927
20928 @kindex remove-symbol-file
20929 @item remove-symbol-file @var{filename}
20930 @item remove-symbol-file -a @var{address}
20931 Remove a symbol file added via the @code{add-symbol-file} command. The
20932 file to remove can be identified by its @var{filename} or by an @var{address}
20933 that lies within the boundaries of this symbol file in memory. Example:
20934
20935 @smallexample
20936 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20937 add symbol table from file "/home/user/gdb/mylib.so" at
20938 .text_addr = 0x7ffff7ff9480
20939 (y or n) y
20940 Reading symbols from /home/user/gdb/mylib.so...
20941 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20942 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20943 (gdb)
20944 @end smallexample
20945
20946
20947 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20948
20949 @kindex add-symbol-file-from-memory
20950 @cindex @code{syscall DSO}
20951 @cindex load symbols from memory
20952 @item add-symbol-file-from-memory @var{address}
20953 Load symbols from the given @var{address} in a dynamically loaded
20954 object file whose image is mapped directly into the inferior's memory.
20955 For example, the Linux kernel maps a @code{syscall DSO} into each
20956 process's address space; this DSO provides kernel-specific code for
20957 some system calls. The argument can be any expression whose
20958 evaluation yields the address of the file's shared object file header.
20959 For this command to work, you must have used @code{symbol-file} or
20960 @code{exec-file} commands in advance.
20961
20962 @kindex section
20963 @item section @var{section} @var{addr}
20964 The @code{section} command changes the base address of the named
20965 @var{section} of the exec file to @var{addr}. This can be used if the
20966 exec file does not contain section addresses, (such as in the
20967 @code{a.out} format), or when the addresses specified in the file
20968 itself are wrong. Each section must be changed separately. The
20969 @code{info files} command, described below, lists all the sections and
20970 their addresses.
20971
20972 @kindex info files
20973 @kindex info target
20974 @item info files
20975 @itemx info target
20976 @code{info files} and @code{info target} are synonymous; both print the
20977 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20978 including the names of the executable and core dump files currently in
20979 use by @value{GDBN}, and the files from which symbols were loaded. The
20980 command @code{help target} lists all possible targets rather than
20981 current ones.
20982
20983 @kindex maint info sections
20984 @item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
20985 Another command that can give you extra information about program sections
20986 is @code{maint info sections}. In addition to the section information
20987 displayed by @code{info files}, this command displays the flags and file
20988 offset of each section in the executable and core dump files.
20989
20990 When @samp{-all-objects} is passed then sections from all loaded object
20991 files, including shared libraries, are printed.
20992
20993 The optional @var{filter-list} is a space separated list of filter
20994 keywords. Sections that match any one of the filter criteria will be
20995 printed. There are two types of filter:
20996
20997 @table @code
20998 @item @var{section-name}
20999 Display information about any section named @var{section-name}.
21000 @item @var{section-flag}
21001 Display information for any section with @var{section-flag}. The
21002 section flags that @value{GDBN} currently knows about are:
21003 @table @code
21004 @item ALLOC
21005 Section will have space allocated in the process when loaded.
21006 Set for all sections except those containing debug information.
21007 @item LOAD
21008 Section will be loaded from the file into the child process memory.
21009 Set for pre-initialized code and data, clear for @code{.bss} sections.
21010 @item RELOC
21011 Section needs to be relocated before loading.
21012 @item READONLY
21013 Section cannot be modified by the child process.
21014 @item CODE
21015 Section contains executable code only.
21016 @item DATA
21017 Section contains data only (no executable code).
21018 @item ROM
21019 Section will reside in ROM.
21020 @item CONSTRUCTOR
21021 Section contains data for constructor/destructor lists.
21022 @item HAS_CONTENTS
21023 Section is not empty.
21024 @item NEVER_LOAD
21025 An instruction to the linker to not output the section.
21026 @item COFF_SHARED_LIBRARY
21027 A notification to the linker that the section contains
21028 COFF shared library information.
21029 @item IS_COMMON
21030 Section contains common symbols.
21031 @end table
21032 @end table
21033
21034 @kindex maint info target-sections
21035 @item maint info target-sections
21036 This command prints @value{GDBN}'s internal section table. For each
21037 target @value{GDBN} maintains a table containing the allocatable
21038 sections from all currently mapped objects, along with information
21039 about where the section is mapped.
21040
21041 @kindex set trust-readonly-sections
21042 @cindex read-only sections
21043 @item set trust-readonly-sections on
21044 Tell @value{GDBN} that readonly sections in your object file
21045 really are read-only (i.e.@: that their contents will not change).
21046 In that case, @value{GDBN} can fetch values from these sections
21047 out of the object file, rather than from the target program.
21048 For some targets (notably embedded ones), this can be a significant
21049 enhancement to debugging performance.
21050
21051 The default is off.
21052
21053 @item set trust-readonly-sections off
21054 Tell @value{GDBN} not to trust readonly sections. This means that
21055 the contents of the section might change while the program is running,
21056 and must therefore be fetched from the target when needed.
21057
21058 @item show trust-readonly-sections
21059 Show the current setting of trusting readonly sections.
21060 @end table
21061
21062 All file-specifying commands allow both absolute and relative file names
21063 as arguments. @value{GDBN} always converts the file name to an absolute file
21064 name and remembers it that way.
21065
21066 @cindex shared libraries
21067 @anchor{Shared Libraries}
21068 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
21069 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
21070 DSBT (TIC6X) shared libraries.
21071
21072 On MS-Windows @value{GDBN} must be linked with the Expat library to support
21073 shared libraries. @xref{Expat}.
21074
21075 @value{GDBN} automatically loads symbol definitions from shared libraries
21076 when you use the @code{run} command, or when you examine a core file.
21077 (Before you issue the @code{run} command, @value{GDBN} does not understand
21078 references to a function in a shared library, however---unless you are
21079 debugging a core file).
21080
21081 @c FIXME: some @value{GDBN} release may permit some refs to undef
21082 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
21083 @c FIXME...lib; check this from time to time when updating manual
21084
21085 There are times, however, when you may wish to not automatically load
21086 symbol definitions from shared libraries, such as when they are
21087 particularly large or there are many of them.
21088
21089 To control the automatic loading of shared library symbols, use the
21090 commands:
21091
21092 @table @code
21093 @kindex set auto-solib-add
21094 @item set auto-solib-add @var{mode}
21095 If @var{mode} is @code{on}, symbols from all shared object libraries
21096 will be loaded automatically when the inferior begins execution, you
21097 attach to an independently started inferior, or when the dynamic linker
21098 informs @value{GDBN} that a new library has been loaded. If @var{mode}
21099 is @code{off}, symbols must be loaded manually, using the
21100 @code{sharedlibrary} command. The default value is @code{on}.
21101
21102 @cindex memory used for symbol tables
21103 If your program uses lots of shared libraries with debug info that
21104 takes large amounts of memory, you can decrease the @value{GDBN}
21105 memory footprint by preventing it from automatically loading the
21106 symbols from shared libraries. To that end, type @kbd{set
21107 auto-solib-add off} before running the inferior, then load each
21108 library whose debug symbols you do need with @kbd{sharedlibrary
21109 @var{regexp}}, where @var{regexp} is a regular expression that matches
21110 the libraries whose symbols you want to be loaded.
21111
21112 @kindex show auto-solib-add
21113 @item show auto-solib-add
21114 Display the current autoloading mode.
21115 @end table
21116
21117 @cindex load shared library
21118 To explicitly load shared library symbols, use the @code{sharedlibrary}
21119 command:
21120
21121 @table @code
21122 @kindex info sharedlibrary
21123 @kindex info share
21124 @item info share @var{regex}
21125 @itemx info sharedlibrary @var{regex}
21126 Print the names of the shared libraries which are currently loaded
21127 that match @var{regex}. If @var{regex} is omitted then print
21128 all shared libraries that are loaded.
21129
21130 @kindex info dll
21131 @item info dll @var{regex}
21132 This is an alias of @code{info sharedlibrary}.
21133
21134 @kindex sharedlibrary
21135 @kindex share
21136 @item sharedlibrary @var{regex}
21137 @itemx share @var{regex}
21138 Load shared object library symbols for files matching a
21139 Unix regular expression.
21140 As with files loaded automatically, it only loads shared libraries
21141 required by your program for a core file or after typing @code{run}. If
21142 @var{regex} is omitted all shared libraries required by your program are
21143 loaded.
21144
21145 @item nosharedlibrary
21146 @kindex nosharedlibrary
21147 @cindex unload symbols from shared libraries
21148 Unload all shared object library symbols. This discards all symbols
21149 that have been loaded from all shared libraries. Symbols from shared
21150 libraries that were loaded by explicit user requests are not
21151 discarded.
21152 @end table
21153
21154 Sometimes you may wish that @value{GDBN} stops and gives you control
21155 when any of shared library events happen. The best way to do this is
21156 to use @code{catch load} and @code{catch unload} (@pxref{Set
21157 Catchpoints}).
21158
21159 @value{GDBN} also supports the @code{set stop-on-solib-events}
21160 command for this. This command exists for historical reasons. It is
21161 less useful than setting a catchpoint, because it does not allow for
21162 conditions or commands as a catchpoint does.
21163
21164 @table @code
21165 @item set stop-on-solib-events
21166 @kindex set stop-on-solib-events
21167 This command controls whether @value{GDBN} should give you control
21168 when the dynamic linker notifies it about some shared library event.
21169 The most common event of interest is loading or unloading of a new
21170 shared library.
21171
21172 @item show stop-on-solib-events
21173 @kindex show stop-on-solib-events
21174 Show whether @value{GDBN} stops and gives you control when shared
21175 library events happen.
21176 @end table
21177
21178 Shared libraries are also supported in many cross or remote debugging
21179 configurations. @value{GDBN} needs to have access to the target's libraries;
21180 this can be accomplished either by providing copies of the libraries
21181 on the host system, or by asking @value{GDBN} to automatically retrieve the
21182 libraries from the target. If copies of the target libraries are
21183 provided, they need to be the same as the target libraries, although the
21184 copies on the target can be stripped as long as the copies on the host are
21185 not.
21186
21187 @cindex where to look for shared libraries
21188 For remote debugging, you need to tell @value{GDBN} where the target
21189 libraries are, so that it can load the correct copies---otherwise, it
21190 may try to load the host's libraries. @value{GDBN} has two variables
21191 to specify the search directories for target libraries.
21192
21193 @table @code
21194 @cindex prefix for executable and shared library file names
21195 @cindex system root, alternate
21196 @kindex set solib-absolute-prefix
21197 @kindex set sysroot
21198 @item set sysroot @var{path}
21199 Use @var{path} as the system root for the program being debugged. Any
21200 absolute shared library paths will be prefixed with @var{path}; many
21201 runtime loaders store the absolute paths to the shared library in the
21202 target program's memory. When starting processes remotely, and when
21203 attaching to already-running processes (local or remote), their
21204 executable filenames will be prefixed with @var{path} if reported to
21205 @value{GDBN} as absolute by the operating system. If you use
21206 @code{set sysroot} to find executables and shared libraries, they need
21207 to be laid out in the same way that they are on the target, with
21208 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
21209 @var{path}.
21210
21211 If @var{path} starts with the sequence @file{target:} and the target
21212 system is remote then @value{GDBN} will retrieve the target binaries
21213 from the remote system. This is only supported when using a remote
21214 target that supports the @code{remote get} command (@pxref{File
21215 Transfer,,Sending files to a remote system}). The part of @var{path}
21216 following the initial @file{target:} (if present) is used as system
21217 root prefix on the remote file system. If @var{path} starts with the
21218 sequence @file{remote:} this is converted to the sequence
21219 @file{target:} by @code{set sysroot}@footnote{Historically the
21220 functionality to retrieve binaries from the remote system was
21221 provided by prefixing @var{path} with @file{remote:}}. If you want
21222 to specify a local system root using a directory that happens to be
21223 named @file{target:} or @file{remote:}, you need to use some
21224 equivalent variant of the name like @file{./target:}.
21225
21226 For targets with an MS-DOS based filesystem, such as MS-Windows,
21227 @value{GDBN} tries prefixing a few variants of the target
21228 absolute file name with @var{path}. But first, on Unix hosts,
21229 @value{GDBN} converts all backslash directory separators into forward
21230 slashes, because the backslash is not a directory separator on Unix:
21231
21232 @smallexample
21233 c:\foo\bar.dll @result{} c:/foo/bar.dll
21234 @end smallexample
21235
21236 Then, @value{GDBN} attempts prefixing the target file name with
21237 @var{path}, and looks for the resulting file name in the host file
21238 system:
21239
21240 @smallexample
21241 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
21242 @end smallexample
21243
21244 If that does not find the binary, @value{GDBN} tries removing
21245 the @samp{:} character from the drive spec, both for convenience, and,
21246 for the case of the host file system not supporting file names with
21247 colons:
21248
21249 @smallexample
21250 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
21251 @end smallexample
21252
21253 This makes it possible to have a system root that mirrors a target
21254 with more than one drive. E.g., you may want to setup your local
21255 copies of the target system shared libraries like so (note @samp{c} vs
21256 @samp{z}):
21257
21258 @smallexample
21259 @file{/path/to/sysroot/c/sys/bin/foo.dll}
21260 @file{/path/to/sysroot/c/sys/bin/bar.dll}
21261 @file{/path/to/sysroot/z/sys/bin/bar.dll}
21262 @end smallexample
21263
21264 @noindent
21265 and point the system root at @file{/path/to/sysroot}, so that
21266 @value{GDBN} can find the correct copies of both
21267 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
21268
21269 If that still does not find the binary, @value{GDBN} tries
21270 removing the whole drive spec from the target file name:
21271
21272 @smallexample
21273 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
21274 @end smallexample
21275
21276 This last lookup makes it possible to not care about the drive name,
21277 if you don't want or need to.
21278
21279 The @code{set solib-absolute-prefix} command is an alias for @code{set
21280 sysroot}.
21281
21282 @cindex default system root
21283 @cindex @samp{--with-sysroot}
21284 You can set the default system root by using the configure-time
21285 @samp{--with-sysroot} option. If the system root is inside
21286 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21287 @samp{--exec-prefix}), then the default system root will be updated
21288 automatically if the installed @value{GDBN} is moved to a new
21289 location.
21290
21291 @kindex show sysroot
21292 @item show sysroot
21293 Display the current executable and shared library prefix.
21294
21295 @kindex set solib-search-path
21296 @item set solib-search-path @var{path}
21297 If this variable is set, @var{path} is a colon-separated list of
21298 directories to search for shared libraries. @samp{solib-search-path}
21299 is used after @samp{sysroot} fails to locate the library, or if the
21300 path to the library is relative instead of absolute. If you want to
21301 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
21302 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
21303 finding your host's libraries. @samp{sysroot} is preferred; setting
21304 it to a nonexistent directory may interfere with automatic loading
21305 of shared library symbols.
21306
21307 @kindex show solib-search-path
21308 @item show solib-search-path
21309 Display the current shared library search path.
21310
21311 @cindex DOS file-name semantics of file names.
21312 @kindex set target-file-system-kind (unix|dos-based|auto)
21313 @kindex show target-file-system-kind
21314 @item set target-file-system-kind @var{kind}
21315 Set assumed file system kind for target reported file names.
21316
21317 Shared library file names as reported by the target system may not
21318 make sense as is on the system @value{GDBN} is running on. For
21319 example, when remote debugging a target that has MS-DOS based file
21320 system semantics, from a Unix host, the target may be reporting to
21321 @value{GDBN} a list of loaded shared libraries with file names such as
21322 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21323 drive letters, so the @samp{c:\} prefix is not normally understood as
21324 indicating an absolute file name, and neither is the backslash
21325 normally considered a directory separator character. In that case,
21326 the native file system would interpret this whole absolute file name
21327 as a relative file name with no directory components. This would make
21328 it impossible to point @value{GDBN} at a copy of the remote target's
21329 shared libraries on the host using @code{set sysroot}, and impractical
21330 with @code{set solib-search-path}. Setting
21331 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21332 to interpret such file names similarly to how the target would, and to
21333 map them to file names valid on @value{GDBN}'s native file system
21334 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21335 to one of the supported file system kinds. In that case, @value{GDBN}
21336 tries to determine the appropriate file system variant based on the
21337 current target's operating system (@pxref{ABI, ,Configuring the
21338 Current ABI}). The supported file system settings are:
21339
21340 @table @code
21341 @item unix
21342 Instruct @value{GDBN} to assume the target file system is of Unix
21343 kind. Only file names starting the forward slash (@samp{/}) character
21344 are considered absolute, and the directory separator character is also
21345 the forward slash.
21346
21347 @item dos-based
21348 Instruct @value{GDBN} to assume the target file system is DOS based.
21349 File names starting with either a forward slash, or a drive letter
21350 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21351 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21352 considered directory separators.
21353
21354 @item auto
21355 Instruct @value{GDBN} to use the file system kind associated with the
21356 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21357 This is the default.
21358 @end table
21359 @end table
21360
21361 @cindex file name canonicalization
21362 @cindex base name differences
21363 When processing file names provided by the user, @value{GDBN}
21364 frequently needs to compare them to the file names recorded in the
21365 program's debug info. Normally, @value{GDBN} compares just the
21366 @dfn{base names} of the files as strings, which is reasonably fast
21367 even for very large programs. (The base name of a file is the last
21368 portion of its name, after stripping all the leading directories.)
21369 This shortcut in comparison is based upon the assumption that files
21370 cannot have more than one base name. This is usually true, but
21371 references to files that use symlinks or similar filesystem
21372 facilities violate that assumption. If your program records files
21373 using such facilities, or if you provide file names to @value{GDBN}
21374 using symlinks etc., you can set @code{basenames-may-differ} to
21375 @code{true} to instruct @value{GDBN} to completely canonicalize each
21376 pair of file names it needs to compare. This will make file-name
21377 comparisons accurate, but at a price of a significant slowdown.
21378
21379 @table @code
21380 @item set basenames-may-differ
21381 @kindex set basenames-may-differ
21382 Set whether a source file may have multiple base names.
21383
21384 @item show basenames-may-differ
21385 @kindex show basenames-may-differ
21386 Show whether a source file may have multiple base names.
21387 @end table
21388
21389 @node File Caching
21390 @section File Caching
21391 @cindex caching of opened files
21392 @cindex caching of bfd objects
21393
21394 To speed up file loading, and reduce memory usage, @value{GDBN} will
21395 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21396 BFD, bfd, The Binary File Descriptor Library}. The following commands
21397 allow visibility and control of the caching behavior.
21398
21399 @table @code
21400 @kindex maint info bfds
21401 @item maint info bfds
21402 This prints information about each @code{bfd} object that is known to
21403 @value{GDBN}.
21404
21405 @kindex maint set bfd-sharing
21406 @kindex maint show bfd-sharing
21407 @kindex bfd caching
21408 @item maint set bfd-sharing
21409 @item maint show bfd-sharing
21410 Control whether @code{bfd} objects can be shared. When sharing is
21411 enabled @value{GDBN} reuses already open @code{bfd} objects rather
21412 than reopening the same file. Turning sharing off does not cause
21413 already shared @code{bfd} objects to be unshared, but all future files
21414 that are opened will create a new @code{bfd} object. Similarly,
21415 re-enabling sharing does not cause multiple existing @code{bfd}
21416 objects to be collapsed into a single shared @code{bfd} object.
21417
21418 @kindex set debug bfd-cache @var{level}
21419 @kindex bfd caching
21420 @item set debug bfd-cache @var{level}
21421 Turns on debugging of the bfd cache, setting the level to @var{level}.
21422
21423 @kindex show debug bfd-cache
21424 @kindex bfd caching
21425 @item show debug bfd-cache
21426 Show the current debugging level of the bfd cache.
21427 @end table
21428
21429 @node Separate Debug Files
21430 @section Debugging Information in Separate Files
21431 @cindex separate debugging information files
21432 @cindex debugging information in separate files
21433 @cindex @file{.debug} subdirectories
21434 @cindex debugging information directory, global
21435 @cindex global debugging information directories
21436 @cindex build ID, and separate debugging files
21437 @cindex @file{.build-id} directory
21438
21439 @value{GDBN} allows you to put a program's debugging information in a
21440 file separate from the executable itself, in a way that allows
21441 @value{GDBN} to find and load the debugging information automatically.
21442 Since debugging information can be very large---sometimes larger
21443 than the executable code itself---some systems distribute debugging
21444 information for their executables in separate files, which users can
21445 install only when they need to debug a problem.
21446
21447 @value{GDBN} supports two ways of specifying the separate debug info
21448 file:
21449
21450 @itemize @bullet
21451 @item
21452 The executable contains a @dfn{debug link} that specifies the name of
21453 the separate debug info file. The separate debug file's name is
21454 usually @file{@var{executable}.debug}, where @var{executable} is the
21455 name of the corresponding executable file without leading directories
21456 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
21457 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21458 checksum for the debug file, which @value{GDBN} uses to validate that
21459 the executable and the debug file came from the same build.
21460
21461 @item
21462 @anchor{build ID}
21463 The executable contains a @dfn{build ID}, a unique bit string that is
21464 also present in the corresponding debug info file. (This is supported
21465 only on some operating systems, when using the ELF or PE file formats
21466 for binary files and the @sc{gnu} Binutils.) For more details about
21467 this feature, see the description of the @option{--build-id}
21468 command-line option in @ref{Options, , Command Line Options, ld,
21469 The GNU Linker}. The debug info file's name is not specified
21470 explicitly by the build ID, but can be computed from the build ID, see
21471 below.
21472 @end itemize
21473
21474 Depending on the way the debug info file is specified, @value{GDBN}
21475 uses two different methods of looking for the debug file:
21476
21477 @itemize @bullet
21478 @item
21479 For the ``debug link'' method, @value{GDBN} looks up the named file in
21480 the directory of the executable file, then in a subdirectory of that
21481 directory named @file{.debug}, and finally under each one of the
21482 global debug directories, in a subdirectory whose name is identical to
21483 the leading directories of the executable's absolute file name. (On
21484 MS-Windows/MS-DOS, the drive letter of the executable's leading
21485 directories is converted to a one-letter subdirectory, i.e.@:
21486 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21487 filesystems disallow colons in file names.)
21488
21489 @item
21490 For the ``build ID'' method, @value{GDBN} looks in the
21491 @file{.build-id} subdirectory of each one of the global debug directories for
21492 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21493 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21494 are the rest of the bit string. (Real build ID strings are 32 or more
21495 hex characters, not 10.) @value{GDBN} can automatically query
21496 @code{debuginfod} servers using build IDs in order to download separate debug
21497 files that cannot be found locally. For more information see @ref{Debuginfod}.
21498 @end itemize
21499
21500 So, for example, suppose you ask @value{GDBN} to debug
21501 @file{/usr/bin/ls}, which has a debug link that specifies the
21502 file @file{ls.debug}, and a build ID whose value in hex is
21503 @code{abcdef1234}. If the list of the global debug directories includes
21504 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21505 debug information files, in the indicated order:
21506
21507 @itemize @minus
21508 @item
21509 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21510 @item
21511 @file{/usr/bin/ls.debug}
21512 @item
21513 @file{/usr/bin/.debug/ls.debug}
21514 @item
21515 @file{/usr/lib/debug/usr/bin/ls.debug}.
21516 @end itemize
21517
21518 If the debug file still has not been found and @code{debuginfod}
21519 (@pxref{Debuginfod}) is enabled, @value{GDBN} will attempt to download the
21520 file from @code{debuginfod} servers.
21521
21522 @anchor{debug-file-directory}
21523 Global debugging info directories default to what is set by @value{GDBN}
21524 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21525 you can also set the global debugging info directories, and view the list
21526 @value{GDBN} is currently using.
21527
21528 @table @code
21529
21530 @kindex set debug-file-directory
21531 @item set debug-file-directory @var{directories}
21532 Set the directories which @value{GDBN} searches for separate debugging
21533 information files to @var{directory}. Multiple path components can be set
21534 concatenating them by a path separator.
21535
21536 @kindex show debug-file-directory
21537 @item show debug-file-directory
21538 Show the directories @value{GDBN} searches for separate debugging
21539 information files.
21540
21541 @end table
21542
21543 @cindex @code{.gnu_debuglink} sections
21544 @cindex debug link sections
21545 A debug link is a special section of the executable file named
21546 @code{.gnu_debuglink}. The section must contain:
21547
21548 @itemize
21549 @item
21550 A filename, with any leading directory components removed, followed by
21551 a zero byte,
21552 @item
21553 zero to three bytes of padding, as needed to reach the next four-byte
21554 boundary within the section, and
21555 @item
21556 a four-byte CRC checksum, stored in the same endianness used for the
21557 executable file itself. The checksum is computed on the debugging
21558 information file's full contents by the function given below, passing
21559 zero as the @var{crc} argument.
21560 @end itemize
21561
21562 Any executable file format can carry a debug link, as long as it can
21563 contain a section named @code{.gnu_debuglink} with the contents
21564 described above.
21565
21566 @cindex @code{.note.gnu.build-id} sections
21567 @cindex build ID sections
21568 The build ID is a special section in the executable file (and in other
21569 ELF binary files that @value{GDBN} may consider). This section is
21570 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21571 It contains unique identification for the built files---the ID remains
21572 the same across multiple builds of the same build tree. The default
21573 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21574 content for the build ID string. The same section with an identical
21575 value is present in the original built binary with symbols, in its
21576 stripped variant, and in the separate debugging information file.
21577
21578 The debugging information file itself should be an ordinary
21579 executable, containing a full set of linker symbols, sections, and
21580 debugging information. The sections of the debugging information file
21581 should have the same names, addresses, and sizes as the original file,
21582 but they need not contain any data---much like a @code{.bss} section
21583 in an ordinary executable.
21584
21585 The @sc{gnu} binary utilities (Binutils) package includes the
21586 @samp{objcopy} utility that can produce
21587 the separated executable / debugging information file pairs using the
21588 following commands:
21589
21590 @smallexample
21591 @kbd{objcopy --only-keep-debug foo foo.debug}
21592 @kbd{strip -g foo}
21593 @end smallexample
21594
21595 @noindent
21596 These commands remove the debugging
21597 information from the executable file @file{foo} and place it in the file
21598 @file{foo.debug}. You can use the first, second or both methods to link the
21599 two files:
21600
21601 @itemize @bullet
21602 @item
21603 The debug link method needs the following additional command to also leave
21604 behind a debug link in @file{foo}:
21605
21606 @smallexample
21607 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21608 @end smallexample
21609
21610 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21611 a version of the @code{strip} command such that the command @kbd{strip foo -f
21612 foo.debug} has the same functionality as the two @code{objcopy} commands and
21613 the @code{ln -s} command above, together.
21614
21615 @item
21616 Build ID gets embedded into the main executable using @code{ld --build-id} or
21617 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21618 compatibility fixes for debug files separation are present in @sc{gnu} binary
21619 utilities (Binutils) package since version 2.18.
21620 @end itemize
21621
21622 @noindent
21623
21624 @cindex CRC algorithm definition
21625 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21626 IEEE 802.3 using the polynomial:
21627
21628 @c TexInfo requires naked braces for multi-digit exponents for Tex
21629 @c output, but this causes HTML output to barf. HTML has to be set using
21630 @c raw commands. So we end up having to specify this equation in 2
21631 @c different ways!
21632 @ifhtml
21633 @display
21634 @html
21635 <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>
21636 + <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
21637 @end html
21638 @end display
21639 @end ifhtml
21640 @ifnothtml
21641 @display
21642 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21643 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21644 @end display
21645 @end ifnothtml
21646
21647 The function is computed byte at a time, taking the least
21648 significant bit of each byte first. The initial pattern
21649 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21650 the final result is inverted to ensure trailing zeros also affect the
21651 CRC.
21652
21653 @emph{Note:} This is the same CRC polynomial as used in handling the
21654 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21655 However in the case of the Remote Serial Protocol, the CRC is computed
21656 @emph{most} significant bit first, and the result is not inverted, so
21657 trailing zeros have no effect on the CRC value.
21658
21659 To complete the description, we show below the code of the function
21660 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21661 initially supplied @code{crc} argument means that an initial call to
21662 this function passing in zero will start computing the CRC using
21663 @code{0xffffffff}.
21664
21665 @kindex gnu_debuglink_crc32
21666 @smallexample
21667 unsigned long
21668 gnu_debuglink_crc32 (unsigned long crc,
21669 unsigned char *buf, size_t len)
21670 @{
21671 static const unsigned long crc32_table[256] =
21672 @{
21673 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21674 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21675 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21676 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21677 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21678 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21679 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21680 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21681 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21682 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21683 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21684 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21685 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21686 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21687 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21688 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21689 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21690 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21691 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21692 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21693 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21694 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21695 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21696 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21697 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21698 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21699 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21700 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21701 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21702 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21703 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21704 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21705 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21706 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21707 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21708 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21709 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21710 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21711 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21712 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21713 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21714 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21715 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21716 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21717 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21718 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21719 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21720 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21721 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21722 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21723 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21724 0x2d02ef8d
21725 @};
21726 unsigned char *end;
21727
21728 crc = ~crc & 0xffffffff;
21729 for (end = buf + len; buf < end; ++buf)
21730 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21731 return ~crc & 0xffffffff;
21732 @}
21733 @end smallexample
21734
21735 @noindent
21736 This computation does not apply to the ``build ID'' method.
21737
21738 @node MiniDebugInfo
21739 @section Debugging information in a special section
21740 @cindex separate debug sections
21741 @cindex @samp{.gnu_debugdata} section
21742
21743 Some systems ship pre-built executables and libraries that have a
21744 special @samp{.gnu_debugdata} section. This feature is called
21745 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21746 is used to supply extra symbols for backtraces.
21747
21748 The intent of this section is to provide extra minimal debugging
21749 information for use in simple backtraces. It is not intended to be a
21750 replacement for full separate debugging information (@pxref{Separate
21751 Debug Files}). The example below shows the intended use; however,
21752 @value{GDBN} does not currently put restrictions on what sort of
21753 debugging information might be included in the section.
21754
21755 @value{GDBN} has support for this extension. If the section exists,
21756 then it is used provided that no other source of debugging information
21757 can be found, and that @value{GDBN} was configured with LZMA support.
21758
21759 This section can be easily created using @command{objcopy} and other
21760 standard utilities:
21761
21762 @smallexample
21763 # Extract the dynamic symbols from the main binary, there is no need
21764 # to also have these in the normal symbol table.
21765 nm -D @var{binary} --format=posix --defined-only \
21766 | awk '@{ print $1 @}' | sort > dynsyms
21767
21768 # Extract all the text (i.e. function) symbols from the debuginfo.
21769 # (Note that we actually also accept "D" symbols, for the benefit
21770 # of platforms like PowerPC64 that use function descriptors.)
21771 nm @var{binary} --format=posix --defined-only \
21772 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21773 | sort > funcsyms
21774
21775 # Keep all the function symbols not already in the dynamic symbol
21776 # table.
21777 comm -13 dynsyms funcsyms > keep_symbols
21778
21779 # Separate full debug info into debug binary.
21780 objcopy --only-keep-debug @var{binary} debug
21781
21782 # Copy the full debuginfo, keeping only a minimal set of symbols and
21783 # removing some unnecessary sections.
21784 objcopy -S --remove-section .gdb_index --remove-section .comment \
21785 --keep-symbols=keep_symbols debug mini_debuginfo
21786
21787 # Drop the full debug info from the original binary.
21788 strip --strip-all -R .comment @var{binary}
21789
21790 # Inject the compressed data into the .gnu_debugdata section of the
21791 # original binary.
21792 xz mini_debuginfo
21793 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21794 @end smallexample
21795
21796 @node Index Files
21797 @section Index Files Speed Up @value{GDBN}
21798 @cindex index files
21799 @cindex @samp{.gdb_index} section
21800
21801 When @value{GDBN} finds a symbol file, it scans the symbols in the
21802 file in order to construct an internal symbol table. This lets most
21803 @value{GDBN} operations work quickly---at the cost of a delay early
21804 on. For large programs, this delay can be quite lengthy, so
21805 @value{GDBN} provides a way to build an index, which speeds up
21806 startup.
21807
21808 For convenience, @value{GDBN} comes with a program,
21809 @command{gdb-add-index}, which can be used to add the index to a
21810 symbol file. It takes the symbol file as its only argument:
21811
21812 @smallexample
21813 $ gdb-add-index symfile
21814 @end smallexample
21815
21816 @xref{gdb-add-index}.
21817
21818 It is also possible to do the work manually. Here is what
21819 @command{gdb-add-index} does behind the curtains.
21820
21821 The index is stored as a section in the symbol file. @value{GDBN} can
21822 write the index to a file, then you can put it into the symbol file
21823 using @command{objcopy}.
21824
21825 To create an index file, use the @code{save gdb-index} command:
21826
21827 @table @code
21828 @item save gdb-index [-dwarf-5] @var{directory}
21829 @kindex save gdb-index
21830 Create index files for all symbol files currently known by
21831 @value{GDBN}. For each known @var{symbol-file}, this command by
21832 default creates it produces a single file
21833 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21834 the @option{-dwarf-5} option, it produces 2 files:
21835 @file{@var{symbol-file}.debug_names} and
21836 @file{@var{symbol-file}.debug_str}. The files are created in the
21837 given @var{directory}.
21838 @end table
21839
21840 Once you have created an index file you can merge it into your symbol
21841 file, here named @file{symfile}, using @command{objcopy}:
21842
21843 @smallexample
21844 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21845 --set-section-flags .gdb_index=readonly symfile symfile
21846 @end smallexample
21847
21848 Or for @code{-dwarf-5}:
21849
21850 @smallexample
21851 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21852 $ cat symfile.debug_str >>symfile.debug_str.new
21853 $ objcopy --add-section .debug_names=symfile.gdb-index \
21854 --set-section-flags .debug_names=readonly \
21855 --update-section .debug_str=symfile.debug_str.new symfile symfile
21856 @end smallexample
21857
21858 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21859 sections that have been deprecated. Usually they are deprecated because
21860 they are missing a new feature or have performance issues.
21861 To tell @value{GDBN} to use a deprecated index section anyway
21862 specify @code{set use-deprecated-index-sections on}.
21863 The default is @code{off}.
21864 This can speed up startup, but may result in some functionality being lost.
21865 @xref{Index Section Format}.
21866
21867 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21868 must be done before gdb reads the file. The following will not work:
21869
21870 @smallexample
21871 $ gdb -ex "set use-deprecated-index-sections on" <program>
21872 @end smallexample
21873
21874 Instead you must do, for example,
21875
21876 @smallexample
21877 $ gdb -iex "set use-deprecated-index-sections on" <program>
21878 @end smallexample
21879
21880 Indices only work when using DWARF debugging information, not stabs.
21881
21882 @subsection Automatic symbol index cache
21883
21884 @cindex automatic symbol index cache
21885 It is possible for @value{GDBN} to automatically save a copy of this index in a
21886 cache on disk and retrieve it from there when loading the same binary in the
21887 future. This feature can be turned on with @kbd{set index-cache enabled on}.
21888 The following commands can be used to tweak the behavior of the index cache.
21889
21890 @table @code
21891
21892 @kindex set index-cache
21893 @item set index-cache enabled on
21894 @itemx set index-cache enabled off
21895 Enable or disable the use of the symbol index cache.
21896
21897 @item set index-cache directory @var{directory}
21898 @kindex show index-cache
21899 @itemx show index-cache directory
21900 Set/show the directory where index files will be saved.
21901
21902 The default value for this directory depends on the host platform. On
21903 most systems, the index is cached in the @file{gdb} subdirectory of
21904 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21905 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21906 of your home directory. However, on some systems, the default may
21907 differ according to local convention.
21908
21909 There is no limit on the disk space used by index cache. It is perfectly safe
21910 to delete the content of that directory to free up disk space.
21911
21912 @item show index-cache stats
21913 Print the number of cache hits and misses since the launch of @value{GDBN}.
21914
21915 @end table
21916
21917 @node Symbol Errors
21918 @section Errors Reading Symbol Files
21919
21920 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21921 such as symbol types it does not recognize, or known bugs in compiler
21922 output. By default, @value{GDBN} does not notify you of such problems, since
21923 they are relatively common and primarily of interest to people
21924 debugging compilers. If you are interested in seeing information
21925 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21926 only one message about each such type of problem, no matter how many
21927 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21928 to see how many times the problems occur, with the @code{set
21929 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21930 Messages}).
21931
21932 The messages currently printed, and their meanings, include:
21933
21934 @table @code
21935 @item inner block not inside outer block in @var{symbol}
21936
21937 The symbol information shows where symbol scopes begin and end
21938 (such as at the start of a function or a block of statements). This
21939 error indicates that an inner scope block is not fully contained
21940 in its outer scope blocks.
21941
21942 @value{GDBN} circumvents the problem by treating the inner block as if it had
21943 the same scope as the outer block. In the error message, @var{symbol}
21944 may be shown as ``@code{(don't know)}'' if the outer block is not a
21945 function.
21946
21947 @item block at @var{address} out of order
21948
21949 The symbol information for symbol scope blocks should occur in
21950 order of increasing addresses. This error indicates that it does not
21951 do so.
21952
21953 @value{GDBN} does not circumvent this problem, and has trouble
21954 locating symbols in the source file whose symbols it is reading. (You
21955 can often determine what source file is affected by specifying
21956 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21957 Messages}.)
21958
21959 @item bad block start address patched
21960
21961 The symbol information for a symbol scope block has a start address
21962 smaller than the address of the preceding source line. This is known
21963 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21964
21965 @value{GDBN} circumvents the problem by treating the symbol scope block as
21966 starting on the previous source line.
21967
21968 @item bad string table offset in symbol @var{n}
21969
21970 @cindex foo
21971 Symbol number @var{n} contains a pointer into the string table which is
21972 larger than the size of the string table.
21973
21974 @value{GDBN} circumvents the problem by considering the symbol to have the
21975 name @code{foo}, which may cause other problems if many symbols end up
21976 with this name.
21977
21978 @item unknown symbol type @code{0x@var{nn}}
21979
21980 The symbol information contains new data types that @value{GDBN} does
21981 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21982 uncomprehended information, in hexadecimal.
21983
21984 @value{GDBN} circumvents the error by ignoring this symbol information.
21985 This usually allows you to debug your program, though certain symbols
21986 are not accessible. If you encounter such a problem and feel like
21987 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21988 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21989 and examine @code{*bufp} to see the symbol.
21990
21991 @item stub type has NULL name
21992
21993 @value{GDBN} could not find the full definition for a struct or class.
21994
21995 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21996 The symbol information for a C@t{++} member function is missing some
21997 information that recent versions of the compiler should have output for
21998 it.
21999
22000 @item info mismatch between compiler and debugger
22001
22002 @value{GDBN} could not parse a type specification output by the compiler.
22003
22004 @end table
22005
22006 @node Data Files
22007 @section GDB Data Files
22008
22009 @cindex prefix for data files
22010 @value{GDBN} will sometimes read an auxiliary data file. These files
22011 are kept in a directory known as the @dfn{data directory}.
22012
22013 You can set the data directory's name, and view the name @value{GDBN}
22014 is currently using.
22015
22016 @table @code
22017 @kindex set data-directory
22018 @item set data-directory @var{directory}
22019 Set the directory which @value{GDBN} searches for auxiliary data files
22020 to @var{directory}.
22021
22022 @kindex show data-directory
22023 @item show data-directory
22024 Show the directory @value{GDBN} searches for auxiliary data files.
22025 @end table
22026
22027 @cindex default data directory
22028 @cindex @samp{--with-gdb-datadir}
22029 You can set the default data directory by using the configure-time
22030 @samp{--with-gdb-datadir} option. If the data directory is inside
22031 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
22032 @samp{--exec-prefix}), then the default data directory will be updated
22033 automatically if the installed @value{GDBN} is moved to a new
22034 location.
22035
22036 The data directory may also be specified with the
22037 @code{--data-directory} command line option.
22038 @xref{Mode Options}.
22039
22040 @node Targets
22041 @chapter Specifying a Debugging Target
22042
22043 @cindex debugging target
22044 A @dfn{target} is the execution environment occupied by your program.
22045
22046 Often, @value{GDBN} runs in the same host environment as your program;
22047 in that case, the debugging target is specified as a side effect when
22048 you use the @code{file} or @code{core} commands. When you need more
22049 flexibility---for example, running @value{GDBN} on a physically separate
22050 host, or controlling a standalone system over a serial port or a
22051 realtime system over a TCP/IP connection---you can use the @code{target}
22052 command to specify one of the target types configured for @value{GDBN}
22053 (@pxref{Target Commands, ,Commands for Managing Targets}).
22054
22055 @cindex target architecture
22056 It is possible to build @value{GDBN} for several different @dfn{target
22057 architectures}. When @value{GDBN} is built like that, you can choose
22058 one of the available architectures with the @kbd{set architecture}
22059 command.
22060
22061 @table @code
22062 @kindex set architecture
22063 @kindex show architecture
22064 @item set architecture @var{arch}
22065 This command sets the current target architecture to @var{arch}. The
22066 value of @var{arch} can be @code{"auto"}, in addition to one of the
22067 supported architectures.
22068
22069 @item show architecture
22070 Show the current target architecture.
22071
22072 @item set processor
22073 @itemx processor
22074 @kindex set processor
22075 @kindex show processor
22076 These are alias commands for, respectively, @code{set architecture}
22077 and @code{show architecture}.
22078 @end table
22079
22080 @menu
22081 * Active Targets:: Active targets
22082 * Target Commands:: Commands for managing targets
22083 * Byte Order:: Choosing target byte order
22084 @end menu
22085
22086 @node Active Targets
22087 @section Active Targets
22088
22089 @cindex stacking targets
22090 @cindex active targets
22091 @cindex multiple targets
22092
22093 There are multiple classes of targets such as: processes, executable files or
22094 recording sessions. Core files belong to the process class, making core file
22095 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
22096 on multiple active targets, one in each class. This allows you to (for
22097 example) start a process and inspect its activity, while still having access to
22098 the executable file after the process finishes. Or if you start process
22099 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
22100 presented a virtual layer of the recording target, while the process target
22101 remains stopped at the chronologically last point of the process execution.
22102
22103 Use the @code{core-file} and @code{exec-file} commands to select a new core
22104 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
22105 specify as a target a process that is already running, use the @code{attach}
22106 command (@pxref{Attach, ,Debugging an Already-running Process}).
22107
22108 @node Target Commands
22109 @section Commands for Managing Targets
22110
22111 @table @code
22112 @item target @var{type} @var{parameters}
22113 Connects the @value{GDBN} host environment to a target machine or
22114 process. A target is typically a protocol for talking to debugging
22115 facilities. You use the argument @var{type} to specify the type or
22116 protocol of the target machine.
22117
22118 Further @var{parameters} are interpreted by the target protocol, but
22119 typically include things like device names or host names to connect
22120 with, process numbers, and baud rates.
22121
22122 The @code{target} command does not repeat if you press @key{RET} again
22123 after executing the command.
22124
22125 @kindex help target
22126 @item help target
22127 Displays the names of all targets available. To display targets
22128 currently selected, use either @code{info target} or @code{info files}
22129 (@pxref{Files, ,Commands to Specify Files}).
22130
22131 @item help target @var{name}
22132 Describe a particular target, including any parameters necessary to
22133 select it.
22134
22135 @kindex set gnutarget
22136 @item set gnutarget @var{args}
22137 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
22138 knows whether it is reading an @dfn{executable},
22139 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
22140 with the @code{set gnutarget} command. Unlike most @code{target} commands,
22141 with @code{gnutarget} the @code{target} refers to a program, not a machine.
22142
22143 @quotation
22144 @emph{Warning:} To specify a file format with @code{set gnutarget},
22145 you must know the actual BFD name.
22146 @end quotation
22147
22148 @noindent
22149 @xref{Files, , Commands to Specify Files}.
22150
22151 @kindex show gnutarget
22152 @item show gnutarget
22153 Use the @code{show gnutarget} command to display what file format
22154 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
22155 @value{GDBN} will determine the file format for each file automatically,
22156 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
22157 @end table
22158
22159 @cindex common targets
22160 Here are some common targets (available, or not, depending on the GDB
22161 configuration):
22162
22163 @table @code
22164 @kindex target
22165 @item target exec @var{program}
22166 @cindex executable file target
22167 An executable file. @samp{target exec @var{program}} is the same as
22168 @samp{exec-file @var{program}}.
22169
22170 @item target core @var{filename}
22171 @cindex core dump file target
22172 A core dump file. @samp{target core @var{filename}} is the same as
22173 @samp{core-file @var{filename}}.
22174
22175 @item target remote @var{medium}
22176 @cindex remote target
22177 A remote system connected to @value{GDBN} via a serial line or network
22178 connection. This command tells @value{GDBN} to use its own remote
22179 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
22180
22181 For example, if you have a board connected to @file{/dev/ttya} on the
22182 machine running @value{GDBN}, you could say:
22183
22184 @smallexample
22185 target remote /dev/ttya
22186 @end smallexample
22187
22188 @code{target remote} supports the @code{load} command. This is only
22189 useful if you have some other way of getting the stub to the target
22190 system, and you can put it somewhere in memory where it won't get
22191 clobbered by the download.
22192
22193 @item target sim @r{[}@var{simargs}@r{]} @dots{}
22194 @cindex built-in simulator target
22195 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
22196 In general,
22197 @smallexample
22198 target sim
22199 load
22200 run
22201 @end smallexample
22202 @noindent
22203 works; however, you cannot assume that a specific memory map, device
22204 drivers, or even basic I/O is available, although some simulators do
22205 provide these. For info about any processor-specific simulator details,
22206 see the appropriate section in @ref{Embedded Processors, ,Embedded
22207 Processors}.
22208
22209 @item target native
22210 @cindex native target
22211 Setup for local/native process debugging. Useful to make the
22212 @code{run} command spawn native processes (likewise @code{attach},
22213 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
22214 (@pxref{set auto-connect-native-target}).
22215
22216 @end table
22217
22218 Different targets are available on different configurations of @value{GDBN};
22219 your configuration may have more or fewer targets.
22220
22221 Many remote targets require you to download the executable's code once
22222 you've successfully established a connection. You may wish to control
22223 various aspects of this process.
22224
22225 @table @code
22226
22227 @item set hash
22228 @kindex set hash@r{, for remote monitors}
22229 @cindex hash mark while downloading
22230 This command controls whether a hash mark @samp{#} is displayed while
22231 downloading a file to the remote monitor. If on, a hash mark is
22232 displayed after each S-record is successfully downloaded to the
22233 monitor.
22234
22235 @item show hash
22236 @kindex show hash@r{, for remote monitors}
22237 Show the current status of displaying the hash mark.
22238
22239 @item set debug monitor
22240 @kindex set debug monitor
22241 @cindex display remote monitor communications
22242 Enable or disable display of communications messages between
22243 @value{GDBN} and the remote monitor.
22244
22245 @item show debug monitor
22246 @kindex show debug monitor
22247 Show the current status of displaying communications between
22248 @value{GDBN} and the remote monitor.
22249 @end table
22250
22251 @table @code
22252
22253 @kindex load @var{filename} @var{offset}
22254 @item load @var{filename} @var{offset}
22255 @anchor{load}
22256 Depending on what remote debugging facilities are configured into
22257 @value{GDBN}, the @code{load} command may be available. Where it exists, it
22258 is meant to make @var{filename} (an executable) available for debugging
22259 on the remote system---by downloading, or dynamic linking, for example.
22260 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
22261 the @code{add-symbol-file} command.
22262
22263 If your @value{GDBN} does not have a @code{load} command, attempting to
22264 execute it gets the error message ``@code{You can't do that when your
22265 target is @dots{}}''
22266
22267 The file is loaded at whatever address is specified in the executable.
22268 For some object file formats, you can specify the load address when you
22269 link the program; for other formats, like a.out, the object file format
22270 specifies a fixed address.
22271 @c FIXME! This would be a good place for an xref to the GNU linker doc.
22272
22273 It is also possible to tell @value{GDBN} to load the executable file at a
22274 specific offset described by the optional argument @var{offset}. When
22275 @var{offset} is provided, @var{filename} must also be provided.
22276
22277 Depending on the remote side capabilities, @value{GDBN} may be able to
22278 load programs into flash memory.
22279
22280 @code{load} does not repeat if you press @key{RET} again after using it.
22281 @end table
22282
22283 @table @code
22284
22285 @kindex flash-erase
22286 @item flash-erase
22287 @anchor{flash-erase}
22288
22289 Erases all known flash memory regions on the target.
22290
22291 @end table
22292
22293 @node Byte Order
22294 @section Choosing Target Byte Order
22295
22296 @cindex choosing target byte order
22297 @cindex target byte order
22298
22299 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
22300 offer the ability to run either big-endian or little-endian byte
22301 orders. Usually the executable or symbol will include a bit to
22302 designate the endian-ness, and you will not need to worry about
22303 which to use. However, you may still find it useful to adjust
22304 @value{GDBN}'s idea of processor endian-ness manually.
22305
22306 @table @code
22307 @kindex set endian
22308 @item set endian big
22309 Instruct @value{GDBN} to assume the target is big-endian.
22310
22311 @item set endian little
22312 Instruct @value{GDBN} to assume the target is little-endian.
22313
22314 @item set endian auto
22315 Instruct @value{GDBN} to use the byte order associated with the
22316 executable.
22317
22318 @item show endian
22319 Display @value{GDBN}'s current idea of the target byte order.
22320
22321 @end table
22322
22323 If the @code{set endian auto} mode is in effect and no executable has
22324 been selected, then the endianness used is the last one chosen either
22325 by one of the @code{set endian big} and @code{set endian little}
22326 commands or by inferring from the last executable used. If no
22327 endianness has been previously chosen, then the default for this mode
22328 is inferred from the target @value{GDBN} has been built for, and is
22329 @code{little} if the name of the target CPU has an @code{el} suffix
22330 and @code{big} otherwise.
22331
22332 Note that these commands merely adjust interpretation of symbolic
22333 data on the host, and that they have absolutely no effect on the
22334 target system.
22335
22336
22337 @node Remote Debugging
22338 @chapter Debugging Remote Programs
22339 @cindex remote debugging
22340
22341 If you are trying to debug a program running on a machine that cannot run
22342 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22343 For example, you might use remote debugging on an operating system kernel,
22344 or on a small system which does not have a general purpose operating system
22345 powerful enough to run a full-featured debugger.
22346
22347 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22348 to make this work with particular debugging targets. In addition,
22349 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22350 but not specific to any particular target system) which you can use if you
22351 write the remote stubs---the code that runs on the remote system to
22352 communicate with @value{GDBN}.
22353
22354 Other remote targets may be available in your
22355 configuration of @value{GDBN}; use @code{help target} to list them.
22356
22357 @menu
22358 * Connecting:: Connecting to a remote target
22359 * File Transfer:: Sending files to a remote system
22360 * Server:: Using the gdbserver program
22361 * Remote Configuration:: Remote configuration
22362 * Remote Stub:: Implementing a remote stub
22363 @end menu
22364
22365 @node Connecting
22366 @section Connecting to a Remote Target
22367 @cindex remote debugging, connecting
22368 @cindex @code{gdbserver}, connecting
22369 @cindex remote debugging, types of connections
22370 @cindex @code{gdbserver}, types of connections
22371 @cindex @code{gdbserver}, @code{target remote} mode
22372 @cindex @code{gdbserver}, @code{target extended-remote} mode
22373
22374 This section describes how to connect to a remote target, including the
22375 types of connections and their differences, how to set up executable and
22376 symbol files on the host and target, and the commands used for
22377 connecting to and disconnecting from the remote target.
22378
22379 @subsection Types of Remote Connections
22380
22381 @value{GDBN} supports two types of remote connections, @code{target remote}
22382 mode and @code{target extended-remote} mode. Note that many remote targets
22383 support only @code{target remote} mode. There are several major
22384 differences between the two types of connections, enumerated here:
22385
22386 @table @asis
22387
22388 @cindex remote debugging, detach and program exit
22389 @item Result of detach or program exit
22390 @strong{With target remote mode:} When the debugged program exits or you
22391 detach from it, @value{GDBN} disconnects from the target. When using
22392 @code{gdbserver}, @code{gdbserver} will exit.
22393
22394 @strong{With target extended-remote mode:} When the debugged program exits or
22395 you detach from it, @value{GDBN} remains connected to the target, even
22396 though no program is running. You can rerun the program, attach to a
22397 running program, or use @code{monitor} commands specific to the target.
22398
22399 When using @code{gdbserver} in this case, it does not exit unless it was
22400 invoked using the @option{--once} option. If the @option{--once} option
22401 was not used, you can ask @code{gdbserver} to exit using the
22402 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22403
22404 @item Specifying the program to debug
22405 For both connection types you use the @code{file} command to specify the
22406 program on the host system. If you are using @code{gdbserver} there are
22407 some differences in how to specify the location of the program on the
22408 target.
22409
22410 @strong{With target remote mode:} You must either specify the program to debug
22411 on the @code{gdbserver} command line or use the @option{--attach} option
22412 (@pxref{Attaching to a program,,Attaching to a Running Program}).
22413
22414 @cindex @option{--multi}, @code{gdbserver} option
22415 @strong{With target extended-remote mode:} You may specify the program to debug
22416 on the @code{gdbserver} command line, or you can load the program or attach
22417 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22418
22419 @anchor{--multi Option in Types of Remote Connnections}
22420 You can start @code{gdbserver} without supplying an initial command to run
22421 or process ID to attach. To do this, use the @option{--multi} command line
22422 option. Then you can connect using @code{target extended-remote} and start
22423 the program you want to debug (see below for details on using the
22424 @code{run} command in this scenario). Note that the conditions under which
22425 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
22426 (@code{target remote} or @code{target extended-remote}). The
22427 @option{--multi} option to @code{gdbserver} has no influence on that.
22428
22429 @item The @code{run} command
22430 @strong{With target remote mode:} The @code{run} command is not
22431 supported. Once a connection has been established, you can use all
22432 the usual @value{GDBN} commands to examine and change data. The
22433 remote program is already running, so you can use commands like
22434 @kbd{step} and @kbd{continue}.
22435
22436 @strong{With target extended-remote mode:} The @code{run} command is
22437 supported. The @code{run} command uses the value set by
22438 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
22439 the program to run. Command line arguments are supported, except for
22440 wildcard expansion and I/O redirection (@pxref{Arguments}).
22441
22442 If you specify the program to debug on the command line, then the
22443 @code{run} command is not required to start execution, and you can
22444 resume using commands like @kbd{step} and @kbd{continue} as with
22445 @code{target remote} mode.
22446
22447 @anchor{Attaching in Types of Remote Connections}
22448 @item Attaching
22449 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22450 not supported. To attach to a running program using @code{gdbserver}, you
22451 must use the @option{--attach} option (@pxref{Running gdbserver}).
22452
22453 @strong{With target extended-remote mode:} To attach to a running program,
22454 you may use the @code{attach} command after the connection has been
22455 established. If you are using @code{gdbserver}, you may also invoke
22456 @code{gdbserver} using the @option{--attach} option
22457 (@pxref{Running gdbserver}).
22458
22459 Some remote targets allow @value{GDBN} to determine the executable file running
22460 in the process the debugger is attaching to. In such a case, @value{GDBN}
22461 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22462 between the executable file name running in the process and the name of the
22463 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22464
22465 @end table
22466
22467 @anchor{Host and target files}
22468 @subsection Host and Target Files
22469 @cindex remote debugging, symbol files
22470 @cindex symbol files, remote debugging
22471
22472 @value{GDBN}, running on the host, needs access to symbol and debugging
22473 information for your program running on the target. This requires
22474 access to an unstripped copy of your program, and possibly any associated
22475 symbol files. Note that this section applies equally to both @code{target
22476 remote} mode and @code{target extended-remote} mode.
22477
22478 Some remote targets (@pxref{qXfer executable filename read}, and
22479 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22480 the same connection used to communicate with @value{GDBN}. With such a
22481 target, if the remote program is unstripped, the only command you need is
22482 @code{target remote} (or @code{target extended-remote}).
22483
22484 If the remote program is stripped, or the target does not support remote
22485 program file access, start up @value{GDBN} using the name of the local
22486 unstripped copy of your program as the first argument, or use the
22487 @code{file} command. Use @code{set sysroot} to specify the location (on
22488 the host) of target libraries (unless your @value{GDBN} was compiled with
22489 the correct sysroot using @code{--with-sysroot}). Alternatively, you
22490 may use @code{set solib-search-path} to specify how @value{GDBN} locates
22491 target libraries.
22492
22493 The symbol file and target libraries must exactly match the executable
22494 and libraries on the target, with one exception: the files on the host
22495 system should not be stripped, even if the files on the target system
22496 are. Mismatched or missing files will lead to confusing results
22497 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22498 files may also prevent @code{gdbserver} from debugging multi-threaded
22499 programs.
22500
22501 @subsection Remote Connection Commands
22502 @cindex remote connection commands
22503 @value{GDBN} can communicate with the target over a serial line, a
22504 local Unix domain socket, or
22505 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22506 each case, @value{GDBN} uses the same protocol for debugging your
22507 program; only the medium carrying the debugging packets varies. The
22508 @code{target remote} and @code{target extended-remote} commands
22509 establish a connection to the target. Both commands accept the same
22510 arguments, which indicate the medium to use:
22511
22512 @table @code
22513
22514 @item target remote @var{serial-device}
22515 @itemx target extended-remote @var{serial-device}
22516 @cindex serial line, @code{target remote}
22517 Use @var{serial-device} to communicate with the target. For example,
22518 to use a serial line connected to the device named @file{/dev/ttyb}:
22519
22520 @smallexample
22521 target remote /dev/ttyb
22522 @end smallexample
22523
22524 If you're using a serial line, you may want to give @value{GDBN} the
22525 @samp{--baud} option, or use the @code{set serial baud} command
22526 (@pxref{Remote Configuration, set serial baud}) before the
22527 @code{target} command.
22528
22529 @item target remote @var{local-socket}
22530 @itemx target extended-remote @var{local-socket}
22531 @cindex local socket, @code{target remote}
22532 @cindex Unix domain socket
22533 Use @var{local-socket} to communicate with the target. For example,
22534 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22535
22536 @smallexample
22537 target remote /tmp/gdb-socket0
22538 @end smallexample
22539
22540 Note that this command has the same form as the command to connect
22541 to a serial line. @value{GDBN} will automatically determine which
22542 kind of file you have specified and will make the appropriate kind
22543 of connection.
22544 This feature is not available if the host system does not support
22545 Unix domain sockets.
22546
22547 @item target remote @code{@var{host}:@var{port}}
22548 @itemx target remote @code{[@var{host}]:@var{port}}
22549 @itemx target remote @code{tcp:@var{host}:@var{port}}
22550 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22551 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22552 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22553 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22554 @itemx target extended-remote @code{@var{host}:@var{port}}
22555 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22556 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22557 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22558 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22559 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22560 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22561 @cindex @acronym{TCP} port, @code{target remote}
22562 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22563 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22564 address, or a numeric @acronym{IPv6} address (with or without the
22565 square brackets to separate the address from the port); @var{port}
22566 must be a decimal number. The @var{host} could be the target machine
22567 itself, if it is directly connected to the net, or it might be a
22568 terminal server which in turn has a serial line to the target.
22569
22570 For example, to connect to port 2828 on a terminal server named
22571 @code{manyfarms}:
22572
22573 @smallexample
22574 target remote manyfarms:2828
22575 @end smallexample
22576
22577 To connect to port 2828 on a terminal server whose address is
22578 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22579 square bracket syntax:
22580
22581 @smallexample
22582 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22583 @end smallexample
22584
22585 @noindent
22586 or explicitly specify the @acronym{IPv6} protocol:
22587
22588 @smallexample
22589 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22590 @end smallexample
22591
22592 This last example may be confusing to the reader, because there is no
22593 visible separation between the hostname and the port number.
22594 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22595 using square brackets for clarity. However, it is important to
22596 mention that for @value{GDBN} there is no ambiguity: the number after
22597 the last colon is considered to be the port number.
22598
22599 If your remote target is actually running on the same machine as your
22600 debugger session (e.g.@: a simulator for your target running on the
22601 same host), you can omit the hostname. For example, to connect to
22602 port 1234 on your local machine:
22603
22604 @smallexample
22605 target remote :1234
22606 @end smallexample
22607 @noindent
22608
22609 Note that the colon is still required here.
22610
22611 @item target remote @code{udp:@var{host}:@var{port}}
22612 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22613 @itemx target remote @code{udp4:@var{host}:@var{port}}
22614 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22615 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22616 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22617 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22618 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22619 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22620 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22621 @cindex @acronym{UDP} port, @code{target remote}
22622 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22623 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22624
22625 @smallexample
22626 target remote udp:manyfarms:2828
22627 @end smallexample
22628
22629 When using a @acronym{UDP} connection for remote debugging, you should
22630 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22631 can silently drop packets on busy or unreliable networks, which will
22632 cause havoc with your debugging session.
22633
22634 @item target remote | @var{command}
22635 @itemx target extended-remote | @var{command}
22636 @cindex pipe, @code{target remote} to
22637 Run @var{command} in the background and communicate with it using a
22638 pipe. The @var{command} is a shell command, to be parsed and expanded
22639 by the system's command shell, @code{/bin/sh}; it should expect remote
22640 protocol packets on its standard input, and send replies on its
22641 standard output. You could use this to run a stand-alone simulator
22642 that speaks the remote debugging protocol, to make net connections
22643 using programs like @code{ssh}, or for other similar tricks.
22644
22645 If @var{command} closes its standard output (perhaps by exiting),
22646 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22647 program has already exited, this will have no effect.)
22648
22649 @end table
22650
22651 @cindex interrupting remote programs
22652 @cindex remote programs, interrupting
22653 Whenever @value{GDBN} is waiting for the remote program, if you type the
22654 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22655 program. This may or may not succeed, depending in part on the hardware
22656 and the serial drivers the remote system uses. If you type the
22657 interrupt character once again, @value{GDBN} displays this prompt:
22658
22659 @smallexample
22660 Interrupted while waiting for the program.
22661 Give up (and stop debugging it)? (y or n)
22662 @end smallexample
22663
22664 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22665 the remote debugging session. (If you decide you want to try again later,
22666 you can use @kbd{target remote} again to connect once more.) If you type
22667 @kbd{n}, @value{GDBN} goes back to waiting.
22668
22669 In @code{target extended-remote} mode, typing @kbd{n} will leave
22670 @value{GDBN} connected to the target.
22671
22672 @table @code
22673 @kindex detach (remote)
22674 @item detach
22675 When you have finished debugging the remote program, you can use the
22676 @code{detach} command to release it from @value{GDBN} control.
22677 Detaching from the target normally resumes its execution, but the results
22678 will depend on your particular remote stub. After the @code{detach}
22679 command in @code{target remote} mode, @value{GDBN} is free to connect to
22680 another target. In @code{target extended-remote} mode, @value{GDBN} is
22681 still connected to the target.
22682
22683 @kindex disconnect
22684 @item disconnect
22685 The @code{disconnect} command closes the connection to the target, and
22686 the target is generally not resumed. It will wait for @value{GDBN}
22687 (this instance or another one) to connect and continue debugging. After
22688 the @code{disconnect} command, @value{GDBN} is again free to connect to
22689 another target.
22690
22691 @cindex send command to remote monitor
22692 @cindex extend @value{GDBN} for remote targets
22693 @cindex add new commands for external monitor
22694 @kindex monitor
22695 @item monitor @var{cmd}
22696 This command allows you to send arbitrary commands directly to the
22697 remote monitor. Since @value{GDBN} doesn't care about the commands it
22698 sends like this, this command is the way to extend @value{GDBN}---you
22699 can add new commands that only the external monitor will understand
22700 and implement.
22701 @end table
22702
22703 @node File Transfer
22704 @section Sending files to a remote system
22705 @cindex remote target, file transfer
22706 @cindex file transfer
22707 @cindex sending files to remote systems
22708
22709 Some remote targets offer the ability to transfer files over the same
22710 connection used to communicate with @value{GDBN}. This is convenient
22711 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22712 running @code{gdbserver} over a network interface. For other targets,
22713 e.g.@: embedded devices with only a single serial port, this may be
22714 the only way to upload or download files.
22715
22716 Not all remote targets support these commands.
22717
22718 @table @code
22719 @kindex remote put
22720 @item remote put @var{hostfile} @var{targetfile}
22721 Copy file @var{hostfile} from the host system (the machine running
22722 @value{GDBN}) to @var{targetfile} on the target system.
22723
22724 @kindex remote get
22725 @item remote get @var{targetfile} @var{hostfile}
22726 Copy file @var{targetfile} from the target system to @var{hostfile}
22727 on the host system.
22728
22729 @kindex remote delete
22730 @item remote delete @var{targetfile}
22731 Delete @var{targetfile} from the target system.
22732
22733 @end table
22734
22735 @node Server
22736 @section Using the @code{gdbserver} Program
22737
22738 @kindex gdbserver
22739 @cindex remote connection without stubs
22740 @code{gdbserver} is a control program for Unix-like systems, which
22741 allows you to connect your program with a remote @value{GDBN} via
22742 @code{target remote} or @code{target extended-remote}---but without
22743 linking in the usual debugging stub.
22744
22745 @code{gdbserver} is not a complete replacement for the debugging stubs,
22746 because it requires essentially the same operating-system facilities
22747 that @value{GDBN} itself does. In fact, a system that can run
22748 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22749 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22750 because it is a much smaller program than @value{GDBN} itself. It is
22751 also easier to port than all of @value{GDBN}, so you may be able to get
22752 started more quickly on a new system by using @code{gdbserver}.
22753 Finally, if you develop code for real-time systems, you may find that
22754 the tradeoffs involved in real-time operation make it more convenient to
22755 do as much development work as possible on another system, for example
22756 by cross-compiling. You can use @code{gdbserver} to make a similar
22757 choice for debugging.
22758
22759 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22760 or a TCP connection, using the standard @value{GDBN} remote serial
22761 protocol.
22762
22763 @quotation
22764 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22765 Do not run @code{gdbserver} connected to any public network; a
22766 @value{GDBN} connection to @code{gdbserver} provides access to the
22767 target system with the same privileges as the user running
22768 @code{gdbserver}.
22769 @end quotation
22770
22771 @anchor{Running gdbserver}
22772 @subsection Running @code{gdbserver}
22773 @cindex arguments, to @code{gdbserver}
22774 @cindex @code{gdbserver}, command-line arguments
22775
22776 Run @code{gdbserver} on the target system. You need a copy of the
22777 program you want to debug, including any libraries it requires.
22778 @code{gdbserver} does not need your program's symbol table, so you can
22779 strip the program if necessary to save space. @value{GDBN} on the host
22780 system does all the symbol handling.
22781
22782 To use the server, you must tell it how to communicate with @value{GDBN};
22783 the name of your program; and the arguments for your program. The usual
22784 syntax is:
22785
22786 @smallexample
22787 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22788 @end smallexample
22789
22790 @var{comm} is either a device name (to use a serial line), or a TCP
22791 hostname and portnumber, or @code{-} or @code{stdio} to use
22792 stdin/stdout of @code{gdbserver}.
22793 For example, to debug Emacs with the argument
22794 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22795 @file{/dev/com1}:
22796
22797 @smallexample
22798 target> gdbserver /dev/com1 emacs foo.txt
22799 @end smallexample
22800
22801 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22802 with it.
22803
22804 To use a TCP connection instead of a serial line:
22805
22806 @smallexample
22807 target> gdbserver host:2345 emacs foo.txt
22808 @end smallexample
22809
22810 The only difference from the previous example is the first argument,
22811 specifying that you are communicating with the host @value{GDBN} via
22812 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22813 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22814 (Currently, the @samp{host} part is ignored.) You can choose any number
22815 you want for the port number as long as it does not conflict with any
22816 TCP ports already in use on the target system (for example, @code{23} is
22817 reserved for @code{telnet}).@footnote{If you choose a port number that
22818 conflicts with another service, @code{gdbserver} prints an error message
22819 and exits.} You must use the same port number with the host @value{GDBN}
22820 @code{target remote} command.
22821
22822 The @code{stdio} connection is useful when starting @code{gdbserver}
22823 with ssh:
22824
22825 @smallexample
22826 (gdb) target remote | ssh -T hostname gdbserver - hello
22827 @end smallexample
22828
22829 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22830 and we don't want escape-character handling. Ssh does this by default when
22831 a command is provided, the flag is provided to make it explicit.
22832 You could elide it if you want to.
22833
22834 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22835 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22836 display through a pipe connected to gdbserver.
22837 Both @code{stdout} and @code{stderr} use the same pipe.
22838
22839 @anchor{Attaching to a program}
22840 @subsubsection Attaching to a Running Program
22841 @cindex attach to a program, @code{gdbserver}
22842 @cindex @option{--attach}, @code{gdbserver} option
22843
22844 On some targets, @code{gdbserver} can also attach to running programs.
22845 This is accomplished via the @code{--attach} argument. The syntax is:
22846
22847 @smallexample
22848 target> gdbserver --attach @var{comm} @var{pid}
22849 @end smallexample
22850
22851 @var{pid} is the process ID of a currently running process. It isn't
22852 necessary to point @code{gdbserver} at a binary for the running process.
22853
22854 In @code{target extended-remote} mode, you can also attach using the
22855 @value{GDBN} attach command
22856 (@pxref{Attaching in Types of Remote Connections}).
22857
22858 @pindex pidof
22859 You can debug processes by name instead of process ID if your target has the
22860 @code{pidof} utility:
22861
22862 @smallexample
22863 target> gdbserver --attach @var{comm} `pidof @var{program}`
22864 @end smallexample
22865
22866 In case more than one copy of @var{program} is running, or @var{program}
22867 has multiple threads, most versions of @code{pidof} support the
22868 @code{-s} option to only return the first process ID.
22869
22870 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22871
22872 This section applies only when @code{gdbserver} is run to listen on a TCP
22873 port.
22874
22875 @code{gdbserver} normally terminates after all of its debugged processes have
22876 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22877 extended-remote}, @code{gdbserver} stays running even with no processes left.
22878 @value{GDBN} normally terminates the spawned debugged process on its exit,
22879 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22880 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22881 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22882 stays running even in the @kbd{target remote} mode.
22883
22884 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22885 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22886 completeness, at most one @value{GDBN} can be connected at a time.
22887
22888 @cindex @option{--once}, @code{gdbserver} option
22889 By default, @code{gdbserver} keeps the listening TCP port open, so that
22890 subsequent connections are possible. However, if you start @code{gdbserver}
22891 with the @option{--once} option, it will stop listening for any further
22892 connection attempts after connecting to the first @value{GDBN} session. This
22893 means no further connections to @code{gdbserver} will be possible after the
22894 first one. It also means @code{gdbserver} will terminate after the first
22895 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22896 connections and even in the @kbd{target extended-remote} mode. The
22897 @option{--once} option allows reusing the same port number for connecting to
22898 multiple instances of @code{gdbserver} running on the same host, since each
22899 instance closes its port after the first connection.
22900
22901 @anchor{Other Command-Line Arguments for gdbserver}
22902 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22903
22904 You can use the @option{--multi} option to start @code{gdbserver} without
22905 specifying a program to debug or a process to attach to. Then you can
22906 attach in @code{target extended-remote} mode and run or attach to a
22907 program. For more information,
22908 @pxref{--multi Option in Types of Remote Connnections}.
22909
22910 @cindex @option{--debug}, @code{gdbserver} option
22911 The @option{--debug} option tells @code{gdbserver} to display extra
22912 status information about the debugging process.
22913 @cindex @option{--remote-debug}, @code{gdbserver} option
22914 The @option{--remote-debug} option tells @code{gdbserver} to display
22915 remote protocol debug output.
22916 @cindex @option{--debug-file}, @code{gdbserver} option
22917 @cindex @code{gdbserver}, send all debug output to a single file
22918 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22919 write any debug output to the given @var{filename}. These options are intended
22920 for @code{gdbserver} development and for bug reports to the developers.
22921
22922 @cindex @option{--debug-format}, @code{gdbserver} option
22923 The @option{--debug-format=option1[,option2,...]} option tells
22924 @code{gdbserver} to include additional information in each output.
22925 Possible options are:
22926
22927 @table @code
22928 @item none
22929 Turn off all extra information in debugging output.
22930 @item all
22931 Turn on all extra information in debugging output.
22932 @item timestamps
22933 Include a timestamp in each line of debugging output.
22934 @end table
22935
22936 Options are processed in order. Thus, for example, if @option{none}
22937 appears last then no additional information is added to debugging output.
22938
22939 @cindex @option{--wrapper}, @code{gdbserver} option
22940 The @option{--wrapper} option specifies a wrapper to launch programs
22941 for debugging. The option should be followed by the name of the
22942 wrapper, then any command-line arguments to pass to the wrapper, then
22943 @kbd{--} indicating the end of the wrapper arguments.
22944
22945 @code{gdbserver} runs the specified wrapper program with a combined
22946 command line including the wrapper arguments, then the name of the
22947 program to debug, then any arguments to the program. The wrapper
22948 runs until it executes your program, and then @value{GDBN} gains control.
22949
22950 You can use any program that eventually calls @code{execve} with
22951 its arguments as a wrapper. Several standard Unix utilities do
22952 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22953 with @code{exec "$@@"} will also work.
22954
22955 For example, you can use @code{env} to pass an environment variable to
22956 the debugged program, without setting the variable in @code{gdbserver}'s
22957 environment:
22958
22959 @smallexample
22960 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22961 @end smallexample
22962
22963 @cindex @option{--selftest}
22964 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22965
22966 @smallexample
22967 $ gdbserver --selftest
22968 Ran 2 unit tests, 0 failed
22969 @end smallexample
22970
22971 These tests are disabled in release.
22972 @subsection Connecting to @code{gdbserver}
22973
22974 The basic procedure for connecting to the remote target is:
22975 @itemize
22976
22977 @item
22978 Run @value{GDBN} on the host system.
22979
22980 @item
22981 Make sure you have the necessary symbol files
22982 (@pxref{Host and target files}).
22983 Load symbols for your application using the @code{file} command before you
22984 connect. Use @code{set sysroot} to locate target libraries (unless your
22985 @value{GDBN} was compiled with the correct sysroot using
22986 @code{--with-sysroot}).
22987
22988 @item
22989 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22990 For TCP connections, you must start up @code{gdbserver} prior to using
22991 the @code{target} command. Otherwise you may get an error whose
22992 text depends on the host system, but which usually looks something like
22993 @samp{Connection refused}. Don't use the @code{load}
22994 command in @value{GDBN} when using @code{target remote} mode, since the
22995 program is already on the target.
22996
22997 @end itemize
22998
22999 @anchor{Monitor Commands for gdbserver}
23000 @subsection Monitor Commands for @code{gdbserver}
23001 @cindex monitor commands, for @code{gdbserver}
23002
23003 During a @value{GDBN} session using @code{gdbserver}, you can use the
23004 @code{monitor} command to send special requests to @code{gdbserver}.
23005 Here are the available commands.
23006
23007 @table @code
23008 @item monitor help
23009 List the available monitor commands.
23010
23011 @item monitor set debug 0
23012 @itemx monitor set debug 1
23013 Disable or enable general debugging messages.
23014
23015 @item monitor set remote-debug 0
23016 @itemx monitor set remote-debug 1
23017 Disable or enable specific debugging messages associated with the remote
23018 protocol (@pxref{Remote Protocol}).
23019
23020 @item monitor set debug-file filename
23021 @itemx monitor set debug-file
23022 Send any debug output to the given file, or to stderr.
23023
23024 @item monitor set debug-format option1@r{[},option2,...@r{]}
23025 Specify additional text to add to debugging messages.
23026 Possible options are:
23027
23028 @table @code
23029 @item none
23030 Turn off all extra information in debugging output.
23031 @item all
23032 Turn on all extra information in debugging output.
23033 @item timestamps
23034 Include a timestamp in each line of debugging output.
23035 @end table
23036
23037 Options are processed in order. Thus, for example, if @option{none}
23038 appears last then no additional information is added to debugging output.
23039
23040 @item monitor set libthread-db-search-path [PATH]
23041 @cindex gdbserver, search path for @code{libthread_db}
23042 When this command is issued, @var{path} is a colon-separated list of
23043 directories to search for @code{libthread_db} (@pxref{Threads,,set
23044 libthread-db-search-path}). If you omit @var{path},
23045 @samp{libthread-db-search-path} will be reset to its default value.
23046
23047 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
23048 not supported in @code{gdbserver}.
23049
23050 @item monitor exit
23051 Tell gdbserver to exit immediately. This command should be followed by
23052 @code{disconnect} to close the debugging session. @code{gdbserver} will
23053 detach from any attached processes and kill any processes it created.
23054 Use @code{monitor exit} to terminate @code{gdbserver} at the end
23055 of a multi-process mode debug session.
23056
23057 @end table
23058
23059 @subsection Tracepoints support in @code{gdbserver}
23060 @cindex tracepoints support in @code{gdbserver}
23061
23062 On some targets, @code{gdbserver} supports tracepoints, fast
23063 tracepoints and static tracepoints.
23064
23065 For fast or static tracepoints to work, a special library called the
23066 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
23067 This library is built and distributed as an integral part of
23068 @code{gdbserver}. In addition, support for static tracepoints
23069 requires building the in-process agent library with static tracepoints
23070 support. At present, the UST (LTTng Userspace Tracer,
23071 @url{http://lttng.org/ust}) tracing engine is supported. This support
23072 is automatically available if UST development headers are found in the
23073 standard include path when @code{gdbserver} is built, or if
23074 @code{gdbserver} was explicitly configured using @option{--with-ust}
23075 to point at such headers. You can explicitly disable the support
23076 using @option{--with-ust=no}.
23077
23078 There are several ways to load the in-process agent in your program:
23079
23080 @table @code
23081 @item Specifying it as dependency at link time
23082
23083 You can link your program dynamically with the in-process agent
23084 library. On most systems, this is accomplished by adding
23085 @code{-linproctrace} to the link command.
23086
23087 @item Using the system's preloading mechanisms
23088
23089 You can force loading the in-process agent at startup time by using
23090 your system's support for preloading shared libraries. Many Unixes
23091 support the concept of preloading user defined libraries. In most
23092 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
23093 in the environment. See also the description of @code{gdbserver}'s
23094 @option{--wrapper} command line option.
23095
23096 @item Using @value{GDBN} to force loading the agent at run time
23097
23098 On some systems, you can force the inferior to load a shared library,
23099 by calling a dynamic loader function in the inferior that takes care
23100 of dynamically looking up and loading a shared library. On most Unix
23101 systems, the function is @code{dlopen}. You'll use the @code{call}
23102 command for that. For example:
23103
23104 @smallexample
23105 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
23106 @end smallexample
23107
23108 Note that on most Unix systems, for the @code{dlopen} function to be
23109 available, the program needs to be linked with @code{-ldl}.
23110 @end table
23111
23112 On systems that have a userspace dynamic loader, like most Unix
23113 systems, when you connect to @code{gdbserver} using @code{target
23114 remote}, you'll find that the program is stopped at the dynamic
23115 loader's entry point, and no shared library has been loaded in the
23116 program's address space yet, including the in-process agent. In that
23117 case, before being able to use any of the fast or static tracepoints
23118 features, you need to let the loader run and load the shared
23119 libraries. The simplest way to do that is to run the program to the
23120 main procedure. E.g., if debugging a C or C@t{++} program, start
23121 @code{gdbserver} like so:
23122
23123 @smallexample
23124 $ gdbserver :9999 myprogram
23125 @end smallexample
23126
23127 Start GDB and connect to @code{gdbserver} like so, and run to main:
23128
23129 @smallexample
23130 $ gdb myprogram
23131 (@value{GDBP}) target remote myhost:9999
23132 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
23133 (@value{GDBP}) b main
23134 (@value{GDBP}) continue
23135 @end smallexample
23136
23137 The in-process tracing agent library should now be loaded into the
23138 process; you can confirm it with the @code{info sharedlibrary}
23139 command, which will list @file{libinproctrace.so} as loaded in the
23140 process. You are now ready to install fast tracepoints, list static
23141 tracepoint markers, probe static tracepoints markers, and start
23142 tracing.
23143
23144 @node Remote Configuration
23145 @section Remote Configuration
23146
23147 @kindex set remote
23148 @kindex show remote
23149 This section documents the configuration options available when
23150 debugging remote programs. For the options related to the File I/O
23151 extensions of the remote protocol, see @ref{system,
23152 system-call-allowed}.
23153
23154 @table @code
23155 @item set remoteaddresssize @var{bits}
23156 @cindex address size for remote targets
23157 @cindex bits in remote address
23158 Set the maximum size of address in a memory packet to the specified
23159 number of bits. @value{GDBN} will mask off the address bits above
23160 that number, when it passes addresses to the remote target. The
23161 default value is the number of bits in the target's address.
23162
23163 @item show remoteaddresssize
23164 Show the current value of remote address size in bits.
23165
23166 @item set serial baud @var{n}
23167 @cindex baud rate for remote targets
23168 Set the baud rate for the remote serial I/O to @var{n} baud. The
23169 value is used to set the speed of the serial port used for debugging
23170 remote targets.
23171
23172 @item show serial baud
23173 Show the current speed of the remote connection.
23174
23175 @item set serial parity @var{parity}
23176 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
23177 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
23178
23179 @item show serial parity
23180 Show the current parity of the serial port.
23181
23182 @item set remotebreak
23183 @cindex interrupt remote programs
23184 @cindex BREAK signal instead of Ctrl-C
23185 @anchor{set remotebreak}
23186 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
23187 when you type @kbd{Ctrl-c} to interrupt the program running
23188 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
23189 character instead. The default is off, since most remote systems
23190 expect to see @samp{Ctrl-C} as the interrupt signal.
23191
23192 @item show remotebreak
23193 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
23194 interrupt the remote program.
23195
23196 @item set remoteflow on
23197 @itemx set remoteflow off
23198 @kindex set remoteflow
23199 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
23200 on the serial port used to communicate to the remote target.
23201
23202 @item show remoteflow
23203 @kindex show remoteflow
23204 Show the current setting of hardware flow control.
23205
23206 @item set remotelogbase @var{base}
23207 Set the base (a.k.a.@: radix) of logging serial protocol
23208 communications to @var{base}. Supported values of @var{base} are:
23209 @code{ascii}, @code{octal}, and @code{hex}. The default is
23210 @code{ascii}.
23211
23212 @item show remotelogbase
23213 Show the current setting of the radix for logging remote serial
23214 protocol.
23215
23216 @item set remotelogfile @var{file}
23217 @cindex record serial communications on file
23218 Record remote serial communications on the named @var{file}. The
23219 default is not to record at all.
23220
23221 @item show remotelogfile
23222 Show the current setting of the file name on which to record the
23223 serial communications.
23224
23225 @item set remotetimeout @var{num}
23226 @cindex timeout for serial communications
23227 @cindex remote timeout
23228 Set the timeout limit to wait for the remote target to respond to
23229 @var{num} seconds. The default is 2 seconds.
23230
23231 @item show remotetimeout
23232 Show the current number of seconds to wait for the remote target
23233 responses.
23234
23235 @cindex limit hardware breakpoints and watchpoints
23236 @cindex remote target, limit break- and watchpoints
23237 @anchor{set remote hardware-watchpoint-limit}
23238 @anchor{set remote hardware-breakpoint-limit}
23239 @item set remote hardware-watchpoint-limit @var{limit}
23240 @itemx set remote hardware-breakpoint-limit @var{limit}
23241 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
23242 or breakpoints. The @var{limit} can be set to 0 to disable hardware
23243 watchpoints or breakpoints, and @code{unlimited} for unlimited
23244 watchpoints or breakpoints.
23245
23246 @item show remote hardware-watchpoint-limit
23247 @itemx show remote hardware-breakpoint-limit
23248 Show the current limit for the number of hardware watchpoints or
23249 breakpoints that @value{GDBN} can use.
23250
23251 @cindex limit hardware watchpoints length
23252 @cindex remote target, limit watchpoints length
23253 @anchor{set remote hardware-watchpoint-length-limit}
23254 @item set remote hardware-watchpoint-length-limit @var{limit}
23255 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
23256 length of a remote hardware watchpoint. A @var{limit} of 0 disables
23257 hardware watchpoints and @code{unlimited} allows watchpoints of any
23258 length.
23259
23260 @item show remote hardware-watchpoint-length-limit
23261 Show the current limit (in bytes) of the maximum length of
23262 a remote hardware watchpoint.
23263
23264 @item set remote exec-file @var{filename}
23265 @itemx show remote exec-file
23266 @anchor{set remote exec-file}
23267 @cindex executable file, for remote target
23268 Select the file used for @code{run} with @code{target
23269 extended-remote}. This should be set to a filename valid on the
23270 target system. If it is not set, the target will use a default
23271 filename (e.g.@: the last program run).
23272
23273 @item set remote interrupt-sequence
23274 @cindex interrupt remote programs
23275 @cindex select Ctrl-C, BREAK or BREAK-g
23276 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
23277 @samp{BREAK-g} as the
23278 sequence to the remote target in order to interrupt the execution.
23279 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
23280 is high level of serial line for some certain time.
23281 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
23282 It is @code{BREAK} signal followed by character @code{g}.
23283
23284 @item show remote interrupt-sequence
23285 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
23286 is sent by @value{GDBN} to interrupt the remote program.
23287 @code{BREAK-g} is BREAK signal followed by @code{g} and
23288 also known as Magic SysRq g.
23289
23290 @item set remote interrupt-on-connect
23291 @cindex send interrupt-sequence on start
23292 Specify whether interrupt-sequence is sent to remote target when
23293 @value{GDBN} connects to it. This is mostly needed when you debug
23294 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
23295 which is known as Magic SysRq g in order to connect @value{GDBN}.
23296
23297 @item show remote interrupt-on-connect
23298 Show whether interrupt-sequence is sent
23299 to remote target when @value{GDBN} connects to it.
23300
23301 @kindex set tcp
23302 @kindex show tcp
23303 @item set tcp auto-retry on
23304 @cindex auto-retry, for remote TCP target
23305 Enable auto-retry for remote TCP connections. This is useful if the remote
23306 debugging agent is launched in parallel with @value{GDBN}; there is a race
23307 condition because the agent may not become ready to accept the connection
23308 before @value{GDBN} attempts to connect. When auto-retry is
23309 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
23310 to establish the connection using the timeout specified by
23311 @code{set tcp connect-timeout}.
23312
23313 @item set tcp auto-retry off
23314 Do not auto-retry failed TCP connections.
23315
23316 @item show tcp auto-retry
23317 Show the current auto-retry setting.
23318
23319 @item set tcp connect-timeout @var{seconds}
23320 @itemx set tcp connect-timeout unlimited
23321 @cindex connection timeout, for remote TCP target
23322 @cindex timeout, for remote target connection
23323 Set the timeout for establishing a TCP connection to the remote target to
23324 @var{seconds}. The timeout affects both polling to retry failed connections
23325 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23326 that are merely slow to complete, and represents an approximate cumulative
23327 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23328 @value{GDBN} will keep attempting to establish a connection forever,
23329 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23330
23331 @item show tcp connect-timeout
23332 Show the current connection timeout setting.
23333 @end table
23334
23335 @cindex remote packets, enabling and disabling
23336 The @value{GDBN} remote protocol autodetects the packets supported by
23337 your debugging stub. If you need to override the autodetection, you
23338 can use these commands to enable or disable individual packets. Each
23339 packet can be set to @samp{on} (the remote target supports this
23340 packet), @samp{off} (the remote target does not support this packet),
23341 or @samp{auto} (detect remote target support for this packet). They
23342 all default to @samp{auto}. For more information about each packet,
23343 see @ref{Remote Protocol}.
23344
23345 During normal use, you should not have to use any of these commands.
23346 If you do, that may be a bug in your remote debugging stub, or a bug
23347 in @value{GDBN}. You may want to report the problem to the
23348 @value{GDBN} developers.
23349
23350 For each packet @var{name}, the command to enable or disable the
23351 packet is @code{set remote @var{name}-packet}. The available settings
23352 are:
23353
23354 @multitable @columnfractions 0.28 0.32 0.25
23355 @item Command Name
23356 @tab Remote Packet
23357 @tab Related Features
23358
23359 @item @code{fetch-register}
23360 @tab @code{p}
23361 @tab @code{info registers}
23362
23363 @item @code{set-register}
23364 @tab @code{P}
23365 @tab @code{set}
23366
23367 @item @code{binary-download}
23368 @tab @code{X}
23369 @tab @code{load}, @code{set}
23370
23371 @item @code{read-aux-vector}
23372 @tab @code{qXfer:auxv:read}
23373 @tab @code{info auxv}
23374
23375 @item @code{symbol-lookup}
23376 @tab @code{qSymbol}
23377 @tab Detecting multiple threads
23378
23379 @item @code{attach}
23380 @tab @code{vAttach}
23381 @tab @code{attach}
23382
23383 @item @code{verbose-resume}
23384 @tab @code{vCont}
23385 @tab Stepping or resuming multiple threads
23386
23387 @item @code{run}
23388 @tab @code{vRun}
23389 @tab @code{run}
23390
23391 @item @code{software-breakpoint}
23392 @tab @code{Z0}
23393 @tab @code{break}
23394
23395 @item @code{hardware-breakpoint}
23396 @tab @code{Z1}
23397 @tab @code{hbreak}
23398
23399 @item @code{write-watchpoint}
23400 @tab @code{Z2}
23401 @tab @code{watch}
23402
23403 @item @code{read-watchpoint}
23404 @tab @code{Z3}
23405 @tab @code{rwatch}
23406
23407 @item @code{access-watchpoint}
23408 @tab @code{Z4}
23409 @tab @code{awatch}
23410
23411 @item @code{pid-to-exec-file}
23412 @tab @code{qXfer:exec-file:read}
23413 @tab @code{attach}, @code{run}
23414
23415 @item @code{target-features}
23416 @tab @code{qXfer:features:read}
23417 @tab @code{set architecture}
23418
23419 @item @code{library-info}
23420 @tab @code{qXfer:libraries:read}
23421 @tab @code{info sharedlibrary}
23422
23423 @item @code{memory-map}
23424 @tab @code{qXfer:memory-map:read}
23425 @tab @code{info mem}
23426
23427 @item @code{read-sdata-object}
23428 @tab @code{qXfer:sdata:read}
23429 @tab @code{print $_sdata}
23430
23431 @item @code{read-siginfo-object}
23432 @tab @code{qXfer:siginfo:read}
23433 @tab @code{print $_siginfo}
23434
23435 @item @code{write-siginfo-object}
23436 @tab @code{qXfer:siginfo:write}
23437 @tab @code{set $_siginfo}
23438
23439 @item @code{threads}
23440 @tab @code{qXfer:threads:read}
23441 @tab @code{info threads}
23442
23443 @item @code{get-thread-local-@*storage-address}
23444 @tab @code{qGetTLSAddr}
23445 @tab Displaying @code{__thread} variables
23446
23447 @item @code{get-thread-information-block-address}
23448 @tab @code{qGetTIBAddr}
23449 @tab Display MS-Windows Thread Information Block.
23450
23451 @item @code{search-memory}
23452 @tab @code{qSearch:memory}
23453 @tab @code{find}
23454
23455 @item @code{supported-packets}
23456 @tab @code{qSupported}
23457 @tab Remote communications parameters
23458
23459 @item @code{catch-syscalls}
23460 @tab @code{QCatchSyscalls}
23461 @tab @code{catch syscall}
23462
23463 @item @code{pass-signals}
23464 @tab @code{QPassSignals}
23465 @tab @code{handle @var{signal}}
23466
23467 @item @code{program-signals}
23468 @tab @code{QProgramSignals}
23469 @tab @code{handle @var{signal}}
23470
23471 @item @code{hostio-close-packet}
23472 @tab @code{vFile:close}
23473 @tab @code{remote get}, @code{remote put}
23474
23475 @item @code{hostio-open-packet}
23476 @tab @code{vFile:open}
23477 @tab @code{remote get}, @code{remote put}
23478
23479 @item @code{hostio-pread-packet}
23480 @tab @code{vFile:pread}
23481 @tab @code{remote get}, @code{remote put}
23482
23483 @item @code{hostio-pwrite-packet}
23484 @tab @code{vFile:pwrite}
23485 @tab @code{remote get}, @code{remote put}
23486
23487 @item @code{hostio-unlink-packet}
23488 @tab @code{vFile:unlink}
23489 @tab @code{remote delete}
23490
23491 @item @code{hostio-readlink-packet}
23492 @tab @code{vFile:readlink}
23493 @tab Host I/O
23494
23495 @item @code{hostio-fstat-packet}
23496 @tab @code{vFile:fstat}
23497 @tab Host I/O
23498
23499 @item @code{hostio-setfs-packet}
23500 @tab @code{vFile:setfs}
23501 @tab Host I/O
23502
23503 @item @code{noack-packet}
23504 @tab @code{QStartNoAckMode}
23505 @tab Packet acknowledgment
23506
23507 @item @code{osdata}
23508 @tab @code{qXfer:osdata:read}
23509 @tab @code{info os}
23510
23511 @item @code{query-attached}
23512 @tab @code{qAttached}
23513 @tab Querying remote process attach state.
23514
23515 @item @code{trace-buffer-size}
23516 @tab @code{QTBuffer:size}
23517 @tab @code{set trace-buffer-size}
23518
23519 @item @code{trace-status}
23520 @tab @code{qTStatus}
23521 @tab @code{tstatus}
23522
23523 @item @code{traceframe-info}
23524 @tab @code{qXfer:traceframe-info:read}
23525 @tab Traceframe info
23526
23527 @item @code{install-in-trace}
23528 @tab @code{InstallInTrace}
23529 @tab Install tracepoint in tracing
23530
23531 @item @code{disable-randomization}
23532 @tab @code{QDisableRandomization}
23533 @tab @code{set disable-randomization}
23534
23535 @item @code{startup-with-shell}
23536 @tab @code{QStartupWithShell}
23537 @tab @code{set startup-with-shell}
23538
23539 @item @code{environment-hex-encoded}
23540 @tab @code{QEnvironmentHexEncoded}
23541 @tab @code{set environment}
23542
23543 @item @code{environment-unset}
23544 @tab @code{QEnvironmentUnset}
23545 @tab @code{unset environment}
23546
23547 @item @code{environment-reset}
23548 @tab @code{QEnvironmentReset}
23549 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23550
23551 @item @code{set-working-dir}
23552 @tab @code{QSetWorkingDir}
23553 @tab @code{set cwd}
23554
23555 @item @code{conditional-breakpoints-packet}
23556 @tab @code{Z0 and Z1}
23557 @tab @code{Support for target-side breakpoint condition evaluation}
23558
23559 @item @code{multiprocess-extensions}
23560 @tab @code{multiprocess extensions}
23561 @tab Debug multiple processes and remote process PID awareness
23562
23563 @item @code{swbreak-feature}
23564 @tab @code{swbreak stop reason}
23565 @tab @code{break}
23566
23567 @item @code{hwbreak-feature}
23568 @tab @code{hwbreak stop reason}
23569 @tab @code{hbreak}
23570
23571 @item @code{fork-event-feature}
23572 @tab @code{fork stop reason}
23573 @tab @code{fork}
23574
23575 @item @code{vfork-event-feature}
23576 @tab @code{vfork stop reason}
23577 @tab @code{vfork}
23578
23579 @item @code{exec-event-feature}
23580 @tab @code{exec stop reason}
23581 @tab @code{exec}
23582
23583 @item @code{thread-events}
23584 @tab @code{QThreadEvents}
23585 @tab Tracking thread lifetime.
23586
23587 @item @code{no-resumed-stop-reply}
23588 @tab @code{no resumed thread left stop reply}
23589 @tab Tracking thread lifetime.
23590
23591 @end multitable
23592
23593 @node Remote Stub
23594 @section Implementing a Remote Stub
23595
23596 @cindex debugging stub, example
23597 @cindex remote stub, example
23598 @cindex stub example, remote debugging
23599 The stub files provided with @value{GDBN} implement the target side of the
23600 communication protocol, and the @value{GDBN} side is implemented in the
23601 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23602 these subroutines to communicate, and ignore the details. (If you're
23603 implementing your own stub file, you can still ignore the details: start
23604 with one of the existing stub files. @file{sparc-stub.c} is the best
23605 organized, and therefore the easiest to read.)
23606
23607 @cindex remote serial debugging, overview
23608 To debug a program running on another machine (the debugging
23609 @dfn{target} machine), you must first arrange for all the usual
23610 prerequisites for the program to run by itself. For example, for a C
23611 program, you need:
23612
23613 @enumerate
23614 @item
23615 A startup routine to set up the C runtime environment; these usually
23616 have a name like @file{crt0}. The startup routine may be supplied by
23617 your hardware supplier, or you may have to write your own.
23618
23619 @item
23620 A C subroutine library to support your program's
23621 subroutine calls, notably managing input and output.
23622
23623 @item
23624 A way of getting your program to the other machine---for example, a
23625 download program. These are often supplied by the hardware
23626 manufacturer, but you may have to write your own from hardware
23627 documentation.
23628 @end enumerate
23629
23630 The next step is to arrange for your program to use a serial port to
23631 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23632 machine). In general terms, the scheme looks like this:
23633
23634 @table @emph
23635 @item On the host,
23636 @value{GDBN} already understands how to use this protocol; when everything
23637 else is set up, you can simply use the @samp{target remote} command
23638 (@pxref{Targets,,Specifying a Debugging Target}).
23639
23640 @item On the target,
23641 you must link with your program a few special-purpose subroutines that
23642 implement the @value{GDBN} remote serial protocol. The file containing these
23643 subroutines is called a @dfn{debugging stub}.
23644
23645 On certain remote targets, you can use an auxiliary program
23646 @code{gdbserver} instead of linking a stub into your program.
23647 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23648 @end table
23649
23650 The debugging stub is specific to the architecture of the remote
23651 machine; for example, use @file{sparc-stub.c} to debug programs on
23652 @sc{sparc} boards.
23653
23654 @cindex remote serial stub list
23655 These working remote stubs are distributed with @value{GDBN}:
23656
23657 @table @code
23658
23659 @item i386-stub.c
23660 @cindex @file{i386-stub.c}
23661 @cindex Intel
23662 @cindex i386
23663 For Intel 386 and compatible architectures.
23664
23665 @item m68k-stub.c
23666 @cindex @file{m68k-stub.c}
23667 @cindex Motorola 680x0
23668 @cindex m680x0
23669 For Motorola 680x0 architectures.
23670
23671 @item sh-stub.c
23672 @cindex @file{sh-stub.c}
23673 @cindex Renesas
23674 @cindex SH
23675 For Renesas SH architectures.
23676
23677 @item sparc-stub.c
23678 @cindex @file{sparc-stub.c}
23679 @cindex Sparc
23680 For @sc{sparc} architectures.
23681
23682 @item sparcl-stub.c
23683 @cindex @file{sparcl-stub.c}
23684 @cindex Fujitsu
23685 @cindex SparcLite
23686 For Fujitsu @sc{sparclite} architectures.
23687
23688 @end table
23689
23690 The @file{README} file in the @value{GDBN} distribution may list other
23691 recently added stubs.
23692
23693 @menu
23694 * Stub Contents:: What the stub can do for you
23695 * Bootstrapping:: What you must do for the stub
23696 * Debug Session:: Putting it all together
23697 @end menu
23698
23699 @node Stub Contents
23700 @subsection What the Stub Can Do for You
23701
23702 @cindex remote serial stub
23703 The debugging stub for your architecture supplies these three
23704 subroutines:
23705
23706 @table @code
23707 @item set_debug_traps
23708 @findex set_debug_traps
23709 @cindex remote serial stub, initialization
23710 This routine arranges for @code{handle_exception} to run when your
23711 program stops. You must call this subroutine explicitly in your
23712 program's startup code.
23713
23714 @item handle_exception
23715 @findex handle_exception
23716 @cindex remote serial stub, main routine
23717 This is the central workhorse, but your program never calls it
23718 explicitly---the setup code arranges for @code{handle_exception} to
23719 run when a trap is triggered.
23720
23721 @code{handle_exception} takes control when your program stops during
23722 execution (for example, on a breakpoint), and mediates communications
23723 with @value{GDBN} on the host machine. This is where the communications
23724 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23725 representative on the target machine. It begins by sending summary
23726 information on the state of your program, then continues to execute,
23727 retrieving and transmitting any information @value{GDBN} needs, until you
23728 execute a @value{GDBN} command that makes your program resume; at that point,
23729 @code{handle_exception} returns control to your own code on the target
23730 machine.
23731
23732 @item breakpoint
23733 @cindex @code{breakpoint} subroutine, remote
23734 Use this auxiliary subroutine to make your program contain a
23735 breakpoint. Depending on the particular situation, this may be the only
23736 way for @value{GDBN} to get control. For instance, if your target
23737 machine has some sort of interrupt button, you won't need to call this;
23738 pressing the interrupt button transfers control to
23739 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23740 simply receiving characters on the serial port may also trigger a trap;
23741 again, in that situation, you don't need to call @code{breakpoint} from
23742 your own program---simply running @samp{target remote} from the host
23743 @value{GDBN} session gets control.
23744
23745 Call @code{breakpoint} if none of these is true, or if you simply want
23746 to make certain your program stops at a predetermined point for the
23747 start of your debugging session.
23748 @end table
23749
23750 @node Bootstrapping
23751 @subsection What You Must Do for the Stub
23752
23753 @cindex remote stub, support routines
23754 The debugging stubs that come with @value{GDBN} are set up for a particular
23755 chip architecture, but they have no information about the rest of your
23756 debugging target machine.
23757
23758 First of all you need to tell the stub how to communicate with the
23759 serial port.
23760
23761 @table @code
23762 @item int getDebugChar()
23763 @findex getDebugChar
23764 Write this subroutine to read a single character from the serial port.
23765 It may be identical to @code{getchar} for your target system; a
23766 different name is used to allow you to distinguish the two if you wish.
23767
23768 @item void putDebugChar(int)
23769 @findex putDebugChar
23770 Write this subroutine to write a single character to the serial port.
23771 It may be identical to @code{putchar} for your target system; a
23772 different name is used to allow you to distinguish the two if you wish.
23773 @end table
23774
23775 @cindex control C, and remote debugging
23776 @cindex interrupting remote targets
23777 If you want @value{GDBN} to be able to stop your program while it is
23778 running, you need to use an interrupt-driven serial driver, and arrange
23779 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23780 character). That is the character which @value{GDBN} uses to tell the
23781 remote system to stop.
23782
23783 Getting the debugging target to return the proper status to @value{GDBN}
23784 probably requires changes to the standard stub; one quick and dirty way
23785 is to just execute a breakpoint instruction (the ``dirty'' part is that
23786 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23787
23788 Other routines you need to supply are:
23789
23790 @table @code
23791 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23792 @findex exceptionHandler
23793 Write this function to install @var{exception_address} in the exception
23794 handling tables. You need to do this because the stub does not have any
23795 way of knowing what the exception handling tables on your target system
23796 are like (for example, the processor's table might be in @sc{rom},
23797 containing entries which point to a table in @sc{ram}).
23798 The @var{exception_number} specifies the exception which should be changed;
23799 its meaning is architecture-dependent (for example, different numbers
23800 might represent divide by zero, misaligned access, etc). When this
23801 exception occurs, control should be transferred directly to
23802 @var{exception_address}, and the processor state (stack, registers,
23803 and so on) should be just as it is when a processor exception occurs. So if
23804 you want to use a jump instruction to reach @var{exception_address}, it
23805 should be a simple jump, not a jump to subroutine.
23806
23807 For the 386, @var{exception_address} should be installed as an interrupt
23808 gate so that interrupts are masked while the handler runs. The gate
23809 should be at privilege level 0 (the most privileged level). The
23810 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23811 help from @code{exceptionHandler}.
23812
23813 @item void flush_i_cache()
23814 @findex flush_i_cache
23815 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23816 instruction cache, if any, on your target machine. If there is no
23817 instruction cache, this subroutine may be a no-op.
23818
23819 On target machines that have instruction caches, @value{GDBN} requires this
23820 function to make certain that the state of your program is stable.
23821 @end table
23822
23823 @noindent
23824 You must also make sure this library routine is available:
23825
23826 @table @code
23827 @item void *memset(void *, int, int)
23828 @findex memset
23829 This is the standard library function @code{memset} that sets an area of
23830 memory to a known value. If you have one of the free versions of
23831 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23832 either obtain it from your hardware manufacturer, or write your own.
23833 @end table
23834
23835 If you do not use the GNU C compiler, you may need other standard
23836 library subroutines as well; this varies from one stub to another,
23837 but in general the stubs are likely to use any of the common library
23838 subroutines which @code{@value{NGCC}} generates as inline code.
23839
23840
23841 @node Debug Session
23842 @subsection Putting it All Together
23843
23844 @cindex remote serial debugging summary
23845 In summary, when your program is ready to debug, you must follow these
23846 steps.
23847
23848 @enumerate
23849 @item
23850 Make sure you have defined the supporting low-level routines
23851 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23852 @display
23853 @code{getDebugChar}, @code{putDebugChar},
23854 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23855 @end display
23856
23857 @item
23858 Insert these lines in your program's startup code, before the main
23859 procedure is called:
23860
23861 @smallexample
23862 set_debug_traps();
23863 breakpoint();
23864 @end smallexample
23865
23866 On some machines, when a breakpoint trap is raised, the hardware
23867 automatically makes the PC point to the instruction after the
23868 breakpoint. If your machine doesn't do that, you may need to adjust
23869 @code{handle_exception} to arrange for it to return to the instruction
23870 after the breakpoint on this first invocation, so that your program
23871 doesn't keep hitting the initial breakpoint instead of making
23872 progress.
23873
23874 @item
23875 For the 680x0 stub only, you need to provide a variable called
23876 @code{exceptionHook}. Normally you just use:
23877
23878 @smallexample
23879 void (*exceptionHook)() = 0;
23880 @end smallexample
23881
23882 @noindent
23883 but if before calling @code{set_debug_traps}, you set it to point to a
23884 function in your program, that function is called when
23885 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23886 error). The function indicated by @code{exceptionHook} is called with
23887 one parameter: an @code{int} which is the exception number.
23888
23889 @item
23890 Compile and link together: your program, the @value{GDBN} debugging stub for
23891 your target architecture, and the supporting subroutines.
23892
23893 @item
23894 Make sure you have a serial connection between your target machine and
23895 the @value{GDBN} host, and identify the serial port on the host.
23896
23897 @item
23898 @c The "remote" target now provides a `load' command, so we should
23899 @c document that. FIXME.
23900 Download your program to your target machine (or get it there by
23901 whatever means the manufacturer provides), and start it.
23902
23903 @item
23904 Start @value{GDBN} on the host, and connect to the target
23905 (@pxref{Connecting,,Connecting to a Remote Target}).
23906
23907 @end enumerate
23908
23909 @node Configurations
23910 @chapter Configuration-Specific Information
23911
23912 While nearly all @value{GDBN} commands are available for all native and
23913 cross versions of the debugger, there are some exceptions. This chapter
23914 describes things that are only available in certain configurations.
23915
23916 There are three major categories of configurations: native
23917 configurations, where the host and target are the same, embedded
23918 operating system configurations, which are usually the same for several
23919 different processor architectures, and bare embedded processors, which
23920 are quite different from each other.
23921
23922 @menu
23923 * Native::
23924 * Embedded OS::
23925 * Embedded Processors::
23926 * Architectures::
23927 @end menu
23928
23929 @node Native
23930 @section Native
23931
23932 This section describes details specific to particular native
23933 configurations.
23934
23935 @menu
23936 * BSD libkvm Interface:: Debugging BSD kernel memory images
23937 * Process Information:: Process information
23938 * DJGPP Native:: Features specific to the DJGPP port
23939 * Cygwin Native:: Features specific to the Cygwin port
23940 * Hurd Native:: Features specific to @sc{gnu} Hurd
23941 * Darwin:: Features specific to Darwin
23942 * FreeBSD:: Features specific to FreeBSD
23943 @end menu
23944
23945 @node BSD libkvm Interface
23946 @subsection BSD libkvm Interface
23947
23948 @cindex libkvm
23949 @cindex kernel memory image
23950 @cindex kernel crash dump
23951
23952 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23953 interface that provides a uniform interface for accessing kernel virtual
23954 memory images, including live systems and crash dumps. @value{GDBN}
23955 uses this interface to allow you to debug live kernels and kernel crash
23956 dumps on many native BSD configurations. This is implemented as a
23957 special @code{kvm} debugging target. For debugging a live system, load
23958 the currently running kernel into @value{GDBN} and connect to the
23959 @code{kvm} target:
23960
23961 @smallexample
23962 (@value{GDBP}) @b{target kvm}
23963 @end smallexample
23964
23965 For debugging crash dumps, provide the file name of the crash dump as an
23966 argument:
23967
23968 @smallexample
23969 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23970 @end smallexample
23971
23972 Once connected to the @code{kvm} target, the following commands are
23973 available:
23974
23975 @table @code
23976 @kindex kvm
23977 @item kvm pcb
23978 Set current context from the @dfn{Process Control Block} (PCB) address.
23979
23980 @item kvm proc
23981 Set current context from proc address. This command isn't available on
23982 modern FreeBSD systems.
23983 @end table
23984
23985 @node Process Information
23986 @subsection Process Information
23987 @cindex /proc
23988 @cindex examine process image
23989 @cindex process info via @file{/proc}
23990
23991 Some operating systems provide interfaces to fetch additional
23992 information about running processes beyond memory and per-thread
23993 register state. If @value{GDBN} is configured for an operating system
23994 with a supported interface, the command @code{info proc} is available
23995 to report information about the process running your program, or about
23996 any process running on your system.
23997
23998 One supported interface is a facility called @samp{/proc} that can be
23999 used to examine the image of a running process using file-system
24000 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
24001 systems.
24002
24003 On FreeBSD and NetBSD systems, system control nodes are used to query
24004 process information.
24005
24006 In addition, some systems may provide additional process information
24007 in core files. Note that a core file may include a subset of the
24008 information available from a live process. Process information is
24009 currently available from cores created on @sc{gnu}/Linux and FreeBSD
24010 systems.
24011
24012 @table @code
24013 @kindex info proc
24014 @cindex process ID
24015 @item info proc
24016 @itemx info proc @var{process-id}
24017 Summarize available information about a process. If a
24018 process ID is specified by @var{process-id}, display information about
24019 that process; otherwise display information about the program being
24020 debugged. The summary includes the debugged process ID, the command
24021 line used to invoke it, its current working directory, and its
24022 executable file's absolute file name.
24023
24024 On some systems, @var{process-id} can be of the form
24025 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
24026 within a process. If the optional @var{pid} part is missing, it means
24027 a thread from the process being debugged (the leading @samp{/} still
24028 needs to be present, or else @value{GDBN} will interpret the number as
24029 a process ID rather than a thread ID).
24030
24031 @item info proc cmdline
24032 @cindex info proc cmdline
24033 Show the original command line of the process. This command is
24034 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24035
24036 @item info proc cwd
24037 @cindex info proc cwd
24038 Show the current working directory of the process. This command is
24039 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
24040
24041 @item info proc exe
24042 @cindex info proc exe
24043 Show the name of executable of the process. This command is supported
24044 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24045
24046 @item info proc files
24047 @cindex info proc files
24048 Show the file descriptors open by the process. For each open file
24049 descriptor, @value{GDBN} shows its number, type (file, directory,
24050 character device, socket), file pointer offset, and the name of the
24051 resource open on the descriptor. The resource name can be a file name
24052 (for files, directories, and devices) or a protocol followed by socket
24053 address (for network connections). This command is supported on
24054 FreeBSD.
24055
24056 This example shows the open file descriptors for a process using a
24057 tty for standard input and output as well as two network sockets:
24058
24059 @smallexample
24060 (gdb) info proc files 22136
24061 process 22136
24062 Open files:
24063
24064 FD Type Offset Flags Name
24065 text file - r-------- /usr/bin/ssh
24066 ctty chr - rw------- /dev/pts/20
24067 cwd dir - r-------- /usr/home/john
24068 root dir - r-------- /
24069 0 chr 0x32933a4 rw------- /dev/pts/20
24070 1 chr 0x32933a4 rw------- /dev/pts/20
24071 2 chr 0x32933a4 rw------- /dev/pts/20
24072 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
24073 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
24074 @end smallexample
24075
24076 @item info proc mappings
24077 @cindex memory address space mappings
24078 Report the memory address space ranges accessible in a process. On
24079 Solaris, FreeBSD and NetBSD systems, each memory range includes information
24080 on whether the process has read, write, or execute access rights to each
24081 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
24082 includes the object file which is mapped to that range.
24083
24084 @item info proc stat
24085 @itemx info proc status
24086 @cindex process detailed status information
24087 Show additional process-related information, including the user ID and
24088 group ID; virtual memory usage; the signals that are pending, blocked,
24089 and ignored; its TTY; its consumption of system and user time; its
24090 stack size; its @samp{nice} value; etc. These commands are supported
24091 on @sc{gnu}/Linux, FreeBSD and NetBSD.
24092
24093 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
24094 information (type @kbd{man 5 proc} from your shell prompt).
24095
24096 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
24097 @code{info proc status}.
24098
24099 @item info proc all
24100 Show all the information about the process described under all of the
24101 above @code{info proc} subcommands.
24102
24103 @ignore
24104 @comment These sub-options of 'info proc' were not included when
24105 @comment procfs.c was re-written. Keep their descriptions around
24106 @comment against the day when someone finds the time to put them back in.
24107 @kindex info proc times
24108 @item info proc times
24109 Starting time, user CPU time, and system CPU time for your program and
24110 its children.
24111
24112 @kindex info proc id
24113 @item info proc id
24114 Report on the process IDs related to your program: its own process ID,
24115 the ID of its parent, the process group ID, and the session ID.
24116 @end ignore
24117
24118 @item set procfs-trace
24119 @kindex set procfs-trace
24120 @cindex @code{procfs} API calls
24121 This command enables and disables tracing of @code{procfs} API calls.
24122
24123 @item show procfs-trace
24124 @kindex show procfs-trace
24125 Show the current state of @code{procfs} API call tracing.
24126
24127 @item set procfs-file @var{file}
24128 @kindex set procfs-file
24129 Tell @value{GDBN} to write @code{procfs} API trace to the named
24130 @var{file}. @value{GDBN} appends the trace info to the previous
24131 contents of the file. The default is to display the trace on the
24132 standard output.
24133
24134 @item show procfs-file
24135 @kindex show procfs-file
24136 Show the file to which @code{procfs} API trace is written.
24137
24138 @item proc-trace-entry
24139 @itemx proc-trace-exit
24140 @itemx proc-untrace-entry
24141 @itemx proc-untrace-exit
24142 @kindex proc-trace-entry
24143 @kindex proc-trace-exit
24144 @kindex proc-untrace-entry
24145 @kindex proc-untrace-exit
24146 These commands enable and disable tracing of entries into and exits
24147 from the @code{syscall} interface.
24148
24149 @item info pidlist
24150 @kindex info pidlist
24151 @cindex process list, QNX Neutrino
24152 For QNX Neutrino only, this command displays the list of all the
24153 processes and all the threads within each process.
24154
24155 @item info meminfo
24156 @kindex info meminfo
24157 @cindex mapinfo list, QNX Neutrino
24158 For QNX Neutrino only, this command displays the list of all mapinfos.
24159 @end table
24160
24161 @node DJGPP Native
24162 @subsection Features for Debugging @sc{djgpp} Programs
24163 @cindex @sc{djgpp} debugging
24164 @cindex native @sc{djgpp} debugging
24165 @cindex MS-DOS-specific commands
24166
24167 @cindex DPMI
24168 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
24169 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
24170 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
24171 top of real-mode DOS systems and their emulations.
24172
24173 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
24174 defines a few commands specific to the @sc{djgpp} port. This
24175 subsection describes those commands.
24176
24177 @table @code
24178 @kindex info dos
24179 @item info dos
24180 This is a prefix of @sc{djgpp}-specific commands which print
24181 information about the target system and important OS structures.
24182
24183 @kindex sysinfo
24184 @cindex MS-DOS system info
24185 @cindex free memory information (MS-DOS)
24186 @item info dos sysinfo
24187 This command displays assorted information about the underlying
24188 platform: the CPU type and features, the OS version and flavor, the
24189 DPMI version, and the available conventional and DPMI memory.
24190
24191 @cindex GDT
24192 @cindex LDT
24193 @cindex IDT
24194 @cindex segment descriptor tables
24195 @cindex descriptor tables display
24196 @item info dos gdt
24197 @itemx info dos ldt
24198 @itemx info dos idt
24199 These 3 commands display entries from, respectively, Global, Local,
24200 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
24201 tables are data structures which store a descriptor for each segment
24202 that is currently in use. The segment's selector is an index into a
24203 descriptor table; the table entry for that index holds the
24204 descriptor's base address and limit, and its attributes and access
24205 rights.
24206
24207 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
24208 segment (used for both data and the stack), and a DOS segment (which
24209 allows access to DOS/BIOS data structures and absolute addresses in
24210 conventional memory). However, the DPMI host will usually define
24211 additional segments in order to support the DPMI environment.
24212
24213 @cindex garbled pointers
24214 These commands allow to display entries from the descriptor tables.
24215 Without an argument, all entries from the specified table are
24216 displayed. An argument, which should be an integer expression, means
24217 display a single entry whose index is given by the argument. For
24218 example, here's a convenient way to display information about the
24219 debugged program's data segment:
24220
24221 @smallexample
24222 @exdent @code{(@value{GDBP}) info dos ldt $ds}
24223 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
24224 @end smallexample
24225
24226 @noindent
24227 This comes in handy when you want to see whether a pointer is outside
24228 the data segment's limit (i.e.@: @dfn{garbled}).
24229
24230 @cindex page tables display (MS-DOS)
24231 @item info dos pde
24232 @itemx info dos pte
24233 These two commands display entries from, respectively, the Page
24234 Directory and the Page Tables. Page Directories and Page Tables are
24235 data structures which control how virtual memory addresses are mapped
24236 into physical addresses. A Page Table includes an entry for every
24237 page of memory that is mapped into the program's address space; there
24238 may be several Page Tables, each one holding up to 4096 entries. A
24239 Page Directory has up to 4096 entries, one each for every Page Table
24240 that is currently in use.
24241
24242 Without an argument, @kbd{info dos pde} displays the entire Page
24243 Directory, and @kbd{info dos pte} displays all the entries in all of
24244 the Page Tables. An argument, an integer expression, given to the
24245 @kbd{info dos pde} command means display only that entry from the Page
24246 Directory table. An argument given to the @kbd{info dos pte} command
24247 means display entries from a single Page Table, the one pointed to by
24248 the specified entry in the Page Directory.
24249
24250 @cindex direct memory access (DMA) on MS-DOS
24251 These commands are useful when your program uses @dfn{DMA} (Direct
24252 Memory Access), which needs physical addresses to program the DMA
24253 controller.
24254
24255 These commands are supported only with some DPMI servers.
24256
24257 @cindex physical address from linear address
24258 @item info dos address-pte @var{addr}
24259 This command displays the Page Table entry for a specified linear
24260 address. The argument @var{addr} is a linear address which should
24261 already have the appropriate segment's base address added to it,
24262 because this command accepts addresses which may belong to @emph{any}
24263 segment. For example, here's how to display the Page Table entry for
24264 the page where a variable @code{i} is stored:
24265
24266 @smallexample
24267 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
24268 @exdent @code{Page Table entry for address 0x11a00d30:}
24269 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
24270 @end smallexample
24271
24272 @noindent
24273 This says that @code{i} is stored at offset @code{0xd30} from the page
24274 whose physical base address is @code{0x02698000}, and shows all the
24275 attributes of that page.
24276
24277 Note that you must cast the addresses of variables to a @code{char *},
24278 since otherwise the value of @code{__djgpp_base_address}, the base
24279 address of all variables and functions in a @sc{djgpp} program, will
24280 be added using the rules of C pointer arithmetics: if @code{i} is
24281 declared an @code{int}, @value{GDBN} will add 4 times the value of
24282 @code{__djgpp_base_address} to the address of @code{i}.
24283
24284 Here's another example, it displays the Page Table entry for the
24285 transfer buffer:
24286
24287 @smallexample
24288 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
24289 @exdent @code{Page Table entry for address 0x29110:}
24290 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
24291 @end smallexample
24292
24293 @noindent
24294 (The @code{+ 3} offset is because the transfer buffer's address is the
24295 3rd member of the @code{_go32_info_block} structure.) The output
24296 clearly shows that this DPMI server maps the addresses in conventional
24297 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
24298 linear (@code{0x29110}) addresses are identical.
24299
24300 This command is supported only with some DPMI servers.
24301 @end table
24302
24303 @cindex DOS serial data link, remote debugging
24304 In addition to native debugging, the DJGPP port supports remote
24305 debugging via a serial data link. The following commands are specific
24306 to remote serial debugging in the DJGPP port of @value{GDBN}.
24307
24308 @table @code
24309 @kindex set com1base
24310 @kindex set com1irq
24311 @kindex set com2base
24312 @kindex set com2irq
24313 @kindex set com3base
24314 @kindex set com3irq
24315 @kindex set com4base
24316 @kindex set com4irq
24317 @item set com1base @var{addr}
24318 This command sets the base I/O port address of the @file{COM1} serial
24319 port.
24320
24321 @item set com1irq @var{irq}
24322 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24323 for the @file{COM1} serial port.
24324
24325 There are similar commands @samp{set com2base}, @samp{set com3irq},
24326 etc.@: for setting the port address and the @code{IRQ} lines for the
24327 other 3 COM ports.
24328
24329 @kindex show com1base
24330 @kindex show com1irq
24331 @kindex show com2base
24332 @kindex show com2irq
24333 @kindex show com3base
24334 @kindex show com3irq
24335 @kindex show com4base
24336 @kindex show com4irq
24337 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24338 display the current settings of the base address and the @code{IRQ}
24339 lines used by the COM ports.
24340
24341 @item info serial
24342 @kindex info serial
24343 @cindex DOS serial port status
24344 This command prints the status of the 4 DOS serial ports. For each
24345 port, it prints whether it's active or not, its I/O base address and
24346 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24347 counts of various errors encountered so far.
24348 @end table
24349
24350
24351 @node Cygwin Native
24352 @subsection Features for Debugging MS Windows PE Executables
24353 @cindex MS Windows debugging
24354 @cindex native Cygwin debugging
24355 @cindex Cygwin-specific commands
24356
24357 @value{GDBN} supports native debugging of MS Windows programs, including
24358 DLLs with and without symbolic debugging information.
24359
24360 @cindex Ctrl-BREAK, MS-Windows
24361 @cindex interrupt debuggee on MS-Windows
24362 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24363 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24364 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24365 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24366 sequence, which can be used to interrupt the debuggee even if it
24367 ignores @kbd{C-c}.
24368
24369 There are various additional Cygwin-specific commands, described in
24370 this section. Working with DLLs that have no debugging symbols is
24371 described in @ref{Non-debug DLL Symbols}.
24372
24373 @table @code
24374 @kindex info w32
24375 @item info w32
24376 This is a prefix of MS Windows-specific commands which print
24377 information about the target system and important OS structures.
24378
24379 @item info w32 selector
24380 This command displays information returned by
24381 the Win32 API @code{GetThreadSelectorEntry} function.
24382 It takes an optional argument that is evaluated to
24383 a long value to give the information about this given selector.
24384 Without argument, this command displays information
24385 about the six segment registers.
24386
24387 @item info w32 thread-information-block
24388 This command displays thread specific information stored in the
24389 Thread Information Block (readable on the X86 CPU family using @code{$fs}
24390 selector for 32-bit programs and @code{$gs} for 64-bit programs).
24391
24392 @kindex signal-event
24393 @item signal-event @var{id}
24394 This command signals an event with user-provided @var{id}. Used to resume
24395 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24396
24397 To use it, create or edit the following keys in
24398 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24399 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24400 (for x86_64 versions):
24401
24402 @itemize @minus
24403 @item
24404 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
24405 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24406 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
24407
24408 The first @code{%ld} will be replaced by the process ID of the
24409 crashing process, the second @code{%ld} will be replaced by the ID of
24410 the event that blocks the crashing process, waiting for @value{GDBN}
24411 to attach.
24412
24413 @item
24414 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24415 make the system run debugger specified by the Debugger key
24416 automatically, @code{0} will cause a dialog box with ``OK'' and
24417 ``Cancel'' buttons to appear, which allows the user to either
24418 terminate the crashing process (OK) or debug it (Cancel).
24419 @end itemize
24420
24421 @kindex set cygwin-exceptions
24422 @cindex debugging the Cygwin DLL
24423 @cindex Cygwin DLL, debugging
24424 @item set cygwin-exceptions @var{mode}
24425 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24426 happen inside the Cygwin DLL. If @var{mode} is @code{off},
24427 @value{GDBN} will delay recognition of exceptions, and may ignore some
24428 exceptions which seem to be caused by internal Cygwin DLL
24429 ``bookkeeping''. This option is meant primarily for debugging the
24430 Cygwin DLL itself; the default value is @code{off} to avoid annoying
24431 @value{GDBN} users with false @code{SIGSEGV} signals.
24432
24433 @kindex show cygwin-exceptions
24434 @item show cygwin-exceptions
24435 Displays whether @value{GDBN} will break on exceptions that happen
24436 inside the Cygwin DLL itself.
24437
24438 @kindex set new-console
24439 @item set new-console @var{mode}
24440 If @var{mode} is @code{on} the debuggee will
24441 be started in a new console on next start.
24442 If @var{mode} is @code{off}, the debuggee will
24443 be started in the same console as the debugger.
24444
24445 @kindex show new-console
24446 @item show new-console
24447 Displays whether a new console is used
24448 when the debuggee is started.
24449
24450 @kindex set new-group
24451 @item set new-group @var{mode}
24452 This boolean value controls whether the debuggee should
24453 start a new group or stay in the same group as the debugger.
24454 This affects the way the Windows OS handles
24455 @samp{Ctrl-C}.
24456
24457 @kindex show new-group
24458 @item show new-group
24459 Displays current value of new-group boolean.
24460
24461 @kindex set debugevents
24462 @item set debugevents
24463 This boolean value adds debug output concerning kernel events related
24464 to the debuggee seen by the debugger. This includes events that
24465 signal thread and process creation and exit, DLL loading and
24466 unloading, console interrupts, and debugging messages produced by the
24467 Windows @code{OutputDebugString} API call.
24468
24469 @kindex set debugexec
24470 @item set debugexec
24471 This boolean value adds debug output concerning execute events
24472 (such as resume thread) seen by the debugger.
24473
24474 @kindex set debugexceptions
24475 @item set debugexceptions
24476 This boolean value adds debug output concerning exceptions in the
24477 debuggee seen by the debugger.
24478
24479 @kindex set debugmemory
24480 @item set debugmemory
24481 This boolean value adds debug output concerning debuggee memory reads
24482 and writes by the debugger.
24483
24484 @kindex set shell
24485 @item set shell
24486 This boolean values specifies whether the debuggee is called
24487 via a shell or directly (default value is on).
24488
24489 @kindex show shell
24490 @item show shell
24491 Displays if the debuggee will be started with a shell.
24492
24493 @end table
24494
24495 @menu
24496 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
24497 @end menu
24498
24499 @node Non-debug DLL Symbols
24500 @subsubsection Support for DLLs without Debugging Symbols
24501 @cindex DLLs with no debugging symbols
24502 @cindex Minimal symbols and DLLs
24503
24504 Very often on windows, some of the DLLs that your program relies on do
24505 not include symbolic debugging information (for example,
24506 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24507 symbols in a DLL, it relies on the minimal amount of symbolic
24508 information contained in the DLL's export table. This section
24509 describes working with such symbols, known internally to @value{GDBN} as
24510 ``minimal symbols''.
24511
24512 Note that before the debugged program has started execution, no DLLs
24513 will have been loaded. The easiest way around this problem is simply to
24514 start the program --- either by setting a breakpoint or letting the
24515 program run once to completion.
24516
24517 @subsubsection DLL Name Prefixes
24518
24519 In keeping with the naming conventions used by the Microsoft debugging
24520 tools, DLL export symbols are made available with a prefix based on the
24521 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24522 also entered into the symbol table, so @code{CreateFileA} is often
24523 sufficient. In some cases there will be name clashes within a program
24524 (particularly if the executable itself includes full debugging symbols)
24525 necessitating the use of the fully qualified name when referring to the
24526 contents of the DLL. Use single-quotes around the name to avoid the
24527 exclamation mark (``!'') being interpreted as a language operator.
24528
24529 Note that the internal name of the DLL may be all upper-case, even
24530 though the file name of the DLL is lower-case, or vice-versa. Since
24531 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24532 some confusion. If in doubt, try the @code{info functions} and
24533 @code{info variables} commands or even @code{maint print msymbols}
24534 (@pxref{Symbols}). Here's an example:
24535
24536 @smallexample
24537 (@value{GDBP}) info function CreateFileA
24538 All functions matching regular expression "CreateFileA":
24539
24540 Non-debugging symbols:
24541 0x77e885f4 CreateFileA
24542 0x77e885f4 KERNEL32!CreateFileA
24543 @end smallexample
24544
24545 @smallexample
24546 (@value{GDBP}) info function !
24547 All functions matching regular expression "!":
24548
24549 Non-debugging symbols:
24550 0x6100114c cygwin1!__assert
24551 0x61004034 cygwin1!_dll_crt0@@0
24552 0x61004240 cygwin1!dll_crt0(per_process *)
24553 [etc...]
24554 @end smallexample
24555
24556 @subsubsection Working with Minimal Symbols
24557
24558 Symbols extracted from a DLL's export table do not contain very much
24559 type information. All that @value{GDBN} can do is guess whether a symbol
24560 refers to a function or variable depending on the linker section that
24561 contains the symbol. Also note that the actual contents of the memory
24562 contained in a DLL are not available unless the program is running. This
24563 means that you cannot examine the contents of a variable or disassemble
24564 a function within a DLL without a running program.
24565
24566 Variables are generally treated as pointers and dereferenced
24567 automatically. For this reason, it is often necessary to prefix a
24568 variable name with the address-of operator (``&'') and provide explicit
24569 type information in the command. Here's an example of the type of
24570 problem:
24571
24572 @smallexample
24573 (@value{GDBP}) print 'cygwin1!__argv'
24574 'cygwin1!__argv' has unknown type; cast it to its declared type
24575 @end smallexample
24576
24577 @smallexample
24578 (@value{GDBP}) x 'cygwin1!__argv'
24579 'cygwin1!__argv' has unknown type; cast it to its declared type
24580 @end smallexample
24581
24582 And two possible solutions:
24583
24584 @smallexample
24585 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24586 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24587 @end smallexample
24588
24589 @smallexample
24590 (@value{GDBP}) x/2x &'cygwin1!__argv'
24591 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24592 (@value{GDBP}) x/x 0x10021608
24593 0x10021608: 0x0022fd98
24594 (@value{GDBP}) x/s 0x0022fd98
24595 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24596 @end smallexample
24597
24598 Setting a break point within a DLL is possible even before the program
24599 starts execution. However, under these circumstances, @value{GDBN} can't
24600 examine the initial instructions of the function in order to skip the
24601 function's frame set-up code. You can work around this by using ``*&''
24602 to set the breakpoint at a raw memory address:
24603
24604 @smallexample
24605 (@value{GDBP}) break *&'python22!PyOS_Readline'
24606 Breakpoint 1 at 0x1e04eff0
24607 @end smallexample
24608
24609 The author of these extensions is not entirely convinced that setting a
24610 break point within a shared DLL like @file{kernel32.dll} is completely
24611 safe.
24612
24613 @node Hurd Native
24614 @subsection Commands Specific to @sc{gnu} Hurd Systems
24615 @cindex @sc{gnu} Hurd debugging
24616
24617 This subsection describes @value{GDBN} commands specific to the
24618 @sc{gnu} Hurd native debugging.
24619
24620 @table @code
24621 @item set signals
24622 @itemx set sigs
24623 @kindex set signals@r{, Hurd command}
24624 @kindex set sigs@r{, Hurd command}
24625 This command toggles the state of inferior signal interception by
24626 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24627 affected by this command. @code{sigs} is a shorthand alias for
24628 @code{signals}.
24629
24630 @item show signals
24631 @itemx show sigs
24632 @kindex show signals@r{, Hurd command}
24633 @kindex show sigs@r{, Hurd command}
24634 Show the current state of intercepting inferior's signals.
24635
24636 @item set signal-thread
24637 @itemx set sigthread
24638 @kindex set signal-thread
24639 @kindex set sigthread
24640 This command tells @value{GDBN} which thread is the @code{libc} signal
24641 thread. That thread is run when a signal is delivered to a running
24642 process. @code{set sigthread} is the shorthand alias of @code{set
24643 signal-thread}.
24644
24645 @item show signal-thread
24646 @itemx show sigthread
24647 @kindex show signal-thread
24648 @kindex show sigthread
24649 These two commands show which thread will run when the inferior is
24650 delivered a signal.
24651
24652 @item set stopped
24653 @kindex set stopped@r{, Hurd command}
24654 This commands tells @value{GDBN} that the inferior process is stopped,
24655 as with the @code{SIGSTOP} signal. The stopped process can be
24656 continued by delivering a signal to it.
24657
24658 @item show stopped
24659 @kindex show stopped@r{, Hurd command}
24660 This command shows whether @value{GDBN} thinks the debuggee is
24661 stopped.
24662
24663 @item set exceptions
24664 @kindex set exceptions@r{, Hurd command}
24665 Use this command to turn off trapping of exceptions in the inferior.
24666 When exception trapping is off, neither breakpoints nor
24667 single-stepping will work. To restore the default, set exception
24668 trapping on.
24669
24670 @item show exceptions
24671 @kindex show exceptions@r{, Hurd command}
24672 Show the current state of trapping exceptions in the inferior.
24673
24674 @item set task pause
24675 @kindex set task@r{, Hurd commands}
24676 @cindex task attributes (@sc{gnu} Hurd)
24677 @cindex pause current task (@sc{gnu} Hurd)
24678 This command toggles task suspension when @value{GDBN} has control.
24679 Setting it to on takes effect immediately, and the task is suspended
24680 whenever @value{GDBN} gets control. Setting it to off will take
24681 effect the next time the inferior is continued. If this option is set
24682 to off, you can use @code{set thread default pause on} or @code{set
24683 thread pause on} (see below) to pause individual threads.
24684
24685 @item show task pause
24686 @kindex show task@r{, Hurd commands}
24687 Show the current state of task suspension.
24688
24689 @item set task detach-suspend-count
24690 @cindex task suspend count
24691 @cindex detach from task, @sc{gnu} Hurd
24692 This command sets the suspend count the task will be left with when
24693 @value{GDBN} detaches from it.
24694
24695 @item show task detach-suspend-count
24696 Show the suspend count the task will be left with when detaching.
24697
24698 @item set task exception-port
24699 @itemx set task excp
24700 @cindex task exception port, @sc{gnu} Hurd
24701 This command sets the task exception port to which @value{GDBN} will
24702 forward exceptions. The argument should be the value of the @dfn{send
24703 rights} of the task. @code{set task excp} is a shorthand alias.
24704
24705 @item set noninvasive
24706 @cindex noninvasive task options
24707 This command switches @value{GDBN} to a mode that is the least
24708 invasive as far as interfering with the inferior is concerned. This
24709 is the same as using @code{set task pause}, @code{set exceptions}, and
24710 @code{set signals} to values opposite to the defaults.
24711
24712 @item info send-rights
24713 @itemx info receive-rights
24714 @itemx info port-rights
24715 @itemx info port-sets
24716 @itemx info dead-names
24717 @itemx info ports
24718 @itemx info psets
24719 @cindex send rights, @sc{gnu} Hurd
24720 @cindex receive rights, @sc{gnu} Hurd
24721 @cindex port rights, @sc{gnu} Hurd
24722 @cindex port sets, @sc{gnu} Hurd
24723 @cindex dead names, @sc{gnu} Hurd
24724 These commands display information about, respectively, send rights,
24725 receive rights, port rights, port sets, and dead names of a task.
24726 There are also shorthand aliases: @code{info ports} for @code{info
24727 port-rights} and @code{info psets} for @code{info port-sets}.
24728
24729 @item set thread pause
24730 @kindex set thread@r{, Hurd command}
24731 @cindex thread properties, @sc{gnu} Hurd
24732 @cindex pause current thread (@sc{gnu} Hurd)
24733 This command toggles current thread suspension when @value{GDBN} has
24734 control. Setting it to on takes effect immediately, and the current
24735 thread is suspended whenever @value{GDBN} gets control. Setting it to
24736 off will take effect the next time the inferior is continued.
24737 Normally, this command has no effect, since when @value{GDBN} has
24738 control, the whole task is suspended. However, if you used @code{set
24739 task pause off} (see above), this command comes in handy to suspend
24740 only the current thread.
24741
24742 @item show thread pause
24743 @kindex show thread@r{, Hurd command}
24744 This command shows the state of current thread suspension.
24745
24746 @item set thread run
24747 This command sets whether the current thread is allowed to run.
24748
24749 @item show thread run
24750 Show whether the current thread is allowed to run.
24751
24752 @item set thread detach-suspend-count
24753 @cindex thread suspend count, @sc{gnu} Hurd
24754 @cindex detach from thread, @sc{gnu} Hurd
24755 This command sets the suspend count @value{GDBN} will leave on a
24756 thread when detaching. This number is relative to the suspend count
24757 found by @value{GDBN} when it notices the thread; use @code{set thread
24758 takeover-suspend-count} to force it to an absolute value.
24759
24760 @item show thread detach-suspend-count
24761 Show the suspend count @value{GDBN} will leave on the thread when
24762 detaching.
24763
24764 @item set thread exception-port
24765 @itemx set thread excp
24766 Set the thread exception port to which to forward exceptions. This
24767 overrides the port set by @code{set task exception-port} (see above).
24768 @code{set thread excp} is the shorthand alias.
24769
24770 @item set thread takeover-suspend-count
24771 Normally, @value{GDBN}'s thread suspend counts are relative to the
24772 value @value{GDBN} finds when it notices each thread. This command
24773 changes the suspend counts to be absolute instead.
24774
24775 @item set thread default
24776 @itemx show thread default
24777 @cindex thread default settings, @sc{gnu} Hurd
24778 Each of the above @code{set thread} commands has a @code{set thread
24779 default} counterpart (e.g., @code{set thread default pause}, @code{set
24780 thread default exception-port}, etc.). The @code{thread default}
24781 variety of commands sets the default thread properties for all
24782 threads; you can then change the properties of individual threads with
24783 the non-default commands.
24784 @end table
24785
24786 @node Darwin
24787 @subsection Darwin
24788 @cindex Darwin
24789
24790 @value{GDBN} provides the following commands specific to the Darwin target:
24791
24792 @table @code
24793 @item set debug darwin @var{num}
24794 @kindex set debug darwin
24795 When set to a non zero value, enables debugging messages specific to
24796 the Darwin support. Higher values produce more verbose output.
24797
24798 @item show debug darwin
24799 @kindex show debug darwin
24800 Show the current state of Darwin messages.
24801
24802 @item set debug mach-o @var{num}
24803 @kindex set debug mach-o
24804 When set to a non zero value, enables debugging messages while
24805 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24806 file format used on Darwin for object and executable files.) Higher
24807 values produce more verbose output. This is a command to diagnose
24808 problems internal to @value{GDBN} and should not be needed in normal
24809 usage.
24810
24811 @item show debug mach-o
24812 @kindex show debug mach-o
24813 Show the current state of Mach-O file messages.
24814
24815 @item set mach-exceptions on
24816 @itemx set mach-exceptions off
24817 @kindex set mach-exceptions
24818 On Darwin, faults are first reported as a Mach exception and are then
24819 mapped to a Posix signal. Use this command to turn on trapping of
24820 Mach exceptions in the inferior. This might be sometimes useful to
24821 better understand the cause of a fault. The default is off.
24822
24823 @item show mach-exceptions
24824 @kindex show mach-exceptions
24825 Show the current state of exceptions trapping.
24826 @end table
24827
24828 @node FreeBSD
24829 @subsection FreeBSD
24830 @cindex FreeBSD
24831
24832 When the ABI of a system call is changed in the FreeBSD kernel, this
24833 is implemented by leaving a compatibility system call using the old
24834 ABI at the existing number and allocating a new system call number for
24835 the version using the new ABI. As a convenience, when a system call
24836 is caught by name (@pxref{catch syscall}), compatibility system calls
24837 are also caught.
24838
24839 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24840 system call and catching the @code{kevent} system call by name catches
24841 both variants:
24842
24843 @smallexample
24844 (@value{GDBP}) catch syscall kevent
24845 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24846 (@value{GDBP})
24847 @end smallexample
24848
24849
24850 @node Embedded OS
24851 @section Embedded Operating Systems
24852
24853 This section describes configurations involving the debugging of
24854 embedded operating systems that are available for several different
24855 architectures.
24856
24857 @value{GDBN} includes the ability to debug programs running on
24858 various real-time operating systems.
24859
24860 @node Embedded Processors
24861 @section Embedded Processors
24862
24863 This section goes into details specific to particular embedded
24864 configurations.
24865
24866 @cindex send command to simulator
24867 Whenever a specific embedded processor has a simulator, @value{GDBN}
24868 allows to send an arbitrary command to the simulator.
24869
24870 @table @code
24871 @item sim @var{command}
24872 @kindex sim@r{, a command}
24873 Send an arbitrary @var{command} string to the simulator. Consult the
24874 documentation for the specific simulator in use for information about
24875 acceptable commands.
24876 @end table
24877
24878
24879 @menu
24880 * ARC:: Synopsys ARC
24881 * ARM:: ARM
24882 * BPF:: eBPF
24883 * M68K:: Motorola M68K
24884 * MicroBlaze:: Xilinx MicroBlaze
24885 * MIPS Embedded:: MIPS Embedded
24886 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24887 * PowerPC Embedded:: PowerPC Embedded
24888 * AVR:: Atmel AVR
24889 * CRIS:: CRIS
24890 * Super-H:: Renesas Super-H
24891 @end menu
24892
24893 @node ARC
24894 @subsection Synopsys ARC
24895 @cindex Synopsys ARC
24896 @cindex ARC specific commands
24897 @cindex ARC600
24898 @cindex ARC700
24899 @cindex ARC EM
24900 @cindex ARC HS
24901
24902 @value{GDBN} provides the following ARC-specific commands:
24903
24904 @table @code
24905 @item set debug arc
24906 @kindex set debug arc
24907 Control the level of ARC specific debug messages. Use 0 for no messages (the
24908 default), 1 for debug messages, and 2 for even more debug messages.
24909
24910 @item show debug arc
24911 @kindex show debug arc
24912 Show the level of ARC specific debugging in operation.
24913
24914 @item maint print arc arc-instruction @var{address}
24915 @kindex maint print arc arc-instruction
24916 Print internal disassembler information about instruction at a given address.
24917
24918 @end table
24919
24920 @node ARM
24921 @subsection ARM
24922
24923 @value{GDBN} provides the following ARM-specific commands:
24924
24925 @table @code
24926 @item set arm disassembler
24927 @kindex set arm
24928 This commands selects from a list of disassembly styles. The
24929 @code{"std"} style is the standard style.
24930
24931 @item show arm disassembler
24932 @kindex show arm
24933 Show the current disassembly style.
24934
24935 @item set arm apcs32
24936 @cindex ARM 32-bit mode
24937 This command toggles ARM operation mode between 32-bit and 26-bit.
24938
24939 @item show arm apcs32
24940 Display the current usage of the ARM 32-bit mode.
24941
24942 @item set arm fpu @var{fputype}
24943 This command sets the ARM floating-point unit (FPU) type. The
24944 argument @var{fputype} can be one of these:
24945
24946 @table @code
24947 @item auto
24948 Determine the FPU type by querying the OS ABI.
24949 @item softfpa
24950 Software FPU, with mixed-endian doubles on little-endian ARM
24951 processors.
24952 @item fpa
24953 GCC-compiled FPA co-processor.
24954 @item softvfp
24955 Software FPU with pure-endian doubles.
24956 @item vfp
24957 VFP co-processor.
24958 @end table
24959
24960 @item show arm fpu
24961 Show the current type of the FPU.
24962
24963 @item set arm abi
24964 This command forces @value{GDBN} to use the specified ABI.
24965
24966 @item show arm abi
24967 Show the currently used ABI.
24968
24969 @item set arm fallback-mode (arm|thumb|auto)
24970 @value{GDBN} uses the symbol table, when available, to determine
24971 whether instructions are ARM or Thumb. This command controls
24972 @value{GDBN}'s default behavior when the symbol table is not
24973 available. The default is @samp{auto}, which causes @value{GDBN} to
24974 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24975 register).
24976
24977 @item show arm fallback-mode
24978 Show the current fallback instruction mode.
24979
24980 @item set arm force-mode (arm|thumb|auto)
24981 This command overrides use of the symbol table to determine whether
24982 instructions are ARM or Thumb. The default is @samp{auto}, which
24983 causes @value{GDBN} to use the symbol table and then the setting
24984 of @samp{set arm fallback-mode}.
24985
24986 @item show arm force-mode
24987 Show the current forced instruction mode.
24988
24989 @item set debug arm
24990 Toggle whether to display ARM-specific debugging messages from the ARM
24991 target support subsystem.
24992
24993 @item show debug arm
24994 Show whether ARM-specific debugging messages are enabled.
24995 @end table
24996
24997 @table @code
24998 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24999 The @value{GDBN} ARM simulator accepts the following optional arguments.
25000
25001 @table @code
25002 @item --swi-support=@var{type}
25003 Tell the simulator which SWI interfaces to support. The argument
25004 @var{type} may be a comma separated list of the following values.
25005 The default value is @code{all}.
25006
25007 @table @code
25008 @item none
25009 @item demon
25010 @item angel
25011 @item redboot
25012 @item all
25013 @end table
25014 @end table
25015 @end table
25016
25017 @node BPF
25018 @subsection BPF
25019
25020 @table @code
25021 @item target sim @r{[}@var{simargs}@r{]} @dots{}
25022 The @value{GDBN} BPF simulator accepts the following optional arguments.
25023
25024 @table @code
25025 @item --skb-data-offset=@var{offset}
25026 Tell the simulator the offset, measured in bytes, of the
25027 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
25028 This offset is used by some BPF specific-purpose load/store
25029 instructions. Defaults to 0.
25030 @end table
25031 @end table
25032
25033 @node M68K
25034 @subsection M68k
25035
25036 The Motorola m68k configuration includes ColdFire support.
25037
25038 @node MicroBlaze
25039 @subsection MicroBlaze
25040 @cindex Xilinx MicroBlaze
25041 @cindex XMD, Xilinx Microprocessor Debugger
25042
25043 The MicroBlaze is a soft-core processor supported on various Xilinx
25044 FPGAs, such as Spartan or Virtex series. Boards with these processors
25045 usually have JTAG ports which connect to a host system running the Xilinx
25046 Embedded Development Kit (EDK) or Software Development Kit (SDK).
25047 This host system is used to download the configuration bitstream to
25048 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
25049 communicates with the target board using the JTAG interface and
25050 presents a @code{gdbserver} interface to the board. By default
25051 @code{xmd} uses port @code{1234}. (While it is possible to change
25052 this default port, it requires the use of undocumented @code{xmd}
25053 commands. Contact Xilinx support if you need to do this.)
25054
25055 Use these GDB commands to connect to the MicroBlaze target processor.
25056
25057 @table @code
25058 @item target remote :1234
25059 Use this command to connect to the target if you are running @value{GDBN}
25060 on the same system as @code{xmd}.
25061
25062 @item target remote @var{xmd-host}:1234
25063 Use this command to connect to the target if it is connected to @code{xmd}
25064 running on a different system named @var{xmd-host}.
25065
25066 @item load
25067 Use this command to download a program to the MicroBlaze target.
25068
25069 @item set debug microblaze @var{n}
25070 Enable MicroBlaze-specific debugging messages if non-zero.
25071
25072 @item show debug microblaze @var{n}
25073 Show MicroBlaze-specific debugging level.
25074 @end table
25075
25076 @node MIPS Embedded
25077 @subsection @acronym{MIPS} Embedded
25078
25079 @noindent
25080 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
25081
25082 @table @code
25083 @item set mipsfpu double
25084 @itemx set mipsfpu single
25085 @itemx set mipsfpu none
25086 @itemx set mipsfpu auto
25087 @itemx show mipsfpu
25088 @kindex set mipsfpu
25089 @kindex show mipsfpu
25090 @cindex @acronym{MIPS} remote floating point
25091 @cindex floating point, @acronym{MIPS} remote
25092 If your target board does not support the @acronym{MIPS} floating point
25093 coprocessor, you should use the command @samp{set mipsfpu none} (if you
25094 need this, you may wish to put the command in your @value{GDBN} init
25095 file). This tells @value{GDBN} how to find the return value of
25096 functions which return floating point values. It also allows
25097 @value{GDBN} to avoid saving the floating point registers when calling
25098 functions on the board. If you are using a floating point coprocessor
25099 with only single precision floating point support, as on the @sc{r4650}
25100 processor, use the command @samp{set mipsfpu single}. The default
25101 double precision floating point coprocessor may be selected using
25102 @samp{set mipsfpu double}.
25103
25104 In previous versions the only choices were double precision or no
25105 floating point, so @samp{set mipsfpu on} will select double precision
25106 and @samp{set mipsfpu off} will select no floating point.
25107
25108 As usual, you can inquire about the @code{mipsfpu} variable with
25109 @samp{show mipsfpu}.
25110 @end table
25111
25112 @node OpenRISC 1000
25113 @subsection OpenRISC 1000
25114 @cindex OpenRISC 1000
25115
25116 @noindent
25117 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
25118 mainly provided as a soft-core which can run on Xilinx, Altera and other
25119 FPGA's.
25120
25121 @value{GDBN} for OpenRISC supports the below commands when connecting to
25122 a target:
25123
25124 @table @code
25125
25126 @kindex target sim
25127 @item target sim
25128
25129 Runs the builtin CPU simulator which can run very basic
25130 programs but does not support most hardware functions like MMU.
25131 For more complex use cases the user is advised to run an external
25132 target, and connect using @samp{target remote}.
25133
25134 Example: @code{target sim}
25135
25136 @item set debug or1k
25137 Toggle whether to display OpenRISC-specific debugging messages from the
25138 OpenRISC target support subsystem.
25139
25140 @item show debug or1k
25141 Show whether OpenRISC-specific debugging messages are enabled.
25142 @end table
25143
25144 @node PowerPC Embedded
25145 @subsection PowerPC Embedded
25146
25147 @cindex DVC register
25148 @value{GDBN} supports using the DVC (Data Value Compare) register to
25149 implement in hardware simple hardware watchpoint conditions of the form:
25150
25151 @smallexample
25152 (@value{GDBP}) watch @var{address|variable} \
25153 if @var{address|variable} == @var{constant expression}
25154 @end smallexample
25155
25156 The DVC register will be automatically used when @value{GDBN} detects
25157 such pattern in a condition expression, and the created watchpoint uses one
25158 debug register (either the @code{exact-watchpoints} option is on and the
25159 variable is scalar, or the variable has a length of one byte). This feature
25160 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
25161 or newer.
25162
25163 When running on PowerPC embedded processors, @value{GDBN} automatically uses
25164 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
25165 in which case watchpoints using only one debug register are created when
25166 watching variables of scalar types.
25167
25168 You can create an artificial array to watch an arbitrary memory
25169 region using one of the following commands (@pxref{Expressions}):
25170
25171 @smallexample
25172 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
25173 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
25174 @end smallexample
25175
25176 PowerPC embedded processors support masked watchpoints. See the discussion
25177 about the @code{mask} argument in @ref{Set Watchpoints}.
25178
25179 @cindex ranged breakpoint
25180 PowerPC embedded processors support hardware accelerated
25181 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
25182 the inferior whenever it executes an instruction at any address within
25183 the range it specifies. To set a ranged breakpoint in @value{GDBN},
25184 use the @code{break-range} command.
25185
25186 @value{GDBN} provides the following PowerPC-specific commands:
25187
25188 @table @code
25189 @kindex break-range
25190 @item break-range @var{start-location}, @var{end-location}
25191 Set a breakpoint for an address range given by
25192 @var{start-location} and @var{end-location}, which can specify a function name,
25193 a line number, an offset of lines from the current line or from the start
25194 location, or an address of an instruction (see @ref{Specify Location},
25195 for a list of all the possible ways to specify a @var{location}.)
25196 The breakpoint will stop execution of the inferior whenever it
25197 executes an instruction at any address within the specified range,
25198 (including @var{start-location} and @var{end-location}.)
25199
25200 @kindex set powerpc
25201 @item set powerpc soft-float
25202 @itemx show powerpc soft-float
25203 Force @value{GDBN} to use (or not use) a software floating point calling
25204 convention. By default, @value{GDBN} selects the calling convention based
25205 on the selected architecture and the provided executable file.
25206
25207 @item set powerpc vector-abi
25208 @itemx show powerpc vector-abi
25209 Force @value{GDBN} to use the specified calling convention for vector
25210 arguments and return values. The valid options are @samp{auto};
25211 @samp{generic}, to avoid vector registers even if they are present;
25212 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
25213 registers. By default, @value{GDBN} selects the calling convention
25214 based on the selected architecture and the provided executable file.
25215
25216 @item set powerpc exact-watchpoints
25217 @itemx show powerpc exact-watchpoints
25218 Allow @value{GDBN} to use only one debug register when watching a variable
25219 of scalar type, thus assuming that the variable is accessed through the
25220 address of its first byte.
25221
25222 @end table
25223
25224 @node AVR
25225 @subsection Atmel AVR
25226 @cindex AVR
25227
25228 When configured for debugging the Atmel AVR, @value{GDBN} supports the
25229 following AVR-specific commands:
25230
25231 @table @code
25232 @item info io_registers
25233 @kindex info io_registers@r{, AVR}
25234 @cindex I/O registers (Atmel AVR)
25235 This command displays information about the AVR I/O registers. For
25236 each register, @value{GDBN} prints its number and value.
25237 @end table
25238
25239 @node CRIS
25240 @subsection CRIS
25241 @cindex CRIS
25242
25243 When configured for debugging CRIS, @value{GDBN} provides the
25244 following CRIS-specific commands:
25245
25246 @table @code
25247 @item set cris-version @var{ver}
25248 @cindex CRIS version
25249 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
25250 The CRIS version affects register names and sizes. This command is useful in
25251 case autodetection of the CRIS version fails.
25252
25253 @item show cris-version
25254 Show the current CRIS version.
25255
25256 @item set cris-dwarf2-cfi
25257 @cindex DWARF-2 CFI and CRIS
25258 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
25259 Change to @samp{off} when using @code{gcc-cris} whose version is below
25260 @code{R59}.
25261
25262 @item show cris-dwarf2-cfi
25263 Show the current state of using DWARF-2 CFI.
25264
25265 @item set cris-mode @var{mode}
25266 @cindex CRIS mode
25267 Set the current CRIS mode to @var{mode}. It should only be changed when
25268 debugging in guru mode, in which case it should be set to
25269 @samp{guru} (the default is @samp{normal}).
25270
25271 @item show cris-mode
25272 Show the current CRIS mode.
25273 @end table
25274
25275 @node Super-H
25276 @subsection Renesas Super-H
25277 @cindex Super-H
25278
25279 For the Renesas Super-H processor, @value{GDBN} provides these
25280 commands:
25281
25282 @table @code
25283 @item set sh calling-convention @var{convention}
25284 @kindex set sh calling-convention
25285 Set the calling-convention used when calling functions from @value{GDBN}.
25286 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
25287 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
25288 convention. If the DWARF-2 information of the called function specifies
25289 that the function follows the Renesas calling convention, the function
25290 is called using the Renesas calling convention. If the calling convention
25291 is set to @samp{renesas}, the Renesas calling convention is always used,
25292 regardless of the DWARF-2 information. This can be used to override the
25293 default of @samp{gcc} if debug information is missing, or the compiler
25294 does not emit the DWARF-2 calling convention entry for a function.
25295
25296 @item show sh calling-convention
25297 @kindex show sh calling-convention
25298 Show the current calling convention setting.
25299
25300 @end table
25301
25302
25303 @node Architectures
25304 @section Architectures
25305
25306 This section describes characteristics of architectures that affect
25307 all uses of @value{GDBN} with the architecture, both native and cross.
25308
25309 @menu
25310 * AArch64::
25311 * i386::
25312 * Alpha::
25313 * MIPS::
25314 * HPPA:: HP PA architecture
25315 * PowerPC::
25316 * Nios II::
25317 * Sparc64::
25318 * S12Z::
25319 @end menu
25320
25321 @node AArch64
25322 @subsection AArch64
25323 @cindex AArch64 support
25324
25325 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25326 following special commands:
25327
25328 @table @code
25329 @item set debug aarch64
25330 @kindex set debug aarch64
25331 This command determines whether AArch64 architecture-specific debugging
25332 messages are to be displayed.
25333
25334 @item show debug aarch64
25335 Show whether AArch64 debugging messages are displayed.
25336
25337 @end table
25338
25339 @subsubsection AArch64 SVE.
25340 @cindex AArch64 SVE.
25341
25342 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25343 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25344 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25345 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25346 @code{$vg} will be provided. This is the vector granule for the current thread
25347 and represents the number of 64-bit chunks in an SVE @code{z} register.
25348
25349 If the vector length changes, then the @code{$vg} register will be updated,
25350 but the lengths of the @code{z} and @code{p} registers will not change. This
25351 is a known limitation of @value{GDBN} and does not affect the execution of the
25352 target process.
25353
25354 @subsubsection AArch64 Pointer Authentication.
25355 @cindex AArch64 Pointer Authentication.
25356
25357 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25358 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25359 register @code{$lr} is pointing to an PAC function its value will be masked.
25360 When GDB prints a backtrace, any addresses that required unmasking will be
25361 postfixed with the marker [PAC]. When using the MI, this is printed as part
25362 of the @code{addr_flags} field.
25363
25364 @subsubsection AArch64 Memory Tagging Extension.
25365 @cindex AArch64 Memory Tagging Extension.
25366
25367 When @value{GDBN} is debugging the AArch64 architecture, the program is
25368 using the v8.5-A feature Memory Tagging Extension (MTE) and there is support
25369 in the kernel for MTE, @value{GDBN} will make memory tagging functionality
25370 available for inspection and editing of logical and allocation tags.
25371 @xref{Memory Tagging}.
25372
25373 To aid debugging, @value{GDBN} will output additional information when SIGSEGV
25374 signals are generated as a result of memory tag failures.
25375
25376 If the tag violation is synchronous, the following will be shown:
25377
25378 @smallexample
25379 Program received signal SIGSEGV, Segmentation fault
25380 Memory tag violation while accessing address 0x0500fffff7ff8000
25381 Allocation tag 0x1
25382 Logical tag 0x5.
25383 @end smallexample
25384
25385 If the tag violation is asynchronous, the fault address is not available.
25386 In this case @value{GDBN} will show the following:
25387
25388 @smallexample
25389 Program received signal SIGSEGV, Segmentation fault
25390 Memory tag violation
25391 Fault address unavailable.
25392 @end smallexample
25393
25394 A special register, @code{tag_ctl}, is made available through the
25395 @code{org.gnu.gdb.aarch64.mte} feature. This register exposes some
25396 options that can be controlled at runtime and emulates the @code{prctl}
25397 option @code{PR_SET_TAGGED_ADDR_CTRL}. For further information, see the
25398 documentation in the Linux kernel.
25399
25400 @node i386
25401 @subsection x86 Architecture-specific Issues
25402
25403 @table @code
25404 @item set struct-convention @var{mode}
25405 @kindex set struct-convention
25406 @cindex struct return convention
25407 @cindex struct/union returned in registers
25408 Set the convention used by the inferior to return @code{struct}s and
25409 @code{union}s from functions to @var{mode}. Possible values of
25410 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25411 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25412 are returned on the stack, while @code{"reg"} means that a
25413 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25414 be returned in a register.
25415
25416 @item show struct-convention
25417 @kindex show struct-convention
25418 Show the current setting of the convention to return @code{struct}s
25419 from functions.
25420 @end table
25421
25422
25423 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25424 @cindex Intel Memory Protection Extensions (MPX).
25425
25426 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25427 @footnote{The register named with capital letters represent the architecture
25428 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25429 which are the lower bound and upper bound. Bounds are effective addresses or
25430 memory locations. The upper bounds are architecturally represented in 1's
25431 complement form. A bound having lower bound = 0, and upper bound = 0
25432 (1's complement of all bits set) will allow access to the entire address space.
25433
25434 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25435 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25436 display the upper bound performing the complement of one operation on the
25437 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25438 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25439 can also be noted that the upper bounds are inclusive.
25440
25441 As an example, assume that the register BND0 holds bounds for a pointer having
25442 access allowed for the range between 0x32 and 0x71. The values present on
25443 bnd0raw and bnd registers are presented as follows:
25444
25445 @smallexample
25446 bnd0raw = @{0x32, 0xffffffff8e@}
25447 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25448 @end smallexample
25449
25450 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25451 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25452 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25453 Python, the display includes the memory size, in bits, accessible to
25454 the pointer.
25455
25456 Bounds can also be stored in bounds tables, which are stored in
25457 application memory. These tables store bounds for pointers by specifying
25458 the bounds pointer's value along with its bounds. Evaluating and changing
25459 bounds located in bound tables is therefore interesting while investigating
25460 bugs on MPX context. @value{GDBN} provides commands for this purpose:
25461
25462 @table @code
25463 @item show mpx bound @var{pointer}
25464 @kindex show mpx bound
25465 Display bounds of the given @var{pointer}.
25466
25467 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25468 @kindex set mpx bound
25469 Set the bounds of a pointer in the bound table.
25470 This command takes three parameters: @var{pointer} is the pointers
25471 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25472 for lower and upper bounds respectively.
25473 @end table
25474
25475 When you call an inferior function on an Intel MPX enabled program,
25476 GDB sets the inferior's bound registers to the init (disabled) state
25477 before calling the function. As a consequence, bounds checks for the
25478 pointer arguments passed to the function will always pass.
25479
25480 This is necessary because when you call an inferior function, the
25481 program is usually in the middle of the execution of other function.
25482 Since at that point bound registers are in an arbitrary state, not
25483 clearing them would lead to random bound violations in the called
25484 function.
25485
25486 You can still examine the influence of the bound registers on the
25487 execution of the called function by stopping the execution of the
25488 called function at its prologue, setting bound registers, and
25489 continuing the execution. For example:
25490
25491 @smallexample
25492 $ break *upper
25493 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25494 $ print upper (a, b, c, d, 1)
25495 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25496 $ print $bnd0
25497 @{lbound = 0x0, ubound = ffffffff@} : size -1
25498 @end smallexample
25499
25500 At this last step the value of bnd0 can be changed for investigation of bound
25501 violations caused along the execution of the call. In order to know how to
25502 set the bound registers or bound table for the call consult the ABI.
25503
25504 @node Alpha
25505 @subsection Alpha
25506
25507 See the following section.
25508
25509 @node MIPS
25510 @subsection @acronym{MIPS}
25511
25512 @cindex stack on Alpha
25513 @cindex stack on @acronym{MIPS}
25514 @cindex Alpha stack
25515 @cindex @acronym{MIPS} stack
25516 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25517 sometimes requires @value{GDBN} to search backward in the object code to
25518 find the beginning of a function.
25519
25520 @cindex response time, @acronym{MIPS} debugging
25521 To improve response time (especially for embedded applications, where
25522 @value{GDBN} may be restricted to a slow serial line for this search)
25523 you may want to limit the size of this search, using one of these
25524 commands:
25525
25526 @table @code
25527 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25528 @item set heuristic-fence-post @var{limit}
25529 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25530 search for the beginning of a function. A value of @var{0} (the
25531 default) means there is no limit. However, except for @var{0}, the
25532 larger the limit the more bytes @code{heuristic-fence-post} must search
25533 and therefore the longer it takes to run. You should only need to use
25534 this command when debugging a stripped executable.
25535
25536 @item show heuristic-fence-post
25537 Display the current limit.
25538 @end table
25539
25540 @noindent
25541 These commands are available @emph{only} when @value{GDBN} is configured
25542 for debugging programs on Alpha or @acronym{MIPS} processors.
25543
25544 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25545 programs:
25546
25547 @table @code
25548 @item set mips abi @var{arg}
25549 @kindex set mips abi
25550 @cindex set ABI for @acronym{MIPS}
25551 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
25552 values of @var{arg} are:
25553
25554 @table @samp
25555 @item auto
25556 The default ABI associated with the current binary (this is the
25557 default).
25558 @item o32
25559 @item o64
25560 @item n32
25561 @item n64
25562 @item eabi32
25563 @item eabi64
25564 @end table
25565
25566 @item show mips abi
25567 @kindex show mips abi
25568 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25569
25570 @item set mips compression @var{arg}
25571 @kindex set mips compression
25572 @cindex code compression, @acronym{MIPS}
25573 Tell @value{GDBN} which @acronym{MIPS} compressed
25574 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25575 inferior. @value{GDBN} uses this for code disassembly and other
25576 internal interpretation purposes. This setting is only referred to
25577 when no executable has been associated with the debugging session or
25578 the executable does not provide information about the encoding it uses.
25579 Otherwise this setting is automatically updated from information
25580 provided by the executable.
25581
25582 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25583 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25584 executables containing @acronym{MIPS16} code frequently are not
25585 identified as such.
25586
25587 This setting is ``sticky''; that is, it retains its value across
25588 debugging sessions until reset either explicitly with this command or
25589 implicitly from an executable.
25590
25591 The compiler and/or assembler typically add symbol table annotations to
25592 identify functions compiled for the @acronym{MIPS16} or
25593 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25594 are present, @value{GDBN} uses them in preference to the global
25595 compressed @acronym{ISA} encoding setting.
25596
25597 @item show mips compression
25598 @kindex show mips compression
25599 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25600 @value{GDBN} to debug the inferior.
25601
25602 @item set mipsfpu
25603 @itemx show mipsfpu
25604 @xref{MIPS Embedded, set mipsfpu}.
25605
25606 @item set mips mask-address @var{arg}
25607 @kindex set mips mask-address
25608 @cindex @acronym{MIPS} addresses, masking
25609 This command determines whether the most-significant 32 bits of 64-bit
25610 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25611 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25612 setting, which lets @value{GDBN} determine the correct value.
25613
25614 @item show mips mask-address
25615 @kindex show mips mask-address
25616 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25617 not.
25618
25619 @item set remote-mips64-transfers-32bit-regs
25620 @kindex set remote-mips64-transfers-32bit-regs
25621 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25622 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25623 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25624 and 64 bits for other registers, set this option to @samp{on}.
25625
25626 @item show remote-mips64-transfers-32bit-regs
25627 @kindex show remote-mips64-transfers-32bit-regs
25628 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25629
25630 @item set debug mips
25631 @kindex set debug mips
25632 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25633 target code in @value{GDBN}.
25634
25635 @item show debug mips
25636 @kindex show debug mips
25637 Show the current setting of @acronym{MIPS} debugging messages.
25638 @end table
25639
25640
25641 @node HPPA
25642 @subsection HPPA
25643 @cindex HPPA support
25644
25645 When @value{GDBN} is debugging the HP PA architecture, it provides the
25646 following special commands:
25647
25648 @table @code
25649 @item set debug hppa
25650 @kindex set debug hppa
25651 This command determines whether HPPA architecture-specific debugging
25652 messages are to be displayed.
25653
25654 @item show debug hppa
25655 Show whether HPPA debugging messages are displayed.
25656
25657 @item maint print unwind @var{address}
25658 @kindex maint print unwind@r{, HPPA}
25659 This command displays the contents of the unwind table entry at the
25660 given @var{address}.
25661
25662 @end table
25663
25664
25665 @node PowerPC
25666 @subsection PowerPC
25667 @cindex PowerPC architecture
25668
25669 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25670 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25671 numbers stored in the floating point registers. These values must be stored
25672 in two consecutive registers, always starting at an even register like
25673 @code{f0} or @code{f2}.
25674
25675 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25676 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25677 @code{f2} and @code{f3} for @code{$dl1} and so on.
25678
25679 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25680 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25681
25682 @node Nios II
25683 @subsection Nios II
25684 @cindex Nios II architecture
25685
25686 When @value{GDBN} is debugging the Nios II architecture,
25687 it provides the following special commands:
25688
25689 @table @code
25690
25691 @item set debug nios2
25692 @kindex set debug nios2
25693 This command turns on and off debugging messages for the Nios II
25694 target code in @value{GDBN}.
25695
25696 @item show debug nios2
25697 @kindex show debug nios2
25698 Show the current setting of Nios II debugging messages.
25699 @end table
25700
25701 @node Sparc64
25702 @subsection Sparc64
25703 @cindex Sparc64 support
25704 @cindex Application Data Integrity
25705 @subsubsection ADI Support
25706
25707 The M7 processor supports an Application Data Integrity (ADI) feature that
25708 detects invalid data accesses. When software allocates memory and enables
25709 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25710 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25711 the 4-bit version in every cacheline of that data. Hardware saves the latter
25712 in spare bits in the cache and memory hierarchy. On each load and store,
25713 the processor compares the upper 4 VA (virtual address) bits to the
25714 cacheline's version. If there is a mismatch, the processor generates a
25715 version mismatch trap which can be either precise or disrupting. The trap
25716 is an error condition which the kernel delivers to the process as a SIGSEGV
25717 signal.
25718
25719 Note that only 64-bit applications can use ADI and need to be built with
25720 ADI-enabled.
25721
25722 Values of the ADI version tags, which are in granularity of a
25723 cacheline (64 bytes), can be viewed or modified.
25724
25725
25726 @table @code
25727 @kindex adi examine
25728 @item adi (examine | x) [ / @var{n} ] @var{addr}
25729
25730 The @code{adi examine} command displays the value of one ADI version tag per
25731 cacheline.
25732
25733 @var{n} is a decimal integer specifying the number in bytes; the default
25734 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25735 block size, to display.
25736
25737 @var{addr} is the address in user address space where you want @value{GDBN}
25738 to begin displaying the ADI version tags.
25739
25740 Below is an example of displaying ADI versions of variable "shmaddr".
25741
25742 @smallexample
25743 (@value{GDBP}) adi x/100 shmaddr
25744 0xfff800010002c000: 0 0
25745 @end smallexample
25746
25747 @kindex adi assign
25748 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25749
25750 The @code{adi assign} command is used to assign new ADI version tag
25751 to an address.
25752
25753 @var{n} is a decimal integer specifying the number in bytes;
25754 the default is 1. It specifies how much ADI version information, at the
25755 ratio of 1:ADI block size, to modify.
25756
25757 @var{addr} is the address in user address space where you want @value{GDBN}
25758 to begin modifying the ADI version tags.
25759
25760 @var{tag} is the new ADI version tag.
25761
25762 For example, do the following to modify then verify ADI versions of
25763 variable "shmaddr":
25764
25765 @smallexample
25766 (@value{GDBP}) adi a/100 shmaddr = 7
25767 (@value{GDBP}) adi x/100 shmaddr
25768 0xfff800010002c000: 7 7
25769 @end smallexample
25770
25771 @end table
25772
25773 @node S12Z
25774 @subsection S12Z
25775 @cindex S12Z support
25776
25777 When @value{GDBN} is debugging the S12Z architecture,
25778 it provides the following special command:
25779
25780 @table @code
25781 @item maint info bdccsr
25782 @kindex maint info bdccsr@r{, S12Z}
25783 This command displays the current value of the microprocessor's
25784 BDCCSR register.
25785 @end table
25786
25787
25788 @node Controlling GDB
25789 @chapter Controlling @value{GDBN}
25790
25791 You can alter the way @value{GDBN} interacts with you by using the
25792 @code{set} command. For commands controlling how @value{GDBN} displays
25793 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25794 described here.
25795
25796 @menu
25797 * Prompt:: Prompt
25798 * Editing:: Command editing
25799 * Command History:: Command history
25800 * Screen Size:: Screen size
25801 * Output Styling:: Output styling
25802 * Numbers:: Numbers
25803 * ABI:: Configuring the current ABI
25804 * Auto-loading:: Automatically loading associated files
25805 * Messages/Warnings:: Optional warnings and messages
25806 * Debugging Output:: Optional messages about internal happenings
25807 * Other Misc Settings:: Other Miscellaneous Settings
25808 @end menu
25809
25810 @node Prompt
25811 @section Prompt
25812
25813 @cindex prompt
25814
25815 @value{GDBN} indicates its readiness to read a command by printing a string
25816 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25817 can change the prompt string with the @code{set prompt} command. For
25818 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25819 the prompt in one of the @value{GDBN} sessions so that you can always tell
25820 which one you are talking to.
25821
25822 @emph{Note:} @code{set prompt} does not add a space for you after the
25823 prompt you set. This allows you to set a prompt which ends in a space
25824 or a prompt that does not.
25825
25826 @table @code
25827 @kindex set prompt
25828 @item set prompt @var{newprompt}
25829 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25830
25831 @kindex show prompt
25832 @item show prompt
25833 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25834 @end table
25835
25836 Versions of @value{GDBN} that ship with Python scripting enabled have
25837 prompt extensions. The commands for interacting with these extensions
25838 are:
25839
25840 @table @code
25841 @kindex set extended-prompt
25842 @item set extended-prompt @var{prompt}
25843 Set an extended prompt that allows for substitutions.
25844 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25845 substitution. Any escape sequences specified as part of the prompt
25846 string are replaced with the corresponding strings each time the prompt
25847 is displayed.
25848
25849 For example:
25850
25851 @smallexample
25852 set extended-prompt Current working directory: \w (gdb)
25853 @end smallexample
25854
25855 Note that when an extended-prompt is set, it takes control of the
25856 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25857
25858 @kindex show extended-prompt
25859 @item show extended-prompt
25860 Prints the extended prompt. Any escape sequences specified as part of
25861 the prompt string with @code{set extended-prompt}, are replaced with the
25862 corresponding strings each time the prompt is displayed.
25863 @end table
25864
25865 @node Editing
25866 @section Command Editing
25867 @cindex readline
25868 @cindex command line editing
25869
25870 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25871 @sc{gnu} library provides consistent behavior for programs which provide a
25872 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25873 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25874 substitution, and a storage and recall of command history across
25875 debugging sessions.
25876
25877 You may control the behavior of command line editing in @value{GDBN} with the
25878 command @code{set}.
25879
25880 @table @code
25881 @kindex set editing
25882 @cindex editing
25883 @item set editing
25884 @itemx set editing on
25885 Enable command line editing (enabled by default).
25886
25887 @item set editing off
25888 Disable command line editing.
25889
25890 @kindex show editing
25891 @item show editing
25892 Show whether command line editing is enabled.
25893 @end table
25894
25895 @ifset SYSTEM_READLINE
25896 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25897 @end ifset
25898 @ifclear SYSTEM_READLINE
25899 @xref{Command Line Editing},
25900 @end ifclear
25901 for more details about the Readline
25902 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25903 encouraged to read that chapter.
25904
25905 @cindex Readline application name
25906 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25907 is useful for conditions in @file{.inputrc}.
25908
25909 @cindex operate-and-get-next
25910 @value{GDBN} defines a bindable Readline command,
25911 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25912 This command accepts the current line for execution and fetches the
25913 next line relative to the current line from the history for editing.
25914 Any argument is ignored.
25915
25916 @node Command History
25917 @section Command History
25918 @cindex command history
25919
25920 @value{GDBN} can keep track of the commands you type during your
25921 debugging sessions, so that you can be certain of precisely what
25922 happened. Use these commands to manage the @value{GDBN} command
25923 history facility.
25924
25925 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25926 package, to provide the history facility.
25927 @ifset SYSTEM_READLINE
25928 @xref{Using History Interactively, , , history, GNU History Library},
25929 @end ifset
25930 @ifclear SYSTEM_READLINE
25931 @xref{Using History Interactively},
25932 @end ifclear
25933 for the detailed description of the History library.
25934
25935 To issue a command to @value{GDBN} without affecting certain aspects of
25936 the state which is seen by users, prefix it with @samp{server }
25937 (@pxref{Server Prefix}). This
25938 means that this command will not affect the command history, nor will it
25939 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25940 pressed on a line by itself.
25941
25942 @cindex @code{server}, command prefix
25943 The server prefix does not affect the recording of values into the value
25944 history; to print a value without recording it into the value history,
25945 use the @code{output} command instead of the @code{print} command.
25946
25947 Here is the description of @value{GDBN} commands related to command
25948 history.
25949
25950 @table @code
25951 @cindex history substitution
25952 @cindex history file
25953 @kindex set history filename
25954 @cindex @env{GDBHISTFILE}, environment variable
25955 @item set history filename @r{[}@var{fname}@r{]}
25956 Set the name of the @value{GDBN} command history file to @var{fname}.
25957 This is the file where @value{GDBN} reads an initial command history
25958 list, and where it writes the command history from this session when it
25959 exits. You can access this list through history expansion or through
25960 the history command editing characters listed below. This file defaults
25961 to the value of the environment variable @env{GDBHISTFILE}, or to
25962 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25963 is not set.
25964
25965 The @env{GDBHISTFILE} environment variable is read after processing
25966 any @value{GDBN} initialization files (@pxref{Startup}) and after
25967 processing any commands passed using command line options (for
25968 example, @code{-ex}).
25969
25970 If the @var{fname} argument is not given, or if the @env{GDBHISTFILE}
25971 is the empty string then @value{GDBN} will neither try to load an
25972 existing history file, nor will it try to save the history on exit.
25973
25974 @cindex save command history
25975 @kindex set history save
25976 @item set history save
25977 @itemx set history save on
25978 Record command history in a file, whose name may be specified with the
25979 @code{set history filename} command. By default, this option is
25980 disabled. The command history will be recorded when @value{GDBN}
25981 exits. If @code{set history filename} is set to the empty string then
25982 history saving is disabled, even when @code{set history save} is
25983 @code{on}.
25984
25985 @item set history save off
25986 Don't record the command history into the file specified by @code{set
25987 history filename} when @value{GDBN} exits.
25988
25989 @cindex history size
25990 @kindex set history size
25991 @cindex @env{GDBHISTSIZE}, environment variable
25992 @item set history size @var{size}
25993 @itemx set history size unlimited
25994 Set the number of commands which @value{GDBN} keeps in its history list.
25995 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25996 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25997 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25998 either a negative number or the empty string, then the number of commands
25999 @value{GDBN} keeps in the history list is unlimited.
26000
26001 The @env{GDBHISTSIZE} environment variable is read after processing
26002 any @value{GDBN} initialization files (@pxref{Startup}) and after
26003 processing any commands passed using command line options (for
26004 example, @code{-ex}).
26005
26006 @cindex remove duplicate history
26007 @kindex set history remove-duplicates
26008 @item set history remove-duplicates @var{count}
26009 @itemx set history remove-duplicates unlimited
26010 Control the removal of duplicate history entries in the command history list.
26011 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
26012 history entries and remove the first entry that is a duplicate of the current
26013 entry being added to the command history list. If @var{count} is
26014 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
26015 removal of duplicate history entries is disabled.
26016
26017 Only history entries added during the current session are considered for
26018 removal. This option is set to 0 by default.
26019
26020 @end table
26021
26022 History expansion assigns special meaning to the character @kbd{!}.
26023 @ifset SYSTEM_READLINE
26024 @xref{Event Designators, , , history, GNU History Library},
26025 @end ifset
26026 @ifclear SYSTEM_READLINE
26027 @xref{Event Designators},
26028 @end ifclear
26029 for more details.
26030
26031 @cindex history expansion, turn on/off
26032 Since @kbd{!} is also the logical not operator in C, history expansion
26033 is off by default. If you decide to enable history expansion with the
26034 @code{set history expansion on} command, you may sometimes need to
26035 follow @kbd{!} (when it is used as logical not, in an expression) with
26036 a space or a tab to prevent it from being expanded. The readline
26037 history facilities do not attempt substitution on the strings
26038 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
26039
26040 The commands to control history expansion are:
26041
26042 @table @code
26043 @item set history expansion on
26044 @itemx set history expansion
26045 @kindex set history expansion
26046 Enable history expansion. History expansion is off by default.
26047
26048 @item set history expansion off
26049 Disable history expansion.
26050
26051 @c @group
26052 @kindex show history
26053 @item show history
26054 @itemx show history filename
26055 @itemx show history save
26056 @itemx show history size
26057 @itemx show history expansion
26058 These commands display the state of the @value{GDBN} history parameters.
26059 @code{show history} by itself displays all four states.
26060 @c @end group
26061 @end table
26062
26063 @table @code
26064 @kindex show commands
26065 @cindex show last commands
26066 @cindex display command history
26067 @item show commands
26068 Display the last ten commands in the command history.
26069
26070 @item show commands @var{n}
26071 Print ten commands centered on command number @var{n}.
26072
26073 @item show commands +
26074 Print ten commands just after the commands last printed.
26075 @end table
26076
26077 @node Screen Size
26078 @section Screen Size
26079 @cindex size of screen
26080 @cindex screen size
26081 @cindex pagination
26082 @cindex page size
26083 @cindex pauses in output
26084
26085 Certain commands to @value{GDBN} may produce large amounts of
26086 information output to the screen. To help you read all of it,
26087 @value{GDBN} pauses and asks you for input at the end of each page of
26088 output. Type @key{RET} when you want to see one more page of output,
26089 @kbd{q} to discard the remaining output, or @kbd{c} to continue
26090 without paging for the rest of the current command. Also, the screen
26091 width setting determines when to wrap lines of output. Depending on
26092 what is being printed, @value{GDBN} tries to break the line at a
26093 readable place, rather than simply letting it overflow onto the
26094 following line.
26095
26096 Normally @value{GDBN} knows the size of the screen from the terminal
26097 driver software. For example, on Unix @value{GDBN} uses the termcap data base
26098 together with the value of the @env{TERM} environment variable and the
26099 @code{stty rows} and @code{stty cols} settings. If this is not correct,
26100 you can override it with the @code{set height} and @code{set
26101 width} commands:
26102
26103 @table @code
26104 @kindex set height
26105 @kindex set width
26106 @kindex show width
26107 @kindex show height
26108 @item set height @var{lpp}
26109 @itemx set height unlimited
26110 @itemx show height
26111 @itemx set width @var{cpl}
26112 @itemx set width unlimited
26113 @itemx show width
26114 These @code{set} commands specify a screen height of @var{lpp} lines and
26115 a screen width of @var{cpl} characters. The associated @code{show}
26116 commands display the current settings.
26117
26118 If you specify a height of either @code{unlimited} or zero lines,
26119 @value{GDBN} does not pause during output no matter how long the
26120 output is. This is useful if output is to a file or to an editor
26121 buffer.
26122
26123 Likewise, you can specify @samp{set width unlimited} or @samp{set
26124 width 0} to prevent @value{GDBN} from wrapping its output.
26125
26126 @item set pagination on
26127 @itemx set pagination off
26128 @kindex set pagination
26129 Turn the output pagination on or off; the default is on. Turning
26130 pagination off is the alternative to @code{set height unlimited}. Note that
26131 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
26132 Options, -batch}) also automatically disables pagination.
26133
26134 @item show pagination
26135 @kindex show pagination
26136 Show the current pagination mode.
26137 @end table
26138
26139 @node Output Styling
26140 @section Output Styling
26141 @cindex styling
26142 @cindex colors
26143
26144 @kindex set style
26145 @kindex show style
26146 @value{GDBN} can style its output on a capable terminal. This is
26147 enabled by default on most systems, but disabled by default when in
26148 batch mode (@pxref{Mode Options}). Various style settings are available;
26149 and styles can also be disabled entirely.
26150
26151 @table @code
26152 @item set style enabled @samp{on|off}
26153 Enable or disable all styling. The default is host-dependent, with
26154 most hosts defaulting to @samp{on}.
26155
26156 @item show style enabled
26157 Show the current state of styling.
26158
26159 @item set style sources @samp{on|off}
26160 Enable or disable source code styling. This affects whether source
26161 code, such as the output of the @code{list} command, is styled. The
26162 default is @samp{on}. Note that source styling only works if styling
26163 in general is enabled, and if a source highlighting library is
26164 available to @value{GDBN}.
26165
26166 There are two ways that highlighting can be done. First, if
26167 @value{GDBN} was linked with the GNU Source Highlight library, then it
26168 is used. Otherwise, if @value{GDBN} was configured with Python
26169 scripting support, and if the Python Pygments package is available,
26170 then it will be used.
26171
26172 @item show style sources
26173 Show the current state of source code styling.
26174
26175 @item set style disassembler enabled @samp{on|off}
26176 Enable or disable disassembler styling. This affects whether
26177 disassembler output, such as the output of the @code{disassemble}
26178 command, is styled. Disassembler styling only works if styling in
26179 general is enabled (with @code{set style enabled on}), and if a source
26180 highlighting library is available to @value{GDBN}.
26181
26182 To highlight disassembler output, @value{GDBN} must be compiled with
26183 Python support, and the Python Pygments package must be available. If
26184 these requirements are not met then @value{GDBN} will not highlight
26185 disassembler output, even when this option is @samp{on}.
26186
26187 @item show style disassembler enabled
26188 Show the current state of disassembler styling.
26189 @end table
26190
26191 Subcommands of @code{set style} control specific forms of styling.
26192 These subcommands all follow the same pattern: each style-able object
26193 can be styled with a foreground color, a background color, and an
26194 intensity.
26195
26196 For example, the style of file names can be controlled using the
26197 @code{set style filename} group of commands:
26198
26199 @table @code
26200 @item set style filename background @var{color}
26201 Set the background to @var{color}. Valid colors are @samp{none}
26202 (meaning the terminal's default color), @samp{black}, @samp{red},
26203 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26204 and@samp{white}.
26205
26206 @item set style filename foreground @var{color}
26207 Set the foreground to @var{color}. Valid colors are @samp{none}
26208 (meaning the terminal's default color), @samp{black}, @samp{red},
26209 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26210 and@samp{white}.
26211
26212 @item set style filename intensity @var{value}
26213 Set the intensity to @var{value}. Valid intensities are @samp{normal}
26214 (the default), @samp{bold}, and @samp{dim}.
26215 @end table
26216
26217 The @code{show style} command and its subcommands are styling
26218 a style name in their output using its own style.
26219 So, use @command{show style} to see the complete list of styles,
26220 their characteristics and the visual aspect of each style.
26221
26222 The style-able objects are:
26223 @table @code
26224 @item filename
26225 Control the styling of file names. By default, this style's
26226 foreground color is green.
26227
26228 @item function
26229 Control the styling of function names. These are managed with the
26230 @code{set style function} family of commands. By default, this
26231 style's foreground color is yellow.
26232
26233 @item variable
26234 Control the styling of variable names. These are managed with the
26235 @code{set style variable} family of commands. By default, this style's
26236 foreground color is cyan.
26237
26238 @item address
26239 Control the styling of addresses. These are managed with the
26240 @code{set style address} family of commands. By default, this style's
26241 foreground color is blue.
26242
26243 @item version
26244 Control the styling of @value{GDBN}'s version number text. By
26245 default, this style's foreground color is magenta and it has bold
26246 intensity. The version number is displayed in two places, the output
26247 of @command{show version}, and when @value{GDBN} starts up.
26248
26249 In order to control how @value{GDBN} styles the version number at
26250 startup, add the @code{set style version} family of commands to the
26251 early initialization command file (@pxref{Initialization
26252 Files}).
26253
26254 @item title
26255 Control the styling of titles. These are managed with the
26256 @code{set style title} family of commands. By default, this style's
26257 intensity is bold. Commands are using the title style to improve
26258 the readability of large output. For example, the commands
26259 @command{apropos} and @command{help} are using the title style
26260 for the command names.
26261
26262 @item highlight
26263 Control the styling of highlightings. These are managed with the
26264 @code{set style highlight} family of commands. By default, this style's
26265 foreground color is red. Commands are using the highlight style to draw
26266 the user attention to some specific parts of their output. For example,
26267 the command @command{apropos -v REGEXP} uses the highlight style to
26268 mark the documentation parts matching @var{regexp}.
26269
26270 @item tui-border
26271 Control the styling of the TUI border. Note that, unlike other
26272 styling options, only the color of the border can be controlled via
26273 @code{set style}. This was done for compatibility reasons, as TUI
26274 controls to set the border's intensity predated the addition of
26275 general styling to @value{GDBN}. @xref{TUI Configuration}.
26276
26277 @item tui-active-border
26278 Control the styling of the active TUI border; that is, the TUI window
26279 that has the focus.
26280
26281 @end table
26282
26283 @node Numbers
26284 @section Numbers
26285 @cindex number representation
26286 @cindex entering numbers
26287
26288 You can always enter numbers in octal, decimal, or hexadecimal in
26289 @value{GDBN} by the usual conventions: octal numbers begin with
26290 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
26291 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
26292 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
26293 10; likewise, the default display for numbers---when no particular
26294 format is specified---is base 10. You can change the default base for
26295 both input and output with the commands described below.
26296
26297 @table @code
26298 @kindex set input-radix
26299 @item set input-radix @var{base}
26300 Set the default base for numeric input. Supported choices
26301 for @var{base} are decimal 8, 10, or 16. The base must itself be
26302 specified either unambiguously or using the current input radix; for
26303 example, any of
26304
26305 @smallexample
26306 set input-radix 012
26307 set input-radix 10.
26308 set input-radix 0xa
26309 @end smallexample
26310
26311 @noindent
26312 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
26313 leaves the input radix unchanged, no matter what it was, since
26314 @samp{10}, being without any leading or trailing signs of its base, is
26315 interpreted in the current radix. Thus, if the current radix is 16,
26316 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
26317 change the radix.
26318
26319 @kindex set output-radix
26320 @item set output-radix @var{base}
26321 Set the default base for numeric display. Supported choices
26322 for @var{base} are decimal 8, 10, or 16. The base must itself be
26323 specified either unambiguously or using the current input radix.
26324
26325 @kindex show input-radix
26326 @item show input-radix
26327 Display the current default base for numeric input.
26328
26329 @kindex show output-radix
26330 @item show output-radix
26331 Display the current default base for numeric display.
26332
26333 @item set radix @r{[}@var{base}@r{]}
26334 @itemx show radix
26335 @kindex set radix
26336 @kindex show radix
26337 These commands set and show the default base for both input and output
26338 of numbers. @code{set radix} sets the radix of input and output to
26339 the same base; without an argument, it resets the radix back to its
26340 default value of 10.
26341
26342 @end table
26343
26344 @node ABI
26345 @section Configuring the Current ABI
26346
26347 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
26348 application automatically. However, sometimes you need to override its
26349 conclusions. Use these commands to manage @value{GDBN}'s view of the
26350 current ABI.
26351
26352 @cindex OS ABI
26353 @kindex set osabi
26354 @kindex show osabi
26355 @cindex Newlib OS ABI and its influence on the longjmp handling
26356
26357 One @value{GDBN} configuration can debug binaries for multiple operating
26358 system targets, either via remote debugging or native emulation.
26359 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
26360 but you can override its conclusion using the @code{set osabi} command.
26361 One example where this is useful is in debugging of binaries which use
26362 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
26363 not have the same identifying marks that the standard C library for your
26364 platform provides.
26365
26366 When @value{GDBN} is debugging the AArch64 architecture, it provides a
26367 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
26368 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
26369 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
26370
26371 @table @code
26372 @item show osabi
26373 Show the OS ABI currently in use.
26374
26375 @item set osabi
26376 With no argument, show the list of registered available OS ABI's.
26377
26378 @item set osabi @var{abi}
26379 Set the current OS ABI to @var{abi}.
26380 @end table
26381
26382 @cindex float promotion
26383
26384 Generally, the way that an argument of type @code{float} is passed to a
26385 function depends on whether the function is prototyped. For a prototyped
26386 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26387 according to the architecture's convention for @code{float}. For unprototyped
26388 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26389 @code{double} and then passed.
26390
26391 Unfortunately, some forms of debug information do not reliably indicate whether
26392 a function is prototyped. If @value{GDBN} calls a function that is not marked
26393 as prototyped, it consults @kbd{set coerce-float-to-double}.
26394
26395 @table @code
26396 @kindex set coerce-float-to-double
26397 @item set coerce-float-to-double
26398 @itemx set coerce-float-to-double on
26399 Arguments of type @code{float} will be promoted to @code{double} when passed
26400 to an unprototyped function. This is the default setting.
26401
26402 @item set coerce-float-to-double off
26403 Arguments of type @code{float} will be passed directly to unprototyped
26404 functions.
26405
26406 @kindex show coerce-float-to-double
26407 @item show coerce-float-to-double
26408 Show the current setting of promoting @code{float} to @code{double}.
26409 @end table
26410
26411 @kindex set cp-abi
26412 @kindex show cp-abi
26413 @value{GDBN} needs to know the ABI used for your program's C@t{++}
26414 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26415 used to build your application. @value{GDBN} only fully supports
26416 programs with a single C@t{++} ABI; if your program contains code using
26417 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26418 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26419 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26420 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26421 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26422 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26423 ``auto''.
26424
26425 @table @code
26426 @item show cp-abi
26427 Show the C@t{++} ABI currently in use.
26428
26429 @item set cp-abi
26430 With no argument, show the list of supported C@t{++} ABI's.
26431
26432 @item set cp-abi @var{abi}
26433 @itemx set cp-abi auto
26434 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26435 @end table
26436
26437 @node Auto-loading
26438 @section Automatically loading associated files
26439 @cindex auto-loading
26440
26441 @value{GDBN} sometimes reads files with commands and settings automatically,
26442 without being explicitly told so by the user. We call this feature
26443 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
26444 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
26445 results or introduce security risks (e.g., if the file comes from untrusted
26446 sources).
26447
26448 There are various kinds of files @value{GDBN} can automatically load.
26449 In addition to these files, @value{GDBN} supports auto-loading code written
26450 in various extension languages. @xref{Auto-loading extensions}.
26451
26452 Note that loading of these associated files (including the local @file{.gdbinit}
26453 file) requires accordingly configured @code{auto-load safe-path}
26454 (@pxref{Auto-loading safe path}).
26455
26456 For these reasons, @value{GDBN} includes commands and options to let you
26457 control when to auto-load files and which files should be auto-loaded.
26458
26459 @table @code
26460 @anchor{set auto-load off}
26461 @kindex set auto-load off
26462 @item set auto-load off
26463 Globally disable loading of all auto-loaded files.
26464 You may want to use this command with the @samp{-iex} option
26465 (@pxref{Option -init-eval-command}) such as:
26466 @smallexample
26467 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26468 @end smallexample
26469
26470 Be aware that system init file (@pxref{System-wide configuration})
26471 and init files from your home directory (@pxref{Home Directory Init File})
26472 still get read (as they come from generally trusted directories).
26473 To prevent @value{GDBN} from auto-loading even those init files, use the
26474 @option{-nx} option (@pxref{Mode Options}), in addition to
26475 @code{set auto-load no}.
26476
26477 @anchor{show auto-load}
26478 @kindex show auto-load
26479 @item show auto-load
26480 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26481 or disabled.
26482
26483 @smallexample
26484 (gdb) show auto-load
26485 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26486 libthread-db: Auto-loading of inferior specific libthread_db is on.
26487 local-gdbinit: Auto-loading of .gdbinit script from current directory
26488 is on.
26489 python-scripts: Auto-loading of Python scripts is on.
26490 safe-path: List of directories from which it is safe to auto-load files
26491 is $debugdir:$datadir/auto-load.
26492 scripts-directory: List of directories from which to load auto-loaded scripts
26493 is $debugdir:$datadir/auto-load.
26494 @end smallexample
26495
26496 @anchor{info auto-load}
26497 @kindex info auto-load
26498 @item info auto-load
26499 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26500 not.
26501
26502 @smallexample
26503 (gdb) info auto-load
26504 gdb-scripts:
26505 Loaded Script
26506 Yes /home/user/gdb/gdb-gdb.gdb
26507 libthread-db: No auto-loaded libthread-db.
26508 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26509 loaded.
26510 python-scripts:
26511 Loaded Script
26512 Yes /home/user/gdb/gdb-gdb.py
26513 @end smallexample
26514 @end table
26515
26516 These are @value{GDBN} control commands for the auto-loading:
26517
26518 @multitable @columnfractions .5 .5
26519 @item @xref{set auto-load off}.
26520 @tab Disable auto-loading globally.
26521 @item @xref{show auto-load}.
26522 @tab Show setting of all kinds of files.
26523 @item @xref{info auto-load}.
26524 @tab Show state of all kinds of files.
26525 @item @xref{set auto-load gdb-scripts}.
26526 @tab Control for @value{GDBN} command scripts.
26527 @item @xref{show auto-load gdb-scripts}.
26528 @tab Show setting of @value{GDBN} command scripts.
26529 @item @xref{info auto-load gdb-scripts}.
26530 @tab Show state of @value{GDBN} command scripts.
26531 @item @xref{set auto-load python-scripts}.
26532 @tab Control for @value{GDBN} Python scripts.
26533 @item @xref{show auto-load python-scripts}.
26534 @tab Show setting of @value{GDBN} Python scripts.
26535 @item @xref{info auto-load python-scripts}.
26536 @tab Show state of @value{GDBN} Python scripts.
26537 @item @xref{set auto-load guile-scripts}.
26538 @tab Control for @value{GDBN} Guile scripts.
26539 @item @xref{show auto-load guile-scripts}.
26540 @tab Show setting of @value{GDBN} Guile scripts.
26541 @item @xref{info auto-load guile-scripts}.
26542 @tab Show state of @value{GDBN} Guile scripts.
26543 @item @xref{set auto-load scripts-directory}.
26544 @tab Control for @value{GDBN} auto-loaded scripts location.
26545 @item @xref{show auto-load scripts-directory}.
26546 @tab Show @value{GDBN} auto-loaded scripts location.
26547 @item @xref{add-auto-load-scripts-directory}.
26548 @tab Add directory for auto-loaded scripts location list.
26549 @item @xref{set auto-load local-gdbinit}.
26550 @tab Control for init file in the current directory.
26551 @item @xref{show auto-load local-gdbinit}.
26552 @tab Show setting of init file in the current directory.
26553 @item @xref{info auto-load local-gdbinit}.
26554 @tab Show state of init file in the current directory.
26555 @item @xref{set auto-load libthread-db}.
26556 @tab Control for thread debugging library.
26557 @item @xref{show auto-load libthread-db}.
26558 @tab Show setting of thread debugging library.
26559 @item @xref{info auto-load libthread-db}.
26560 @tab Show state of thread debugging library.
26561 @item @xref{set auto-load safe-path}.
26562 @tab Control directories trusted for automatic loading.
26563 @item @xref{show auto-load safe-path}.
26564 @tab Show directories trusted for automatic loading.
26565 @item @xref{add-auto-load-safe-path}.
26566 @tab Add directory trusted for automatic loading.
26567 @end multitable
26568
26569 @menu
26570 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26571 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26572
26573 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26574 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
26575 @end menu
26576
26577 @node Init File in the Current Directory
26578 @subsection Automatically loading init file in the current directory
26579 @cindex auto-loading init file in the current directory
26580
26581 By default, @value{GDBN} reads and executes the canned sequences of commands
26582 from init file (if any) in the current working directory,
26583 see @ref{Init File in the Current Directory during Startup}.
26584
26585 Note that loading of this local @file{.gdbinit} file also requires accordingly
26586 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26587
26588 @table @code
26589 @anchor{set auto-load local-gdbinit}
26590 @kindex set auto-load local-gdbinit
26591 @item set auto-load local-gdbinit [on|off]
26592 Enable or disable the auto-loading of canned sequences of commands
26593 (@pxref{Sequences}) found in init file in the current directory.
26594
26595 @anchor{show auto-load local-gdbinit}
26596 @kindex show auto-load local-gdbinit
26597 @item show auto-load local-gdbinit
26598 Show whether auto-loading of canned sequences of commands from init file in the
26599 current directory is enabled or disabled.
26600
26601 @anchor{info auto-load local-gdbinit}
26602 @kindex info auto-load local-gdbinit
26603 @item info auto-load local-gdbinit
26604 Print whether canned sequences of commands from init file in the
26605 current directory have been auto-loaded.
26606 @end table
26607
26608 @node libthread_db.so.1 file
26609 @subsection Automatically loading thread debugging library
26610 @cindex auto-loading libthread_db.so.1
26611
26612 This feature is currently present only on @sc{gnu}/Linux native hosts.
26613
26614 @value{GDBN} reads in some cases thread debugging library from places specific
26615 to the inferior (@pxref{set libthread-db-search-path}).
26616
26617 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26618 without checking this @samp{set auto-load libthread-db} switch as system
26619 libraries have to be trusted in general. In all other cases of
26620 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26621 auto-load libthread-db} is enabled before trying to open such thread debugging
26622 library.
26623
26624 Note that loading of this debugging library also requires accordingly configured
26625 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26626
26627 @table @code
26628 @anchor{set auto-load libthread-db}
26629 @kindex set auto-load libthread-db
26630 @item set auto-load libthread-db [on|off]
26631 Enable or disable the auto-loading of inferior specific thread debugging library.
26632
26633 @anchor{show auto-load libthread-db}
26634 @kindex show auto-load libthread-db
26635 @item show auto-load libthread-db
26636 Show whether auto-loading of inferior specific thread debugging library is
26637 enabled or disabled.
26638
26639 @anchor{info auto-load libthread-db}
26640 @kindex info auto-load libthread-db
26641 @item info auto-load libthread-db
26642 Print the list of all loaded inferior specific thread debugging libraries and
26643 for each such library print list of inferior @var{pid}s using it.
26644 @end table
26645
26646 @node Auto-loading safe path
26647 @subsection Security restriction for auto-loading
26648 @cindex auto-loading safe-path
26649
26650 As the files of inferior can come from untrusted source (such as submitted by
26651 an application user) @value{GDBN} does not always load any files automatically.
26652 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26653 directories trusted for loading files not explicitly requested by user.
26654 Each directory can also be a shell wildcard pattern.
26655
26656 If the path is not set properly you will see a warning and the file will not
26657 get loaded:
26658
26659 @smallexample
26660 $ ./gdb -q ./gdb
26661 Reading symbols from /home/user/gdb/gdb...
26662 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26663 declined by your `auto-load safe-path' set
26664 to "$debugdir:$datadir/auto-load".
26665 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26666 declined by your `auto-load safe-path' set
26667 to "$debugdir:$datadir/auto-load".
26668 @end smallexample
26669
26670 @noindent
26671 To instruct @value{GDBN} to go ahead and use the init files anyway,
26672 invoke @value{GDBN} like this:
26673
26674 @smallexample
26675 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26676 @end smallexample
26677
26678 The list of trusted directories is controlled by the following commands:
26679
26680 @table @code
26681 @anchor{set auto-load safe-path}
26682 @kindex set auto-load safe-path
26683 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26684 Set the list of directories (and their subdirectories) trusted for automatic
26685 loading and execution of scripts. You can also enter a specific trusted file.
26686 Each directory can also be a shell wildcard pattern; wildcards do not match
26687 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26688 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26689 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26690 its default value as specified during @value{GDBN} compilation.
26691
26692 The list of directories uses path separator (@samp{:} on GNU and Unix
26693 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26694 to the @env{PATH} environment variable.
26695
26696 @anchor{show auto-load safe-path}
26697 @kindex show auto-load safe-path
26698 @item show auto-load safe-path
26699 Show the list of directories trusted for automatic loading and execution of
26700 scripts.
26701
26702 @anchor{add-auto-load-safe-path}
26703 @kindex add-auto-load-safe-path
26704 @item add-auto-load-safe-path
26705 Add an entry (or list of entries) to the list of directories trusted for
26706 automatic loading and execution of scripts. Multiple entries may be delimited
26707 by the host platform path separator in use.
26708 @end table
26709
26710 This variable defaults to what @code{--with-auto-load-dir} has been configured
26711 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26712 substitution applies the same as for @ref{set auto-load scripts-directory}.
26713 The default @code{set auto-load safe-path} value can be also overriden by
26714 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26715
26716 Setting this variable to @file{/} disables this security protection,
26717 corresponding @value{GDBN} configuration option is
26718 @option{--without-auto-load-safe-path}.
26719 This variable is supposed to be set to the system directories writable by the
26720 system superuser only. Users can add their source directories in init files in
26721 their home directories (@pxref{Home Directory Init File}). See also deprecated
26722 init file in the current directory
26723 (@pxref{Init File in the Current Directory during Startup}).
26724
26725 To force @value{GDBN} to load the files it declined to load in the previous
26726 example, you could use one of the following ways:
26727
26728 @table @asis
26729 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26730 Specify this trusted directory (or a file) as additional component of the list.
26731 You have to specify also any existing directories displayed by
26732 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26733
26734 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26735 Specify this directory as in the previous case but just for a single
26736 @value{GDBN} session.
26737
26738 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26739 Disable auto-loading safety for a single @value{GDBN} session.
26740 This assumes all the files you debug during this @value{GDBN} session will come
26741 from trusted sources.
26742
26743 @item @kbd{./configure --without-auto-load-safe-path}
26744 During compilation of @value{GDBN} you may disable any auto-loading safety.
26745 This assumes all the files you will ever debug with this @value{GDBN} come from
26746 trusted sources.
26747 @end table
26748
26749 On the other hand you can also explicitly forbid automatic files loading which
26750 also suppresses any such warning messages:
26751
26752 @table @asis
26753 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26754 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26755
26756 @item @file{~/.gdbinit}: @samp{set auto-load no}
26757 Disable auto-loading globally for the user
26758 (@pxref{Home Directory Init File}). While it is improbable, you could also
26759 use system init file instead (@pxref{System-wide configuration}).
26760 @end table
26761
26762 This setting applies to the file names as entered by user. If no entry matches
26763 @value{GDBN} tries as a last resort to also resolve all the file names into
26764 their canonical form (typically resolving symbolic links) and compare the
26765 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26766 own before starting the comparison so a canonical form of directories is
26767 recommended to be entered.
26768
26769 @node Auto-loading verbose mode
26770 @subsection Displaying files tried for auto-load
26771 @cindex auto-loading verbose mode
26772
26773 For better visibility of all the file locations where you can place scripts to
26774 be auto-loaded with inferior --- or to protect yourself against accidental
26775 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26776 all the files attempted to be loaded. Both existing and non-existing files may
26777 be printed.
26778
26779 For example the list of directories from which it is safe to auto-load files
26780 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26781 may not be too obvious while setting it up.
26782
26783 @smallexample
26784 (gdb) set debug auto-load on
26785 (gdb) file ~/src/t/true
26786 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26787 for objfile "/tmp/true".
26788 auto-load: Updating directories of "/usr:/opt".
26789 auto-load: Using directory "/usr".
26790 auto-load: Using directory "/opt".
26791 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26792 by your `auto-load safe-path' set to "/usr:/opt".
26793 @end smallexample
26794
26795 @table @code
26796 @anchor{set debug auto-load}
26797 @kindex set debug auto-load
26798 @item set debug auto-load [on|off]
26799 Set whether to print the filenames attempted to be auto-loaded.
26800
26801 @anchor{show debug auto-load}
26802 @kindex show debug auto-load
26803 @item show debug auto-load
26804 Show whether printing of the filenames attempted to be auto-loaded is turned
26805 on or off.
26806 @end table
26807
26808 @node Messages/Warnings
26809 @section Optional Warnings and Messages
26810
26811 @cindex verbose operation
26812 @cindex optional warnings
26813 By default, @value{GDBN} is silent about its inner workings. If you are
26814 running on a slow machine, you may want to use the @code{set verbose}
26815 command. This makes @value{GDBN} tell you when it does a lengthy
26816 internal operation, so you will not think it has crashed.
26817
26818 Currently, the messages controlled by @code{set verbose} are those
26819 which announce that the symbol table for a source file is being read;
26820 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26821
26822 @table @code
26823 @kindex set verbose
26824 @item set verbose on
26825 Enables @value{GDBN} output of certain informational messages.
26826
26827 @item set verbose off
26828 Disables @value{GDBN} output of certain informational messages.
26829
26830 @kindex show verbose
26831 @item show verbose
26832 Displays whether @code{set verbose} is on or off.
26833 @end table
26834
26835 By default, if @value{GDBN} encounters bugs in the symbol table of an
26836 object file, it is silent; but if you are debugging a compiler, you may
26837 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26838 Symbol Files}).
26839
26840 @table @code
26841
26842 @kindex set complaints
26843 @item set complaints @var{limit}
26844 Permits @value{GDBN} to output @var{limit} complaints about each type of
26845 unusual symbols before becoming silent about the problem. Set
26846 @var{limit} to zero to suppress all complaints; set it to a large number
26847 to prevent complaints from being suppressed.
26848
26849 @kindex show complaints
26850 @item show complaints
26851 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26852
26853 @end table
26854
26855 @anchor{confirmation requests}
26856 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26857 lot of stupid questions to confirm certain commands. For example, if
26858 you try to run a program which is already running:
26859
26860 @smallexample
26861 (@value{GDBP}) run
26862 The program being debugged has been started already.
26863 Start it from the beginning? (y or n)
26864 @end smallexample
26865
26866 If you are willing to unflinchingly face the consequences of your own
26867 commands, you can disable this ``feature'':
26868
26869 @table @code
26870
26871 @kindex set confirm
26872 @cindex flinching
26873 @cindex confirmation
26874 @cindex stupid questions
26875 @item set confirm off
26876 Disables confirmation requests. Note that running @value{GDBN} with
26877 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26878 automatically disables confirmation requests.
26879
26880 @item set confirm on
26881 Enables confirmation requests (the default).
26882
26883 @kindex show confirm
26884 @item show confirm
26885 Displays state of confirmation requests.
26886
26887 @end table
26888
26889 @cindex command tracing
26890 If you need to debug user-defined commands or sourced files you may find it
26891 useful to enable @dfn{command tracing}. In this mode each command will be
26892 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26893 quantity denoting the call depth of each command.
26894
26895 @table @code
26896 @kindex set trace-commands
26897 @cindex command scripts, debugging
26898 @item set trace-commands on
26899 Enable command tracing.
26900 @item set trace-commands off
26901 Disable command tracing.
26902 @item show trace-commands
26903 Display the current state of command tracing.
26904 @end table
26905
26906 @node Debugging Output
26907 @section Optional Messages about Internal Happenings
26908 @cindex optional debugging messages
26909
26910 @value{GDBN} has commands that enable optional debugging messages from
26911 various @value{GDBN} subsystems; normally these commands are of
26912 interest to @value{GDBN} maintainers, or when reporting a bug. This
26913 section documents those commands.
26914
26915 @table @code
26916 @kindex set exec-done-display
26917 @item set exec-done-display
26918 Turns on or off the notification of asynchronous commands'
26919 completion. When on, @value{GDBN} will print a message when an
26920 asynchronous command finishes its execution. The default is off.
26921 @kindex show exec-done-display
26922 @item show exec-done-display
26923 Displays the current setting of asynchronous command completion
26924 notification.
26925
26926 @kindex set debug
26927 @cindex ARM AArch64
26928 @item set debug aarch64
26929 Turns on or off display of debugging messages related to ARM AArch64.
26930 The default is off.
26931 @kindex show debug
26932 @item show debug aarch64
26933 Displays the current state of displaying debugging messages related to
26934 ARM AArch64.
26935
26936 @cindex gdbarch debugging info
26937 @cindex architecture debugging info
26938 @item set debug arch
26939 Turns on or off display of gdbarch debugging info. The default is off
26940 @item show debug arch
26941 Displays the current state of displaying gdbarch debugging info.
26942
26943 @item set debug aix-solib
26944 @cindex AIX shared library debugging
26945 Control display of debugging messages from the AIX shared library
26946 support module. The default is off.
26947 @item show debug aix-solib
26948 Show the current state of displaying AIX shared library debugging messages.
26949
26950 @item set debug aix-thread
26951 @cindex AIX threads
26952 Display debugging messages about inner workings of the AIX thread
26953 module.
26954 @item show debug aix-thread
26955 Show the current state of AIX thread debugging info display.
26956
26957 @item set debug check-physname
26958 @cindex physname
26959 Check the results of the ``physname'' computation. When reading DWARF
26960 debugging information for C@t{++}, @value{GDBN} attempts to compute
26961 each entity's name. @value{GDBN} can do this computation in two
26962 different ways, depending on exactly what information is present.
26963 When enabled, this setting causes @value{GDBN} to compute the names
26964 both ways and display any discrepancies.
26965 @item show debug check-physname
26966 Show the current state of ``physname'' checking.
26967
26968 @item set debug coff-pe-read
26969 @cindex COFF/PE exported symbols
26970 Control display of debugging messages related to reading of COFF/PE
26971 exported symbols. The default is off.
26972 @item show debug coff-pe-read
26973 Displays the current state of displaying debugging messages related to
26974 reading of COFF/PE exported symbols.
26975
26976 @item set debug dwarf-die
26977 @cindex DWARF DIEs
26978 Dump DWARF DIEs after they are read in.
26979 The value is the number of nesting levels to print.
26980 A value of zero turns off the display.
26981 @item show debug dwarf-die
26982 Show the current state of DWARF DIE debugging.
26983
26984 @item set debug dwarf-line
26985 @cindex DWARF Line Tables
26986 Turns on or off display of debugging messages related to reading
26987 DWARF line tables. The default is 0 (off).
26988 A value of 1 provides basic information.
26989 A value greater than 1 provides more verbose information.
26990 @item show debug dwarf-line
26991 Show the current state of DWARF line table debugging.
26992
26993 @item set debug dwarf-read
26994 @cindex DWARF Reading
26995 Turns on or off display of debugging messages related to reading
26996 DWARF debug info. The default is 0 (off).
26997 A value of 1 provides basic information.
26998 A value greater than 1 provides more verbose information.
26999 @item show debug dwarf-read
27000 Show the current state of DWARF reader debugging.
27001
27002 @item set debug displaced
27003 @cindex displaced stepping debugging info
27004 Turns on or off display of @value{GDBN} debugging info for the
27005 displaced stepping support. The default is off.
27006 @item show debug displaced
27007 Displays the current state of displaying @value{GDBN} debugging info
27008 related to displaced stepping.
27009
27010 @item set debug event
27011 @cindex event debugging info
27012 Turns on or off display of @value{GDBN} event debugging info. The
27013 default is off.
27014 @item show debug event
27015 Displays the current state of displaying @value{GDBN} event debugging
27016 info.
27017
27018 @item set debug event-loop
27019 @cindex event-loop debugging
27020 Controls output of debugging info about the event loop. The possible
27021 values are @samp{off}, @samp{all} (shows all debugging info) and
27022 @samp{all-except-ui} (shows all debugging info except those about
27023 UI-related events).
27024 @item show debug event-loop
27025 Shows the current state of displaying debugging info about the event
27026 loop.
27027
27028 @item set debug expression
27029 @cindex expression debugging info
27030 Turns on or off display of debugging info about @value{GDBN}
27031 expression parsing. The default is off.
27032 @item show debug expression
27033 Displays the current state of displaying debugging info about
27034 @value{GDBN} expression parsing.
27035
27036 @item set debug fbsd-lwp
27037 @cindex FreeBSD LWP debug messages
27038 Turns on or off debugging messages from the FreeBSD LWP debug support.
27039 @item show debug fbsd-lwp
27040 Show the current state of FreeBSD LWP debugging messages.
27041
27042 @item set debug fbsd-nat
27043 @cindex FreeBSD native target debug messages
27044 Turns on or off debugging messages from the FreeBSD native target.
27045 @item show debug fbsd-nat
27046 Show the current state of FreeBSD native target debugging messages.
27047
27048 @item set debug fortran-array-slicing
27049 @cindex fortran array slicing debugging info
27050 Turns on or off display of @value{GDBN} Fortran array slicing
27051 debugging info. The default is off.
27052
27053 @item show debug fortran-array-slicing
27054 Displays the current state of displaying @value{GDBN} Fortran array
27055 slicing debugging info.
27056
27057 @item set debug frame
27058 @cindex frame debugging info
27059 Turns on or off display of @value{GDBN} frame debugging info. The
27060 default is off.
27061 @item show debug frame
27062 Displays the current state of displaying @value{GDBN} frame debugging
27063 info.
27064
27065 @item set debug gnu-nat
27066 @cindex @sc{gnu}/Hurd debug messages
27067 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
27068 @item show debug gnu-nat
27069 Show the current state of @sc{gnu}/Hurd debugging messages.
27070
27071 @item set debug infrun
27072 @cindex inferior debugging info
27073 Turns on or off display of @value{GDBN} debugging info for running the inferior.
27074 The default is off. @file{infrun.c} contains GDB's runtime state machine used
27075 for implementing operations such as single-stepping the inferior.
27076 @item show debug infrun
27077 Displays the current state of @value{GDBN} inferior debugging.
27078
27079 @item set debug jit
27080 @cindex just-in-time compilation, debugging messages
27081 Turn on or off debugging messages from JIT debug support.
27082 @item show debug jit
27083 Displays the current state of @value{GDBN} JIT debugging.
27084
27085 @item set debug linux-nat @r{[}on@r{|}off@r{]}
27086 @cindex @sc{gnu}/Linux native target debug messages
27087 @cindex Linux native targets
27088 Turn on or off debugging messages from the Linux native target debug support.
27089 @item show debug linux-nat
27090 Show the current state of Linux native target debugging messages.
27091
27092 @item set debug linux-namespaces
27093 @cindex @sc{gnu}/Linux namespaces debug messages
27094 Turn on or off debugging messages from the Linux namespaces debug support.
27095 @item show debug linux-namespaces
27096 Show the current state of Linux namespaces debugging messages.
27097
27098 @item set debug mach-o
27099 @cindex Mach-O symbols processing
27100 Control display of debugging messages related to Mach-O symbols
27101 processing. The default is off.
27102 @item show debug mach-o
27103 Displays the current state of displaying debugging messages related to
27104 reading of COFF/PE exported symbols.
27105
27106 @item set debug notification
27107 @cindex remote async notification debugging info
27108 Turn on or off debugging messages about remote async notification.
27109 The default is off.
27110 @item show debug notification
27111 Displays the current state of remote async notification debugging messages.
27112
27113 @item set debug observer
27114 @cindex observer debugging info
27115 Turns on or off display of @value{GDBN} observer debugging. This
27116 includes info such as the notification of observable events.
27117 @item show debug observer
27118 Displays the current state of observer debugging.
27119
27120 @item set debug overload
27121 @cindex C@t{++} overload debugging info
27122 Turns on or off display of @value{GDBN} C@t{++} overload debugging
27123 info. This includes info such as ranking of functions, etc. The default
27124 is off.
27125 @item show debug overload
27126 Displays the current state of displaying @value{GDBN} C@t{++} overload
27127 debugging info.
27128
27129 @cindex expression parser, debugging info
27130 @cindex debug expression parser
27131 @item set debug parser
27132 Turns on or off the display of expression parser debugging output.
27133 Internally, this sets the @code{yydebug} variable in the expression
27134 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
27135 details. The default is off.
27136 @item show debug parser
27137 Show the current state of expression parser debugging.
27138
27139 @cindex packets, reporting on stdout
27140 @cindex serial connections, debugging
27141 @cindex debug remote protocol
27142 @cindex remote protocol debugging
27143 @cindex display remote packets
27144 @item set debug remote
27145 Turns on or off display of reports on all packets sent back and forth across
27146 the serial line to the remote machine. The info is printed on the
27147 @value{GDBN} standard output stream. The default is off.
27148 @item show debug remote
27149 Displays the state of display of remote packets.
27150
27151 @item set debug remote-packet-max-chars
27152 Sets the maximum number of characters to display for each remote packet when
27153 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
27154 displaying lengthy remote packets and polluting the console.
27155
27156 The default value is @code{512}, which means @value{GDBN} will truncate each
27157 remote packet after 512 bytes.
27158
27159 Setting this option to @code{unlimited} will disable truncation and will output
27160 the full length of the remote packets.
27161 @item show debug remote-packet-max-chars
27162 Displays the number of bytes to output for remote packet debugging.
27163
27164 @item set debug separate-debug-file
27165 Turns on or off display of debug output about separate debug file search.
27166 @item show debug separate-debug-file
27167 Displays the state of separate debug file search debug output.
27168
27169 @item set debug serial
27170 Turns on or off display of @value{GDBN} serial debugging info. The
27171 default is off.
27172 @item show debug serial
27173 Displays the current state of displaying @value{GDBN} serial debugging
27174 info.
27175
27176 @item set debug solib-frv
27177 @cindex FR-V shared-library debugging
27178 Turn on or off debugging messages for FR-V shared-library code.
27179 @item show debug solib-frv
27180 Display the current state of FR-V shared-library code debugging
27181 messages.
27182
27183 @item set debug symbol-lookup
27184 @cindex symbol lookup
27185 Turns on or off display of debugging messages related to symbol lookup.
27186 The default is 0 (off).
27187 A value of 1 provides basic information.
27188 A value greater than 1 provides more verbose information.
27189 @item show debug symbol-lookup
27190 Show the current state of symbol lookup debugging messages.
27191
27192 @item set debug symfile
27193 @cindex symbol file functions
27194 Turns on or off display of debugging messages related to symbol file functions.
27195 The default is off. @xref{Files}.
27196 @item show debug symfile
27197 Show the current state of symbol file debugging messages.
27198
27199 @item set debug symtab-create
27200 @cindex symbol table creation
27201 Turns on or off display of debugging messages related to symbol table creation.
27202 The default is 0 (off).
27203 A value of 1 provides basic information.
27204 A value greater than 1 provides more verbose information.
27205 @item show debug symtab-create
27206 Show the current state of symbol table creation debugging.
27207
27208 @item set debug target
27209 @cindex target debugging info
27210 Turns on or off display of @value{GDBN} target debugging info. This info
27211 includes what is going on at the target level of GDB, as it happens. The
27212 default is 0. Set it to 1 to track events, and to 2 to also track the
27213 value of large memory transfers.
27214 @item show debug target
27215 Displays the current state of displaying @value{GDBN} target debugging
27216 info.
27217
27218 @item set debug timestamp
27219 @cindex timestamping debugging info
27220 Turns on or off display of timestamps with @value{GDBN} debugging info.
27221 When enabled, seconds and microseconds are displayed before each debugging
27222 message.
27223 @item show debug timestamp
27224 Displays the current state of displaying timestamps with @value{GDBN}
27225 debugging info.
27226
27227 @item set debug varobj
27228 @cindex variable object debugging info
27229 Turns on or off display of @value{GDBN} variable object debugging
27230 info. The default is off.
27231 @item show debug varobj
27232 Displays the current state of displaying @value{GDBN} variable object
27233 debugging info.
27234
27235 @item set debug xml
27236 @cindex XML parser debugging
27237 Turn on or off debugging messages for built-in XML parsers.
27238 @item show debug xml
27239 Displays the current state of XML debugging messages.
27240 @end table
27241
27242 @node Other Misc Settings
27243 @section Other Miscellaneous Settings
27244 @cindex miscellaneous settings
27245
27246 @table @code
27247 @kindex set interactive-mode
27248 @item set interactive-mode
27249 If @code{on}, forces @value{GDBN} to assume that GDB was started
27250 in a terminal. In practice, this means that @value{GDBN} should wait
27251 for the user to answer queries generated by commands entered at
27252 the command prompt. If @code{off}, forces @value{GDBN} to operate
27253 in the opposite mode, and it uses the default answers to all queries.
27254 If @code{auto} (the default), @value{GDBN} tries to determine whether
27255 its standard input is a terminal, and works in interactive-mode if it
27256 is, non-interactively otherwise.
27257
27258 In the vast majority of cases, the debugger should be able to guess
27259 correctly which mode should be used. But this setting can be useful
27260 in certain specific cases, such as running a MinGW @value{GDBN}
27261 inside a cygwin window.
27262
27263 @kindex show interactive-mode
27264 @item show interactive-mode
27265 Displays whether the debugger is operating in interactive mode or not.
27266 @end table
27267
27268 @table @code
27269 @kindex set suppress-cli-notifications
27270 @item set suppress-cli-notifications
27271 If @code{on}, command-line-interface (CLI) notifications that are
27272 printed by @value{GDBN} are suppressed. If @code{off}, the
27273 notifications are printed as usual. The default value is @code{off}.
27274 CLI notifications occur when you change the selected context or when
27275 the program being debugged stops, as detailed below.
27276
27277 @table @emph
27278 @item User-selected context changes:
27279 When you change the selected context (i.e.@: the current inferior,
27280 thread and/or the frame), @value{GDBN} prints information about the
27281 new context. For example, the default behavior is below:
27282
27283 @smallexample
27284 (gdb) inferior 1
27285 [Switching to inferior 1 [process 634] (/tmp/test)]
27286 [Switching to thread 1 (process 634)]
27287 #0 main () at test.c:3
27288 3 return 0;
27289 (gdb)
27290 @end smallexample
27291
27292 When the notifications are suppressed, the new context is not printed:
27293
27294 @smallexample
27295 (gdb) set suppress-cli-notifications on
27296 (gdb) inferior 1
27297 (gdb)
27298 @end smallexample
27299
27300 @item The program being debugged stops:
27301 When the program you are debugging stops (e.g.@: because of hitting a
27302 breakpoint, completing source-stepping, an interrupt, etc.),
27303 @value{GDBN} prints information about the stop event. For example,
27304 below is a breakpoint hit:
27305
27306 @smallexample
27307 (gdb) break test.c:3
27308 Breakpoint 2 at 0x555555555155: file test.c, line 3.
27309 (gdb) continue
27310 Continuing.
27311
27312 Breakpoint 2, main () at test.c:3
27313 3 return 0;
27314 (gdb)
27315 @end smallexample
27316
27317 When the notifications are suppressed, the output becomes:
27318
27319 @smallexample
27320 (gdb) break test.c:3
27321 Breakpoint 2 at 0x555555555155: file test.c, line 3.
27322 (gdb) set suppress-cli-notifications on
27323 (gdb) continue
27324 Continuing.
27325 (gdb)
27326 @end smallexample
27327
27328 Suppressing CLI notifications may be useful in scripts to obtain a
27329 reduced output from a list of commands.
27330 @end table
27331
27332 @kindex show suppress-cli-notifications
27333 @item show suppress-cli-notifications
27334 Displays whether printing CLI notifications is suppressed or not.
27335 @end table
27336
27337 @node Extending GDB
27338 @chapter Extending @value{GDBN}
27339 @cindex extending GDB
27340
27341 @value{GDBN} provides several mechanisms for extension.
27342 @value{GDBN} also provides the ability to automatically load
27343 extensions when it reads a file for debugging. This allows the
27344 user to automatically customize @value{GDBN} for the program
27345 being debugged.
27346
27347 To facilitate the use of extension languages, @value{GDBN} is capable
27348 of evaluating the contents of a file. When doing so, @value{GDBN}
27349 can recognize which extension language is being used by looking at
27350 the filename extension. Files with an unrecognized filename extension
27351 are always treated as a @value{GDBN} Command Files.
27352 @xref{Command Files,, Command files}.
27353
27354 You can control how @value{GDBN} evaluates these files with the following
27355 setting:
27356
27357 @table @code
27358 @kindex set script-extension
27359 @kindex show script-extension
27360 @item set script-extension off
27361 All scripts are always evaluated as @value{GDBN} Command Files.
27362
27363 @item set script-extension soft
27364 The debugger determines the scripting language based on filename
27365 extension. If this scripting language is supported, @value{GDBN}
27366 evaluates the script using that language. Otherwise, it evaluates
27367 the file as a @value{GDBN} Command File.
27368
27369 @item set script-extension strict
27370 The debugger determines the scripting language based on filename
27371 extension, and evaluates the script using that language. If the
27372 language is not supported, then the evaluation fails.
27373
27374 @item show script-extension
27375 Display the current value of the @code{script-extension} option.
27376
27377 @end table
27378
27379 @ifset SYSTEM_GDBINIT_DIR
27380 This setting is not used for files in the system-wide gdbinit directory.
27381 Files in that directory must have an extension matching their language,
27382 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
27383 commands. @xref{Startup}.
27384 @end ifset
27385
27386 @menu
27387 * Sequences:: Canned Sequences of @value{GDBN} Commands
27388 * Aliases:: Command Aliases
27389 * Python:: Extending @value{GDBN} using Python
27390 * Guile:: Extending @value{GDBN} using Guile
27391 * Auto-loading extensions:: Automatically loading extensions
27392 * Multiple Extension Languages:: Working with multiple extension languages
27393 @end menu
27394
27395 @node Sequences
27396 @section Canned Sequences of Commands
27397
27398 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
27399 Command Lists}), @value{GDBN} provides two ways to store sequences of
27400 commands for execution as a unit: user-defined commands and command
27401 files.
27402
27403 @menu
27404 * Define:: How to define your own commands
27405 * Hooks:: Hooks for user-defined commands
27406 * Command Files:: How to write scripts of commands to be stored in a file
27407 * Output:: Commands for controlled output
27408 * Auto-loading sequences:: Controlling auto-loaded command files
27409 @end menu
27410
27411 @node Define
27412 @subsection User-defined Commands
27413
27414 @cindex user-defined command
27415 @cindex arguments, to user-defined commands
27416 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
27417 which you assign a new name as a command. This is done with the
27418 @code{define} command. User commands may accept an unlimited number of arguments
27419 separated by whitespace. Arguments are accessed within the user command
27420 via @code{$arg0@dots{}$argN}. A trivial example:
27421
27422 @smallexample
27423 define adder
27424 print $arg0 + $arg1 + $arg2
27425 end
27426 @end smallexample
27427
27428 @noindent
27429 To execute the command use:
27430
27431 @smallexample
27432 adder 1 2 3
27433 @end smallexample
27434
27435 @noindent
27436 This defines the command @code{adder}, which prints the sum of
27437 its three arguments. Note the arguments are text substitutions, so they may
27438 reference variables, use complex expressions, or even perform inferior
27439 functions calls.
27440
27441 @cindex argument count in user-defined commands
27442 @cindex how many arguments (user-defined commands)
27443 In addition, @code{$argc} may be used to find out how many arguments have
27444 been passed.
27445
27446 @smallexample
27447 define adder
27448 if $argc == 2
27449 print $arg0 + $arg1
27450 end
27451 if $argc == 3
27452 print $arg0 + $arg1 + $arg2
27453 end
27454 end
27455 @end smallexample
27456
27457 Combining with the @code{eval} command (@pxref{eval}) makes it easier
27458 to process a variable number of arguments:
27459
27460 @smallexample
27461 define adder
27462 set $i = 0
27463 set $sum = 0
27464 while $i < $argc
27465 eval "set $sum = $sum + $arg%d", $i
27466 set $i = $i + 1
27467 end
27468 print $sum
27469 end
27470 @end smallexample
27471
27472 @table @code
27473
27474 @kindex define
27475 @item define @var{commandname}
27476 Define a command named @var{commandname}. If there is already a command
27477 by that name, you are asked to confirm that you want to redefine it.
27478 The argument @var{commandname} may be a bare command name consisting of letters,
27479 numbers, dashes, dots, and underscores. It may also start with any
27480 predefined or user-defined prefix command.
27481 For example, @samp{define target my-target} creates
27482 a user-defined @samp{target my-target} command.
27483
27484 The definition of the command is made up of other @value{GDBN} command lines,
27485 which are given following the @code{define} command. The end of these
27486 commands is marked by a line containing @code{end}.
27487
27488 @kindex document
27489 @kindex end@r{ (user-defined commands)}
27490 @item document @var{commandname}
27491 Document the user-defined command @var{commandname}, so that it can be
27492 accessed by @code{help}. The command @var{commandname} must already be
27493 defined. This command reads lines of documentation just as @code{define}
27494 reads the lines of the command definition, ending with @code{end}.
27495 After the @code{document} command is finished, @code{help} on command
27496 @var{commandname} displays the documentation you have written.
27497
27498 You may use the @code{document} command again to change the
27499 documentation of a command. Redefining the command with @code{define}
27500 does not change the documentation.
27501
27502 @kindex define-prefix
27503 @item define-prefix @var{commandname}
27504 Define or mark the command @var{commandname} as a user-defined prefix
27505 command. Once marked, @var{commandname} can be used as prefix command
27506 by the @code{define} command.
27507 Note that @code{define-prefix} can be used with a not yet defined
27508 @var{commandname}. In such a case, @var{commandname} is defined as
27509 an empty user-defined command.
27510 In case you redefine a command that was marked as a user-defined
27511 prefix command, the subcommands of the redefined command are kept
27512 (and @value{GDBN} indicates so to the user).
27513
27514 Example:
27515 @example
27516 (gdb) define-prefix abc
27517 (gdb) define-prefix abc def
27518 (gdb) define abc def
27519 Type commands for definition of "abc def".
27520 End with a line saying just "end".
27521 >echo command initial def\n
27522 >end
27523 (gdb) define abc def ghi
27524 Type commands for definition of "abc def ghi".
27525 End with a line saying just "end".
27526 >echo command ghi\n
27527 >end
27528 (gdb) define abc def
27529 Keeping subcommands of prefix command "def".
27530 Redefine command "def"? (y or n) y
27531 Type commands for definition of "abc def".
27532 End with a line saying just "end".
27533 >echo command def\n
27534 >end
27535 (gdb) abc def ghi
27536 command ghi
27537 (gdb) abc def
27538 command def
27539 (gdb)
27540 @end example
27541
27542 @kindex dont-repeat
27543 @cindex don't repeat command
27544 @item dont-repeat
27545 Used inside a user-defined command, this tells @value{GDBN} that this
27546 command should not be repeated when the user hits @key{RET}
27547 (@pxref{Command Syntax, repeat last command}).
27548
27549 @kindex help user-defined
27550 @item help user-defined
27551 List all user-defined commands and all python commands defined in class
27552 COMMAND_USER. The first line of the documentation or docstring is
27553 included (if any).
27554
27555 @kindex show user
27556 @item show user
27557 @itemx show user @var{commandname}
27558 Display the @value{GDBN} commands used to define @var{commandname} (but
27559 not its documentation). If no @var{commandname} is given, display the
27560 definitions for all user-defined commands.
27561 This does not work for user-defined python commands.
27562
27563 @cindex infinite recursion in user-defined commands
27564 @kindex show max-user-call-depth
27565 @kindex set max-user-call-depth
27566 @item show max-user-call-depth
27567 @itemx set max-user-call-depth
27568 The value of @code{max-user-call-depth} controls how many recursion
27569 levels are allowed in user-defined commands before @value{GDBN} suspects an
27570 infinite recursion and aborts the command.
27571 This does not apply to user-defined python commands.
27572 @end table
27573
27574 In addition to the above commands, user-defined commands frequently
27575 use control flow commands, described in @ref{Command Files}.
27576
27577 When user-defined commands are executed, the
27578 commands of the definition are not printed. An error in any command
27579 stops execution of the user-defined command.
27580
27581 If used interactively, commands that would ask for confirmation proceed
27582 without asking when used inside a user-defined command. Many @value{GDBN}
27583 commands that normally print messages to say what they are doing omit the
27584 messages when used in a user-defined command.
27585
27586 @node Hooks
27587 @subsection User-defined Command Hooks
27588 @cindex command hooks
27589 @cindex hooks, for commands
27590 @cindex hooks, pre-command
27591
27592 @kindex hook
27593 You may define @dfn{hooks}, which are a special kind of user-defined
27594 command. Whenever you run the command @samp{foo}, if the user-defined
27595 command @samp{hook-foo} exists, it is executed (with no arguments)
27596 before that command.
27597
27598 @cindex hooks, post-command
27599 @kindex hookpost
27600 A hook may also be defined which is run after the command you executed.
27601 Whenever you run the command @samp{foo}, if the user-defined command
27602 @samp{hookpost-foo} exists, it is executed (with no arguments) after
27603 that command. Post-execution hooks may exist simultaneously with
27604 pre-execution hooks, for the same command.
27605
27606 It is valid for a hook to call the command which it hooks. If this
27607 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
27608
27609 @c It would be nice if hookpost could be passed a parameter indicating
27610 @c if the command it hooks executed properly or not. FIXME!
27611
27612 @kindex stop@r{, a pseudo-command}
27613 In addition, a pseudo-command, @samp{stop} exists. Defining
27614 (@samp{hook-stop}) makes the associated commands execute every time
27615 execution stops in your program: before breakpoint commands are run,
27616 displays are printed, or the stack frame is printed.
27617
27618 For example, to ignore @code{SIGALRM} signals while
27619 single-stepping, but treat them normally during normal execution,
27620 you could define:
27621
27622 @smallexample
27623 define hook-stop
27624 handle SIGALRM nopass
27625 end
27626
27627 define hook-run
27628 handle SIGALRM pass
27629 end
27630
27631 define hook-continue
27632 handle SIGALRM pass
27633 end
27634 @end smallexample
27635
27636 As a further example, to hook at the beginning and end of the @code{echo}
27637 command, and to add extra text to the beginning and end of the message,
27638 you could define:
27639
27640 @smallexample
27641 define hook-echo
27642 echo <<<---
27643 end
27644
27645 define hookpost-echo
27646 echo --->>>\n
27647 end
27648
27649 (@value{GDBP}) echo Hello World
27650 <<<---Hello World--->>>
27651 (@value{GDBP})
27652
27653 @end smallexample
27654
27655 You can define a hook for any single-word command in @value{GDBN}, but
27656 not for command aliases; you should define a hook for the basic command
27657 name, e.g.@: @code{backtrace} rather than @code{bt}.
27658 @c FIXME! So how does Joe User discover whether a command is an alias
27659 @c or not?
27660 You can hook a multi-word command by adding @code{hook-} or
27661 @code{hookpost-} to the last word of the command, e.g.@:
27662 @samp{define target hook-remote} to add a hook to @samp{target remote}.
27663
27664 If an error occurs during the execution of your hook, execution of
27665 @value{GDBN} commands stops and @value{GDBN} issues a prompt
27666 (before the command that you actually typed had a chance to run).
27667
27668 If you try to define a hook which does not match any known command, you
27669 get a warning from the @code{define} command.
27670
27671 @node Command Files
27672 @subsection Command Files
27673
27674 @cindex command files
27675 @cindex scripting commands
27676 A command file for @value{GDBN} is a text file made of lines that are
27677 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27678 also be included. An empty line in a command file does nothing; it
27679 does not mean to repeat the last command, as it would from the
27680 terminal.
27681
27682 You can request the execution of a command file with the @code{source}
27683 command. Note that the @code{source} command is also used to evaluate
27684 scripts that are not Command Files. The exact behavior can be configured
27685 using the @code{script-extension} setting.
27686 @xref{Extending GDB,, Extending GDB}.
27687
27688 @table @code
27689 @kindex source
27690 @cindex execute commands from a file
27691 @item source [-s] [-v] @var{filename}
27692 Execute the command file @var{filename}.
27693 @end table
27694
27695 The lines in a command file are generally executed sequentially,
27696 unless the order of execution is changed by one of the
27697 @emph{flow-control commands} described below. The commands are not
27698 printed as they are executed. An error in any command terminates
27699 execution of the command file and control is returned to the console.
27700
27701 @value{GDBN} first searches for @var{filename} in the current directory.
27702 If the file is not found there, and @var{filename} does not specify a
27703 directory, then @value{GDBN} also looks for the file on the source search path
27704 (specified with the @samp{directory} command);
27705 except that @file{$cdir} is not searched because the compilation directory
27706 is not relevant to scripts.
27707
27708 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27709 on the search path even if @var{filename} specifies a directory.
27710 The search is done by appending @var{filename} to each element of the
27711 search path. So, for example, if @var{filename} is @file{mylib/myscript}
27712 and the search path contains @file{/home/user} then @value{GDBN} will
27713 look for the script @file{/home/user/mylib/myscript}.
27714 The search is also done if @var{filename} is an absolute path.
27715 For example, if @var{filename} is @file{/tmp/myscript} and
27716 the search path contains @file{/home/user} then @value{GDBN} will
27717 look for the script @file{/home/user/tmp/myscript}.
27718 For DOS-like systems, if @var{filename} contains a drive specification,
27719 it is stripped before concatenation. For example, if @var{filename} is
27720 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27721 will look for the script @file{c:/tmp/myscript}.
27722
27723 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27724 each command as it is executed. The option must be given before
27725 @var{filename}, and is interpreted as part of the filename anywhere else.
27726
27727 Commands that would ask for confirmation if used interactively proceed
27728 without asking when used in a command file. Many @value{GDBN} commands that
27729 normally print messages to say what they are doing omit the messages
27730 when called from command files.
27731
27732 @value{GDBN} also accepts command input from standard input. In this
27733 mode, normal output goes to standard output and error output goes to
27734 standard error. Errors in a command file supplied on standard input do
27735 not terminate execution of the command file---execution continues with
27736 the next command.
27737
27738 @smallexample
27739 gdb < cmds > log 2>&1
27740 @end smallexample
27741
27742 (The syntax above will vary depending on the shell used.) This example
27743 will execute commands from the file @file{cmds}. All output and errors
27744 would be directed to @file{log}.
27745
27746 Since commands stored on command files tend to be more general than
27747 commands typed interactively, they frequently need to deal with
27748 complicated situations, such as different or unexpected values of
27749 variables and symbols, changes in how the program being debugged is
27750 built, etc. @value{GDBN} provides a set of flow-control commands to
27751 deal with these complexities. Using these commands, you can write
27752 complex scripts that loop over data structures, execute commands
27753 conditionally, etc.
27754
27755 @table @code
27756 @kindex if
27757 @kindex else
27758 @item if
27759 @itemx else
27760 This command allows to include in your script conditionally executed
27761 commands. The @code{if} command takes a single argument, which is an
27762 expression to evaluate. It is followed by a series of commands that
27763 are executed only if the expression is true (its value is nonzero).
27764 There can then optionally be an @code{else} line, followed by a series
27765 of commands that are only executed if the expression was false. The
27766 end of the list is marked by a line containing @code{end}.
27767
27768 @kindex while
27769 @item while
27770 This command allows to write loops. Its syntax is similar to
27771 @code{if}: the command takes a single argument, which is an expression
27772 to evaluate, and must be followed by the commands to execute, one per
27773 line, terminated by an @code{end}. These commands are called the
27774 @dfn{body} of the loop. The commands in the body of @code{while} are
27775 executed repeatedly as long as the expression evaluates to true.
27776
27777 @kindex loop_break
27778 @item loop_break
27779 This command exits the @code{while} loop in whose body it is included.
27780 Execution of the script continues after that @code{while}s @code{end}
27781 line.
27782
27783 @kindex loop_continue
27784 @item loop_continue
27785 This command skips the execution of the rest of the body of commands
27786 in the @code{while} loop in whose body it is included. Execution
27787 branches to the beginning of the @code{while} loop, where it evaluates
27788 the controlling expression.
27789
27790 @kindex end@r{ (if/else/while commands)}
27791 @item end
27792 Terminate the block of commands that are the body of @code{if},
27793 @code{else}, or @code{while} flow-control commands.
27794 @end table
27795
27796
27797 @node Output
27798 @subsection Commands for Controlled Output
27799
27800 During the execution of a command file or a user-defined command, normal
27801 @value{GDBN} output is suppressed; the only output that appears is what is
27802 explicitly printed by the commands in the definition. This section
27803 describes three commands useful for generating exactly the output you
27804 want.
27805
27806 @table @code
27807 @kindex echo
27808 @item echo @var{text}
27809 @c I do not consider backslash-space a standard C escape sequence
27810 @c because it is not in ANSI.
27811 Print @var{text}. Nonprinting characters can be included in
27812 @var{text} using C escape sequences, such as @samp{\n} to print a
27813 newline. @strong{No newline is printed unless you specify one.}
27814 In addition to the standard C escape sequences, a backslash followed
27815 by a space stands for a space. This is useful for displaying a
27816 string with spaces at the beginning or the end, since leading and
27817 trailing spaces are otherwise trimmed from all arguments.
27818 To print @samp{@w{ }and foo =@w{ }}, use the command
27819 @samp{echo \@w{ }and foo = \@w{ }}.
27820
27821 A backslash at the end of @var{text} can be used, as in C, to continue
27822 the command onto subsequent lines. For example,
27823
27824 @smallexample
27825 echo This is some text\n\
27826 which is continued\n\
27827 onto several lines.\n
27828 @end smallexample
27829
27830 produces the same output as
27831
27832 @smallexample
27833 echo This is some text\n
27834 echo which is continued\n
27835 echo onto several lines.\n
27836 @end smallexample
27837
27838 @kindex output
27839 @item output @var{expression}
27840 Print the value of @var{expression} and nothing but that value: no
27841 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27842 value history either. @xref{Expressions, ,Expressions}, for more information
27843 on expressions.
27844
27845 @item output/@var{fmt} @var{expression}
27846 Print the value of @var{expression} in format @var{fmt}. You can use
27847 the same formats as for @code{print}. @xref{Output Formats,,Output
27848 Formats}, for more information.
27849
27850 @kindex printf
27851 @item printf @var{template}, @var{expressions}@dots{}
27852 Print the values of one or more @var{expressions} under the control of
27853 the string @var{template}. To print several values, make
27854 @var{expressions} be a comma-separated list of individual expressions,
27855 which may be either numbers or pointers. Their values are printed as
27856 specified by @var{template}, exactly as a C program would do by
27857 executing the code below:
27858
27859 @smallexample
27860 printf (@var{template}, @var{expressions}@dots{});
27861 @end smallexample
27862
27863 As in @code{C} @code{printf}, ordinary characters in @var{template}
27864 are printed verbatim, while @dfn{conversion specification} introduced
27865 by the @samp{%} character cause subsequent @var{expressions} to be
27866 evaluated, their values converted and formatted according to type and
27867 style information encoded in the conversion specifications, and then
27868 printed.
27869
27870 For example, you can print two values in hex like this:
27871
27872 @smallexample
27873 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27874 @end smallexample
27875
27876 @code{printf} supports all the standard @code{C} conversion
27877 specifications, including the flags and modifiers between the @samp{%}
27878 character and the conversion letter, with the following exceptions:
27879
27880 @itemize @bullet
27881 @item
27882 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27883
27884 @item
27885 The modifier @samp{*} is not supported for specifying precision or
27886 width.
27887
27888 @item
27889 The @samp{'} flag (for separation of digits into groups according to
27890 @code{LC_NUMERIC'}) is not supported.
27891
27892 @item
27893 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27894 supported.
27895
27896 @item
27897 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27898
27899 @item
27900 The conversion letters @samp{a} and @samp{A} are not supported.
27901 @end itemize
27902
27903 @noindent
27904 Note that the @samp{ll} type modifier is supported only if the
27905 underlying @code{C} implementation used to build @value{GDBN} supports
27906 the @code{long long int} type, and the @samp{L} type modifier is
27907 supported only if @code{long double} type is available.
27908
27909 As in @code{C}, @code{printf} supports simple backslash-escape
27910 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27911 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27912 single character. Octal and hexadecimal escape sequences are not
27913 supported.
27914
27915 Additionally, @code{printf} supports conversion specifications for DFP
27916 (@dfn{Decimal Floating Point}) types using the following length modifiers
27917 together with a floating point specifier.
27918 letters:
27919
27920 @itemize @bullet
27921 @item
27922 @samp{H} for printing @code{Decimal32} types.
27923
27924 @item
27925 @samp{D} for printing @code{Decimal64} types.
27926
27927 @item
27928 @samp{DD} for printing @code{Decimal128} types.
27929 @end itemize
27930
27931 If the underlying @code{C} implementation used to build @value{GDBN} has
27932 support for the three length modifiers for DFP types, other modifiers
27933 such as width and precision will also be available for @value{GDBN} to use.
27934
27935 In case there is no such @code{C} support, no additional modifiers will be
27936 available and the value will be printed in the standard way.
27937
27938 Here's an example of printing DFP types using the above conversion letters:
27939 @smallexample
27940 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27941 @end smallexample
27942
27943 @anchor{eval}
27944 @kindex eval
27945 @item eval @var{template}, @var{expressions}@dots{}
27946 Convert the values of one or more @var{expressions} under the control of
27947 the string @var{template} to a command line, and call it.
27948
27949 @end table
27950
27951 @node Auto-loading sequences
27952 @subsection Controlling auto-loading native @value{GDBN} scripts
27953 @cindex native script auto-loading
27954
27955 When a new object file is read (for example, due to the @code{file}
27956 command, or because the inferior has loaded a shared library),
27957 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27958 @xref{Auto-loading extensions}.
27959
27960 Auto-loading can be enabled or disabled,
27961 and the list of auto-loaded scripts can be printed.
27962
27963 @table @code
27964 @anchor{set auto-load gdb-scripts}
27965 @kindex set auto-load gdb-scripts
27966 @item set auto-load gdb-scripts [on|off]
27967 Enable or disable the auto-loading of canned sequences of commands scripts.
27968
27969 @anchor{show auto-load gdb-scripts}
27970 @kindex show auto-load gdb-scripts
27971 @item show auto-load gdb-scripts
27972 Show whether auto-loading of canned sequences of commands scripts is enabled or
27973 disabled.
27974
27975 @anchor{info auto-load gdb-scripts}
27976 @kindex info auto-load gdb-scripts
27977 @cindex print list of auto-loaded canned sequences of commands scripts
27978 @item info auto-load gdb-scripts [@var{regexp}]
27979 Print the list of all canned sequences of commands scripts that @value{GDBN}
27980 auto-loaded.
27981 @end table
27982
27983 If @var{regexp} is supplied only canned sequences of commands scripts with
27984 matching names are printed.
27985
27986 @node Aliases
27987 @section Command Aliases
27988 @cindex aliases for commands
27989
27990 Aliases allow you to define alternate spellings for existing commands.
27991 For example, if a new @value{GDBN} command defined in Python
27992 (@pxref{Python}) has a long name, it is handy to have an abbreviated
27993 version of it that involves less typing.
27994
27995 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27996 of the @samp{step} command even though it is otherwise an ambiguous
27997 abbreviation of other commands like @samp{set} and @samp{show}.
27998
27999 Aliases are also used to provide shortened or more common versions
28000 of multi-word commands. For example, @value{GDBN} provides the
28001 @samp{tty} alias of the @samp{set inferior-tty} command.
28002
28003 You can define a new alias with the @samp{alias} command.
28004
28005 @table @code
28006
28007 @kindex alias
28008 @item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
28009
28010 @end table
28011
28012 @var{alias} specifies the name of the new alias. Each word of
28013 @var{alias} must consist of letters, numbers, dashes and underscores.
28014
28015 @var{command} specifies the name of an existing command
28016 that is being aliased.
28017
28018 @var{command} can also be the name of an existing alias. In this
28019 case, @var{command} cannot be an alias that has default arguments.
28020
28021 The @samp{-a} option specifies that the new alias is an abbreviation
28022 of the command. Abbreviations are not used in command completion.
28023
28024 The @samp{--} option specifies the end of options,
28025 and is useful when @var{alias} begins with a dash.
28026
28027 You can specify @var{default-args} for your alias. These
28028 @var{default-args} will be automatically added before the alias
28029 arguments typed explicitly on the command line.
28030
28031 For example, the below defines an alias @code{btfullall} that shows all local
28032 variables and all frame arguments:
28033 @smallexample
28034 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
28035 @end smallexample
28036
28037 For more information about @var{default-args}, see @ref{Command
28038 aliases default args, ,Default Arguments}.
28039
28040 Here is a simple example showing how to make an abbreviation of a
28041 command so that there is less to type. Suppose you were tired of
28042 typing @samp{disas}, the current shortest unambiguous abbreviation of
28043 the @samp{disassemble} command and you wanted an even shorter version
28044 named @samp{di}. The following will accomplish this.
28045
28046 @smallexample
28047 (gdb) alias -a di = disas
28048 @end smallexample
28049
28050 Note that aliases are different from user-defined commands. With a
28051 user-defined command, you also need to write documentation for it with
28052 the @samp{document} command. An alias automatically picks up the
28053 documentation of the existing command.
28054
28055 Here is an example where we make @samp{elms} an abbreviation of
28056 @samp{elements} in the @samp{set print elements} command.
28057 This is to show that you can make an abbreviation of any part
28058 of a command.
28059
28060 @smallexample
28061 (gdb) alias -a set print elms = set print elements
28062 (gdb) alias -a show print elms = show print elements
28063 (gdb) set p elms 200
28064 (gdb) show p elms
28065 Limit on string chars or array elements to print is 200.
28066 @end smallexample
28067
28068 Note that if you are defining an alias of a @samp{set} command,
28069 and you want to have an alias for the corresponding @samp{show}
28070 command, then you need to define the latter separately.
28071
28072 Unambiguously abbreviated commands are allowed in @var{command} and
28073 @var{alias}, just as they are normally.
28074
28075 @smallexample
28076 (gdb) alias -a set pr elms = set p ele
28077 @end smallexample
28078
28079 Finally, here is an example showing the creation of a one word
28080 alias for a more complex command.
28081 This creates alias @samp{spe} of the command @samp{set print elements}.
28082
28083 @smallexample
28084 (gdb) alias spe = set print elements
28085 (gdb) spe 20
28086 @end smallexample
28087
28088 @menu
28089 * Command aliases default args:: Default arguments for aliases
28090 @end menu
28091
28092 @node Command aliases default args
28093 @subsection Default Arguments
28094 @cindex aliases for commands, default arguments
28095
28096 You can tell @value{GDBN} to always prepend some default arguments to
28097 the list of arguments provided explicitly by the user when using a
28098 user-defined alias.
28099
28100 If you repeatedly use the same arguments or options for a command, you
28101 can define an alias for this command and tell @value{GDBN} to
28102 automatically prepend these arguments or options to the list of
28103 arguments you type explicitly when using the alias@footnote{@value{GDBN}
28104 could easily accept default arguments for pre-defined commands and aliases,
28105 but it was deemed this would be confusing, and so is not allowed.}.
28106
28107 For example, if you often use the command @code{thread apply all}
28108 specifying to work on the threads in ascending order and to continue in case it
28109 encounters an error, you can tell @value{GDBN} to automatically preprend
28110 the @code{-ascending} and @code{-c} options by using:
28111
28112 @smallexample
28113 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
28114 @end smallexample
28115
28116 Once you have defined this alias with its default args, any time you type
28117 the @code{thread apply asc-all} followed by @code{some arguments},
28118 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
28119
28120 To have even less to type, you can also define a one word alias:
28121 @smallexample
28122 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
28123 @end smallexample
28124
28125 As usual, unambiguous abbreviations can be used for @var{alias}
28126 and @var{default-args}.
28127
28128 The different aliases of a command do not share their default args.
28129 For example, you define a new alias @code{bt_ALL} showing all possible
28130 information and another alias @code{bt_SMALL} showing very limited information
28131 using:
28132 @smallexample
28133 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
28134 -past-main -past-entry -full
28135 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
28136 -past-main off -past-entry off
28137 @end smallexample
28138
28139 (For more on using the @code{alias} command, see @ref{Aliases}.)
28140
28141 Default args are not limited to the arguments and options of @var{command},
28142 but can specify nested commands if @var{command} accepts such a nested command
28143 as argument.
28144 For example, the below defines @code{faalocalsoftype} that lists the
28145 frames having locals of a certain type, together with the matching
28146 local vars:
28147 @smallexample
28148 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
28149 (@value{GDBP}) faalocalsoftype int
28150 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
28151 i = 0
28152 ret = 21845
28153 @end smallexample
28154
28155 This is also very useful to define an alias for a set of nested @code{with}
28156 commands to have a particular combination of temporary settings. For example,
28157 the below defines the alias @code{pp10} that pretty prints an expression
28158 argument, with a maximum of 10 elements if the expression is a string or
28159 an array:
28160 @smallexample
28161 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
28162 @end smallexample
28163 This defines the alias @code{pp10} as being a sequence of 3 commands.
28164 The first part @code{with print pretty --} temporarily activates the setting
28165 @code{set print pretty}, then launches the command that follows the separator
28166 @code{--}.
28167 The command following the first part is also a @code{with} command that
28168 temporarily changes the setting @code{set print elements} to 10, then
28169 launches the command that follows the second separator @code{--}.
28170 The third part @code{print} is the command the @code{pp10} alias will launch,
28171 using the temporary values of the settings and the arguments explicitly given
28172 by the user.
28173 For more information about the @code{with} command usage,
28174 see @ref{Command Settings}.
28175
28176 @c Python docs live in a separate file.
28177 @include python.texi
28178
28179 @c Guile docs live in a separate file.
28180 @include guile.texi
28181
28182 @node Auto-loading extensions
28183 @section Auto-loading extensions
28184 @cindex auto-loading extensions
28185
28186 @value{GDBN} provides two mechanisms for automatically loading
28187 extensions when a new object file is read (for example, due to the
28188 @code{file} command, or because the inferior has loaded a shared
28189 library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
28190 file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
28191 @code{.debug_gdb_scripts} section of modern file formats like ELF
28192 (@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
28193 section}). For a discussion of the differences between these two
28194 approaches see @ref{Which flavor to choose?}.
28195
28196 The auto-loading feature is useful for supplying application-specific
28197 debugging commands and features.
28198
28199 Auto-loading can be enabled or disabled,
28200 and the list of auto-loaded scripts can be printed.
28201 See the @samp{auto-loading} section of each extension language
28202 for more information.
28203 For @value{GDBN} command files see @ref{Auto-loading sequences}.
28204 For Python files see @ref{Python Auto-loading}.
28205
28206 Note that loading of this script file also requires accordingly configured
28207 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28208
28209 @menu
28210 * objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
28211 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
28212 * Which flavor to choose?:: Choosing between these approaches
28213 @end menu
28214
28215 @node objfile-gdbdotext file
28216 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
28217 @cindex @file{@var{objfile}-gdb.gdb}
28218 @cindex @file{@var{objfile}-gdb.py}
28219 @cindex @file{@var{objfile}-gdb.scm}
28220
28221 When a new object file is read, @value{GDBN} looks for a file named
28222 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
28223 where @var{objfile} is the object file's name and
28224 where @var{ext} is the file extension for the extension language:
28225
28226 @table @code
28227 @item @file{@var{objfile}-gdb.gdb}
28228 GDB's own command language
28229 @item @file{@var{objfile}-gdb.py}
28230 Python
28231 @item @file{@var{objfile}-gdb.scm}
28232 Guile
28233 @end table
28234
28235 @var{script-name} is formed by ensuring that the file name of @var{objfile}
28236 is absolute, following all symlinks, and resolving @code{.} and @code{..}
28237 components, and appending the @file{-gdb.@var{ext}} suffix.
28238 If this file exists and is readable, @value{GDBN} will evaluate it as a
28239 script in the specified extension language.
28240
28241 If this file does not exist, then @value{GDBN} will look for
28242 @var{script-name} file in all of the directories as specified below.
28243 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
28244 directories is converted to a one-letter subdirectory, i.e.@:
28245 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
28246 filesystems disallow colons in file names.)
28247
28248 Note that loading of these files requires an accordingly configured
28249 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28250
28251 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
28252 scripts normally according to its @file{.exe} filename. But if no scripts are
28253 found @value{GDBN} also tries script filenames matching the object file without
28254 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
28255 is attempted on any platform. This makes the script filenames compatible
28256 between Unix and MS-Windows hosts.
28257
28258 @table @code
28259 @anchor{set auto-load scripts-directory}
28260 @kindex set auto-load scripts-directory
28261 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
28262 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
28263 may be delimited by the host platform path separator in use
28264 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
28265
28266 Each entry here needs to be covered also by the security setting
28267 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
28268
28269 @anchor{with-auto-load-dir}
28270 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
28271 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
28272 configuration option @option{--with-auto-load-dir}.
28273
28274 Any reference to @file{$debugdir} will get replaced by
28275 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
28276 reference to @file{$datadir} will get replaced by @var{data-directory} which is
28277 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
28278 @file{$datadir} must be placed as a directory component --- either alone or
28279 delimited by @file{/} or @file{\} directory separators, depending on the host
28280 platform.
28281
28282 The list of directories uses path separator (@samp{:} on GNU and Unix
28283 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
28284 to the @env{PATH} environment variable.
28285
28286 @anchor{show auto-load scripts-directory}
28287 @kindex show auto-load scripts-directory
28288 @item show auto-load scripts-directory
28289 Show @value{GDBN} auto-loaded scripts location.
28290
28291 @anchor{add-auto-load-scripts-directory}
28292 @kindex add-auto-load-scripts-directory
28293 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
28294 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
28295 Multiple entries may be delimited by the host platform path separator in use.
28296 @end table
28297
28298 @value{GDBN} does not track which files it has already auto-loaded this way.
28299 @value{GDBN} will load the associated script every time the corresponding
28300 @var{objfile} is opened.
28301 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
28302 is evaluated more than once.
28303
28304 @node dotdebug_gdb_scripts section
28305 @subsection The @code{.debug_gdb_scripts} section
28306 @cindex @code{.debug_gdb_scripts} section
28307
28308 For systems using file formats like ELF and COFF,
28309 when @value{GDBN} loads a new object file
28310 it will look for a special section named @code{.debug_gdb_scripts}.
28311 If this section exists, its contents is a list of null-terminated entries
28312 specifying scripts to load. Each entry begins with a non-null prefix byte that
28313 specifies the kind of entry, typically the extension language and whether the
28314 script is in a file or inlined in @code{.debug_gdb_scripts}.
28315
28316 The following entries are supported:
28317
28318 @table @code
28319 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
28320 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
28321 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
28322 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
28323 @end table
28324
28325 @subsubsection Script File Entries
28326
28327 If the entry specifies a file, @value{GDBN} will look for the file first
28328 in the current directory and then along the source search path
28329 (@pxref{Source Path, ,Specifying Source Directories}),
28330 except that @file{$cdir} is not searched, since the compilation
28331 directory is not relevant to scripts.
28332
28333 File entries can be placed in section @code{.debug_gdb_scripts} with,
28334 for example, this GCC macro for Python scripts.
28335
28336 @example
28337 /* Note: The "MS" section flags are to remove duplicates. */
28338 #define DEFINE_GDB_PY_SCRIPT(script_name) \
28339 asm("\
28340 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
28341 .byte 1 /* Python */\n\
28342 .asciz \"" script_name "\"\n\
28343 .popsection \n\
28344 ");
28345 @end example
28346
28347 @noindent
28348 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
28349 Then one can reference the macro in a header or source file like this:
28350
28351 @example
28352 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
28353 @end example
28354
28355 The script name may include directories if desired.
28356
28357 Note that loading of this script file also requires accordingly configured
28358 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28359
28360 If the macro invocation is put in a header, any application or library
28361 using this header will get a reference to the specified script,
28362 and with the use of @code{"MS"} attributes on the section, the linker
28363 will remove duplicates.
28364
28365 @subsubsection Script Text Entries
28366
28367 Script text entries allow to put the executable script in the entry
28368 itself instead of loading it from a file.
28369 The first line of the entry, everything after the prefix byte and up to
28370 the first newline (@code{0xa}) character, is the script name, and must not
28371 contain any kind of space character, e.g., spaces or tabs.
28372 The rest of the entry, up to the trailing null byte, is the script to
28373 execute in the specified language. The name needs to be unique among
28374 all script names, as @value{GDBN} executes each script only once based
28375 on its name.
28376
28377 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
28378 testsuite.
28379
28380 @example
28381 #include "symcat.h"
28382 #include "gdb/section-scripts.h"
28383 asm(
28384 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
28385 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
28386 ".ascii \"gdb.inlined-script\\n\"\n"
28387 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
28388 ".ascii \" def __init__ (self):\\n\"\n"
28389 ".ascii \" super (test_cmd, self).__init__ ("
28390 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
28391 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
28392 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
28393 ".ascii \"test_cmd ()\\n\"\n"
28394 ".byte 0\n"
28395 ".popsection\n"
28396 );
28397 @end example
28398
28399 Loading of inlined scripts requires a properly configured
28400 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28401 The path to specify in @code{auto-load safe-path} is the path of the file
28402 containing the @code{.debug_gdb_scripts} section.
28403
28404 @node Which flavor to choose?
28405 @subsection Which flavor to choose?
28406
28407 Given the multiple ways of auto-loading extensions, it might not always
28408 be clear which one to choose. This section provides some guidance.
28409
28410 @noindent
28411 Benefits of the @file{-gdb.@var{ext}} way:
28412
28413 @itemize @bullet
28414 @item
28415 Can be used with file formats that don't support multiple sections.
28416
28417 @item
28418 Ease of finding scripts for public libraries.
28419
28420 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
28421 in the source search path.
28422 For publicly installed libraries, e.g., @file{libstdc++}, there typically
28423 isn't a source directory in which to find the script.
28424
28425 @item
28426 Doesn't require source code additions.
28427 @end itemize
28428
28429 @noindent
28430 Benefits of the @code{.debug_gdb_scripts} way:
28431
28432 @itemize @bullet
28433 @item
28434 Works with static linking.
28435
28436 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
28437 trigger their loading. When an application is statically linked the only
28438 objfile available is the executable, and it is cumbersome to attach all the
28439 scripts from all the input libraries to the executable's
28440 @file{-gdb.@var{ext}} script.
28441
28442 @item
28443 Works with classes that are entirely inlined.
28444
28445 Some classes can be entirely inlined, and thus there may not be an associated
28446 shared library to attach a @file{-gdb.@var{ext}} script to.
28447
28448 @item
28449 Scripts needn't be copied out of the source tree.
28450
28451 In some circumstances, apps can be built out of large collections of internal
28452 libraries, and the build infrastructure necessary to install the
28453 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
28454 cumbersome. It may be easier to specify the scripts in the
28455 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
28456 top of the source tree to the source search path.
28457 @end itemize
28458
28459 @node Multiple Extension Languages
28460 @section Multiple Extension Languages
28461
28462 The Guile and Python extension languages do not share any state,
28463 and generally do not interfere with each other.
28464 There are some things to be aware of, however.
28465
28466 @subsection Python comes first
28467
28468 Python was @value{GDBN}'s first extension language, and to avoid breaking
28469 existing behaviour Python comes first. This is generally solved by the
28470 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
28471 extension languages, and when it makes a call to an extension language,
28472 (say to pretty-print a value), it tries each in turn until an extension
28473 language indicates it has performed the request (e.g., has returned the
28474 pretty-printed form of a value).
28475 This extends to errors while performing such requests: If an error happens
28476 while, for example, trying to pretty-print an object then the error is
28477 reported and any following extension languages are not tried.
28478
28479 @node Interpreters
28480 @chapter Command Interpreters
28481 @cindex command interpreters
28482
28483 @value{GDBN} supports multiple command interpreters, and some command
28484 infrastructure to allow users or user interface writers to switch
28485 between interpreters or run commands in other interpreters.
28486
28487 @value{GDBN} currently supports two command interpreters, the console
28488 interpreter (sometimes called the command-line interpreter or @sc{cli})
28489 and the machine interface interpreter (or @sc{gdb/mi}). This manual
28490 describes both of these interfaces in great detail.
28491
28492 By default, @value{GDBN} will start with the console interpreter.
28493 However, the user may choose to start @value{GDBN} with another
28494 interpreter by specifying the @option{-i} or @option{--interpreter}
28495 startup options. Defined interpreters include:
28496
28497 @table @code
28498 @item console
28499 @cindex console interpreter
28500 The traditional console or command-line interpreter. This is the most often
28501 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
28502 @value{GDBN} will use this interpreter.
28503
28504 @item mi
28505 @cindex mi interpreter
28506 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
28507 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
28508 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
28509 Interface}.
28510
28511 @item mi3
28512 @cindex mi3 interpreter
28513 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
28514
28515 @item mi2
28516 @cindex mi2 interpreter
28517 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
28518
28519 @item mi1
28520 @cindex mi1 interpreter
28521 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
28522
28523 @end table
28524
28525 @cindex invoke another interpreter
28526
28527 @kindex interpreter-exec
28528 You may execute commands in any interpreter from the current
28529 interpreter using the appropriate command. If you are running the
28530 console interpreter, simply use the @code{interpreter-exec} command:
28531
28532 @smallexample
28533 interpreter-exec mi "-data-list-register-names"
28534 @end smallexample
28535
28536 @sc{gdb/mi} has a similar command, although it is only available in versions of
28537 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28538
28539 Note that @code{interpreter-exec} only changes the interpreter for the
28540 duration of the specified command. It does not change the interpreter
28541 permanently.
28542
28543 @cindex start a new independent interpreter
28544
28545 Although you may only choose a single interpreter at startup, it is
28546 possible to run an independent interpreter on a specified input/output
28547 device (usually a tty).
28548
28549 For example, consider a debugger GUI or IDE that wants to provide a
28550 @value{GDBN} console view. It may do so by embedding a terminal
28551 emulator widget in its GUI, starting @value{GDBN} in the traditional
28552 command-line mode with stdin/stdout/stderr redirected to that
28553 terminal, and then creating an MI interpreter running on a specified
28554 input/output device. The console interpreter created by @value{GDBN}
28555 at startup handles commands the user types in the terminal widget,
28556 while the GUI controls and synchronizes state with @value{GDBN} using
28557 the separate MI interpreter.
28558
28559 To start a new secondary @dfn{user interface} running MI, use the
28560 @code{new-ui} command:
28561
28562 @kindex new-ui
28563 @cindex new user interface
28564 @smallexample
28565 new-ui @var{interpreter} @var{tty}
28566 @end smallexample
28567
28568 The @var{interpreter} parameter specifies the interpreter to run.
28569 This accepts the same values as the @code{interpreter-exec} command.
28570 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28571 @var{tty} parameter specifies the name of the bidirectional file the
28572 interpreter uses for input/output, usually the name of a
28573 pseudoterminal slave on Unix systems. For example:
28574
28575 @smallexample
28576 (@value{GDBP}) new-ui mi /dev/pts/9
28577 @end smallexample
28578
28579 @noindent
28580 runs an MI interpreter on @file{/dev/pts/9}.
28581
28582 @node TUI
28583 @chapter @value{GDBN} Text User Interface
28584 @cindex TUI
28585 @cindex Text User Interface
28586
28587 The @value{GDBN} Text User Interface (TUI) is a terminal
28588 interface which uses the @code{curses} library to show the source
28589 file, the assembly output, the program registers and @value{GDBN}
28590 commands in separate text windows. The TUI mode is supported only
28591 on platforms where a suitable version of the @code{curses} library
28592 is available.
28593
28594 The TUI mode is enabled by default when you invoke @value{GDBN} as
28595 @samp{@value{GDBP} -tui}.
28596 You can also switch in and out of TUI mode while @value{GDBN} runs by
28597 using various TUI commands and key bindings, such as @command{tui
28598 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
28599 @ref{TUI Keys, ,TUI Key Bindings}.
28600
28601 @menu
28602 * TUI Overview:: TUI overview
28603 * TUI Keys:: TUI key bindings
28604 * TUI Single Key Mode:: TUI single key mode
28605 * TUI Mouse Support:: TUI mouse support
28606 * TUI Commands:: TUI-specific commands
28607 * TUI Configuration:: TUI configuration variables
28608 @end menu
28609
28610 @node TUI Overview
28611 @section TUI Overview
28612
28613 In TUI mode, @value{GDBN} can display several text windows:
28614
28615 @table @emph
28616 @item command
28617 This window is the @value{GDBN} command window with the @value{GDBN}
28618 prompt and the @value{GDBN} output. The @value{GDBN} input is still
28619 managed using readline.
28620
28621 @item source
28622 The source window shows the source file of the program. The current
28623 line and active breakpoints are displayed in this window.
28624
28625 @item assembly
28626 The assembly window shows the disassembly output of the program.
28627
28628 @item register
28629 This window shows the processor registers. Registers are highlighted
28630 when their values change.
28631 @end table
28632
28633 The source and assembly windows show the current program position
28634 by highlighting the current line and marking it with a @samp{>} marker.
28635 Breakpoints are indicated with two markers. The first marker
28636 indicates the breakpoint type:
28637
28638 @table @code
28639 @item B
28640 Breakpoint which was hit at least once.
28641
28642 @item b
28643 Breakpoint which was never hit.
28644
28645 @item H
28646 Hardware breakpoint which was hit at least once.
28647
28648 @item h
28649 Hardware breakpoint which was never hit.
28650 @end table
28651
28652 The second marker indicates whether the breakpoint is enabled or not:
28653
28654 @table @code
28655 @item +
28656 Breakpoint is enabled.
28657
28658 @item -
28659 Breakpoint is disabled.
28660 @end table
28661
28662 The source, assembly and register windows are updated when the current
28663 thread changes, when the frame changes, or when the program counter
28664 changes.
28665
28666 These windows are not all visible at the same time. The command
28667 window is always visible. The others can be arranged in several
28668 layouts:
28669
28670 @itemize @bullet
28671 @item
28672 source only,
28673
28674 @item
28675 assembly only,
28676
28677 @item
28678 source and assembly,
28679
28680 @item
28681 source and registers, or
28682
28683 @item
28684 assembly and registers.
28685 @end itemize
28686
28687 These are the standard layouts, but other layouts can be defined.
28688
28689 A status line above the command window shows the following information:
28690
28691 @table @emph
28692 @item target
28693 Indicates the current @value{GDBN} target.
28694 (@pxref{Targets, ,Specifying a Debugging Target}).
28695
28696 @item process
28697 Gives the current process or thread number.
28698 When no process is being debugged, this field is set to @code{No process}.
28699
28700 @item function
28701 Gives the current function name for the selected frame.
28702 The name is demangled if demangling is turned on (@pxref{Print Settings}).
28703 When there is no symbol corresponding to the current program counter,
28704 the string @code{??} is displayed.
28705
28706 @item line
28707 Indicates the current line number for the selected frame.
28708 When the current line number is not known, the string @code{??} is displayed.
28709
28710 @item pc
28711 Indicates the current program counter address.
28712 @end table
28713
28714 @node TUI Keys
28715 @section TUI Key Bindings
28716 @cindex TUI key bindings
28717
28718 The TUI installs several key bindings in the readline keymaps
28719 @ifset SYSTEM_READLINE
28720 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28721 @end ifset
28722 @ifclear SYSTEM_READLINE
28723 (@pxref{Command Line Editing}).
28724 @end ifclear
28725 The following key bindings are installed for both TUI mode and the
28726 @value{GDBN} standard mode.
28727
28728 @table @kbd
28729 @kindex C-x C-a
28730 @item C-x C-a
28731 @kindex C-x a
28732 @itemx C-x a
28733 @kindex C-x A
28734 @itemx C-x A
28735 Enter or leave the TUI mode. When leaving the TUI mode,
28736 the curses window management stops and @value{GDBN} operates using
28737 its standard mode, writing on the terminal directly. When reentering
28738 the TUI mode, control is given back to the curses windows.
28739 The screen is then refreshed.
28740
28741 This key binding uses the bindable Readline function
28742 @code{tui-switch-mode}.
28743
28744 @kindex C-x 1
28745 @item C-x 1
28746 Use a TUI layout with only one window. The layout will
28747 either be @samp{source} or @samp{assembly}. When the TUI mode
28748 is not active, it will switch to the TUI mode.
28749
28750 Think of this key binding as the Emacs @kbd{C-x 1} binding.
28751
28752 This key binding uses the bindable Readline function
28753 @code{tui-delete-other-windows}.
28754
28755 @kindex C-x 2
28756 @item C-x 2
28757 Use a TUI layout with at least two windows. When the current
28758 layout already has two windows, the next layout with two windows is used.
28759 When a new layout is chosen, one window will always be common to the
28760 previous layout and the new one.
28761
28762 Think of it as the Emacs @kbd{C-x 2} binding.
28763
28764 This key binding uses the bindable Readline function
28765 @code{tui-change-windows}.
28766
28767 @kindex C-x o
28768 @item C-x o
28769 Change the active window. The TUI associates several key bindings
28770 (like scrolling and arrow keys) with the active window. This command
28771 gives the focus to the next TUI window.
28772
28773 Think of it as the Emacs @kbd{C-x o} binding.
28774
28775 This key binding uses the bindable Readline function
28776 @code{tui-other-window}.
28777
28778 @kindex C-x s
28779 @item C-x s
28780 Switch in and out of the TUI SingleKey mode that binds single
28781 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
28782
28783 This key binding uses the bindable Readline function
28784 @code{next-keymap}.
28785 @end table
28786
28787 The following key bindings only work in the TUI mode:
28788
28789 @table @asis
28790 @kindex PgUp
28791 @item @key{PgUp}
28792 Scroll the active window one page up.
28793
28794 @kindex PgDn
28795 @item @key{PgDn}
28796 Scroll the active window one page down.
28797
28798 @kindex Up
28799 @item @key{Up}
28800 Scroll the active window one line up.
28801
28802 @kindex Down
28803 @item @key{Down}
28804 Scroll the active window one line down.
28805
28806 @kindex Left
28807 @item @key{Left}
28808 Scroll the active window one column left.
28809
28810 @kindex Right
28811 @item @key{Right}
28812 Scroll the active window one column right.
28813
28814 @kindex C-L
28815 @item @kbd{C-L}
28816 Refresh the screen.
28817 @end table
28818
28819 Because the arrow keys scroll the active window in the TUI mode, they
28820 are not available for their normal use by readline unless the command
28821 window has the focus. When another window is active, you must use
28822 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28823 and @kbd{C-f} to control the command window.
28824
28825 @node TUI Single Key Mode
28826 @section TUI Single Key Mode
28827 @cindex TUI single key mode
28828
28829 The TUI also provides a @dfn{SingleKey} mode, which binds several
28830 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28831 switch into this mode, where the following key bindings are used:
28832
28833 @table @kbd
28834 @kindex c @r{(SingleKey TUI key)}
28835 @item c
28836 continue
28837
28838 @kindex d @r{(SingleKey TUI key)}
28839 @item d
28840 down
28841
28842 @kindex f @r{(SingleKey TUI key)}
28843 @item f
28844 finish
28845
28846 @kindex n @r{(SingleKey TUI key)}
28847 @item n
28848 next
28849
28850 @kindex o @r{(SingleKey TUI key)}
28851 @item o
28852 nexti. The shortcut letter @samp{o} stands for ``step Over''.
28853
28854 @kindex q @r{(SingleKey TUI key)}
28855 @item q
28856 exit the SingleKey mode.
28857
28858 @kindex r @r{(SingleKey TUI key)}
28859 @item r
28860 run
28861
28862 @kindex s @r{(SingleKey TUI key)}
28863 @item s
28864 step
28865
28866 @kindex i @r{(SingleKey TUI key)}
28867 @item i
28868 stepi. The shortcut letter @samp{i} stands for ``step Into''.
28869
28870 @kindex u @r{(SingleKey TUI key)}
28871 @item u
28872 up
28873
28874 @kindex v @r{(SingleKey TUI key)}
28875 @item v
28876 info locals
28877
28878 @kindex w @r{(SingleKey TUI key)}
28879 @item w
28880 where
28881 @end table
28882
28883 Other keys temporarily switch to the @value{GDBN} command prompt.
28884 The key that was pressed is inserted in the editing buffer so that
28885 it is possible to type most @value{GDBN} commands without interaction
28886 with the TUI SingleKey mode. Once the command is entered the TUI
28887 SingleKey mode is restored. The only way to permanently leave
28888 this mode is by typing @kbd{q} or @kbd{C-x s}.
28889
28890 @cindex SingleKey keymap name
28891 If @value{GDBN} was built with Readline 8.0 or later, the TUI
28892 SingleKey keymap will be named @samp{SingleKey}. This can be used in
28893 @file{.inputrc} to add additional bindings to this keymap.
28894
28895 @node TUI Mouse Support
28896 @section TUI Mouse Support
28897 @cindex TUI mouse support
28898
28899 If the curses library supports the mouse, the TUI supports mouse
28900 actions.
28901
28902 The mouse wheel scrolls the appropriate window under the mouse cursor.
28903
28904 The TUI itself does not directly support copying/pasting with the
28905 mouse. However, on Unix terminals, you can typically press and hold
28906 the @key{SHIFT} key on your keyboard to temporarily bypass
28907 @value{GDBN}'s TUI and access the terminal's native mouse copy/paste
28908 functionality (commonly, click-drag-release or double-click to select
28909 text, middle-click to paste). This copy/paste works with the
28910 terminal's selection buffer, as opposed to the TUI's buffer.
28911
28912 @node TUI Commands
28913 @section TUI-specific Commands
28914 @cindex TUI commands
28915
28916 The TUI has specific commands to control the text windows.
28917 These commands are always available, even when @value{GDBN} is not in
28918 the TUI mode. When @value{GDBN} is in the standard mode, most
28919 of these commands will automatically switch to the TUI mode.
28920
28921 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28922 terminal, or @value{GDBN} has been started with the machine interface
28923 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28924 these commands will fail with an error, because it would not be
28925 possible or desirable to enable curses window management.
28926
28927 @table @code
28928 @item tui enable
28929 @kindex tui enable
28930 Activate TUI mode. The last active TUI window layout will be used if
28931 TUI mode has previously been used in the current debugging session,
28932 otherwise a default layout is used.
28933
28934 @item tui disable
28935 @kindex tui disable
28936 Disable TUI mode, returning to the console interpreter.
28937
28938 @anchor{info_win_command}
28939 @item info win
28940 @kindex info win
28941 List the names and sizes of all currently displayed windows.
28942
28943 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28944 @kindex tui new-layout
28945 Create a new TUI layout. The new layout will be named @var{name}, and
28946 can be accessed using the @code{layout} command (see below).
28947
28948 Each @var{window} parameter is either the name of a window to display,
28949 or a window description. The windows will be displayed from top to
28950 bottom in the order listed.
28951
28952 The names of the windows are the same as the ones given to the
28953 @code{focus} command (see below); additional, the @code{status}
28954 window can be specified. Note that, because it is of fixed height,
28955 the weight assigned to the status window is of no importance. It is
28956 conventional to use @samp{0} here.
28957
28958 A window description looks a bit like an invocation of @code{tui
28959 new-layout}, and is of the form
28960 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28961
28962 This specifies a sub-layout. If @code{-horizontal} is given, the
28963 windows in this description will be arranged side-by-side, rather than
28964 top-to-bottom.
28965
28966 Each @var{weight} is an integer. It is the weight of this window
28967 relative to all the other windows in the layout. These numbers are
28968 used to calculate how much of the screen is given to each window.
28969
28970 For example:
28971
28972 @example
28973 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28974 @end example
28975
28976 Here, the new layout is called @samp{example}. It shows the source
28977 and register windows, followed by the status window, and then finally
28978 the command window. The non-status windows all have the same weight,
28979 so the terminal will be split into three roughly equal sections.
28980
28981 Here is a more complex example, showing a horizontal layout:
28982
28983 @example
28984 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28985 @end example
28986
28987 This will result in side-by-side source and assembly windows; with the
28988 status and command window being beneath these, filling the entire
28989 width of the terminal. Because they have weight 2, the source and
28990 assembly windows will be twice the height of the command window.
28991
28992 @item layout @var{name}
28993 @kindex layout
28994 Changes which TUI windows are displayed. The @var{name} parameter
28995 controls which layout is shown. It can be either one of the built-in
28996 layout names, or the name of a layout defined by the user using
28997 @code{tui new-layout}.
28998
28999 The built-in layouts are as follows:
29000
29001 @table @code
29002 @item next
29003 Display the next layout.
29004
29005 @item prev
29006 Display the previous layout.
29007
29008 @item src
29009 Display the source and command windows.
29010
29011 @item asm
29012 Display the assembly and command windows.
29013
29014 @item split
29015 Display the source, assembly, and command windows.
29016
29017 @item regs
29018 When in @code{src} layout display the register, source, and command
29019 windows. When in @code{asm} or @code{split} layout display the
29020 register, assembler, and command windows.
29021 @end table
29022
29023 @item focus @var{name}
29024 @kindex focus
29025 Changes which TUI window is currently active for scrolling. The
29026 @var{name} parameter can be any of the following:
29027
29028 @table @code
29029 @item next
29030 Make the next window active for scrolling.
29031
29032 @item prev
29033 Make the previous window active for scrolling.
29034
29035 @item src
29036 Make the source window active for scrolling.
29037
29038 @item asm
29039 Make the assembly window active for scrolling.
29040
29041 @item regs
29042 Make the register window active for scrolling.
29043
29044 @item cmd
29045 Make the command window active for scrolling.
29046 @end table
29047
29048 @item refresh
29049 @kindex refresh
29050 Refresh the screen. This is similar to typing @kbd{C-L}.
29051
29052 @item tui reg @var{group}
29053 @kindex tui reg
29054 Changes the register group displayed in the tui register window to
29055 @var{group}. If the register window is not currently displayed this
29056 command will cause the register window to be displayed. The list of
29057 register groups, as well as their order is target specific. The
29058 following groups are available on most targets:
29059 @table @code
29060 @item next
29061 Repeatedly selecting this group will cause the display to cycle
29062 through all of the available register groups.
29063
29064 @item prev
29065 Repeatedly selecting this group will cause the display to cycle
29066 through all of the available register groups in the reverse order to
29067 @var{next}.
29068
29069 @item general
29070 Display the general registers.
29071 @item float
29072 Display the floating point registers.
29073 @item system
29074 Display the system registers.
29075 @item vector
29076 Display the vector registers.
29077 @item all
29078 Display all registers.
29079 @end table
29080
29081 @item update
29082 @kindex update
29083 Update the source window and the current execution point.
29084
29085 @item winheight @var{name} +@var{count}
29086 @itemx winheight @var{name} -@var{count}
29087 @kindex winheight
29088 Change the height of the window @var{name} by @var{count} lines.
29089 Positive counts increase the height, while negative counts decrease
29090 it. The @var{name} parameter can be the name of any currently visible
29091 window. The names of the currently visible windows can be discovered
29092 using @kbd{info win} (@pxref{info_win_command,,info win}).
29093 @end table
29094
29095 @node TUI Configuration
29096 @section TUI Configuration Variables
29097 @cindex TUI configuration variables
29098
29099 Several configuration variables control the appearance of TUI windows.
29100
29101 @table @code
29102 @item set tui border-kind @var{kind}
29103 @kindex set tui border-kind
29104 Select the border appearance for the source, assembly and register windows.
29105 The possible values are the following:
29106 @table @code
29107 @item space
29108 Use a space character to draw the border.
29109
29110 @item ascii
29111 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
29112
29113 @item acs
29114 Use the Alternate Character Set to draw the border. The border is
29115 drawn using character line graphics if the terminal supports them.
29116 @end table
29117
29118 @item set tui border-mode @var{mode}
29119 @kindex set tui border-mode
29120 @itemx set tui active-border-mode @var{mode}
29121 @kindex set tui active-border-mode
29122 Select the display attributes for the borders of the inactive windows
29123 or the active window. The @var{mode} can be one of the following:
29124 @table @code
29125 @item normal
29126 Use normal attributes to display the border.
29127
29128 @item standout
29129 Use standout mode.
29130
29131 @item reverse
29132 Use reverse video mode.
29133
29134 @item half
29135 Use half bright mode.
29136
29137 @item half-standout
29138 Use half bright and standout mode.
29139
29140 @item bold
29141 Use extra bright or bold mode.
29142
29143 @item bold-standout
29144 Use extra bright or bold and standout mode.
29145 @end table
29146
29147 @item set tui tab-width @var{nchars}
29148 @kindex set tui tab-width
29149 @kindex tabset
29150 Set the width of tab stops to be @var{nchars} characters. This
29151 setting affects the display of TAB characters in the source and
29152 assembly windows.
29153
29154 @item set tui compact-source @r{[}on@r{|}off@r{]}
29155 @kindex set tui compact-source
29156 Set whether the TUI source window is displayed in ``compact'' form.
29157 The default display uses more space for line numbers and starts the
29158 source text at the next tab stop; the compact display uses only as
29159 much space as is needed for the line numbers in the current file, and
29160 only a single space to separate the line numbers from the source.
29161 @end table
29162
29163 Note that the colors of the TUI borders can be controlled using the
29164 appropriate @code{set style} commands. @xref{Output Styling}.
29165
29166 @node Emacs
29167 @chapter Using @value{GDBN} under @sc{gnu} Emacs
29168
29169 @cindex Emacs
29170 @cindex @sc{gnu} Emacs
29171 A special interface allows you to use @sc{gnu} Emacs to view (and
29172 edit) the source files for the program you are debugging with
29173 @value{GDBN}.
29174
29175 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
29176 executable file you want to debug as an argument. This command starts
29177 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
29178 created Emacs buffer.
29179 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
29180
29181 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
29182 things:
29183
29184 @itemize @bullet
29185 @item
29186 All ``terminal'' input and output goes through an Emacs buffer, called
29187 the GUD buffer.
29188
29189 This applies both to @value{GDBN} commands and their output, and to the input
29190 and output done by the program you are debugging.
29191
29192 This is useful because it means that you can copy the text of previous
29193 commands and input them again; you can even use parts of the output
29194 in this way.
29195
29196 All the facilities of Emacs' Shell mode are available for interacting
29197 with your program. In particular, you can send signals the usual
29198 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
29199 stop.
29200
29201 @item
29202 @value{GDBN} displays source code through Emacs.
29203
29204 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
29205 source file for that frame and puts an arrow (@samp{=>}) at the
29206 left margin of the current line. Emacs uses a separate buffer for
29207 source display, and splits the screen to show both your @value{GDBN} session
29208 and the source.
29209
29210 Explicit @value{GDBN} @code{list} or search commands still produce output as
29211 usual, but you probably have no reason to use them from Emacs.
29212 @end itemize
29213
29214 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
29215 a graphical mode, enabled by default, which provides further buffers
29216 that can control the execution and describe the state of your program.
29217 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
29218
29219 If you specify an absolute file name when prompted for the @kbd{M-x
29220 gdb} argument, then Emacs sets your current working directory to where
29221 your program resides. If you only specify the file name, then Emacs
29222 sets your current working directory to the directory associated
29223 with the previous buffer. In this case, @value{GDBN} may find your
29224 program by searching your environment's @env{PATH} variable, but on
29225 some operating systems it might not find the source. So, although the
29226 @value{GDBN} input and output session proceeds normally, the auxiliary
29227 buffer does not display the current source and line of execution.
29228
29229 The initial working directory of @value{GDBN} is printed on the top
29230 line of the GUD buffer and this serves as a default for the commands
29231 that specify files for @value{GDBN} to operate on. @xref{Files,
29232 ,Commands to Specify Files}.
29233
29234 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
29235 need to call @value{GDBN} by a different name (for example, if you
29236 keep several configurations around, with different names) you can
29237 customize the Emacs variable @code{gud-gdb-command-name} to run the
29238 one you want.
29239
29240 In the GUD buffer, you can use these special Emacs commands in
29241 addition to the standard Shell mode commands:
29242
29243 @table @kbd
29244 @item C-h m
29245 Describe the features of Emacs' GUD Mode.
29246
29247 @item C-c C-s
29248 Execute to another source line, like the @value{GDBN} @code{step} command; also
29249 update the display window to show the current file and location.
29250
29251 @item C-c C-n
29252 Execute to next source line in this function, skipping all function
29253 calls, like the @value{GDBN} @code{next} command. Then update the display window
29254 to show the current file and location.
29255
29256 @item C-c C-i
29257 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
29258 display window accordingly.
29259
29260 @item C-c C-f
29261 Execute until exit from the selected stack frame, like the @value{GDBN}
29262 @code{finish} command.
29263
29264 @item C-c C-r
29265 Continue execution of your program, like the @value{GDBN} @code{continue}
29266 command.
29267
29268 @item C-c <
29269 Go up the number of frames indicated by the numeric argument
29270 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
29271 like the @value{GDBN} @code{up} command.
29272
29273 @item C-c >
29274 Go down the number of frames indicated by the numeric argument, like the
29275 @value{GDBN} @code{down} command.
29276 @end table
29277
29278 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
29279 tells @value{GDBN} to set a breakpoint on the source line point is on.
29280
29281 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
29282 separate frame which shows a backtrace when the GUD buffer is current.
29283 Move point to any frame in the stack and type @key{RET} to make it
29284 become the current frame and display the associated source in the
29285 source buffer. Alternatively, click @kbd{Mouse-2} to make the
29286 selected frame become the current one. In graphical mode, the
29287 speedbar displays watch expressions.
29288
29289 If you accidentally delete the source-display buffer, an easy way to get
29290 it back is to type the command @code{f} in the @value{GDBN} buffer, to
29291 request a frame display; when you run under Emacs, this recreates
29292 the source buffer if necessary to show you the context of the current
29293 frame.
29294
29295 The source files displayed in Emacs are in ordinary Emacs buffers
29296 which are visiting the source files in the usual way. You can edit
29297 the files with these buffers if you wish; but keep in mind that @value{GDBN}
29298 communicates with Emacs in terms of line numbers. If you add or
29299 delete lines from the text, the line numbers that @value{GDBN} knows cease
29300 to correspond properly with the code.
29301
29302 A more detailed description of Emacs' interaction with @value{GDBN} is
29303 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
29304 Emacs Manual}).
29305
29306 @node GDB/MI
29307 @chapter The @sc{gdb/mi} Interface
29308
29309 @unnumberedsec Function and Purpose
29310
29311 @cindex @sc{gdb/mi}, its purpose
29312 @sc{gdb/mi} is a line based machine oriented text interface to
29313 @value{GDBN} and is activated by specifying using the
29314 @option{--interpreter} command line option (@pxref{Mode Options}). It
29315 is specifically intended to support the development of systems which
29316 use the debugger as just one small component of a larger system.
29317
29318 This chapter is a specification of the @sc{gdb/mi} interface. It is written
29319 in the form of a reference manual.
29320
29321 Note that @sc{gdb/mi} is still under construction, so some of the
29322 features described below are incomplete and subject to change
29323 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
29324
29325 @unnumberedsec Notation and Terminology
29326
29327 @cindex notational conventions, for @sc{gdb/mi}
29328 This chapter uses the following notation:
29329
29330 @itemize @bullet
29331 @item
29332 @code{|} separates two alternatives.
29333
29334 @item
29335 @code{[ @var{something} ]} indicates that @var{something} is optional:
29336 it may or may not be given.
29337
29338 @item
29339 @code{( @var{group} )*} means that @var{group} inside the parentheses
29340 may repeat zero or more times.
29341
29342 @item
29343 @code{( @var{group} )+} means that @var{group} inside the parentheses
29344 may repeat one or more times.
29345
29346 @item
29347 @code{"@var{string}"} means a literal @var{string}.
29348 @end itemize
29349
29350 @ignore
29351 @heading Dependencies
29352 @end ignore
29353
29354 @menu
29355 * GDB/MI General Design::
29356 * GDB/MI Command Syntax::
29357 * GDB/MI Compatibility with CLI::
29358 * GDB/MI Development and Front Ends::
29359 * GDB/MI Output Records::
29360 * GDB/MI Simple Examples::
29361 * GDB/MI Command Description Format::
29362 * GDB/MI Breakpoint Commands::
29363 * GDB/MI Catchpoint Commands::
29364 * GDB/MI Program Context::
29365 * GDB/MI Thread Commands::
29366 * GDB/MI Ada Tasking Commands::
29367 * GDB/MI Program Execution::
29368 * GDB/MI Stack Manipulation::
29369 * GDB/MI Variable Objects::
29370 * GDB/MI Data Manipulation::
29371 * GDB/MI Tracepoint Commands::
29372 * GDB/MI Symbol Query::
29373 * GDB/MI File Commands::
29374 @ignore
29375 * GDB/MI Kod Commands::
29376 * GDB/MI Memory Overlay Commands::
29377 * GDB/MI Signal Handling Commands::
29378 @end ignore
29379 * GDB/MI Target Manipulation::
29380 * GDB/MI File Transfer Commands::
29381 * GDB/MI Ada Exceptions Commands::
29382 * GDB/MI Support Commands::
29383 * GDB/MI Miscellaneous Commands::
29384 @end menu
29385
29386 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29387 @node GDB/MI General Design
29388 @section @sc{gdb/mi} General Design
29389 @cindex GDB/MI General Design
29390
29391 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
29392 parts---commands sent to @value{GDBN}, responses to those commands
29393 and notifications. Each command results in exactly one response,
29394 indicating either successful completion of the command, or an error.
29395 For the commands that do not resume the target, the response contains the
29396 requested information. For the commands that resume the target, the
29397 response only indicates whether the target was successfully resumed.
29398 Notifications is the mechanism for reporting changes in the state of the
29399 target, or in @value{GDBN} state, that cannot conveniently be associated with
29400 a command and reported as part of that command response.
29401
29402 The important examples of notifications are:
29403 @itemize @bullet
29404
29405 @item
29406 Exec notifications. These are used to report changes in
29407 target state---when a target is resumed, or stopped. It would not
29408 be feasible to include this information in response of resuming
29409 commands, because one resume commands can result in multiple events in
29410 different threads. Also, quite some time may pass before any event
29411 happens in the target, while a frontend needs to know whether the resuming
29412 command itself was successfully executed.
29413
29414 @item
29415 Console output, and status notifications. Console output
29416 notifications are used to report output of CLI commands, as well as
29417 diagnostics for other commands. Status notifications are used to
29418 report the progress of a long-running operation. Naturally, including
29419 this information in command response would mean no output is produced
29420 until the command is finished, which is undesirable.
29421
29422 @item
29423 General notifications. Commands may have various side effects on
29424 the @value{GDBN} or target state beyond their official purpose. For example,
29425 a command may change the selected thread. Although such changes can
29426 be included in command response, using notification allows for more
29427 orthogonal frontend design.
29428
29429 @end itemize
29430
29431 There's no guarantee that whenever an MI command reports an error,
29432 @value{GDBN} or the target are in any specific state, and especially,
29433 the state is not reverted to the state before the MI command was
29434 processed. Therefore, whenever an MI command results in an error,
29435 we recommend that the frontend refreshes all the information shown in
29436 the user interface.
29437
29438
29439 @menu
29440 * Context management::
29441 * Asynchronous and non-stop modes::
29442 * Thread groups::
29443 @end menu
29444
29445 @node Context management
29446 @subsection Context management
29447
29448 @subsubsection Threads and Frames
29449
29450 In most cases when @value{GDBN} accesses the target, this access is
29451 done in context of a specific thread and frame (@pxref{Frames}).
29452 Often, even when accessing global data, the target requires that a thread
29453 be specified. The CLI interface maintains the selected thread and frame,
29454 and supplies them to target on each command. This is convenient,
29455 because a command line user would not want to specify that information
29456 explicitly on each command, and because user interacts with
29457 @value{GDBN} via a single terminal, so no confusion is possible as
29458 to what thread and frame are the current ones.
29459
29460 In the case of MI, the concept of selected thread and frame is less
29461 useful. First, a frontend can easily remember this information
29462 itself. Second, a graphical frontend can have more than one window,
29463 each one used for debugging a different thread, and the frontend might
29464 want to access additional threads for internal purposes. This
29465 increases the risk that by relying on implicitly selected thread, the
29466 frontend may be operating on a wrong one. Therefore, each MI command
29467 should explicitly specify which thread and frame to operate on. To
29468 make it possible, each MI command accepts the @samp{--thread} and
29469 @samp{--frame} options, the value to each is @value{GDBN} global
29470 identifier for thread and frame to operate on.
29471
29472 Usually, each top-level window in a frontend allows the user to select
29473 a thread and a frame, and remembers the user selection for further
29474 operations. However, in some cases @value{GDBN} may suggest that the
29475 current thread or frame be changed. For example, when stopping on a
29476 breakpoint it is reasonable to switch to the thread where breakpoint is
29477 hit. For another example, if the user issues the CLI @samp{thread} or
29478 @samp{frame} commands via the frontend, it is desirable to change the
29479 frontend's selection to the one specified by user. @value{GDBN}
29480 communicates the suggestion to change current thread and frame using the
29481 @samp{=thread-selected} notification.
29482
29483 Note that historically, MI shares the selected thread with CLI, so
29484 frontends used the @code{-thread-select} to execute commands in the
29485 right context. However, getting this to work right is cumbersome. The
29486 simplest way is for frontend to emit @code{-thread-select} command
29487 before every command. This doubles the number of commands that need
29488 to be sent. The alternative approach is to suppress @code{-thread-select}
29489 if the selected thread in @value{GDBN} is supposed to be identical to the
29490 thread the frontend wants to operate on. However, getting this
29491 optimization right can be tricky. In particular, if the frontend
29492 sends several commands to @value{GDBN}, and one of the commands changes the
29493 selected thread, then the behaviour of subsequent commands will
29494 change. So, a frontend should either wait for response from such
29495 problematic commands, or explicitly add @code{-thread-select} for
29496 all subsequent commands. No frontend is known to do this exactly
29497 right, so it is suggested to just always pass the @samp{--thread} and
29498 @samp{--frame} options.
29499
29500 @subsubsection Language
29501
29502 The execution of several commands depends on which language is selected.
29503 By default, the current language (@pxref{show language}) is used.
29504 But for commands known to be language-sensitive, it is recommended
29505 to use the @samp{--language} option. This option takes one argument,
29506 which is the name of the language to use while executing the command.
29507 For instance:
29508
29509 @smallexample
29510 -data-evaluate-expression --language c "sizeof (void*)"
29511 ^done,value="4"
29512 (gdb)
29513 @end smallexample
29514
29515 The valid language names are the same names accepted by the
29516 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
29517 @samp{local} or @samp{unknown}.
29518
29519 @node Asynchronous and non-stop modes
29520 @subsection Asynchronous command execution and non-stop mode
29521
29522 On some targets, @value{GDBN} is capable of processing MI commands
29523 even while the target is running. This is called @dfn{asynchronous
29524 command execution} (@pxref{Background Execution}). The frontend may
29525 specify a preference for asynchronous execution using the
29526 @code{-gdb-set mi-async 1} command, which should be emitted before
29527 either running the executable or attaching to the target. After the
29528 frontend has started the executable or attached to the target, it can
29529 find if asynchronous execution is enabled using the
29530 @code{-list-target-features} command.
29531
29532 @table @code
29533 @cindex foreground execution
29534 @cindex background execution
29535 @cindex asynchronous execution
29536 @cindex execution, foreground, background and asynchronous
29537 @kindex set mi-async
29538 @item -gdb-set mi-async @r{[}on@r{|}off@r{]}
29539 Set whether MI is in asynchronous mode.
29540
29541 When @code{off}, which is the default, MI execution commands (e.g.,
29542 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
29543 for the program to stop before processing further commands.
29544
29545 When @code{on}, MI execution commands are background execution
29546 commands (e.g., @code{-exec-continue} becomes the equivalent of the
29547 @code{c&} CLI command), and so @value{GDBN} is capable of processing
29548 MI commands even while the target is running.
29549
29550 @kindex show mi-async
29551 @item -gdb-show mi-async
29552 Show whether MI asynchronous mode is enabled.
29553 @end table
29554
29555 Note: In @value{GDBN} version 7.7 and earlier, this option was called
29556 @code{target-async} instead of @code{mi-async}, and it had the effect
29557 of both putting MI in asynchronous mode and making CLI background
29558 commands possible. CLI background commands are now always possible
29559 ``out of the box'' if the target supports them. The old spelling is
29560 kept as a deprecated alias for backwards compatibility.
29561
29562 Even if @value{GDBN} can accept a command while target is running,
29563 many commands that access the target do not work when the target is
29564 running. Therefore, asynchronous command execution is most useful
29565 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29566 it is possible to examine the state of one thread, while other threads
29567 are running.
29568
29569 When a given thread is running, MI commands that try to access the
29570 target in the context of that thread may not work, or may work only on
29571 some targets. In particular, commands that try to operate on thread's
29572 stack will not work, on any target. Commands that read memory, or
29573 modify breakpoints, may work or not work, depending on the target. Note
29574 that even commands that operate on global state, such as @code{print},
29575 @code{set}, and breakpoint commands, still access the target in the
29576 context of a specific thread, so frontend should try to find a
29577 stopped thread and perform the operation on that thread (using the
29578 @samp{--thread} option).
29579
29580 Which commands will work in the context of a running thread is
29581 highly target dependent. However, the two commands
29582 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29583 to find the state of a thread, will always work.
29584
29585 @node Thread groups
29586 @subsection Thread groups
29587 @value{GDBN} may be used to debug several processes at the same time.
29588 On some platforms, @value{GDBN} may support debugging of several
29589 hardware systems, each one having several cores with several different
29590 processes running on each core. This section describes the MI
29591 mechanism to support such debugging scenarios.
29592
29593 The key observation is that regardless of the structure of the
29594 target, MI can have a global list of threads, because most commands that
29595 accept the @samp{--thread} option do not need to know what process that
29596 thread belongs to. Therefore, it is not necessary to introduce
29597 neither additional @samp{--process} option, nor an notion of the
29598 current process in the MI interface. The only strictly new feature
29599 that is required is the ability to find how the threads are grouped
29600 into processes.
29601
29602 To allow the user to discover such grouping, and to support arbitrary
29603 hierarchy of machines/cores/processes, MI introduces the concept of a
29604 @dfn{thread group}. Thread group is a collection of threads and other
29605 thread groups. A thread group always has a string identifier, a type,
29606 and may have additional attributes specific to the type. A new
29607 command, @code{-list-thread-groups}, returns the list of top-level
29608 thread groups, which correspond to processes that @value{GDBN} is
29609 debugging at the moment. By passing an identifier of a thread group
29610 to the @code{-list-thread-groups} command, it is possible to obtain
29611 the members of specific thread group.
29612
29613 To allow the user to easily discover processes, and other objects, he
29614 wishes to debug, a concept of @dfn{available thread group} is
29615 introduced. Available thread group is an thread group that
29616 @value{GDBN} is not debugging, but that can be attached to, using the
29617 @code{-target-attach} command. The list of available top-level thread
29618 groups can be obtained using @samp{-list-thread-groups --available}.
29619 In general, the content of a thread group may be only retrieved only
29620 after attaching to that thread group.
29621
29622 Thread groups are related to inferiors (@pxref{Inferiors Connections and
29623 Programs}). Each inferior corresponds to a thread group of a special
29624 type @samp{process}, and some additional operations are permitted on
29625 such thread groups.
29626
29627 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29628 @node GDB/MI Command Syntax
29629 @section @sc{gdb/mi} Command Syntax
29630
29631 @menu
29632 * GDB/MI Input Syntax::
29633 * GDB/MI Output Syntax::
29634 @end menu
29635
29636 @node GDB/MI Input Syntax
29637 @subsection @sc{gdb/mi} Input Syntax
29638
29639 @cindex input syntax for @sc{gdb/mi}
29640 @cindex @sc{gdb/mi}, input syntax
29641 @table @code
29642 @item @var{command} @expansion{}
29643 @code{@var{cli-command} | @var{mi-command}}
29644
29645 @item @var{cli-command} @expansion{}
29646 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29647 @var{cli-command} is any existing @value{GDBN} CLI command.
29648
29649 @item @var{mi-command} @expansion{}
29650 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29651 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29652
29653 @item @var{token} @expansion{}
29654 "any sequence of digits"
29655
29656 @item @var{option} @expansion{}
29657 @code{"-" @var{parameter} [ " " @var{parameter} ]}
29658
29659 @item @var{parameter} @expansion{}
29660 @code{@var{non-blank-sequence} | @var{c-string}}
29661
29662 @item @var{operation} @expansion{}
29663 @emph{any of the operations described in this chapter}
29664
29665 @item @var{non-blank-sequence} @expansion{}
29666 @emph{anything, provided it doesn't contain special characters such as
29667 "-", @var{nl}, """ and of course " "}
29668
29669 @item @var{c-string} @expansion{}
29670 @code{""" @var{seven-bit-iso-c-string-content} """}
29671
29672 @item @var{nl} @expansion{}
29673 @code{CR | CR-LF}
29674 @end table
29675
29676 @noindent
29677 Notes:
29678
29679 @itemize @bullet
29680 @item
29681 The CLI commands are still handled by the @sc{mi} interpreter; their
29682 output is described below.
29683
29684 @item
29685 The @code{@var{token}}, when present, is passed back when the command
29686 finishes.
29687
29688 @item
29689 Some @sc{mi} commands accept optional arguments as part of the parameter
29690 list. Each option is identified by a leading @samp{-} (dash) and may be
29691 followed by an optional argument parameter. Options occur first in the
29692 parameter list and can be delimited from normal parameters using
29693 @samp{--} (this is useful when some parameters begin with a dash).
29694 @end itemize
29695
29696 Pragmatics:
29697
29698 @itemize @bullet
29699 @item
29700 We want easy access to the existing CLI syntax (for debugging).
29701
29702 @item
29703 We want it to be easy to spot a @sc{mi} operation.
29704 @end itemize
29705
29706 @node GDB/MI Output Syntax
29707 @subsection @sc{gdb/mi} Output Syntax
29708
29709 @cindex output syntax of @sc{gdb/mi}
29710 @cindex @sc{gdb/mi}, output syntax
29711 The output from @sc{gdb/mi} consists of zero or more out-of-band records
29712 followed, optionally, by a single result record. This result record
29713 is for the most recent command. The sequence of output records is
29714 terminated by @samp{(gdb)}.
29715
29716 If an input command was prefixed with a @code{@var{token}} then the
29717 corresponding output for that command will also be prefixed by that same
29718 @var{token}.
29719
29720 @table @code
29721 @item @var{output} @expansion{}
29722 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
29723
29724 @item @var{result-record} @expansion{}
29725 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29726
29727 @item @var{out-of-band-record} @expansion{}
29728 @code{@var{async-record} | @var{stream-record}}
29729
29730 @item @var{async-record} @expansion{}
29731 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29732
29733 @item @var{exec-async-output} @expansion{}
29734 @code{[ @var{token} ] "*" @var{async-output nl}}
29735
29736 @item @var{status-async-output} @expansion{}
29737 @code{[ @var{token} ] "+" @var{async-output nl}}
29738
29739 @item @var{notify-async-output} @expansion{}
29740 @code{[ @var{token} ] "=" @var{async-output nl}}
29741
29742 @item @var{async-output} @expansion{}
29743 @code{@var{async-class} ( "," @var{result} )*}
29744
29745 @item @var{result-class} @expansion{}
29746 @code{"done" | "running" | "connected" | "error" | "exit"}
29747
29748 @item @var{async-class} @expansion{}
29749 @code{"stopped" | @var{others}} (where @var{others} will be added
29750 depending on the needs---this is still in development).
29751
29752 @item @var{result} @expansion{}
29753 @code{ @var{variable} "=" @var{value}}
29754
29755 @item @var{variable} @expansion{}
29756 @code{ @var{string} }
29757
29758 @item @var{value} @expansion{}
29759 @code{ @var{const} | @var{tuple} | @var{list} }
29760
29761 @item @var{const} @expansion{}
29762 @code{@var{c-string}}
29763
29764 @item @var{tuple} @expansion{}
29765 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29766
29767 @item @var{list} @expansion{}
29768 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29769 @var{result} ( "," @var{result} )* "]" }
29770
29771 @item @var{stream-record} @expansion{}
29772 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29773
29774 @item @var{console-stream-output} @expansion{}
29775 @code{"~" @var{c-string nl}}
29776
29777 @item @var{target-stream-output} @expansion{}
29778 @code{"@@" @var{c-string nl}}
29779
29780 @item @var{log-stream-output} @expansion{}
29781 @code{"&" @var{c-string nl}}
29782
29783 @item @var{nl} @expansion{}
29784 @code{CR | CR-LF}
29785
29786 @item @var{token} @expansion{}
29787 @emph{any sequence of digits}.
29788 @end table
29789
29790 @noindent
29791 Notes:
29792
29793 @itemize @bullet
29794 @item
29795 All output sequences end in a single line containing a period.
29796
29797 @item
29798 The @code{@var{token}} is from the corresponding request. Note that
29799 for all async output, while the token is allowed by the grammar and
29800 may be output by future versions of @value{GDBN} for select async
29801 output messages, it is generally omitted. Frontends should treat
29802 all async output as reporting general changes in the state of the
29803 target and there should be no need to associate async output to any
29804 prior command.
29805
29806 @item
29807 @cindex status output in @sc{gdb/mi}
29808 @var{status-async-output} contains on-going status information about the
29809 progress of a slow operation. It can be discarded. All status output is
29810 prefixed by @samp{+}.
29811
29812 @item
29813 @cindex async output in @sc{gdb/mi}
29814 @var{exec-async-output} contains asynchronous state change on the target
29815 (stopped, started, disappeared). All async output is prefixed by
29816 @samp{*}.
29817
29818 @item
29819 @cindex notify output in @sc{gdb/mi}
29820 @var{notify-async-output} contains supplementary information that the
29821 client should handle (e.g., a new breakpoint information). All notify
29822 output is prefixed by @samp{=}.
29823
29824 @item
29825 @cindex console output in @sc{gdb/mi}
29826 @var{console-stream-output} is output that should be displayed as is in the
29827 console. It is the textual response to a CLI command. All the console
29828 output is prefixed by @samp{~}.
29829
29830 @item
29831 @cindex target output in @sc{gdb/mi}
29832 @var{target-stream-output} is the output produced by the target program.
29833 All the target output is prefixed by @samp{@@}.
29834
29835 @item
29836 @cindex log output in @sc{gdb/mi}
29837 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29838 instance messages that should be displayed as part of an error log. All
29839 the log output is prefixed by @samp{&}.
29840
29841 @item
29842 @cindex list output in @sc{gdb/mi}
29843 New @sc{gdb/mi} commands should only output @var{lists} containing
29844 @var{values}.
29845
29846
29847 @end itemize
29848
29849 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29850 details about the various output records.
29851
29852 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29853 @node GDB/MI Compatibility with CLI
29854 @section @sc{gdb/mi} Compatibility with CLI
29855
29856 @cindex compatibility, @sc{gdb/mi} and CLI
29857 @cindex @sc{gdb/mi}, compatibility with CLI
29858
29859 For the developers convenience CLI commands can be entered directly,
29860 but there may be some unexpected behaviour. For example, commands
29861 that query the user will behave as if the user replied yes, breakpoint
29862 command lists are not executed and some CLI commands, such as
29863 @code{if}, @code{when} and @code{define}, prompt for further input with
29864 @samp{>}, which is not valid MI output.
29865
29866 This feature may be removed at some stage in the future and it is
29867 recommended that front ends use the @code{-interpreter-exec} command
29868 (@pxref{-interpreter-exec}).
29869
29870 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29871 @node GDB/MI Development and Front Ends
29872 @section @sc{gdb/mi} Development and Front Ends
29873 @cindex @sc{gdb/mi} development
29874
29875 The application which takes the MI output and presents the state of the
29876 program being debugged to the user is called a @dfn{front end}.
29877
29878 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29879 to the MI interface may break existing usage. This section describes how the
29880 protocol changes and how to request previous version of the protocol when it
29881 does.
29882
29883 Some changes in MI need not break a carefully designed front end, and
29884 for these the MI version will remain unchanged. The following is a
29885 list of changes that may occur within one level, so front ends should
29886 parse MI output in a way that can handle them:
29887
29888 @itemize @bullet
29889 @item
29890 New MI commands may be added.
29891
29892 @item
29893 New fields may be added to the output of any MI command.
29894
29895 @item
29896 The range of values for fields with specified values, e.g.,
29897 @code{in_scope} (@pxref{-var-update}) may be extended.
29898
29899 @c The format of field's content e.g type prefix, may change so parse it
29900 @c at your own risk. Yes, in general?
29901
29902 @c The order of fields may change? Shouldn't really matter but it might
29903 @c resolve inconsistencies.
29904 @end itemize
29905
29906 If the changes are likely to break front ends, the MI version level
29907 will be increased by one. The new versions of the MI protocol are not compatible
29908 with the old versions. Old versions of MI remain available, allowing front ends
29909 to keep using them until they are modified to use the latest MI version.
29910
29911 Since @code{--interpreter=mi} always points to the latest MI version, it is
29912 recommended that front ends request a specific version of MI when launching
29913 @value{GDBN} (e.g.@: @code{--interpreter=mi2}) to make sure they get an
29914 interpreter with the MI version they expect.
29915
29916 The following table gives a summary of the released versions of the MI
29917 interface: the version number, the version of GDB in which it first appeared
29918 and the breaking changes compared to the previous version.
29919
29920 @multitable @columnfractions .05 .05 .9
29921 @headitem MI version @tab GDB version @tab Breaking changes
29922
29923 @item
29924 @center 1
29925 @tab
29926 @center 5.1
29927 @tab
29928 None
29929
29930 @item
29931 @center 2
29932 @tab
29933 @center 6.0
29934 @tab
29935
29936 @itemize
29937 @item
29938 The @code{-environment-pwd}, @code{-environment-directory} and
29939 @code{-environment-path} commands now returns values using the MI output
29940 syntax, rather than CLI output syntax.
29941
29942 @item
29943 @code{-var-list-children}'s @code{children} result field is now a list, rather
29944 than a tuple.
29945
29946 @item
29947 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29948 a tuple.
29949 @end itemize
29950
29951 @item
29952 @center 3
29953 @tab
29954 @center 9.1
29955 @tab
29956
29957 @itemize
29958 @item
29959 The output of information about multi-location breakpoints has changed in the
29960 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29961 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29962 The multiple locations are now placed in a @code{locations} field, whose value
29963 is a list.
29964 @end itemize
29965
29966 @end multitable
29967
29968 If your front end cannot yet migrate to a more recent version of the
29969 MI protocol, you can nevertheless selectively enable specific features
29970 available in those recent MI versions, using the following commands:
29971
29972 @table @code
29973
29974 @item -fix-multi-location-breakpoint-output
29975 Use the output for multi-location breakpoints which was introduced by
29976 MI 3, even when using MI versions 2 or 1. This command has no
29977 effect when using MI version 3 or later.
29978
29979 @end table
29980
29981 The best way to avoid unexpected changes in MI that might break your front
29982 end is to make your project known to @value{GDBN} developers and
29983 follow development on @email{gdb@@sourceware.org} and
29984 @email{gdb-patches@@sourceware.org}.
29985 @cindex mailing lists
29986
29987 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29988 @node GDB/MI Output Records
29989 @section @sc{gdb/mi} Output Records
29990
29991 @menu
29992 * GDB/MI Result Records::
29993 * GDB/MI Stream Records::
29994 * GDB/MI Async Records::
29995 * GDB/MI Breakpoint Information::
29996 * GDB/MI Frame Information::
29997 * GDB/MI Thread Information::
29998 * GDB/MI Ada Exception Information::
29999 @end menu
30000
30001 @node GDB/MI Result Records
30002 @subsection @sc{gdb/mi} Result Records
30003
30004 @cindex result records in @sc{gdb/mi}
30005 @cindex @sc{gdb/mi}, result records
30006 In addition to a number of out-of-band notifications, the response to a
30007 @sc{gdb/mi} command includes one of the following result indications:
30008
30009 @table @code
30010 @findex ^done
30011 @item "^done" [ "," @var{results} ]
30012 The synchronous operation was successful, @code{@var{results}} are the return
30013 values.
30014
30015 @item "^running"
30016 @findex ^running
30017 This result record is equivalent to @samp{^done}. Historically, it
30018 was output instead of @samp{^done} if the command has resumed the
30019 target. This behaviour is maintained for backward compatibility, but
30020 all frontends should treat @samp{^done} and @samp{^running}
30021 identically and rely on the @samp{*running} output record to determine
30022 which threads are resumed.
30023
30024 @item "^connected"
30025 @findex ^connected
30026 @value{GDBN} has connected to a remote target.
30027
30028 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
30029 @findex ^error
30030 The operation failed. The @code{msg=@var{c-string}} variable contains
30031 the corresponding error message.
30032
30033 If present, the @code{code=@var{c-string}} variable provides an error
30034 code on which consumers can rely on to detect the corresponding
30035 error condition. At present, only one error code is defined:
30036
30037 @table @samp
30038 @item "undefined-command"
30039 Indicates that the command causing the error does not exist.
30040 @end table
30041
30042 @item "^exit"
30043 @findex ^exit
30044 @value{GDBN} has terminated.
30045
30046 @end table
30047
30048 @node GDB/MI Stream Records
30049 @subsection @sc{gdb/mi} Stream Records
30050
30051 @cindex @sc{gdb/mi}, stream records
30052 @cindex stream records in @sc{gdb/mi}
30053 @value{GDBN} internally maintains a number of output streams: the console, the
30054 target, and the log. The output intended for each of these streams is
30055 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
30056
30057 Each stream record begins with a unique @dfn{prefix character} which
30058 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
30059 Syntax}). In addition to the prefix, each stream record contains a
30060 @code{@var{string-output}}. This is either raw text (with an implicit new
30061 line) or a quoted C string (which does not contain an implicit newline).
30062
30063 @table @code
30064 @item "~" @var{string-output}
30065 The console output stream contains text that should be displayed in the
30066 CLI console window. It contains the textual responses to CLI commands.
30067
30068 @item "@@" @var{string-output}
30069 The target output stream contains any textual output from the running
30070 target. This is only present when GDB's event loop is truly
30071 asynchronous, which is currently only the case for remote targets.
30072
30073 @item "&" @var{string-output}
30074 The log stream contains debugging messages being produced by @value{GDBN}'s
30075 internals.
30076 @end table
30077
30078 @node GDB/MI Async Records
30079 @subsection @sc{gdb/mi} Async Records
30080
30081 @cindex async records in @sc{gdb/mi}
30082 @cindex @sc{gdb/mi}, async records
30083 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
30084 additional changes that have occurred. Those changes can either be a
30085 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
30086 target activity (e.g., target stopped).
30087
30088 The following is the list of possible async records:
30089
30090 @table @code
30091
30092 @item *running,thread-id="@var{thread}"
30093 The target is now running. The @var{thread} field can be the global
30094 thread ID of the thread that is now running, and it can be
30095 @samp{all} if all threads are running. The frontend should assume
30096 that no interaction with a running thread is possible after this
30097 notification is produced. The frontend should not assume that this
30098 notification is output only once for any command. @value{GDBN} may
30099 emit this notification several times, either for different threads,
30100 because it cannot resume all threads together, or even for a single
30101 thread, if the thread must be stepped though some code before letting
30102 it run freely.
30103
30104 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
30105 The target has stopped. The @var{reason} field can have one of the
30106 following values:
30107
30108 @table @code
30109 @item breakpoint-hit
30110 A breakpoint was reached.
30111 @item watchpoint-trigger
30112 A watchpoint was triggered.
30113 @item read-watchpoint-trigger
30114 A read watchpoint was triggered.
30115 @item access-watchpoint-trigger
30116 An access watchpoint was triggered.
30117 @item function-finished
30118 An -exec-finish or similar CLI command was accomplished.
30119 @item location-reached
30120 An -exec-until or similar CLI command was accomplished.
30121 @item watchpoint-scope
30122 A watchpoint has gone out of scope.
30123 @item end-stepping-range
30124 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
30125 similar CLI command was accomplished.
30126 @item exited-signalled
30127 The inferior exited because of a signal.
30128 @item exited
30129 The inferior exited.
30130 @item exited-normally
30131 The inferior exited normally.
30132 @item signal-received
30133 A signal was received by the inferior.
30134 @item solib-event
30135 The inferior has stopped due to a library being loaded or unloaded.
30136 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
30137 set or when a @code{catch load} or @code{catch unload} catchpoint is
30138 in use (@pxref{Set Catchpoints}).
30139 @item fork
30140 The inferior has forked. This is reported when @code{catch fork}
30141 (@pxref{Set Catchpoints}) has been used.
30142 @item vfork
30143 The inferior has vforked. This is reported in when @code{catch vfork}
30144 (@pxref{Set Catchpoints}) has been used.
30145 @item syscall-entry
30146 The inferior entered a system call. This is reported when @code{catch
30147 syscall} (@pxref{Set Catchpoints}) has been used.
30148 @item syscall-return
30149 The inferior returned from a system call. This is reported when
30150 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
30151 @item exec
30152 The inferior called @code{exec}. This is reported when @code{catch exec}
30153 (@pxref{Set Catchpoints}) has been used.
30154 @end table
30155
30156 The @var{id} field identifies the global thread ID of the thread
30157 that directly caused the stop -- for example by hitting a breakpoint.
30158 Depending on whether all-stop
30159 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
30160 stop all threads, or only the thread that directly triggered the stop.
30161 If all threads are stopped, the @var{stopped} field will have the
30162 value of @code{"all"}. Otherwise, the value of the @var{stopped}
30163 field will be a list of thread identifiers. Presently, this list will
30164 always include a single thread, but frontend should be prepared to see
30165 several threads in the list. The @var{core} field reports the
30166 processor core on which the stop event has happened. This field may be absent
30167 if such information is not available.
30168
30169 @item =thread-group-added,id="@var{id}"
30170 @itemx =thread-group-removed,id="@var{id}"
30171 A thread group was either added or removed. The @var{id} field
30172 contains the @value{GDBN} identifier of the thread group. When a thread
30173 group is added, it generally might not be associated with a running
30174 process. When a thread group is removed, its id becomes invalid and
30175 cannot be used in any way.
30176
30177 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
30178 A thread group became associated with a running program,
30179 either because the program was just started or the thread group
30180 was attached to a program. The @var{id} field contains the
30181 @value{GDBN} identifier of the thread group. The @var{pid} field
30182 contains process identifier, specific to the operating system.
30183
30184 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
30185 A thread group is no longer associated with a running program,
30186 either because the program has exited, or because it was detached
30187 from. The @var{id} field contains the @value{GDBN} identifier of the
30188 thread group. The @var{code} field is the exit code of the inferior; it exists
30189 only when the inferior exited with some code.
30190
30191 @item =thread-created,id="@var{id}",group-id="@var{gid}"
30192 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
30193 A thread either was created, or has exited. The @var{id} field
30194 contains the global @value{GDBN} identifier of the thread. The @var{gid}
30195 field identifies the thread group this thread belongs to.
30196
30197 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
30198 Informs that the selected thread or frame were changed. This notification
30199 is not emitted as result of the @code{-thread-select} or
30200 @code{-stack-select-frame} commands, but is emitted whenever an MI command
30201 that is not documented to change the selected thread and frame actually
30202 changes them. In particular, invoking, directly or indirectly
30203 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
30204 will generate this notification. Changing the thread or frame from another
30205 user interface (see @ref{Interpreters}) will also generate this notification.
30206
30207 The @var{frame} field is only present if the newly selected thread is
30208 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
30209
30210 We suggest that in response to this notification, front ends
30211 highlight the selected thread and cause subsequent commands to apply to
30212 that thread.
30213
30214 @item =library-loaded,...
30215 Reports that a new library file was loaded by the program. This
30216 notification has 5 fields---@var{id}, @var{target-name},
30217 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
30218 opaque identifier of the library. For remote debugging case,
30219 @var{target-name} and @var{host-name} fields give the name of the
30220 library file on the target, and on the host respectively. For native
30221 debugging, both those fields have the same value. The
30222 @var{symbols-loaded} field is emitted only for backward compatibility
30223 and should not be relied on to convey any useful information. The
30224 @var{thread-group} field, if present, specifies the id of the thread
30225 group in whose context the library was loaded. If the field is
30226 absent, it means the library was loaded in the context of all present
30227 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
30228 to this library.
30229
30230 @item =library-unloaded,...
30231 Reports that a library was unloaded by the program. This notification
30232 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
30233 the same meaning as for the @code{=library-loaded} notification.
30234 The @var{thread-group} field, if present, specifies the id of the
30235 thread group in whose context the library was unloaded. If the field is
30236 absent, it means the library was unloaded in the context of all present
30237 thread groups.
30238
30239 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
30240 @itemx =traceframe-changed,end
30241 Reports that the trace frame was changed and its new number is
30242 @var{tfnum}. The number of the tracepoint associated with this trace
30243 frame is @var{tpnum}.
30244
30245 @item =tsv-created,name=@var{name},initial=@var{initial}
30246 Reports that the new trace state variable @var{name} is created with
30247 initial value @var{initial}.
30248
30249 @item =tsv-deleted,name=@var{name}
30250 @itemx =tsv-deleted
30251 Reports that the trace state variable @var{name} is deleted or all
30252 trace state variables are deleted.
30253
30254 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
30255 Reports that the trace state variable @var{name} is modified with
30256 the initial value @var{initial}. The current value @var{current} of
30257 trace state variable is optional and is reported if the current
30258 value of trace state variable is known.
30259
30260 @item =breakpoint-created,bkpt=@{...@}
30261 @itemx =breakpoint-modified,bkpt=@{...@}
30262 @itemx =breakpoint-deleted,id=@var{number}
30263 Reports that a breakpoint was created, modified, or deleted,
30264 respectively. Only user-visible breakpoints are reported to the MI
30265 user.
30266
30267 The @var{bkpt} argument is of the same form as returned by the various
30268 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
30269 @var{number} is the ordinal number of the breakpoint.
30270
30271 Note that if a breakpoint is emitted in the result record of a
30272 command, then it will not also be emitted in an async record.
30273
30274 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
30275 @itemx =record-stopped,thread-group="@var{id}"
30276 Execution log recording was either started or stopped on an
30277 inferior. The @var{id} is the @value{GDBN} identifier of the thread
30278 group corresponding to the affected inferior.
30279
30280 The @var{method} field indicates the method used to record execution. If the
30281 method in use supports multiple recording formats, @var{format} will be present
30282 and contain the currently used format. @xref{Process Record and Replay},
30283 for existing method and format values.
30284
30285 @item =cmd-param-changed,param=@var{param},value=@var{value}
30286 Reports that a parameter of the command @code{set @var{param}} is
30287 changed to @var{value}. In the multi-word @code{set} command,
30288 the @var{param} is the whole parameter list to @code{set} command.
30289 For example, In command @code{set check type on}, @var{param}
30290 is @code{check type} and @var{value} is @code{on}.
30291
30292 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
30293 Reports that bytes from @var{addr} to @var{data} + @var{len} were
30294 written in an inferior. The @var{id} is the identifier of the
30295 thread group corresponding to the affected inferior. The optional
30296 @code{type="code"} part is reported if the memory written to holds
30297 executable code.
30298 @end table
30299
30300 @node GDB/MI Breakpoint Information
30301 @subsection @sc{gdb/mi} Breakpoint Information
30302
30303 When @value{GDBN} reports information about a breakpoint, a
30304 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
30305 following fields:
30306
30307 @table @code
30308 @item number
30309 The breakpoint number.
30310
30311 @item type
30312 The type of the breakpoint. For ordinary breakpoints this will be
30313 @samp{breakpoint}, but many values are possible.
30314
30315 @item catch-type
30316 If the type of the breakpoint is @samp{catchpoint}, then this
30317 indicates the exact type of catchpoint.
30318
30319 @item disp
30320 This is the breakpoint disposition---either @samp{del}, meaning that
30321 the breakpoint will be deleted at the next stop, or @samp{keep},
30322 meaning that the breakpoint will not be deleted.
30323
30324 @item enabled
30325 This indicates whether the breakpoint is enabled, in which case the
30326 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30327 Note that this is not the same as the field @code{enable}.
30328
30329 @item addr
30330 The address of the breakpoint. This may be a hexidecimal number,
30331 giving the address; or the string @samp{<PENDING>}, for a pending
30332 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
30333 multiple locations. This field will not be present if no address can
30334 be determined. For example, a watchpoint does not have an address.
30335
30336 @item addr_flags
30337 Optional field containing any flags related to the address. These flags are
30338 architecture-dependent; see @ref{Architectures} for their meaning for a
30339 particular CPU.
30340
30341 @item func
30342 If known, the function in which the breakpoint appears.
30343 If not known, this field is not present.
30344
30345 @item filename
30346 The name of the source file which contains this function, if known.
30347 If not known, this field is not present.
30348
30349 @item fullname
30350 The full file name of the source file which contains this function, if
30351 known. If not known, this field is not present.
30352
30353 @item line
30354 The line number at which this breakpoint appears, if known.
30355 If not known, this field is not present.
30356
30357 @item at
30358 If the source file is not known, this field may be provided. If
30359 provided, this holds the address of the breakpoint, possibly followed
30360 by a symbol name.
30361
30362 @item pending
30363 If this breakpoint is pending, this field is present and holds the
30364 text used to set the breakpoint, as entered by the user.
30365
30366 @item evaluated-by
30367 Where this breakpoint's condition is evaluated, either @samp{host} or
30368 @samp{target}.
30369
30370 @item thread
30371 If this is a thread-specific breakpoint, then this identifies the
30372 thread in which the breakpoint can trigger.
30373
30374 @item task
30375 If this breakpoint is restricted to a particular Ada task, then this
30376 field will hold the task identifier.
30377
30378 @item cond
30379 If the breakpoint is conditional, this is the condition expression.
30380
30381 @item ignore
30382 The ignore count of the breakpoint.
30383
30384 @item enable
30385 The enable count of the breakpoint.
30386
30387 @item traceframe-usage
30388 FIXME.
30389
30390 @item static-tracepoint-marker-string-id
30391 For a static tracepoint, the name of the static tracepoint marker.
30392
30393 @item mask
30394 For a masked watchpoint, this is the mask.
30395
30396 @item pass
30397 A tracepoint's pass count.
30398
30399 @item original-location
30400 The location of the breakpoint as originally specified by the user.
30401 This field is optional.
30402
30403 @item times
30404 The number of times the breakpoint has been hit.
30405
30406 @item installed
30407 This field is only given for tracepoints. This is either @samp{y},
30408 meaning that the tracepoint is installed, or @samp{n}, meaning that it
30409 is not.
30410
30411 @item what
30412 Some extra data, the exact contents of which are type-dependent.
30413
30414 @item locations
30415 This field is present if the breakpoint has multiple locations. It is also
30416 exceptionally present if the breakpoint is enabled and has a single, disabled
30417 location.
30418
30419 The value is a list of locations. The format of a location is described below.
30420
30421 @end table
30422
30423 A location in a multi-location breakpoint is represented as a tuple with the
30424 following fields:
30425
30426 @table @code
30427
30428 @item number
30429 The location number as a dotted pair, like @samp{1.2}. The first digit is the
30430 number of the parent breakpoint. The second digit is the number of the
30431 location within that breakpoint.
30432
30433 @item enabled
30434 There are three possible values, with the following meanings:
30435 @table @code
30436 @item y
30437 The location is enabled.
30438 @item n
30439 The location is disabled by the user.
30440 @item N
30441 The location is disabled because the breakpoint condition is invalid
30442 at this location.
30443 @end table
30444
30445 @item addr
30446 The address of this location as an hexidecimal number.
30447
30448 @item addr_flags
30449 Optional field containing any flags related to the address. These flags are
30450 architecture-dependent; see @ref{Architectures} for their meaning for a
30451 particular CPU.
30452
30453 @item func
30454 If known, the function in which the location appears.
30455 If not known, this field is not present.
30456
30457 @item file
30458 The name of the source file which contains this location, if known.
30459 If not known, this field is not present.
30460
30461 @item fullname
30462 The full file name of the source file which contains this location, if
30463 known. If not known, this field is not present.
30464
30465 @item line
30466 The line number at which this location appears, if known.
30467 If not known, this field is not present.
30468
30469 @item thread-groups
30470 The thread groups this location is in.
30471
30472 @end table
30473
30474 For example, here is what the output of @code{-break-insert}
30475 (@pxref{GDB/MI Breakpoint Commands}) might be:
30476
30477 @smallexample
30478 -> -break-insert main
30479 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30480 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30481 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30482 times="0"@}
30483 <- (gdb)
30484 @end smallexample
30485
30486 @node GDB/MI Frame Information
30487 @subsection @sc{gdb/mi} Frame Information
30488
30489 Response from many MI commands includes an information about stack
30490 frame. This information is a tuple that may have the following
30491 fields:
30492
30493 @table @code
30494 @item level
30495 The level of the stack frame. The innermost frame has the level of
30496 zero. This field is always present.
30497
30498 @item func
30499 The name of the function corresponding to the frame. This field may
30500 be absent if @value{GDBN} is unable to determine the function name.
30501
30502 @item addr
30503 The code address for the frame. This field is always present.
30504
30505 @item addr_flags
30506 Optional field containing any flags related to the address. These flags are
30507 architecture-dependent; see @ref{Architectures} for their meaning for a
30508 particular CPU.
30509
30510 @item file
30511 The name of the source files that correspond to the frame's code
30512 address. This field may be absent.
30513
30514 @item line
30515 The source line corresponding to the frames' code address. This field
30516 may be absent.
30517
30518 @item from
30519 The name of the binary file (either executable or shared library) the
30520 corresponds to the frame's code address. This field may be absent.
30521
30522 @end table
30523
30524 @node GDB/MI Thread Information
30525 @subsection @sc{gdb/mi} Thread Information
30526
30527 Whenever @value{GDBN} has to report an information about a thread, it
30528 uses a tuple with the following fields. The fields are always present unless
30529 stated otherwise.
30530
30531 @table @code
30532 @item id
30533 The global numeric id assigned to the thread by @value{GDBN}.
30534
30535 @item target-id
30536 The target-specific string identifying the thread.
30537
30538 @item details
30539 Additional information about the thread provided by the target.
30540 It is supposed to be human-readable and not interpreted by the
30541 frontend. This field is optional.
30542
30543 @item name
30544 The name of the thread. If the user specified a name using the
30545 @code{thread name} command, then this name is given. Otherwise, if
30546 @value{GDBN} can extract the thread name from the target, then that
30547 name is given. If @value{GDBN} cannot find the thread name, then this
30548 field is omitted.
30549
30550 @item state
30551 The execution state of the thread, either @samp{stopped} or @samp{running},
30552 depending on whether the thread is presently running.
30553
30554 @item frame
30555 The stack frame currently executing in the thread. This field is only present
30556 if the thread is stopped. Its format is documented in
30557 @ref{GDB/MI Frame Information}.
30558
30559 @item core
30560 The value of this field is an integer number of the processor core the
30561 thread was last seen on. This field is optional.
30562 @end table
30563
30564 @node GDB/MI Ada Exception Information
30565 @subsection @sc{gdb/mi} Ada Exception Information
30566
30567 Whenever a @code{*stopped} record is emitted because the program
30568 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30569 @value{GDBN} provides the name of the exception that was raised via
30570 the @code{exception-name} field. Also, for exceptions that were raised
30571 with an exception message, @value{GDBN} provides that message via
30572 the @code{exception-message} field.
30573
30574 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30575 @node GDB/MI Simple Examples
30576 @section Simple Examples of @sc{gdb/mi} Interaction
30577 @cindex @sc{gdb/mi}, simple examples
30578
30579 This subsection presents several simple examples of interaction using
30580 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30581 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30582 the output received from @sc{gdb/mi}.
30583
30584 Note the line breaks shown in the examples are here only for
30585 readability, they don't appear in the real output.
30586
30587 @subheading Setting a Breakpoint
30588
30589 Setting a breakpoint generates synchronous output which contains detailed
30590 information of the breakpoint.
30591
30592 @smallexample
30593 -> -break-insert main
30594 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30595 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30596 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30597 times="0"@}
30598 <- (gdb)
30599 @end smallexample
30600
30601 @subheading Program Execution
30602
30603 Program execution generates asynchronous records and MI gives the
30604 reason that execution stopped.
30605
30606 @smallexample
30607 -> -exec-run
30608 <- ^running
30609 <- (gdb)
30610 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
30611 frame=@{addr="0x08048564",func="main",
30612 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
30613 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30614 arch="i386:x86_64"@}
30615 <- (gdb)
30616 -> -exec-continue
30617 <- ^running
30618 <- (gdb)
30619 <- *stopped,reason="exited-normally"
30620 <- (gdb)
30621 @end smallexample
30622
30623 @subheading Quitting @value{GDBN}
30624
30625 Quitting @value{GDBN} just prints the result class @samp{^exit}.
30626
30627 @smallexample
30628 -> (gdb)
30629 <- -gdb-exit
30630 <- ^exit
30631 @end smallexample
30632
30633 Please note that @samp{^exit} is printed immediately, but it might
30634 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30635 performs necessary cleanups, including killing programs being debugged
30636 or disconnecting from debug hardware, so the frontend should wait till
30637 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30638 fails to exit in reasonable time.
30639
30640 @subheading A Bad Command
30641
30642 Here's what happens if you pass a non-existent command:
30643
30644 @smallexample
30645 -> -rubbish
30646 <- ^error,msg="Undefined MI command: rubbish"
30647 <- (gdb)
30648 @end smallexample
30649
30650
30651 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30652 @node GDB/MI Command Description Format
30653 @section @sc{gdb/mi} Command Description Format
30654
30655 The remaining sections describe blocks of commands. Each block of
30656 commands is laid out in a fashion similar to this section.
30657
30658 @subheading Motivation
30659
30660 The motivation for this collection of commands.
30661
30662 @subheading Introduction
30663
30664 A brief introduction to this collection of commands as a whole.
30665
30666 @subheading Commands
30667
30668 For each command in the block, the following is described:
30669
30670 @subsubheading Synopsis
30671
30672 @smallexample
30673 -command @var{args}@dots{}
30674 @end smallexample
30675
30676 @subsubheading Result
30677
30678 @subsubheading @value{GDBN} Command
30679
30680 The corresponding @value{GDBN} CLI command(s), if any.
30681
30682 @subsubheading Example
30683
30684 Example(s) formatted for readability. Some of the described commands have
30685 not been implemented yet and these are labeled N.A.@: (not available).
30686
30687
30688 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30689 @node GDB/MI Breakpoint Commands
30690 @section @sc{gdb/mi} Breakpoint Commands
30691
30692 @cindex breakpoint commands for @sc{gdb/mi}
30693 @cindex @sc{gdb/mi}, breakpoint commands
30694 This section documents @sc{gdb/mi} commands for manipulating
30695 breakpoints.
30696
30697 @subheading The @code{-break-after} Command
30698 @findex -break-after
30699
30700 @subsubheading Synopsis
30701
30702 @smallexample
30703 -break-after @var{number} @var{count}
30704 @end smallexample
30705
30706 The breakpoint number @var{number} is not in effect until it has been
30707 hit @var{count} times. To see how this is reflected in the output of
30708 the @samp{-break-list} command, see the description of the
30709 @samp{-break-list} command below.
30710
30711 @subsubheading @value{GDBN} Command
30712
30713 The corresponding @value{GDBN} command is @samp{ignore}.
30714
30715 @subsubheading Example
30716
30717 @smallexample
30718 (gdb)
30719 -break-insert main
30720 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30721 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30722 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30723 times="0"@}
30724 (gdb)
30725 -break-after 1 3
30726 ~
30727 ^done
30728 (gdb)
30729 -break-list
30730 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30731 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30732 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30733 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30734 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30735 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30736 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30737 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30738 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30739 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
30740 (gdb)
30741 @end smallexample
30742
30743 @ignore
30744 @subheading The @code{-break-catch} Command
30745 @findex -break-catch
30746 @end ignore
30747
30748 @subheading The @code{-break-commands} Command
30749 @findex -break-commands
30750
30751 @subsubheading Synopsis
30752
30753 @smallexample
30754 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30755 @end smallexample
30756
30757 Specifies the CLI commands that should be executed when breakpoint
30758 @var{number} is hit. The parameters @var{command1} to @var{commandN}
30759 are the commands. If no command is specified, any previously-set
30760 commands are cleared. @xref{Break Commands}. Typical use of this
30761 functionality is tracing a program, that is, printing of values of
30762 some variables whenever breakpoint is hit and then continuing.
30763
30764 @subsubheading @value{GDBN} Command
30765
30766 The corresponding @value{GDBN} command is @samp{commands}.
30767
30768 @subsubheading Example
30769
30770 @smallexample
30771 (gdb)
30772 -break-insert main
30773 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30774 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30775 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30776 times="0"@}
30777 (gdb)
30778 -break-commands 1 "print v" "continue"
30779 ^done
30780 (gdb)
30781 @end smallexample
30782
30783 @subheading The @code{-break-condition} Command
30784 @findex -break-condition
30785
30786 @subsubheading Synopsis
30787
30788 @smallexample
30789 -break-condition [ --force ] @var{number} [ @var{expr} ]
30790 @end smallexample
30791
30792 Breakpoint @var{number} will stop the program only if the condition in
30793 @var{expr} is true. The condition becomes part of the
30794 @samp{-break-list} output (see the description of the @samp{-break-list}
30795 command below). If the @samp{--force} flag is passed, the condition
30796 is forcibly defined even when it is invalid for all locations of
30797 breakpoint @var{number}. If the @var{expr} argument is omitted,
30798 breakpoint @var{number} becomes unconditional.
30799
30800 @subsubheading @value{GDBN} Command
30801
30802 The corresponding @value{GDBN} command is @samp{condition}.
30803
30804 @subsubheading Example
30805
30806 @smallexample
30807 (gdb)
30808 -break-condition 1 1
30809 ^done
30810 (gdb)
30811 -break-list
30812 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30813 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30814 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30815 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30816 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30817 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30818 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30819 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30820 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30821 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
30822 (gdb)
30823 @end smallexample
30824
30825 @subheading The @code{-break-delete} Command
30826 @findex -break-delete
30827
30828 @subsubheading Synopsis
30829
30830 @smallexample
30831 -break-delete ( @var{breakpoint} )+
30832 @end smallexample
30833
30834 Delete the breakpoint(s) whose number(s) are specified in the argument
30835 list. This is obviously reflected in the breakpoint list.
30836
30837 @subsubheading @value{GDBN} Command
30838
30839 The corresponding @value{GDBN} command is @samp{delete}.
30840
30841 @subsubheading Example
30842
30843 @smallexample
30844 (gdb)
30845 -break-delete 1
30846 ^done
30847 (gdb)
30848 -break-list
30849 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30850 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30851 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30852 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30853 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30854 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30855 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30856 body=[]@}
30857 (gdb)
30858 @end smallexample
30859
30860 @subheading The @code{-break-disable} Command
30861 @findex -break-disable
30862
30863 @subsubheading Synopsis
30864
30865 @smallexample
30866 -break-disable ( @var{breakpoint} )+
30867 @end smallexample
30868
30869 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30870 break list is now set to @samp{n} for the named @var{breakpoint}(s).
30871
30872 @subsubheading @value{GDBN} Command
30873
30874 The corresponding @value{GDBN} command is @samp{disable}.
30875
30876 @subsubheading Example
30877
30878 @smallexample
30879 (gdb)
30880 -break-disable 2
30881 ^done
30882 (gdb)
30883 -break-list
30884 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30885 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30886 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30887 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30888 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30889 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30890 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30891 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30892 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30893 line="5",thread-groups=["i1"],times="0"@}]@}
30894 (gdb)
30895 @end smallexample
30896
30897 @subheading The @code{-break-enable} Command
30898 @findex -break-enable
30899
30900 @subsubheading Synopsis
30901
30902 @smallexample
30903 -break-enable ( @var{breakpoint} )+
30904 @end smallexample
30905
30906 Enable (previously disabled) @var{breakpoint}(s).
30907
30908 @subsubheading @value{GDBN} Command
30909
30910 The corresponding @value{GDBN} command is @samp{enable}.
30911
30912 @subsubheading Example
30913
30914 @smallexample
30915 (gdb)
30916 -break-enable 2
30917 ^done
30918 (gdb)
30919 -break-list
30920 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30921 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30922 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30923 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30924 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30925 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30926 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30927 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30928 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30929 line="5",thread-groups=["i1"],times="0"@}]@}
30930 (gdb)
30931 @end smallexample
30932
30933 @subheading The @code{-break-info} Command
30934 @findex -break-info
30935
30936 @subsubheading Synopsis
30937
30938 @smallexample
30939 -break-info @var{breakpoint}
30940 @end smallexample
30941
30942 @c REDUNDANT???
30943 Get information about a single breakpoint.
30944
30945 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30946 Information}, for details on the format of each breakpoint in the
30947 table.
30948
30949 @subsubheading @value{GDBN} Command
30950
30951 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30952
30953 @subsubheading Example
30954 N.A.
30955
30956 @subheading The @code{-break-insert} Command
30957 @findex -break-insert
30958 @anchor{-break-insert}
30959
30960 @subsubheading Synopsis
30961
30962 @smallexample
30963 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
30964 [ -c @var{condition} ] [ --force-condition ] [ -i @var{ignore-count} ]
30965 [ -p @var{thread-id} ] [ @var{location} ]
30966 @end smallexample
30967
30968 @noindent
30969 If specified, @var{location}, can be one of:
30970
30971 @table @var
30972 @item linespec location
30973 A linespec location. @xref{Linespec Locations}.
30974
30975 @item explicit location
30976 An explicit location. @sc{gdb/mi} explicit locations are
30977 analogous to the CLI's explicit locations using the option names
30978 listed below. @xref{Explicit Locations}.
30979
30980 @table @samp
30981 @item --source @var{filename}
30982 The source file name of the location. This option requires the use
30983 of either @samp{--function} or @samp{--line}.
30984
30985 @item --function @var{function}
30986 The name of a function or method.
30987
30988 @item --label @var{label}
30989 The name of a label.
30990
30991 @item --line @var{lineoffset}
30992 An absolute or relative line offset from the start of the location.
30993 @end table
30994
30995 @item address location
30996 An address location, *@var{address}. @xref{Address Locations}.
30997 @end table
30998
30999 @noindent
31000 The possible optional parameters of this command are:
31001
31002 @table @samp
31003 @item -t
31004 Insert a temporary breakpoint.
31005 @item -h
31006 Insert a hardware breakpoint.
31007 @item -f
31008 If @var{location} cannot be parsed (for example if it
31009 refers to unknown files or functions), create a pending
31010 breakpoint. Without this flag, @value{GDBN} will report
31011 an error, and won't create a breakpoint, if @var{location}
31012 cannot be parsed.
31013 @item -d
31014 Create a disabled breakpoint.
31015 @item -a
31016 Create a tracepoint. @xref{Tracepoints}. When this parameter
31017 is used together with @samp{-h}, a fast tracepoint is created.
31018 @item -c @var{condition}
31019 Make the breakpoint conditional on @var{condition}.
31020 @item --force-condition
31021 Forcibly define the breakpoint even if the condition is invalid at
31022 all of the breakpoint locations.
31023 @item -i @var{ignore-count}
31024 Initialize the @var{ignore-count}.
31025 @item -p @var{thread-id}
31026 Restrict the breakpoint to the thread with the specified global
31027 @var{thread-id}.
31028 @item --qualified
31029 This option makes @value{GDBN} interpret a function name specified as
31030 a complete fully-qualified name.
31031 @end table
31032
31033 @subsubheading Result
31034
31035 @xref{GDB/MI Breakpoint Information}, for details on the format of the
31036 resulting breakpoint.
31037
31038 Note: this format is open to change.
31039 @c An out-of-band breakpoint instead of part of the result?
31040
31041 @subsubheading @value{GDBN} Command
31042
31043 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
31044 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
31045
31046 @subsubheading Example
31047
31048 @smallexample
31049 (gdb)
31050 -break-insert main
31051 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
31052 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
31053 times="0"@}
31054 (gdb)
31055 -break-insert -t foo
31056 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
31057 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
31058 times="0"@}
31059 (gdb)
31060 -break-list
31061 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31062 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31063 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31064 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31065 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31066 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31067 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31068 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31069 addr="0x0001072c", func="main",file="recursive2.c",
31070 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
31071 times="0"@},
31072 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
31073 addr="0x00010774",func="foo",file="recursive2.c",
31074 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
31075 times="0"@}]@}
31076 (gdb)
31077 @c -break-insert -r foo.*
31078 @c ~int foo(int, int);
31079 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
31080 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
31081 @c times="0"@}
31082 @c (gdb)
31083 @end smallexample
31084
31085 @subheading The @code{-dprintf-insert} Command
31086 @findex -dprintf-insert
31087
31088 @subsubheading Synopsis
31089
31090 @smallexample
31091 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
31092 [ -c @var{condition} ] [--force-condition] [ -i @var{ignore-count} ]
31093 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
31094 [ @var{argument} ]
31095 @end smallexample
31096
31097 @noindent
31098 If supplied, @var{location} and @code{--qualified} may be specified
31099 the same way as for the @code{-break-insert} command.
31100 @xref{-break-insert}.
31101
31102 The possible optional parameters of this command are:
31103
31104 @table @samp
31105 @item -t
31106 Insert a temporary breakpoint.
31107 @item -f
31108 If @var{location} cannot be parsed (for example, if it
31109 refers to unknown files or functions), create a pending
31110 breakpoint. Without this flag, @value{GDBN} will report
31111 an error, and won't create a breakpoint, if @var{location}
31112 cannot be parsed.
31113 @item -d
31114 Create a disabled breakpoint.
31115 @item -c @var{condition}
31116 Make the breakpoint conditional on @var{condition}.
31117 @item --force-condition
31118 Forcibly define the breakpoint even if the condition is invalid at
31119 all of the breakpoint locations.
31120 @item -i @var{ignore-count}
31121 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
31122 to @var{ignore-count}.
31123 @item -p @var{thread-id}
31124 Restrict the breakpoint to the thread with the specified global
31125 @var{thread-id}.
31126 @end table
31127
31128 @subsubheading Result
31129
31130 @xref{GDB/MI Breakpoint Information}, for details on the format of the
31131 resulting breakpoint.
31132
31133 @c An out-of-band breakpoint instead of part of the result?
31134
31135 @subsubheading @value{GDBN} Command
31136
31137 The corresponding @value{GDBN} command is @samp{dprintf}.
31138
31139 @subsubheading Example
31140
31141 @smallexample
31142 (gdb)
31143 4-dprintf-insert foo "At foo entry\n"
31144 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
31145 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
31146 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
31147 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
31148 original-location="foo"@}
31149 (gdb)
31150 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
31151 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
31152 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
31153 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
31154 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
31155 original-location="mi-dprintf.c:26"@}
31156 (gdb)
31157 @end smallexample
31158
31159 @subheading The @code{-break-list} Command
31160 @findex -break-list
31161
31162 @subsubheading Synopsis
31163
31164 @smallexample
31165 -break-list
31166 @end smallexample
31167
31168 Displays the list of inserted breakpoints, showing the following fields:
31169
31170 @table @samp
31171 @item Number
31172 number of the breakpoint
31173 @item Type
31174 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
31175 @item Disposition
31176 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
31177 or @samp{nokeep}
31178 @item Enabled
31179 is the breakpoint enabled or no: @samp{y} or @samp{n}
31180 @item Address
31181 memory location at which the breakpoint is set
31182 @item What
31183 logical location of the breakpoint, expressed by function name, file
31184 name, line number
31185 @item Thread-groups
31186 list of thread groups to which this breakpoint applies
31187 @item Times
31188 number of times the breakpoint has been hit
31189 @end table
31190
31191 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
31192 @code{body} field is an empty list.
31193
31194 @subsubheading @value{GDBN} Command
31195
31196 The corresponding @value{GDBN} command is @samp{info break}.
31197
31198 @subsubheading Example
31199
31200 @smallexample
31201 (gdb)
31202 -break-list
31203 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31204 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31205 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31206 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31207 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31208 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31209 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31210 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31211 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
31212 times="0"@},
31213 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
31214 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
31215 line="13",thread-groups=["i1"],times="0"@}]@}
31216 (gdb)
31217 @end smallexample
31218
31219 Here's an example of the result when there are no breakpoints:
31220
31221 @smallexample
31222 (gdb)
31223 -break-list
31224 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
31225 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31226 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31227 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31228 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31229 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31230 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31231 body=[]@}
31232 (gdb)
31233 @end smallexample
31234
31235 @subheading The @code{-break-passcount} Command
31236 @findex -break-passcount
31237
31238 @subsubheading Synopsis
31239
31240 @smallexample
31241 -break-passcount @var{tracepoint-number} @var{passcount}
31242 @end smallexample
31243
31244 Set the passcount for tracepoint @var{tracepoint-number} to
31245 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
31246 is not a tracepoint, error is emitted. This corresponds to CLI
31247 command @samp{passcount}.
31248
31249 @subheading The @code{-break-watch} Command
31250 @findex -break-watch
31251
31252 @subsubheading Synopsis
31253
31254 @smallexample
31255 -break-watch [ -a | -r ]
31256 @end smallexample
31257
31258 Create a watchpoint. With the @samp{-a} option it will create an
31259 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
31260 read from or on a write to the memory location. With the @samp{-r}
31261 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
31262 trigger only when the memory location is accessed for reading. Without
31263 either of the options, the watchpoint created is a regular watchpoint,
31264 i.e., it will trigger when the memory location is accessed for writing.
31265 @xref{Set Watchpoints, , Setting Watchpoints}.
31266
31267 Note that @samp{-break-list} will report a single list of watchpoints and
31268 breakpoints inserted.
31269
31270 @subsubheading @value{GDBN} Command
31271
31272 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
31273 @samp{rwatch}.
31274
31275 @subsubheading Example
31276
31277 Setting a watchpoint on a variable in the @code{main} function:
31278
31279 @smallexample
31280 (gdb)
31281 -break-watch x
31282 ^done,wpt=@{number="2",exp="x"@}
31283 (gdb)
31284 -exec-continue
31285 ^running
31286 (gdb)
31287 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
31288 value=@{old="-268439212",new="55"@},
31289 frame=@{func="main",args=[],file="recursive2.c",
31290 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
31291 (gdb)
31292 @end smallexample
31293
31294 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
31295 the program execution twice: first for the variable changing value, then
31296 for the watchpoint going out of scope.
31297
31298 @smallexample
31299 (gdb)
31300 -break-watch C
31301 ^done,wpt=@{number="5",exp="C"@}
31302 (gdb)
31303 -exec-continue
31304 ^running
31305 (gdb)
31306 *stopped,reason="watchpoint-trigger",
31307 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
31308 frame=@{func="callee4",args=[],
31309 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31310 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31311 arch="i386:x86_64"@}
31312 (gdb)
31313 -exec-continue
31314 ^running
31315 (gdb)
31316 *stopped,reason="watchpoint-scope",wpnum="5",
31317 frame=@{func="callee3",args=[@{name="strarg",
31318 value="0x11940 \"A string argument.\""@}],
31319 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31320 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31321 arch="i386:x86_64"@}
31322 (gdb)
31323 @end smallexample
31324
31325 Listing breakpoints and watchpoints, at different points in the program
31326 execution. Note that once the watchpoint goes out of scope, it is
31327 deleted.
31328
31329 @smallexample
31330 (gdb)
31331 -break-watch C
31332 ^done,wpt=@{number="2",exp="C"@}
31333 (gdb)
31334 -break-list
31335 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31336 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31337 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31338 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31339 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31340 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31341 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31342 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31343 addr="0x00010734",func="callee4",
31344 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31345 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
31346 times="1"@},
31347 bkpt=@{number="2",type="watchpoint",disp="keep",
31348 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
31349 (gdb)
31350 -exec-continue
31351 ^running
31352 (gdb)
31353 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
31354 value=@{old="-276895068",new="3"@},
31355 frame=@{func="callee4",args=[],
31356 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31357 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31358 arch="i386:x86_64"@}
31359 (gdb)
31360 -break-list
31361 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31362 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31363 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31364 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31365 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31366 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31367 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31368 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31369 addr="0x00010734",func="callee4",
31370 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31371 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
31372 times="1"@},
31373 bkpt=@{number="2",type="watchpoint",disp="keep",
31374 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
31375 (gdb)
31376 -exec-continue
31377 ^running
31378 ^done,reason="watchpoint-scope",wpnum="2",
31379 frame=@{func="callee3",args=[@{name="strarg",
31380 value="0x11940 \"A string argument.\""@}],
31381 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31382 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31383 arch="i386:x86_64"@}
31384 (gdb)
31385 -break-list
31386 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31387 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31388 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31389 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31390 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31391 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31392 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31393 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31394 addr="0x00010734",func="callee4",
31395 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31396 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31397 thread-groups=["i1"],times="1"@}]@}
31398 (gdb)
31399 @end smallexample
31400
31401
31402 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31403 @node GDB/MI Catchpoint Commands
31404 @section @sc{gdb/mi} Catchpoint Commands
31405
31406 This section documents @sc{gdb/mi} commands for manipulating
31407 catchpoints.
31408
31409 @menu
31410 * Shared Library GDB/MI Catchpoint Commands::
31411 * Ada Exception GDB/MI Catchpoint Commands::
31412 * C++ Exception GDB/MI Catchpoint Commands::
31413 @end menu
31414
31415 @node Shared Library GDB/MI Catchpoint Commands
31416 @subsection Shared Library @sc{gdb/mi} Catchpoints
31417
31418 @subheading The @code{-catch-load} Command
31419 @findex -catch-load
31420
31421 @subsubheading Synopsis
31422
31423 @smallexample
31424 -catch-load [ -t ] [ -d ] @var{regexp}
31425 @end smallexample
31426
31427 Add a catchpoint for library load events. If the @samp{-t} option is used,
31428 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31429 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
31430 in a disabled state. The @samp{regexp} argument is a regular
31431 expression used to match the name of the loaded library.
31432
31433
31434 @subsubheading @value{GDBN} Command
31435
31436 The corresponding @value{GDBN} command is @samp{catch load}.
31437
31438 @subsubheading Example
31439
31440 @smallexample
31441 -catch-load -t foo.so
31442 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
31443 what="load of library matching foo.so",catch-type="load",times="0"@}
31444 (gdb)
31445 @end smallexample
31446
31447
31448 @subheading The @code{-catch-unload} Command
31449 @findex -catch-unload
31450
31451 @subsubheading Synopsis
31452
31453 @smallexample
31454 -catch-unload [ -t ] [ -d ] @var{regexp}
31455 @end smallexample
31456
31457 Add a catchpoint for library unload events. If the @samp{-t} option is
31458 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31459 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
31460 created in a disabled state. The @samp{regexp} argument is a regular
31461 expression used to match the name of the unloaded library.
31462
31463 @subsubheading @value{GDBN} Command
31464
31465 The corresponding @value{GDBN} command is @samp{catch unload}.
31466
31467 @subsubheading Example
31468
31469 @smallexample
31470 -catch-unload -d bar.so
31471 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
31472 what="load of library matching bar.so",catch-type="unload",times="0"@}
31473 (gdb)
31474 @end smallexample
31475
31476 @node Ada Exception GDB/MI Catchpoint Commands
31477 @subsection Ada Exception @sc{gdb/mi} Catchpoints
31478
31479 The following @sc{gdb/mi} commands can be used to create catchpoints
31480 that stop the execution when Ada exceptions are being raised.
31481
31482 @subheading The @code{-catch-assert} Command
31483 @findex -catch-assert
31484
31485 @subsubheading Synopsis
31486
31487 @smallexample
31488 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
31489 @end smallexample
31490
31491 Add a catchpoint for failed Ada assertions.
31492
31493 The possible optional parameters for this command are:
31494
31495 @table @samp
31496 @item -c @var{condition}
31497 Make the catchpoint conditional on @var{condition}.
31498 @item -d
31499 Create a disabled catchpoint.
31500 @item -t
31501 Create a temporary catchpoint.
31502 @end table
31503
31504 @subsubheading @value{GDBN} Command
31505
31506 The corresponding @value{GDBN} command is @samp{catch assert}.
31507
31508 @subsubheading Example
31509
31510 @smallexample
31511 -catch-assert
31512 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
31513 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
31514 thread-groups=["i1"],times="0",
31515 original-location="__gnat_debug_raise_assert_failure"@}
31516 (gdb)
31517 @end smallexample
31518
31519 @subheading The @code{-catch-exception} Command
31520 @findex -catch-exception
31521
31522 @subsubheading Synopsis
31523
31524 @smallexample
31525 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31526 [ -t ] [ -u ]
31527 @end smallexample
31528
31529 Add a catchpoint stopping when Ada exceptions are raised.
31530 By default, the command stops the program when any Ada exception
31531 gets raised. But it is also possible, by using some of the
31532 optional parameters described below, to create more selective
31533 catchpoints.
31534
31535 The possible optional parameters for this command are:
31536
31537 @table @samp
31538 @item -c @var{condition}
31539 Make the catchpoint conditional on @var{condition}.
31540 @item -d
31541 Create a disabled catchpoint.
31542 @item -e @var{exception-name}
31543 Only stop when @var{exception-name} is raised. This option cannot
31544 be used combined with @samp{-u}.
31545 @item -t
31546 Create a temporary catchpoint.
31547 @item -u
31548 Stop only when an unhandled exception gets raised. This option
31549 cannot be used combined with @samp{-e}.
31550 @end table
31551
31552 @subsubheading @value{GDBN} Command
31553
31554 The corresponding @value{GDBN} commands are @samp{catch exception}
31555 and @samp{catch exception unhandled}.
31556
31557 @subsubheading Example
31558
31559 @smallexample
31560 -catch-exception -e Program_Error
31561 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31562 enabled="y",addr="0x0000000000404874",
31563 what="`Program_Error' Ada exception", thread-groups=["i1"],
31564 times="0",original-location="__gnat_debug_raise_exception"@}
31565 (gdb)
31566 @end smallexample
31567
31568 @subheading The @code{-catch-handlers} Command
31569 @findex -catch-handlers
31570
31571 @subsubheading Synopsis
31572
31573 @smallexample
31574 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31575 [ -t ]
31576 @end smallexample
31577
31578 Add a catchpoint stopping when Ada exceptions are handled.
31579 By default, the command stops the program when any Ada exception
31580 gets handled. But it is also possible, by using some of the
31581 optional parameters described below, to create more selective
31582 catchpoints.
31583
31584 The possible optional parameters for this command are:
31585
31586 @table @samp
31587 @item -c @var{condition}
31588 Make the catchpoint conditional on @var{condition}.
31589 @item -d
31590 Create a disabled catchpoint.
31591 @item -e @var{exception-name}
31592 Only stop when @var{exception-name} is handled.
31593 @item -t
31594 Create a temporary catchpoint.
31595 @end table
31596
31597 @subsubheading @value{GDBN} Command
31598
31599 The corresponding @value{GDBN} command is @samp{catch handlers}.
31600
31601 @subsubheading Example
31602
31603 @smallexample
31604 -catch-handlers -e Constraint_Error
31605 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31606 enabled="y",addr="0x0000000000402f68",
31607 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31608 times="0",original-location="__gnat_begin_handler"@}
31609 (gdb)
31610 @end smallexample
31611
31612 @node C++ Exception GDB/MI Catchpoint Commands
31613 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31614
31615 The following @sc{gdb/mi} commands can be used to create catchpoints
31616 that stop the execution when C@t{++} exceptions are being throw, rethrown,
31617 or caught.
31618
31619 @subheading The @code{-catch-throw} Command
31620 @findex -catch-throw
31621
31622 @subsubheading Synopsis
31623
31624 @smallexample
31625 -catch-throw [ -t ] [ -r @var{regexp}]
31626 @end smallexample
31627
31628 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31629 given, then only exceptions whose type matches the regular expression
31630 will be caught.
31631
31632 If @samp{-t} is given, then the catchpoint is enabled only for one
31633 stop, the catchpoint is automatically deleted after stopping once for
31634 the event.
31635
31636 @subsubheading @value{GDBN} Command
31637
31638 The corresponding @value{GDBN} commands are @samp{catch throw}
31639 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31640
31641 @subsubheading Example
31642
31643 @smallexample
31644 -catch-throw -r exception_type
31645 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31646 what="exception throw",catch-type="throw",
31647 thread-groups=["i1"],
31648 regexp="exception_type",times="0"@}
31649 (gdb)
31650 -exec-run
31651 ^running
31652 (gdb)
31653 ~"\n"
31654 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31655 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31656 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31657 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31658 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31659 thread-id="1",stopped-threads="all",core="6"
31660 (gdb)
31661 @end smallexample
31662
31663 @subheading The @code{-catch-rethrow} Command
31664 @findex -catch-rethrow
31665
31666 @subsubheading Synopsis
31667
31668 @smallexample
31669 -catch-rethrow [ -t ] [ -r @var{regexp}]
31670 @end smallexample
31671
31672 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31673 then only exceptions whose type matches the regular expression will be
31674 caught.
31675
31676 If @samp{-t} is given, then the catchpoint is enabled only for one
31677 stop, the catchpoint is automatically deleted after the first event is
31678 caught.
31679
31680 @subsubheading @value{GDBN} Command
31681
31682 The corresponding @value{GDBN} commands are @samp{catch rethrow}
31683 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31684
31685 @subsubheading Example
31686
31687 @smallexample
31688 -catch-rethrow -r exception_type
31689 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31690 what="exception rethrow",catch-type="rethrow",
31691 thread-groups=["i1"],
31692 regexp="exception_type",times="0"@}
31693 (gdb)
31694 -exec-run
31695 ^running
31696 (gdb)
31697 ~"\n"
31698 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31699 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31700 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31701 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31702 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31703 thread-id="1",stopped-threads="all",core="6"
31704 (gdb)
31705 @end smallexample
31706
31707 @subheading The @code{-catch-catch} Command
31708 @findex -catch-catch
31709
31710 @subsubheading Synopsis
31711
31712 @smallexample
31713 -catch-catch [ -t ] [ -r @var{regexp}]
31714 @end smallexample
31715
31716 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31717 is given, then only exceptions whose type matches the regular
31718 expression will be caught.
31719
31720 If @samp{-t} is given, then the catchpoint is enabled only for one
31721 stop, the catchpoint is automatically deleted after the first event is
31722 caught.
31723
31724 @subsubheading @value{GDBN} Command
31725
31726 The corresponding @value{GDBN} commands are @samp{catch catch}
31727 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31728
31729 @subsubheading Example
31730
31731 @smallexample
31732 -catch-catch -r exception_type
31733 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31734 what="exception catch",catch-type="catch",
31735 thread-groups=["i1"],
31736 regexp="exception_type",times="0"@}
31737 (gdb)
31738 -exec-run
31739 ^running
31740 (gdb)
31741 ~"\n"
31742 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31743 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31744 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31745 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31746 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31747 thread-id="1",stopped-threads="all",core="6"
31748 (gdb)
31749 @end smallexample
31750
31751 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31752 @node GDB/MI Program Context
31753 @section @sc{gdb/mi} Program Context
31754
31755 @subheading The @code{-exec-arguments} Command
31756 @findex -exec-arguments
31757
31758
31759 @subsubheading Synopsis
31760
31761 @smallexample
31762 -exec-arguments @var{args}
31763 @end smallexample
31764
31765 Set the inferior program arguments, to be used in the next
31766 @samp{-exec-run}.
31767
31768 @subsubheading @value{GDBN} Command
31769
31770 The corresponding @value{GDBN} command is @samp{set args}.
31771
31772 @subsubheading Example
31773
31774 @smallexample
31775 (gdb)
31776 -exec-arguments -v word
31777 ^done
31778 (gdb)
31779 @end smallexample
31780
31781
31782 @ignore
31783 @subheading The @code{-exec-show-arguments} Command
31784 @findex -exec-show-arguments
31785
31786 @subsubheading Synopsis
31787
31788 @smallexample
31789 -exec-show-arguments
31790 @end smallexample
31791
31792 Print the arguments of the program.
31793
31794 @subsubheading @value{GDBN} Command
31795
31796 The corresponding @value{GDBN} command is @samp{show args}.
31797
31798 @subsubheading Example
31799 N.A.
31800 @end ignore
31801
31802
31803 @subheading The @code{-environment-cd} Command
31804 @findex -environment-cd
31805
31806 @subsubheading Synopsis
31807
31808 @smallexample
31809 -environment-cd @var{pathdir}
31810 @end smallexample
31811
31812 Set @value{GDBN}'s working directory.
31813
31814 @subsubheading @value{GDBN} Command
31815
31816 The corresponding @value{GDBN} command is @samp{cd}.
31817
31818 @subsubheading Example
31819
31820 @smallexample
31821 (gdb)
31822 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31823 ^done
31824 (gdb)
31825 @end smallexample
31826
31827
31828 @subheading The @code{-environment-directory} Command
31829 @findex -environment-directory
31830
31831 @subsubheading Synopsis
31832
31833 @smallexample
31834 -environment-directory [ -r ] [ @var{pathdir} ]+
31835 @end smallexample
31836
31837 Add directories @var{pathdir} to beginning of search path for source files.
31838 If the @samp{-r} option is used, the search path is reset to the default
31839 search path. If directories @var{pathdir} are supplied in addition to the
31840 @samp{-r} option, the search path is first reset and then addition
31841 occurs as normal.
31842 Multiple directories may be specified, separated by blanks. Specifying
31843 multiple directories in a single command
31844 results in the directories added to the beginning of the
31845 search path in the same order they were presented in the command.
31846 If blanks are needed as
31847 part of a directory name, double-quotes should be used around
31848 the name. In the command output, the path will show up separated
31849 by the system directory-separator character. The directory-separator
31850 character must not be used
31851 in any directory name.
31852 If no directories are specified, the current search path is displayed.
31853
31854 @subsubheading @value{GDBN} Command
31855
31856 The corresponding @value{GDBN} command is @samp{dir}.
31857
31858 @subsubheading Example
31859
31860 @smallexample
31861 (gdb)
31862 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31863 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31864 (gdb)
31865 -environment-directory ""
31866 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31867 (gdb)
31868 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
31869 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31870 (gdb)
31871 -environment-directory -r
31872 ^done,source-path="$cdir:$cwd"
31873 (gdb)
31874 @end smallexample
31875
31876
31877 @subheading The @code{-environment-path} Command
31878 @findex -environment-path
31879
31880 @subsubheading Synopsis
31881
31882 @smallexample
31883 -environment-path [ -r ] [ @var{pathdir} ]+
31884 @end smallexample
31885
31886 Add directories @var{pathdir} to beginning of search path for object files.
31887 If the @samp{-r} option is used, the search path is reset to the original
31888 search path that existed at gdb start-up. If directories @var{pathdir} are
31889 supplied in addition to the
31890 @samp{-r} option, the search path is first reset and then addition
31891 occurs as normal.
31892 Multiple directories may be specified, separated by blanks. Specifying
31893 multiple directories in a single command
31894 results in the directories added to the beginning of the
31895 search path in the same order they were presented in the command.
31896 If blanks are needed as
31897 part of a directory name, double-quotes should be used around
31898 the name. In the command output, the path will show up separated
31899 by the system directory-separator character. The directory-separator
31900 character must not be used
31901 in any directory name.
31902 If no directories are specified, the current path is displayed.
31903
31904
31905 @subsubheading @value{GDBN} Command
31906
31907 The corresponding @value{GDBN} command is @samp{path}.
31908
31909 @subsubheading Example
31910
31911 @smallexample
31912 (gdb)
31913 -environment-path
31914 ^done,path="/usr/bin"
31915 (gdb)
31916 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31917 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31918 (gdb)
31919 -environment-path -r /usr/local/bin
31920 ^done,path="/usr/local/bin:/usr/bin"
31921 (gdb)
31922 @end smallexample
31923
31924
31925 @subheading The @code{-environment-pwd} Command
31926 @findex -environment-pwd
31927
31928 @subsubheading Synopsis
31929
31930 @smallexample
31931 -environment-pwd
31932 @end smallexample
31933
31934 Show the current working directory.
31935
31936 @subsubheading @value{GDBN} Command
31937
31938 The corresponding @value{GDBN} command is @samp{pwd}.
31939
31940 @subsubheading Example
31941
31942 @smallexample
31943 (gdb)
31944 -environment-pwd
31945 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31946 (gdb)
31947 @end smallexample
31948
31949 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31950 @node GDB/MI Thread Commands
31951 @section @sc{gdb/mi} Thread Commands
31952
31953
31954 @subheading The @code{-thread-info} Command
31955 @findex -thread-info
31956
31957 @subsubheading Synopsis
31958
31959 @smallexample
31960 -thread-info [ @var{thread-id} ]
31961 @end smallexample
31962
31963 Reports information about either a specific thread, if the
31964 @var{thread-id} parameter is present, or about all threads.
31965 @var{thread-id} is the thread's global thread ID. When printing
31966 information about all threads, also reports the global ID of the
31967 current thread.
31968
31969 @subsubheading @value{GDBN} Command
31970
31971 The @samp{info thread} command prints the same information
31972 about all threads.
31973
31974 @subsubheading Result
31975
31976 The result contains the following attributes:
31977
31978 @table @samp
31979 @item threads
31980 A list of threads. The format of the elements of the list is described in
31981 @ref{GDB/MI Thread Information}.
31982
31983 @item current-thread-id
31984 The global id of the currently selected thread. This field is omitted if there
31985 is no selected thread (for example, when the selected inferior is not running,
31986 and therefore has no threads) or if a @var{thread-id} argument was passed to
31987 the command.
31988
31989 @end table
31990
31991 @subsubheading Example
31992
31993 @smallexample
31994 -thread-info
31995 ^done,threads=[
31996 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31997 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31998 args=[]@},state="running"@},
31999 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
32000 frame=@{level="0",addr="0x0804891f",func="foo",
32001 args=[@{name="i",value="10"@}],
32002 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
32003 state="running"@}],
32004 current-thread-id="1"
32005 (gdb)
32006 @end smallexample
32007
32008 @subheading The @code{-thread-list-ids} Command
32009 @findex -thread-list-ids
32010
32011 @subsubheading Synopsis
32012
32013 @smallexample
32014 -thread-list-ids
32015 @end smallexample
32016
32017 Produces a list of the currently known global @value{GDBN} thread ids.
32018 At the end of the list it also prints the total number of such
32019 threads.
32020
32021 This command is retained for historical reasons, the
32022 @code{-thread-info} command should be used instead.
32023
32024 @subsubheading @value{GDBN} Command
32025
32026 Part of @samp{info threads} supplies the same information.
32027
32028 @subsubheading Example
32029
32030 @smallexample
32031 (gdb)
32032 -thread-list-ids
32033 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
32034 current-thread-id="1",number-of-threads="3"
32035 (gdb)
32036 @end smallexample
32037
32038
32039 @subheading The @code{-thread-select} Command
32040 @findex -thread-select
32041
32042 @subsubheading Synopsis
32043
32044 @smallexample
32045 -thread-select @var{thread-id}
32046 @end smallexample
32047
32048 Make thread with global thread number @var{thread-id} the current
32049 thread. It prints the number of the new current thread, and the
32050 topmost frame for that thread.
32051
32052 This command is deprecated in favor of explicitly using the
32053 @samp{--thread} option to each command.
32054
32055 @subsubheading @value{GDBN} Command
32056
32057 The corresponding @value{GDBN} command is @samp{thread}.
32058
32059 @subsubheading Example
32060
32061 @smallexample
32062 (gdb)
32063 -exec-next
32064 ^running
32065 (gdb)
32066 *stopped,reason="end-stepping-range",thread-id="2",line="187",
32067 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
32068 (gdb)
32069 -thread-list-ids
32070 ^done,
32071 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
32072 number-of-threads="3"
32073 (gdb)
32074 -thread-select 3
32075 ^done,new-thread-id="3",
32076 frame=@{level="0",func="vprintf",
32077 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
32078 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
32079 (gdb)
32080 @end smallexample
32081
32082 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32083 @node GDB/MI Ada Tasking Commands
32084 @section @sc{gdb/mi} Ada Tasking Commands
32085
32086 @subheading The @code{-ada-task-info} Command
32087 @findex -ada-task-info
32088
32089 @subsubheading Synopsis
32090
32091 @smallexample
32092 -ada-task-info [ @var{task-id} ]
32093 @end smallexample
32094
32095 Reports information about either a specific Ada task, if the
32096 @var{task-id} parameter is present, or about all Ada tasks.
32097
32098 @subsubheading @value{GDBN} Command
32099
32100 The @samp{info tasks} command prints the same information
32101 about all Ada tasks (@pxref{Ada Tasks}).
32102
32103 @subsubheading Result
32104
32105 The result is a table of Ada tasks. The following columns are
32106 defined for each Ada task:
32107
32108 @table @samp
32109 @item current
32110 This field exists only for the current thread. It has the value @samp{*}.
32111
32112 @item id
32113 The identifier that @value{GDBN} uses to refer to the Ada task.
32114
32115 @item task-id
32116 The identifier that the target uses to refer to the Ada task.
32117
32118 @item thread-id
32119 The global thread identifier of the thread corresponding to the Ada
32120 task.
32121
32122 This field should always exist, as Ada tasks are always implemented
32123 on top of a thread. But if @value{GDBN} cannot find this corresponding
32124 thread for any reason, the field is omitted.
32125
32126 @item parent-id
32127 This field exists only when the task was created by another task.
32128 In this case, it provides the ID of the parent task.
32129
32130 @item priority
32131 The base priority of the task.
32132
32133 @item state
32134 The current state of the task. For a detailed description of the
32135 possible states, see @ref{Ada Tasks}.
32136
32137 @item name
32138 The name of the task.
32139
32140 @end table
32141
32142 @subsubheading Example
32143
32144 @smallexample
32145 -ada-task-info
32146 ^done,tasks=@{nr_rows="3",nr_cols="8",
32147 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
32148 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
32149 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
32150 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
32151 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
32152 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
32153 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
32154 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
32155 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
32156 state="Child Termination Wait",name="main_task"@}]@}
32157 (gdb)
32158 @end smallexample
32159
32160 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32161 @node GDB/MI Program Execution
32162 @section @sc{gdb/mi} Program Execution
32163
32164 These are the asynchronous commands which generate the out-of-band
32165 record @samp{*stopped}. Currently @value{GDBN} only really executes
32166 asynchronously with remote targets and this interaction is mimicked in
32167 other cases.
32168
32169 @subheading The @code{-exec-continue} Command
32170 @findex -exec-continue
32171
32172 @subsubheading Synopsis
32173
32174 @smallexample
32175 -exec-continue [--reverse] [--all|--thread-group N]
32176 @end smallexample
32177
32178 Resumes the execution of the inferior program, which will continue
32179 to execute until it reaches a debugger stop event. If the
32180 @samp{--reverse} option is specified, execution resumes in reverse until
32181 it reaches a stop event. Stop events may include
32182 @itemize @bullet
32183 @item
32184 breakpoints or watchpoints
32185 @item
32186 signals or exceptions
32187 @item
32188 the end of the process (or its beginning under @samp{--reverse})
32189 @item
32190 the end or beginning of a replay log if one is being used.
32191 @end itemize
32192 In all-stop mode (@pxref{All-Stop
32193 Mode}), may resume only one thread, or all threads, depending on the
32194 value of the @samp{scheduler-locking} variable. If @samp{--all} is
32195 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
32196 ignored in all-stop mode. If the @samp{--thread-group} options is
32197 specified, then all threads in that thread group are resumed.
32198
32199 @subsubheading @value{GDBN} Command
32200
32201 The corresponding @value{GDBN} corresponding is @samp{continue}.
32202
32203 @subsubheading Example
32204
32205 @smallexample
32206 -exec-continue
32207 ^running
32208 (gdb)
32209 @@Hello world
32210 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
32211 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
32212 line="13",arch="i386:x86_64"@}
32213 (gdb)
32214 @end smallexample
32215
32216
32217 @subheading The @code{-exec-finish} Command
32218 @findex -exec-finish
32219
32220 @subsubheading Synopsis
32221
32222 @smallexample
32223 -exec-finish [--reverse]
32224 @end smallexample
32225
32226 Resumes the execution of the inferior program until the current
32227 function is exited. Displays the results returned by the function.
32228 If the @samp{--reverse} option is specified, resumes the reverse
32229 execution of the inferior program until the point where current
32230 function was called.
32231
32232 @subsubheading @value{GDBN} Command
32233
32234 The corresponding @value{GDBN} command is @samp{finish}.
32235
32236 @subsubheading Example
32237
32238 Function returning @code{void}.
32239
32240 @smallexample
32241 -exec-finish
32242 ^running
32243 (gdb)
32244 @@hello from foo
32245 *stopped,reason="function-finished",frame=@{func="main",args=[],
32246 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
32247 (gdb)
32248 @end smallexample
32249
32250 Function returning other than @code{void}. The name of the internal
32251 @value{GDBN} variable storing the result is printed, together with the
32252 value itself.
32253
32254 @smallexample
32255 -exec-finish
32256 ^running
32257 (gdb)
32258 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
32259 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
32260 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32261 arch="i386:x86_64"@},
32262 gdb-result-var="$1",return-value="0"
32263 (gdb)
32264 @end smallexample
32265
32266
32267 @subheading The @code{-exec-interrupt} Command
32268 @findex -exec-interrupt
32269
32270 @subsubheading Synopsis
32271
32272 @smallexample
32273 -exec-interrupt [--all|--thread-group N]
32274 @end smallexample
32275
32276 Interrupts the background execution of the target. Note how the token
32277 associated with the stop message is the one for the execution command
32278 that has been interrupted. The token for the interrupt itself only
32279 appears in the @samp{^done} output. If the user is trying to
32280 interrupt a non-running program, an error message will be printed.
32281
32282 Note that when asynchronous execution is enabled, this command is
32283 asynchronous just like other execution commands. That is, first the
32284 @samp{^done} response will be printed, and the target stop will be
32285 reported after that using the @samp{*stopped} notification.
32286
32287 In non-stop mode, only the context thread is interrupted by default.
32288 All threads (in all inferiors) will be interrupted if the
32289 @samp{--all} option is specified. If the @samp{--thread-group}
32290 option is specified, all threads in that group will be interrupted.
32291
32292 @subsubheading @value{GDBN} Command
32293
32294 The corresponding @value{GDBN} command is @samp{interrupt}.
32295
32296 @subsubheading Example
32297
32298 @smallexample
32299 (gdb)
32300 111-exec-continue
32301 111^running
32302
32303 (gdb)
32304 222-exec-interrupt
32305 222^done
32306 (gdb)
32307 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
32308 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
32309 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
32310 (gdb)
32311
32312 (gdb)
32313 -exec-interrupt
32314 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
32315 (gdb)
32316 @end smallexample
32317
32318 @subheading The @code{-exec-jump} Command
32319 @findex -exec-jump
32320
32321 @subsubheading Synopsis
32322
32323 @smallexample
32324 -exec-jump @var{location}
32325 @end smallexample
32326
32327 Resumes execution of the inferior program at the location specified by
32328 parameter. @xref{Specify Location}, for a description of the
32329 different forms of @var{location}.
32330
32331 @subsubheading @value{GDBN} Command
32332
32333 The corresponding @value{GDBN} command is @samp{jump}.
32334
32335 @subsubheading Example
32336
32337 @smallexample
32338 -exec-jump foo.c:10
32339 *running,thread-id="all"
32340 ^running
32341 @end smallexample
32342
32343
32344 @subheading The @code{-exec-next} Command
32345 @findex -exec-next
32346
32347 @subsubheading Synopsis
32348
32349 @smallexample
32350 -exec-next [--reverse]
32351 @end smallexample
32352
32353 Resumes execution of the inferior program, stopping when the beginning
32354 of the next source line is reached.
32355
32356 If the @samp{--reverse} option is specified, resumes reverse execution
32357 of the inferior program, stopping at the beginning of the previous
32358 source line. If you issue this command on the first line of a
32359 function, it will take you back to the caller of that function, to the
32360 source line where the function was called.
32361
32362
32363 @subsubheading @value{GDBN} Command
32364
32365 The corresponding @value{GDBN} command is @samp{next}.
32366
32367 @subsubheading Example
32368
32369 @smallexample
32370 -exec-next
32371 ^running
32372 (gdb)
32373 *stopped,reason="end-stepping-range",line="8",file="hello.c"
32374 (gdb)
32375 @end smallexample
32376
32377
32378 @subheading The @code{-exec-next-instruction} Command
32379 @findex -exec-next-instruction
32380
32381 @subsubheading Synopsis
32382
32383 @smallexample
32384 -exec-next-instruction [--reverse]
32385 @end smallexample
32386
32387 Executes one machine instruction. If the instruction is a function
32388 call, continues until the function returns. If the program stops at an
32389 instruction in the middle of a source line, the address will be
32390 printed as well.
32391
32392 If the @samp{--reverse} option is specified, resumes reverse execution
32393 of the inferior program, stopping at the previous instruction. If the
32394 previously executed instruction was a return from another function,
32395 it will continue to execute in reverse until the call to that function
32396 (from the current stack frame) is reached.
32397
32398 @subsubheading @value{GDBN} Command
32399
32400 The corresponding @value{GDBN} command is @samp{nexti}.
32401
32402 @subsubheading Example
32403
32404 @smallexample
32405 (gdb)
32406 -exec-next-instruction
32407 ^running
32408
32409 (gdb)
32410 *stopped,reason="end-stepping-range",
32411 addr="0x000100d4",line="5",file="hello.c"
32412 (gdb)
32413 @end smallexample
32414
32415
32416 @subheading The @code{-exec-return} Command
32417 @findex -exec-return
32418
32419 @subsubheading Synopsis
32420
32421 @smallexample
32422 -exec-return
32423 @end smallexample
32424
32425 Makes current function return immediately. Doesn't execute the inferior.
32426 Displays the new current frame.
32427
32428 @subsubheading @value{GDBN} Command
32429
32430 The corresponding @value{GDBN} command is @samp{return}.
32431
32432 @subsubheading Example
32433
32434 @smallexample
32435 (gdb)
32436 200-break-insert callee4
32437 200^done,bkpt=@{number="1",addr="0x00010734",
32438 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
32439 (gdb)
32440 000-exec-run
32441 000^running
32442 (gdb)
32443 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32444 frame=@{func="callee4",args=[],
32445 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32446 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32447 arch="i386:x86_64"@}
32448 (gdb)
32449 205-break-delete
32450 205^done
32451 (gdb)
32452 111-exec-return
32453 111^done,frame=@{level="0",func="callee3",
32454 args=[@{name="strarg",
32455 value="0x11940 \"A string argument.\""@}],
32456 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32457 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32458 arch="i386:x86_64"@}
32459 (gdb)
32460 @end smallexample
32461
32462
32463 @subheading The @code{-exec-run} Command
32464 @findex -exec-run
32465
32466 @subsubheading Synopsis
32467
32468 @smallexample
32469 -exec-run [ --all | --thread-group N ] [ --start ]
32470 @end smallexample
32471
32472 Starts execution of the inferior from the beginning. The inferior
32473 executes until either a breakpoint is encountered or the program
32474 exits. In the latter case the output will include an exit code, if
32475 the program has exited exceptionally.
32476
32477 When neither the @samp{--all} nor the @samp{--thread-group} option
32478 is specified, the current inferior is started. If the
32479 @samp{--thread-group} option is specified, it should refer to a thread
32480 group of type @samp{process}, and that thread group will be started.
32481 If the @samp{--all} option is specified, then all inferiors will be started.
32482
32483 Using the @samp{--start} option instructs the debugger to stop
32484 the execution at the start of the inferior's main subprogram,
32485 following the same behavior as the @code{start} command
32486 (@pxref{Starting}).
32487
32488 @subsubheading @value{GDBN} Command
32489
32490 The corresponding @value{GDBN} command is @samp{run}.
32491
32492 @subsubheading Examples
32493
32494 @smallexample
32495 (gdb)
32496 -break-insert main
32497 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
32498 (gdb)
32499 -exec-run
32500 ^running
32501 (gdb)
32502 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32503 frame=@{func="main",args=[],file="recursive2.c",
32504 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
32505 (gdb)
32506 @end smallexample
32507
32508 @noindent
32509 Program exited normally:
32510
32511 @smallexample
32512 (gdb)
32513 -exec-run
32514 ^running
32515 (gdb)
32516 x = 55
32517 *stopped,reason="exited-normally"
32518 (gdb)
32519 @end smallexample
32520
32521 @noindent
32522 Program exited exceptionally:
32523
32524 @smallexample
32525 (gdb)
32526 -exec-run
32527 ^running
32528 (gdb)
32529 x = 55
32530 *stopped,reason="exited",exit-code="01"
32531 (gdb)
32532 @end smallexample
32533
32534 Another way the program can terminate is if it receives a signal such as
32535 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
32536
32537 @smallexample
32538 (gdb)
32539 *stopped,reason="exited-signalled",signal-name="SIGINT",
32540 signal-meaning="Interrupt"
32541 @end smallexample
32542
32543
32544 @c @subheading -exec-signal
32545
32546
32547 @subheading The @code{-exec-step} Command
32548 @findex -exec-step
32549
32550 @subsubheading Synopsis
32551
32552 @smallexample
32553 -exec-step [--reverse]
32554 @end smallexample
32555
32556 Resumes execution of the inferior program, stopping when the beginning
32557 of the next source line is reached, if the next source line is not a
32558 function call. If it is, stop at the first instruction of the called
32559 function. If the @samp{--reverse} option is specified, resumes reverse
32560 execution of the inferior program, stopping at the beginning of the
32561 previously executed source line.
32562
32563 @subsubheading @value{GDBN} Command
32564
32565 The corresponding @value{GDBN} command is @samp{step}.
32566
32567 @subsubheading Example
32568
32569 Stepping into a function:
32570
32571 @smallexample
32572 -exec-step
32573 ^running
32574 (gdb)
32575 *stopped,reason="end-stepping-range",
32576 frame=@{func="foo",args=[@{name="a",value="10"@},
32577 @{name="b",value="0"@}],file="recursive2.c",
32578 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
32579 (gdb)
32580 @end smallexample
32581
32582 Regular stepping:
32583
32584 @smallexample
32585 -exec-step
32586 ^running
32587 (gdb)
32588 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
32589 (gdb)
32590 @end smallexample
32591
32592
32593 @subheading The @code{-exec-step-instruction} Command
32594 @findex -exec-step-instruction
32595
32596 @subsubheading Synopsis
32597
32598 @smallexample
32599 -exec-step-instruction [--reverse]
32600 @end smallexample
32601
32602 Resumes the inferior which executes one machine instruction. If the
32603 @samp{--reverse} option is specified, resumes reverse execution of the
32604 inferior program, stopping at the previously executed instruction.
32605 The output, once @value{GDBN} has stopped, will vary depending on
32606 whether we have stopped in the middle of a source line or not. In the
32607 former case, the address at which the program stopped will be printed
32608 as well.
32609
32610 @subsubheading @value{GDBN} Command
32611
32612 The corresponding @value{GDBN} command is @samp{stepi}.
32613
32614 @subsubheading Example
32615
32616 @smallexample
32617 (gdb)
32618 -exec-step-instruction
32619 ^running
32620
32621 (gdb)
32622 *stopped,reason="end-stepping-range",
32623 frame=@{func="foo",args=[],file="try.c",
32624 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32625 (gdb)
32626 -exec-step-instruction
32627 ^running
32628
32629 (gdb)
32630 *stopped,reason="end-stepping-range",
32631 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
32632 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32633 (gdb)
32634 @end smallexample
32635
32636
32637 @subheading The @code{-exec-until} Command
32638 @findex -exec-until
32639
32640 @subsubheading Synopsis
32641
32642 @smallexample
32643 -exec-until [ @var{location} ]
32644 @end smallexample
32645
32646 Executes the inferior until the @var{location} specified in the
32647 argument is reached. If there is no argument, the inferior executes
32648 until a source line greater than the current one is reached. The
32649 reason for stopping in this case will be @samp{location-reached}.
32650
32651 @subsubheading @value{GDBN} Command
32652
32653 The corresponding @value{GDBN} command is @samp{until}.
32654
32655 @subsubheading Example
32656
32657 @smallexample
32658 (gdb)
32659 -exec-until recursive2.c:6
32660 ^running
32661 (gdb)
32662 x = 55
32663 *stopped,reason="location-reached",frame=@{func="main",args=[],
32664 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32665 arch="i386:x86_64"@}
32666 (gdb)
32667 @end smallexample
32668
32669 @ignore
32670 @subheading -file-clear
32671 Is this going away????
32672 @end ignore
32673
32674 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32675 @node GDB/MI Stack Manipulation
32676 @section @sc{gdb/mi} Stack Manipulation Commands
32677
32678 @subheading The @code{-enable-frame-filters} Command
32679 @findex -enable-frame-filters
32680
32681 @smallexample
32682 -enable-frame-filters
32683 @end smallexample
32684
32685 @value{GDBN} allows Python-based frame filters to affect the output of
32686 the MI commands relating to stack traces. As there is no way to
32687 implement this in a fully backward-compatible way, a front end must
32688 request that this functionality be enabled.
32689
32690 Once enabled, this feature cannot be disabled.
32691
32692 Note that if Python support has not been compiled into @value{GDBN},
32693 this command will still succeed (and do nothing).
32694
32695 @subheading The @code{-stack-info-frame} Command
32696 @findex -stack-info-frame
32697
32698 @subsubheading Synopsis
32699
32700 @smallexample
32701 -stack-info-frame
32702 @end smallexample
32703
32704 Get info on the selected frame.
32705
32706 @subsubheading @value{GDBN} Command
32707
32708 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32709 (without arguments).
32710
32711 @subsubheading Example
32712
32713 @smallexample
32714 (gdb)
32715 -stack-info-frame
32716 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32717 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32718 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32719 arch="i386:x86_64"@}
32720 (gdb)
32721 @end smallexample
32722
32723 @subheading The @code{-stack-info-depth} Command
32724 @findex -stack-info-depth
32725
32726 @subsubheading Synopsis
32727
32728 @smallexample
32729 -stack-info-depth [ @var{max-depth} ]
32730 @end smallexample
32731
32732 Return the depth of the stack. If the integer argument @var{max-depth}
32733 is specified, do not count beyond @var{max-depth} frames.
32734
32735 @subsubheading @value{GDBN} Command
32736
32737 There's no equivalent @value{GDBN} command.
32738
32739 @subsubheading Example
32740
32741 For a stack with frame levels 0 through 11:
32742
32743 @smallexample
32744 (gdb)
32745 -stack-info-depth
32746 ^done,depth="12"
32747 (gdb)
32748 -stack-info-depth 4
32749 ^done,depth="4"
32750 (gdb)
32751 -stack-info-depth 12
32752 ^done,depth="12"
32753 (gdb)
32754 -stack-info-depth 11
32755 ^done,depth="11"
32756 (gdb)
32757 -stack-info-depth 13
32758 ^done,depth="12"
32759 (gdb)
32760 @end smallexample
32761
32762 @anchor{-stack-list-arguments}
32763 @subheading The @code{-stack-list-arguments} Command
32764 @findex -stack-list-arguments
32765
32766 @subsubheading Synopsis
32767
32768 @smallexample
32769 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32770 [ @var{low-frame} @var{high-frame} ]
32771 @end smallexample
32772
32773 Display a list of the arguments for the frames between @var{low-frame}
32774 and @var{high-frame} (inclusive). If @var{low-frame} and
32775 @var{high-frame} are not provided, list the arguments for the whole
32776 call stack. If the two arguments are equal, show the single frame
32777 at the corresponding level. It is an error if @var{low-frame} is
32778 larger than the actual number of frames. On the other hand,
32779 @var{high-frame} may be larger than the actual number of frames, in
32780 which case only existing frames will be returned.
32781
32782 If @var{print-values} is 0 or @code{--no-values}, print only the names of
32783 the variables; if it is 1 or @code{--all-values}, print also their
32784 values; and if it is 2 or @code{--simple-values}, print the name,
32785 type and value for simple data types, and the name and type for arrays,
32786 structures and unions. If the option @code{--no-frame-filters} is
32787 supplied, then Python frame filters will not be executed.
32788
32789 If the @code{--skip-unavailable} option is specified, arguments that
32790 are not available are not listed. Partially available arguments
32791 are still displayed, however.
32792
32793 Use of this command to obtain arguments in a single frame is
32794 deprecated in favor of the @samp{-stack-list-variables} command.
32795
32796 @subsubheading @value{GDBN} Command
32797
32798 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32799 @samp{gdb_get_args} command which partially overlaps with the
32800 functionality of @samp{-stack-list-arguments}.
32801
32802 @subsubheading Example
32803
32804 @smallexample
32805 (gdb)
32806 -stack-list-frames
32807 ^done,
32808 stack=[
32809 frame=@{level="0",addr="0x00010734",func="callee4",
32810 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32811 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32812 arch="i386:x86_64"@},
32813 frame=@{level="1",addr="0x0001076c",func="callee3",
32814 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32815 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32816 arch="i386:x86_64"@},
32817 frame=@{level="2",addr="0x0001078c",func="callee2",
32818 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32819 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32820 arch="i386:x86_64"@},
32821 frame=@{level="3",addr="0x000107b4",func="callee1",
32822 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32823 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32824 arch="i386:x86_64"@},
32825 frame=@{level="4",addr="0x000107e0",func="main",
32826 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32827 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32828 arch="i386:x86_64"@}]
32829 (gdb)
32830 -stack-list-arguments 0
32831 ^done,
32832 stack-args=[
32833 frame=@{level="0",args=[]@},
32834 frame=@{level="1",args=[name="strarg"]@},
32835 frame=@{level="2",args=[name="intarg",name="strarg"]@},
32836 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32837 frame=@{level="4",args=[]@}]
32838 (gdb)
32839 -stack-list-arguments 1
32840 ^done,
32841 stack-args=[
32842 frame=@{level="0",args=[]@},
32843 frame=@{level="1",
32844 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32845 frame=@{level="2",args=[
32846 @{name="intarg",value="2"@},
32847 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32848 @{frame=@{level="3",args=[
32849 @{name="intarg",value="2"@},
32850 @{name="strarg",value="0x11940 \"A string argument.\""@},
32851 @{name="fltarg",value="3.5"@}]@},
32852 frame=@{level="4",args=[]@}]
32853 (gdb)
32854 -stack-list-arguments 0 2 2
32855 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32856 (gdb)
32857 -stack-list-arguments 1 2 2
32858 ^done,stack-args=[frame=@{level="2",
32859 args=[@{name="intarg",value="2"@},
32860 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32861 (gdb)
32862 @end smallexample
32863
32864 @c @subheading -stack-list-exception-handlers
32865
32866
32867 @anchor{-stack-list-frames}
32868 @subheading The @code{-stack-list-frames} Command
32869 @findex -stack-list-frames
32870
32871 @subsubheading Synopsis
32872
32873 @smallexample
32874 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32875 @end smallexample
32876
32877 List the frames currently on the stack. For each frame it displays the
32878 following info:
32879
32880 @table @samp
32881 @item @var{level}
32882 The frame number, 0 being the topmost frame, i.e., the innermost function.
32883 @item @var{addr}
32884 The @code{$pc} value for that frame.
32885 @item @var{func}
32886 Function name.
32887 @item @var{file}
32888 File name of the source file where the function lives.
32889 @item @var{fullname}
32890 The full file name of the source file where the function lives.
32891 @item @var{line}
32892 Line number corresponding to the @code{$pc}.
32893 @item @var{from}
32894 The shared library where this function is defined. This is only given
32895 if the frame's function is not known.
32896 @item @var{arch}
32897 Frame's architecture.
32898 @end table
32899
32900 If invoked without arguments, this command prints a backtrace for the
32901 whole stack. If given two integer arguments, it shows the frames whose
32902 levels are between the two arguments (inclusive). If the two arguments
32903 are equal, it shows the single frame at the corresponding level. It is
32904 an error if @var{low-frame} is larger than the actual number of
32905 frames. On the other hand, @var{high-frame} may be larger than the
32906 actual number of frames, in which case only existing frames will be
32907 returned. If the option @code{--no-frame-filters} is supplied, then
32908 Python frame filters will not be executed.
32909
32910 @subsubheading @value{GDBN} Command
32911
32912 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32913
32914 @subsubheading Example
32915
32916 Full stack backtrace:
32917
32918 @smallexample
32919 (gdb)
32920 -stack-list-frames
32921 ^done,stack=
32922 [frame=@{level="0",addr="0x0001076c",func="foo",
32923 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32924 arch="i386:x86_64"@},
32925 frame=@{level="1",addr="0x000107a4",func="foo",
32926 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32927 arch="i386:x86_64"@},
32928 frame=@{level="2",addr="0x000107a4",func="foo",
32929 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32930 arch="i386:x86_64"@},
32931 frame=@{level="3",addr="0x000107a4",func="foo",
32932 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32933 arch="i386:x86_64"@},
32934 frame=@{level="4",addr="0x000107a4",func="foo",
32935 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32936 arch="i386:x86_64"@},
32937 frame=@{level="5",addr="0x000107a4",func="foo",
32938 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32939 arch="i386:x86_64"@},
32940 frame=@{level="6",addr="0x000107a4",func="foo",
32941 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32942 arch="i386:x86_64"@},
32943 frame=@{level="7",addr="0x000107a4",func="foo",
32944 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32945 arch="i386:x86_64"@},
32946 frame=@{level="8",addr="0x000107a4",func="foo",
32947 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32948 arch="i386:x86_64"@},
32949 frame=@{level="9",addr="0x000107a4",func="foo",
32950 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32951 arch="i386:x86_64"@},
32952 frame=@{level="10",addr="0x000107a4",func="foo",
32953 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32954 arch="i386:x86_64"@},
32955 frame=@{level="11",addr="0x00010738",func="main",
32956 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32957 arch="i386:x86_64"@}]
32958 (gdb)
32959 @end smallexample
32960
32961 Show frames between @var{low_frame} and @var{high_frame}:
32962
32963 @smallexample
32964 (gdb)
32965 -stack-list-frames 3 5
32966 ^done,stack=
32967 [frame=@{level="3",addr="0x000107a4",func="foo",
32968 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32969 arch="i386:x86_64"@},
32970 frame=@{level="4",addr="0x000107a4",func="foo",
32971 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32972 arch="i386:x86_64"@},
32973 frame=@{level="5",addr="0x000107a4",func="foo",
32974 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32975 arch="i386:x86_64"@}]
32976 (gdb)
32977 @end smallexample
32978
32979 Show a single frame:
32980
32981 @smallexample
32982 (gdb)
32983 -stack-list-frames 3 3
32984 ^done,stack=
32985 [frame=@{level="3",addr="0x000107a4",func="foo",
32986 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32987 arch="i386:x86_64"@}]
32988 (gdb)
32989 @end smallexample
32990
32991
32992 @subheading The @code{-stack-list-locals} Command
32993 @findex -stack-list-locals
32994 @anchor{-stack-list-locals}
32995
32996 @subsubheading Synopsis
32997
32998 @smallexample
32999 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33000 @end smallexample
33001
33002 Display the local variable names for the selected frame. If
33003 @var{print-values} is 0 or @code{--no-values}, print only the names of
33004 the variables; if it is 1 or @code{--all-values}, print also their
33005 values; and if it is 2 or @code{--simple-values}, print the name,
33006 type and value for simple data types, and the name and type for arrays,
33007 structures and unions. In this last case, a frontend can immediately
33008 display the value of simple data types and create variable objects for
33009 other data types when the user wishes to explore their values in
33010 more detail. If the option @code{--no-frame-filters} is supplied, then
33011 Python frame filters will not be executed.
33012
33013 If the @code{--skip-unavailable} option is specified, local variables
33014 that are not available are not listed. Partially available local
33015 variables are still displayed, however.
33016
33017 This command is deprecated in favor of the
33018 @samp{-stack-list-variables} command.
33019
33020 @subsubheading @value{GDBN} Command
33021
33022 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
33023
33024 @subsubheading Example
33025
33026 @smallexample
33027 (gdb)
33028 -stack-list-locals 0
33029 ^done,locals=[name="A",name="B",name="C"]
33030 (gdb)
33031 -stack-list-locals --all-values
33032 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
33033 @{name="C",value="@{1, 2, 3@}"@}]
33034 -stack-list-locals --simple-values
33035 ^done,locals=[@{name="A",type="int",value="1"@},
33036 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
33037 (gdb)
33038 @end smallexample
33039
33040 @anchor{-stack-list-variables}
33041 @subheading The @code{-stack-list-variables} Command
33042 @findex -stack-list-variables
33043
33044 @subsubheading Synopsis
33045
33046 @smallexample
33047 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
33048 @end smallexample
33049
33050 Display the names of local variables and function arguments for the selected frame. If
33051 @var{print-values} is 0 or @code{--no-values}, print only the names of
33052 the variables; if it is 1 or @code{--all-values}, print also their
33053 values; and if it is 2 or @code{--simple-values}, print the name,
33054 type and value for simple data types, and the name and type for arrays,
33055 structures and unions. If the option @code{--no-frame-filters} is
33056 supplied, then Python frame filters will not be executed.
33057
33058 If the @code{--skip-unavailable} option is specified, local variables
33059 and arguments that are not available are not listed. Partially
33060 available arguments and local variables are still displayed, however.
33061
33062 @subsubheading Example
33063
33064 @smallexample
33065 (gdb)
33066 -stack-list-variables --thread 1 --frame 0 --all-values
33067 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
33068 (gdb)
33069 @end smallexample
33070
33071
33072 @subheading The @code{-stack-select-frame} Command
33073 @findex -stack-select-frame
33074
33075 @subsubheading Synopsis
33076
33077 @smallexample
33078 -stack-select-frame @var{framenum}
33079 @end smallexample
33080
33081 Change the selected frame. Select a different frame @var{framenum} on
33082 the stack.
33083
33084 This command in deprecated in favor of passing the @samp{--frame}
33085 option to every command.
33086
33087 @subsubheading @value{GDBN} Command
33088
33089 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
33090 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
33091
33092 @subsubheading Example
33093
33094 @smallexample
33095 (gdb)
33096 -stack-select-frame 2
33097 ^done
33098 (gdb)
33099 @end smallexample
33100
33101 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33102 @node GDB/MI Variable Objects
33103 @section @sc{gdb/mi} Variable Objects
33104
33105 @ignore
33106
33107 @subheading Motivation for Variable Objects in @sc{gdb/mi}
33108
33109 For the implementation of a variable debugger window (locals, watched
33110 expressions, etc.), we are proposing the adaptation of the existing code
33111 used by @code{Insight}.
33112
33113 The two main reasons for that are:
33114
33115 @enumerate 1
33116 @item
33117 It has been proven in practice (it is already on its second generation).
33118
33119 @item
33120 It will shorten development time (needless to say how important it is
33121 now).
33122 @end enumerate
33123
33124 The original interface was designed to be used by Tcl code, so it was
33125 slightly changed so it could be used through @sc{gdb/mi}. This section
33126 describes the @sc{gdb/mi} operations that will be available and gives some
33127 hints about their use.
33128
33129 @emph{Note}: In addition to the set of operations described here, we
33130 expect the @sc{gui} implementation of a variable window to require, at
33131 least, the following operations:
33132
33133 @itemize @bullet
33134 @item @code{-gdb-show} @code{output-radix}
33135 @item @code{-stack-list-arguments}
33136 @item @code{-stack-list-locals}
33137 @item @code{-stack-select-frame}
33138 @end itemize
33139
33140 @end ignore
33141
33142 @subheading Introduction to Variable Objects
33143
33144 @cindex variable objects in @sc{gdb/mi}
33145
33146 Variable objects are "object-oriented" MI interface for examining and
33147 changing values of expressions. Unlike some other MI interfaces that
33148 work with expressions, variable objects are specifically designed for
33149 simple and efficient presentation in the frontend. A variable object
33150 is identified by string name. When a variable object is created, the
33151 frontend specifies the expression for that variable object. The
33152 expression can be a simple variable, or it can be an arbitrary complex
33153 expression, and can even involve CPU registers. After creating a
33154 variable object, the frontend can invoke other variable object
33155 operations---for example to obtain or change the value of a variable
33156 object, or to change display format.
33157
33158 Variable objects have hierarchical tree structure. Any variable object
33159 that corresponds to a composite type, such as structure in C, has
33160 a number of child variable objects, for example corresponding to each
33161 element of a structure. A child variable object can itself have
33162 children, recursively. Recursion ends when we reach
33163 leaf variable objects, which always have built-in types. Child variable
33164 objects are created only by explicit request, so if a frontend
33165 is not interested in the children of a particular variable object, no
33166 child will be created.
33167
33168 For a leaf variable object it is possible to obtain its value as a
33169 string, or set the value from a string. String value can be also
33170 obtained for a non-leaf variable object, but it's generally a string
33171 that only indicates the type of the object, and does not list its
33172 contents. Assignment to a non-leaf variable object is not allowed.
33173
33174 A frontend does not need to read the values of all variable objects each time
33175 the program stops. Instead, MI provides an update command that lists all
33176 variable objects whose values has changed since the last update
33177 operation. This considerably reduces the amount of data that must
33178 be transferred to the frontend. As noted above, children variable
33179 objects are created on demand, and only leaf variable objects have a
33180 real value. As result, gdb will read target memory only for leaf
33181 variables that frontend has created.
33182
33183 The automatic update is not always desirable. For example, a frontend
33184 might want to keep a value of some expression for future reference,
33185 and never update it. For another example, fetching memory is
33186 relatively slow for embedded targets, so a frontend might want
33187 to disable automatic update for the variables that are either not
33188 visible on the screen, or ``closed''. This is possible using so
33189 called ``frozen variable objects''. Such variable objects are never
33190 implicitly updated.
33191
33192 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
33193 fixed variable object, the expression is parsed when the variable
33194 object is created, including associating identifiers to specific
33195 variables. The meaning of expression never changes. For a floating
33196 variable object the values of variables whose names appear in the
33197 expressions are re-evaluated every time in the context of the current
33198 frame. Consider this example:
33199
33200 @smallexample
33201 void do_work(...)
33202 @{
33203 struct work_state state;
33204
33205 if (...)
33206 do_work(...);
33207 @}
33208 @end smallexample
33209
33210 If a fixed variable object for the @code{state} variable is created in
33211 this function, and we enter the recursive call, the variable
33212 object will report the value of @code{state} in the top-level
33213 @code{do_work} invocation. On the other hand, a floating variable
33214 object will report the value of @code{state} in the current frame.
33215
33216 If an expression specified when creating a fixed variable object
33217 refers to a local variable, the variable object becomes bound to the
33218 thread and frame in which the variable object is created. When such
33219 variable object is updated, @value{GDBN} makes sure that the
33220 thread/frame combination the variable object is bound to still exists,
33221 and re-evaluates the variable object in context of that thread/frame.
33222
33223 The following is the complete set of @sc{gdb/mi} operations defined to
33224 access this functionality:
33225
33226 @multitable @columnfractions .4 .6
33227 @item @strong{Operation}
33228 @tab @strong{Description}
33229
33230 @item @code{-enable-pretty-printing}
33231 @tab enable Python-based pretty-printing
33232 @item @code{-var-create}
33233 @tab create a variable object
33234 @item @code{-var-delete}
33235 @tab delete the variable object and/or its children
33236 @item @code{-var-set-format}
33237 @tab set the display format of this variable
33238 @item @code{-var-show-format}
33239 @tab show the display format of this variable
33240 @item @code{-var-info-num-children}
33241 @tab tells how many children this object has
33242 @item @code{-var-list-children}
33243 @tab return a list of the object's children
33244 @item @code{-var-info-type}
33245 @tab show the type of this variable object
33246 @item @code{-var-info-expression}
33247 @tab print parent-relative expression that this variable object represents
33248 @item @code{-var-info-path-expression}
33249 @tab print full expression that this variable object represents
33250 @item @code{-var-show-attributes}
33251 @tab is this variable editable? does it exist here?
33252 @item @code{-var-evaluate-expression}
33253 @tab get the value of this variable
33254 @item @code{-var-assign}
33255 @tab set the value of this variable
33256 @item @code{-var-update}
33257 @tab update the variable and its children
33258 @item @code{-var-set-frozen}
33259 @tab set frozenness attribute
33260 @item @code{-var-set-update-range}
33261 @tab set range of children to display on update
33262 @end multitable
33263
33264 In the next subsection we describe each operation in detail and suggest
33265 how it can be used.
33266
33267 @subheading Description And Use of Operations on Variable Objects
33268
33269 @subheading The @code{-enable-pretty-printing} Command
33270 @findex -enable-pretty-printing
33271
33272 @smallexample
33273 -enable-pretty-printing
33274 @end smallexample
33275
33276 @value{GDBN} allows Python-based visualizers to affect the output of the
33277 MI variable object commands. However, because there was no way to
33278 implement this in a fully backward-compatible way, a front end must
33279 request that this functionality be enabled.
33280
33281 Once enabled, this feature cannot be disabled.
33282
33283 Note that if Python support has not been compiled into @value{GDBN},
33284 this command will still succeed (and do nothing).
33285
33286 This feature is currently (as of @value{GDBN} 7.0) experimental, and
33287 may work differently in future versions of @value{GDBN}.
33288
33289 @subheading The @code{-var-create} Command
33290 @findex -var-create
33291
33292 @subsubheading Synopsis
33293
33294 @smallexample
33295 -var-create @{@var{name} | "-"@}
33296 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
33297 @end smallexample
33298
33299 This operation creates a variable object, which allows the monitoring of
33300 a variable, the result of an expression, a memory cell or a CPU
33301 register.
33302
33303 The @var{name} parameter is the string by which the object can be
33304 referenced. It must be unique. If @samp{-} is specified, the varobj
33305 system will generate a string ``varNNNNNN'' automatically. It will be
33306 unique provided that one does not specify @var{name} of that format.
33307 The command fails if a duplicate name is found.
33308
33309 The frame under which the expression should be evaluated can be
33310 specified by @var{frame-addr}. A @samp{*} indicates that the current
33311 frame should be used. A @samp{@@} indicates that a floating variable
33312 object must be created.
33313
33314 @var{expression} is any expression valid on the current language set (must not
33315 begin with a @samp{*}), or one of the following:
33316
33317 @itemize @bullet
33318 @item
33319 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
33320
33321 @item
33322 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
33323
33324 @item
33325 @samp{$@var{regname}} --- a CPU register name
33326 @end itemize
33327
33328 @cindex dynamic varobj
33329 A varobj's contents may be provided by a Python-based pretty-printer. In this
33330 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
33331 have slightly different semantics in some cases. If the
33332 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
33333 will never create a dynamic varobj. This ensures backward
33334 compatibility for existing clients.
33335
33336 @subsubheading Result
33337
33338 This operation returns attributes of the newly-created varobj. These
33339 are:
33340
33341 @table @samp
33342 @item name
33343 The name of the varobj.
33344
33345 @item numchild
33346 The number of children of the varobj. This number is not necessarily
33347 reliable for a dynamic varobj. Instead, you must examine the
33348 @samp{has_more} attribute.
33349
33350 @item value
33351 The varobj's scalar value. For a varobj whose type is some sort of
33352 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
33353 will not be interesting.
33354
33355 @item type
33356 The varobj's type. This is a string representation of the type, as
33357 would be printed by the @value{GDBN} CLI. If @samp{print object}
33358 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33359 @emph{actual} (derived) type of the object is shown rather than the
33360 @emph{declared} one.
33361
33362 @item thread-id
33363 If a variable object is bound to a specific thread, then this is the
33364 thread's global identifier.
33365
33366 @item has_more
33367 For a dynamic varobj, this indicates whether there appear to be any
33368 children available. For a non-dynamic varobj, this will be 0.
33369
33370 @item dynamic
33371 This attribute will be present and have the value @samp{1} if the
33372 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33373 then this attribute will not be present.
33374
33375 @item displayhint
33376 A dynamic varobj can supply a display hint to the front end. The
33377 value comes directly from the Python pretty-printer object's
33378 @code{display_hint} method. @xref{Pretty Printing API}.
33379 @end table
33380
33381 Typical output will look like this:
33382
33383 @smallexample
33384 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
33385 has_more="@var{has_more}"
33386 @end smallexample
33387
33388
33389 @subheading The @code{-var-delete} Command
33390 @findex -var-delete
33391
33392 @subsubheading Synopsis
33393
33394 @smallexample
33395 -var-delete [ -c ] @var{name}
33396 @end smallexample
33397
33398 Deletes a previously created variable object and all of its children.
33399 With the @samp{-c} option, just deletes the children.
33400
33401 Returns an error if the object @var{name} is not found.
33402
33403
33404 @subheading The @code{-var-set-format} Command
33405 @findex -var-set-format
33406
33407 @subsubheading Synopsis
33408
33409 @smallexample
33410 -var-set-format @var{name} @var{format-spec}
33411 @end smallexample
33412
33413 Sets the output format for the value of the object @var{name} to be
33414 @var{format-spec}.
33415
33416 @anchor{-var-set-format}
33417 The syntax for the @var{format-spec} is as follows:
33418
33419 @smallexample
33420 @var{format-spec} @expansion{}
33421 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
33422 @end smallexample
33423
33424 The natural format is the default format choosen automatically
33425 based on the variable type (like decimal for an @code{int}, hex
33426 for pointers, etc.).
33427
33428 The zero-hexadecimal format has a representation similar to hexadecimal
33429 but with padding zeroes to the left of the value. For example, a 32-bit
33430 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
33431 zero-hexadecimal format.
33432
33433 For a variable with children, the format is set only on the
33434 variable itself, and the children are not affected.
33435
33436 @subheading The @code{-var-show-format} Command
33437 @findex -var-show-format
33438
33439 @subsubheading Synopsis
33440
33441 @smallexample
33442 -var-show-format @var{name}
33443 @end smallexample
33444
33445 Returns the format used to display the value of the object @var{name}.
33446
33447 @smallexample
33448 @var{format} @expansion{}
33449 @var{format-spec}
33450 @end smallexample
33451
33452
33453 @subheading The @code{-var-info-num-children} Command
33454 @findex -var-info-num-children
33455
33456 @subsubheading Synopsis
33457
33458 @smallexample
33459 -var-info-num-children @var{name}
33460 @end smallexample
33461
33462 Returns the number of children of a variable object @var{name}:
33463
33464 @smallexample
33465 numchild=@var{n}
33466 @end smallexample
33467
33468 Note that this number is not completely reliable for a dynamic varobj.
33469 It will return the current number of children, but more children may
33470 be available.
33471
33472
33473 @subheading The @code{-var-list-children} Command
33474 @findex -var-list-children
33475
33476 @subsubheading Synopsis
33477
33478 @smallexample
33479 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
33480 @end smallexample
33481 @anchor{-var-list-children}
33482
33483 Return a list of the children of the specified variable object and
33484 create variable objects for them, if they do not already exist. With
33485 a single argument or if @var{print-values} has a value of 0 or
33486 @code{--no-values}, print only the names of the variables; if
33487 @var{print-values} is 1 or @code{--all-values}, also print their
33488 values; and if it is 2 or @code{--simple-values} print the name and
33489 value for simple data types and just the name for arrays, structures
33490 and unions.
33491
33492 @var{from} and @var{to}, if specified, indicate the range of children
33493 to report. If @var{from} or @var{to} is less than zero, the range is
33494 reset and all children will be reported. Otherwise, children starting
33495 at @var{from} (zero-based) and up to and excluding @var{to} will be
33496 reported.
33497
33498 If a child range is requested, it will only affect the current call to
33499 @code{-var-list-children}, but not future calls to @code{-var-update}.
33500 For this, you must instead use @code{-var-set-update-range}. The
33501 intent of this approach is to enable a front end to implement any
33502 update approach it likes; for example, scrolling a view may cause the
33503 front end to request more children with @code{-var-list-children}, and
33504 then the front end could call @code{-var-set-update-range} with a
33505 different range to ensure that future updates are restricted to just
33506 the visible items.
33507
33508 For each child the following results are returned:
33509
33510 @table @var
33511
33512 @item name
33513 Name of the variable object created for this child.
33514
33515 @item exp
33516 The expression to be shown to the user by the front end to designate this child.
33517 For example this may be the name of a structure member.
33518
33519 For a dynamic varobj, this value cannot be used to form an
33520 expression. There is no way to do this at all with a dynamic varobj.
33521
33522 For C/C@t{++} structures there are several pseudo children returned to
33523 designate access qualifiers. For these pseudo children @var{exp} is
33524 @samp{public}, @samp{private}, or @samp{protected}. In this case the
33525 type and value are not present.
33526
33527 A dynamic varobj will not report the access qualifying
33528 pseudo-children, regardless of the language. This information is not
33529 available at all with a dynamic varobj.
33530
33531 @item numchild
33532 Number of children this child has. For a dynamic varobj, this will be
33533 0.
33534
33535 @item type
33536 The type of the child. If @samp{print object}
33537 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33538 @emph{actual} (derived) type of the object is shown rather than the
33539 @emph{declared} one.
33540
33541 @item value
33542 If values were requested, this is the value.
33543
33544 @item thread-id
33545 If this variable object is associated with a thread, this is the
33546 thread's global thread id. Otherwise this result is not present.
33547
33548 @item frozen
33549 If the variable object is frozen, this variable will be present with a value of 1.
33550
33551 @item displayhint
33552 A dynamic varobj can supply a display hint to the front end. The
33553 value comes directly from the Python pretty-printer object's
33554 @code{display_hint} method. @xref{Pretty Printing API}.
33555
33556 @item dynamic
33557 This attribute will be present and have the value @samp{1} if the
33558 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33559 then this attribute will not be present.
33560
33561 @end table
33562
33563 The result may have its own attributes:
33564
33565 @table @samp
33566 @item displayhint
33567 A dynamic varobj can supply a display hint to the front end. The
33568 value comes directly from the Python pretty-printer object's
33569 @code{display_hint} method. @xref{Pretty Printing API}.
33570
33571 @item has_more
33572 This is an integer attribute which is nonzero if there are children
33573 remaining after the end of the selected range.
33574 @end table
33575
33576 @subsubheading Example
33577
33578 @smallexample
33579 (gdb)
33580 -var-list-children n
33581 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33582 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
33583 (gdb)
33584 -var-list-children --all-values n
33585 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33586 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
33587 @end smallexample
33588
33589
33590 @subheading The @code{-var-info-type} Command
33591 @findex -var-info-type
33592
33593 @subsubheading Synopsis
33594
33595 @smallexample
33596 -var-info-type @var{name}
33597 @end smallexample
33598
33599 Returns the type of the specified variable @var{name}. The type is
33600 returned as a string in the same format as it is output by the
33601 @value{GDBN} CLI:
33602
33603 @smallexample
33604 type=@var{typename}
33605 @end smallexample
33606
33607
33608 @subheading The @code{-var-info-expression} Command
33609 @findex -var-info-expression
33610
33611 @subsubheading Synopsis
33612
33613 @smallexample
33614 -var-info-expression @var{name}
33615 @end smallexample
33616
33617 Returns a string that is suitable for presenting this
33618 variable object in user interface. The string is generally
33619 not valid expression in the current language, and cannot be evaluated.
33620
33621 For example, if @code{a} is an array, and variable object
33622 @code{A} was created for @code{a}, then we'll get this output:
33623
33624 @smallexample
33625 (gdb) -var-info-expression A.1
33626 ^done,lang="C",exp="1"
33627 @end smallexample
33628
33629 @noindent
33630 Here, the value of @code{lang} is the language name, which can be
33631 found in @ref{Supported Languages}.
33632
33633 Note that the output of the @code{-var-list-children} command also
33634 includes those expressions, so the @code{-var-info-expression} command
33635 is of limited use.
33636
33637 @subheading The @code{-var-info-path-expression} Command
33638 @findex -var-info-path-expression
33639
33640 @subsubheading Synopsis
33641
33642 @smallexample
33643 -var-info-path-expression @var{name}
33644 @end smallexample
33645
33646 Returns an expression that can be evaluated in the current
33647 context and will yield the same value that a variable object has.
33648 Compare this with the @code{-var-info-expression} command, which
33649 result can be used only for UI presentation. Typical use of
33650 the @code{-var-info-path-expression} command is creating a
33651 watchpoint from a variable object.
33652
33653 This command is currently not valid for children of a dynamic varobj,
33654 and will give an error when invoked on one.
33655
33656 For example, suppose @code{C} is a C@t{++} class, derived from class
33657 @code{Base}, and that the @code{Base} class has a member called
33658 @code{m_size}. Assume a variable @code{c} is has the type of
33659 @code{C} and a variable object @code{C} was created for variable
33660 @code{c}. Then, we'll get this output:
33661 @smallexample
33662 (gdb) -var-info-path-expression C.Base.public.m_size
33663 ^done,path_expr=((Base)c).m_size)
33664 @end smallexample
33665
33666 @subheading The @code{-var-show-attributes} Command
33667 @findex -var-show-attributes
33668
33669 @subsubheading Synopsis
33670
33671 @smallexample
33672 -var-show-attributes @var{name}
33673 @end smallexample
33674
33675 List attributes of the specified variable object @var{name}:
33676
33677 @smallexample
33678 status=@var{attr} [ ( ,@var{attr} )* ]
33679 @end smallexample
33680
33681 @noindent
33682 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33683
33684 @subheading The @code{-var-evaluate-expression} Command
33685 @findex -var-evaluate-expression
33686
33687 @subsubheading Synopsis
33688
33689 @smallexample
33690 -var-evaluate-expression [-f @var{format-spec}] @var{name}
33691 @end smallexample
33692
33693 Evaluates the expression that is represented by the specified variable
33694 object and returns its value as a string. The format of the string
33695 can be specified with the @samp{-f} option. The possible values of
33696 this option are the same as for @code{-var-set-format}
33697 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33698 the current display format will be used. The current display format
33699 can be changed using the @code{-var-set-format} command.
33700
33701 @smallexample
33702 value=@var{value}
33703 @end smallexample
33704
33705 Note that one must invoke @code{-var-list-children} for a variable
33706 before the value of a child variable can be evaluated.
33707
33708 @subheading The @code{-var-assign} Command
33709 @findex -var-assign
33710
33711 @subsubheading Synopsis
33712
33713 @smallexample
33714 -var-assign @var{name} @var{expression}
33715 @end smallexample
33716
33717 Assigns the value of @var{expression} to the variable object specified
33718 by @var{name}. The object must be @samp{editable}. If the variable's
33719 value is altered by the assign, the variable will show up in any
33720 subsequent @code{-var-update} list.
33721
33722 @subsubheading Example
33723
33724 @smallexample
33725 (gdb)
33726 -var-assign var1 3
33727 ^done,value="3"
33728 (gdb)
33729 -var-update *
33730 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
33731 (gdb)
33732 @end smallexample
33733
33734 @subheading The @code{-var-update} Command
33735 @findex -var-update
33736
33737 @subsubheading Synopsis
33738
33739 @smallexample
33740 -var-update [@var{print-values}] @{@var{name} | "*"@}
33741 @end smallexample
33742
33743 Reevaluate the expressions corresponding to the variable object
33744 @var{name} and all its direct and indirect children, and return the
33745 list of variable objects whose values have changed; @var{name} must
33746 be a root variable object. Here, ``changed'' means that the result of
33747 @code{-var-evaluate-expression} before and after the
33748 @code{-var-update} is different. If @samp{*} is used as the variable
33749 object names, all existing variable objects are updated, except
33750 for frozen ones (@pxref{-var-set-frozen}). The option
33751 @var{print-values} determines whether both names and values, or just
33752 names are printed. The possible values of this option are the same
33753 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33754 recommended to use the @samp{--all-values} option, to reduce the
33755 number of MI commands needed on each program stop.
33756
33757 With the @samp{*} parameter, if a variable object is bound to a
33758 currently running thread, it will not be updated, without any
33759 diagnostic.
33760
33761 If @code{-var-set-update-range} was previously used on a varobj, then
33762 only the selected range of children will be reported.
33763
33764 @code{-var-update} reports all the changed varobjs in a tuple named
33765 @samp{changelist}.
33766
33767 Each item in the change list is itself a tuple holding:
33768
33769 @table @samp
33770 @item name
33771 The name of the varobj.
33772
33773 @item value
33774 If values were requested for this update, then this field will be
33775 present and will hold the value of the varobj.
33776
33777 @item in_scope
33778 @anchor{-var-update}
33779 This field is a string which may take one of three values:
33780
33781 @table @code
33782 @item "true"
33783 The variable object's current value is valid.
33784
33785 @item "false"
33786 The variable object does not currently hold a valid value but it may
33787 hold one in the future if its associated expression comes back into
33788 scope.
33789
33790 @item "invalid"
33791 The variable object no longer holds a valid value.
33792 This can occur when the executable file being debugged has changed,
33793 either through recompilation or by using the @value{GDBN} @code{file}
33794 command. The front end should normally choose to delete these variable
33795 objects.
33796 @end table
33797
33798 In the future new values may be added to this list so the front should
33799 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33800
33801 @item type_changed
33802 This is only present if the varobj is still valid. If the type
33803 changed, then this will be the string @samp{true}; otherwise it will
33804 be @samp{false}.
33805
33806 When a varobj's type changes, its children are also likely to have
33807 become incorrect. Therefore, the varobj's children are automatically
33808 deleted when this attribute is @samp{true}. Also, the varobj's update
33809 range, when set using the @code{-var-set-update-range} command, is
33810 unset.
33811
33812 @item new_type
33813 If the varobj's type changed, then this field will be present and will
33814 hold the new type.
33815
33816 @item new_num_children
33817 For a dynamic varobj, if the number of children changed, or if the
33818 type changed, this will be the new number of children.
33819
33820 The @samp{numchild} field in other varobj responses is generally not
33821 valid for a dynamic varobj -- it will show the number of children that
33822 @value{GDBN} knows about, but because dynamic varobjs lazily
33823 instantiate their children, this will not reflect the number of
33824 children which may be available.
33825
33826 The @samp{new_num_children} attribute only reports changes to the
33827 number of children known by @value{GDBN}. This is the only way to
33828 detect whether an update has removed children (which necessarily can
33829 only happen at the end of the update range).
33830
33831 @item displayhint
33832 The display hint, if any.
33833
33834 @item has_more
33835 This is an integer value, which will be 1 if there are more children
33836 available outside the varobj's update range.
33837
33838 @item dynamic
33839 This attribute will be present and have the value @samp{1} if the
33840 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33841 then this attribute will not be present.
33842
33843 @item new_children
33844 If new children were added to a dynamic varobj within the selected
33845 update range (as set by @code{-var-set-update-range}), then they will
33846 be listed in this attribute.
33847 @end table
33848
33849 @subsubheading Example
33850
33851 @smallexample
33852 (gdb)
33853 -var-assign var1 3
33854 ^done,value="3"
33855 (gdb)
33856 -var-update --all-values var1
33857 ^done,changelist=[@{name="var1",value="3",in_scope="true",
33858 type_changed="false"@}]
33859 (gdb)
33860 @end smallexample
33861
33862 @subheading The @code{-var-set-frozen} Command
33863 @findex -var-set-frozen
33864 @anchor{-var-set-frozen}
33865
33866 @subsubheading Synopsis
33867
33868 @smallexample
33869 -var-set-frozen @var{name} @var{flag}
33870 @end smallexample
33871
33872 Set the frozenness flag on the variable object @var{name}. The
33873 @var{flag} parameter should be either @samp{1} to make the variable
33874 frozen or @samp{0} to make it unfrozen. If a variable object is
33875 frozen, then neither itself, nor any of its children, are
33876 implicitly updated by @code{-var-update} of
33877 a parent variable or by @code{-var-update *}. Only
33878 @code{-var-update} of the variable itself will update its value and
33879 values of its children. After a variable object is unfrozen, it is
33880 implicitly updated by all subsequent @code{-var-update} operations.
33881 Unfreezing a variable does not update it, only subsequent
33882 @code{-var-update} does.
33883
33884 @subsubheading Example
33885
33886 @smallexample
33887 (gdb)
33888 -var-set-frozen V 1
33889 ^done
33890 (gdb)
33891 @end smallexample
33892
33893 @subheading The @code{-var-set-update-range} command
33894 @findex -var-set-update-range
33895 @anchor{-var-set-update-range}
33896
33897 @subsubheading Synopsis
33898
33899 @smallexample
33900 -var-set-update-range @var{name} @var{from} @var{to}
33901 @end smallexample
33902
33903 Set the range of children to be returned by future invocations of
33904 @code{-var-update}.
33905
33906 @var{from} and @var{to} indicate the range of children to report. If
33907 @var{from} or @var{to} is less than zero, the range is reset and all
33908 children will be reported. Otherwise, children starting at @var{from}
33909 (zero-based) and up to and excluding @var{to} will be reported.
33910
33911 @subsubheading Example
33912
33913 @smallexample
33914 (gdb)
33915 -var-set-update-range V 1 2
33916 ^done
33917 @end smallexample
33918
33919 @subheading The @code{-var-set-visualizer} command
33920 @findex -var-set-visualizer
33921 @anchor{-var-set-visualizer}
33922
33923 @subsubheading Synopsis
33924
33925 @smallexample
33926 -var-set-visualizer @var{name} @var{visualizer}
33927 @end smallexample
33928
33929 Set a visualizer for the variable object @var{name}.
33930
33931 @var{visualizer} is the visualizer to use. The special value
33932 @samp{None} means to disable any visualizer in use.
33933
33934 If not @samp{None}, @var{visualizer} must be a Python expression.
33935 This expression must evaluate to a callable object which accepts a
33936 single argument. @value{GDBN} will call this object with the value of
33937 the varobj @var{name} as an argument (this is done so that the same
33938 Python pretty-printing code can be used for both the CLI and MI).
33939 When called, this object must return an object which conforms to the
33940 pretty-printing interface (@pxref{Pretty Printing API}).
33941
33942 The pre-defined function @code{gdb.default_visualizer} may be used to
33943 select a visualizer by following the built-in process
33944 (@pxref{Selecting Pretty-Printers}). This is done automatically when
33945 a varobj is created, and so ordinarily is not needed.
33946
33947 This feature is only available if Python support is enabled. The MI
33948 command @code{-list-features} (@pxref{GDB/MI Support Commands})
33949 can be used to check this.
33950
33951 @subsubheading Example
33952
33953 Resetting the visualizer:
33954
33955 @smallexample
33956 (gdb)
33957 -var-set-visualizer V None
33958 ^done
33959 @end smallexample
33960
33961 Reselecting the default (type-based) visualizer:
33962
33963 @smallexample
33964 (gdb)
33965 -var-set-visualizer V gdb.default_visualizer
33966 ^done
33967 @end smallexample
33968
33969 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33970 can be used to instantiate this class for a varobj:
33971
33972 @smallexample
33973 (gdb)
33974 -var-set-visualizer V "lambda val: SomeClass()"
33975 ^done
33976 @end smallexample
33977
33978 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33979 @node GDB/MI Data Manipulation
33980 @section @sc{gdb/mi} Data Manipulation
33981
33982 @cindex data manipulation, in @sc{gdb/mi}
33983 @cindex @sc{gdb/mi}, data manipulation
33984 This section describes the @sc{gdb/mi} commands that manipulate data:
33985 examine memory and registers, evaluate expressions, etc.
33986
33987 For details about what an addressable memory unit is,
33988 @pxref{addressable memory unit}.
33989
33990 @c REMOVED FROM THE INTERFACE.
33991 @c @subheading -data-assign
33992 @c Change the value of a program variable. Plenty of side effects.
33993 @c @subsubheading GDB Command
33994 @c set variable
33995 @c @subsubheading Example
33996 @c N.A.
33997
33998 @subheading The @code{-data-disassemble} Command
33999 @findex -data-disassemble
34000
34001 @subsubheading Synopsis
34002
34003 @smallexample
34004 -data-disassemble
34005 [ -s @var{start-addr} -e @var{end-addr} ]
34006 | [ -a @var{addr} ]
34007 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
34008 -- @var{mode}
34009 @end smallexample
34010
34011 @noindent
34012 Where:
34013
34014 @table @samp
34015 @item @var{start-addr}
34016 is the beginning address (or @code{$pc})
34017 @item @var{end-addr}
34018 is the end address
34019 @item @var{addr}
34020 is an address anywhere within (or the name of) the function to
34021 disassemble. If an address is specified, the whole function
34022 surrounding that address will be disassembled. If a name is
34023 specified, the whole function with that name will be disassembled.
34024 @item @var{filename}
34025 is the name of the file to disassemble
34026 @item @var{linenum}
34027 is the line number to disassemble around
34028 @item @var{lines}
34029 is the number of disassembly lines to be produced. If it is -1,
34030 the whole function will be disassembled, in case no @var{end-addr} is
34031 specified. If @var{end-addr} is specified as a non-zero value, and
34032 @var{lines} is lower than the number of disassembly lines between
34033 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
34034 displayed; if @var{lines} is higher than the number of lines between
34035 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
34036 are displayed.
34037 @item @var{mode}
34038 is one of:
34039 @itemize @bullet
34040 @item 0 disassembly only
34041 @item 1 mixed source and disassembly (deprecated)
34042 @item 2 disassembly with raw opcodes
34043 @item 3 mixed source and disassembly with raw opcodes (deprecated)
34044 @item 4 mixed source and disassembly
34045 @item 5 mixed source and disassembly with raw opcodes
34046 @end itemize
34047
34048 Modes 1 and 3 are deprecated. The output is ``source centric''
34049 which hasn't proved useful in practice.
34050 @xref{Machine Code}, for a discussion of the difference between
34051 @code{/m} and @code{/s} output of the @code{disassemble} command.
34052 @end table
34053
34054 @subsubheading Result
34055
34056 The result of the @code{-data-disassemble} command will be a list named
34057 @samp{asm_insns}, the contents of this list depend on the @var{mode}
34058 used with the @code{-data-disassemble} command.
34059
34060 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
34061 following fields:
34062
34063 @table @code
34064 @item address
34065 The address at which this instruction was disassembled.
34066
34067 @item func-name
34068 The name of the function this instruction is within.
34069
34070 @item offset
34071 The decimal offset in bytes from the start of @samp{func-name}.
34072
34073 @item inst
34074 The text disassembly for this @samp{address}.
34075
34076 @item opcodes
34077 This field is only present for modes 2, 3 and 5. This contains the raw opcode
34078 bytes for the @samp{inst} field.
34079
34080 @end table
34081
34082 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
34083 @samp{src_and_asm_line}, each of which has the following fields:
34084
34085 @table @code
34086 @item line
34087 The line number within @samp{file}.
34088
34089 @item file
34090 The file name from the compilation unit. This might be an absolute
34091 file name or a relative file name depending on the compile command
34092 used.
34093
34094 @item fullname
34095 Absolute file name of @samp{file}. It is converted to a canonical form
34096 using the source file search path
34097 (@pxref{Source Path, ,Specifying Source Directories})
34098 and after resolving all the symbolic links.
34099
34100 If the source file is not found this field will contain the path as
34101 present in the debug information.
34102
34103 @item line_asm_insn
34104 This is a list of tuples containing the disassembly for @samp{line} in
34105 @samp{file}. The fields of each tuple are the same as for
34106 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
34107 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
34108 @samp{opcodes}.
34109
34110 @end table
34111
34112 Note that whatever included in the @samp{inst} field, is not
34113 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
34114 adjust its format.
34115
34116 @subsubheading @value{GDBN} Command
34117
34118 The corresponding @value{GDBN} command is @samp{disassemble}.
34119
34120 @subsubheading Example
34121
34122 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
34123
34124 @smallexample
34125 (gdb)
34126 -data-disassemble -s $pc -e "$pc + 20" -- 0
34127 ^done,
34128 asm_insns=[
34129 @{address="0x000107c0",func-name="main",offset="4",
34130 inst="mov 2, %o0"@},
34131 @{address="0x000107c4",func-name="main",offset="8",
34132 inst="sethi %hi(0x11800), %o2"@},
34133 @{address="0x000107c8",func-name="main",offset="12",
34134 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
34135 @{address="0x000107cc",func-name="main",offset="16",
34136 inst="sethi %hi(0x11800), %o2"@},
34137 @{address="0x000107d0",func-name="main",offset="20",
34138 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
34139 (gdb)
34140 @end smallexample
34141
34142 Disassemble the whole @code{main} function. Line 32 is part of
34143 @code{main}.
34144
34145 @smallexample
34146 -data-disassemble -f basics.c -l 32 -- 0
34147 ^done,asm_insns=[
34148 @{address="0x000107bc",func-name="main",offset="0",
34149 inst="save %sp, -112, %sp"@},
34150 @{address="0x000107c0",func-name="main",offset="4",
34151 inst="mov 2, %o0"@},
34152 @{address="0x000107c4",func-name="main",offset="8",
34153 inst="sethi %hi(0x11800), %o2"@},
34154 [@dots{}]
34155 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
34156 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
34157 (gdb)
34158 @end smallexample
34159
34160 Disassemble 3 instructions from the start of @code{main}:
34161
34162 @smallexample
34163 (gdb)
34164 -data-disassemble -f basics.c -l 32 -n 3 -- 0
34165 ^done,asm_insns=[
34166 @{address="0x000107bc",func-name="main",offset="0",
34167 inst="save %sp, -112, %sp"@},
34168 @{address="0x000107c0",func-name="main",offset="4",
34169 inst="mov 2, %o0"@},
34170 @{address="0x000107c4",func-name="main",offset="8",
34171 inst="sethi %hi(0x11800), %o2"@}]
34172 (gdb)
34173 @end smallexample
34174
34175 Disassemble 3 instructions from the start of @code{main} in mixed mode:
34176
34177 @smallexample
34178 (gdb)
34179 -data-disassemble -f basics.c -l 32 -n 3 -- 1
34180 ^done,asm_insns=[
34181 src_and_asm_line=@{line="31",
34182 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
34183 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
34184 line_asm_insn=[@{address="0x000107bc",
34185 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
34186 src_and_asm_line=@{line="32",
34187 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
34188 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
34189 line_asm_insn=[@{address="0x000107c0",
34190 func-name="main",offset="4",inst="mov 2, %o0"@},
34191 @{address="0x000107c4",func-name="main",offset="8",
34192 inst="sethi %hi(0x11800), %o2"@}]@}]
34193 (gdb)
34194 @end smallexample
34195
34196
34197 @subheading The @code{-data-evaluate-expression} Command
34198 @findex -data-evaluate-expression
34199
34200 @subsubheading Synopsis
34201
34202 @smallexample
34203 -data-evaluate-expression @var{expr}
34204 @end smallexample
34205
34206 Evaluate @var{expr} as an expression. The expression could contain an
34207 inferior function call. The function call will execute synchronously.
34208 If the expression contains spaces, it must be enclosed in double quotes.
34209
34210 @subsubheading @value{GDBN} Command
34211
34212 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
34213 @samp{call}. In @code{gdbtk} only, there's a corresponding
34214 @samp{gdb_eval} command.
34215
34216 @subsubheading Example
34217
34218 In the following example, the numbers that precede the commands are the
34219 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
34220 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
34221 output.
34222
34223 @smallexample
34224 211-data-evaluate-expression A
34225 211^done,value="1"
34226 (gdb)
34227 311-data-evaluate-expression &A
34228 311^done,value="0xefffeb7c"
34229 (gdb)
34230 411-data-evaluate-expression A+3
34231 411^done,value="4"
34232 (gdb)
34233 511-data-evaluate-expression "A + 3"
34234 511^done,value="4"
34235 (gdb)
34236 @end smallexample
34237
34238
34239 @subheading The @code{-data-list-changed-registers} Command
34240 @findex -data-list-changed-registers
34241
34242 @subsubheading Synopsis
34243
34244 @smallexample
34245 -data-list-changed-registers
34246 @end smallexample
34247
34248 Display a list of the registers that have changed.
34249
34250 @subsubheading @value{GDBN} Command
34251
34252 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
34253 has the corresponding command @samp{gdb_changed_register_list}.
34254
34255 @subsubheading Example
34256
34257 On a PPC MBX board:
34258
34259 @smallexample
34260 (gdb)
34261 -exec-continue
34262 ^running
34263
34264 (gdb)
34265 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
34266 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
34267 line="5",arch="powerpc"@}
34268 (gdb)
34269 -data-list-changed-registers
34270 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
34271 "10","11","13","14","15","16","17","18","19","20","21","22","23",
34272 "24","25","26","27","28","30","31","64","65","66","67","69"]
34273 (gdb)
34274 @end smallexample
34275
34276
34277 @subheading The @code{-data-list-register-names} Command
34278 @findex -data-list-register-names
34279
34280 @subsubheading Synopsis
34281
34282 @smallexample
34283 -data-list-register-names [ ( @var{regno} )+ ]
34284 @end smallexample
34285
34286 Show a list of register names for the current target. If no arguments
34287 are given, it shows a list of the names of all the registers. If
34288 integer numbers are given as arguments, it will print a list of the
34289 names of the registers corresponding to the arguments. To ensure
34290 consistency between a register name and its number, the output list may
34291 include empty register names.
34292
34293 @subsubheading @value{GDBN} Command
34294
34295 @value{GDBN} does not have a command which corresponds to
34296 @samp{-data-list-register-names}. In @code{gdbtk} there is a
34297 corresponding command @samp{gdb_regnames}.
34298
34299 @subsubheading Example
34300
34301 For the PPC MBX board:
34302 @smallexample
34303 (gdb)
34304 -data-list-register-names
34305 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
34306 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
34307 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
34308 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
34309 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
34310 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
34311 "", "pc","ps","cr","lr","ctr","xer"]
34312 (gdb)
34313 -data-list-register-names 1 2 3
34314 ^done,register-names=["r1","r2","r3"]
34315 (gdb)
34316 @end smallexample
34317
34318 @subheading The @code{-data-list-register-values} Command
34319 @findex -data-list-register-values
34320
34321 @subsubheading Synopsis
34322
34323 @smallexample
34324 -data-list-register-values
34325 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
34326 @end smallexample
34327
34328 Display the registers' contents. The format according to which the
34329 registers' contents are to be returned is given by @var{fmt}, followed
34330 by an optional list of numbers specifying the registers to display. A
34331 missing list of numbers indicates that the contents of all the
34332 registers must be returned. The @code{--skip-unavailable} option
34333 indicates that only the available registers are to be returned.
34334
34335 Allowed formats for @var{fmt} are:
34336
34337 @table @code
34338 @item x
34339 Hexadecimal
34340 @item o
34341 Octal
34342 @item t
34343 Binary
34344 @item d
34345 Decimal
34346 @item r
34347 Raw
34348 @item N
34349 Natural
34350 @end table
34351
34352 @subsubheading @value{GDBN} Command
34353
34354 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
34355 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
34356
34357 @subsubheading Example
34358
34359 For a PPC MBX board (note: line breaks are for readability only, they
34360 don't appear in the actual output):
34361
34362 @smallexample
34363 (gdb)
34364 -data-list-register-values r 64 65
34365 ^done,register-values=[@{number="64",value="0xfe00a300"@},
34366 @{number="65",value="0x00029002"@}]
34367 (gdb)
34368 -data-list-register-values x
34369 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
34370 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
34371 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
34372 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
34373 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
34374 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
34375 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
34376 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
34377 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
34378 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
34379 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
34380 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
34381 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
34382 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
34383 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
34384 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
34385 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
34386 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
34387 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
34388 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
34389 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
34390 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
34391 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
34392 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
34393 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
34394 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
34395 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
34396 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
34397 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
34398 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
34399 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
34400 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
34401 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
34402 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
34403 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
34404 @{number="69",value="0x20002b03"@}]
34405 (gdb)
34406 @end smallexample
34407
34408
34409 @subheading The @code{-data-read-memory} Command
34410 @findex -data-read-memory
34411
34412 This command is deprecated, use @code{-data-read-memory-bytes} instead.
34413
34414 @subsubheading Synopsis
34415
34416 @smallexample
34417 -data-read-memory [ -o @var{byte-offset} ]
34418 @var{address} @var{word-format} @var{word-size}
34419 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
34420 @end smallexample
34421
34422 @noindent
34423 where:
34424
34425 @table @samp
34426 @item @var{address}
34427 An expression specifying the address of the first memory word to be
34428 read. Complex expressions containing embedded white space should be
34429 quoted using the C convention.
34430
34431 @item @var{word-format}
34432 The format to be used to print the memory words. The notation is the
34433 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
34434 ,Output Formats}).
34435
34436 @item @var{word-size}
34437 The size of each memory word in bytes.
34438
34439 @item @var{nr-rows}
34440 The number of rows in the output table.
34441
34442 @item @var{nr-cols}
34443 The number of columns in the output table.
34444
34445 @item @var{aschar}
34446 If present, indicates that each row should include an @sc{ascii} dump. The
34447 value of @var{aschar} is used as a padding character when a byte is not a
34448 member of the printable @sc{ascii} character set (printable @sc{ascii}
34449 characters are those whose code is between 32 and 126, inclusively).
34450
34451 @item @var{byte-offset}
34452 An offset to add to the @var{address} before fetching memory.
34453 @end table
34454
34455 This command displays memory contents as a table of @var{nr-rows} by
34456 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
34457 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
34458 (returned as @samp{total-bytes}). Should less than the requested number
34459 of bytes be returned by the target, the missing words are identified
34460 using @samp{N/A}. The number of bytes read from the target is returned
34461 in @samp{nr-bytes} and the starting address used to read memory in
34462 @samp{addr}.
34463
34464 The address of the next/previous row or page is available in
34465 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
34466 @samp{prev-page}.
34467
34468 @subsubheading @value{GDBN} Command
34469
34470 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
34471 @samp{gdb_get_mem} memory read command.
34472
34473 @subsubheading Example
34474
34475 Read six bytes of memory starting at @code{bytes+6} but then offset by
34476 @code{-6} bytes. Format as three rows of two columns. One byte per
34477 word. Display each word in hex.
34478
34479 @smallexample
34480 (gdb)
34481 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
34482 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
34483 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
34484 prev-page="0x0000138a",memory=[
34485 @{addr="0x00001390",data=["0x00","0x01"]@},
34486 @{addr="0x00001392",data=["0x02","0x03"]@},
34487 @{addr="0x00001394",data=["0x04","0x05"]@}]
34488 (gdb)
34489 @end smallexample
34490
34491 Read two bytes of memory starting at address @code{shorts + 64} and
34492 display as a single word formatted in decimal.
34493
34494 @smallexample
34495 (gdb)
34496 5-data-read-memory shorts+64 d 2 1 1
34497 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
34498 next-row="0x00001512",prev-row="0x0000150e",
34499 next-page="0x00001512",prev-page="0x0000150e",memory=[
34500 @{addr="0x00001510",data=["128"]@}]
34501 (gdb)
34502 @end smallexample
34503
34504 Read thirty two bytes of memory starting at @code{bytes+16} and format
34505 as eight rows of four columns. Include a string encoding with @samp{x}
34506 used as the non-printable character.
34507
34508 @smallexample
34509 (gdb)
34510 4-data-read-memory bytes+16 x 1 8 4 x
34511 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
34512 next-row="0x000013c0",prev-row="0x0000139c",
34513 next-page="0x000013c0",prev-page="0x00001380",memory=[
34514 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
34515 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
34516 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
34517 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
34518 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
34519 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
34520 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
34521 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
34522 (gdb)
34523 @end smallexample
34524
34525 @subheading The @code{-data-read-memory-bytes} Command
34526 @findex -data-read-memory-bytes
34527
34528 @subsubheading Synopsis
34529
34530 @smallexample
34531 -data-read-memory-bytes [ -o @var{offset} ]
34532 @var{address} @var{count}
34533 @end smallexample
34534
34535 @noindent
34536 where:
34537
34538 @table @samp
34539 @item @var{address}
34540 An expression specifying the address of the first addressable memory unit
34541 to be read. Complex expressions containing embedded white space should be
34542 quoted using the C convention.
34543
34544 @item @var{count}
34545 The number of addressable memory units to read. This should be an integer
34546 literal.
34547
34548 @item @var{offset}
34549 The offset relative to @var{address} at which to start reading. This
34550 should be an integer literal. This option is provided so that a frontend
34551 is not required to first evaluate address and then perform address
34552 arithmetics itself.
34553
34554 @end table
34555
34556 This command attempts to read all accessible memory regions in the
34557 specified range. First, all regions marked as unreadable in the memory
34558 map (if one is defined) will be skipped. @xref{Memory Region
34559 Attributes}. Second, @value{GDBN} will attempt to read the remaining
34560 regions. For each one, if reading full region results in an errors,
34561 @value{GDBN} will try to read a subset of the region.
34562
34563 In general, every single memory unit in the region may be readable or not,
34564 and the only way to read every readable unit is to try a read at
34565 every address, which is not practical. Therefore, @value{GDBN} will
34566 attempt to read all accessible memory units at either beginning or the end
34567 of the region, using a binary division scheme. This heuristic works
34568 well for reading across a memory map boundary. Note that if a region
34569 has a readable range that is neither at the beginning or the end,
34570 @value{GDBN} will not read it.
34571
34572 The result record (@pxref{GDB/MI Result Records}) that is output of
34573 the command includes a field named @samp{memory} whose content is a
34574 list of tuples. Each tuple represent a successfully read memory block
34575 and has the following fields:
34576
34577 @table @code
34578 @item begin
34579 The start address of the memory block, as hexadecimal literal.
34580
34581 @item end
34582 The end address of the memory block, as hexadecimal literal.
34583
34584 @item offset
34585 The offset of the memory block, as hexadecimal literal, relative to
34586 the start address passed to @code{-data-read-memory-bytes}.
34587
34588 @item contents
34589 The contents of the memory block, in hex.
34590
34591 @end table
34592
34593
34594
34595 @subsubheading @value{GDBN} Command
34596
34597 The corresponding @value{GDBN} command is @samp{x}.
34598
34599 @subsubheading Example
34600
34601 @smallexample
34602 (gdb)
34603 -data-read-memory-bytes &a 10
34604 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34605 end="0xbffff15e",
34606 contents="01000000020000000300"@}]
34607 (gdb)
34608 @end smallexample
34609
34610
34611 @subheading The @code{-data-write-memory-bytes} Command
34612 @findex -data-write-memory-bytes
34613
34614 @subsubheading Synopsis
34615
34616 @smallexample
34617 -data-write-memory-bytes @var{address} @var{contents}
34618 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
34619 @end smallexample
34620
34621 @noindent
34622 where:
34623
34624 @table @samp
34625 @item @var{address}
34626 An expression specifying the address of the first addressable memory unit
34627 to be written. Complex expressions containing embedded white space should
34628 be quoted using the C convention.
34629
34630 @item @var{contents}
34631 The hex-encoded data to write. It is an error if @var{contents} does
34632 not represent an integral number of addressable memory units.
34633
34634 @item @var{count}
34635 Optional argument indicating the number of addressable memory units to be
34636 written. If @var{count} is greater than @var{contents}' length,
34637 @value{GDBN} will repeatedly write @var{contents} until it fills
34638 @var{count} memory units.
34639
34640 @end table
34641
34642 @subsubheading @value{GDBN} Command
34643
34644 There's no corresponding @value{GDBN} command.
34645
34646 @subsubheading Example
34647
34648 @smallexample
34649 (gdb)
34650 -data-write-memory-bytes &a "aabbccdd"
34651 ^done
34652 (gdb)
34653 @end smallexample
34654
34655 @smallexample
34656 (gdb)
34657 -data-write-memory-bytes &a "aabbccdd" 16e
34658 ^done
34659 (gdb)
34660 @end smallexample
34661
34662 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34663 @node GDB/MI Tracepoint Commands
34664 @section @sc{gdb/mi} Tracepoint Commands
34665
34666 The commands defined in this section implement MI support for
34667 tracepoints. For detailed introduction, see @ref{Tracepoints}.
34668
34669 @subheading The @code{-trace-find} Command
34670 @findex -trace-find
34671
34672 @subsubheading Synopsis
34673
34674 @smallexample
34675 -trace-find @var{mode} [@var{parameters}@dots{}]
34676 @end smallexample
34677
34678 Find a trace frame using criteria defined by @var{mode} and
34679 @var{parameters}. The following table lists permissible
34680 modes and their parameters. For details of operation, see @ref{tfind}.
34681
34682 @table @samp
34683
34684 @item none
34685 No parameters are required. Stops examining trace frames.
34686
34687 @item frame-number
34688 An integer is required as parameter. Selects tracepoint frame with
34689 that index.
34690
34691 @item tracepoint-number
34692 An integer is required as parameter. Finds next
34693 trace frame that corresponds to tracepoint with the specified number.
34694
34695 @item pc
34696 An address is required as parameter. Finds
34697 next trace frame that corresponds to any tracepoint at the specified
34698 address.
34699
34700 @item pc-inside-range
34701 Two addresses are required as parameters. Finds next trace
34702 frame that corresponds to a tracepoint at an address inside the
34703 specified range. Both bounds are considered to be inside the range.
34704
34705 @item pc-outside-range
34706 Two addresses are required as parameters. Finds
34707 next trace frame that corresponds to a tracepoint at an address outside
34708 the specified range. Both bounds are considered to be inside the range.
34709
34710 @item line
34711 Line specification is required as parameter. @xref{Specify Location}.
34712 Finds next trace frame that corresponds to a tracepoint at
34713 the specified location.
34714
34715 @end table
34716
34717 If @samp{none} was passed as @var{mode}, the response does not
34718 have fields. Otherwise, the response may have the following fields:
34719
34720 @table @samp
34721 @item found
34722 This field has either @samp{0} or @samp{1} as the value, depending
34723 on whether a matching tracepoint was found.
34724
34725 @item traceframe
34726 The index of the found traceframe. This field is present iff
34727 the @samp{found} field has value of @samp{1}.
34728
34729 @item tracepoint
34730 The index of the found tracepoint. This field is present iff
34731 the @samp{found} field has value of @samp{1}.
34732
34733 @item frame
34734 The information about the frame corresponding to the found trace
34735 frame. This field is present only if a trace frame was found.
34736 @xref{GDB/MI Frame Information}, for description of this field.
34737
34738 @end table
34739
34740 @subsubheading @value{GDBN} Command
34741
34742 The corresponding @value{GDBN} command is @samp{tfind}.
34743
34744 @subheading -trace-define-variable
34745 @findex -trace-define-variable
34746
34747 @subsubheading Synopsis
34748
34749 @smallexample
34750 -trace-define-variable @var{name} [ @var{value} ]
34751 @end smallexample
34752
34753 Create trace variable @var{name} if it does not exist. If
34754 @var{value} is specified, sets the initial value of the specified
34755 trace variable to that value. Note that the @var{name} should start
34756 with the @samp{$} character.
34757
34758 @subsubheading @value{GDBN} Command
34759
34760 The corresponding @value{GDBN} command is @samp{tvariable}.
34761
34762 @subheading The @code{-trace-frame-collected} Command
34763 @findex -trace-frame-collected
34764
34765 @subsubheading Synopsis
34766
34767 @smallexample
34768 -trace-frame-collected
34769 [--var-print-values @var{var_pval}]
34770 [--comp-print-values @var{comp_pval}]
34771 [--registers-format @var{regformat}]
34772 [--memory-contents]
34773 @end smallexample
34774
34775 This command returns the set of collected objects, register names,
34776 trace state variable names, memory ranges and computed expressions
34777 that have been collected at a particular trace frame. The optional
34778 parameters to the command affect the output format in different ways.
34779 See the output description table below for more details.
34780
34781 The reported names can be used in the normal manner to create
34782 varobjs and inspect the objects themselves. The items returned by
34783 this command are categorized so that it is clear which is a variable,
34784 which is a register, which is a trace state variable, which is a
34785 memory range and which is a computed expression.
34786
34787 For instance, if the actions were
34788 @smallexample
34789 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34790 collect *(int*)0xaf02bef0@@40
34791 @end smallexample
34792
34793 @noindent
34794 the object collected in its entirety would be @code{myVar}. The
34795 object @code{myArray} would be partially collected, because only the
34796 element at index @code{myIndex} would be collected. The remaining
34797 objects would be computed expressions.
34798
34799 An example output would be:
34800
34801 @smallexample
34802 (gdb)
34803 -trace-frame-collected
34804 ^done,
34805 explicit-variables=[@{name="myVar",value="1"@}],
34806 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34807 @{name="myObj.field",value="0"@},
34808 @{name="myPtr->field",value="1"@},
34809 @{name="myCount + 2",value="3"@},
34810 @{name="$tvar1 + 1",value="43970027"@}],
34811 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34812 @{number="1",value="0x0"@},
34813 @{number="2",value="0x4"@},
34814 ...
34815 @{number="125",value="0x0"@}],
34816 tvars=[@{name="$tvar1",current="43970026"@}],
34817 memory=[@{address="0x0000000000602264",length="4"@},
34818 @{address="0x0000000000615bc0",length="4"@}]
34819 (gdb)
34820 @end smallexample
34821
34822 Where:
34823
34824 @table @code
34825 @item explicit-variables
34826 The set of objects that have been collected in their entirety (as
34827 opposed to collecting just a few elements of an array or a few struct
34828 members). For each object, its name and value are printed.
34829 The @code{--var-print-values} option affects how or whether the value
34830 field is output. If @var{var_pval} is 0, then print only the names;
34831 if it is 1, print also their values; and if it is 2, print the name,
34832 type and value for simple data types, and the name and type for
34833 arrays, structures and unions.
34834
34835 @item computed-expressions
34836 The set of computed expressions that have been collected at the
34837 current trace frame. The @code{--comp-print-values} option affects
34838 this set like the @code{--var-print-values} option affects the
34839 @code{explicit-variables} set. See above.
34840
34841 @item registers
34842 The registers that have been collected at the current trace frame.
34843 For each register collected, the name and current value are returned.
34844 The value is formatted according to the @code{--registers-format}
34845 option. See the @command{-data-list-register-values} command for a
34846 list of the allowed formats. The default is @samp{x}.
34847
34848 @item tvars
34849 The trace state variables that have been collected at the current
34850 trace frame. For each trace state variable collected, the name and
34851 current value are returned.
34852
34853 @item memory
34854 The set of memory ranges that have been collected at the current trace
34855 frame. Its content is a list of tuples. Each tuple represents a
34856 collected memory range and has the following fields:
34857
34858 @table @code
34859 @item address
34860 The start address of the memory range, as hexadecimal literal.
34861
34862 @item length
34863 The length of the memory range, as decimal literal.
34864
34865 @item contents
34866 The contents of the memory block, in hex. This field is only present
34867 if the @code{--memory-contents} option is specified.
34868
34869 @end table
34870
34871 @end table
34872
34873 @subsubheading @value{GDBN} Command
34874
34875 There is no corresponding @value{GDBN} command.
34876
34877 @subsubheading Example
34878
34879 @subheading -trace-list-variables
34880 @findex -trace-list-variables
34881
34882 @subsubheading Synopsis
34883
34884 @smallexample
34885 -trace-list-variables
34886 @end smallexample
34887
34888 Return a table of all defined trace variables. Each element of the
34889 table has the following fields:
34890
34891 @table @samp
34892 @item name
34893 The name of the trace variable. This field is always present.
34894
34895 @item initial
34896 The initial value. This is a 64-bit signed integer. This
34897 field is always present.
34898
34899 @item current
34900 The value the trace variable has at the moment. This is a 64-bit
34901 signed integer. This field is absent iff current value is
34902 not defined, for example if the trace was never run, or is
34903 presently running.
34904
34905 @end table
34906
34907 @subsubheading @value{GDBN} Command
34908
34909 The corresponding @value{GDBN} command is @samp{tvariables}.
34910
34911 @subsubheading Example
34912
34913 @smallexample
34914 (gdb)
34915 -trace-list-variables
34916 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
34917 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34918 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34919 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34920 body=[variable=@{name="$trace_timestamp",initial="0"@}
34921 variable=@{name="$foo",initial="10",current="15"@}]@}
34922 (gdb)
34923 @end smallexample
34924
34925 @subheading -trace-save
34926 @findex -trace-save
34927
34928 @subsubheading Synopsis
34929
34930 @smallexample
34931 -trace-save [ -r ] [ -ctf ] @var{filename}
34932 @end smallexample
34933
34934 Saves the collected trace data to @var{filename}. Without the
34935 @samp{-r} option, the data is downloaded from the target and saved
34936 in a local file. With the @samp{-r} option the target is asked
34937 to perform the save.
34938
34939 By default, this command will save the trace in the tfile format. You can
34940 supply the optional @samp{-ctf} argument to save it the CTF format. See
34941 @ref{Trace Files} for more information about CTF.
34942
34943 @subsubheading @value{GDBN} Command
34944
34945 The corresponding @value{GDBN} command is @samp{tsave}.
34946
34947
34948 @subheading -trace-start
34949 @findex -trace-start
34950
34951 @subsubheading Synopsis
34952
34953 @smallexample
34954 -trace-start
34955 @end smallexample
34956
34957 Starts a tracing experiment. The result of this command does not
34958 have any fields.
34959
34960 @subsubheading @value{GDBN} Command
34961
34962 The corresponding @value{GDBN} command is @samp{tstart}.
34963
34964 @subheading -trace-status
34965 @findex -trace-status
34966
34967 @subsubheading Synopsis
34968
34969 @smallexample
34970 -trace-status
34971 @end smallexample
34972
34973 Obtains the status of a tracing experiment. The result may include
34974 the following fields:
34975
34976 @table @samp
34977
34978 @item supported
34979 May have a value of either @samp{0}, when no tracing operations are
34980 supported, @samp{1}, when all tracing operations are supported, or
34981 @samp{file} when examining trace file. In the latter case, examining
34982 of trace frame is possible but new tracing experiement cannot be
34983 started. This field is always present.
34984
34985 @item running
34986 May have a value of either @samp{0} or @samp{1} depending on whether
34987 tracing experiement is in progress on target. This field is present
34988 if @samp{supported} field is not @samp{0}.
34989
34990 @item stop-reason
34991 Report the reason why the tracing was stopped last time. This field
34992 may be absent iff tracing was never stopped on target yet. The
34993 value of @samp{request} means the tracing was stopped as result of
34994 the @code{-trace-stop} command. The value of @samp{overflow} means
34995 the tracing buffer is full. The value of @samp{disconnection} means
34996 tracing was automatically stopped when @value{GDBN} has disconnected.
34997 The value of @samp{passcount} means tracing was stopped when a
34998 tracepoint was passed a maximal number of times for that tracepoint.
34999 This field is present if @samp{supported} field is not @samp{0}.
35000
35001 @item stopping-tracepoint
35002 The number of tracepoint whose passcount as exceeded. This field is
35003 present iff the @samp{stop-reason} field has the value of
35004 @samp{passcount}.
35005
35006 @item frames
35007 @itemx frames-created
35008 The @samp{frames} field is a count of the total number of trace frames
35009 in the trace buffer, while @samp{frames-created} is the total created
35010 during the run, including ones that were discarded, such as when a
35011 circular trace buffer filled up. Both fields are optional.
35012
35013 @item buffer-size
35014 @itemx buffer-free
35015 These fields tell the current size of the tracing buffer and the
35016 remaining space. These fields are optional.
35017
35018 @item circular
35019 The value of the circular trace buffer flag. @code{1} means that the
35020 trace buffer is circular and old trace frames will be discarded if
35021 necessary to make room, @code{0} means that the trace buffer is linear
35022 and may fill up.
35023
35024 @item disconnected
35025 The value of the disconnected tracing flag. @code{1} means that
35026 tracing will continue after @value{GDBN} disconnects, @code{0} means
35027 that the trace run will stop.
35028
35029 @item trace-file
35030 The filename of the trace file being examined. This field is
35031 optional, and only present when examining a trace file.
35032
35033 @end table
35034
35035 @subsubheading @value{GDBN} Command
35036
35037 The corresponding @value{GDBN} command is @samp{tstatus}.
35038
35039 @subheading -trace-stop
35040 @findex -trace-stop
35041
35042 @subsubheading Synopsis
35043
35044 @smallexample
35045 -trace-stop
35046 @end smallexample
35047
35048 Stops a tracing experiment. The result of this command has the same
35049 fields as @code{-trace-status}, except that the @samp{supported} and
35050 @samp{running} fields are not output.
35051
35052 @subsubheading @value{GDBN} Command
35053
35054 The corresponding @value{GDBN} command is @samp{tstop}.
35055
35056
35057 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35058 @node GDB/MI Symbol Query
35059 @section @sc{gdb/mi} Symbol Query Commands
35060
35061
35062 @ignore
35063 @subheading The @code{-symbol-info-address} Command
35064 @findex -symbol-info-address
35065
35066 @subsubheading Synopsis
35067
35068 @smallexample
35069 -symbol-info-address @var{symbol}
35070 @end smallexample
35071
35072 Describe where @var{symbol} is stored.
35073
35074 @subsubheading @value{GDBN} Command
35075
35076 The corresponding @value{GDBN} command is @samp{info address}.
35077
35078 @subsubheading Example
35079 N.A.
35080
35081
35082 @subheading The @code{-symbol-info-file} Command
35083 @findex -symbol-info-file
35084
35085 @subsubheading Synopsis
35086
35087 @smallexample
35088 -symbol-info-file
35089 @end smallexample
35090
35091 Show the file for the symbol.
35092
35093 @subsubheading @value{GDBN} Command
35094
35095 There's no equivalent @value{GDBN} command. @code{gdbtk} has
35096 @samp{gdb_find_file}.
35097
35098 @subsubheading Example
35099 N.A.
35100 @end ignore
35101
35102 @subheading The @code{-symbol-info-functions} Command
35103 @findex -symbol-info-functions
35104 @anchor{-symbol-info-functions}
35105
35106 @subsubheading Synopsis
35107
35108 @smallexample
35109 -symbol-info-functions [--include-nondebug]
35110 [--type @var{type_regexp}]
35111 [--name @var{name_regexp}]
35112 [--max-results @var{limit}]
35113 @end smallexample
35114
35115 @noindent
35116 Return a list containing the names and types for all global functions
35117 taken from the debug information. The functions are grouped by source
35118 file, and shown with the line number on which each function is
35119 defined.
35120
35121 The @code{--include-nondebug} option causes the output to include
35122 code symbols from the symbol table.
35123
35124 The options @code{--type} and @code{--name} allow the symbols returned
35125 to be filtered based on either the name of the function, or the type
35126 signature of the function.
35127
35128 The option @code{--max-results} restricts the command to return no
35129 more than @var{limit} results. If exactly @var{limit} results are
35130 returned then there might be additional results available if a higher
35131 limit is used.
35132
35133 @subsubheading @value{GDBN} Command
35134
35135 The corresponding @value{GDBN} command is @samp{info functions}.
35136
35137 @subsubheading Example
35138 @smallexample
35139 @group
35140 (gdb)
35141 -symbol-info-functions
35142 ^done,symbols=
35143 @{debug=
35144 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35145 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35146 symbols=[@{line="36", name="f4", type="void (int *)",
35147 description="void f4(int *);"@},
35148 @{line="42", name="main", type="int ()",
35149 description="int main();"@},
35150 @{line="30", name="f1", type="my_int_t (int, int)",
35151 description="static my_int_t f1(int, int);"@}]@},
35152 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35153 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35154 symbols=[@{line="33", name="f2", type="float (another_float_t)",
35155 description="float f2(another_float_t);"@},
35156 @{line="39", name="f3", type="int (another_int_t)",
35157 description="int f3(another_int_t);"@},
35158 @{line="27", name="f1", type="another_float_t (int)",
35159 description="static another_float_t f1(int);"@}]@}]@}
35160 @end group
35161 @group
35162 (gdb)
35163 -symbol-info-functions --name f1
35164 ^done,symbols=
35165 @{debug=
35166 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35167 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35168 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
35169 description="static my_int_t f1(int, int);"@}]@},
35170 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35171 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35172 symbols=[@{line="27", name="f1", type="another_float_t (int)",
35173 description="static another_float_t f1(int);"@}]@}]@}
35174 @end group
35175 @group
35176 (gdb)
35177 -symbol-info-functions --type void
35178 ^done,symbols=
35179 @{debug=
35180 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35181 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35182 symbols=[@{line="36", name="f4", type="void (int *)",
35183 description="void f4(int *);"@}]@}]@}
35184 @end group
35185 @group
35186 (gdb)
35187 -symbol-info-functions --include-nondebug
35188 ^done,symbols=
35189 @{debug=
35190 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35191 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35192 symbols=[@{line="36", name="f4", type="void (int *)",
35193 description="void f4(int *);"@},
35194 @{line="42", name="main", type="int ()",
35195 description="int main();"@},
35196 @{line="30", name="f1", type="my_int_t (int, int)",
35197 description="static my_int_t f1(int, int);"@}]@},
35198 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35199 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35200 symbols=[@{line="33", name="f2", type="float (another_float_t)",
35201 description="float f2(another_float_t);"@},
35202 @{line="39", name="f3", type="int (another_int_t)",
35203 description="int f3(another_int_t);"@},
35204 @{line="27", name="f1", type="another_float_t (int)",
35205 description="static another_float_t f1(int);"@}]@}],
35206 nondebug=
35207 [@{address="0x0000000000400398",name="_init"@},
35208 @{address="0x00000000004003b0",name="_start"@},
35209 ...
35210 ]@}
35211 @end group
35212 @end smallexample
35213
35214 @subheading The @code{-symbol-info-module-functions} Command
35215 @findex -symbol-info-module-functions
35216 @anchor{-symbol-info-module-functions}
35217
35218 @subsubheading Synopsis
35219
35220 @smallexample
35221 -symbol-info-module-functions [--module @var{module_regexp}]
35222 [--name @var{name_regexp}]
35223 [--type @var{type_regexp}]
35224 @end smallexample
35225
35226 @noindent
35227 Return a list containing the names of all known functions within all
35228 know Fortran modules. The functions are grouped by source file and
35229 containing module, and shown with the line number on which each
35230 function is defined.
35231
35232 The option @code{--module} only returns results for modules matching
35233 @var{module_regexp}. The option @code{--name} only returns functions
35234 whose name matches @var{name_regexp}, and @code{--type} only returns
35235 functions whose type matches @var{type_regexp}.
35236
35237 @subsubheading @value{GDBN} Command
35238
35239 The corresponding @value{GDBN} command is @samp{info module functions}.
35240
35241 @subsubheading Example
35242
35243 @smallexample
35244 @group
35245 (gdb)
35246 -symbol-info-module-functions
35247 ^done,symbols=
35248 [@{module="mod1",
35249 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35250 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35251 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
35252 description="void mod1::check_all(void);"@}]@}]@},
35253 @{module="mod2",
35254 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35255 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35256 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
35257 description="void mod2::check_var_i(void);"@}]@}]@},
35258 @{module="mod3",
35259 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35260 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35261 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
35262 description="void mod3::check_all(void);"@},
35263 @{line="27",name="mod3::check_mod2",type="void (void)",
35264 description="void mod3::check_mod2(void);"@}]@}]@},
35265 @{module="modmany",
35266 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35267 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35268 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
35269 description="void modmany::check_some(void);"@}]@}]@},
35270 @{module="moduse",
35271 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35272 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35273 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
35274 description="void moduse::check_all(void);"@},
35275 @{line="49",name="moduse::check_var_x",type="void (void)",
35276 description="void moduse::check_var_x(void);"@}]@}]@}]
35277 @end group
35278 @end smallexample
35279
35280 @subheading The @code{-symbol-info-module-variables} Command
35281 @findex -symbol-info-module-variables
35282 @anchor{-symbol-info-module-variables}
35283
35284 @subsubheading Synopsis
35285
35286 @smallexample
35287 -symbol-info-module-variables [--module @var{module_regexp}]
35288 [--name @var{name_regexp}]
35289 [--type @var{type_regexp}]
35290 @end smallexample
35291
35292 @noindent
35293 Return a list containing the names of all known variables within all
35294 know Fortran modules. The variables are grouped by source file and
35295 containing module, and shown with the line number on which each
35296 variable is defined.
35297
35298 The option @code{--module} only returns results for modules matching
35299 @var{module_regexp}. The option @code{--name} only returns variables
35300 whose name matches @var{name_regexp}, and @code{--type} only returns
35301 variables whose type matches @var{type_regexp}.
35302
35303 @subsubheading @value{GDBN} Command
35304
35305 The corresponding @value{GDBN} command is @samp{info module variables}.
35306
35307 @subsubheading Example
35308
35309 @smallexample
35310 @group
35311 (gdb)
35312 -symbol-info-module-variables
35313 ^done,symbols=
35314 [@{module="mod1",
35315 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35316 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35317 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
35318 description="integer(kind=4) mod1::var_const;"@},
35319 @{line="17",name="mod1::var_i",type="integer(kind=4)",
35320 description="integer(kind=4) mod1::var_i;"@}]@}]@},
35321 @{module="mod2",
35322 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35323 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35324 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
35325 description="integer(kind=4) mod2::var_i;"@}]@}]@},
35326 @{module="mod3",
35327 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35328 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35329 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
35330 description="integer(kind=4) mod3::mod1;"@},
35331 @{line="17",name="mod3::mod2",type="integer(kind=4)",
35332 description="integer(kind=4) mod3::mod2;"@},
35333 @{line="19",name="mod3::var_i",type="integer(kind=4)",
35334 description="integer(kind=4) mod3::var_i;"@}]@}]@},
35335 @{module="modmany",
35336 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35337 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35338 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
35339 description="integer(kind=4) modmany::var_a;"@},
35340 @{line="33",name="modmany::var_b",type="integer(kind=4)",
35341 description="integer(kind=4) modmany::var_b;"@},
35342 @{line="33",name="modmany::var_c",type="integer(kind=4)",
35343 description="integer(kind=4) modmany::var_c;"@},
35344 @{line="33",name="modmany::var_i",type="integer(kind=4)",
35345 description="integer(kind=4) modmany::var_i;"@}]@}]@},
35346 @{module="moduse",
35347 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35348 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35349 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
35350 description="integer(kind=4) moduse::var_x;"@},
35351 @{line="42",name="moduse::var_y",type="integer(kind=4)",
35352 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
35353 @end group
35354 @end smallexample
35355
35356 @subheading The @code{-symbol-info-modules} Command
35357 @findex -symbol-info-modules
35358 @anchor{-symbol-info-modules}
35359
35360 @subsubheading Synopsis
35361
35362 @smallexample
35363 -symbol-info-modules [--name @var{name_regexp}]
35364 [--max-results @var{limit}]
35365
35366 @end smallexample
35367
35368 @noindent
35369 Return a list containing the names of all known Fortran modules. The
35370 modules are grouped by source file, and shown with the line number on
35371 which each modules is defined.
35372
35373 The option @code{--name} allows the modules returned to be filtered
35374 based the name of the module.
35375
35376 The option @code{--max-results} restricts the command to return no
35377 more than @var{limit} results. If exactly @var{limit} results are
35378 returned then there might be additional results available if a higher
35379 limit is used.
35380
35381 @subsubheading @value{GDBN} Command
35382
35383 The corresponding @value{GDBN} command is @samp{info modules}.
35384
35385 @subsubheading Example
35386 @smallexample
35387 @group
35388 (gdb)
35389 -symbol-info-modules
35390 ^done,symbols=
35391 @{debug=
35392 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35393 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35394 symbols=[@{line="16",name="mod1"@},
35395 @{line="22",name="mod2"@}]@},
35396 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35397 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35398 symbols=[@{line="16",name="mod3"@},
35399 @{line="22",name="modmany"@},
35400 @{line="26",name="moduse"@}]@}]@}
35401 @end group
35402 @group
35403 (gdb)
35404 -symbol-info-modules --name mod[123]
35405 ^done,symbols=
35406 @{debug=
35407 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35408 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35409 symbols=[@{line="16",name="mod1"@},
35410 @{line="22",name="mod2"@}]@},
35411 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35412 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35413 symbols=[@{line="16",name="mod3"@}]@}]@}
35414 @end group
35415 @end smallexample
35416
35417 @subheading The @code{-symbol-info-types} Command
35418 @findex -symbol-info-types
35419 @anchor{-symbol-info-types}
35420
35421 @subsubheading Synopsis
35422
35423 @smallexample
35424 -symbol-info-types [--name @var{name_regexp}]
35425 [--max-results @var{limit}]
35426
35427 @end smallexample
35428
35429 @noindent
35430 Return a list of all defined types. The types are grouped by source
35431 file, and shown with the line number on which each user defined type
35432 is defined. Some base types are not defined in the source code but
35433 are added to the debug information by the compiler, for example
35434 @code{int}, @code{float}, etc.; these types do not have an associated
35435 line number.
35436
35437 The option @code{--name} allows the list of types returned to be
35438 filtered by name.
35439
35440 The option @code{--max-results} restricts the command to return no
35441 more than @var{limit} results. If exactly @var{limit} results are
35442 returned then there might be additional results available if a higher
35443 limit is used.
35444
35445 @subsubheading @value{GDBN} Command
35446
35447 The corresponding @value{GDBN} command is @samp{info types}.
35448
35449 @subsubheading Example
35450 @smallexample
35451 @group
35452 (gdb)
35453 -symbol-info-types
35454 ^done,symbols=
35455 @{debug=
35456 [@{filename="gdb.mi/mi-sym-info-1.c",
35457 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35458 symbols=[@{name="float"@},
35459 @{name="int"@},
35460 @{line="27",name="typedef int my_int_t;"@}]@},
35461 @{filename="gdb.mi/mi-sym-info-2.c",
35462 fullname="/project/gdb.mi/mi-sym-info-2.c",
35463 symbols=[@{line="24",name="typedef float another_float_t;"@},
35464 @{line="23",name="typedef int another_int_t;"@},
35465 @{name="float"@},
35466 @{name="int"@}]@}]@}
35467 @end group
35468 @group
35469 (gdb)
35470 -symbol-info-types --name _int_
35471 ^done,symbols=
35472 @{debug=
35473 [@{filename="gdb.mi/mi-sym-info-1.c",
35474 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35475 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
35476 @{filename="gdb.mi/mi-sym-info-2.c",
35477 fullname="/project/gdb.mi/mi-sym-info-2.c",
35478 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
35479 @end group
35480 @end smallexample
35481
35482 @subheading The @code{-symbol-info-variables} Command
35483 @findex -symbol-info-variables
35484 @anchor{-symbol-info-variables}
35485
35486 @subsubheading Synopsis
35487
35488 @smallexample
35489 -symbol-info-variables [--include-nondebug]
35490 [--type @var{type_regexp}]
35491 [--name @var{name_regexp}]
35492 [--max-results @var{limit}]
35493
35494 @end smallexample
35495
35496 @noindent
35497 Return a list containing the names and types for all global variables
35498 taken from the debug information. The variables are grouped by source
35499 file, and shown with the line number on which each variable is
35500 defined.
35501
35502 The @code{--include-nondebug} option causes the output to include
35503 data symbols from the symbol table.
35504
35505 The options @code{--type} and @code{--name} allow the symbols returned
35506 to be filtered based on either the name of the variable, or the type
35507 of the variable.
35508
35509 The option @code{--max-results} restricts the command to return no
35510 more than @var{limit} results. If exactly @var{limit} results are
35511 returned then there might be additional results available if a higher
35512 limit is used.
35513
35514 @subsubheading @value{GDBN} Command
35515
35516 The corresponding @value{GDBN} command is @samp{info variables}.
35517
35518 @subsubheading Example
35519 @smallexample
35520 @group
35521 (gdb)
35522 -symbol-info-variables
35523 ^done,symbols=
35524 @{debug=
35525 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35526 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35527 symbols=[@{line="25",name="global_f1",type="float",
35528 description="static float global_f1;"@},
35529 @{line="24",name="global_i1",type="int",
35530 description="static int global_i1;"@}]@},
35531 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35532 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35533 symbols=[@{line="21",name="global_f2",type="int",
35534 description="int global_f2;"@},
35535 @{line="20",name="global_i2",type="int",
35536 description="int global_i2;"@},
35537 @{line="19",name="global_f1",type="float",
35538 description="static float global_f1;"@},
35539 @{line="18",name="global_i1",type="int",
35540 description="static int global_i1;"@}]@}]@}
35541 @end group
35542 @group
35543 (gdb)
35544 -symbol-info-variables --name f1
35545 ^done,symbols=
35546 @{debug=
35547 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35548 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35549 symbols=[@{line="25",name="global_f1",type="float",
35550 description="static float global_f1;"@}]@},
35551 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35552 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35553 symbols=[@{line="19",name="global_f1",type="float",
35554 description="static float global_f1;"@}]@}]@}
35555 @end group
35556 @group
35557 (gdb)
35558 -symbol-info-variables --type float
35559 ^done,symbols=
35560 @{debug=
35561 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35562 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35563 symbols=[@{line="25",name="global_f1",type="float",
35564 description="static float global_f1;"@}]@},
35565 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35566 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35567 symbols=[@{line="19",name="global_f1",type="float",
35568 description="static float global_f1;"@}]@}]@}
35569 @end group
35570 @group
35571 (gdb)
35572 -symbol-info-variables --include-nondebug
35573 ^done,symbols=
35574 @{debug=
35575 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35576 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35577 symbols=[@{line="25",name="global_f1",type="float",
35578 description="static float global_f1;"@},
35579 @{line="24",name="global_i1",type="int",
35580 description="static int global_i1;"@}]@},
35581 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35582 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35583 symbols=[@{line="21",name="global_f2",type="int",
35584 description="int global_f2;"@},
35585 @{line="20",name="global_i2",type="int",
35586 description="int global_i2;"@},
35587 @{line="19",name="global_f1",type="float",
35588 description="static float global_f1;"@},
35589 @{line="18",name="global_i1",type="int",
35590 description="static int global_i1;"@}]@}],
35591 nondebug=
35592 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35593 @{address="0x00000000004005d8",name="__dso_handle"@}
35594 ...
35595 ]@}
35596 @end group
35597 @end smallexample
35598
35599 @ignore
35600 @subheading The @code{-symbol-info-line} Command
35601 @findex -symbol-info-line
35602
35603 @subsubheading Synopsis
35604
35605 @smallexample
35606 -symbol-info-line
35607 @end smallexample
35608
35609 Show the core addresses of the code for a source line.
35610
35611 @subsubheading @value{GDBN} Command
35612
35613 The corresponding @value{GDBN} command is @samp{info line}.
35614 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
35615
35616 @subsubheading Example
35617 N.A.
35618
35619
35620 @subheading The @code{-symbol-info-symbol} Command
35621 @findex -symbol-info-symbol
35622
35623 @subsubheading Synopsis
35624
35625 @smallexample
35626 -symbol-info-symbol @var{addr}
35627 @end smallexample
35628
35629 Describe what symbol is at location @var{addr}.
35630
35631 @subsubheading @value{GDBN} Command
35632
35633 The corresponding @value{GDBN} command is @samp{info symbol}.
35634
35635 @subsubheading Example
35636 N.A.
35637
35638
35639 @subheading The @code{-symbol-list-functions} Command
35640 @findex -symbol-list-functions
35641
35642 @subsubheading Synopsis
35643
35644 @smallexample
35645 -symbol-list-functions
35646 @end smallexample
35647
35648 List the functions in the executable.
35649
35650 @subsubheading @value{GDBN} Command
35651
35652 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35653 @samp{gdb_search} in @code{gdbtk}.
35654
35655 @subsubheading Example
35656 N.A.
35657 @end ignore
35658
35659
35660 @subheading The @code{-symbol-list-lines} Command
35661 @findex -symbol-list-lines
35662
35663 @subsubheading Synopsis
35664
35665 @smallexample
35666 -symbol-list-lines @var{filename}
35667 @end smallexample
35668
35669 Print the list of lines that contain code and their associated program
35670 addresses for the given source filename. The entries are sorted in
35671 ascending PC order.
35672
35673 @subsubheading @value{GDBN} Command
35674
35675 There is no corresponding @value{GDBN} command.
35676
35677 @subsubheading Example
35678 @smallexample
35679 (gdb)
35680 -symbol-list-lines basics.c
35681 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
35682 (gdb)
35683 @end smallexample
35684
35685
35686 @ignore
35687 @subheading The @code{-symbol-list-types} Command
35688 @findex -symbol-list-types
35689
35690 @subsubheading Synopsis
35691
35692 @smallexample
35693 -symbol-list-types
35694 @end smallexample
35695
35696 List all the type names.
35697
35698 @subsubheading @value{GDBN} Command
35699
35700 The corresponding commands are @samp{info types} in @value{GDBN},
35701 @samp{gdb_search} in @code{gdbtk}.
35702
35703 @subsubheading Example
35704 N.A.
35705
35706
35707 @subheading The @code{-symbol-list-variables} Command
35708 @findex -symbol-list-variables
35709
35710 @subsubheading Synopsis
35711
35712 @smallexample
35713 -symbol-list-variables
35714 @end smallexample
35715
35716 List all the global and static variable names.
35717
35718 @subsubheading @value{GDBN} Command
35719
35720 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
35721
35722 @subsubheading Example
35723 N.A.
35724
35725
35726 @subheading The @code{-symbol-locate} Command
35727 @findex -symbol-locate
35728
35729 @subsubheading Synopsis
35730
35731 @smallexample
35732 -symbol-locate
35733 @end smallexample
35734
35735 @subsubheading @value{GDBN} Command
35736
35737 @samp{gdb_loc} in @code{gdbtk}.
35738
35739 @subsubheading Example
35740 N.A.
35741
35742
35743 @subheading The @code{-symbol-type} Command
35744 @findex -symbol-type
35745
35746 @subsubheading Synopsis
35747
35748 @smallexample
35749 -symbol-type @var{variable}
35750 @end smallexample
35751
35752 Show type of @var{variable}.
35753
35754 @subsubheading @value{GDBN} Command
35755
35756 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35757 @samp{gdb_obj_variable}.
35758
35759 @subsubheading Example
35760 N.A.
35761 @end ignore
35762
35763
35764 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35765 @node GDB/MI File Commands
35766 @section @sc{gdb/mi} File Commands
35767
35768 This section describes the GDB/MI commands to specify executable file names
35769 and to read in and obtain symbol table information.
35770
35771 @subheading The @code{-file-exec-and-symbols} Command
35772 @findex -file-exec-and-symbols
35773
35774 @subsubheading Synopsis
35775
35776 @smallexample
35777 -file-exec-and-symbols @var{file}
35778 @end smallexample
35779
35780 Specify the executable file to be debugged. This file is the one from
35781 which the symbol table is also read. If no file is specified, the
35782 command clears the executable and symbol information. If breakpoints
35783 are set when using this command with no arguments, @value{GDBN} will produce
35784 error messages. Otherwise, no output is produced, except a completion
35785 notification.
35786
35787 @subsubheading @value{GDBN} Command
35788
35789 The corresponding @value{GDBN} command is @samp{file}.
35790
35791 @subsubheading Example
35792
35793 @smallexample
35794 (gdb)
35795 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35796 ^done
35797 (gdb)
35798 @end smallexample
35799
35800
35801 @subheading The @code{-file-exec-file} Command
35802 @findex -file-exec-file
35803
35804 @subsubheading Synopsis
35805
35806 @smallexample
35807 -file-exec-file @var{file}
35808 @end smallexample
35809
35810 Specify the executable file to be debugged. Unlike
35811 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35812 from this file. If used without argument, @value{GDBN} clears the information
35813 about the executable file. No output is produced, except a completion
35814 notification.
35815
35816 @subsubheading @value{GDBN} Command
35817
35818 The corresponding @value{GDBN} command is @samp{exec-file}.
35819
35820 @subsubheading Example
35821
35822 @smallexample
35823 (gdb)
35824 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35825 ^done
35826 (gdb)
35827 @end smallexample
35828
35829
35830 @ignore
35831 @subheading The @code{-file-list-exec-sections} Command
35832 @findex -file-list-exec-sections
35833
35834 @subsubheading Synopsis
35835
35836 @smallexample
35837 -file-list-exec-sections
35838 @end smallexample
35839
35840 List the sections of the current executable file.
35841
35842 @subsubheading @value{GDBN} Command
35843
35844 The @value{GDBN} command @samp{info file} shows, among the rest, the same
35845 information as this command. @code{gdbtk} has a corresponding command
35846 @samp{gdb_load_info}.
35847
35848 @subsubheading Example
35849 N.A.
35850 @end ignore
35851
35852
35853 @subheading The @code{-file-list-exec-source-file} Command
35854 @findex -file-list-exec-source-file
35855
35856 @subsubheading Synopsis
35857
35858 @smallexample
35859 -file-list-exec-source-file
35860 @end smallexample
35861
35862 List the line number, the current source file, and the absolute path
35863 to the current source file for the current executable. The macro
35864 information field has a value of @samp{1} or @samp{0} depending on
35865 whether or not the file includes preprocessor macro information.
35866
35867 @subsubheading @value{GDBN} Command
35868
35869 The @value{GDBN} equivalent is @samp{info source}
35870
35871 @subsubheading Example
35872
35873 @smallexample
35874 (gdb)
35875 123-file-list-exec-source-file
35876 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35877 (gdb)
35878 @end smallexample
35879
35880
35881 @subheading The @code{-file-list-exec-source-files} Command
35882 @kindex info sources
35883 @findex -file-list-exec-source-files
35884
35885 @subsubheading Synopsis
35886
35887 @smallexample
35888 -file-list-exec-source-files @r{[} @var{--group-by-objfile} @r{]}
35889 @r{[} @var{--dirname} @r{|} @var{--basename} @r{]}
35890 @r{[} -- @r{]}
35891 @r{[} @var{regexp} @r{]}
35892 @end smallexample
35893
35894 This command returns information about the source files @value{GDBN}
35895 knows about, it will output both the filename and fullname (absolute
35896 file name) of a source file, though the fullname can be elided if this
35897 information is not known to @value{GDBN}.
35898
35899 With no arguments this command returns a list of source files. Each
35900 source file is represented by a tuple with the fields; @var{file},
35901 @var{fullname}, and @var{debug-fully-read}. The @var{file} is the
35902 display name for the file, while @var{fullname} is the absolute name
35903 of the file. The @var{fullname} field can be elided if the absolute
35904 name of the source file can't be computed. The field
35905 @var{debug-fully-read} will be a string, either @code{true} or
35906 @code{false}. When @code{true}, this indicates the full debug
35907 information for the compilation unit describing this file has been
35908 read in. When @code{false}, the full debug information has not yet
35909 been read in. While reading in the full debug information it is
35910 possible that @value{GDBN} could become aware of additional source
35911 files.
35912
35913 The optional @var{regexp} can be used to filter the list of source
35914 files returned. The @var{regexp} will be matched against the full
35915 source file name. The matching is case-sensitive, except on operating
35916 systems that have case-insensitive filesystem (e.g.,
35917 MS-Windows). @samp{--} can be used before @var{regexp} to prevent
35918 @value{GDBN} interpreting @var{regexp} as a command option (e.g.@: if
35919 @var{regexp} starts with @samp{-}).
35920
35921 If @code{--dirname} is provided, then @var{regexp} is matched only
35922 against the directory name of each source file. If @code{--basename}
35923 is provided, then @var{regexp} is matched against the basename of each
35924 source file. Only one of @code{--dirname} or @code{--basename} may be
35925 given, and if either is given then @var{regexp} is required.
35926
35927 If @code{--group-by-objfile} is used then the format of the results is
35928 changed. The results will now be a list of tuples, with each tuple
35929 representing an object file (executable or shared library) loaded into
35930 @value{GDBN}. The fields of these tuples are; @var{filename},
35931 @var{debug-info}, and @var{sources}. The @var{filename} is the
35932 absolute name of the object file, @var{debug-info} is a string with
35933 one of the following values:
35934
35935 @table @code
35936 @item none
35937 This object file has no debug information.
35938 @item partially-read
35939 This object file has debug information, but it is not fully read in
35940 yet. When it is read in later, GDB might become aware of additional
35941 source files.
35942 @item fully-read
35943 This object file has debug information, and this information is fully
35944 read into GDB. The list of source files is complete.
35945 @end table
35946
35947 The @var{sources} is a list or tuples, with each tuple describing a
35948 single source file with the same fields as described previously. The
35949 @var{sources} list can be empty for object files that have no debug
35950 information.
35951
35952 @subsubheading @value{GDBN} Command
35953
35954 The @value{GDBN} equivalent is @samp{info sources}.
35955 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35956
35957 @subsubheading Example
35958 @smallexample
35959 (@value{GDBP})
35960 -file-list-exec-source-files
35961 ^done,files=[@{file="foo.c",fullname="/home/foo.c",debug-fully-read="true"@},
35962 @{file="/home/bar.c",fullname="/home/bar.c",debug-fully-read="true"@},
35963 @{file="gdb_could_not_find_fullpath.c",debug-fully-read="true"@}]
35964 (@value{GDBP})
35965 -file-list-exec-source-files
35966 ^done,files=[@{file="test.c",
35967 fullname="/tmp/info-sources/test.c",
35968 debug-fully-read="true"@},
35969 @{file="/usr/include/stdc-predef.h",
35970 fullname="/usr/include/stdc-predef.h",
35971 debug-fully-read="true"@},
35972 @{file="header.h",
35973 fullname="/tmp/info-sources/header.h",
35974 debug-fully-read="true"@},
35975 @{file="helper.c",
35976 fullname="/tmp/info-sources/helper.c",
35977 debug-fully-read="true"@}]
35978 (@value{GDBP})
35979 -file-list-exec-source-files -- \\.c
35980 ^done,files=[@{file="test.c",
35981 fullname="/tmp/info-sources/test.c",
35982 debug-fully-read="true"@},
35983 @{file="helper.c",
35984 fullname="/tmp/info-sources/helper.c",
35985 debug-fully-read="true"@}]
35986 (@value{GDBP})
35987 -file-list-exec-source-files --group-by-objfile
35988 ^done,files=[@{filename="/tmp/info-sources/test.x",
35989 debug-info="fully-read",
35990 sources=[@{file="test.c",
35991 fullname="/tmp/info-sources/test.c",
35992 debug-fully-read="true"@},
35993 @{file="/usr/include/stdc-predef.h",
35994 fullname="/usr/include/stdc-predef.h",
35995 debug-fully-read="true"@},
35996 @{file="header.h",
35997 fullname="/tmp/info-sources/header.h",
35998 debug-fully-read="true"@}]@},
35999 @{filename="/lib64/ld-linux-x86-64.so.2",
36000 debug-info="none",
36001 sources=[]@},
36002 @{filename="system-supplied DSO at 0x7ffff7fcf000",
36003 debug-info="none",
36004 sources=[]@},
36005 @{filename="/tmp/info-sources/libhelper.so",
36006 debug-info="fully-read",
36007 sources=[@{file="helper.c",
36008 fullname="/tmp/info-sources/helper.c",
36009 debug-fully-read="true"@},
36010 @{file="/usr/include/stdc-predef.h",
36011 fullname="/usr/include/stdc-predef.h",
36012 debug-fully-read="true"@},
36013 @{file="header.h",
36014 fullname="/tmp/info-sources/header.h",
36015 debug-fully-read="true"@}]@},
36016 @{filename="/lib64/libc.so.6",
36017 debug-info="none",
36018 sources=[]@}]
36019 @end smallexample
36020
36021 @subheading The @code{-file-list-shared-libraries} Command
36022 @findex -file-list-shared-libraries
36023
36024 @subsubheading Synopsis
36025
36026 @smallexample
36027 -file-list-shared-libraries [ @var{regexp} ]
36028 @end smallexample
36029
36030 List the shared libraries in the program.
36031 With a regular expression @var{regexp}, only those libraries whose
36032 names match @var{regexp} are listed.
36033
36034 @subsubheading @value{GDBN} Command
36035
36036 The corresponding @value{GDBN} command is @samp{info shared}. The fields
36037 have a similar meaning to the @code{=library-loaded} notification.
36038 The @code{ranges} field specifies the multiple segments belonging to this
36039 library. Each range has the following fields:
36040
36041 @table @samp
36042 @item from
36043 The address defining the inclusive lower bound of the segment.
36044 @item to
36045 The address defining the exclusive upper bound of the segment.
36046 @end table
36047
36048 @subsubheading Example
36049 @smallexample
36050 (gdb)
36051 -file-list-exec-source-files
36052 ^done,shared-libraries=[
36053 @{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"@}]@},
36054 @{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"@}]@}]
36055 (gdb)
36056 @end smallexample
36057
36058
36059 @ignore
36060 @subheading The @code{-file-list-symbol-files} Command
36061 @findex -file-list-symbol-files
36062
36063 @subsubheading Synopsis
36064
36065 @smallexample
36066 -file-list-symbol-files
36067 @end smallexample
36068
36069 List symbol files.
36070
36071 @subsubheading @value{GDBN} Command
36072
36073 The corresponding @value{GDBN} command is @samp{info file} (part of it).
36074
36075 @subsubheading Example
36076 N.A.
36077 @end ignore
36078
36079
36080 @subheading The @code{-file-symbol-file} Command
36081 @findex -file-symbol-file
36082
36083 @subsubheading Synopsis
36084
36085 @smallexample
36086 -file-symbol-file @var{file}
36087 @end smallexample
36088
36089 Read symbol table info from the specified @var{file} argument. When
36090 used without arguments, clears @value{GDBN}'s symbol table info. No output is
36091 produced, except for a completion notification.
36092
36093 @subsubheading @value{GDBN} Command
36094
36095 The corresponding @value{GDBN} command is @samp{symbol-file}.
36096
36097 @subsubheading Example
36098
36099 @smallexample
36100 (gdb)
36101 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
36102 ^done
36103 (gdb)
36104 @end smallexample
36105
36106 @ignore
36107 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36108 @node GDB/MI Memory Overlay Commands
36109 @section @sc{gdb/mi} Memory Overlay Commands
36110
36111 The memory overlay commands are not implemented.
36112
36113 @c @subheading -overlay-auto
36114
36115 @c @subheading -overlay-list-mapping-state
36116
36117 @c @subheading -overlay-list-overlays
36118
36119 @c @subheading -overlay-map
36120
36121 @c @subheading -overlay-off
36122
36123 @c @subheading -overlay-on
36124
36125 @c @subheading -overlay-unmap
36126
36127 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36128 @node GDB/MI Signal Handling Commands
36129 @section @sc{gdb/mi} Signal Handling Commands
36130
36131 Signal handling commands are not implemented.
36132
36133 @c @subheading -signal-handle
36134
36135 @c @subheading -signal-list-handle-actions
36136
36137 @c @subheading -signal-list-signal-types
36138 @end ignore
36139
36140
36141 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36142 @node GDB/MI Target Manipulation
36143 @section @sc{gdb/mi} Target Manipulation Commands
36144
36145
36146 @subheading The @code{-target-attach} Command
36147 @findex -target-attach
36148
36149 @subsubheading Synopsis
36150
36151 @smallexample
36152 -target-attach @var{pid} | @var{gid} | @var{file}
36153 @end smallexample
36154
36155 Attach to a process @var{pid} or a file @var{file} outside of
36156 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
36157 group, the id previously returned by
36158 @samp{-list-thread-groups --available} must be used.
36159
36160 @subsubheading @value{GDBN} Command
36161
36162 The corresponding @value{GDBN} command is @samp{attach}.
36163
36164 @subsubheading Example
36165 @smallexample
36166 (gdb)
36167 -target-attach 34
36168 =thread-created,id="1"
36169 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
36170 ^done
36171 (gdb)
36172 @end smallexample
36173
36174 @ignore
36175 @subheading The @code{-target-compare-sections} Command
36176 @findex -target-compare-sections
36177
36178 @subsubheading Synopsis
36179
36180 @smallexample
36181 -target-compare-sections [ @var{section} ]
36182 @end smallexample
36183
36184 Compare data of section @var{section} on target to the exec file.
36185 Without the argument, all sections are compared.
36186
36187 @subsubheading @value{GDBN} Command
36188
36189 The @value{GDBN} equivalent is @samp{compare-sections}.
36190
36191 @subsubheading Example
36192 N.A.
36193 @end ignore
36194
36195
36196 @subheading The @code{-target-detach} Command
36197 @findex -target-detach
36198
36199 @subsubheading Synopsis
36200
36201 @smallexample
36202 -target-detach [ @var{pid} | @var{gid} ]
36203 @end smallexample
36204
36205 Detach from the remote target which normally resumes its execution.
36206 If either @var{pid} or @var{gid} is specified, detaches from either
36207 the specified process, or specified thread group. There's no output.
36208
36209 @subsubheading @value{GDBN} Command
36210
36211 The corresponding @value{GDBN} command is @samp{detach}.
36212
36213 @subsubheading Example
36214
36215 @smallexample
36216 (gdb)
36217 -target-detach
36218 ^done
36219 (gdb)
36220 @end smallexample
36221
36222
36223 @subheading The @code{-target-disconnect} Command
36224 @findex -target-disconnect
36225
36226 @subsubheading Synopsis
36227
36228 @smallexample
36229 -target-disconnect
36230 @end smallexample
36231
36232 Disconnect from the remote target. There's no output and the target is
36233 generally not resumed.
36234
36235 @subsubheading @value{GDBN} Command
36236
36237 The corresponding @value{GDBN} command is @samp{disconnect}.
36238
36239 @subsubheading Example
36240
36241 @smallexample
36242 (gdb)
36243 -target-disconnect
36244 ^done
36245 (gdb)
36246 @end smallexample
36247
36248
36249 @subheading The @code{-target-download} Command
36250 @findex -target-download
36251
36252 @subsubheading Synopsis
36253
36254 @smallexample
36255 -target-download
36256 @end smallexample
36257
36258 Loads the executable onto the remote target.
36259 It prints out an update message every half second, which includes the fields:
36260
36261 @table @samp
36262 @item section
36263 The name of the section.
36264 @item section-sent
36265 The size of what has been sent so far for that section.
36266 @item section-size
36267 The size of the section.
36268 @item total-sent
36269 The total size of what was sent so far (the current and the previous sections).
36270 @item total-size
36271 The size of the overall executable to download.
36272 @end table
36273
36274 @noindent
36275 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
36276 @sc{gdb/mi} Output Syntax}).
36277
36278 In addition, it prints the name and size of the sections, as they are
36279 downloaded. These messages include the following fields:
36280
36281 @table @samp
36282 @item section
36283 The name of the section.
36284 @item section-size
36285 The size of the section.
36286 @item total-size
36287 The size of the overall executable to download.
36288 @end table
36289
36290 @noindent
36291 At the end, a summary is printed.
36292
36293 @subsubheading @value{GDBN} Command
36294
36295 The corresponding @value{GDBN} command is @samp{load}.
36296
36297 @subsubheading Example
36298
36299 Note: each status message appears on a single line. Here the messages
36300 have been broken down so that they can fit onto a page.
36301
36302 @smallexample
36303 (gdb)
36304 -target-download
36305 +download,@{section=".text",section-size="6668",total-size="9880"@}
36306 +download,@{section=".text",section-sent="512",section-size="6668",
36307 total-sent="512",total-size="9880"@}
36308 +download,@{section=".text",section-sent="1024",section-size="6668",
36309 total-sent="1024",total-size="9880"@}
36310 +download,@{section=".text",section-sent="1536",section-size="6668",
36311 total-sent="1536",total-size="9880"@}
36312 +download,@{section=".text",section-sent="2048",section-size="6668",
36313 total-sent="2048",total-size="9880"@}
36314 +download,@{section=".text",section-sent="2560",section-size="6668",
36315 total-sent="2560",total-size="9880"@}
36316 +download,@{section=".text",section-sent="3072",section-size="6668",
36317 total-sent="3072",total-size="9880"@}
36318 +download,@{section=".text",section-sent="3584",section-size="6668",
36319 total-sent="3584",total-size="9880"@}
36320 +download,@{section=".text",section-sent="4096",section-size="6668",
36321 total-sent="4096",total-size="9880"@}
36322 +download,@{section=".text",section-sent="4608",section-size="6668",
36323 total-sent="4608",total-size="9880"@}
36324 +download,@{section=".text",section-sent="5120",section-size="6668",
36325 total-sent="5120",total-size="9880"@}
36326 +download,@{section=".text",section-sent="5632",section-size="6668",
36327 total-sent="5632",total-size="9880"@}
36328 +download,@{section=".text",section-sent="6144",section-size="6668",
36329 total-sent="6144",total-size="9880"@}
36330 +download,@{section=".text",section-sent="6656",section-size="6668",
36331 total-sent="6656",total-size="9880"@}
36332 +download,@{section=".init",section-size="28",total-size="9880"@}
36333 +download,@{section=".fini",section-size="28",total-size="9880"@}
36334 +download,@{section=".data",section-size="3156",total-size="9880"@}
36335 +download,@{section=".data",section-sent="512",section-size="3156",
36336 total-sent="7236",total-size="9880"@}
36337 +download,@{section=".data",section-sent="1024",section-size="3156",
36338 total-sent="7748",total-size="9880"@}
36339 +download,@{section=".data",section-sent="1536",section-size="3156",
36340 total-sent="8260",total-size="9880"@}
36341 +download,@{section=".data",section-sent="2048",section-size="3156",
36342 total-sent="8772",total-size="9880"@}
36343 +download,@{section=".data",section-sent="2560",section-size="3156",
36344 total-sent="9284",total-size="9880"@}
36345 +download,@{section=".data",section-sent="3072",section-size="3156",
36346 total-sent="9796",total-size="9880"@}
36347 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
36348 write-rate="429"
36349 (gdb)
36350 @end smallexample
36351
36352
36353 @ignore
36354 @subheading The @code{-target-exec-status} Command
36355 @findex -target-exec-status
36356
36357 @subsubheading Synopsis
36358
36359 @smallexample
36360 -target-exec-status
36361 @end smallexample
36362
36363 Provide information on the state of the target (whether it is running or
36364 not, for instance).
36365
36366 @subsubheading @value{GDBN} Command
36367
36368 There's no equivalent @value{GDBN} command.
36369
36370 @subsubheading Example
36371 N.A.
36372
36373
36374 @subheading The @code{-target-list-available-targets} Command
36375 @findex -target-list-available-targets
36376
36377 @subsubheading Synopsis
36378
36379 @smallexample
36380 -target-list-available-targets
36381 @end smallexample
36382
36383 List the possible targets to connect to.
36384
36385 @subsubheading @value{GDBN} Command
36386
36387 The corresponding @value{GDBN} command is @samp{help target}.
36388
36389 @subsubheading Example
36390 N.A.
36391
36392
36393 @subheading The @code{-target-list-current-targets} Command
36394 @findex -target-list-current-targets
36395
36396 @subsubheading Synopsis
36397
36398 @smallexample
36399 -target-list-current-targets
36400 @end smallexample
36401
36402 Describe the current target.
36403
36404 @subsubheading @value{GDBN} Command
36405
36406 The corresponding information is printed by @samp{info file} (among
36407 other things).
36408
36409 @subsubheading Example
36410 N.A.
36411
36412
36413 @subheading The @code{-target-list-parameters} Command
36414 @findex -target-list-parameters
36415
36416 @subsubheading Synopsis
36417
36418 @smallexample
36419 -target-list-parameters
36420 @end smallexample
36421
36422 @c ????
36423 @end ignore
36424
36425 @subsubheading @value{GDBN} Command
36426
36427 No equivalent.
36428
36429 @subsubheading Example
36430 N.A.
36431
36432 @subheading The @code{-target-flash-erase} Command
36433 @findex -target-flash-erase
36434
36435 @subsubheading Synopsis
36436
36437 @smallexample
36438 -target-flash-erase
36439 @end smallexample
36440
36441 Erases all known flash memory regions on the target.
36442
36443 The corresponding @value{GDBN} command is @samp{flash-erase}.
36444
36445 The output is a list of flash regions that have been erased, with starting
36446 addresses and memory region sizes.
36447
36448 @smallexample
36449 (gdb)
36450 -target-flash-erase
36451 ^done,erased-regions=@{address="0x0",size="0x40000"@}
36452 (gdb)
36453 @end smallexample
36454
36455 @subheading The @code{-target-select} Command
36456 @findex -target-select
36457
36458 @subsubheading Synopsis
36459
36460 @smallexample
36461 -target-select @var{type} @var{parameters @dots{}}
36462 @end smallexample
36463
36464 Connect @value{GDBN} to the remote target. This command takes two args:
36465
36466 @table @samp
36467 @item @var{type}
36468 The type of target, for instance @samp{remote}, etc.
36469 @item @var{parameters}
36470 Device names, host names and the like. @xref{Target Commands, ,
36471 Commands for Managing Targets}, for more details.
36472 @end table
36473
36474 The output is a connection notification, followed by the address at
36475 which the target program is, in the following form:
36476
36477 @smallexample
36478 ^connected,addr="@var{address}",func="@var{function name}",
36479 args=[@var{arg list}]
36480 @end smallexample
36481
36482 @subsubheading @value{GDBN} Command
36483
36484 The corresponding @value{GDBN} command is @samp{target}.
36485
36486 @subsubheading Example
36487
36488 @smallexample
36489 (gdb)
36490 -target-select remote /dev/ttya
36491 ^connected,addr="0xfe00a300",func="??",args=[]
36492 (gdb)
36493 @end smallexample
36494
36495 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36496 @node GDB/MI File Transfer Commands
36497 @section @sc{gdb/mi} File Transfer Commands
36498
36499
36500 @subheading The @code{-target-file-put} Command
36501 @findex -target-file-put
36502
36503 @subsubheading Synopsis
36504
36505 @smallexample
36506 -target-file-put @var{hostfile} @var{targetfile}
36507 @end smallexample
36508
36509 Copy file @var{hostfile} from the host system (the machine running
36510 @value{GDBN}) to @var{targetfile} on the target system.
36511
36512 @subsubheading @value{GDBN} Command
36513
36514 The corresponding @value{GDBN} command is @samp{remote put}.
36515
36516 @subsubheading Example
36517
36518 @smallexample
36519 (gdb)
36520 -target-file-put localfile remotefile
36521 ^done
36522 (gdb)
36523 @end smallexample
36524
36525
36526 @subheading The @code{-target-file-get} Command
36527 @findex -target-file-get
36528
36529 @subsubheading Synopsis
36530
36531 @smallexample
36532 -target-file-get @var{targetfile} @var{hostfile}
36533 @end smallexample
36534
36535 Copy file @var{targetfile} from the target system to @var{hostfile}
36536 on the host system.
36537
36538 @subsubheading @value{GDBN} Command
36539
36540 The corresponding @value{GDBN} command is @samp{remote get}.
36541
36542 @subsubheading Example
36543
36544 @smallexample
36545 (gdb)
36546 -target-file-get remotefile localfile
36547 ^done
36548 (gdb)
36549 @end smallexample
36550
36551
36552 @subheading The @code{-target-file-delete} Command
36553 @findex -target-file-delete
36554
36555 @subsubheading Synopsis
36556
36557 @smallexample
36558 -target-file-delete @var{targetfile}
36559 @end smallexample
36560
36561 Delete @var{targetfile} from the target system.
36562
36563 @subsubheading @value{GDBN} Command
36564
36565 The corresponding @value{GDBN} command is @samp{remote delete}.
36566
36567 @subsubheading Example
36568
36569 @smallexample
36570 (gdb)
36571 -target-file-delete remotefile
36572 ^done
36573 (gdb)
36574 @end smallexample
36575
36576
36577 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36578 @node GDB/MI Ada Exceptions Commands
36579 @section Ada Exceptions @sc{gdb/mi} Commands
36580
36581 @subheading The @code{-info-ada-exceptions} Command
36582 @findex -info-ada-exceptions
36583
36584 @subsubheading Synopsis
36585
36586 @smallexample
36587 -info-ada-exceptions [ @var{regexp}]
36588 @end smallexample
36589
36590 List all Ada exceptions defined within the program being debugged.
36591 With a regular expression @var{regexp}, only those exceptions whose
36592 names match @var{regexp} are listed.
36593
36594 @subsubheading @value{GDBN} Command
36595
36596 The corresponding @value{GDBN} command is @samp{info exceptions}.
36597
36598 @subsubheading Result
36599
36600 The result is a table of Ada exceptions. The following columns are
36601 defined for each exception:
36602
36603 @table @samp
36604 @item name
36605 The name of the exception.
36606
36607 @item address
36608 The address of the exception.
36609
36610 @end table
36611
36612 @subsubheading Example
36613
36614 @smallexample
36615 -info-ada-exceptions aint
36616 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
36617 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
36618 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
36619 body=[@{name="constraint_error",address="0x0000000000613da0"@},
36620 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
36621 @end smallexample
36622
36623 @subheading Catching Ada Exceptions
36624
36625 The commands describing how to ask @value{GDBN} to stop when a program
36626 raises an exception are described at @ref{Ada Exception GDB/MI
36627 Catchpoint Commands}.
36628
36629
36630 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36631 @node GDB/MI Support Commands
36632 @section @sc{gdb/mi} Support Commands
36633
36634 Since new commands and features get regularly added to @sc{gdb/mi},
36635 some commands are available to help front-ends query the debugger
36636 about support for these capabilities. Similarly, it is also possible
36637 to query @value{GDBN} about target support of certain features.
36638
36639 @subheading The @code{-info-gdb-mi-command} Command
36640 @cindex @code{-info-gdb-mi-command}
36641 @findex -info-gdb-mi-command
36642
36643 @subsubheading Synopsis
36644
36645 @smallexample
36646 -info-gdb-mi-command @var{cmd_name}
36647 @end smallexample
36648
36649 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
36650
36651 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
36652 is technically not part of the command name (@pxref{GDB/MI Input
36653 Syntax}), and thus should be omitted in @var{cmd_name}. However,
36654 for ease of use, this command also accepts the form with the leading
36655 dash.
36656
36657 @subsubheading @value{GDBN} Command
36658
36659 There is no corresponding @value{GDBN} command.
36660
36661 @subsubheading Result
36662
36663 The result is a tuple. There is currently only one field:
36664
36665 @table @samp
36666 @item exists
36667 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
36668 @code{"false"} otherwise.
36669
36670 @end table
36671
36672 @subsubheading Example
36673
36674 Here is an example where the @sc{gdb/mi} command does not exist:
36675
36676 @smallexample
36677 -info-gdb-mi-command unsupported-command
36678 ^done,command=@{exists="false"@}
36679 @end smallexample
36680
36681 @noindent
36682 And here is an example where the @sc{gdb/mi} command is known
36683 to the debugger:
36684
36685 @smallexample
36686 -info-gdb-mi-command symbol-list-lines
36687 ^done,command=@{exists="true"@}
36688 @end smallexample
36689
36690 @subheading The @code{-list-features} Command
36691 @findex -list-features
36692 @cindex supported @sc{gdb/mi} features, list
36693
36694 Returns a list of particular features of the MI protocol that
36695 this version of gdb implements. A feature can be a command,
36696 or a new field in an output of some command, or even an
36697 important bugfix. While a frontend can sometimes detect presence
36698 of a feature at runtime, it is easier to perform detection at debugger
36699 startup.
36700
36701 The command returns a list of strings, with each string naming an
36702 available feature. Each returned string is just a name, it does not
36703 have any internal structure. The list of possible feature names
36704 is given below.
36705
36706 Example output:
36707
36708 @smallexample
36709 (gdb) -list-features
36710 ^done,result=["feature1","feature2"]
36711 @end smallexample
36712
36713 The current list of features is:
36714
36715 @ftable @samp
36716 @item frozen-varobjs
36717 Indicates support for the @code{-var-set-frozen} command, as well
36718 as possible presence of the @code{frozen} field in the output
36719 of @code{-varobj-create}.
36720 @item pending-breakpoints
36721 Indicates support for the @option{-f} option to the @code{-break-insert}
36722 command.
36723 @item python
36724 Indicates Python scripting support, Python-based
36725 pretty-printing commands, and possible presence of the
36726 @samp{display_hint} field in the output of @code{-var-list-children}
36727 @item thread-info
36728 Indicates support for the @code{-thread-info} command.
36729 @item data-read-memory-bytes
36730 Indicates support for the @code{-data-read-memory-bytes} and the
36731 @code{-data-write-memory-bytes} commands.
36732 @item breakpoint-notifications
36733 Indicates that changes to breakpoints and breakpoints created via the
36734 CLI will be announced via async records.
36735 @item ada-task-info
36736 Indicates support for the @code{-ada-task-info} command.
36737 @item language-option
36738 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36739 option (@pxref{Context management}).
36740 @item info-gdb-mi-command
36741 Indicates support for the @code{-info-gdb-mi-command} command.
36742 @item undefined-command-error-code
36743 Indicates support for the "undefined-command" error code in error result
36744 records, produced when trying to execute an undefined @sc{gdb/mi} command
36745 (@pxref{GDB/MI Result Records}).
36746 @item exec-run-start-option
36747 Indicates that the @code{-exec-run} command supports the @option{--start}
36748 option (@pxref{GDB/MI Program Execution}).
36749 @item data-disassemble-a-option
36750 Indicates that the @code{-data-disassemble} command supports the @option{-a}
36751 option (@pxref{GDB/MI Data Manipulation}).
36752 @end ftable
36753
36754 @subheading The @code{-list-target-features} Command
36755 @findex -list-target-features
36756
36757 Returns a list of particular features that are supported by the
36758 target. Those features affect the permitted MI commands, but
36759 unlike the features reported by the @code{-list-features} command, the
36760 features depend on which target GDB is using at the moment. Whenever
36761 a target can change, due to commands such as @code{-target-select},
36762 @code{-target-attach} or @code{-exec-run}, the list of target features
36763 may change, and the frontend should obtain it again.
36764 Example output:
36765
36766 @smallexample
36767 (gdb) -list-target-features
36768 ^done,result=["async"]
36769 @end smallexample
36770
36771 The current list of features is:
36772
36773 @table @samp
36774 @item async
36775 Indicates that the target is capable of asynchronous command
36776 execution, which means that @value{GDBN} will accept further commands
36777 while the target is running.
36778
36779 @item reverse
36780 Indicates that the target is capable of reverse execution.
36781 @xref{Reverse Execution}, for more information.
36782
36783 @end table
36784
36785 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36786 @node GDB/MI Miscellaneous Commands
36787 @section Miscellaneous @sc{gdb/mi} Commands
36788
36789 @c @subheading -gdb-complete
36790
36791 @subheading The @code{-gdb-exit} Command
36792 @findex -gdb-exit
36793
36794 @subsubheading Synopsis
36795
36796 @smallexample
36797 -gdb-exit
36798 @end smallexample
36799
36800 Exit @value{GDBN} immediately.
36801
36802 @subsubheading @value{GDBN} Command
36803
36804 Approximately corresponds to @samp{quit}.
36805
36806 @subsubheading Example
36807
36808 @smallexample
36809 (gdb)
36810 -gdb-exit
36811 ^exit
36812 @end smallexample
36813
36814
36815 @ignore
36816 @subheading The @code{-exec-abort} Command
36817 @findex -exec-abort
36818
36819 @subsubheading Synopsis
36820
36821 @smallexample
36822 -exec-abort
36823 @end smallexample
36824
36825 Kill the inferior running program.
36826
36827 @subsubheading @value{GDBN} Command
36828
36829 The corresponding @value{GDBN} command is @samp{kill}.
36830
36831 @subsubheading Example
36832 N.A.
36833 @end ignore
36834
36835
36836 @subheading The @code{-gdb-set} Command
36837 @findex -gdb-set
36838
36839 @subsubheading Synopsis
36840
36841 @smallexample
36842 -gdb-set
36843 @end smallexample
36844
36845 Set an internal @value{GDBN} variable.
36846 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36847
36848 @subsubheading @value{GDBN} Command
36849
36850 The corresponding @value{GDBN} command is @samp{set}.
36851
36852 @subsubheading Example
36853
36854 @smallexample
36855 (gdb)
36856 -gdb-set $foo=3
36857 ^done
36858 (gdb)
36859 @end smallexample
36860
36861
36862 @subheading The @code{-gdb-show} Command
36863 @findex -gdb-show
36864
36865 @subsubheading Synopsis
36866
36867 @smallexample
36868 -gdb-show
36869 @end smallexample
36870
36871 Show the current value of a @value{GDBN} variable.
36872
36873 @subsubheading @value{GDBN} Command
36874
36875 The corresponding @value{GDBN} command is @samp{show}.
36876
36877 @subsubheading Example
36878
36879 @smallexample
36880 (gdb)
36881 -gdb-show annotate
36882 ^done,value="0"
36883 (gdb)
36884 @end smallexample
36885
36886 @c @subheading -gdb-source
36887
36888
36889 @subheading The @code{-gdb-version} Command
36890 @findex -gdb-version
36891
36892 @subsubheading Synopsis
36893
36894 @smallexample
36895 -gdb-version
36896 @end smallexample
36897
36898 Show version information for @value{GDBN}. Used mostly in testing.
36899
36900 @subsubheading @value{GDBN} Command
36901
36902 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36903 default shows this information when you start an interactive session.
36904
36905 @subsubheading Example
36906
36907 @c This example modifies the actual output from GDB to avoid overfull
36908 @c box in TeX.
36909 @smallexample
36910 (gdb)
36911 -gdb-version
36912 ~GNU gdb 5.2.1
36913 ~Copyright 2000 Free Software Foundation, Inc.
36914 ~GDB is free software, covered by the GNU General Public License, and
36915 ~you are welcome to change it and/or distribute copies of it under
36916 ~ certain conditions.
36917 ~Type "show copying" to see the conditions.
36918 ~There is absolutely no warranty for GDB. Type "show warranty" for
36919 ~ details.
36920 ~This GDB was configured as
36921 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36922 ^done
36923 (gdb)
36924 @end smallexample
36925
36926 @subheading The @code{-list-thread-groups} Command
36927 @findex -list-thread-groups
36928
36929 @subheading Synopsis
36930
36931 @smallexample
36932 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
36933 @end smallexample
36934
36935 Lists thread groups (@pxref{Thread groups}). When a single thread
36936 group is passed as the argument, lists the children of that group.
36937 When several thread group are passed, lists information about those
36938 thread groups. Without any parameters, lists information about all
36939 top-level thread groups.
36940
36941 Normally, thread groups that are being debugged are reported.
36942 With the @samp{--available} option, @value{GDBN} reports thread groups
36943 available on the target.
36944
36945 The output of this command may have either a @samp{threads} result or
36946 a @samp{groups} result. The @samp{thread} result has a list of tuples
36947 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36948 Information}). The @samp{groups} result has a list of tuples as value,
36949 each tuple describing a thread group. If top-level groups are
36950 requested (that is, no parameter is passed), or when several groups
36951 are passed, the output always has a @samp{groups} result. The format
36952 of the @samp{group} result is described below.
36953
36954 To reduce the number of roundtrips it's possible to list thread groups
36955 together with their children, by passing the @samp{--recurse} option
36956 and the recursion depth. Presently, only recursion depth of 1 is
36957 permitted. If this option is present, then every reported thread group
36958 will also include its children, either as @samp{group} or
36959 @samp{threads} field.
36960
36961 In general, any combination of option and parameters is permitted, with
36962 the following caveats:
36963
36964 @itemize @bullet
36965 @item
36966 When a single thread group is passed, the output will typically
36967 be the @samp{threads} result. Because threads may not contain
36968 anything, the @samp{recurse} option will be ignored.
36969
36970 @item
36971 When the @samp{--available} option is passed, limited information may
36972 be available. In particular, the list of threads of a process might
36973 be inaccessible. Further, specifying specific thread groups might
36974 not give any performance advantage over listing all thread groups.
36975 The frontend should assume that @samp{-list-thread-groups --available}
36976 is always an expensive operation and cache the results.
36977
36978 @end itemize
36979
36980 The @samp{groups} result is a list of tuples, where each tuple may
36981 have the following fields:
36982
36983 @table @code
36984 @item id
36985 Identifier of the thread group. This field is always present.
36986 The identifier is an opaque string; frontends should not try to
36987 convert it to an integer, even though it might look like one.
36988
36989 @item type
36990 The type of the thread group. At present, only @samp{process} is a
36991 valid type.
36992
36993 @item pid
36994 The target-specific process identifier. This field is only present
36995 for thread groups of type @samp{process} and only if the process exists.
36996
36997 @item exit-code
36998 The exit code of this group's last exited thread, formatted in octal.
36999 This field is only present for thread groups of type @samp{process} and
37000 only if the process is not running.
37001
37002 @item num_children
37003 The number of children this thread group has. This field may be
37004 absent for an available thread group.
37005
37006 @item threads
37007 This field has a list of tuples as value, each tuple describing a
37008 thread. It may be present if the @samp{--recurse} option is
37009 specified, and it's actually possible to obtain the threads.
37010
37011 @item cores
37012 This field is a list of integers, each identifying a core that one
37013 thread of the group is running on. This field may be absent if
37014 such information is not available.
37015
37016 @item executable
37017 The name of the executable file that corresponds to this thread group.
37018 The field is only present for thread groups of type @samp{process},
37019 and only if there is a corresponding executable file.
37020
37021 @end table
37022
37023 @subheading Example
37024
37025 @smallexample
37026 (@value{GDBP})
37027 -list-thread-groups
37028 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
37029 -list-thread-groups 17
37030 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
37031 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
37032 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
37033 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
37034 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
37035 -list-thread-groups --available
37036 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
37037 -list-thread-groups --available --recurse 1
37038 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
37039 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
37040 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
37041 -list-thread-groups --available --recurse 1 17 18
37042 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
37043 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
37044 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
37045 @end smallexample
37046
37047 @subheading The @code{-info-os} Command
37048 @findex -info-os
37049
37050 @subsubheading Synopsis
37051
37052 @smallexample
37053 -info-os [ @var{type} ]
37054 @end smallexample
37055
37056 If no argument is supplied, the command returns a table of available
37057 operating-system-specific information types. If one of these types is
37058 supplied as an argument @var{type}, then the command returns a table
37059 of data of that type.
37060
37061 The types of information available depend on the target operating
37062 system.
37063
37064 @subsubheading @value{GDBN} Command
37065
37066 The corresponding @value{GDBN} command is @samp{info os}.
37067
37068 @subsubheading Example
37069
37070 When run on a @sc{gnu}/Linux system, the output will look something
37071 like this:
37072
37073 @smallexample
37074 (@value{GDBP})
37075 -info-os
37076 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
37077 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
37078 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
37079 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
37080 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
37081 col2="CPUs"@},
37082 item=@{col0="files",col1="Listing of all file descriptors",
37083 col2="File descriptors"@},
37084 item=@{col0="modules",col1="Listing of all loaded kernel modules",
37085 col2="Kernel modules"@},
37086 item=@{col0="msg",col1="Listing of all message queues",
37087 col2="Message queues"@},
37088 item=@{col0="processes",col1="Listing of all processes",
37089 col2="Processes"@},
37090 item=@{col0="procgroups",col1="Listing of all process groups",
37091 col2="Process groups"@},
37092 item=@{col0="semaphores",col1="Listing of all semaphores",
37093 col2="Semaphores"@},
37094 item=@{col0="shm",col1="Listing of all shared-memory regions",
37095 col2="Shared-memory regions"@},
37096 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
37097 col2="Sockets"@},
37098 item=@{col0="threads",col1="Listing of all threads",
37099 col2="Threads"@}]
37100 (@value{GDBP})
37101 -info-os processes
37102 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
37103 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
37104 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
37105 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
37106 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
37107 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
37108 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
37109 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
37110 ...
37111 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
37112 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
37113 (@value{GDBP})
37114 @end smallexample
37115
37116 (Note that the MI output here includes a @code{"Title"} column that
37117 does not appear in command-line @code{info os}; this column is useful
37118 for MI clients that want to enumerate the types of data, such as in a
37119 popup menu, but is needless clutter on the command line, and
37120 @code{info os} omits it.)
37121
37122 @subheading The @code{-add-inferior} Command
37123 @findex -add-inferior
37124
37125 @subheading Synopsis
37126
37127 @smallexample
37128 -add-inferior
37129 @end smallexample
37130
37131 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
37132 inferior is not associated with any executable. Such association may
37133 be established with the @samp{-file-exec-and-symbols} command
37134 (@pxref{GDB/MI File Commands}). The command response has a single
37135 field, @samp{inferior}, whose value is the identifier of the
37136 thread group corresponding to the new inferior.
37137
37138 @subheading Example
37139
37140 @smallexample
37141 (@value{GDBP})
37142 -add-inferior
37143 ^done,inferior="i3"
37144 @end smallexample
37145
37146 @subheading The @code{-interpreter-exec} Command
37147 @findex -interpreter-exec
37148
37149 @subheading Synopsis
37150
37151 @smallexample
37152 -interpreter-exec @var{interpreter} @var{command}
37153 @end smallexample
37154 @anchor{-interpreter-exec}
37155
37156 Execute the specified @var{command} in the given @var{interpreter}.
37157
37158 @subheading @value{GDBN} Command
37159
37160 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
37161
37162 @subheading Example
37163
37164 @smallexample
37165 (gdb)
37166 -interpreter-exec console "break main"
37167 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
37168 &"During symbol reading, bad structure-type format.\n"
37169 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
37170 ^done
37171 (gdb)
37172 @end smallexample
37173
37174 @subheading The @code{-inferior-tty-set} Command
37175 @findex -inferior-tty-set
37176
37177 @subheading Synopsis
37178
37179 @smallexample
37180 -inferior-tty-set /dev/pts/1
37181 @end smallexample
37182
37183 Set terminal for future runs of the program being debugged.
37184
37185 @subheading @value{GDBN} Command
37186
37187 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
37188
37189 @subheading Example
37190
37191 @smallexample
37192 (gdb)
37193 -inferior-tty-set /dev/pts/1
37194 ^done
37195 (gdb)
37196 @end smallexample
37197
37198 @subheading The @code{-inferior-tty-show} Command
37199 @findex -inferior-tty-show
37200
37201 @subheading Synopsis
37202
37203 @smallexample
37204 -inferior-tty-show
37205 @end smallexample
37206
37207 Show terminal for future runs of program being debugged.
37208
37209 @subheading @value{GDBN} Command
37210
37211 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
37212
37213 @subheading Example
37214
37215 @smallexample
37216 (gdb)
37217 -inferior-tty-set /dev/pts/1
37218 ^done
37219 (gdb)
37220 -inferior-tty-show
37221 ^done,inferior_tty_terminal="/dev/pts/1"
37222 (gdb)
37223 @end smallexample
37224
37225 @subheading The @code{-enable-timings} Command
37226 @findex -enable-timings
37227
37228 @subheading Synopsis
37229
37230 @smallexample
37231 -enable-timings [yes | no]
37232 @end smallexample
37233
37234 Toggle the printing of the wallclock, user and system times for an MI
37235 command as a field in its output. This command is to help frontend
37236 developers optimize the performance of their code. No argument is
37237 equivalent to @samp{yes}.
37238
37239 @subheading @value{GDBN} Command
37240
37241 No equivalent.
37242
37243 @subheading Example
37244
37245 @smallexample
37246 (gdb)
37247 -enable-timings
37248 ^done
37249 (gdb)
37250 -break-insert main
37251 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
37252 addr="0x080484ed",func="main",file="myprog.c",
37253 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
37254 times="0"@},
37255 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
37256 (gdb)
37257 -enable-timings no
37258 ^done
37259 (gdb)
37260 -exec-run
37261 ^running
37262 (gdb)
37263 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
37264 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
37265 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
37266 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
37267 (gdb)
37268 @end smallexample
37269
37270 @subheading The @code{-complete} Command
37271 @findex -complete
37272
37273 @subheading Synopsis
37274
37275 @smallexample
37276 -complete @var{command}
37277 @end smallexample
37278
37279 Show a list of completions for partially typed CLI @var{command}.
37280
37281 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
37282 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
37283 because @value{GDBN} is used remotely via a SSH connection.
37284
37285 @subheading Result
37286
37287 The result consists of two or three fields:
37288
37289 @table @samp
37290 @item completion
37291 This field contains the completed @var{command}. If @var{command}
37292 has no known completions, this field is omitted.
37293
37294 @item matches
37295 This field contains a (possibly empty) array of matches. It is always present.
37296
37297 @item max_completions_reached
37298 This field contains @code{1} if number of known completions is above
37299 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
37300 @code{0}. It is always present.
37301
37302 @end table
37303
37304 @subheading @value{GDBN} Command
37305
37306 The corresponding @value{GDBN} command is @samp{complete}.
37307
37308 @subheading Example
37309
37310 @smallexample
37311 (gdb)
37312 -complete br
37313 ^done,completion="break",
37314 matches=["break","break-range"],
37315 max_completions_reached="0"
37316 (gdb)
37317 -complete "b ma"
37318 ^done,completion="b ma",
37319 matches=["b madvise","b main"],max_completions_reached="0"
37320 (gdb)
37321 -complete "b push_b"
37322 ^done,completion="b push_back(",
37323 matches=[
37324 "b A::push_back(void*)",
37325 "b std::string::push_back(char)",
37326 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
37327 max_completions_reached="0"
37328 (gdb)
37329 -complete "nonexist"
37330 ^done,matches=[],max_completions_reached="0"
37331 (gdb)
37332
37333 @end smallexample
37334
37335 @node Annotations
37336 @chapter @value{GDBN} Annotations
37337
37338 This chapter describes annotations in @value{GDBN}. Annotations were
37339 designed to interface @value{GDBN} to graphical user interfaces or other
37340 similar programs which want to interact with @value{GDBN} at a
37341 relatively high level.
37342
37343 The annotation mechanism has largely been superseded by @sc{gdb/mi}
37344 (@pxref{GDB/MI}).
37345
37346 @ignore
37347 This is Edition @value{EDITION}, @value{DATE}.
37348 @end ignore
37349
37350 @menu
37351 * Annotations Overview:: What annotations are; the general syntax.
37352 * Server Prefix:: Issuing a command without affecting user state.
37353 * Prompting:: Annotations marking @value{GDBN}'s need for input.
37354 * Errors:: Annotations for error messages.
37355 * Invalidation:: Some annotations describe things now invalid.
37356 * Annotations for Running::
37357 Whether the program is running, how it stopped, etc.
37358 * Source Annotations:: Annotations describing source code.
37359 @end menu
37360
37361 @node Annotations Overview
37362 @section What is an Annotation?
37363 @cindex annotations
37364
37365 Annotations start with a newline character, two @samp{control-z}
37366 characters, and the name of the annotation. If there is no additional
37367 information associated with this annotation, the name of the annotation
37368 is followed immediately by a newline. If there is additional
37369 information, the name of the annotation is followed by a space, the
37370 additional information, and a newline. The additional information
37371 cannot contain newline characters.
37372
37373 Any output not beginning with a newline and two @samp{control-z}
37374 characters denotes literal output from @value{GDBN}. Currently there is
37375 no need for @value{GDBN} to output a newline followed by two
37376 @samp{control-z} characters, but if there was such a need, the
37377 annotations could be extended with an @samp{escape} annotation which
37378 means those three characters as output.
37379
37380 The annotation @var{level}, which is specified using the
37381 @option{--annotate} command line option (@pxref{Mode Options}), controls
37382 how much information @value{GDBN} prints together with its prompt,
37383 values of expressions, source lines, and other types of output. Level 0
37384 is for no annotations, level 1 is for use when @value{GDBN} is run as a
37385 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
37386 for programs that control @value{GDBN}, and level 2 annotations have
37387 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
37388 Interface, annotate, GDB's Obsolete Annotations}).
37389
37390 @table @code
37391 @kindex set annotate
37392 @item set annotate @var{level}
37393 The @value{GDBN} command @code{set annotate} sets the level of
37394 annotations to the specified @var{level}.
37395
37396 @item show annotate
37397 @kindex show annotate
37398 Show the current annotation level.
37399 @end table
37400
37401 This chapter describes level 3 annotations.
37402
37403 A simple example of starting up @value{GDBN} with annotations is:
37404
37405 @smallexample
37406 $ @kbd{gdb --annotate=3}
37407 GNU gdb 6.0
37408 Copyright 2003 Free Software Foundation, Inc.
37409 GDB is free software, covered by the GNU General Public License,
37410 and you are welcome to change it and/or distribute copies of it
37411 under certain conditions.
37412 Type "show copying" to see the conditions.
37413 There is absolutely no warranty for GDB. Type "show warranty"
37414 for details.
37415 This GDB was configured as "i386-pc-linux-gnu"
37416
37417 ^Z^Zpre-prompt
37418 (@value{GDBP})
37419 ^Z^Zprompt
37420 @kbd{quit}
37421
37422 ^Z^Zpost-prompt
37423 $
37424 @end smallexample
37425
37426 Here @samp{quit} is input to @value{GDBN}; the rest is output from
37427 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
37428 denotes a @samp{control-z} character) are annotations; the rest is
37429 output from @value{GDBN}.
37430
37431 @node Server Prefix
37432 @section The Server Prefix
37433 @cindex server prefix
37434
37435 If you prefix a command with @samp{server } then it will not affect
37436 the command history, nor will it affect @value{GDBN}'s notion of which
37437 command to repeat if @key{RET} is pressed on a line by itself. This
37438 means that commands can be run behind a user's back by a front-end in
37439 a transparent manner.
37440
37441 The @code{server } prefix does not affect the recording of values into
37442 the value history; to print a value without recording it into the
37443 value history, use the @code{output} command instead of the
37444 @code{print} command.
37445
37446 Using this prefix also disables confirmation requests
37447 (@pxref{confirmation requests}).
37448
37449 @node Prompting
37450 @section Annotation for @value{GDBN} Input
37451
37452 @cindex annotations for prompts
37453 When @value{GDBN} prompts for input, it annotates this fact so it is possible
37454 to know when to send output, when the output from a given command is
37455 over, etc.
37456
37457 Different kinds of input each have a different @dfn{input type}. Each
37458 input type has three annotations: a @code{pre-} annotation, which
37459 denotes the beginning of any prompt which is being output, a plain
37460 annotation, which denotes the end of the prompt, and then a @code{post-}
37461 annotation which denotes the end of any echo which may (or may not) be
37462 associated with the input. For example, the @code{prompt} input type
37463 features the following annotations:
37464
37465 @smallexample
37466 ^Z^Zpre-prompt
37467 ^Z^Zprompt
37468 ^Z^Zpost-prompt
37469 @end smallexample
37470
37471 The input types are
37472
37473 @table @code
37474 @findex pre-prompt annotation
37475 @findex prompt annotation
37476 @findex post-prompt annotation
37477 @item prompt
37478 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
37479
37480 @findex pre-commands annotation
37481 @findex commands annotation
37482 @findex post-commands annotation
37483 @item commands
37484 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
37485 command. The annotations are repeated for each command which is input.
37486
37487 @findex pre-overload-choice annotation
37488 @findex overload-choice annotation
37489 @findex post-overload-choice annotation
37490 @item overload-choice
37491 When @value{GDBN} wants the user to select between various overloaded functions.
37492
37493 @findex pre-query annotation
37494 @findex query annotation
37495 @findex post-query annotation
37496 @item query
37497 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
37498
37499 @findex pre-prompt-for-continue annotation
37500 @findex prompt-for-continue annotation
37501 @findex post-prompt-for-continue annotation
37502 @item prompt-for-continue
37503 When @value{GDBN} is asking the user to press return to continue. Note: Don't
37504 expect this to work well; instead use @code{set height 0} to disable
37505 prompting. This is because the counting of lines is buggy in the
37506 presence of annotations.
37507 @end table
37508
37509 @node Errors
37510 @section Errors
37511 @cindex annotations for errors, warnings and interrupts
37512
37513 @findex quit annotation
37514 @smallexample
37515 ^Z^Zquit
37516 @end smallexample
37517
37518 This annotation occurs right before @value{GDBN} responds to an interrupt.
37519
37520 @findex error annotation
37521 @smallexample
37522 ^Z^Zerror
37523 @end smallexample
37524
37525 This annotation occurs right before @value{GDBN} responds to an error.
37526
37527 Quit and error annotations indicate that any annotations which @value{GDBN} was
37528 in the middle of may end abruptly. For example, if a
37529 @code{value-history-begin} annotation is followed by a @code{error}, one
37530 cannot expect to receive the matching @code{value-history-end}. One
37531 cannot expect not to receive it either, however; an error annotation
37532 does not necessarily mean that @value{GDBN} is immediately returning all the way
37533 to the top level.
37534
37535 @findex error-begin annotation
37536 A quit or error annotation may be preceded by
37537
37538 @smallexample
37539 ^Z^Zerror-begin
37540 @end smallexample
37541
37542 Any output between that and the quit or error annotation is the error
37543 message.
37544
37545 Warning messages are not yet annotated.
37546 @c If we want to change that, need to fix warning(), type_error(),
37547 @c range_error(), and possibly other places.
37548
37549 @node Invalidation
37550 @section Invalidation Notices
37551
37552 @cindex annotations for invalidation messages
37553 The following annotations say that certain pieces of state may have
37554 changed.
37555
37556 @table @code
37557 @findex frames-invalid annotation
37558 @item ^Z^Zframes-invalid
37559
37560 The frames (for example, output from the @code{backtrace} command) may
37561 have changed.
37562
37563 @findex breakpoints-invalid annotation
37564 @item ^Z^Zbreakpoints-invalid
37565
37566 The breakpoints may have changed. For example, the user just added or
37567 deleted a breakpoint.
37568 @end table
37569
37570 @node Annotations for Running
37571 @section Running the Program
37572 @cindex annotations for running programs
37573
37574 @findex starting annotation
37575 @findex stopping annotation
37576 When the program starts executing due to a @value{GDBN} command such as
37577 @code{step} or @code{continue},
37578
37579 @smallexample
37580 ^Z^Zstarting
37581 @end smallexample
37582
37583 is output. When the program stops,
37584
37585 @smallexample
37586 ^Z^Zstopped
37587 @end smallexample
37588
37589 is output. Before the @code{stopped} annotation, a variety of
37590 annotations describe how the program stopped.
37591
37592 @table @code
37593 @findex exited annotation
37594 @item ^Z^Zexited @var{exit-status}
37595 The program exited, and @var{exit-status} is the exit status (zero for
37596 successful exit, otherwise nonzero).
37597
37598 @findex signalled annotation
37599 @findex signal-name annotation
37600 @findex signal-name-end annotation
37601 @findex signal-string annotation
37602 @findex signal-string-end annotation
37603 @item ^Z^Zsignalled
37604 The program exited with a signal. After the @code{^Z^Zsignalled}, the
37605 annotation continues:
37606
37607 @smallexample
37608 @var{intro-text}
37609 ^Z^Zsignal-name
37610 @var{name}
37611 ^Z^Zsignal-name-end
37612 @var{middle-text}
37613 ^Z^Zsignal-string
37614 @var{string}
37615 ^Z^Zsignal-string-end
37616 @var{end-text}
37617 @end smallexample
37618
37619 @noindent
37620 where @var{name} is the name of the signal, such as @code{SIGILL} or
37621 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
37622 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
37623 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
37624 user's benefit and have no particular format.
37625
37626 @findex signal annotation
37627 @item ^Z^Zsignal
37628 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
37629 just saying that the program received the signal, not that it was
37630 terminated with it.
37631
37632 @findex breakpoint annotation
37633 @item ^Z^Zbreakpoint @var{number}
37634 The program hit breakpoint number @var{number}.
37635
37636 @findex watchpoint annotation
37637 @item ^Z^Zwatchpoint @var{number}
37638 The program hit watchpoint number @var{number}.
37639 @end table
37640
37641 @node Source Annotations
37642 @section Displaying Source
37643 @cindex annotations for source display
37644
37645 @findex source annotation
37646 The following annotation is used instead of displaying source code:
37647
37648 @smallexample
37649 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
37650 @end smallexample
37651
37652 where @var{filename} is an absolute file name indicating which source
37653 file, @var{line} is the line number within that file (where 1 is the
37654 first line in the file), @var{character} is the character position
37655 within the file (where 0 is the first character in the file) (for most
37656 debug formats this will necessarily point to the beginning of a line),
37657 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
37658 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
37659 @var{addr} is the address in the target program associated with the
37660 source which is being displayed. The @var{addr} is in the form @samp{0x}
37661 followed by one or more lowercase hex digits (note that this does not
37662 depend on the language).
37663
37664 @node JIT Interface
37665 @chapter JIT Compilation Interface
37666 @cindex just-in-time compilation
37667 @cindex JIT compilation interface
37668
37669 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
37670 interface. A JIT compiler is a program or library that generates native
37671 executable code at runtime and executes it, usually in order to achieve good
37672 performance while maintaining platform independence.
37673
37674 Programs that use JIT compilation are normally difficult to debug because
37675 portions of their code are generated at runtime, instead of being loaded from
37676 object files, which is where @value{GDBN} normally finds the program's symbols
37677 and debug information. In order to debug programs that use JIT compilation,
37678 @value{GDBN} has an interface that allows the program to register in-memory
37679 symbol files with @value{GDBN} at runtime.
37680
37681 If you are using @value{GDBN} to debug a program that uses this interface, then
37682 it should work transparently so long as you have not stripped the binary. If
37683 you are developing a JIT compiler, then the interface is documented in the rest
37684 of this chapter. At this time, the only known client of this interface is the
37685 LLVM JIT.
37686
37687 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37688 JIT compiler communicates with @value{GDBN} by writing data into a global
37689 variable and calling a function at a well-known symbol. When @value{GDBN}
37690 attaches, it reads a linked list of symbol files from the global variable to
37691 find existing code, and puts a breakpoint in the function so that it can find
37692 out about additional code.
37693
37694 @menu
37695 * Declarations:: Relevant C struct declarations
37696 * Registering Code:: Steps to register code
37697 * Unregistering Code:: Steps to unregister code
37698 * Custom Debug Info:: Emit debug information in a custom format
37699 @end menu
37700
37701 @node Declarations
37702 @section JIT Declarations
37703
37704 These are the relevant struct declarations that a C program should include to
37705 implement the interface:
37706
37707 @smallexample
37708 typedef enum
37709 @{
37710 JIT_NOACTION = 0,
37711 JIT_REGISTER_FN,
37712 JIT_UNREGISTER_FN
37713 @} jit_actions_t;
37714
37715 struct jit_code_entry
37716 @{
37717 struct jit_code_entry *next_entry;
37718 struct jit_code_entry *prev_entry;
37719 const char *symfile_addr;
37720 uint64_t symfile_size;
37721 @};
37722
37723 struct jit_descriptor
37724 @{
37725 uint32_t version;
37726 /* This type should be jit_actions_t, but we use uint32_t
37727 to be explicit about the bitwidth. */
37728 uint32_t action_flag;
37729 struct jit_code_entry *relevant_entry;
37730 struct jit_code_entry *first_entry;
37731 @};
37732
37733 /* GDB puts a breakpoint in this function. */
37734 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37735
37736 /* Make sure to specify the version statically, because the
37737 debugger may check the version before we can set it. */
37738 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37739 @end smallexample
37740
37741 If the JIT is multi-threaded, then it is important that the JIT synchronize any
37742 modifications to this global data properly, which can easily be done by putting
37743 a global mutex around modifications to these structures.
37744
37745 @node Registering Code
37746 @section Registering Code
37747
37748 To register code with @value{GDBN}, the JIT should follow this protocol:
37749
37750 @itemize @bullet
37751 @item
37752 Generate an object file in memory with symbols and other desired debug
37753 information. The file must include the virtual addresses of the sections.
37754
37755 @item
37756 Create a code entry for the file, which gives the start and size of the symbol
37757 file.
37758
37759 @item
37760 Add it to the linked list in the JIT descriptor.
37761
37762 @item
37763 Point the relevant_entry field of the descriptor at the entry.
37764
37765 @item
37766 Set @code{action_flag} to @code{JIT_REGISTER} and call
37767 @code{__jit_debug_register_code}.
37768 @end itemize
37769
37770 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37771 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
37772 new code. However, the linked list must still be maintained in order to allow
37773 @value{GDBN} to attach to a running process and still find the symbol files.
37774
37775 @node Unregistering Code
37776 @section Unregistering Code
37777
37778 If code is freed, then the JIT should use the following protocol:
37779
37780 @itemize @bullet
37781 @item
37782 Remove the code entry corresponding to the code from the linked list.
37783
37784 @item
37785 Point the @code{relevant_entry} field of the descriptor at the code entry.
37786
37787 @item
37788 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37789 @code{__jit_debug_register_code}.
37790 @end itemize
37791
37792 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37793 and the JIT will leak the memory used for the associated symbol files.
37794
37795 @node Custom Debug Info
37796 @section Custom Debug Info
37797 @cindex custom JIT debug info
37798 @cindex JIT debug info reader
37799
37800 Generating debug information in platform-native file formats (like ELF
37801 or COFF) may be an overkill for JIT compilers; especially if all the
37802 debug info is used for is displaying a meaningful backtrace. The
37803 issue can be resolved by having the JIT writers decide on a debug info
37804 format and also provide a reader that parses the debug info generated
37805 by the JIT compiler. This section gives a brief overview on writing
37806 such a parser. More specific details can be found in the source file
37807 @file{gdb/jit-reader.in}, which is also installed as a header at
37808 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37809
37810 The reader is implemented as a shared object (so this functionality is
37811 not available on platforms which don't allow loading shared objects at
37812 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37813 @code{jit-reader-unload} are provided, to be used to load and unload
37814 the readers from a preconfigured directory. Once loaded, the shared
37815 object is used the parse the debug information emitted by the JIT
37816 compiler.
37817
37818 @menu
37819 * Using JIT Debug Info Readers:: How to use supplied readers correctly
37820 * Writing JIT Debug Info Readers:: Creating a debug-info reader
37821 @end menu
37822
37823 @node Using JIT Debug Info Readers
37824 @subsection Using JIT Debug Info Readers
37825 @kindex jit-reader-load
37826 @kindex jit-reader-unload
37827
37828 Readers can be loaded and unloaded using the @code{jit-reader-load}
37829 and @code{jit-reader-unload} commands.
37830
37831 @table @code
37832 @item jit-reader-load @var{reader}
37833 Load the JIT reader named @var{reader}, which is a shared
37834 object specified as either an absolute or a relative file name. In
37835 the latter case, @value{GDBN} will try to load the reader from a
37836 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37837 system (here @var{libdir} is the system library directory, often
37838 @file{/usr/local/lib}).
37839
37840 Only one reader can be active at a time; trying to load a second
37841 reader when one is already loaded will result in @value{GDBN}
37842 reporting an error. A new JIT reader can be loaded by first unloading
37843 the current one using @code{jit-reader-unload} and then invoking
37844 @code{jit-reader-load}.
37845
37846 @item jit-reader-unload
37847 Unload the currently loaded JIT reader.
37848
37849 @end table
37850
37851 @node Writing JIT Debug Info Readers
37852 @subsection Writing JIT Debug Info Readers
37853 @cindex writing JIT debug info readers
37854
37855 As mentioned, a reader is essentially a shared object conforming to a
37856 certain ABI. This ABI is described in @file{jit-reader.h}.
37857
37858 @file{jit-reader.h} defines the structures, macros and functions
37859 required to write a reader. It is installed (along with
37860 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37861 the system include directory.
37862
37863 Readers need to be released under a GPL compatible license. A reader
37864 can be declared as released under such a license by placing the macro
37865 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37866
37867 The entry point for readers is the symbol @code{gdb_init_reader},
37868 which is expected to be a function with the prototype
37869
37870 @findex gdb_init_reader
37871 @smallexample
37872 extern struct gdb_reader_funcs *gdb_init_reader (void);
37873 @end smallexample
37874
37875 @cindex @code{struct gdb_reader_funcs}
37876
37877 @code{struct gdb_reader_funcs} contains a set of pointers to callback
37878 functions. These functions are executed to read the debug info
37879 generated by the JIT compiler (@code{read}), to unwind stack frames
37880 (@code{unwind}) and to create canonical frame IDs
37881 (@code{get_frame_id}). It also has a callback that is called when the
37882 reader is being unloaded (@code{destroy}). The struct looks like this
37883
37884 @smallexample
37885 struct gdb_reader_funcs
37886 @{
37887 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37888 int reader_version;
37889
37890 /* For use by the reader. */
37891 void *priv_data;
37892
37893 gdb_read_debug_info *read;
37894 gdb_unwind_frame *unwind;
37895 gdb_get_frame_id *get_frame_id;
37896 gdb_destroy_reader *destroy;
37897 @};
37898 @end smallexample
37899
37900 @cindex @code{struct gdb_symbol_callbacks}
37901 @cindex @code{struct gdb_unwind_callbacks}
37902
37903 The callbacks are provided with another set of callbacks by
37904 @value{GDBN} to do their job. For @code{read}, these callbacks are
37905 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37906 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37907 @code{struct gdb_symbol_callbacks} has callbacks to create new object
37908 files and new symbol tables inside those object files. @code{struct
37909 gdb_unwind_callbacks} has callbacks to read registers off the current
37910 frame and to write out the values of the registers in the previous
37911 frame. Both have a callback (@code{target_read}) to read bytes off the
37912 target's address space.
37913
37914 @node In-Process Agent
37915 @chapter In-Process Agent
37916 @cindex debugging agent
37917 The traditional debugging model is conceptually low-speed, but works fine,
37918 because most bugs can be reproduced in debugging-mode execution. However,
37919 as multi-core or many-core processors are becoming mainstream, and
37920 multi-threaded programs become more and more popular, there should be more
37921 and more bugs that only manifest themselves at normal-mode execution, for
37922 example, thread races, because debugger's interference with the program's
37923 timing may conceal the bugs. On the other hand, in some applications,
37924 it is not feasible for the debugger to interrupt the program's execution
37925 long enough for the developer to learn anything helpful about its behavior.
37926 If the program's correctness depends on its real-time behavior, delays
37927 introduced by a debugger might cause the program to fail, even when the
37928 code itself is correct. It is useful to be able to observe the program's
37929 behavior without interrupting it.
37930
37931 Therefore, traditional debugging model is too intrusive to reproduce
37932 some bugs. In order to reduce the interference with the program, we can
37933 reduce the number of operations performed by debugger. The
37934 @dfn{In-Process Agent}, a shared library, is running within the same
37935 process with inferior, and is able to perform some debugging operations
37936 itself. As a result, debugger is only involved when necessary, and
37937 performance of debugging can be improved accordingly. Note that
37938 interference with program can be reduced but can't be removed completely,
37939 because the in-process agent will still stop or slow down the program.
37940
37941 The in-process agent can interpret and execute Agent Expressions
37942 (@pxref{Agent Expressions}) during performing debugging operations. The
37943 agent expressions can be used for different purposes, such as collecting
37944 data in tracepoints, and condition evaluation in breakpoints.
37945
37946 @anchor{Control Agent}
37947 You can control whether the in-process agent is used as an aid for
37948 debugging with the following commands:
37949
37950 @table @code
37951 @kindex set agent on
37952 @item set agent on
37953 Causes the in-process agent to perform some operations on behalf of the
37954 debugger. Just which operations requested by the user will be done
37955 by the in-process agent depends on the its capabilities. For example,
37956 if you request to evaluate breakpoint conditions in the in-process agent,
37957 and the in-process agent has such capability as well, then breakpoint
37958 conditions will be evaluated in the in-process agent.
37959
37960 @kindex set agent off
37961 @item set agent off
37962 Disables execution of debugging operations by the in-process agent. All
37963 of the operations will be performed by @value{GDBN}.
37964
37965 @kindex show agent
37966 @item show agent
37967 Display the current setting of execution of debugging operations by
37968 the in-process agent.
37969 @end table
37970
37971 @menu
37972 * In-Process Agent Protocol::
37973 @end menu
37974
37975 @node In-Process Agent Protocol
37976 @section In-Process Agent Protocol
37977 @cindex in-process agent protocol
37978
37979 The in-process agent is able to communicate with both @value{GDBN} and
37980 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37981 used for communications between @value{GDBN} or GDBserver and the IPA.
37982 In general, @value{GDBN} or GDBserver sends commands
37983 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37984 in-process agent replies back with the return result of the command, or
37985 some other information. The data sent to in-process agent is composed
37986 of primitive data types, such as 4-byte or 8-byte type, and composite
37987 types, which are called objects (@pxref{IPA Protocol Objects}).
37988
37989 @menu
37990 * IPA Protocol Objects::
37991 * IPA Protocol Commands::
37992 @end menu
37993
37994 @node IPA Protocol Objects
37995 @subsection IPA Protocol Objects
37996 @cindex ipa protocol objects
37997
37998 The commands sent to and results received from agent may contain some
37999 complex data types called @dfn{objects}.
38000
38001 The in-process agent is running on the same machine with @value{GDBN}
38002 or GDBserver, so it doesn't have to handle as much differences between
38003 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
38004 However, there are still some differences of two ends in two processes:
38005
38006 @enumerate
38007 @item
38008 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
38009 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
38010 @item
38011 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
38012 GDBserver is compiled with one, and in-process agent is compiled with
38013 the other one.
38014 @end enumerate
38015
38016 Here are the IPA Protocol Objects:
38017
38018 @enumerate
38019 @item
38020 agent expression object. It represents an agent expression
38021 (@pxref{Agent Expressions}).
38022 @anchor{agent expression object}
38023 @item
38024 tracepoint action object. It represents a tracepoint action
38025 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
38026 memory, static trace data and to evaluate expression.
38027 @anchor{tracepoint action object}
38028 @item
38029 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
38030 @anchor{tracepoint object}
38031
38032 @end enumerate
38033
38034 The following table describes important attributes of each IPA protocol
38035 object:
38036
38037 @multitable @columnfractions .30 .20 .50
38038 @headitem Name @tab Size @tab Description
38039 @item @emph{agent expression object} @tab @tab
38040 @item length @tab 4 @tab length of bytes code
38041 @item byte code @tab @var{length} @tab contents of byte code
38042 @item @emph{tracepoint action for collecting memory} @tab @tab
38043 @item 'M' @tab 1 @tab type of tracepoint action
38044 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
38045 address of the lowest byte to collect, otherwise @var{addr} is the offset
38046 of @var{basereg} for memory collecting.
38047 @item len @tab 8 @tab length of memory for collecting
38048 @item basereg @tab 4 @tab the register number containing the starting
38049 memory address for collecting.
38050 @item @emph{tracepoint action for collecting registers} @tab @tab
38051 @item 'R' @tab 1 @tab type of tracepoint action
38052 @item @emph{tracepoint action for collecting static trace data} @tab @tab
38053 @item 'L' @tab 1 @tab type of tracepoint action
38054 @item @emph{tracepoint action for expression evaluation} @tab @tab
38055 @item 'X' @tab 1 @tab type of tracepoint action
38056 @item agent expression @tab length of @tab @ref{agent expression object}
38057 @item @emph{tracepoint object} @tab @tab
38058 @item number @tab 4 @tab number of tracepoint
38059 @item address @tab 8 @tab address of tracepoint inserted on
38060 @item type @tab 4 @tab type of tracepoint
38061 @item enabled @tab 1 @tab enable or disable of tracepoint
38062 @item step_count @tab 8 @tab step
38063 @item pass_count @tab 8 @tab pass
38064 @item numactions @tab 4 @tab number of tracepoint actions
38065 @item hit count @tab 8 @tab hit count
38066 @item trace frame usage @tab 8 @tab trace frame usage
38067 @item compiled_cond @tab 8 @tab compiled condition
38068 @item orig_size @tab 8 @tab orig size
38069 @item condition @tab 4 if condition is NULL otherwise length of
38070 @ref{agent expression object}
38071 @tab zero if condition is NULL, otherwise is
38072 @ref{agent expression object}
38073 @item actions @tab variable
38074 @tab numactions number of @ref{tracepoint action object}
38075 @end multitable
38076
38077 @node IPA Protocol Commands
38078 @subsection IPA Protocol Commands
38079 @cindex ipa protocol commands
38080
38081 The spaces in each command are delimiters to ease reading this commands
38082 specification. They don't exist in real commands.
38083
38084 @table @samp
38085
38086 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
38087 Installs a new fast tracepoint described by @var{tracepoint_object}
38088 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
38089 head of @dfn{jumppad}, which is used to jump to data collection routine
38090 in IPA finally.
38091
38092 Replies:
38093 @table @samp
38094 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
38095 @var{target_address} is address of tracepoint in the inferior.
38096 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
38097 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
38098 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
38099 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
38100 @item E @var{NN}
38101 for an error
38102
38103 @end table
38104
38105 @item close
38106 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
38107 is about to kill inferiors.
38108
38109 @item qTfSTM
38110 @xref{qTfSTM}.
38111 @item qTsSTM
38112 @xref{qTsSTM}.
38113 @item qTSTMat
38114 @xref{qTSTMat}.
38115 @item probe_marker_at:@var{address}
38116 Asks in-process agent to probe the marker at @var{address}.
38117
38118 Replies:
38119 @table @samp
38120 @item E @var{NN}
38121 for an error
38122 @end table
38123 @item unprobe_marker_at:@var{address}
38124 Asks in-process agent to unprobe the marker at @var{address}.
38125 @end table
38126
38127 @node GDB Bugs
38128 @chapter Reporting Bugs in @value{GDBN}
38129 @cindex bugs in @value{GDBN}
38130 @cindex reporting bugs in @value{GDBN}
38131
38132 Your bug reports play an essential role in making @value{GDBN} reliable.
38133
38134 Reporting a bug may help you by bringing a solution to your problem, or it
38135 may not. But in any case the principal function of a bug report is to help
38136 the entire community by making the next version of @value{GDBN} work better. Bug
38137 reports are your contribution to the maintenance of @value{GDBN}.
38138
38139 In order for a bug report to serve its purpose, you must include the
38140 information that enables us to fix the bug.
38141
38142 @menu
38143 * Bug Criteria:: Have you found a bug?
38144 * Bug Reporting:: How to report bugs
38145 @end menu
38146
38147 @node Bug Criteria
38148 @section Have You Found a Bug?
38149 @cindex bug criteria
38150
38151 If you are not sure whether you have found a bug, here are some guidelines:
38152
38153 @itemize @bullet
38154 @cindex fatal signal
38155 @cindex debugger crash
38156 @cindex crash of debugger
38157 @item
38158 If the debugger gets a fatal signal, for any input whatever, that is a
38159 @value{GDBN} bug. Reliable debuggers never crash.
38160
38161 @cindex error on valid input
38162 @item
38163 If @value{GDBN} produces an error message for valid input, that is a
38164 bug. (Note that if you're cross debugging, the problem may also be
38165 somewhere in the connection to the target.)
38166
38167 @cindex invalid input
38168 @item
38169 If @value{GDBN} does not produce an error message for invalid input,
38170 that is a bug. However, you should note that your idea of
38171 ``invalid input'' might be our idea of ``an extension'' or ``support
38172 for traditional practice''.
38173
38174 @item
38175 If you are an experienced user of debugging tools, your suggestions
38176 for improvement of @value{GDBN} are welcome in any case.
38177 @end itemize
38178
38179 @node Bug Reporting
38180 @section How to Report Bugs
38181 @cindex bug reports
38182 @cindex @value{GDBN} bugs, reporting
38183
38184 A number of companies and individuals offer support for @sc{gnu} products.
38185 If you obtained @value{GDBN} from a support organization, we recommend you
38186 contact that organization first.
38187
38188 You can find contact information for many support companies and
38189 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
38190 distribution.
38191 @c should add a web page ref...
38192
38193 @ifset BUGURL
38194 @ifset BUGURL_DEFAULT
38195 In any event, we also recommend that you submit bug reports for
38196 @value{GDBN}. The preferred method is to submit them directly using
38197 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
38198 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
38199 be used.
38200
38201 @strong{Do not send bug reports to @samp{info-gdb}, or to
38202 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
38203 not want to receive bug reports. Those that do have arranged to receive
38204 @samp{bug-gdb}.
38205
38206 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
38207 serves as a repeater. The mailing list and the newsgroup carry exactly
38208 the same messages. Often people think of posting bug reports to the
38209 newsgroup instead of mailing them. This appears to work, but it has one
38210 problem which can be crucial: a newsgroup posting often lacks a mail
38211 path back to the sender. Thus, if we need to ask for more information,
38212 we may be unable to reach you. For this reason, it is better to send
38213 bug reports to the mailing list.
38214 @end ifset
38215 @ifclear BUGURL_DEFAULT
38216 In any event, we also recommend that you submit bug reports for
38217 @value{GDBN} to @value{BUGURL}.
38218 @end ifclear
38219 @end ifset
38220
38221 The fundamental principle of reporting bugs usefully is this:
38222 @strong{report all the facts}. If you are not sure whether to state a
38223 fact or leave it out, state it!
38224
38225 Often people omit facts because they think they know what causes the
38226 problem and assume that some details do not matter. Thus, you might
38227 assume that the name of the variable you use in an example does not matter.
38228 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
38229 stray memory reference which happens to fetch from the location where that
38230 name is stored in memory; perhaps, if the name were different, the contents
38231 of that location would fool the debugger into doing the right thing despite
38232 the bug. Play it safe and give a specific, complete example. That is the
38233 easiest thing for you to do, and the most helpful.
38234
38235 Keep in mind that the purpose of a bug report is to enable us to fix the
38236 bug. It may be that the bug has been reported previously, but neither
38237 you nor we can know that unless your bug report is complete and
38238 self-contained.
38239
38240 Sometimes people give a few sketchy facts and ask, ``Does this ring a
38241 bell?'' Those bug reports are useless, and we urge everyone to
38242 @emph{refuse to respond to them} except to chide the sender to report
38243 bugs properly.
38244
38245 To enable us to fix the bug, you should include all these things:
38246
38247 @itemize @bullet
38248 @item
38249 The version of @value{GDBN}. @value{GDBN} announces it if you start
38250 with no arguments; you can also print it at any time using @code{show
38251 version}.
38252
38253 Without this, we will not know whether there is any point in looking for
38254 the bug in the current version of @value{GDBN}.
38255
38256 @item
38257 The type of machine you are using, and the operating system name and
38258 version number.
38259
38260 @item
38261 The details of the @value{GDBN} build-time configuration.
38262 @value{GDBN} shows these details if you invoke it with the
38263 @option{--configuration} command-line option, or if you type
38264 @code{show configuration} at @value{GDBN}'s prompt.
38265
38266 @item
38267 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
38268 ``@value{GCC}--2.8.1''.
38269
38270 @item
38271 What compiler (and its version) was used to compile the program you are
38272 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
38273 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
38274 to get this information; for other compilers, see the documentation for
38275 those compilers.
38276
38277 @item
38278 The command arguments you gave the compiler to compile your example and
38279 observe the bug. For example, did you use @samp{-O}? To guarantee
38280 you will not omit something important, list them all. A copy of the
38281 Makefile (or the output from make) is sufficient.
38282
38283 If we were to try to guess the arguments, we would probably guess wrong
38284 and then we might not encounter the bug.
38285
38286 @item
38287 A complete input script, and all necessary source files, that will
38288 reproduce the bug.
38289
38290 @item
38291 A description of what behavior you observe that you believe is
38292 incorrect. For example, ``It gets a fatal signal.''
38293
38294 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
38295 will certainly notice it. But if the bug is incorrect output, we might
38296 not notice unless it is glaringly wrong. You might as well not give us
38297 a chance to make a mistake.
38298
38299 Even if the problem you experience is a fatal signal, you should still
38300 say so explicitly. Suppose something strange is going on, such as, your
38301 copy of @value{GDBN} is out of synch, or you have encountered a bug in
38302 the C library on your system. (This has happened!) Your copy might
38303 crash and ours would not. If you told us to expect a crash, then when
38304 ours fails to crash, we would know that the bug was not happening for
38305 us. If you had not told us to expect a crash, then we would not be able
38306 to draw any conclusion from our observations.
38307
38308 @pindex script
38309 @cindex recording a session script
38310 To collect all this information, you can use a session recording program
38311 such as @command{script}, which is available on many Unix systems.
38312 Just run your @value{GDBN} session inside @command{script} and then
38313 include the @file{typescript} file with your bug report.
38314
38315 Another way to record a @value{GDBN} session is to run @value{GDBN}
38316 inside Emacs and then save the entire buffer to a file.
38317
38318 @item
38319 If you wish to suggest changes to the @value{GDBN} source, send us context
38320 diffs. If you even discuss something in the @value{GDBN} source, refer to
38321 it by context, not by line number.
38322
38323 The line numbers in our development sources will not match those in your
38324 sources. Your line numbers would convey no useful information to us.
38325
38326 @end itemize
38327
38328 Here are some things that are not necessary:
38329
38330 @itemize @bullet
38331 @item
38332 A description of the envelope of the bug.
38333
38334 Often people who encounter a bug spend a lot of time investigating
38335 which changes to the input file will make the bug go away and which
38336 changes will not affect it.
38337
38338 This is often time consuming and not very useful, because the way we
38339 will find the bug is by running a single example under the debugger
38340 with breakpoints, not by pure deduction from a series of examples.
38341 We recommend that you save your time for something else.
38342
38343 Of course, if you can find a simpler example to report @emph{instead}
38344 of the original one, that is a convenience for us. Errors in the
38345 output will be easier to spot, running under the debugger will take
38346 less time, and so on.
38347
38348 However, simplification is not vital; if you do not want to do this,
38349 report the bug anyway and send us the entire test case you used.
38350
38351 @item
38352 A patch for the bug.
38353
38354 A patch for the bug does help us if it is a good one. But do not omit
38355 the necessary information, such as the test case, on the assumption that
38356 a patch is all we need. We might see problems with your patch and decide
38357 to fix the problem another way, or we might not understand it at all.
38358
38359 Sometimes with a program as complicated as @value{GDBN} it is very hard to
38360 construct an example that will make the program follow a certain path
38361 through the code. If you do not send us the example, we will not be able
38362 to construct one, so we will not be able to verify that the bug is fixed.
38363
38364 And if we cannot understand what bug you are trying to fix, or why your
38365 patch should be an improvement, we will not install it. A test case will
38366 help us to understand.
38367
38368 @item
38369 A guess about what the bug is or what it depends on.
38370
38371 Such guesses are usually wrong. Even we cannot guess right about such
38372 things without first using the debugger to find the facts.
38373 @end itemize
38374
38375 @c The readline documentation is distributed with the readline code
38376 @c and consists of the two following files:
38377 @c rluser.texi
38378 @c hsuser.texi
38379 @c Use -I with makeinfo to point to the appropriate directory,
38380 @c environment var TEXINPUTS with TeX.
38381 @ifclear SYSTEM_READLINE
38382 @include rluser.texi
38383 @include hsuser.texi
38384 @end ifclear
38385
38386 @node In Memoriam
38387 @appendix In Memoriam
38388
38389 The @value{GDBN} project mourns the loss of the following long-time
38390 contributors:
38391
38392 @table @code
38393 @item Fred Fish
38394 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
38395 to Free Software in general. Outside of @value{GDBN}, he was known in
38396 the Amiga world for his series of Fish Disks, and the GeekGadget project.
38397
38398 @item Michael Snyder
38399 Michael was one of the Global Maintainers of the @value{GDBN} project,
38400 with contributions recorded as early as 1996, until 2011. In addition
38401 to his day to day participation, he was a large driving force behind
38402 adding Reverse Debugging to @value{GDBN}.
38403 @end table
38404
38405 Beyond their technical contributions to the project, they were also
38406 enjoyable members of the Free Software Community. We will miss them.
38407
38408 @node Formatting Documentation
38409 @appendix Formatting Documentation
38410
38411 @cindex @value{GDBN} reference card
38412 @cindex reference card
38413 The @value{GDBN} 4 release includes an already-formatted reference card, ready
38414 for printing with PostScript or Ghostscript, in the @file{gdb}
38415 subdirectory of the main source directory@footnote{In
38416 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
38417 release.}. If you can use PostScript or Ghostscript with your printer,
38418 you can print the reference card immediately with @file{refcard.ps}.
38419
38420 The release also includes the source for the reference card. You
38421 can format it, using @TeX{}, by typing:
38422
38423 @smallexample
38424 make refcard.dvi
38425 @end smallexample
38426
38427 The @value{GDBN} reference card is designed to print in @dfn{landscape}
38428 mode on US ``letter'' size paper;
38429 that is, on a sheet 11 inches wide by 8.5 inches
38430 high. You will need to specify this form of printing as an option to
38431 your @sc{dvi} output program.
38432
38433 @cindex documentation
38434
38435 All the documentation for @value{GDBN} comes as part of the machine-readable
38436 distribution. The documentation is written in Texinfo format, which is
38437 a documentation system that uses a single source file to produce both
38438 on-line information and a printed manual. You can use one of the Info
38439 formatting commands to create the on-line version of the documentation
38440 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
38441
38442 @value{GDBN} includes an already formatted copy of the on-line Info
38443 version of this manual in the @file{gdb} subdirectory. The main Info
38444 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
38445 subordinate files matching @samp{gdb.info*} in the same directory. If
38446 necessary, you can print out these files, or read them with any editor;
38447 but they are easier to read using the @code{info} subsystem in @sc{gnu}
38448 Emacs or the standalone @code{info} program, available as part of the
38449 @sc{gnu} Texinfo distribution.
38450
38451 If you want to format these Info files yourself, you need one of the
38452 Info formatting programs, such as @code{texinfo-format-buffer} or
38453 @code{makeinfo}.
38454
38455 If you have @code{makeinfo} installed, and are in the top level
38456 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
38457 version @value{GDBVN}), you can make the Info file by typing:
38458
38459 @smallexample
38460 cd gdb
38461 make gdb.info
38462 @end smallexample
38463
38464 If you want to typeset and print copies of this manual, you need @TeX{},
38465 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
38466 Texinfo definitions file.
38467
38468 @TeX{} is a typesetting program; it does not print files directly, but
38469 produces output files called @sc{dvi} files. To print a typeset
38470 document, you need a program to print @sc{dvi} files. If your system
38471 has @TeX{} installed, chances are it has such a program. The precise
38472 command to use depends on your system; @kbd{lpr -d} is common; another
38473 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
38474 require a file name without any extension or a @samp{.dvi} extension.
38475
38476 @TeX{} also requires a macro definitions file called
38477 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
38478 written in Texinfo format. On its own, @TeX{} cannot either read or
38479 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
38480 and is located in the @file{gdb-@var{version-number}/texinfo}
38481 directory.
38482
38483 If you have @TeX{} and a @sc{dvi} printer program installed, you can
38484 typeset and print this manual. First switch to the @file{gdb}
38485 subdirectory of the main source directory (for example, to
38486 @file{gdb-@value{GDBVN}/gdb}) and type:
38487
38488 @smallexample
38489 make gdb.dvi
38490 @end smallexample
38491
38492 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
38493
38494 @node Installing GDB
38495 @appendix Installing @value{GDBN}
38496 @cindex installation
38497
38498 @menu
38499 * Requirements:: Requirements for building @value{GDBN}
38500 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
38501 * Separate Objdir:: Compiling @value{GDBN} in another directory
38502 * Config Names:: Specifying names for hosts and targets
38503 * Configure Options:: Summary of options for configure
38504 * System-wide configuration:: Having a system-wide init file
38505 @end menu
38506
38507 @node Requirements
38508 @section Requirements for Building @value{GDBN}
38509 @cindex building @value{GDBN}, requirements for
38510
38511 Building @value{GDBN} requires various tools and packages to be available.
38512 Other packages will be used only if they are found.
38513
38514 @heading Tools/Packages Necessary for Building @value{GDBN}
38515 @table @asis
38516 @item C@t{++}11 compiler
38517 @value{GDBN} is written in C@t{++}11. It should be buildable with any
38518 recent C@t{++}11 compiler, e.g.@: GCC.
38519
38520 @item GNU make
38521 @value{GDBN}'s build system relies on features only found in the GNU
38522 make program. Other variants of @code{make} will not work.
38523
38524 @item GMP (The GNU Multiple Precision Arithmetic Library)
38525 @value{GDBN} now uses GMP to perform some of its arithmetics.
38526 This library may be included with your operating system distribution;
38527 if it is not, you can get the latest version from
38528 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
38529 you can use the @option{--with-libgmp-prefix} option to specify
38530 its location.
38531
38532 @end table
38533
38534 @heading Tools/Packages Optional for Building @value{GDBN}
38535 @table @asis
38536 @item Expat
38537 @anchor{Expat}
38538 @value{GDBN} can use the Expat XML parsing library. This library may be
38539 included with your operating system distribution; if it is not, you
38540 can get the latest version from @url{http://expat.sourceforge.net}.
38541 The @file{configure} script will search for this library in several
38542 standard locations; if it is installed in an unusual path, you can
38543 use the @option{--with-libexpat-prefix} option to specify its location.
38544
38545 Expat is used for:
38546
38547 @itemize @bullet
38548 @item
38549 Remote protocol memory maps (@pxref{Memory Map Format})
38550 @item
38551 Target descriptions (@pxref{Target Descriptions})
38552 @item
38553 Remote shared library lists (@xref{Library List Format},
38554 or alternatively @pxref{Library List Format for SVR4 Targets})
38555 @item
38556 MS-Windows shared libraries (@pxref{Shared Libraries})
38557 @item
38558 Traceframe info (@pxref{Traceframe Info Format})
38559 @item
38560 Branch trace (@pxref{Branch Trace Format},
38561 @pxref{Branch Trace Configuration Format})
38562 @end itemize
38563
38564 @item Guile
38565 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
38566 default, @value{GDBN} will be compiled if the Guile libraries are
38567 installed and are found by @file{configure}. You can use the
38568 @code{--with-guile} option to request Guile, and pass either the Guile
38569 version number or the file name of the relevant @code{pkg-config}
38570 program to choose a particular version of Guile.
38571
38572 @item iconv
38573 @value{GDBN}'s features related to character sets (@pxref{Character
38574 Sets}) require a functioning @code{iconv} implementation. If you are
38575 on a GNU system, then this is provided by the GNU C Library. Some
38576 other systems also provide a working @code{iconv}.
38577
38578 If @value{GDBN} is using the @code{iconv} program which is installed
38579 in a non-standard place, you will need to tell @value{GDBN} where to
38580 find it. This is done with @option{--with-iconv-bin} which specifies
38581 the directory that contains the @code{iconv} program. This program is
38582 run in order to make a list of the available character sets.
38583
38584 On systems without @code{iconv}, you can install GNU Libiconv. If
38585 Libiconv is installed in a standard place, @value{GDBN} will
38586 automatically use it if it is needed. If you have previously
38587 installed Libiconv in a non-standard place, you can use the
38588 @option{--with-libiconv-prefix} option to @file{configure}.
38589
38590 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
38591 arrange to build Libiconv if a directory named @file{libiconv} appears
38592 in the top-most source directory. If Libiconv is built this way, and
38593 if the operating system does not provide a suitable @code{iconv}
38594 implementation, then the just-built library will automatically be used
38595 by @value{GDBN}. One easy way to set this up is to download GNU
38596 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
38597 source tree, and then rename the directory holding the Libiconv source
38598 code to @samp{libiconv}.
38599
38600 @item lzma
38601 @value{GDBN} can support debugging sections that are compressed with
38602 the LZMA library. @xref{MiniDebugInfo}. If this library is not
38603 included with your operating system, you can find it in the xz package
38604 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
38605 the usual place, then the @file{configure} script will use it
38606 automatically. If it is installed in an unusual path, you can use the
38607 @option{--with-lzma-prefix} option to specify its location.
38608
38609 @item MPFR
38610 @anchor{MPFR}
38611 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
38612 library. This library may be included with your operating system
38613 distribution; if it is not, you can get the latest version from
38614 @url{http://www.mpfr.org}. The @file{configure} script will search
38615 for this library in several standard locations; if it is installed
38616 in an unusual path, you can use the @option{--with-libmpfr-prefix}
38617 option to specify its location.
38618
38619 GNU MPFR is used to emulate target floating-point arithmetic during
38620 expression evaluation when the target uses different floating-point
38621 formats than the host. If GNU MPFR it is not available, @value{GDBN}
38622 will fall back to using host floating-point arithmetic.
38623
38624 @item Python
38625 @value{GDBN} can be scripted using Python language. @xref{Python}.
38626 By default, @value{GDBN} will be compiled if the Python libraries are
38627 installed and are found by @file{configure}. You can use the
38628 @code{--with-python} option to request Python, and pass either the
38629 file name of the relevant @code{python} executable, or the name of the
38630 directory in which Python is installed, to choose a particular
38631 installation of Python.
38632
38633 @item zlib
38634 @cindex compressed debug sections
38635 @value{GDBN} will use the @samp{zlib} library, if available, to read
38636 compressed debug sections. Some linkers, such as GNU gold, are capable
38637 of producing binaries with compressed debug sections. If @value{GDBN}
38638 is compiled with @samp{zlib}, it will be able to read the debug
38639 information in such binaries.
38640
38641 The @samp{zlib} library is likely included with your operating system
38642 distribution; if it is not, you can get the latest version from
38643 @url{http://zlib.net}.
38644 @end table
38645
38646 @node Running Configure
38647 @section Invoking the @value{GDBN} @file{configure} Script
38648 @cindex configuring @value{GDBN}
38649 @value{GDBN} comes with a @file{configure} script that automates the process
38650 of preparing @value{GDBN} for installation; you can then use @code{make} to
38651 build the @code{gdb} program.
38652 @iftex
38653 @c irrelevant in info file; it's as current as the code it lives with.
38654 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
38655 look at the @file{README} file in the sources; we may have improved the
38656 installation procedures since publishing this manual.}
38657 @end iftex
38658
38659 The @value{GDBN} distribution includes all the source code you need for
38660 @value{GDBN} in a single directory, whose name is usually composed by
38661 appending the version number to @samp{gdb}.
38662
38663 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
38664 @file{gdb-@value{GDBVN}} directory. That directory contains:
38665
38666 @table @code
38667 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
38668 script for configuring @value{GDBN} and all its supporting libraries
38669
38670 @item gdb-@value{GDBVN}/gdb
38671 the source specific to @value{GDBN} itself
38672
38673 @item gdb-@value{GDBVN}/bfd
38674 source for the Binary File Descriptor library
38675
38676 @item gdb-@value{GDBVN}/include
38677 @sc{gnu} include files
38678
38679 @item gdb-@value{GDBVN}/libiberty
38680 source for the @samp{-liberty} free software library
38681
38682 @item gdb-@value{GDBVN}/opcodes
38683 source for the library of opcode tables and disassemblers
38684
38685 @item gdb-@value{GDBVN}/readline
38686 source for the @sc{gnu} command-line interface
38687 @end table
38688
38689 There may be other subdirectories as well.
38690
38691 The simplest way to configure and build @value{GDBN} is to run @file{configure}
38692 from the @file{gdb-@var{version-number}} source directory, which in
38693 this example is the @file{gdb-@value{GDBVN}} directory.
38694
38695 First switch to the @file{gdb-@var{version-number}} source directory
38696 if you are not already in it; then run @file{configure}. Pass the
38697 identifier for the platform on which @value{GDBN} will run as an
38698 argument.
38699
38700 For example:
38701
38702 @smallexample
38703 cd gdb-@value{GDBVN}
38704 ./configure
38705 make
38706 @end smallexample
38707
38708 Running @samp{configure} and then running @code{make} builds the
38709 included supporting libraries, then @code{gdb} itself. The configured
38710 source files, and the binaries, are left in the corresponding source
38711 directories.
38712
38713 @need 750
38714 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
38715 system does not recognize this automatically when you run a different
38716 shell, you may need to run @code{sh} on it explicitly:
38717
38718 @smallexample
38719 sh configure
38720 @end smallexample
38721
38722 You should run the @file{configure} script from the top directory in the
38723 source tree, the @file{gdb-@var{version-number}} directory. If you run
38724 @file{configure} from one of the subdirectories, you will configure only
38725 that subdirectory. That is usually not what you want. In particular,
38726 if you run the first @file{configure} from the @file{gdb} subdirectory
38727 of the @file{gdb-@var{version-number}} directory, you will omit the
38728 configuration of @file{bfd}, @file{readline}, and other sibling
38729 directories of the @file{gdb} subdirectory. This leads to build errors
38730 about missing include files such as @file{bfd/bfd.h}.
38731
38732 You can install @code{@value{GDBN}} anywhere. The best way to do this
38733 is to pass the @code{--prefix} option to @code{configure}, and then
38734 install it with @code{make install}.
38735
38736 @node Separate Objdir
38737 @section Compiling @value{GDBN} in Another Directory
38738
38739 If you want to run @value{GDBN} versions for several host or target machines,
38740 you need a different @code{gdb} compiled for each combination of
38741 host and target. @file{configure} is designed to make this easy by
38742 allowing you to generate each configuration in a separate subdirectory,
38743 rather than in the source directory. If your @code{make} program
38744 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38745 @code{make} in each of these directories builds the @code{gdb}
38746 program specified there.
38747
38748 To build @code{gdb} in a separate directory, run @file{configure}
38749 with the @samp{--srcdir} option to specify where to find the source.
38750 (You also need to specify a path to find @file{configure}
38751 itself from your working directory. If the path to @file{configure}
38752 would be the same as the argument to @samp{--srcdir}, you can leave out
38753 the @samp{--srcdir} option; it is assumed.)
38754
38755 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38756 separate directory for a Sun 4 like this:
38757
38758 @smallexample
38759 @group
38760 cd gdb-@value{GDBVN}
38761 mkdir ../gdb-sun4
38762 cd ../gdb-sun4
38763 ../gdb-@value{GDBVN}/configure
38764 make
38765 @end group
38766 @end smallexample
38767
38768 When @file{configure} builds a configuration using a remote source
38769 directory, it creates a tree for the binaries with the same structure
38770 (and using the same names) as the tree under the source directory. In
38771 the example, you'd find the Sun 4 library @file{libiberty.a} in the
38772 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38773 @file{gdb-sun4/gdb}.
38774
38775 Make sure that your path to the @file{configure} script has just one
38776 instance of @file{gdb} in it. If your path to @file{configure} looks
38777 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38778 one subdirectory of @value{GDBN}, not the whole package. This leads to
38779 build errors about missing include files such as @file{bfd/bfd.h}.
38780
38781 One popular reason to build several @value{GDBN} configurations in separate
38782 directories is to configure @value{GDBN} for cross-compiling (where
38783 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
38784 programs that run on another machine---the @dfn{target}).
38785 You specify a cross-debugging target by
38786 giving the @samp{--target=@var{target}} option to @file{configure}.
38787
38788 When you run @code{make} to build a program or library, you must run
38789 it in a configured directory---whatever directory you were in when you
38790 called @file{configure} (or one of its subdirectories).
38791
38792 The @code{Makefile} that @file{configure} generates in each source
38793 directory also runs recursively. If you type @code{make} in a source
38794 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38795 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38796 will build all the required libraries, and then build GDB.
38797
38798 When you have multiple hosts or targets configured in separate
38799 directories, you can run @code{make} on them in parallel (for example,
38800 if they are NFS-mounted on each of the hosts); they will not interfere
38801 with each other.
38802
38803 @node Config Names
38804 @section Specifying Names for Hosts and Targets
38805
38806 The specifications used for hosts and targets in the @file{configure}
38807 script are based on a three-part naming scheme, but some short predefined
38808 aliases are also supported. The full naming scheme encodes three pieces
38809 of information in the following pattern:
38810
38811 @smallexample
38812 @var{architecture}-@var{vendor}-@var{os}
38813 @end smallexample
38814
38815 For example, you can use the alias @code{sun4} as a @var{host} argument,
38816 or as the value for @var{target} in a @code{--target=@var{target}}
38817 option. The equivalent full name is @samp{sparc-sun-sunos4}.
38818
38819 The @file{configure} script accompanying @value{GDBN} does not provide
38820 any query facility to list all supported host and target names or
38821 aliases. @file{configure} calls the Bourne shell script
38822 @code{config.sub} to map abbreviations to full names; you can read the
38823 script, if you wish, or you can use it to test your guesses on
38824 abbreviations---for example:
38825
38826 @smallexample
38827 % sh config.sub i386-linux
38828 i386-pc-linux-gnu
38829 % sh config.sub alpha-linux
38830 alpha-unknown-linux-gnu
38831 % sh config.sub hp9k700
38832 hppa1.1-hp-hpux
38833 % sh config.sub sun4
38834 sparc-sun-sunos4.1.1
38835 % sh config.sub sun3
38836 m68k-sun-sunos4.1.1
38837 % sh config.sub i986v
38838 Invalid configuration `i986v': machine `i986v' not recognized
38839 @end smallexample
38840
38841 @noindent
38842 @code{config.sub} is also distributed in the @value{GDBN} source
38843 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
38844
38845 @node Configure Options
38846 @section @file{configure} Options
38847
38848 Here is a summary of the @file{configure} options and arguments that
38849 are most often useful for building @value{GDBN}. @file{configure}
38850 also has several other options not listed here. @xref{Running
38851 configure Scripts,,,autoconf}, for a full
38852 explanation of @file{configure}.
38853
38854 @smallexample
38855 configure @r{[}--help@r{]}
38856 @r{[}--prefix=@var{dir}@r{]}
38857 @r{[}--exec-prefix=@var{dir}@r{]}
38858 @r{[}--srcdir=@var{dirname}@r{]}
38859 @r{[}--target=@var{target}@r{]}
38860 @end smallexample
38861
38862 @noindent
38863 You may introduce options with a single @samp{-} rather than
38864 @samp{--} if you prefer; but you may abbreviate option names if you use
38865 @samp{--}.
38866
38867 @table @code
38868 @item --help
38869 Display a quick summary of how to invoke @file{configure}.
38870
38871 @item --prefix=@var{dir}
38872 Configure the source to install programs and files under directory
38873 @file{@var{dir}}.
38874
38875 @item --exec-prefix=@var{dir}
38876 Configure the source to install programs under directory
38877 @file{@var{dir}}.
38878
38879 @c avoid splitting the warning from the explanation:
38880 @need 2000
38881 @item --srcdir=@var{dirname}
38882 Use this option to make configurations in directories separate from the
38883 @value{GDBN} source directories. Among other things, you can use this to
38884 build (or maintain) several configurations simultaneously, in separate
38885 directories. @file{configure} writes configuration-specific files in
38886 the current directory, but arranges for them to use the source in the
38887 directory @var{dirname}. @file{configure} creates directories under
38888 the working directory in parallel to the source directories below
38889 @var{dirname}.
38890
38891 @item --target=@var{target}
38892 Configure @value{GDBN} for cross-debugging programs running on the specified
38893 @var{target}. Without this option, @value{GDBN} is configured to debug
38894 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
38895
38896 There is no convenient way to generate a list of all available
38897 targets. Also see the @code{--enable-targets} option, below.
38898 @end table
38899
38900 There are many other options that are specific to @value{GDBN}. This
38901 lists just the most common ones; there are some very specialized
38902 options not described here.
38903
38904 @table @code
38905 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38906 @itemx --enable-targets=all
38907 Configure @value{GDBN} for cross-debugging programs running on the
38908 specified list of targets. The special value @samp{all} configures
38909 @value{GDBN} for debugging programs running on any target it supports.
38910
38911 @item --with-gdb-datadir=@var{path}
38912 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38913 here for certain supporting files or scripts. This defaults to the
38914 @file{gdb} subdirectory of @samp{datadir} (which can be set using
38915 @code{--datadir}).
38916
38917 @item --with-relocated-sources=@var{dir}
38918 Sets up the default source path substitution rule so that directory
38919 names recorded in debug information will be automatically adjusted for
38920 any directory under @var{dir}. @var{dir} should be a subdirectory of
38921 @value{GDBN}'s configured prefix, the one mentioned in the
38922 @code{--prefix} or @code{--exec-prefix} options to configure. This
38923 option is useful if GDB is supposed to be moved to a different place
38924 after it is built.
38925
38926 @item --enable-64-bit-bfd
38927 Enable 64-bit support in BFD on 32-bit hosts.
38928
38929 @item --disable-gdbmi
38930 Build @value{GDBN} without the GDB/MI machine interface
38931 (@pxref{GDB/MI}).
38932
38933 @item --enable-tui
38934 Build @value{GDBN} with the text-mode full-screen user interface
38935 (TUI). Requires a curses library (ncurses and cursesX are also
38936 supported).
38937
38938 @item --with-curses
38939 Use the curses library instead of the termcap library, for text-mode
38940 terminal operations.
38941
38942 @item --with-debuginfod
38943 Build @value{GDBN} with @file{libdebuginfod}, the @code{debuginfod} client
38944 library. Used to automatically fetch ELF, DWARF and source files from
38945 @code{debuginfod} servers using build IDs associated with any missing
38946 files. Enabled by default if @file{libdebuginfod} is installed and found
38947 at configure time. For more information regarding @code{debuginfod} see
38948 @ref{Debuginfod}.
38949
38950 @item --with-libunwind-ia64
38951 Use the libunwind library for unwinding function call stack on ia64
38952 target platforms. See http://www.nongnu.org/libunwind/index.html for
38953 details.
38954
38955 @item --with-system-readline
38956 Use the readline library installed on the host, rather than the
38957 library supplied as part of @value{GDBN}. Readline 7 or newer is
38958 required; this is enforced by the build system.
38959
38960 @item --with-system-zlib
38961 Use the zlib library installed on the host, rather than the library
38962 supplied as part of @value{GDBN}.
38963
38964 @item --with-expat
38965 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38966 default if libexpat is installed and found at configure time.) This
38967 library is used to read XML files supplied with @value{GDBN}. If it
38968 is unavailable, some features, such as remote protocol memory maps,
38969 target descriptions, and shared library lists, that are based on XML
38970 files, will not be available in @value{GDBN}. If your host does not
38971 have libexpat installed, you can get the latest version from
38972 `http://expat.sourceforge.net'.
38973
38974 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38975
38976 Build @value{GDBN} with GNU libiconv, a character set encoding
38977 conversion library. This is not done by default, as on GNU systems
38978 the @code{iconv} that is built in to the C library is sufficient. If
38979 your host does not have a working @code{iconv}, you can get the latest
38980 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38981
38982 @value{GDBN}'s build system also supports building GNU libiconv as
38983 part of the overall build. @xref{Requirements}.
38984
38985 @item --with-lzma
38986 Build @value{GDBN} with LZMA, a compression library. (Done by default
38987 if liblzma is installed and found at configure time.) LZMA is used by
38988 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
38989 platforms using the ELF object file format. If your host does not
38990 have liblzma installed, you can get the latest version from
38991 `https://tukaani.org/xz/'.
38992
38993 @item --with-mpfr
38994 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38995 floating-point computation with correct rounding. (Done by default if
38996 GNU MPFR is installed and found at configure time.) This library is
38997 used to emulate target floating-point arithmetic during expression
38998 evaluation when the target uses different floating-point formats than
38999 the host. If GNU MPFR is not available, @value{GDBN} will fall back
39000 to using host floating-point arithmetic. If your host does not have
39001 GNU MPFR installed, you can get the latest version from
39002 `http://www.mpfr.org'.
39003
39004 @item --with-python@r{[}=@var{python}@r{]}
39005 Build @value{GDBN} with Python scripting support. (Done by default if
39006 libpython is present and found at configure time.) Python makes
39007 @value{GDBN} scripting much more powerful than the restricted CLI
39008 scripting language. If your host does not have Python installed, you
39009 can find it on `http://www.python.org/download/'. The oldest version
39010 of Python supported by GDB is 2.6. The optional argument @var{python}
39011 is used to find the Python headers and libraries. It can be either
39012 the name of a Python executable, or the name of the directory in which
39013 Python is installed.
39014
39015 @item --with-guile[=GUILE]'
39016 Build @value{GDBN} with GNU Guile scripting support. (Done by default
39017 if libguile is present and found at configure time.) If your host
39018 does not have Guile installed, you can find it at
39019 `https://www.gnu.org/software/guile/'. The optional argument GUILE
39020 can be a version number, which will cause @code{configure} to try to
39021 use that version of Guile; or the file name of a @code{pkg-config}
39022 executable, which will be queried to find the information needed to
39023 compile and link against Guile.
39024
39025 @item --without-included-regex
39026 Don't use the regex library included with @value{GDBN} (as part of the
39027 libiberty library). This is the default on hosts with version 2 of
39028 the GNU C library.
39029
39030 @item --with-sysroot=@var{dir}
39031 Use @var{dir} as the default system root directory for libraries whose
39032 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
39033 @var{dir} can be modified at run time by using the @command{set
39034 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
39035 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
39036 default system root will be automatically adjusted if and when
39037 @value{GDBN} is moved to a different location.
39038
39039 @item --with-system-gdbinit=@var{file}
39040 Configure @value{GDBN} to automatically load a system-wide init file.
39041 @var{file} should be an absolute file name. If @var{file} is in a
39042 directory under the configured prefix, and @value{GDBN} is moved to
39043 another location after being built, the location of the system-wide
39044 init file will be adjusted accordingly.
39045
39046 @item --with-system-gdbinit-dir=@var{directory}
39047 Configure @value{GDBN} to automatically load init files from a
39048 system-wide directory. @var{directory} should be an absolute directory
39049 name. If @var{directory} is in a directory under the configured
39050 prefix, and @value{GDBN} is moved to another location after being
39051 built, the location of the system-wide init directory will be
39052 adjusted accordingly.
39053
39054 @item --enable-build-warnings
39055 When building the @value{GDBN} sources, ask the compiler to warn about
39056 any code which looks even vaguely suspicious. It passes many
39057 different warning flags, depending on the exact version of the
39058 compiler you are using.
39059
39060 @item --enable-werror
39061 Treat compiler warnings as errors. It adds the @code{-Werror} flag
39062 to the compiler, which will fail the compilation if the compiler
39063 outputs any warning messages.
39064
39065 @item --enable-ubsan
39066 Enable the GCC undefined behavior sanitizer. This is disabled by
39067 default, but passing @code{--enable-ubsan=yes} or
39068 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
39069 undefined behavior sanitizer checks for C@t{++} undefined behavior.
39070 It has a performance cost, so if you are looking at @value{GDBN}'s
39071 performance, you should disable it. The undefined behavior sanitizer
39072 was first introduced in GCC 4.9.
39073 @end table
39074
39075 @node System-wide configuration
39076 @section System-wide configuration and settings
39077 @cindex system-wide init file
39078
39079 @value{GDBN} can be configured to have a system-wide init file and a
39080 system-wide init file directory; this file and files in that directory
39081 (if they have a recognized file extension) will be read and executed at
39082 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
39083
39084 Here are the corresponding configure options:
39085
39086 @table @code
39087 @item --with-system-gdbinit=@var{file}
39088 Specify that the default location of the system-wide init file is
39089 @var{file}.
39090 @item --with-system-gdbinit-dir=@var{directory}
39091 Specify that the default location of the system-wide init file directory
39092 is @var{directory}.
39093 @end table
39094
39095 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
39096 they may be subject to relocation. Two possible cases:
39097
39098 @itemize @bullet
39099 @item
39100 If the default location of this init file/directory contains @file{$prefix},
39101 it will be subject to relocation. Suppose that the configure options
39102 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
39103 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
39104 init file is looked for as @file{$install/etc/gdbinit} instead of
39105 @file{$prefix/etc/gdbinit}.
39106
39107 @item
39108 By contrast, if the default location does not contain the prefix,
39109 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
39110 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
39111 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
39112 wherever @value{GDBN} is installed.
39113 @end itemize
39114
39115 If the configured location of the system-wide init file (as given by the
39116 @option{--with-system-gdbinit} option at configure time) is in the
39117 data-directory (as specified by @option{--with-gdb-datadir} at configure
39118 time) or in one of its subdirectories, then @value{GDBN} will look for the
39119 system-wide init file in the directory specified by the
39120 @option{--data-directory} command-line option.
39121 Note that the system-wide init file is only read once, during @value{GDBN}
39122 initialization. If the data-directory is changed after @value{GDBN} has
39123 started with the @code{set data-directory} command, the file will not be
39124 reread.
39125
39126 This applies similarly to the system-wide directory specified in
39127 @option{--with-system-gdbinit-dir}.
39128
39129 Any supported scripting language can be used for these init files, as long
39130 as the file extension matches the scripting language. To be interpreted
39131 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
39132 extension.
39133
39134 @menu
39135 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
39136 @end menu
39137
39138 @node System-wide Configuration Scripts
39139 @subsection Installed System-wide Configuration Scripts
39140 @cindex system-wide configuration scripts
39141
39142 The @file{system-gdbinit} directory, located inside the data-directory
39143 (as specified by @option{--with-gdb-datadir} at configure time) contains
39144 a number of scripts which can be used as system-wide init files. To
39145 automatically source those scripts at startup, @value{GDBN} should be
39146 configured with @option{--with-system-gdbinit}. Otherwise, any user
39147 should be able to source them by hand as needed.
39148
39149 The following scripts are currently available:
39150 @itemize @bullet
39151
39152 @item @file{elinos.py}
39153 @pindex elinos.py
39154 @cindex ELinOS system-wide configuration script
39155 This script is useful when debugging a program on an ELinOS target.
39156 It takes advantage of the environment variables defined in a standard
39157 ELinOS environment in order to determine the location of the system
39158 shared libraries, and then sets the @samp{solib-absolute-prefix}
39159 and @samp{solib-search-path} variables appropriately.
39160
39161 @item @file{wrs-linux.py}
39162 @pindex wrs-linux.py
39163 @cindex Wind River Linux system-wide configuration script
39164 This script is useful when debugging a program on a target running
39165 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
39166 the host-side sysroot used by the target system.
39167
39168 @end itemize
39169
39170 @node Maintenance Commands
39171 @appendix Maintenance Commands
39172 @cindex maintenance commands
39173 @cindex internal commands
39174
39175 In addition to commands intended for @value{GDBN} users, @value{GDBN}
39176 includes a number of commands intended for @value{GDBN} developers,
39177 that are not documented elsewhere in this manual. These commands are
39178 provided here for reference. (For commands that turn on debugging
39179 messages, see @ref{Debugging Output}.)
39180
39181 @table @code
39182 @kindex maint agent
39183 @kindex maint agent-eval
39184 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
39185 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
39186 Translate the given @var{expression} into remote agent bytecodes.
39187 This command is useful for debugging the Agent Expression mechanism
39188 (@pxref{Agent Expressions}). The @samp{agent} version produces an
39189 expression useful for data collection, such as by tracepoints, while
39190 @samp{maint agent-eval} produces an expression that evaluates directly
39191 to a result. For instance, a collection expression for @code{globa +
39192 globb} will include bytecodes to record four bytes of memory at each
39193 of the addresses of @code{globa} and @code{globb}, while discarding
39194 the result of the addition, while an evaluation expression will do the
39195 addition and return the sum.
39196 If @code{-at} is given, generate remote agent bytecode for @var{location}.
39197 If not, generate remote agent bytecode for current frame PC address.
39198
39199 @kindex maint agent-printf
39200 @item maint agent-printf @var{format},@var{expr},...
39201 Translate the given format string and list of argument expressions
39202 into remote agent bytecodes and display them as a disassembled list.
39203 This command is useful for debugging the agent version of dynamic
39204 printf (@pxref{Dynamic Printf}).
39205
39206 @kindex maint info breakpoints
39207 @item @anchor{maint info breakpoints}maint info breakpoints
39208 Using the same format as @samp{info breakpoints}, display both the
39209 breakpoints you've set explicitly, and those @value{GDBN} is using for
39210 internal purposes. Internal breakpoints are shown with negative
39211 breakpoint numbers. The type column identifies what kind of breakpoint
39212 is shown:
39213
39214 @table @code
39215 @item breakpoint
39216 Normal, explicitly set breakpoint.
39217
39218 @item watchpoint
39219 Normal, explicitly set watchpoint.
39220
39221 @item longjmp
39222 Internal breakpoint, used to handle correctly stepping through
39223 @code{longjmp} calls.
39224
39225 @item longjmp resume
39226 Internal breakpoint at the target of a @code{longjmp}.
39227
39228 @item until
39229 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
39230
39231 @item finish
39232 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
39233
39234 @item shlib events
39235 Shared library events.
39236
39237 @end table
39238
39239 @kindex maint info btrace
39240 @item maint info btrace
39241 Pint information about raw branch tracing data.
39242
39243 @kindex maint btrace packet-history
39244 @item maint btrace packet-history
39245 Print the raw branch trace packets that are used to compute the
39246 execution history for the @samp{record btrace} command. Both the
39247 information and the format in which it is printed depend on the btrace
39248 recording format.
39249
39250 @table @code
39251 @item bts
39252 For the BTS recording format, print a list of blocks of sequential
39253 code. For each block, the following information is printed:
39254
39255 @table @asis
39256 @item Block number
39257 Newer blocks have higher numbers. The oldest block has number zero.
39258 @item Lowest @samp{PC}
39259 @item Highest @samp{PC}
39260 @end table
39261
39262 @item pt
39263 For the Intel Processor Trace recording format, print a list of
39264 Intel Processor Trace packets. For each packet, the following
39265 information is printed:
39266
39267 @table @asis
39268 @item Packet number
39269 Newer packets have higher numbers. The oldest packet has number zero.
39270 @item Trace offset
39271 The packet's offset in the trace stream.
39272 @item Packet opcode and payload
39273 @end table
39274 @end table
39275
39276 @kindex maint btrace clear-packet-history
39277 @item maint btrace clear-packet-history
39278 Discards the cached packet history printed by the @samp{maint btrace
39279 packet-history} command. The history will be computed again when
39280 needed.
39281
39282 @kindex maint btrace clear
39283 @item maint btrace clear
39284 Discard the branch trace data. The data will be fetched anew and the
39285 branch trace will be recomputed when needed.
39286
39287 This implicitly truncates the branch trace to a single branch trace
39288 buffer. When updating branch trace incrementally, the branch trace
39289 available to @value{GDBN} may be bigger than a single branch trace
39290 buffer.
39291
39292 @kindex maint set btrace pt skip-pad
39293 @item maint set btrace pt skip-pad
39294 @kindex maint show btrace pt skip-pad
39295 @item maint show btrace pt skip-pad
39296 Control whether @value{GDBN} will skip PAD packets when computing the
39297 packet history.
39298
39299 @kindex maint info jit
39300 @item maint info jit
39301 Print information about JIT code objects loaded in the current inferior.
39302
39303 @kindex set displaced-stepping
39304 @kindex show displaced-stepping
39305 @cindex displaced stepping support
39306 @cindex out-of-line single-stepping
39307 @item set displaced-stepping
39308 @itemx show displaced-stepping
39309 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
39310 if the target supports it. Displaced stepping is a way to single-step
39311 over breakpoints without removing them from the inferior, by executing
39312 an out-of-line copy of the instruction that was originally at the
39313 breakpoint location. It is also known as out-of-line single-stepping.
39314
39315 @table @code
39316 @item set displaced-stepping on
39317 If the target architecture supports it, @value{GDBN} will use
39318 displaced stepping to step over breakpoints.
39319
39320 @item set displaced-stepping off
39321 @value{GDBN} will not use displaced stepping to step over breakpoints,
39322 even if such is supported by the target architecture.
39323
39324 @cindex non-stop mode, and @samp{set displaced-stepping}
39325 @item set displaced-stepping auto
39326 This is the default mode. @value{GDBN} will use displaced stepping
39327 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
39328 architecture supports displaced stepping.
39329 @end table
39330
39331 @kindex maint check-psymtabs
39332 @item maint check-psymtabs
39333 Check the consistency of currently expanded psymtabs versus symtabs.
39334 Use this to check, for example, whether a symbol is in one but not the other.
39335
39336 @kindex maint check-symtabs
39337 @item maint check-symtabs
39338 Check the consistency of currently expanded symtabs.
39339
39340 @kindex maint expand-symtabs
39341 @item maint expand-symtabs [@var{regexp}]
39342 Expand symbol tables.
39343 If @var{regexp} is specified, only expand symbol tables for file
39344 names matching @var{regexp}.
39345
39346 @kindex maint set catch-demangler-crashes
39347 @kindex maint show catch-demangler-crashes
39348 @cindex demangler crashes
39349 @item maint set catch-demangler-crashes [on|off]
39350 @itemx maint show catch-demangler-crashes
39351 Control whether @value{GDBN} should attempt to catch crashes in the
39352 symbol name demangler. The default is to attempt to catch crashes.
39353 If enabled, the first time a crash is caught, a core file is created,
39354 the offending symbol is displayed and the user is presented with the
39355 option to terminate the current session.
39356
39357 @kindex maint cplus first_component
39358 @item maint cplus first_component @var{name}
39359 Print the first C@t{++} class/namespace component of @var{name}.
39360
39361 @kindex maint cplus namespace
39362 @item maint cplus namespace
39363 Print the list of possible C@t{++} namespaces.
39364
39365 @kindex maint deprecate
39366 @kindex maint undeprecate
39367 @cindex deprecated commands
39368 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
39369 @itemx maint undeprecate @var{command}
39370 Deprecate or undeprecate the named @var{command}. Deprecated commands
39371 cause @value{GDBN} to issue a warning when you use them. The optional
39372 argument @var{replacement} says which newer command should be used in
39373 favor of the deprecated one; if it is given, @value{GDBN} will mention
39374 the replacement as part of the warning.
39375
39376 @kindex maint dump-me
39377 @item maint dump-me
39378 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
39379 Cause a fatal signal in the debugger and force it to dump its core.
39380 This is supported only on systems which support aborting a program
39381 with the @code{SIGQUIT} signal.
39382
39383 @kindex maint internal-error
39384 @kindex maint internal-warning
39385 @kindex maint demangler-warning
39386 @cindex demangler crashes
39387 @item maint internal-error @r{[}@var{message-text}@r{]}
39388 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
39389 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
39390
39391 Cause @value{GDBN} to call the internal function @code{internal_error},
39392 @code{internal_warning} or @code{demangler_warning} and hence behave
39393 as though an internal problem has been detected. In addition to
39394 reporting the internal problem, these functions give the user the
39395 opportunity to either quit @value{GDBN} or (for @code{internal_error}
39396 and @code{internal_warning}) create a core file of the current
39397 @value{GDBN} session.
39398
39399 These commands take an optional parameter @var{message-text} that is
39400 used as the text of the error or warning message.
39401
39402 Here's an example of using @code{internal-error}:
39403
39404 @smallexample
39405 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
39406 @dots{}/maint.c:121: internal-error: testing, 1, 2
39407 A problem internal to GDB has been detected. Further
39408 debugging may prove unreliable.
39409 Quit this debugging session? (y or n) @kbd{n}
39410 Create a core file? (y or n) @kbd{n}
39411 (@value{GDBP})
39412 @end smallexample
39413
39414 @cindex @value{GDBN} internal error
39415 @cindex internal errors, control of @value{GDBN} behavior
39416 @cindex demangler crashes
39417
39418 @kindex maint set internal-error
39419 @kindex maint show internal-error
39420 @kindex maint set internal-warning
39421 @kindex maint show internal-warning
39422 @kindex maint set demangler-warning
39423 @kindex maint show demangler-warning
39424 @item maint set internal-error @var{action} [ask|yes|no]
39425 @itemx maint show internal-error @var{action}
39426 @itemx maint set internal-warning @var{action} [ask|yes|no]
39427 @itemx maint show internal-warning @var{action}
39428 @itemx maint set demangler-warning @var{action} [ask|yes|no]
39429 @itemx maint show demangler-warning @var{action}
39430 When @value{GDBN} reports an internal problem (error or warning) it
39431 gives the user the opportunity to both quit @value{GDBN} and create a
39432 core file of the current @value{GDBN} session. These commands let you
39433 override the default behaviour for each particular @var{action},
39434 described in the table below.
39435
39436 @table @samp
39437 @item quit
39438 You can specify that @value{GDBN} should always (yes) or never (no)
39439 quit. The default is to ask the user what to do.
39440
39441 @item corefile
39442 You can specify that @value{GDBN} should always (yes) or never (no)
39443 create a core file. The default is to ask the user what to do. Note
39444 that there is no @code{corefile} option for @code{demangler-warning}:
39445 demangler warnings always create a core file and this cannot be
39446 disabled.
39447 @end table
39448
39449 @kindex maint set internal-error
39450 @kindex maint show internal-error
39451 @kindex maint set internal-warning
39452 @kindex maint show internal-warning
39453 @item maint set internal-error backtrace @r{[}on|off@r{]}
39454 @itemx maint show internal-error backtrace
39455 @itemx maint set internal-warning backtrace @r{[}on|off@r{]}
39456 @itemx maint show internal-warning backtrace
39457 When @value{GDBN} reports an internal problem (error or warning) it is
39458 possible to have a backtrace of @value{GDBN} printed to the standard
39459 error stream. This is @samp{on} by default for @code{internal-error}
39460 and @samp{off} by default for @code{internal-warning}.
39461
39462 @anchor{maint packet}
39463 @kindex maint packet
39464 @item maint packet @var{text}
39465 If @value{GDBN} is talking to an inferior via the serial protocol,
39466 then this command sends the string @var{text} to the inferior, and
39467 displays the response packet. @value{GDBN} supplies the initial
39468 @samp{$} character, the terminating @samp{#} character, and the
39469 checksum.
39470
39471 Any non-printable characters in the reply are printed as escaped hex,
39472 e.g. @samp{\x00}, @samp{\x01}, etc.
39473
39474 @kindex maint print architecture
39475 @item maint print architecture @r{[}@var{file}@r{]}
39476 Print the entire architecture configuration. The optional argument
39477 @var{file} names the file where the output goes.
39478
39479 @kindex maint print c-tdesc
39480 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
39481 Print the target description (@pxref{Target Descriptions}) as
39482 a C source file. By default, the target description is for the current
39483 target, but if the optional argument @var{file} is provided, that file
39484 is used to produce the description. The @var{file} should be an XML
39485 document, of the form described in @ref{Target Description Format}.
39486 The created source file is built into @value{GDBN} when @value{GDBN} is
39487 built again. This command is used by developers after they add or
39488 modify XML target descriptions.
39489
39490 When the optional flag @samp{-single-feature} is provided then the
39491 target description being processed (either the default, or from
39492 @var{file}) must only contain a single feature. The source file
39493 produced is different in this case.
39494
39495 @kindex maint print xml-tdesc
39496 @item maint print xml-tdesc @r{[}@var{file}@r{]}
39497 Print the target description (@pxref{Target Descriptions}) as an XML
39498 file. By default print the target description for the current target,
39499 but if the optional argument @var{file} is provided, then that file is
39500 read in by GDB and then used to produce the description. The
39501 @var{file} should be an XML document, of the form described in
39502 @ref{Target Description Format}.
39503
39504 @kindex maint check xml-descriptions
39505 @item maint check xml-descriptions @var{dir}
39506 Check that the target descriptions dynamically created by @value{GDBN}
39507 equal the descriptions created from XML files found in @var{dir}.
39508
39509 @anchor{maint check libthread-db}
39510 @kindex maint check libthread-db
39511 @item maint check libthread-db
39512 Run integrity checks on the current inferior's thread debugging
39513 library. This exercises all @code{libthread_db} functionality used by
39514 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
39515 @code{proc_service} functions provided by @value{GDBN} that
39516 @code{libthread_db} uses. Note that parts of the test may be skipped
39517 on some platforms when debugging core files.
39518
39519 @kindex maint print core-file-backed-mappings
39520 @cindex memory address space mappings
39521 @item maint print core-file-backed-mappings
39522 Print the file-backed mappings which were loaded from a core file note.
39523 This output represents state internal to @value{GDBN} and should be
39524 similar to the mappings displayed by the @code{info proc mappings}
39525 command.
39526
39527 @kindex maint print dummy-frames
39528 @item maint print dummy-frames
39529 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
39530
39531 @smallexample
39532 (@value{GDBP}) @kbd{b add}
39533 @dots{}
39534 (@value{GDBP}) @kbd{print add(2,3)}
39535 Breakpoint 2, add (a=2, b=3) at @dots{}
39536 58 return (a + b);
39537 The program being debugged stopped while in a function called from GDB.
39538 @dots{}
39539 (@value{GDBP}) @kbd{maint print dummy-frames}
39540 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
39541 (@value{GDBP})
39542 @end smallexample
39543
39544 Takes an optional file parameter.
39545
39546 @kindex maint print registers
39547 @kindex maint print raw-registers
39548 @kindex maint print cooked-registers
39549 @kindex maint print register-groups
39550 @kindex maint print remote-registers
39551 @item maint print registers @r{[}@var{file}@r{]}
39552 @itemx maint print raw-registers @r{[}@var{file}@r{]}
39553 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
39554 @itemx maint print register-groups @r{[}@var{file}@r{]}
39555 @itemx maint print remote-registers @r{[}@var{file}@r{]}
39556 Print @value{GDBN}'s internal register data structures.
39557
39558 The command @code{maint print raw-registers} includes the contents of
39559 the raw register cache; the command @code{maint print
39560 cooked-registers} includes the (cooked) value of all registers,
39561 including registers which aren't available on the target nor visible
39562 to user; the command @code{maint print register-groups} includes the
39563 groups that each register is a member of; and the command @code{maint
39564 print remote-registers} includes the remote target's register numbers
39565 and offsets in the `G' packets.
39566
39567 These commands take an optional parameter, a file name to which to
39568 write the information.
39569
39570 @kindex maint print reggroups
39571 @item maint print reggroups @r{[}@var{file}@r{]}
39572 Print @value{GDBN}'s internal register group data structures. The
39573 optional argument @var{file} tells to what file to write the
39574 information.
39575
39576 The register groups info looks like this:
39577
39578 @smallexample
39579 (@value{GDBP}) @kbd{maint print reggroups}
39580 Group Type
39581 general user
39582 float user
39583 all user
39584 vector user
39585 system user
39586 save internal
39587 restore internal
39588 @end smallexample
39589
39590 @kindex maint flush register-cache
39591 @kindex flushregs
39592 @cindex register cache, flushing
39593 @item maint flush register-cache
39594 @itemx flushregs
39595 Flush the contents of the register cache and as a consequence the
39596 frame cache. This command is useful when debugging issues related to
39597 register fetching, or frame unwinding. The command @code{flushregs}
39598 is deprecated in favor of @code{maint flush register-cache}.
39599
39600 @kindex maint flush source-cache
39601 @cindex source code, caching
39602 @item maint flush source-cache
39603 Flush @value{GDBN}'s cache of source code file contents. After
39604 @value{GDBN} reads a source file, and optionally applies styling
39605 (@pxref{Output Styling}), the file contents are cached. This command
39606 clears that cache. The next time @value{GDBN} wants to show lines
39607 from a source file, the content will be re-read.
39608
39609 This command is useful when debugging issues related to source code
39610 styling. After flushing the cache any source code displayed by
39611 @value{GDBN} will be re-read and re-styled.
39612
39613 @kindex maint print objfiles
39614 @cindex info for known object files
39615 @item maint print objfiles @r{[}@var{regexp}@r{]}
39616 Print a dump of all known object files.
39617 If @var{regexp} is specified, only print object files whose names
39618 match @var{regexp}. For each object file, this command prints its name,
39619 address in memory, and all of its psymtabs and symtabs.
39620
39621 @kindex maint print user-registers
39622 @cindex user registers
39623 @item maint print user-registers
39624 List all currently available @dfn{user registers}. User registers
39625 typically provide alternate names for actual hardware registers. They
39626 include the four ``standard'' registers @code{$fp}, @code{$pc},
39627 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
39628 registers can be used in expressions in the same way as the canonical
39629 register names, but only the latter are listed by the @code{info
39630 registers} and @code{maint print registers} commands.
39631
39632 @kindex maint print section-scripts
39633 @cindex info for known .debug_gdb_scripts-loaded scripts
39634 @item maint print section-scripts [@var{regexp}]
39635 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
39636 If @var{regexp} is specified, only print scripts loaded by object files
39637 matching @var{regexp}.
39638 For each script, this command prints its name as specified in the objfile,
39639 and the full path if known.
39640 @xref{dotdebug_gdb_scripts section}.
39641
39642 @kindex maint print statistics
39643 @cindex bcache statistics
39644 @item maint print statistics
39645 This command prints, for each object file in the program, various data
39646 about that object file followed by the byte cache (@dfn{bcache})
39647 statistics for the object file. The objfile data includes the number
39648 of minimal, partial, full, and stabs symbols, the number of types
39649 defined by the objfile, the number of as yet unexpanded psym tables,
39650 the number of line tables and string tables, and the amount of memory
39651 used by the various tables. The bcache statistics include the counts,
39652 sizes, and counts of duplicates of all and unique objects, max,
39653 average, and median entry size, total memory used and its overhead and
39654 savings, and various measures of the hash table size and chain
39655 lengths.
39656
39657 @kindex maint print target-stack
39658 @cindex target stack description
39659 @item maint print target-stack
39660 A @dfn{target} is an interface between the debugger and a particular
39661 kind of file or process. Targets can be stacked in @dfn{strata},
39662 so that more than one target can potentially respond to a request.
39663 In particular, memory accesses will walk down the stack of targets
39664 until they find a target that is interested in handling that particular
39665 address.
39666
39667 This command prints a short description of each layer that was pushed on
39668 the @dfn{target stack}, starting from the top layer down to the bottom one.
39669
39670 @kindex maint print type
39671 @cindex type chain of a data type
39672 @item maint print type @var{expr}
39673 Print the type chain for a type specified by @var{expr}. The argument
39674 can be either a type name or a symbol. If it is a symbol, the type of
39675 that symbol is described. The type chain produced by this command is
39676 a recursive definition of the data type as stored in @value{GDBN}'s
39677 data structures, including its flags and contained types.
39678
39679 @kindex maint selftest
39680 @cindex self tests
39681 @item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}
39682 Run any self tests that were compiled in to @value{GDBN}. This will
39683 print a message showing how many tests were run, and how many failed.
39684 If a @var{filter} is passed, only the tests with @var{filter} in their
39685 name will be ran. If @code{-verbose} is passed, the self tests can be
39686 more verbose.
39687
39688 @kindex maint set selftest verbose
39689 @kindex maint show selftest verbose
39690 @cindex self tests
39691 @item maint set selftest verbose
39692 @item maint show selftest verbose
39693 Control whether self tests are run verbosely or not.
39694
39695 @kindex maint info selftests
39696 @cindex self tests
39697 @item maint info selftests
39698 List the selftests compiled in to @value{GDBN}.
39699
39700 @kindex maint set dwarf always-disassemble
39701 @kindex maint show dwarf always-disassemble
39702 @item maint set dwarf always-disassemble
39703 @item maint show dwarf always-disassemble
39704 Control the behavior of @code{info address} when using DWARF debugging
39705 information.
39706
39707 The default is @code{off}, which means that @value{GDBN} should try to
39708 describe a variable's location in an easily readable format. When
39709 @code{on}, @value{GDBN} will instead display the DWARF location
39710 expression in an assembly-like format. Note that some locations are
39711 too complex for @value{GDBN} to describe simply; in this case you will
39712 always see the disassembly form.
39713
39714 Here is an example of the resulting disassembly:
39715
39716 @smallexample
39717 (gdb) info addr argc
39718 Symbol "argc" is a complex DWARF expression:
39719 1: DW_OP_fbreg 0
39720 @end smallexample
39721
39722 For more information on these expressions, see
39723 @uref{http://www.dwarfstd.org/, the DWARF standard}.
39724
39725 @kindex maint set dwarf max-cache-age
39726 @kindex maint show dwarf max-cache-age
39727 @item maint set dwarf max-cache-age
39728 @itemx maint show dwarf max-cache-age
39729 Control the DWARF compilation unit cache.
39730
39731 @cindex DWARF compilation units cache
39732 In object files with inter-compilation-unit references, such as those
39733 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
39734 reader needs to frequently refer to previously read compilation units.
39735 This setting controls how long a compilation unit will remain in the
39736 cache if it is not referenced. A higher limit means that cached
39737 compilation units will be stored in memory longer, and more total
39738 memory will be used. Setting it to zero disables caching, which will
39739 slow down @value{GDBN} startup, but reduce memory consumption.
39740
39741 @kindex maint set dwarf unwinders
39742 @kindex maint show dwarf unwinders
39743 @item maint set dwarf unwinders
39744 @itemx maint show dwarf unwinders
39745 Control use of the DWARF frame unwinders.
39746
39747 @cindex DWARF frame unwinders
39748 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39749 frame unwinders to build the backtrace. Many of these targets will
39750 also have a second mechanism for building the backtrace for use in
39751 cases where DWARF information is not available, this second mechanism
39752 is often an analysis of a function's prologue.
39753
39754 In order to extend testing coverage of the second level stack
39755 unwinding mechanisms it is helpful to be able to disable the DWARF
39756 stack unwinders, this can be done with this switch.
39757
39758 In normal use of @value{GDBN} disabling the DWARF unwinders is not
39759 advisable, there are cases that are better handled through DWARF than
39760 prologue analysis, and the debug experience is likely to be better
39761 with the DWARF frame unwinders enabled.
39762
39763 If DWARF frame unwinders are not supported for a particular target
39764 architecture, then enabling this flag does not cause them to be used.
39765
39766 @kindex maint set worker-threads
39767 @kindex maint show worker-threads
39768 @item maint set worker-threads
39769 @item maint show worker-threads
39770 Control the number of worker threads that may be used by @value{GDBN}.
39771 On capable hosts, @value{GDBN} may use multiple threads to speed up
39772 certain CPU-intensive operations, such as demangling symbol names.
39773 While the number of threads used by @value{GDBN} may vary, this
39774 command can be used to set an upper bound on this number. The default
39775 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39776 number. Note that this only controls worker threads started by
39777 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
39778 of their own.
39779
39780 @kindex maint set profile
39781 @kindex maint show profile
39782 @cindex profiling GDB
39783 @item maint set profile
39784 @itemx maint show profile
39785 Control profiling of @value{GDBN}.
39786
39787 Profiling will be disabled until you use the @samp{maint set profile}
39788 command to enable it. When you enable profiling, the system will begin
39789 collecting timing and execution count data; when you disable profiling or
39790 exit @value{GDBN}, the results will be written to a log file. Remember that
39791 if you use profiling, @value{GDBN} will overwrite the profiling log file
39792 (often called @file{gmon.out}). If you have a record of important profiling
39793 data in a @file{gmon.out} file, be sure to move it to a safe location.
39794
39795 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
39796 compiled with the @samp{-pg} compiler option.
39797
39798 @kindex maint set show-debug-regs
39799 @kindex maint show show-debug-regs
39800 @cindex hardware debug registers
39801 @item maint set show-debug-regs
39802 @itemx maint show show-debug-regs
39803 Control whether to show variables that mirror the hardware debug
39804 registers. Use @code{on} to enable, @code{off} to disable. If
39805 enabled, the debug registers values are shown when @value{GDBN} inserts or
39806 removes a hardware breakpoint or watchpoint, and when the inferior
39807 triggers a hardware-assisted breakpoint or watchpoint.
39808
39809 @kindex maint set show-all-tib
39810 @kindex maint show show-all-tib
39811 @item maint set show-all-tib
39812 @itemx maint show show-all-tib
39813 Control whether to show all non zero areas within a 1k block starting
39814 at thread local base, when using the @samp{info w32 thread-information-block}
39815 command.
39816
39817 @kindex maint set target-async
39818 @kindex maint show target-async
39819 @item maint set target-async
39820 @itemx maint show target-async
39821 This controls whether @value{GDBN} targets operate in synchronous or
39822 asynchronous mode (@pxref{Background Execution}). Normally the
39823 default is asynchronous, if it is available; but this can be changed
39824 to more easily debug problems occurring only in synchronous mode.
39825
39826 @kindex maint set target-non-stop @var{mode} [on|off|auto]
39827 @kindex maint show target-non-stop
39828 @item maint set target-non-stop
39829 @itemx maint show target-non-stop
39830
39831 This controls whether @value{GDBN} targets always operate in non-stop
39832 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39833 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39834 if supported by the target.
39835
39836 @table @code
39837 @item maint set target-non-stop auto
39838 This is the default mode. @value{GDBN} controls the target in
39839 non-stop mode if the target supports it.
39840
39841 @item maint set target-non-stop on
39842 @value{GDBN} controls the target in non-stop mode even if the target
39843 does not indicate support.
39844
39845 @item maint set target-non-stop off
39846 @value{GDBN} does not control the target in non-stop mode even if the
39847 target supports it.
39848 @end table
39849
39850 @kindex maint set tui-resize-message
39851 @kindex maint show tui-resize-message
39852 @item maint set tui-resize-message
39853 @item maint show tui-resize-message
39854 Control whether @value{GDBN} displays a message each time the terminal
39855 is resized when in TUI mode. The default is @code{off}, which means
39856 that @value{GDBN} is silent during resizes. When @code{on},
39857 @value{GDBN} will display a message after a resize is completed; the
39858 message will include a number indicating how many times the terminal
39859 has been resized. This setting is intended for use by the test suite,
39860 where it would otherwise be difficult to determine when a resize and
39861 refresh has been completed.
39862
39863 @kindex maint set per-command
39864 @kindex maint show per-command
39865 @item maint set per-command
39866 @itemx maint show per-command
39867 @cindex resources used by commands
39868
39869 @value{GDBN} can display the resources used by each command.
39870 This is useful in debugging performance problems.
39871
39872 @table @code
39873 @item maint set per-command space [on|off]
39874 @itemx maint show per-command space
39875 Enable or disable the printing of the memory used by GDB for each command.
39876 If enabled, @value{GDBN} will display how much memory each command
39877 took, following the command's own output.
39878 This can also be requested by invoking @value{GDBN} with the
39879 @option{--statistics} command-line switch (@pxref{Mode Options}).
39880
39881 @item maint set per-command time [on|off]
39882 @itemx maint show per-command time
39883 Enable or disable the printing of the execution time of @value{GDBN}
39884 for each command.
39885 If enabled, @value{GDBN} will display how much time it
39886 took to execute each command, following the command's own output.
39887 Both CPU time and wallclock time are printed.
39888 Printing both is useful when trying to determine whether the cost is
39889 CPU or, e.g., disk/network latency.
39890 Note that the CPU time printed is for @value{GDBN} only, it does not include
39891 the execution time of the inferior because there's no mechanism currently
39892 to compute how much time was spent by @value{GDBN} and how much time was
39893 spent by the program been debugged.
39894 This can also be requested by invoking @value{GDBN} with the
39895 @option{--statistics} command-line switch (@pxref{Mode Options}).
39896
39897 @item maint set per-command symtab [on|off]
39898 @itemx maint show per-command symtab
39899 Enable or disable the printing of basic symbol table statistics
39900 for each command.
39901 If enabled, @value{GDBN} will display the following information:
39902
39903 @enumerate a
39904 @item
39905 number of symbol tables
39906 @item
39907 number of primary symbol tables
39908 @item
39909 number of blocks in the blockvector
39910 @end enumerate
39911 @end table
39912
39913 @kindex maint set check-libthread-db
39914 @kindex maint show check-libthread-db
39915 @item maint set check-libthread-db [on|off]
39916 @itemx maint show check-libthread-db
39917 Control whether @value{GDBN} should run integrity checks on inferior
39918 specific thread debugging libraries as they are loaded. The default
39919 is not to perform such checks. If any check fails @value{GDBN} will
39920 unload the library and continue searching for a suitable candidate as
39921 described in @ref{set libthread-db-search-path}. For more information
39922 about the tests, see @ref{maint check libthread-db}.
39923
39924 @kindex maint set gnu-source-highlight enabled
39925 @kindex maint show gnu-source-highlight enabled
39926 @item maint set gnu-source-highlight enabled @r{[}on|off@r{]}
39927 @itemx maint show gnu-source-highlight enabled
39928 Control whether @value{GDBN} should use the GNU Source Highlight
39929 library for applying styling to source code (@pxref{Output Styling}).
39930 This will be @samp{on} by default if the GNU Source Highlight library
39931 is available. If the GNU Source Highlight library is not available,
39932 then this will be @samp{off} by default, and attempting to change this
39933 value to @samp{on} will give an error.
39934
39935 If the GNU Source Highlight library is not being used, then
39936 @value{GDBN} will use the Python Pygments package for source code
39937 styling, if it is available.
39938
39939 This option is useful for debugging @value{GDBN}'s use of the Pygments
39940 library when @value{GDBN} is linked against the GNU Source Highlight
39941 library.
39942
39943 @kindex maint space
39944 @cindex memory used by commands
39945 @item maint space @var{value}
39946 An alias for @code{maint set per-command space}.
39947 A non-zero value enables it, zero disables it.
39948
39949 @kindex maint time
39950 @cindex time of command execution
39951 @item maint time @var{value}
39952 An alias for @code{maint set per-command time}.
39953 A non-zero value enables it, zero disables it.
39954
39955 @kindex maint translate-address
39956 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39957 Find the symbol stored at the location specified by the address
39958 @var{addr} and an optional section name @var{section}. If found,
39959 @value{GDBN} prints the name of the closest symbol and an offset from
39960 the symbol's location to the specified address. This is similar to
39961 the @code{info address} command (@pxref{Symbols}), except that this
39962 command also allows to find symbols in other sections.
39963
39964 If section was not specified, the section in which the symbol was found
39965 is also printed. For dynamically linked executables, the name of
39966 executable or shared library containing the symbol is printed as well.
39967
39968 @kindex maint test-options
39969 @item maint test-options require-delimiter
39970 @itemx maint test-options unknown-is-error
39971 @itemx maint test-options unknown-is-operand
39972 These commands are used by the testsuite to validate the command
39973 options framework. The @code{require-delimiter} variant requires a
39974 double-dash delimiter to indicate end of options. The
39975 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
39976 @code{unknown-is-error} variant throws an error on unknown option,
39977 while @code{unknown-is-operand} treats unknown options as the start of
39978 the command's operands. When run, the commands output the result of
39979 the processed options. When completed, the commands store the
39980 internal result of completion in a variable exposed by the @code{maint
39981 show test-options-completion-result} command.
39982
39983 @kindex maint show test-options-completion-result
39984 @item maint show test-options-completion-result
39985 Shows the result of completing the @code{maint test-options}
39986 subcommands. This is used by the testsuite to validate completion
39987 support in the command options framework.
39988
39989 @kindex maint set test-settings
39990 @kindex maint show test-settings
39991 @item maint set test-settings @var{kind}
39992 @itemx maint show test-settings @var{kind}
39993 These are representative commands for each @var{kind} of setting type
39994 @value{GDBN} supports. They are used by the testsuite for exercising
39995 the settings infrastructure.
39996
39997 @kindex maint set backtrace-on-fatal-signal
39998 @kindex maint show backtrace-on-fatal-signal
39999 @item maint set backtrace-on-fatal-signal [on|off]
40000 @itemx maint show backtrace-on-fatal-signal
40001 When this setting is @code{on}, if @value{GDBN} itself terminates with
40002 a fatal signal (e.g.@: SIGSEGV), then a limited backtrace will be
40003 printed to the standard error stream. This backtrace can be used to
40004 help diagnose crashes within @value{GDBN} in situations where a user
40005 is unable to share a corefile with the @value{GDBN} developers.
40006
40007 If the functionality to provide this backtrace is not available for
40008 the platform on which GDB is running then this feature will be
40009 @code{off} by default, and attempting to turn this feature on will
40010 give an error.
40011
40012 For platforms that do support creating the backtrace this feature is
40013 @code{on} by default.
40014
40015 @kindex maint with
40016 @item maint with @var{setting} [@var{value}] [-- @var{command}]
40017 Like the @code{with} command, but works with @code{maintenance set}
40018 variables. This is used by the testsuite to exercise the @code{with}
40019 command's infrastructure.
40020
40021 @end table
40022
40023 The following command is useful for non-interactive invocations of
40024 @value{GDBN}, such as in the test suite.
40025
40026 @table @code
40027 @item set watchdog @var{nsec}
40028 @kindex set watchdog
40029 @cindex watchdog timer
40030 @cindex timeout for commands
40031 Set the maximum number of seconds @value{GDBN} will wait for the
40032 target operation to finish. If this time expires, @value{GDBN}
40033 reports and error and the command is aborted.
40034
40035 @item show watchdog
40036 Show the current setting of the target wait timeout.
40037 @end table
40038
40039 @node Remote Protocol
40040 @appendix @value{GDBN} Remote Serial Protocol
40041
40042 @menu
40043 * Overview::
40044 * Packets::
40045 * Stop Reply Packets::
40046 * General Query Packets::
40047 * Architecture-Specific Protocol Details::
40048 * Tracepoint Packets::
40049 * Host I/O Packets::
40050 * Interrupts::
40051 * Notification Packets::
40052 * Remote Non-Stop::
40053 * Packet Acknowledgment::
40054 * Examples::
40055 * File-I/O Remote Protocol Extension::
40056 * Library List Format::
40057 * Library List Format for SVR4 Targets::
40058 * Memory Map Format::
40059 * Thread List Format::
40060 * Traceframe Info Format::
40061 * Branch Trace Format::
40062 * Branch Trace Configuration Format::
40063 @end menu
40064
40065 @node Overview
40066 @section Overview
40067
40068 There may be occasions when you need to know something about the
40069 protocol---for example, if there is only one serial port to your target
40070 machine, you might want your program to do something special if it
40071 recognizes a packet meant for @value{GDBN}.
40072
40073 In the examples below, @samp{->} and @samp{<-} are used to indicate
40074 transmitted and received data, respectively.
40075
40076 @cindex protocol, @value{GDBN} remote serial
40077 @cindex serial protocol, @value{GDBN} remote
40078 @cindex remote serial protocol
40079 All @value{GDBN} commands and responses (other than acknowledgments
40080 and notifications, see @ref{Notification Packets}) are sent as a
40081 @var{packet}. A @var{packet} is introduced with the character
40082 @samp{$}, the actual @var{packet-data}, and the terminating character
40083 @samp{#} followed by a two-digit @var{checksum}:
40084
40085 @smallexample
40086 @code{$}@var{packet-data}@code{#}@var{checksum}
40087 @end smallexample
40088 @noindent
40089
40090 @cindex checksum, for @value{GDBN} remote
40091 @noindent
40092 The two-digit @var{checksum} is computed as the modulo 256 sum of all
40093 characters between the leading @samp{$} and the trailing @samp{#} (an
40094 eight bit unsigned checksum).
40095
40096 Implementors should note that prior to @value{GDBN} 5.0 the protocol
40097 specification also included an optional two-digit @var{sequence-id}:
40098
40099 @smallexample
40100 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
40101 @end smallexample
40102
40103 @cindex sequence-id, for @value{GDBN} remote
40104 @noindent
40105 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
40106 has never output @var{sequence-id}s. Stubs that handle packets added
40107 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
40108
40109 When either the host or the target machine receives a packet, the first
40110 response expected is an acknowledgment: either @samp{+} (to indicate
40111 the package was received correctly) or @samp{-} (to request
40112 retransmission):
40113
40114 @smallexample
40115 -> @code{$}@var{packet-data}@code{#}@var{checksum}
40116 <- @code{+}
40117 @end smallexample
40118 @noindent
40119
40120 The @samp{+}/@samp{-} acknowledgments can be disabled
40121 once a connection is established.
40122 @xref{Packet Acknowledgment}, for details.
40123
40124 The host (@value{GDBN}) sends @var{command}s, and the target (the
40125 debugging stub incorporated in your program) sends a @var{response}. In
40126 the case of step and continue @var{command}s, the response is only sent
40127 when the operation has completed, and the target has again stopped all
40128 threads in all attached processes. This is the default all-stop mode
40129 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
40130 execution mode; see @ref{Remote Non-Stop}, for details.
40131
40132 @var{packet-data} consists of a sequence of characters with the
40133 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
40134 exceptions).
40135
40136 @cindex remote protocol, field separator
40137 Fields within the packet should be separated using @samp{,} @samp{;} or
40138 @samp{:}. Except where otherwise noted all numbers are represented in
40139 @sc{hex} with leading zeros suppressed.
40140
40141 Implementors should note that prior to @value{GDBN} 5.0, the character
40142 @samp{:} could not appear as the third character in a packet (as it
40143 would potentially conflict with the @var{sequence-id}).
40144
40145 @cindex remote protocol, binary data
40146 @anchor{Binary Data}
40147 Binary data in most packets is encoded either as two hexadecimal
40148 digits per byte of binary data. This allowed the traditional remote
40149 protocol to work over connections which were only seven-bit clean.
40150 Some packets designed more recently assume an eight-bit clean
40151 connection, and use a more efficient encoding to send and receive
40152 binary data.
40153
40154 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
40155 as an escape character. Any escaped byte is transmitted as the escape
40156 character followed by the original character XORed with @code{0x20}.
40157 For example, the byte @code{0x7d} would be transmitted as the two
40158 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
40159 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
40160 @samp{@}}) must always be escaped. Responses sent by the stub
40161 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
40162 is not interpreted as the start of a run-length encoded sequence
40163 (described next).
40164
40165 Response @var{data} can be run-length encoded to save space.
40166 Run-length encoding replaces runs of identical characters with one
40167 instance of the repeated character, followed by a @samp{*} and a
40168 repeat count. The repeat count is itself sent encoded, to avoid
40169 binary characters in @var{data}: a value of @var{n} is sent as
40170 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
40171 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
40172 code 32) for a repeat count of 3. (This is because run-length
40173 encoding starts to win for counts 3 or more.) Thus, for example,
40174 @samp{0* } is a run-length encoding of ``0000'': the space character
40175 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
40176 3}} more times.
40177
40178 The printable characters @samp{#} and @samp{$} or with a numeric value
40179 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
40180 seven repeats (@samp{$}) can be expanded using a repeat count of only
40181 five (@samp{"}). For example, @samp{00000000} can be encoded as
40182 @samp{0*"00}.
40183
40184 The error response returned for some packets includes a two character
40185 error number. That number is not well defined.
40186
40187 @cindex empty response, for unsupported packets
40188 For any @var{command} not supported by the stub, an empty response
40189 (@samp{$#00}) should be returned. That way it is possible to extend the
40190 protocol. A newer @value{GDBN} can tell if a packet is supported based
40191 on that response.
40192
40193 At a minimum, a stub is required to support the @samp{?} command to
40194 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
40195 commands for register access, and the @samp{m} and @samp{M} commands
40196 for memory access. Stubs that only control single-threaded targets
40197 can implement run control with the @samp{c} (continue) command, and if
40198 the target architecture supports hardware-assisted single-stepping,
40199 the @samp{s} (step) command. Stubs that support multi-threading
40200 targets should support the @samp{vCont} command. All other commands
40201 are optional.
40202
40203 @node Packets
40204 @section Packets
40205
40206 The following table provides a complete list of all currently defined
40207 @var{command}s and their corresponding response @var{data}.
40208 @xref{File-I/O Remote Protocol Extension}, for details about the File
40209 I/O extension of the remote protocol.
40210
40211 Each packet's description has a template showing the packet's overall
40212 syntax, followed by an explanation of the packet's meaning. We
40213 include spaces in some of the templates for clarity; these are not
40214 part of the packet's syntax. No @value{GDBN} packet uses spaces to
40215 separate its components. For example, a template like @samp{foo
40216 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
40217 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
40218 @var{baz}. @value{GDBN} does not transmit a space character between the
40219 @samp{foo} and the @var{bar}, or between the @var{bar} and the
40220 @var{baz}.
40221
40222 @cindex @var{thread-id}, in remote protocol
40223 @anchor{thread-id syntax}
40224 Several packets and replies include a @var{thread-id} field to identify
40225 a thread. Normally these are positive numbers with a target-specific
40226 interpretation, formatted as big-endian hex strings. A @var{thread-id}
40227 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
40228 pick any thread.
40229
40230 In addition, the remote protocol supports a multiprocess feature in
40231 which the @var{thread-id} syntax is extended to optionally include both
40232 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
40233 The @var{pid} (process) and @var{tid} (thread) components each have the
40234 format described above: a positive number with target-specific
40235 interpretation formatted as a big-endian hex string, literal @samp{-1}
40236 to indicate all processes or threads (respectively), or @samp{0} to
40237 indicate an arbitrary process or thread. Specifying just a process, as
40238 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
40239 error to specify all processes but a specific thread, such as
40240 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
40241 for those packets and replies explicitly documented to include a process
40242 ID, rather than a @var{thread-id}.
40243
40244 The multiprocess @var{thread-id} syntax extensions are only used if both
40245 @value{GDBN} and the stub report support for the @samp{multiprocess}
40246 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
40247 more information.
40248
40249 Note that all packet forms beginning with an upper- or lower-case
40250 letter, other than those described here, are reserved for future use.
40251
40252 Here are the packet descriptions.
40253
40254 @table @samp
40255
40256 @item !
40257 @cindex @samp{!} packet
40258 @anchor{extended mode}
40259 Enable extended mode. In extended mode, the remote server is made
40260 persistent. The @samp{R} packet is used to restart the program being
40261 debugged.
40262
40263 Reply:
40264 @table @samp
40265 @item OK
40266 The remote target both supports and has enabled extended mode.
40267 @end table
40268
40269 @item ?
40270 @cindex @samp{?} packet
40271 @anchor{? packet}
40272 This is sent when connection is first established to query the reason
40273 the target halted. The reply is the same as for step and continue.
40274 This packet has a special interpretation when the target is in
40275 non-stop mode; see @ref{Remote Non-Stop}.
40276
40277 Reply:
40278 @xref{Stop Reply Packets}, for the reply specifications.
40279
40280 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
40281 @cindex @samp{A} packet
40282 Initialized @code{argv[]} array passed into program. @var{arglen}
40283 specifies the number of bytes in the hex encoded byte stream
40284 @var{arg}. See @code{gdbserver} for more details.
40285
40286 Reply:
40287 @table @samp
40288 @item OK
40289 The arguments were set.
40290 @item E @var{NN}
40291 An error occurred.
40292 @end table
40293
40294 @item b @var{baud}
40295 @cindex @samp{b} packet
40296 (Don't use this packet; its behavior is not well-defined.)
40297 Change the serial line speed to @var{baud}.
40298
40299 JTC: @emph{When does the transport layer state change? When it's
40300 received, or after the ACK is transmitted. In either case, there are
40301 problems if the command or the acknowledgment packet is dropped.}
40302
40303 Stan: @emph{If people really wanted to add something like this, and get
40304 it working for the first time, they ought to modify ser-unix.c to send
40305 some kind of out-of-band message to a specially-setup stub and have the
40306 switch happen "in between" packets, so that from remote protocol's point
40307 of view, nothing actually happened.}
40308
40309 @item B @var{addr},@var{mode}
40310 @cindex @samp{B} packet
40311 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
40312 breakpoint at @var{addr}.
40313
40314 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
40315 (@pxref{insert breakpoint or watchpoint packet}).
40316
40317 @cindex @samp{bc} packet
40318 @anchor{bc}
40319 @item bc
40320 Backward continue. Execute the target system in reverse. No parameter.
40321 @xref{Reverse Execution}, for more information.
40322
40323 Reply:
40324 @xref{Stop Reply Packets}, for the reply specifications.
40325
40326 @cindex @samp{bs} packet
40327 @anchor{bs}
40328 @item bs
40329 Backward single step. Execute one instruction in reverse. No parameter.
40330 @xref{Reverse Execution}, for more information.
40331
40332 Reply:
40333 @xref{Stop Reply Packets}, for the reply specifications.
40334
40335 @item c @r{[}@var{addr}@r{]}
40336 @cindex @samp{c} packet
40337 Continue at @var{addr}, which is the address to resume. If @var{addr}
40338 is omitted, resume at current address.
40339
40340 This packet is deprecated for multi-threading support. @xref{vCont
40341 packet}.
40342
40343 Reply:
40344 @xref{Stop Reply Packets}, for the reply specifications.
40345
40346 @item C @var{sig}@r{[};@var{addr}@r{]}
40347 @cindex @samp{C} packet
40348 Continue with signal @var{sig} (hex signal number). If
40349 @samp{;@var{addr}} is omitted, resume at same address.
40350
40351 This packet is deprecated for multi-threading support. @xref{vCont
40352 packet}.
40353
40354 Reply:
40355 @xref{Stop Reply Packets}, for the reply specifications.
40356
40357 @item d
40358 @cindex @samp{d} packet
40359 Toggle debug flag.
40360
40361 Don't use this packet; instead, define a general set packet
40362 (@pxref{General Query Packets}).
40363
40364 @item D
40365 @itemx D;@var{pid}
40366 @cindex @samp{D} packet
40367 The first form of the packet is used to detach @value{GDBN} from the
40368 remote system. It is sent to the remote target
40369 before @value{GDBN} disconnects via the @code{detach} command.
40370
40371 The second form, including a process ID, is used when multiprocess
40372 protocol extensions are enabled (@pxref{multiprocess extensions}), to
40373 detach only a specific process. The @var{pid} is specified as a
40374 big-endian hex string.
40375
40376 Reply:
40377 @table @samp
40378 @item OK
40379 for success
40380 @item E @var{NN}
40381 for an error
40382 @end table
40383
40384 @item F @var{RC},@var{EE},@var{CF};@var{XX}
40385 @cindex @samp{F} packet
40386 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
40387 This is part of the File-I/O protocol extension. @xref{File-I/O
40388 Remote Protocol Extension}, for the specification.
40389
40390 @item g
40391 @anchor{read registers packet}
40392 @cindex @samp{g} packet
40393 Read general registers.
40394
40395 Reply:
40396 @table @samp
40397 @item @var{XX@dots{}}
40398 Each byte of register data is described by two hex digits. The bytes
40399 with the register are transmitted in target byte order. The size of
40400 each register and their position within the @samp{g} packet are
40401 determined by the @value{GDBN} internal gdbarch functions
40402 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
40403
40404 When reading registers from a trace frame (@pxref{Analyze Collected
40405 Data,,Using the Collected Data}), the stub may also return a string of
40406 literal @samp{x}'s in place of the register data digits, to indicate
40407 that the corresponding register has not been collected, thus its value
40408 is unavailable. For example, for an architecture with 4 registers of
40409 4 bytes each, the following reply indicates to @value{GDBN} that
40410 registers 0 and 2 have not been collected, while registers 1 and 3
40411 have been collected, and both have zero value:
40412
40413 @smallexample
40414 -> @code{g}
40415 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
40416 @end smallexample
40417
40418 @item E @var{NN}
40419 for an error.
40420 @end table
40421
40422 @item G @var{XX@dots{}}
40423 @cindex @samp{G} packet
40424 Write general registers. @xref{read registers packet}, for a
40425 description of the @var{XX@dots{}} data.
40426
40427 Reply:
40428 @table @samp
40429 @item OK
40430 for success
40431 @item E @var{NN}
40432 for an error
40433 @end table
40434
40435 @item H @var{op} @var{thread-id}
40436 @cindex @samp{H} packet
40437 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
40438 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
40439 should be @samp{c} for step and continue operations (note that this
40440 is deprecated, supporting the @samp{vCont} command is a better
40441 option), and @samp{g} for other operations. The thread designator
40442 @var{thread-id} has the format and interpretation described in
40443 @ref{thread-id syntax}.
40444
40445 Reply:
40446 @table @samp
40447 @item OK
40448 for success
40449 @item E @var{NN}
40450 for an error
40451 @end table
40452
40453 @c FIXME: JTC:
40454 @c 'H': How restrictive (or permissive) is the thread model. If a
40455 @c thread is selected and stopped, are other threads allowed
40456 @c to continue to execute? As I mentioned above, I think the
40457 @c semantics of each command when a thread is selected must be
40458 @c described. For example:
40459 @c
40460 @c 'g': If the stub supports threads and a specific thread is
40461 @c selected, returns the register block from that thread;
40462 @c otherwise returns current registers.
40463 @c
40464 @c 'G' If the stub supports threads and a specific thread is
40465 @c selected, sets the registers of the register block of
40466 @c that thread; otherwise sets current registers.
40467
40468 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
40469 @anchor{cycle step packet}
40470 @cindex @samp{i} packet
40471 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
40472 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
40473 step starting at that address.
40474
40475 @item I
40476 @cindex @samp{I} packet
40477 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
40478 step packet}.
40479
40480 @item k
40481 @cindex @samp{k} packet
40482 Kill request.
40483
40484 The exact effect of this packet is not specified.
40485
40486 For a bare-metal target, it may power cycle or reset the target
40487 system. For that reason, the @samp{k} packet has no reply.
40488
40489 For a single-process target, it may kill that process if possible.
40490
40491 A multiple-process target may choose to kill just one process, or all
40492 that are under @value{GDBN}'s control. For more precise control, use
40493 the vKill packet (@pxref{vKill packet}).
40494
40495 If the target system immediately closes the connection in response to
40496 @samp{k}, @value{GDBN} does not consider the lack of packet
40497 acknowledgment to be an error, and assumes the kill was successful.
40498
40499 If connected using @kbd{target extended-remote}, and the target does
40500 not close the connection in response to a kill request, @value{GDBN}
40501 probes the target state as if a new connection was opened
40502 (@pxref{? packet}).
40503
40504 @item m @var{addr},@var{length}
40505 @cindex @samp{m} packet
40506 Read @var{length} addressable memory units starting at address @var{addr}
40507 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
40508 any particular boundary.
40509
40510 The stub need not use any particular size or alignment when gathering
40511 data from memory for the response; even if @var{addr} is word-aligned
40512 and @var{length} is a multiple of the word size, the stub is free to
40513 use byte accesses, or not. For this reason, this packet may not be
40514 suitable for accessing memory-mapped I/O devices.
40515 @cindex alignment of remote memory accesses
40516 @cindex size of remote memory accesses
40517 @cindex memory, alignment and size of remote accesses
40518
40519 Reply:
40520 @table @samp
40521 @item @var{XX@dots{}}
40522 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
40523 The reply may contain fewer addressable memory units than requested if the
40524 server was able to read only part of the region of memory.
40525 @item E @var{NN}
40526 @var{NN} is errno
40527 @end table
40528
40529 @item M @var{addr},@var{length}:@var{XX@dots{}}
40530 @cindex @samp{M} packet
40531 Write @var{length} addressable memory units starting at address @var{addr}
40532 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
40533 byte is transmitted as a two-digit hexadecimal number.
40534
40535 Reply:
40536 @table @samp
40537 @item OK
40538 for success
40539 @item E @var{NN}
40540 for an error (this includes the case where only part of the data was
40541 written).
40542 @end table
40543
40544 @item p @var{n}
40545 @cindex @samp{p} packet
40546 Read the value of register @var{n}; @var{n} is in hex.
40547 @xref{read registers packet}, for a description of how the returned
40548 register value is encoded.
40549
40550 Reply:
40551 @table @samp
40552 @item @var{XX@dots{}}
40553 the register's value
40554 @item E @var{NN}
40555 for an error
40556 @item @w{}
40557 Indicating an unrecognized @var{query}.
40558 @end table
40559
40560 @item P @var{n@dots{}}=@var{r@dots{}}
40561 @anchor{write register packet}
40562 @cindex @samp{P} packet
40563 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
40564 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
40565 digits for each byte in the register (target byte order).
40566
40567 Reply:
40568 @table @samp
40569 @item OK
40570 for success
40571 @item E @var{NN}
40572 for an error
40573 @end table
40574
40575 @item q @var{name} @var{params}@dots{}
40576 @itemx Q @var{name} @var{params}@dots{}
40577 @cindex @samp{q} packet
40578 @cindex @samp{Q} packet
40579 General query (@samp{q}) and set (@samp{Q}). These packets are
40580 described fully in @ref{General Query Packets}.
40581
40582 @item r
40583 @cindex @samp{r} packet
40584 Reset the entire system.
40585
40586 Don't use this packet; use the @samp{R} packet instead.
40587
40588 @item R @var{XX}
40589 @cindex @samp{R} packet
40590 Restart the program being debugged. The @var{XX}, while needed, is ignored.
40591 This packet is only available in extended mode (@pxref{extended mode}).
40592
40593 The @samp{R} packet has no reply.
40594
40595 @item s @r{[}@var{addr}@r{]}
40596 @cindex @samp{s} packet
40597 Single step, resuming at @var{addr}. If
40598 @var{addr} is omitted, resume at same address.
40599
40600 This packet is deprecated for multi-threading support. @xref{vCont
40601 packet}.
40602
40603 Reply:
40604 @xref{Stop Reply Packets}, for the reply specifications.
40605
40606 @item S @var{sig}@r{[};@var{addr}@r{]}
40607 @anchor{step with signal packet}
40608 @cindex @samp{S} packet
40609 Step with signal. This is analogous to the @samp{C} packet, but
40610 requests a single-step, rather than a normal resumption of execution.
40611
40612 This packet is deprecated for multi-threading support. @xref{vCont
40613 packet}.
40614
40615 Reply:
40616 @xref{Stop Reply Packets}, for the reply specifications.
40617
40618 @item t @var{addr}:@var{PP},@var{MM}
40619 @cindex @samp{t} packet
40620 Search backwards starting at address @var{addr} for a match with pattern
40621 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
40622 There must be at least 3 digits in @var{addr}.
40623
40624 @item T @var{thread-id}
40625 @cindex @samp{T} packet
40626 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
40627
40628 Reply:
40629 @table @samp
40630 @item OK
40631 thread is still alive
40632 @item E @var{NN}
40633 thread is dead
40634 @end table
40635
40636 @item v
40637 Packets starting with @samp{v} are identified by a multi-letter name,
40638 up to the first @samp{;} or @samp{?} (or the end of the packet).
40639
40640 @item vAttach;@var{pid}
40641 @cindex @samp{vAttach} packet
40642 Attach to a new process with the specified process ID @var{pid}.
40643 The process ID is a
40644 hexadecimal integer identifying the process. In all-stop mode, all
40645 threads in the attached process are stopped; in non-stop mode, it may be
40646 attached without being stopped if that is supported by the target.
40647
40648 @c In non-stop mode, on a successful vAttach, the stub should set the
40649 @c current thread to a thread of the newly-attached process. After
40650 @c attaching, GDB queries for the attached process's thread ID with qC.
40651 @c Also note that, from a user perspective, whether or not the
40652 @c target is stopped on attach in non-stop mode depends on whether you
40653 @c use the foreground or background version of the attach command, not
40654 @c on what vAttach does; GDB does the right thing with respect to either
40655 @c stopping or restarting threads.
40656
40657 This packet is only available in extended mode (@pxref{extended mode}).
40658
40659 Reply:
40660 @table @samp
40661 @item E @var{nn}
40662 for an error
40663 @item @r{Any stop packet}
40664 for success in all-stop mode (@pxref{Stop Reply Packets})
40665 @item OK
40666 for success in non-stop mode (@pxref{Remote Non-Stop})
40667 @end table
40668
40669 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
40670 @cindex @samp{vCont} packet
40671 @anchor{vCont packet}
40672 Resume the inferior, specifying different actions for each thread.
40673
40674 For each inferior thread, the leftmost action with a matching
40675 @var{thread-id} is applied. Threads that don't match any action
40676 remain in their current state. Thread IDs are specified using the
40677 syntax described in @ref{thread-id syntax}. If multiprocess
40678 extensions (@pxref{multiprocess extensions}) are supported, actions
40679 can be specified to match all threads in a process by using the
40680 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
40681 @var{thread-id} matches all threads. Specifying no actions is an
40682 error.
40683
40684 Currently supported actions are:
40685
40686 @table @samp
40687 @item c
40688 Continue.
40689 @item C @var{sig}
40690 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
40691 @item s
40692 Step.
40693 @item S @var{sig}
40694 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
40695 @item t
40696 Stop.
40697 @item r @var{start},@var{end}
40698 Step once, and then keep stepping as long as the thread stops at
40699 addresses between @var{start} (inclusive) and @var{end} (exclusive).
40700 The remote stub reports a stop reply when either the thread goes out
40701 of the range or is stopped due to an unrelated reason, such as hitting
40702 a breakpoint. @xref{range stepping}.
40703
40704 If the range is empty (@var{start} == @var{end}), then the action
40705 becomes equivalent to the @samp{s} action. In other words,
40706 single-step once, and report the stop (even if the stepped instruction
40707 jumps to @var{start}).
40708
40709 (A stop reply may be sent at any point even if the PC is still within
40710 the stepping range; for example, it is valid to implement this packet
40711 in a degenerate way as a single instruction step operation.)
40712
40713 @end table
40714
40715 The optional argument @var{addr} normally associated with the
40716 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
40717 not supported in @samp{vCont}.
40718
40719 The @samp{t} action is only relevant in non-stop mode
40720 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
40721 A stop reply should be generated for any affected thread not already stopped.
40722 When a thread is stopped by means of a @samp{t} action,
40723 the corresponding stop reply should indicate that the thread has stopped with
40724 signal @samp{0}, regardless of whether the target uses some other signal
40725 as an implementation detail.
40726
40727 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
40728 @samp{r} actions for threads that are already running. Conversely,
40729 the server must ignore @samp{t} actions for threads that are already
40730 stopped.
40731
40732 @emph{Note:} In non-stop mode, a thread is considered running until
40733 @value{GDBN} acknowledges an asynchronous stop notification for it with
40734 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
40735
40736 The stub must support @samp{vCont} if it reports support for
40737 multiprocess extensions (@pxref{multiprocess extensions}).
40738
40739 Reply:
40740 @xref{Stop Reply Packets}, for the reply specifications.
40741
40742 @item vCont?
40743 @cindex @samp{vCont?} packet
40744 Request a list of actions supported by the @samp{vCont} packet.
40745
40746 Reply:
40747 @table @samp
40748 @item vCont@r{[};@var{action}@dots{}@r{]}
40749 The @samp{vCont} packet is supported. Each @var{action} is a supported
40750 command in the @samp{vCont} packet.
40751 @item @w{}
40752 The @samp{vCont} packet is not supported.
40753 @end table
40754
40755 @anchor{vCtrlC packet}
40756 @item vCtrlC
40757 @cindex @samp{vCtrlC} packet
40758 Interrupt remote target as if a control-C was pressed on the remote
40759 terminal. This is the equivalent to reacting to the @code{^C}
40760 (@samp{\003}, the control-C character) character in all-stop mode
40761 while the target is running, except this works in non-stop mode.
40762 @xref{interrupting remote targets}, for more info on the all-stop
40763 variant.
40764
40765 Reply:
40766 @table @samp
40767 @item E @var{nn}
40768 for an error
40769 @item OK
40770 for success
40771 @end table
40772
40773 @item vFile:@var{operation}:@var{parameter}@dots{}
40774 @cindex @samp{vFile} packet
40775 Perform a file operation on the target system. For details,
40776 see @ref{Host I/O Packets}.
40777
40778 @item vFlashErase:@var{addr},@var{length}
40779 @cindex @samp{vFlashErase} packet
40780 Direct the stub to erase @var{length} bytes of flash starting at
40781 @var{addr}. The region may enclose any number of flash blocks, but
40782 its start and end must fall on block boundaries, as indicated by the
40783 flash block size appearing in the memory map (@pxref{Memory Map
40784 Format}). @value{GDBN} groups flash memory programming operations
40785 together, and sends a @samp{vFlashDone} request after each group; the
40786 stub is allowed to delay erase operation until the @samp{vFlashDone}
40787 packet is received.
40788
40789 Reply:
40790 @table @samp
40791 @item OK
40792 for success
40793 @item E @var{NN}
40794 for an error
40795 @end table
40796
40797 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
40798 @cindex @samp{vFlashWrite} packet
40799 Direct the stub to write data to flash address @var{addr}. The data
40800 is passed in binary form using the same encoding as for the @samp{X}
40801 packet (@pxref{Binary Data}). The memory ranges specified by
40802 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40803 not overlap, and must appear in order of increasing addresses
40804 (although @samp{vFlashErase} packets for higher addresses may already
40805 have been received; the ordering is guaranteed only between
40806 @samp{vFlashWrite} packets). If a packet writes to an address that was
40807 neither erased by a preceding @samp{vFlashErase} packet nor by some other
40808 target-specific method, the results are unpredictable.
40809
40810
40811 Reply:
40812 @table @samp
40813 @item OK
40814 for success
40815 @item E.memtype
40816 for vFlashWrite addressing non-flash memory
40817 @item E @var{NN}
40818 for an error
40819 @end table
40820
40821 @item vFlashDone
40822 @cindex @samp{vFlashDone} packet
40823 Indicate to the stub that flash programming operation is finished.
40824 The stub is permitted to delay or batch the effects of a group of
40825 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
40826 @samp{vFlashDone} packet is received. The contents of the affected
40827 regions of flash memory are unpredictable until the @samp{vFlashDone}
40828 request is completed.
40829
40830 @item vKill;@var{pid}
40831 @cindex @samp{vKill} packet
40832 @anchor{vKill packet}
40833 Kill the process with the specified process ID @var{pid}, which is a
40834 hexadecimal integer identifying the process. This packet is used in
40835 preference to @samp{k} when multiprocess protocol extensions are
40836 supported; see @ref{multiprocess extensions}.
40837
40838 Reply:
40839 @table @samp
40840 @item E @var{nn}
40841 for an error
40842 @item OK
40843 for success
40844 @end table
40845
40846 @item vMustReplyEmpty
40847 @cindex @samp{vMustReplyEmpty} packet
40848 The correct reply to an unknown @samp{v} packet is to return the empty
40849 string, however, some older versions of @command{gdbserver} would
40850 incorrectly return @samp{OK} for unknown @samp{v} packets.
40851
40852 The @samp{vMustReplyEmpty} is used as a feature test to check how
40853 @command{gdbserver} handles unknown packets, it is important that this
40854 packet be handled in the same way as other unknown @samp{v} packets.
40855 If this packet is handled differently to other unknown @samp{v}
40856 packets then it is possible that @value{GDBN} may run into problems in
40857 other areas, specifically around use of @samp{vFile:setfs:}.
40858
40859 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40860 @cindex @samp{vRun} packet
40861 Run the program @var{filename}, passing it each @var{argument} on its
40862 command line. The file and arguments are hex-encoded strings. If
40863 @var{filename} is an empty string, the stub may use a default program
40864 (e.g.@: the last program run). The program is created in the stopped
40865 state.
40866
40867 @c FIXME: What about non-stop mode?
40868
40869 This packet is only available in extended mode (@pxref{extended mode}).
40870
40871 Reply:
40872 @table @samp
40873 @item E @var{nn}
40874 for an error
40875 @item @r{Any stop packet}
40876 for success (@pxref{Stop Reply Packets})
40877 @end table
40878
40879 @item vStopped
40880 @cindex @samp{vStopped} packet
40881 @xref{Notification Packets}.
40882
40883 @item X @var{addr},@var{length}:@var{XX@dots{}}
40884 @anchor{X packet}
40885 @cindex @samp{X} packet
40886 Write data to memory, where the data is transmitted in binary.
40887 Memory is specified by its address @var{addr} and number of addressable memory
40888 units @var{length} (@pxref{addressable memory unit});
40889 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
40890
40891 Reply:
40892 @table @samp
40893 @item OK
40894 for success
40895 @item E @var{NN}
40896 for an error
40897 @end table
40898
40899 @item z @var{type},@var{addr},@var{kind}
40900 @itemx Z @var{type},@var{addr},@var{kind}
40901 @anchor{insert breakpoint or watchpoint packet}
40902 @cindex @samp{z} packet
40903 @cindex @samp{Z} packets
40904 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
40905 watchpoint starting at address @var{address} of kind @var{kind}.
40906
40907 Each breakpoint and watchpoint packet @var{type} is documented
40908 separately.
40909
40910 @emph{Implementation notes: A remote target shall return an empty string
40911 for an unrecognized breakpoint or watchpoint packet @var{type}. A
40912 remote target shall support either both or neither of a given
40913 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
40914 avoid potential problems with duplicate packets, the operations should
40915 be implemented in an idempotent way.}
40916
40917 @item z0,@var{addr},@var{kind}
40918 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40919 @cindex @samp{z0} packet
40920 @cindex @samp{Z0} packet
40921 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
40922 @var{addr} of type @var{kind}.
40923
40924 A software breakpoint is implemented by replacing the instruction at
40925 @var{addr} with a software breakpoint or trap instruction. The
40926 @var{kind} is target-specific and typically indicates the size of the
40927 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40928 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40929 architectures have additional meanings for @var{kind}
40930 (@pxref{Architecture-Specific Protocol Details}); if no
40931 architecture-specific value is being used, it should be @samp{0}.
40932 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
40933 conditional expressions in bytecode form that should be evaluated on
40934 the target's side. These are the conditions that should be taken into
40935 consideration when deciding if the breakpoint trigger should be
40936 reported back to @value{GDBN}.
40937
40938 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
40939 for how to best report a software breakpoint event to @value{GDBN}.
40940
40941 The @var{cond_list} parameter is comprised of a series of expressions,
40942 concatenated without separators. Each expression has the following form:
40943
40944 @table @samp
40945
40946 @item X @var{len},@var{expr}
40947 @var{len} is the length of the bytecode expression and @var{expr} is the
40948 actual conditional expression in bytecode form.
40949
40950 @end table
40951
40952 The optional @var{cmd_list} parameter introduces commands that may be
40953 run on the target, rather than being reported back to @value{GDBN}.
40954 The parameter starts with a numeric flag @var{persist}; if the flag is
40955 nonzero, then the breakpoint may remain active and the commands
40956 continue to be run even when @value{GDBN} disconnects from the target.
40957 Following this flag is a series of expressions concatenated with no
40958 separators. Each expression has the following form:
40959
40960 @table @samp
40961
40962 @item X @var{len},@var{expr}
40963 @var{len} is the length of the bytecode expression and @var{expr} is the
40964 actual commands expression in bytecode form.
40965
40966 @end table
40967
40968 @emph{Implementation note: It is possible for a target to copy or move
40969 code that contains software breakpoints (e.g., when implementing
40970 overlays). The behavior of this packet, in the presence of such a
40971 target, is not defined.}
40972
40973 Reply:
40974 @table @samp
40975 @item OK
40976 success
40977 @item @w{}
40978 not supported
40979 @item E @var{NN}
40980 for an error
40981 @end table
40982
40983 @item z1,@var{addr},@var{kind}
40984 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40985 @cindex @samp{z1} packet
40986 @cindex @samp{Z1} packet
40987 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
40988 address @var{addr}.
40989
40990 A hardware breakpoint is implemented using a mechanism that is not
40991 dependent on being able to modify the target's memory. The
40992 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40993 same meaning as in @samp{Z0} packets.
40994
40995 @emph{Implementation note: A hardware breakpoint is not affected by code
40996 movement.}
40997
40998 Reply:
40999 @table @samp
41000 @item OK
41001 success
41002 @item @w{}
41003 not supported
41004 @item E @var{NN}
41005 for an error
41006 @end table
41007
41008 @item z2,@var{addr},@var{kind}
41009 @itemx Z2,@var{addr},@var{kind}
41010 @cindex @samp{z2} packet
41011 @cindex @samp{Z2} packet
41012 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
41013 The number of bytes to watch is specified by @var{kind}.
41014
41015 Reply:
41016 @table @samp
41017 @item OK
41018 success
41019 @item @w{}
41020 not supported
41021 @item E @var{NN}
41022 for an error
41023 @end table
41024
41025 @item z3,@var{addr},@var{kind}
41026 @itemx Z3,@var{addr},@var{kind}
41027 @cindex @samp{z3} packet
41028 @cindex @samp{Z3} packet
41029 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
41030 The number of bytes to watch is specified by @var{kind}.
41031
41032 Reply:
41033 @table @samp
41034 @item OK
41035 success
41036 @item @w{}
41037 not supported
41038 @item E @var{NN}
41039 for an error
41040 @end table
41041
41042 @item z4,@var{addr},@var{kind}
41043 @itemx Z4,@var{addr},@var{kind}
41044 @cindex @samp{z4} packet
41045 @cindex @samp{Z4} packet
41046 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
41047 The number of bytes to watch is specified by @var{kind}.
41048
41049 Reply:
41050 @table @samp
41051 @item OK
41052 success
41053 @item @w{}
41054 not supported
41055 @item E @var{NN}
41056 for an error
41057 @end table
41058
41059 @end table
41060
41061 @node Stop Reply Packets
41062 @section Stop Reply Packets
41063 @cindex stop reply packets
41064
41065 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
41066 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
41067 receive any of the below as a reply. Except for @samp{?}
41068 and @samp{vStopped}, that reply is only returned
41069 when the target halts. In the below the exact meaning of @dfn{signal
41070 number} is defined by the header @file{include/gdb/signals.h} in the
41071 @value{GDBN} source code.
41072
41073 In non-stop mode, the server will simply reply @samp{OK} to commands
41074 such as @samp{vCont}; any stop will be the subject of a future
41075 notification. @xref{Remote Non-Stop}.
41076
41077 As in the description of request packets, we include spaces in the
41078 reply templates for clarity; these are not part of the reply packet's
41079 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
41080 components.
41081
41082 @table @samp
41083
41084 @item S @var{AA}
41085 The program received signal number @var{AA} (a two-digit hexadecimal
41086 number). This is equivalent to a @samp{T} response with no
41087 @var{n}:@var{r} pairs.
41088
41089 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
41090 @cindex @samp{T} packet reply
41091 The program received signal number @var{AA} (a two-digit hexadecimal
41092 number). This is equivalent to an @samp{S} response, except that the
41093 @samp{@var{n}:@var{r}} pairs can carry values of important registers
41094 and other information directly in the stop reply packet, reducing
41095 round-trip latency. Single-step and breakpoint traps are reported
41096 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
41097
41098 @itemize @bullet
41099 @item
41100 If @var{n} is a hexadecimal number, it is a register number, and the
41101 corresponding @var{r} gives that register's value. The data @var{r} is a
41102 series of bytes in target byte order, with each byte given by a
41103 two-digit hex number.
41104
41105 @item
41106 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
41107 the stopped thread, as specified in @ref{thread-id syntax}.
41108
41109 @item
41110 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
41111 the core on which the stop event was detected.
41112
41113 @item
41114 If @var{n} is a recognized @dfn{stop reason}, it describes a more
41115 specific event that stopped the target. The currently defined stop
41116 reasons are listed below. The @var{aa} should be @samp{05}, the trap
41117 signal. At most one stop reason should be present.
41118
41119 @item
41120 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
41121 and go on to the next; this allows us to extend the protocol in the
41122 future.
41123 @end itemize
41124
41125 The currently defined stop reasons are:
41126
41127 @table @samp
41128 @item watch
41129 @itemx rwatch
41130 @itemx awatch
41131 The packet indicates a watchpoint hit, and @var{r} is the data address, in
41132 hex.
41133
41134 @item syscall_entry
41135 @itemx syscall_return
41136 The packet indicates a syscall entry or return, and @var{r} is the
41137 syscall number, in hex.
41138
41139 @cindex shared library events, remote reply
41140 @item library
41141 The packet indicates that the loaded libraries have changed.
41142 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
41143 list of loaded libraries. The @var{r} part is ignored.
41144
41145 @cindex replay log events, remote reply
41146 @item replaylog
41147 The packet indicates that the target cannot continue replaying
41148 logged execution events, because it has reached the end (or the
41149 beginning when executing backward) of the log. The value of @var{r}
41150 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
41151 for more information.
41152
41153 @item swbreak
41154 @anchor{swbreak stop reason}
41155 The packet indicates a software breakpoint instruction was executed,
41156 irrespective of whether it was @value{GDBN} that planted the
41157 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
41158 part must be left empty.
41159
41160 On some architectures, such as x86, at the architecture level, when a
41161 breakpoint instruction executes the program counter points at the
41162 breakpoint address plus an offset. On such targets, the stub is
41163 responsible for adjusting the PC to point back at the breakpoint
41164 address.
41165
41166 This packet should not be sent by default; older @value{GDBN} versions
41167 did not support it. @value{GDBN} requests it, by supplying an
41168 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41169 remote stub must also supply the appropriate @samp{qSupported} feature
41170 indicating support.
41171
41172 This packet is required for correct non-stop mode operation.
41173
41174 @item hwbreak
41175 The packet indicates the target stopped for a hardware breakpoint.
41176 The @var{r} part must be left empty.
41177
41178 The same remarks about @samp{qSupported} and non-stop mode above
41179 apply.
41180
41181 @cindex fork events, remote reply
41182 @item fork
41183 The packet indicates that @code{fork} was called, and @var{r}
41184 is the thread ID of the new child process. Refer to
41185 @ref{thread-id syntax} for the format of the @var{thread-id}
41186 field. This packet is only applicable to targets that support
41187 fork events.
41188
41189 This packet should not be sent by default; older @value{GDBN} versions
41190 did not support it. @value{GDBN} requests it, by supplying an
41191 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41192 remote stub must also supply the appropriate @samp{qSupported} feature
41193 indicating support.
41194
41195 @cindex vfork events, remote reply
41196 @item vfork
41197 The packet indicates that @code{vfork} was called, and @var{r}
41198 is the thread ID of the new child process. Refer to
41199 @ref{thread-id syntax} for the format of the @var{thread-id}
41200 field. This packet is only applicable to targets that support
41201 vfork events.
41202
41203 This packet should not be sent by default; older @value{GDBN} versions
41204 did not support it. @value{GDBN} requests it, by supplying an
41205 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41206 remote stub must also supply the appropriate @samp{qSupported} feature
41207 indicating support.
41208
41209 @cindex vforkdone events, remote reply
41210 @item vforkdone
41211 The packet indicates that a child process created by a vfork
41212 has either called @code{exec} or terminated, so that the
41213 address spaces of the parent and child process are no longer
41214 shared. The @var{r} part is ignored. This packet is only
41215 applicable to targets that support vforkdone events.
41216
41217 This packet should not be sent by default; older @value{GDBN} versions
41218 did not support it. @value{GDBN} requests it, by supplying an
41219 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41220 remote stub must also supply the appropriate @samp{qSupported} feature
41221 indicating support.
41222
41223 @cindex exec events, remote reply
41224 @item exec
41225 The packet indicates that @code{execve} was called, and @var{r}
41226 is the absolute pathname of the file that was executed, in hex.
41227 This packet is only applicable to targets that support exec events.
41228
41229 This packet should not be sent by default; older @value{GDBN} versions
41230 did not support it. @value{GDBN} requests it, by supplying an
41231 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
41232 remote stub must also supply the appropriate @samp{qSupported} feature
41233 indicating support.
41234
41235 @cindex thread create event, remote reply
41236 @anchor{thread create event}
41237 @item create
41238 The packet indicates that the thread was just created. The new thread
41239 is stopped until @value{GDBN} sets it running with a resumption packet
41240 (@pxref{vCont packet}). This packet should not be sent by default;
41241 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
41242 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
41243 @var{r} part is ignored.
41244
41245 @end table
41246
41247 @item W @var{AA}
41248 @itemx W @var{AA} ; process:@var{pid}
41249 The process exited, and @var{AA} is the exit status. This is only
41250 applicable to certain targets.
41251
41252 The second form of the response, including the process ID of the
41253 exited process, can be used only when @value{GDBN} has reported
41254 support for multiprocess protocol extensions; see @ref{multiprocess
41255 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
41256 hex strings.
41257
41258 @item X @var{AA}
41259 @itemx X @var{AA} ; process:@var{pid}
41260 The process terminated with signal @var{AA}.
41261
41262 The second form of the response, including the process ID of the
41263 terminated process, can be used only when @value{GDBN} has reported
41264 support for multiprocess protocol extensions; see @ref{multiprocess
41265 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
41266 hex strings.
41267
41268 @anchor{thread exit event}
41269 @cindex thread exit event, remote reply
41270 @item w @var{AA} ; @var{tid}
41271
41272 The thread exited, and @var{AA} is the exit status. This response
41273 should not be sent by default; @value{GDBN} requests it with the
41274 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
41275 @var{AA} is formatted as a big-endian hex string.
41276
41277 @item N
41278 There are no resumed threads left in the target. In other words, even
41279 though the process is alive, the last resumed thread has exited. For
41280 example, say the target process has two threads: thread 1 and thread
41281 2. The client leaves thread 1 stopped, and resumes thread 2, which
41282 subsequently exits. At this point, even though the process is still
41283 alive, and thus no @samp{W} stop reply is sent, no thread is actually
41284 executing either. The @samp{N} stop reply thus informs the client
41285 that it can stop waiting for stop replies. This packet should not be
41286 sent by default; older @value{GDBN} versions did not support it.
41287 @value{GDBN} requests it, by supplying an appropriate
41288 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
41289 also supply the appropriate @samp{qSupported} feature indicating
41290 support.
41291
41292 @item O @var{XX}@dots{}
41293 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
41294 written as the program's console output. This can happen at any time
41295 while the program is running and the debugger should continue to wait
41296 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
41297
41298 @item F @var{call-id},@var{parameter}@dots{}
41299 @var{call-id} is the identifier which says which host system call should
41300 be called. This is just the name of the function. Translation into the
41301 correct system call is only applicable as it's defined in @value{GDBN}.
41302 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
41303 system calls.
41304
41305 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
41306 this very system call.
41307
41308 The target replies with this packet when it expects @value{GDBN} to
41309 call a host system call on behalf of the target. @value{GDBN} replies
41310 with an appropriate @samp{F} packet and keeps up waiting for the next
41311 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
41312 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
41313 Protocol Extension}, for more details.
41314
41315 @end table
41316
41317 @node General Query Packets
41318 @section General Query Packets
41319 @cindex remote query requests
41320
41321 Packets starting with @samp{q} are @dfn{general query packets};
41322 packets starting with @samp{Q} are @dfn{general set packets}. General
41323 query and set packets are a semi-unified form for retrieving and
41324 sending information to and from the stub.
41325
41326 The initial letter of a query or set packet is followed by a name
41327 indicating what sort of thing the packet applies to. For example,
41328 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
41329 definitions with the stub. These packet names follow some
41330 conventions:
41331
41332 @itemize @bullet
41333 @item
41334 The name must not contain commas, colons or semicolons.
41335 @item
41336 Most @value{GDBN} query and set packets have a leading upper case
41337 letter.
41338 @item
41339 The names of custom vendor packets should use a company prefix, in
41340 lower case, followed by a period. For example, packets designed at
41341 the Acme Corporation might begin with @samp{qacme.foo} (for querying
41342 foos) or @samp{Qacme.bar} (for setting bars).
41343 @end itemize
41344
41345 The name of a query or set packet should be separated from any
41346 parameters by a @samp{:}; the parameters themselves should be
41347 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
41348 full packet name, and check for a separator or the end of the packet,
41349 in case two packet names share a common prefix. New packets should not begin
41350 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
41351 packets predate these conventions, and have arguments without any terminator
41352 for the packet name; we suspect they are in widespread use in places that
41353 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
41354 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
41355 packet.}.
41356
41357 Like the descriptions of the other packets, each description here
41358 has a template showing the packet's overall syntax, followed by an
41359 explanation of the packet's meaning. We include spaces in some of the
41360 templates for clarity; these are not part of the packet's syntax. No
41361 @value{GDBN} packet uses spaces to separate its components.
41362
41363 Here are the currently defined query and set packets:
41364
41365 @table @samp
41366
41367 @item QAgent:1
41368 @itemx QAgent:0
41369 Turn on or off the agent as a helper to perform some debugging operations
41370 delegated from @value{GDBN} (@pxref{Control Agent}).
41371
41372 @item QAllow:@var{op}:@var{val}@dots{}
41373 @cindex @samp{QAllow} packet
41374 Specify which operations @value{GDBN} expects to request of the
41375 target, as a semicolon-separated list of operation name and value
41376 pairs. Possible values for @var{op} include @samp{WriteReg},
41377 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
41378 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
41379 indicating that @value{GDBN} will not request the operation, or 1,
41380 indicating that it may. (The target can then use this to set up its
41381 own internals optimally, for instance if the debugger never expects to
41382 insert breakpoints, it may not need to install its own trap handler.)
41383
41384 @item qC
41385 @cindex current thread, remote request
41386 @cindex @samp{qC} packet
41387 Return the current thread ID.
41388
41389 Reply:
41390 @table @samp
41391 @item QC @var{thread-id}
41392 Where @var{thread-id} is a thread ID as documented in
41393 @ref{thread-id syntax}.
41394 @item @r{(anything else)}
41395 Any other reply implies the old thread ID.
41396 @end table
41397
41398 @item qCRC:@var{addr},@var{length}
41399 @cindex CRC of memory block, remote request
41400 @cindex @samp{qCRC} packet
41401 @anchor{qCRC packet}
41402 Compute the CRC checksum of a block of memory using CRC-32 defined in
41403 IEEE 802.3. The CRC is computed byte at a time, taking the most
41404 significant bit of each byte first. The initial pattern code
41405 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
41406
41407 @emph{Note:} This is the same CRC used in validating separate debug
41408 files (@pxref{Separate Debug Files, , Debugging Information in Separate
41409 Files}). However the algorithm is slightly different. When validating
41410 separate debug files, the CRC is computed taking the @emph{least}
41411 significant bit of each byte first, and the final result is inverted to
41412 detect trailing zeros.
41413
41414 Reply:
41415 @table @samp
41416 @item E @var{NN}
41417 An error (such as memory fault)
41418 @item C @var{crc32}
41419 The specified memory region's checksum is @var{crc32}.
41420 @end table
41421
41422 @item QDisableRandomization:@var{value}
41423 @cindex disable address space randomization, remote request
41424 @cindex @samp{QDisableRandomization} packet
41425 Some target operating systems will randomize the virtual address space
41426 of the inferior process as a security feature, but provide a feature
41427 to disable such randomization, e.g.@: to allow for a more deterministic
41428 debugging experience. On such systems, this packet with a @var{value}
41429 of 1 directs the target to disable address space randomization for
41430 processes subsequently started via @samp{vRun} packets, while a packet
41431 with a @var{value} of 0 tells the target to enable address space
41432 randomization.
41433
41434 This packet is only available in extended mode (@pxref{extended mode}).
41435
41436 Reply:
41437 @table @samp
41438 @item OK
41439 The request succeeded.
41440
41441 @item E @var{nn}
41442 An error occurred. The error number @var{nn} is given as hex digits.
41443
41444 @item @w{}
41445 An empty reply indicates that @samp{QDisableRandomization} is not supported
41446 by the stub.
41447 @end table
41448
41449 This packet is not probed by default; the remote stub must request it,
41450 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41451 This should only be done on targets that actually support disabling
41452 address space randomization.
41453
41454 @item QStartupWithShell:@var{value}
41455 @cindex startup with shell, remote request
41456 @cindex @samp{QStartupWithShell} packet
41457 On UNIX-like targets, it is possible to start the inferior using a
41458 shell program. This is the default behavior on both @value{GDBN} and
41459 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
41460 used to inform @command{gdbserver} whether it should start the
41461 inferior using a shell or not.
41462
41463 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
41464 to start the inferior. If @var{value} is @samp{1},
41465 @command{gdbserver} will use a shell to start the inferior. All other
41466 values are considered an error.
41467
41468 This packet is only available in extended mode (@pxref{extended
41469 mode}).
41470
41471 Reply:
41472 @table @samp
41473 @item OK
41474 The request succeeded.
41475
41476 @item E @var{nn}
41477 An error occurred. The error number @var{nn} is given as hex digits.
41478 @end table
41479
41480 This packet is not probed by default; the remote stub must request it,
41481 by supplying an appropriate @samp{qSupported} response
41482 (@pxref{qSupported}). This should only be done on targets that
41483 actually support starting the inferior using a shell.
41484
41485 Use of this packet is controlled by the @code{set startup-with-shell}
41486 command; @pxref{set startup-with-shell}.
41487
41488 @item QEnvironmentHexEncoded:@var{hex-value}
41489 @anchor{QEnvironmentHexEncoded}
41490 @cindex set environment variable, remote request
41491 @cindex @samp{QEnvironmentHexEncoded} packet
41492 On UNIX-like targets, it is possible to set environment variables that
41493 will be passed to the inferior during the startup process. This
41494 packet is used to inform @command{gdbserver} of an environment
41495 variable that has been defined by the user on @value{GDBN} (@pxref{set
41496 environment}).
41497
41498 The packet is composed by @var{hex-value}, an hex encoded
41499 representation of the @var{name=value} format representing an
41500 environment variable. The name of the environment variable is
41501 represented by @var{name}, and the value to be assigned to the
41502 environment variable is represented by @var{value}. If the variable
41503 has no value (i.e., the value is @code{null}), then @var{value} will
41504 not be present.
41505
41506 This packet is only available in extended mode (@pxref{extended
41507 mode}).
41508
41509 Reply:
41510 @table @samp
41511 @item OK
41512 The request succeeded.
41513 @end table
41514
41515 This packet is not probed by default; the remote stub must request it,
41516 by supplying an appropriate @samp{qSupported} response
41517 (@pxref{qSupported}). This should only be done on targets that
41518 actually support passing environment variables to the starting
41519 inferior.
41520
41521 This packet is related to the @code{set environment} command;
41522 @pxref{set environment}.
41523
41524 @item QEnvironmentUnset:@var{hex-value}
41525 @anchor{QEnvironmentUnset}
41526 @cindex unset environment variable, remote request
41527 @cindex @samp{QEnvironmentUnset} packet
41528 On UNIX-like targets, it is possible to unset environment variables
41529 before starting the inferior in the remote target. This packet is
41530 used to inform @command{gdbserver} of an environment variable that has
41531 been unset by the user on @value{GDBN} (@pxref{unset environment}).
41532
41533 The packet is composed by @var{hex-value}, an hex encoded
41534 representation of the name of the environment variable to be unset.
41535
41536 This packet is only available in extended mode (@pxref{extended
41537 mode}).
41538
41539 Reply:
41540 @table @samp
41541 @item OK
41542 The request succeeded.
41543 @end table
41544
41545 This packet is not probed by default; the remote stub must request it,
41546 by supplying an appropriate @samp{qSupported} response
41547 (@pxref{qSupported}). This should only be done on targets that
41548 actually support passing environment variables to the starting
41549 inferior.
41550
41551 This packet is related to the @code{unset environment} command;
41552 @pxref{unset environment}.
41553
41554 @item QEnvironmentReset
41555 @anchor{QEnvironmentReset}
41556 @cindex reset environment, remote request
41557 @cindex @samp{QEnvironmentReset} packet
41558 On UNIX-like targets, this packet is used to reset the state of
41559 environment variables in the remote target before starting the
41560 inferior. In this context, reset means unsetting all environment
41561 variables that were previously set by the user (i.e., were not
41562 initially present in the environment). It is sent to
41563 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
41564 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
41565 (@pxref{QEnvironmentUnset}) packets.
41566
41567 This packet is only available in extended mode (@pxref{extended
41568 mode}).
41569
41570 Reply:
41571 @table @samp
41572 @item OK
41573 The request succeeded.
41574 @end table
41575
41576 This packet is not probed by default; the remote stub must request it,
41577 by supplying an appropriate @samp{qSupported} response
41578 (@pxref{qSupported}). This should only be done on targets that
41579 actually support passing environment variables to the starting
41580 inferior.
41581
41582 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
41583 @anchor{QSetWorkingDir packet}
41584 @cindex set working directory, remote request
41585 @cindex @samp{QSetWorkingDir} packet
41586 This packet is used to inform the remote server of the intended
41587 current working directory for programs that are going to be executed.
41588
41589 The packet is composed by @var{directory}, an hex encoded
41590 representation of the directory that the remote inferior will use as
41591 its current working directory. If @var{directory} is an empty string,
41592 the remote server should reset the inferior's current working
41593 directory to its original, empty value.
41594
41595 This packet is only available in extended mode (@pxref{extended
41596 mode}).
41597
41598 Reply:
41599 @table @samp
41600 @item OK
41601 The request succeeded.
41602 @end table
41603
41604 @item qfThreadInfo
41605 @itemx qsThreadInfo
41606 @cindex list active threads, remote request
41607 @cindex @samp{qfThreadInfo} packet
41608 @cindex @samp{qsThreadInfo} packet
41609 Obtain a list of all active thread IDs from the target (OS). Since there
41610 may be too many active threads to fit into one reply packet, this query
41611 works iteratively: it may require more than one query/reply sequence to
41612 obtain the entire list of threads. The first query of the sequence will
41613 be the @samp{qfThreadInfo} query; subsequent queries in the
41614 sequence will be the @samp{qsThreadInfo} query.
41615
41616 NOTE: This packet replaces the @samp{qL} query (see below).
41617
41618 Reply:
41619 @table @samp
41620 @item m @var{thread-id}
41621 A single thread ID
41622 @item m @var{thread-id},@var{thread-id}@dots{}
41623 a comma-separated list of thread IDs
41624 @item l
41625 (lower case letter @samp{L}) denotes end of list.
41626 @end table
41627
41628 In response to each query, the target will reply with a list of one or
41629 more thread IDs, separated by commas.
41630 @value{GDBN} will respond to each reply with a request for more thread
41631 ids (using the @samp{qs} form of the query), until the target responds
41632 with @samp{l} (lower-case ell, for @dfn{last}).
41633 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
41634 fields.
41635
41636 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
41637 initial connection with the remote target, and the very first thread ID
41638 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
41639 message. Therefore, the stub should ensure that the first thread ID in
41640 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
41641
41642 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
41643 @cindex get thread-local storage address, remote request
41644 @cindex @samp{qGetTLSAddr} packet
41645 Fetch the address associated with thread local storage specified
41646 by @var{thread-id}, @var{offset}, and @var{lm}.
41647
41648 @var{thread-id} is the thread ID associated with the
41649 thread for which to fetch the TLS address. @xref{thread-id syntax}.
41650
41651 @var{offset} is the (big endian, hex encoded) offset associated with the
41652 thread local variable. (This offset is obtained from the debug
41653 information associated with the variable.)
41654
41655 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
41656 load module associated with the thread local storage. For example,
41657 a @sc{gnu}/Linux system will pass the link map address of the shared
41658 object associated with the thread local storage under consideration.
41659 Other operating environments may choose to represent the load module
41660 differently, so the precise meaning of this parameter will vary.
41661
41662 Reply:
41663 @table @samp
41664 @item @var{XX}@dots{}
41665 Hex encoded (big endian) bytes representing the address of the thread
41666 local storage requested.
41667
41668 @item E @var{nn}
41669 An error occurred. The error number @var{nn} is given as hex digits.
41670
41671 @item @w{}
41672 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
41673 @end table
41674
41675 @item qGetTIBAddr:@var{thread-id}
41676 @cindex get thread information block address
41677 @cindex @samp{qGetTIBAddr} packet
41678 Fetch address of the Windows OS specific Thread Information Block.
41679
41680 @var{thread-id} is the thread ID associated with the thread.
41681
41682 Reply:
41683 @table @samp
41684 @item @var{XX}@dots{}
41685 Hex encoded (big endian) bytes representing the linear address of the
41686 thread information block.
41687
41688 @item E @var{nn}
41689 An error occured. This means that either the thread was not found, or the
41690 address could not be retrieved.
41691
41692 @item @w{}
41693 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
41694 @end table
41695
41696 @item qL @var{startflag} @var{threadcount} @var{nextthread}
41697 Obtain thread information from RTOS. Where: @var{startflag} (one hex
41698 digit) is one to indicate the first query and zero to indicate a
41699 subsequent query; @var{threadcount} (two hex digits) is the maximum
41700 number of threads the response packet can contain; and @var{nextthread}
41701 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
41702 returned in the response as @var{argthread}.
41703
41704 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
41705
41706 Reply:
41707 @table @samp
41708 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
41709 Where: @var{count} (two hex digits) is the number of threads being
41710 returned; @var{done} (one hex digit) is zero to indicate more threads
41711 and one indicates no further threads; @var{argthreadid} (eight hex
41712 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
41713 is a sequence of thread IDs, @var{threadid} (eight hex
41714 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
41715 @end table
41716
41717 @item qMemTags:@var{start address},@var{length}:@var{type}
41718 @anchor{qMemTags}
41719 @cindex fetch memory tags
41720 @cindex @samp{qMemTags} packet
41721 Fetch memory tags of type @var{type} from the address range
41722 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41723 target is responsible for calculating how many tags will be returned, as this
41724 is architecture-specific.
41725
41726 @var{start address} is the starting address of the memory range.
41727
41728 @var{length} is the length, in bytes, of the memory range.
41729
41730 @var{type} is the type of tag the request wants to fetch. The type is a signed
41731 integer.
41732
41733 Reply:
41734 @table @samp
41735 @item @var{mxx}@dots{}
41736 Hex encoded sequence of uninterpreted bytes, @var{xx}@dots{}, representing the
41737 tags found in the requested memory range.
41738
41739 @item E @var{nn}
41740 An error occured. This means that fetching of memory tags failed for some
41741 reason.
41742
41743 @item @w{}
41744 An empty reply indicates that @samp{qMemTags} is not supported by the stub,
41745 although this should not happen given @value{GDBN} will only send this packet
41746 if the stub has advertised support for memory tagging via @samp{qSupported}.
41747 @end table
41748
41749 @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes}
41750 @anchor{QMemTags}
41751 @cindex store memory tags
41752 @cindex @samp{QMemTags} packet
41753 Store memory tags of type @var{type} to the address range
41754 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41755 target is responsible for interpreting the type, the tag bytes and modifying
41756 the memory tag granules accordingly, given this is architecture-specific.
41757
41758 The interpretation of how many tags (@var{nt}) should be written to how many
41759 memory tag granules (@var{ng}) is also architecture-specific. The behavior is
41760 implementation-specific, but the following is suggested.
41761
41762 If the number of memory tags, @var{nt}, is greater than or equal to the
41763 number of memory tag granules, @var{ng}, only @var{ng} tags will be
41764 stored.
41765
41766 If @var{nt} is less than @var{ng}, the behavior is that of a fill operation,
41767 and the tag bytes will be used as a pattern that will get repeated until
41768 @var{ng} tags are stored.
41769
41770 @var{start address} is the starting address of the memory range. The address
41771 does not have any restriction on alignment or size.
41772
41773 @var{length} is the length, in bytes, of the memory range.
41774
41775 @var{type} is the type of tag the request wants to fetch. The type is a signed
41776 integer.
41777
41778 @var{tag bytes} is a sequence of hex encoded uninterpreted bytes which will be
41779 interpreted by the target. Each pair of hex digits is interpreted as a
41780 single byte.
41781
41782 Reply:
41783 @table @samp
41784 @item OK
41785 The request was successful and the memory tag granules were modified
41786 accordingly.
41787
41788 @item E @var{nn}
41789 An error occured. This means that modifying the memory tag granules failed
41790 for some reason.
41791
41792 @item @w{}
41793 An empty reply indicates that @samp{QMemTags} is not supported by the stub,
41794 although this should not happen given @value{GDBN} will only send this packet
41795 if the stub has advertised support for memory tagging via @samp{qSupported}.
41796 @end table
41797
41798 @item qOffsets
41799 @cindex section offsets, remote request
41800 @cindex @samp{qOffsets} packet
41801 Get section offsets that the target used when relocating the downloaded
41802 image.
41803
41804 Reply:
41805 @table @samp
41806 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
41807 Relocate the @code{Text} section by @var{xxx} from its original address.
41808 Relocate the @code{Data} section by @var{yyy} from its original address.
41809 If the object file format provides segment information (e.g.@: @sc{elf}
41810 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
41811 segments by the supplied offsets.
41812
41813 @emph{Note: while a @code{Bss} offset may be included in the response,
41814 @value{GDBN} ignores this and instead applies the @code{Data} offset
41815 to the @code{Bss} section.}
41816
41817 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
41818 Relocate the first segment of the object file, which conventionally
41819 contains program code, to a starting address of @var{xxx}. If
41820 @samp{DataSeg} is specified, relocate the second segment, which
41821 conventionally contains modifiable data, to a starting address of
41822 @var{yyy}. @value{GDBN} will report an error if the object file
41823 does not contain segment information, or does not contain at least
41824 as many segments as mentioned in the reply. Extra segments are
41825 kept at fixed offsets relative to the last relocated segment.
41826 @end table
41827
41828 @item qP @var{mode} @var{thread-id}
41829 @cindex thread information, remote request
41830 @cindex @samp{qP} packet
41831 Returns information on @var{thread-id}. Where: @var{mode} is a hex
41832 encoded 32 bit mode; @var{thread-id} is a thread ID
41833 (@pxref{thread-id syntax}).
41834
41835 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
41836 (see below).
41837
41838 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
41839
41840 @item QNonStop:1
41841 @itemx QNonStop:0
41842 @cindex non-stop mode, remote request
41843 @cindex @samp{QNonStop} packet
41844 @anchor{QNonStop}
41845 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
41846 @xref{Remote Non-Stop}, for more information.
41847
41848 Reply:
41849 @table @samp
41850 @item OK
41851 The request succeeded.
41852
41853 @item E @var{nn}
41854 An error occurred. The error number @var{nn} is given as hex digits.
41855
41856 @item @w{}
41857 An empty reply indicates that @samp{QNonStop} is not supported by
41858 the stub.
41859 @end table
41860
41861 This packet is not probed by default; the remote stub must request it,
41862 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41863 Use of this packet is controlled by the @code{set non-stop} command;
41864 @pxref{Non-Stop Mode}.
41865
41866 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41867 @itemx QCatchSyscalls:0
41868 @cindex catch syscalls from inferior, remote request
41869 @cindex @samp{QCatchSyscalls} packet
41870 @anchor{QCatchSyscalls}
41871 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41872 catching syscalls from the inferior process.
41873
41874 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41875 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41876 is listed, every system call should be reported.
41877
41878 Note that if a syscall not in the list is reported, @value{GDBN} will
41879 still filter the event according to its own list from all corresponding
41880 @code{catch syscall} commands. However, it is more efficient to only
41881 report the requested syscalls.
41882
41883 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41884 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
41885
41886 If the inferior process execs, the state of @samp{QCatchSyscalls} is
41887 kept for the new process too. On targets where exec may affect syscall
41888 numbers, for example with exec between 32 and 64-bit processes, the
41889 client should send a new packet with the new syscall list.
41890
41891 Reply:
41892 @table @samp
41893 @item OK
41894 The request succeeded.
41895
41896 @item E @var{nn}
41897 An error occurred. @var{nn} are hex digits.
41898
41899 @item @w{}
41900 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41901 the stub.
41902 @end table
41903
41904 Use of this packet is controlled by the @code{set remote catch-syscalls}
41905 command (@pxref{Remote Configuration, set remote catch-syscalls}).
41906 This packet is not probed by default; the remote stub must request it,
41907 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41908
41909 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41910 @cindex pass signals to inferior, remote request
41911 @cindex @samp{QPassSignals} packet
41912 @anchor{QPassSignals}
41913 Each listed @var{signal} should be passed directly to the inferior process.
41914 Signals are numbered identically to continue packets and stop replies
41915 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41916 strictly greater than the previous item. These signals do not need to stop
41917 the inferior, or be reported to @value{GDBN}. All other signals should be
41918 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41919 combine; any earlier @samp{QPassSignals} list is completely replaced by the
41920 new list. This packet improves performance when using @samp{handle
41921 @var{signal} nostop noprint pass}.
41922
41923 Reply:
41924 @table @samp
41925 @item OK
41926 The request succeeded.
41927
41928 @item E @var{nn}
41929 An error occurred. The error number @var{nn} is given as hex digits.
41930
41931 @item @w{}
41932 An empty reply indicates that @samp{QPassSignals} is not supported by
41933 the stub.
41934 @end table
41935
41936 Use of this packet is controlled by the @code{set remote pass-signals}
41937 command (@pxref{Remote Configuration, set remote pass-signals}).
41938 This packet is not probed by default; the remote stub must request it,
41939 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41940
41941 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41942 @cindex signals the inferior may see, remote request
41943 @cindex @samp{QProgramSignals} packet
41944 @anchor{QProgramSignals}
41945 Each listed @var{signal} may be delivered to the inferior process.
41946 Others should be silently discarded.
41947
41948 In some cases, the remote stub may need to decide whether to deliver a
41949 signal to the program or not without @value{GDBN} involvement. One
41950 example of that is while detaching --- the program's threads may have
41951 stopped for signals that haven't yet had a chance of being reported to
41952 @value{GDBN}, and so the remote stub can use the signal list specified
41953 by this packet to know whether to deliver or ignore those pending
41954 signals.
41955
41956 This does not influence whether to deliver a signal as requested by a
41957 resumption packet (@pxref{vCont packet}).
41958
41959 Signals are numbered identically to continue packets and stop replies
41960 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41961 strictly greater than the previous item. Multiple
41962 @samp{QProgramSignals} packets do not combine; any earlier
41963 @samp{QProgramSignals} list is completely replaced by the new list.
41964
41965 Reply:
41966 @table @samp
41967 @item OK
41968 The request succeeded.
41969
41970 @item E @var{nn}
41971 An error occurred. The error number @var{nn} is given as hex digits.
41972
41973 @item @w{}
41974 An empty reply indicates that @samp{QProgramSignals} is not supported
41975 by the stub.
41976 @end table
41977
41978 Use of this packet is controlled by the @code{set remote program-signals}
41979 command (@pxref{Remote Configuration, set remote program-signals}).
41980 This packet is not probed by default; the remote stub must request it,
41981 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41982
41983 @anchor{QThreadEvents}
41984 @item QThreadEvents:1
41985 @itemx QThreadEvents:0
41986 @cindex thread create/exit events, remote request
41987 @cindex @samp{QThreadEvents} packet
41988
41989 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41990 reporting of thread create and exit events. @xref{thread create
41991 event}, for the reply specifications. For example, this is used in
41992 non-stop mode when @value{GDBN} stops a set of threads and
41993 synchronously waits for the their corresponding stop replies. Without
41994 exit events, if one of the threads exits, @value{GDBN} would hang
41995 forever not knowing that it should no longer expect a stop for that
41996 same thread. @value{GDBN} does not enable this feature unless the
41997 stub reports that it supports it by including @samp{QThreadEvents+} in
41998 its @samp{qSupported} reply.
41999
42000 Reply:
42001 @table @samp
42002 @item OK
42003 The request succeeded.
42004
42005 @item E @var{nn}
42006 An error occurred. The error number @var{nn} is given as hex digits.
42007
42008 @item @w{}
42009 An empty reply indicates that @samp{QThreadEvents} is not supported by
42010 the stub.
42011 @end table
42012
42013 Use of this packet is controlled by the @code{set remote thread-events}
42014 command (@pxref{Remote Configuration, set remote thread-events}).
42015
42016 @item qRcmd,@var{command}
42017 @cindex execute remote command, remote request
42018 @cindex @samp{qRcmd} packet
42019 @var{command} (hex encoded) is passed to the local interpreter for
42020 execution. Invalid commands should be reported using the output
42021 string. Before the final result packet, the target may also respond
42022 with a number of intermediate @samp{O@var{output}} console output
42023 packets. @emph{Implementors should note that providing access to a
42024 stubs's interpreter may have security implications}.
42025
42026 Reply:
42027 @table @samp
42028 @item OK
42029 A command response with no output.
42030 @item @var{OUTPUT}
42031 A command response with the hex encoded output string @var{OUTPUT}.
42032 @item E @var{NN}
42033 Indicate a badly formed request.
42034 @item @w{}
42035 An empty reply indicates that @samp{qRcmd} is not recognized.
42036 @end table
42037
42038 (Note that the @code{qRcmd} packet's name is separated from the
42039 command by a @samp{,}, not a @samp{:}, contrary to the naming
42040 conventions above. Please don't use this packet as a model for new
42041 packets.)
42042
42043 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
42044 @cindex searching memory, in remote debugging
42045 @ifnotinfo
42046 @cindex @samp{qSearch:memory} packet
42047 @end ifnotinfo
42048 @cindex @samp{qSearch memory} packet
42049 @anchor{qSearch memory}
42050 Search @var{length} bytes at @var{address} for @var{search-pattern}.
42051 Both @var{address} and @var{length} are encoded in hex;
42052 @var{search-pattern} is a sequence of bytes, also hex encoded.
42053
42054 Reply:
42055 @table @samp
42056 @item 0
42057 The pattern was not found.
42058 @item 1,address
42059 The pattern was found at @var{address}.
42060 @item E @var{NN}
42061 A badly formed request or an error was encountered while searching memory.
42062 @item @w{}
42063 An empty reply indicates that @samp{qSearch:memory} is not recognized.
42064 @end table
42065
42066 @item QStartNoAckMode
42067 @cindex @samp{QStartNoAckMode} packet
42068 @anchor{QStartNoAckMode}
42069 Request that the remote stub disable the normal @samp{+}/@samp{-}
42070 protocol acknowledgments (@pxref{Packet Acknowledgment}).
42071
42072 Reply:
42073 @table @samp
42074 @item OK
42075 The stub has switched to no-acknowledgment mode.
42076 @value{GDBN} acknowledges this response,
42077 but neither the stub nor @value{GDBN} shall send or expect further
42078 @samp{+}/@samp{-} acknowledgments in the current connection.
42079 @item @w{}
42080 An empty reply indicates that the stub does not support no-acknowledgment mode.
42081 @end table
42082
42083 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
42084 @cindex supported packets, remote query
42085 @cindex features of the remote protocol
42086 @cindex @samp{qSupported} packet
42087 @anchor{qSupported}
42088 Tell the remote stub about features supported by @value{GDBN}, and
42089 query the stub for features it supports. This packet allows
42090 @value{GDBN} and the remote stub to take advantage of each others'
42091 features. @samp{qSupported} also consolidates multiple feature probes
42092 at startup, to improve @value{GDBN} performance---a single larger
42093 packet performs better than multiple smaller probe packets on
42094 high-latency links. Some features may enable behavior which must not
42095 be on by default, e.g.@: because it would confuse older clients or
42096 stubs. Other features may describe packets which could be
42097 automatically probed for, but are not. These features must be
42098 reported before @value{GDBN} will use them. This ``default
42099 unsupported'' behavior is not appropriate for all packets, but it
42100 helps to keep the initial connection time under control with new
42101 versions of @value{GDBN} which support increasing numbers of packets.
42102
42103 Reply:
42104 @table @samp
42105 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
42106 The stub supports or does not support each returned @var{stubfeature},
42107 depending on the form of each @var{stubfeature} (see below for the
42108 possible forms).
42109 @item @w{}
42110 An empty reply indicates that @samp{qSupported} is not recognized,
42111 or that no features needed to be reported to @value{GDBN}.
42112 @end table
42113
42114 The allowed forms for each feature (either a @var{gdbfeature} in the
42115 @samp{qSupported} packet, or a @var{stubfeature} in the response)
42116 are:
42117
42118 @table @samp
42119 @item @var{name}=@var{value}
42120 The remote protocol feature @var{name} is supported, and associated
42121 with the specified @var{value}. The format of @var{value} depends
42122 on the feature, but it must not include a semicolon.
42123 @item @var{name}+
42124 The remote protocol feature @var{name} is supported, and does not
42125 need an associated value.
42126 @item @var{name}-
42127 The remote protocol feature @var{name} is not supported.
42128 @item @var{name}?
42129 The remote protocol feature @var{name} may be supported, and
42130 @value{GDBN} should auto-detect support in some other way when it is
42131 needed. This form will not be used for @var{gdbfeature} notifications,
42132 but may be used for @var{stubfeature} responses.
42133 @end table
42134
42135 Whenever the stub receives a @samp{qSupported} request, the
42136 supplied set of @value{GDBN} features should override any previous
42137 request. This allows @value{GDBN} to put the stub in a known
42138 state, even if the stub had previously been communicating with
42139 a different version of @value{GDBN}.
42140
42141 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
42142 are defined:
42143
42144 @table @samp
42145 @item multiprocess
42146 This feature indicates whether @value{GDBN} supports multiprocess
42147 extensions to the remote protocol. @value{GDBN} does not use such
42148 extensions unless the stub also reports that it supports them by
42149 including @samp{multiprocess+} in its @samp{qSupported} reply.
42150 @xref{multiprocess extensions}, for details.
42151
42152 @item xmlRegisters
42153 This feature indicates that @value{GDBN} supports the XML target
42154 description. If the stub sees @samp{xmlRegisters=} with target
42155 specific strings separated by a comma, it will report register
42156 description.
42157
42158 @item qRelocInsn
42159 This feature indicates whether @value{GDBN} supports the
42160 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
42161 instruction reply packet}).
42162
42163 @item swbreak
42164 This feature indicates whether @value{GDBN} supports the swbreak stop
42165 reason in stop replies. @xref{swbreak stop reason}, for details.
42166
42167 @item hwbreak
42168 This feature indicates whether @value{GDBN} supports the hwbreak stop
42169 reason in stop replies. @xref{swbreak stop reason}, for details.
42170
42171 @item fork-events
42172 This feature indicates whether @value{GDBN} supports fork event
42173 extensions to the remote protocol. @value{GDBN} does not use such
42174 extensions unless the stub also reports that it supports them by
42175 including @samp{fork-events+} in its @samp{qSupported} reply.
42176
42177 @item vfork-events
42178 This feature indicates whether @value{GDBN} supports vfork event
42179 extensions to the remote protocol. @value{GDBN} does not use such
42180 extensions unless the stub also reports that it supports them by
42181 including @samp{vfork-events+} in its @samp{qSupported} reply.
42182
42183 @item exec-events
42184 This feature indicates whether @value{GDBN} supports exec event
42185 extensions to the remote protocol. @value{GDBN} does not use such
42186 extensions unless the stub also reports that it supports them by
42187 including @samp{exec-events+} in its @samp{qSupported} reply.
42188
42189 @item vContSupported
42190 This feature indicates whether @value{GDBN} wants to know the
42191 supported actions in the reply to @samp{vCont?} packet.
42192 @end table
42193
42194 Stubs should ignore any unknown values for
42195 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
42196 packet supports receiving packets of unlimited length (earlier
42197 versions of @value{GDBN} may reject overly long responses). Additional values
42198 for @var{gdbfeature} may be defined in the future to let the stub take
42199 advantage of new features in @value{GDBN}, e.g.@: incompatible
42200 improvements in the remote protocol---the @samp{multiprocess} feature is
42201 an example of such a feature. The stub's reply should be independent
42202 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
42203 describes all the features it supports, and then the stub replies with
42204 all the features it supports.
42205
42206 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
42207 responses, as long as each response uses one of the standard forms.
42208
42209 Some features are flags. A stub which supports a flag feature
42210 should respond with a @samp{+} form response. Other features
42211 require values, and the stub should respond with an @samp{=}
42212 form response.
42213
42214 Each feature has a default value, which @value{GDBN} will use if
42215 @samp{qSupported} is not available or if the feature is not mentioned
42216 in the @samp{qSupported} response. The default values are fixed; a
42217 stub is free to omit any feature responses that match the defaults.
42218
42219 Not all features can be probed, but for those which can, the probing
42220 mechanism is useful: in some cases, a stub's internal
42221 architecture may not allow the protocol layer to know some information
42222 about the underlying target in advance. This is especially common in
42223 stubs which may be configured for multiple targets.
42224
42225 These are the currently defined stub features and their properties:
42226
42227 @multitable @columnfractions 0.35 0.2 0.12 0.2
42228 @c NOTE: The first row should be @headitem, but we do not yet require
42229 @c a new enough version of Texinfo (4.7) to use @headitem.
42230 @item Feature Name
42231 @tab Value Required
42232 @tab Default
42233 @tab Probe Allowed
42234
42235 @item @samp{PacketSize}
42236 @tab Yes
42237 @tab @samp{-}
42238 @tab No
42239
42240 @item @samp{qXfer:auxv:read}
42241 @tab No
42242 @tab @samp{-}
42243 @tab Yes
42244
42245 @item @samp{qXfer:btrace:read}
42246 @tab No
42247 @tab @samp{-}
42248 @tab Yes
42249
42250 @item @samp{qXfer:btrace-conf:read}
42251 @tab No
42252 @tab @samp{-}
42253 @tab Yes
42254
42255 @item @samp{qXfer:exec-file:read}
42256 @tab No
42257 @tab @samp{-}
42258 @tab Yes
42259
42260 @item @samp{qXfer:features:read}
42261 @tab No
42262 @tab @samp{-}
42263 @tab Yes
42264
42265 @item @samp{qXfer:libraries:read}
42266 @tab No
42267 @tab @samp{-}
42268 @tab Yes
42269
42270 @item @samp{qXfer:libraries-svr4:read}
42271 @tab No
42272 @tab @samp{-}
42273 @tab Yes
42274
42275 @item @samp{augmented-libraries-svr4-read}
42276 @tab No
42277 @tab @samp{-}
42278 @tab No
42279
42280 @item @samp{qXfer:memory-map:read}
42281 @tab No
42282 @tab @samp{-}
42283 @tab Yes
42284
42285 @item @samp{qXfer:sdata:read}
42286 @tab No
42287 @tab @samp{-}
42288 @tab Yes
42289
42290 @item @samp{qXfer:siginfo:read}
42291 @tab No
42292 @tab @samp{-}
42293 @tab Yes
42294
42295 @item @samp{qXfer:siginfo:write}
42296 @tab No
42297 @tab @samp{-}
42298 @tab Yes
42299
42300 @item @samp{qXfer:threads:read}
42301 @tab No
42302 @tab @samp{-}
42303 @tab Yes
42304
42305 @item @samp{qXfer:traceframe-info:read}
42306 @tab No
42307 @tab @samp{-}
42308 @tab Yes
42309
42310 @item @samp{qXfer:uib:read}
42311 @tab No
42312 @tab @samp{-}
42313 @tab Yes
42314
42315 @item @samp{qXfer:fdpic:read}
42316 @tab No
42317 @tab @samp{-}
42318 @tab Yes
42319
42320 @item @samp{Qbtrace:off}
42321 @tab Yes
42322 @tab @samp{-}
42323 @tab Yes
42324
42325 @item @samp{Qbtrace:bts}
42326 @tab Yes
42327 @tab @samp{-}
42328 @tab Yes
42329
42330 @item @samp{Qbtrace:pt}
42331 @tab Yes
42332 @tab @samp{-}
42333 @tab Yes
42334
42335 @item @samp{Qbtrace-conf:bts:size}
42336 @tab Yes
42337 @tab @samp{-}
42338 @tab Yes
42339
42340 @item @samp{Qbtrace-conf:pt:size}
42341 @tab Yes
42342 @tab @samp{-}
42343 @tab Yes
42344
42345 @item @samp{QNonStop}
42346 @tab No
42347 @tab @samp{-}
42348 @tab Yes
42349
42350 @item @samp{QCatchSyscalls}
42351 @tab No
42352 @tab @samp{-}
42353 @tab Yes
42354
42355 @item @samp{QPassSignals}
42356 @tab No
42357 @tab @samp{-}
42358 @tab Yes
42359
42360 @item @samp{QStartNoAckMode}
42361 @tab No
42362 @tab @samp{-}
42363 @tab Yes
42364
42365 @item @samp{multiprocess}
42366 @tab No
42367 @tab @samp{-}
42368 @tab No
42369
42370 @item @samp{ConditionalBreakpoints}
42371 @tab No
42372 @tab @samp{-}
42373 @tab No
42374
42375 @item @samp{ConditionalTracepoints}
42376 @tab No
42377 @tab @samp{-}
42378 @tab No
42379
42380 @item @samp{ReverseContinue}
42381 @tab No
42382 @tab @samp{-}
42383 @tab No
42384
42385 @item @samp{ReverseStep}
42386 @tab No
42387 @tab @samp{-}
42388 @tab No
42389
42390 @item @samp{TracepointSource}
42391 @tab No
42392 @tab @samp{-}
42393 @tab No
42394
42395 @item @samp{QAgent}
42396 @tab No
42397 @tab @samp{-}
42398 @tab No
42399
42400 @item @samp{QAllow}
42401 @tab No
42402 @tab @samp{-}
42403 @tab No
42404
42405 @item @samp{QDisableRandomization}
42406 @tab No
42407 @tab @samp{-}
42408 @tab No
42409
42410 @item @samp{EnableDisableTracepoints}
42411 @tab No
42412 @tab @samp{-}
42413 @tab No
42414
42415 @item @samp{QTBuffer:size}
42416 @tab No
42417 @tab @samp{-}
42418 @tab No
42419
42420 @item @samp{tracenz}
42421 @tab No
42422 @tab @samp{-}
42423 @tab No
42424
42425 @item @samp{BreakpointCommands}
42426 @tab No
42427 @tab @samp{-}
42428 @tab No
42429
42430 @item @samp{swbreak}
42431 @tab No
42432 @tab @samp{-}
42433 @tab No
42434
42435 @item @samp{hwbreak}
42436 @tab No
42437 @tab @samp{-}
42438 @tab No
42439
42440 @item @samp{fork-events}
42441 @tab No
42442 @tab @samp{-}
42443 @tab No
42444
42445 @item @samp{vfork-events}
42446 @tab No
42447 @tab @samp{-}
42448 @tab No
42449
42450 @item @samp{exec-events}
42451 @tab No
42452 @tab @samp{-}
42453 @tab No
42454
42455 @item @samp{QThreadEvents}
42456 @tab No
42457 @tab @samp{-}
42458 @tab No
42459
42460 @item @samp{no-resumed}
42461 @tab No
42462 @tab @samp{-}
42463 @tab No
42464
42465 @item @samp{memory-tagging}
42466 @tab No
42467 @tab @samp{-}
42468 @tab No
42469
42470 @end multitable
42471
42472 These are the currently defined stub features, in more detail:
42473
42474 @table @samp
42475 @cindex packet size, remote protocol
42476 @item PacketSize=@var{bytes}
42477 The remote stub can accept packets up to at least @var{bytes} in
42478 length. @value{GDBN} will send packets up to this size for bulk
42479 transfers, and will never send larger packets. This is a limit on the
42480 data characters in the packet, including the frame and checksum.
42481 There is no trailing NUL byte in a remote protocol packet; if the stub
42482 stores packets in a NUL-terminated format, it should allow an extra
42483 byte in its buffer for the NUL. If this stub feature is not supported,
42484 @value{GDBN} guesses based on the size of the @samp{g} packet response.
42485
42486 @item qXfer:auxv:read
42487 The remote stub understands the @samp{qXfer:auxv:read} packet
42488 (@pxref{qXfer auxiliary vector read}).
42489
42490 @item qXfer:btrace:read
42491 The remote stub understands the @samp{qXfer:btrace:read}
42492 packet (@pxref{qXfer btrace read}).
42493
42494 @item qXfer:btrace-conf:read
42495 The remote stub understands the @samp{qXfer:btrace-conf:read}
42496 packet (@pxref{qXfer btrace-conf read}).
42497
42498 @item qXfer:exec-file:read
42499 The remote stub understands the @samp{qXfer:exec-file:read} packet
42500 (@pxref{qXfer executable filename read}).
42501
42502 @item qXfer:features:read
42503 The remote stub understands the @samp{qXfer:features:read} packet
42504 (@pxref{qXfer target description read}).
42505
42506 @item qXfer:libraries:read
42507 The remote stub understands the @samp{qXfer:libraries:read} packet
42508 (@pxref{qXfer library list read}).
42509
42510 @item qXfer:libraries-svr4:read
42511 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
42512 (@pxref{qXfer svr4 library list read}).
42513
42514 @item augmented-libraries-svr4-read
42515 The remote stub understands the augmented form of the
42516 @samp{qXfer:libraries-svr4:read} packet
42517 (@pxref{qXfer svr4 library list read}).
42518
42519 @item qXfer:memory-map:read
42520 The remote stub understands the @samp{qXfer:memory-map:read} packet
42521 (@pxref{qXfer memory map read}).
42522
42523 @item qXfer:sdata:read
42524 The remote stub understands the @samp{qXfer:sdata:read} packet
42525 (@pxref{qXfer sdata read}).
42526
42527 @item qXfer:siginfo:read
42528 The remote stub understands the @samp{qXfer:siginfo:read} packet
42529 (@pxref{qXfer siginfo read}).
42530
42531 @item qXfer:siginfo:write
42532 The remote stub understands the @samp{qXfer:siginfo:write} packet
42533 (@pxref{qXfer siginfo write}).
42534
42535 @item qXfer:threads:read
42536 The remote stub understands the @samp{qXfer:threads:read} packet
42537 (@pxref{qXfer threads read}).
42538
42539 @item qXfer:traceframe-info:read
42540 The remote stub understands the @samp{qXfer:traceframe-info:read}
42541 packet (@pxref{qXfer traceframe info read}).
42542
42543 @item qXfer:uib:read
42544 The remote stub understands the @samp{qXfer:uib:read}
42545 packet (@pxref{qXfer unwind info block}).
42546
42547 @item qXfer:fdpic:read
42548 The remote stub understands the @samp{qXfer:fdpic:read}
42549 packet (@pxref{qXfer fdpic loadmap read}).
42550
42551 @item QNonStop
42552 The remote stub understands the @samp{QNonStop} packet
42553 (@pxref{QNonStop}).
42554
42555 @item QCatchSyscalls
42556 The remote stub understands the @samp{QCatchSyscalls} packet
42557 (@pxref{QCatchSyscalls}).
42558
42559 @item QPassSignals
42560 The remote stub understands the @samp{QPassSignals} packet
42561 (@pxref{QPassSignals}).
42562
42563 @item QStartNoAckMode
42564 The remote stub understands the @samp{QStartNoAckMode} packet and
42565 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
42566
42567 @item multiprocess
42568 @anchor{multiprocess extensions}
42569 @cindex multiprocess extensions, in remote protocol
42570 The remote stub understands the multiprocess extensions to the remote
42571 protocol syntax. The multiprocess extensions affect the syntax of
42572 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
42573 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
42574 replies. Note that reporting this feature indicates support for the
42575 syntactic extensions only, not that the stub necessarily supports
42576 debugging of more than one process at a time. The stub must not use
42577 multiprocess extensions in packet replies unless @value{GDBN} has also
42578 indicated it supports them in its @samp{qSupported} request.
42579
42580 @item qXfer:osdata:read
42581 The remote stub understands the @samp{qXfer:osdata:read} packet
42582 ((@pxref{qXfer osdata read}).
42583
42584 @item ConditionalBreakpoints
42585 The target accepts and implements evaluation of conditional expressions
42586 defined for breakpoints. The target will only report breakpoint triggers
42587 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
42588
42589 @item ConditionalTracepoints
42590 The remote stub accepts and implements conditional expressions defined
42591 for tracepoints (@pxref{Tracepoint Conditions}).
42592
42593 @item ReverseContinue
42594 The remote stub accepts and implements the reverse continue packet
42595 (@pxref{bc}).
42596
42597 @item ReverseStep
42598 The remote stub accepts and implements the reverse step packet
42599 (@pxref{bs}).
42600
42601 @item TracepointSource
42602 The remote stub understands the @samp{QTDPsrc} packet that supplies
42603 the source form of tracepoint definitions.
42604
42605 @item QAgent
42606 The remote stub understands the @samp{QAgent} packet.
42607
42608 @item QAllow
42609 The remote stub understands the @samp{QAllow} packet.
42610
42611 @item QDisableRandomization
42612 The remote stub understands the @samp{QDisableRandomization} packet.
42613
42614 @item StaticTracepoint
42615 @cindex static tracepoints, in remote protocol
42616 The remote stub supports static tracepoints.
42617
42618 @item InstallInTrace
42619 @anchor{install tracepoint in tracing}
42620 The remote stub supports installing tracepoint in tracing.
42621
42622 @item EnableDisableTracepoints
42623 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
42624 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
42625 to be enabled and disabled while a trace experiment is running.
42626
42627 @item QTBuffer:size
42628 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
42629 packet that allows to change the size of the trace buffer.
42630
42631 @item tracenz
42632 @cindex string tracing, in remote protocol
42633 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
42634 See @ref{Bytecode Descriptions} for details about the bytecode.
42635
42636 @item BreakpointCommands
42637 @cindex breakpoint commands, in remote protocol
42638 The remote stub supports running a breakpoint's command list itself,
42639 rather than reporting the hit to @value{GDBN}.
42640
42641 @item Qbtrace:off
42642 The remote stub understands the @samp{Qbtrace:off} packet.
42643
42644 @item Qbtrace:bts
42645 The remote stub understands the @samp{Qbtrace:bts} packet.
42646
42647 @item Qbtrace:pt
42648 The remote stub understands the @samp{Qbtrace:pt} packet.
42649
42650 @item Qbtrace-conf:bts:size
42651 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
42652
42653 @item Qbtrace-conf:pt:size
42654 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
42655
42656 @item swbreak
42657 The remote stub reports the @samp{swbreak} stop reason for memory
42658 breakpoints.
42659
42660 @item hwbreak
42661 The remote stub reports the @samp{hwbreak} stop reason for hardware
42662 breakpoints.
42663
42664 @item fork-events
42665 The remote stub reports the @samp{fork} stop reason for fork events.
42666
42667 @item vfork-events
42668 The remote stub reports the @samp{vfork} stop reason for vfork events
42669 and vforkdone events.
42670
42671 @item exec-events
42672 The remote stub reports the @samp{exec} stop reason for exec events.
42673
42674 @item vContSupported
42675 The remote stub reports the supported actions in the reply to
42676 @samp{vCont?} packet.
42677
42678 @item QThreadEvents
42679 The remote stub understands the @samp{QThreadEvents} packet.
42680
42681 @item no-resumed
42682 The remote stub reports the @samp{N} stop reply.
42683
42684
42685 @item memory-tagging
42686 The remote stub supports and implements the required memory tagging
42687 functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and
42688 @samp{QMemTags} (@pxref{QMemTags}) packets.
42689
42690 For AArch64 GNU/Linux systems, this feature also requires access to the
42691 @file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected.
42692 This is done via the @samp{vFile} requests.
42693
42694 @end table
42695
42696 @item qSymbol::
42697 @cindex symbol lookup, remote request
42698 @cindex @samp{qSymbol} packet
42699 Notify the target that @value{GDBN} is prepared to serve symbol lookup
42700 requests. Accept requests from the target for the values of symbols.
42701
42702 Reply:
42703 @table @samp
42704 @item OK
42705 The target does not need to look up any (more) symbols.
42706 @item qSymbol:@var{sym_name}
42707 The target requests the value of symbol @var{sym_name} (hex encoded).
42708 @value{GDBN} may provide the value by using the
42709 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
42710 below.
42711 @end table
42712
42713 @item qSymbol:@var{sym_value}:@var{sym_name}
42714 Set the value of @var{sym_name} to @var{sym_value}.
42715
42716 @var{sym_name} (hex encoded) is the name of a symbol whose value the
42717 target has previously requested.
42718
42719 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
42720 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
42721 will be empty.
42722
42723 Reply:
42724 @table @samp
42725 @item OK
42726 The target does not need to look up any (more) symbols.
42727 @item qSymbol:@var{sym_name}
42728 The target requests the value of a new symbol @var{sym_name} (hex
42729 encoded). @value{GDBN} will continue to supply the values of symbols
42730 (if available), until the target ceases to request them.
42731 @end table
42732
42733 @item qTBuffer
42734 @itemx QTBuffer
42735 @itemx QTDisconnected
42736 @itemx QTDP
42737 @itemx QTDPsrc
42738 @itemx QTDV
42739 @itemx qTfP
42740 @itemx qTfV
42741 @itemx QTFrame
42742 @itemx qTMinFTPILen
42743
42744 @xref{Tracepoint Packets}.
42745
42746 @anchor{qThreadExtraInfo}
42747 @item qThreadExtraInfo,@var{thread-id}
42748 @cindex thread attributes info, remote request
42749 @cindex @samp{qThreadExtraInfo} packet
42750 Obtain from the target OS a printable string description of thread
42751 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
42752 for the forms of @var{thread-id}. This
42753 string may contain anything that the target OS thinks is interesting
42754 for @value{GDBN} to tell the user about the thread. The string is
42755 displayed in @value{GDBN}'s @code{info threads} display. Some
42756 examples of possible thread extra info strings are @samp{Runnable}, or
42757 @samp{Blocked on Mutex}.
42758
42759 Reply:
42760 @table @samp
42761 @item @var{XX}@dots{}
42762 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
42763 comprising the printable string containing the extra information about
42764 the thread's attributes.
42765 @end table
42766
42767 (Note that the @code{qThreadExtraInfo} packet's name is separated from
42768 the command by a @samp{,}, not a @samp{:}, contrary to the naming
42769 conventions above. Please don't use this packet as a model for new
42770 packets.)
42771
42772 @item QTNotes
42773 @itemx qTP
42774 @itemx QTSave
42775 @itemx qTsP
42776 @itemx qTsV
42777 @itemx QTStart
42778 @itemx QTStop
42779 @itemx QTEnable
42780 @itemx QTDisable
42781 @itemx QTinit
42782 @itemx QTro
42783 @itemx qTStatus
42784 @itemx qTV
42785 @itemx qTfSTM
42786 @itemx qTsSTM
42787 @itemx qTSTMat
42788 @xref{Tracepoint Packets}.
42789
42790 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
42791 @cindex read special object, remote request
42792 @cindex @samp{qXfer} packet
42793 @anchor{qXfer read}
42794 Read uninterpreted bytes from the target's special data area
42795 identified by the keyword @var{object}. Request @var{length} bytes
42796 starting at @var{offset} bytes into the data. The content and
42797 encoding of @var{annex} is specific to @var{object}; it can supply
42798 additional details about what data to access.
42799
42800 Reply:
42801 @table @samp
42802 @item m @var{data}
42803 Data @var{data} (@pxref{Binary Data}) has been read from the
42804 target. There may be more data at a higher address (although
42805 it is permitted to return @samp{m} even for the last valid
42806 block of data, as long as at least one byte of data was read).
42807 It is possible for @var{data} to have fewer bytes than the @var{length} in the
42808 request.
42809
42810 @item l @var{data}
42811 Data @var{data} (@pxref{Binary Data}) has been read from the target.
42812 There is no more data to be read. It is possible for @var{data} to
42813 have fewer bytes than the @var{length} in the request.
42814
42815 @item l
42816 The @var{offset} in the request is at the end of the data.
42817 There is no more data to be read.
42818
42819 @item E00
42820 The request was malformed, or @var{annex} was invalid.
42821
42822 @item E @var{nn}
42823 The offset was invalid, or there was an error encountered reading the data.
42824 The @var{nn} part is a hex-encoded @code{errno} value.
42825
42826 @item @w{}
42827 An empty reply indicates the @var{object} string was not recognized by
42828 the stub, or that the object does not support reading.
42829 @end table
42830
42831 Here are the specific requests of this form defined so far. All the
42832 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
42833 formats, listed above.
42834
42835 @table @samp
42836 @item qXfer:auxv:read::@var{offset},@var{length}
42837 @anchor{qXfer auxiliary vector read}
42838 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
42839 auxiliary vector}. Note @var{annex} must be empty.
42840
42841 This packet is not probed by default; the remote stub must request it,
42842 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42843
42844 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
42845 @anchor{qXfer btrace read}
42846
42847 Return a description of the current branch trace.
42848 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
42849 packet may have one of the following values:
42850
42851 @table @code
42852 @item all
42853 Returns all available branch trace.
42854
42855 @item new
42856 Returns all available branch trace if the branch trace changed since
42857 the last read request.
42858
42859 @item delta
42860 Returns the new branch trace since the last read request. Adds a new
42861 block to the end of the trace that begins at zero and ends at the source
42862 location of the first branch in the trace buffer. This extra block is
42863 used to stitch traces together.
42864
42865 If the trace buffer overflowed, returns an error indicating the overflow.
42866 @end table
42867
42868 This packet is not probed by default; the remote stub must request it
42869 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42870
42871 @item qXfer:btrace-conf:read::@var{offset},@var{length}
42872 @anchor{qXfer btrace-conf read}
42873
42874 Return a description of the current branch trace configuration.
42875 @xref{Branch Trace Configuration Format}.
42876
42877 This packet is not probed by default; the remote stub must request it
42878 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42879
42880 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42881 @anchor{qXfer executable filename read}
42882 Return the full absolute name of the file that was executed to create
42883 a process running on the remote system. The annex specifies the
42884 numeric process ID of the process to query, encoded as a hexadecimal
42885 number. If the annex part is empty the remote stub should return the
42886 filename corresponding to the currently executing process.
42887
42888 This packet is not probed by default; the remote stub must request it,
42889 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42890
42891 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42892 @anchor{qXfer target description read}
42893 Access the @dfn{target description}. @xref{Target Descriptions}. The
42894 annex specifies which XML document to access. The main description is
42895 always loaded from the @samp{target.xml} annex.
42896
42897 This packet is not probed by default; the remote stub must request it,
42898 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42899
42900 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42901 @anchor{qXfer library list read}
42902 Access the target's list of loaded libraries. @xref{Library List Format}.
42903 The annex part of the generic @samp{qXfer} packet must be empty
42904 (@pxref{qXfer read}).
42905
42906 Targets which maintain a list of libraries in the program's memory do
42907 not need to implement this packet; it is designed for platforms where
42908 the operating system manages the list of loaded libraries.
42909
42910 This packet is not probed by default; the remote stub must request it,
42911 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42912
42913 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42914 @anchor{qXfer svr4 library list read}
42915 Access the target's list of loaded libraries when the target is an SVR4
42916 platform. @xref{Library List Format for SVR4 Targets}. The annex part
42917 of the generic @samp{qXfer} packet must be empty unless the remote
42918 stub indicated it supports the augmented form of this packet
42919 by supplying an appropriate @samp{qSupported} response
42920 (@pxref{qXfer read}, @ref{qSupported}).
42921
42922 This packet is optional for better performance on SVR4 targets.
42923 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42924
42925 This packet is not probed by default; the remote stub must request it,
42926 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42927
42928 If the remote stub indicates it supports the augmented form of this
42929 packet then the annex part of the generic @samp{qXfer} packet may
42930 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42931 arguments. The currently supported arguments are:
42932
42933 @table @code
42934 @item start=@var{address}
42935 A hexadecimal number specifying the address of the @samp{struct
42936 link_map} to start reading the library list from. If unset or zero
42937 then the first @samp{struct link_map} in the library list will be
42938 chosen as the starting point.
42939
42940 @item prev=@var{address}
42941 A hexadecimal number specifying the address of the @samp{struct
42942 link_map} immediately preceding the @samp{struct link_map}
42943 specified by the @samp{start} argument. If unset or zero then
42944 the remote stub will expect that no @samp{struct link_map}
42945 exists prior to the starting point.
42946
42947 @end table
42948
42949 Arguments that are not understood by the remote stub will be silently
42950 ignored.
42951
42952 @item qXfer:memory-map:read::@var{offset},@var{length}
42953 @anchor{qXfer memory map read}
42954 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
42955 annex part of the generic @samp{qXfer} packet must be empty
42956 (@pxref{qXfer read}).
42957
42958 This packet is not probed by default; the remote stub must request it,
42959 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42960
42961 @item qXfer:sdata:read::@var{offset},@var{length}
42962 @anchor{qXfer sdata read}
42963
42964 Read contents of the extra collected static tracepoint marker
42965 information. The annex part of the generic @samp{qXfer} packet must
42966 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42967 Action Lists}.
42968
42969 This packet is not probed by default; the remote stub must request it,
42970 by supplying an appropriate @samp{qSupported} response
42971 (@pxref{qSupported}).
42972
42973 @item qXfer:siginfo:read::@var{offset},@var{length}
42974 @anchor{qXfer siginfo read}
42975 Read contents of the extra signal information on the target
42976 system. The annex part of the generic @samp{qXfer} packet must be
42977 empty (@pxref{qXfer read}).
42978
42979 This packet is not probed by default; the remote stub must request it,
42980 by supplying an appropriate @samp{qSupported} response
42981 (@pxref{qSupported}).
42982
42983 @item qXfer:threads:read::@var{offset},@var{length}
42984 @anchor{qXfer threads read}
42985 Access the list of threads on target. @xref{Thread List Format}. The
42986 annex part of the generic @samp{qXfer} packet must be empty
42987 (@pxref{qXfer read}).
42988
42989 This packet is not probed by default; the remote stub must request it,
42990 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42991
42992 @item qXfer:traceframe-info:read::@var{offset},@var{length}
42993 @anchor{qXfer traceframe info read}
42994
42995 Return a description of the current traceframe's contents.
42996 @xref{Traceframe Info Format}. The annex part of the generic
42997 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
42998
42999 This packet is not probed by default; the remote stub must request it,
43000 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43001
43002 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
43003 @anchor{qXfer unwind info block}
43004
43005 Return the unwind information block for @var{pc}. This packet is used
43006 on OpenVMS/ia64 to ask the kernel unwind information.
43007
43008 This packet is not probed by default.
43009
43010 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
43011 @anchor{qXfer fdpic loadmap read}
43012 Read contents of @code{loadmap}s on the target system. The
43013 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
43014 executable @code{loadmap} or interpreter @code{loadmap} to read.
43015
43016 This packet is not probed by default; the remote stub must request it,
43017 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
43018
43019 @item qXfer:osdata:read::@var{offset},@var{length}
43020 @anchor{qXfer osdata read}
43021 Access the target's @dfn{operating system information}.
43022 @xref{Operating System Information}.
43023
43024 @end table
43025
43026 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
43027 @cindex write data into object, remote request
43028 @anchor{qXfer write}
43029 Write uninterpreted bytes into the target's special data area
43030 identified by the keyword @var{object}, starting at @var{offset} bytes
43031 into the data. The binary-encoded data (@pxref{Binary Data}) to be
43032 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
43033 is specific to @var{object}; it can supply additional details about what data
43034 to access.
43035
43036 Reply:
43037 @table @samp
43038 @item @var{nn}
43039 @var{nn} (hex encoded) is the number of bytes written.
43040 This may be fewer bytes than supplied in the request.
43041
43042 @item E00
43043 The request was malformed, or @var{annex} was invalid.
43044
43045 @item E @var{nn}
43046 The offset was invalid, or there was an error encountered writing the data.
43047 The @var{nn} part is a hex-encoded @code{errno} value.
43048
43049 @item @w{}
43050 An empty reply indicates the @var{object} string was not
43051 recognized by the stub, or that the object does not support writing.
43052 @end table
43053
43054 Here are the specific requests of this form defined so far. All the
43055 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
43056 formats, listed above.
43057
43058 @table @samp
43059 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
43060 @anchor{qXfer siginfo write}
43061 Write @var{data} to the extra signal information on the target system.
43062 The annex part of the generic @samp{qXfer} packet must be
43063 empty (@pxref{qXfer write}).
43064
43065 This packet is not probed by default; the remote stub must request it,
43066 by supplying an appropriate @samp{qSupported} response
43067 (@pxref{qSupported}).
43068 @end table
43069
43070 @item qXfer:@var{object}:@var{operation}:@dots{}
43071 Requests of this form may be added in the future. When a stub does
43072 not recognize the @var{object} keyword, or its support for
43073 @var{object} does not recognize the @var{operation} keyword, the stub
43074 must respond with an empty packet.
43075
43076 @item qAttached:@var{pid}
43077 @cindex query attached, remote request
43078 @cindex @samp{qAttached} packet
43079 Return an indication of whether the remote server attached to an
43080 existing process or created a new process. When the multiprocess
43081 protocol extensions are supported (@pxref{multiprocess extensions}),
43082 @var{pid} is an integer in hexadecimal format identifying the target
43083 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
43084 the query packet will be simplified as @samp{qAttached}.
43085
43086 This query is used, for example, to know whether the remote process
43087 should be detached or killed when a @value{GDBN} session is ended with
43088 the @code{quit} command.
43089
43090 Reply:
43091 @table @samp
43092 @item 1
43093 The remote server attached to an existing process.
43094 @item 0
43095 The remote server created a new process.
43096 @item E @var{NN}
43097 A badly formed request or an error was encountered.
43098 @end table
43099
43100 @item Qbtrace:bts
43101 Enable branch tracing for the current thread using Branch Trace Store.
43102
43103 Reply:
43104 @table @samp
43105 @item OK
43106 Branch tracing has been enabled.
43107 @item E.errtext
43108 A badly formed request or an error was encountered.
43109 @end table
43110
43111 @item Qbtrace:pt
43112 Enable branch tracing for the current thread using Intel Processor Trace.
43113
43114 Reply:
43115 @table @samp
43116 @item OK
43117 Branch tracing has been enabled.
43118 @item E.errtext
43119 A badly formed request or an error was encountered.
43120 @end table
43121
43122 @item Qbtrace:off
43123 Disable branch tracing for the current thread.
43124
43125 Reply:
43126 @table @samp
43127 @item OK
43128 Branch tracing has been disabled.
43129 @item E.errtext
43130 A badly formed request or an error was encountered.
43131 @end table
43132
43133 @item Qbtrace-conf:bts:size=@var{value}
43134 Set the requested ring buffer size for new threads that use the
43135 btrace recording method in bts format.
43136
43137 Reply:
43138 @table @samp
43139 @item OK
43140 The ring buffer size has been set.
43141 @item E.errtext
43142 A badly formed request or an error was encountered.
43143 @end table
43144
43145 @item Qbtrace-conf:pt:size=@var{value}
43146 Set the requested ring buffer size for new threads that use the
43147 btrace recording method in pt format.
43148
43149 Reply:
43150 @table @samp
43151 @item OK
43152 The ring buffer size has been set.
43153 @item E.errtext
43154 A badly formed request or an error was encountered.
43155 @end table
43156
43157 @end table
43158
43159 @node Architecture-Specific Protocol Details
43160 @section Architecture-Specific Protocol Details
43161
43162 This section describes how the remote protocol is applied to specific
43163 target architectures. Also see @ref{Standard Target Features}, for
43164 details of XML target descriptions for each architecture.
43165
43166 @menu
43167 * ARM-Specific Protocol Details::
43168 * MIPS-Specific Protocol Details::
43169 @end menu
43170
43171 @node ARM-Specific Protocol Details
43172 @subsection @acronym{ARM}-specific Protocol Details
43173
43174 @menu
43175 * ARM Breakpoint Kinds::
43176 * ARM Memory Tag Types::
43177 @end menu
43178
43179 @node ARM Breakpoint Kinds
43180 @subsubsection @acronym{ARM} Breakpoint Kinds
43181 @cindex breakpoint kinds, @acronym{ARM}
43182
43183 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
43184
43185 @table @r
43186
43187 @item 2
43188 16-bit Thumb mode breakpoint.
43189
43190 @item 3
43191 32-bit Thumb mode (Thumb-2) breakpoint.
43192
43193 @item 4
43194 32-bit @acronym{ARM} mode breakpoint.
43195
43196 @end table
43197
43198 @node ARM Memory Tag Types
43199 @subsubsection @acronym{ARM} Memory Tag Types
43200 @cindex memory tag types, @acronym{ARM}
43201
43202 These memory tag types are defined for the @samp{qMemTag} and @samp{QMemTag}
43203 packets.
43204
43205 @table @r
43206
43207 @item 0
43208 MTE logical tag
43209
43210 @item 1
43211 MTE allocation tag
43212
43213 @end table
43214
43215 @node MIPS-Specific Protocol Details
43216 @subsection @acronym{MIPS}-specific Protocol Details
43217
43218 @menu
43219 * MIPS Register packet Format::
43220 * MIPS Breakpoint Kinds::
43221 @end menu
43222
43223 @node MIPS Register packet Format
43224 @subsubsection @acronym{MIPS} Register Packet Format
43225 @cindex register packet format, @acronym{MIPS}
43226
43227 The following @code{g}/@code{G} packets have previously been defined.
43228 In the below, some thirty-two bit registers are transferred as
43229 sixty-four bits. Those registers should be zero/sign extended (which?)
43230 to fill the space allocated. Register bytes are transferred in target
43231 byte order. The two nibbles within a register byte are transferred
43232 most-significant -- least-significant.
43233
43234 @table @r
43235
43236 @item MIPS32
43237 All registers are transferred as thirty-two bit quantities in the order:
43238 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
43239 registers; fsr; fir; fp.
43240
43241 @item MIPS64
43242 All registers are transferred as sixty-four bit quantities (including
43243 thirty-two bit registers such as @code{sr}). The ordering is the same
43244 as @code{MIPS32}.
43245
43246 @end table
43247
43248 @node MIPS Breakpoint Kinds
43249 @subsubsection @acronym{MIPS} Breakpoint Kinds
43250 @cindex breakpoint kinds, @acronym{MIPS}
43251
43252 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
43253
43254 @table @r
43255
43256 @item 2
43257 16-bit @acronym{MIPS16} mode breakpoint.
43258
43259 @item 3
43260 16-bit @acronym{microMIPS} mode breakpoint.
43261
43262 @item 4
43263 32-bit standard @acronym{MIPS} mode breakpoint.
43264
43265 @item 5
43266 32-bit @acronym{microMIPS} mode breakpoint.
43267
43268 @end table
43269
43270 @node Tracepoint Packets
43271 @section Tracepoint Packets
43272 @cindex tracepoint packets
43273 @cindex packets, tracepoint
43274
43275 Here we describe the packets @value{GDBN} uses to implement
43276 tracepoints (@pxref{Tracepoints}).
43277
43278 @table @samp
43279
43280 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
43281 @cindex @samp{QTDP} packet
43282 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
43283 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
43284 the tracepoint is disabled. The @var{step} gives the tracepoint's step
43285 count, and @var{pass} gives its pass count. If an @samp{F} is present,
43286 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
43287 the number of bytes that the target should copy elsewhere to make room
43288 for the tracepoint. If an @samp{X} is present, it introduces a
43289 tracepoint condition, which consists of a hexadecimal length, followed
43290 by a comma and hex-encoded bytes, in a manner similar to action
43291 encodings as described below. If the trailing @samp{-} is present,
43292 further @samp{QTDP} packets will follow to specify this tracepoint's
43293 actions.
43294
43295 Replies:
43296 @table @samp
43297 @item OK
43298 The packet was understood and carried out.
43299 @item qRelocInsn
43300 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
43301 @item @w{}
43302 The packet was not recognized.
43303 @end table
43304
43305 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
43306 Define actions to be taken when a tracepoint is hit. The @var{n} and
43307 @var{addr} must be the same as in the initial @samp{QTDP} packet for
43308 this tracepoint. This packet may only be sent immediately after
43309 another @samp{QTDP} packet that ended with a @samp{-}. If the
43310 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
43311 specifying more actions for this tracepoint.
43312
43313 In the series of action packets for a given tracepoint, at most one
43314 can have an @samp{S} before its first @var{action}. If such a packet
43315 is sent, it and the following packets define ``while-stepping''
43316 actions. Any prior packets define ordinary actions --- that is, those
43317 taken when the tracepoint is first hit. If no action packet has an
43318 @samp{S}, then all the packets in the series specify ordinary
43319 tracepoint actions.
43320
43321 The @samp{@var{action}@dots{}} portion of the packet is a series of
43322 actions, concatenated without separators. Each action has one of the
43323 following forms:
43324
43325 @table @samp
43326
43327 @item R @var{mask}
43328 Collect the registers whose bits are set in @var{mask},
43329 a hexadecimal number whose @var{i}'th bit is set if register number
43330 @var{i} should be collected. (The least significant bit is numbered
43331 zero.) Note that @var{mask} may be any number of digits long; it may
43332 not fit in a 32-bit word.
43333
43334 @item M @var{basereg},@var{offset},@var{len}
43335 Collect @var{len} bytes of memory starting at the address in register
43336 number @var{basereg}, plus @var{offset}. If @var{basereg} is
43337 @samp{-1}, then the range has a fixed address: @var{offset} is the
43338 address of the lowest byte to collect. The @var{basereg},
43339 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
43340 values (the @samp{-1} value for @var{basereg} is a special case).
43341
43342 @item X @var{len},@var{expr}
43343 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
43344 it directs. The agent expression @var{expr} is as described in
43345 @ref{Agent Expressions}. Each byte of the expression is encoded as a
43346 two-digit hex number in the packet; @var{len} is the number of bytes
43347 in the expression (and thus one-half the number of hex digits in the
43348 packet).
43349
43350 @end table
43351
43352 Any number of actions may be packed together in a single @samp{QTDP}
43353 packet, as long as the packet does not exceed the maximum packet
43354 length (400 bytes, for many stubs). There may be only one @samp{R}
43355 action per tracepoint, and it must precede any @samp{M} or @samp{X}
43356 actions. Any registers referred to by @samp{M} and @samp{X} actions
43357 must be collected by a preceding @samp{R} action. (The
43358 ``while-stepping'' actions are treated as if they were attached to a
43359 separate tracepoint, as far as these restrictions are concerned.)
43360
43361 Replies:
43362 @table @samp
43363 @item OK
43364 The packet was understood and carried out.
43365 @item qRelocInsn
43366 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
43367 @item @w{}
43368 The packet was not recognized.
43369 @end table
43370
43371 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
43372 @cindex @samp{QTDPsrc} packet
43373 Specify a source string of tracepoint @var{n} at address @var{addr}.
43374 This is useful to get accurate reproduction of the tracepoints
43375 originally downloaded at the beginning of the trace run. The @var{type}
43376 is the name of the tracepoint part, such as @samp{cond} for the
43377 tracepoint's conditional expression (see below for a list of types), while
43378 @var{bytes} is the string, encoded in hexadecimal.
43379
43380 @var{start} is the offset of the @var{bytes} within the overall source
43381 string, while @var{slen} is the total length of the source string.
43382 This is intended for handling source strings that are longer than will
43383 fit in a single packet.
43384 @c Add detailed example when this info is moved into a dedicated
43385 @c tracepoint descriptions section.
43386
43387 The available string types are @samp{at} for the location,
43388 @samp{cond} for the conditional, and @samp{cmd} for an action command.
43389 @value{GDBN} sends a separate packet for each command in the action
43390 list, in the same order in which the commands are stored in the list.
43391
43392 The target does not need to do anything with source strings except
43393 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
43394 query packets.
43395
43396 Although this packet is optional, and @value{GDBN} will only send it
43397 if the target replies with @samp{TracepointSource} @xref{General
43398 Query Packets}, it makes both disconnected tracing and trace files
43399 much easier to use. Otherwise the user must be careful that the
43400 tracepoints in effect while looking at trace frames are identical to
43401 the ones in effect during the trace run; even a small discrepancy
43402 could cause @samp{tdump} not to work, or a particular trace frame not
43403 be found.
43404
43405 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
43406 @cindex define trace state variable, remote request
43407 @cindex @samp{QTDV} packet
43408 Create a new trace state variable, number @var{n}, with an initial
43409 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
43410 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
43411 the option of not using this packet for initial values of zero; the
43412 target should simply create the trace state variables as they are
43413 mentioned in expressions. The value @var{builtin} should be 1 (one)
43414 if the trace state variable is builtin and 0 (zero) if it is not builtin.
43415 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
43416 @samp{qTsV} packet had it set. The contents of @var{name} is the
43417 hex-encoded name (without the leading @samp{$}) of the trace state
43418 variable.
43419
43420 @item QTFrame:@var{n}
43421 @cindex @samp{QTFrame} packet
43422 Select the @var{n}'th tracepoint frame from the buffer, and use the
43423 register and memory contents recorded there to answer subsequent
43424 request packets from @value{GDBN}.
43425
43426 A successful reply from the stub indicates that the stub has found the
43427 requested frame. The response is a series of parts, concatenated
43428 without separators, describing the frame we selected. Each part has
43429 one of the following forms:
43430
43431 @table @samp
43432 @item F @var{f}
43433 The selected frame is number @var{n} in the trace frame buffer;
43434 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
43435 was no frame matching the criteria in the request packet.
43436
43437 @item T @var{t}
43438 The selected trace frame records a hit of tracepoint number @var{t};
43439 @var{t} is a hexadecimal number.
43440
43441 @end table
43442
43443 @item QTFrame:pc:@var{addr}
43444 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43445 currently selected frame whose PC is @var{addr};
43446 @var{addr} is a hexadecimal number.
43447
43448 @item QTFrame:tdp:@var{t}
43449 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43450 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
43451 is a hexadecimal number.
43452
43453 @item QTFrame:range:@var{start}:@var{end}
43454 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
43455 currently selected frame whose PC is between @var{start} (inclusive)
43456 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
43457 numbers.
43458
43459 @item QTFrame:outside:@var{start}:@var{end}
43460 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
43461 frame @emph{outside} the given range of addresses (exclusive).
43462
43463 @item qTMinFTPILen
43464 @cindex @samp{qTMinFTPILen} packet
43465 This packet requests the minimum length of instruction at which a fast
43466 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
43467 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
43468 it depends on the target system being able to create trampolines in
43469 the first 64K of memory, which might or might not be possible for that
43470 system. So the reply to this packet will be 4 if it is able to
43471 arrange for that.
43472
43473 Replies:
43474
43475 @table @samp
43476 @item 0
43477 The minimum instruction length is currently unknown.
43478 @item @var{length}
43479 The minimum instruction length is @var{length}, where @var{length}
43480 is a hexadecimal number greater or equal to 1. A reply
43481 of 1 means that a fast tracepoint may be placed on any instruction
43482 regardless of size.
43483 @item E
43484 An error has occurred.
43485 @item @w{}
43486 An empty reply indicates that the request is not supported by the stub.
43487 @end table
43488
43489 @item QTStart
43490 @cindex @samp{QTStart} packet
43491 Begin the tracepoint experiment. Begin collecting data from
43492 tracepoint hits in the trace frame buffer. This packet supports the
43493 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
43494 instruction reply packet}).
43495
43496 @item QTStop
43497 @cindex @samp{QTStop} packet
43498 End the tracepoint experiment. Stop collecting trace frames.
43499
43500 @item QTEnable:@var{n}:@var{addr}
43501 @anchor{QTEnable}
43502 @cindex @samp{QTEnable} packet
43503 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
43504 experiment. If the tracepoint was previously disabled, then collection
43505 of data from it will resume.
43506
43507 @item QTDisable:@var{n}:@var{addr}
43508 @anchor{QTDisable}
43509 @cindex @samp{QTDisable} packet
43510 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
43511 experiment. No more data will be collected from the tracepoint unless
43512 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
43513
43514 @item QTinit
43515 @cindex @samp{QTinit} packet
43516 Clear the table of tracepoints, and empty the trace frame buffer.
43517
43518 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
43519 @cindex @samp{QTro} packet
43520 Establish the given ranges of memory as ``transparent''. The stub
43521 will answer requests for these ranges from memory's current contents,
43522 if they were not collected as part of the tracepoint hit.
43523
43524 @value{GDBN} uses this to mark read-only regions of memory, like those
43525 containing program code. Since these areas never change, they should
43526 still have the same contents they did when the tracepoint was hit, so
43527 there's no reason for the stub to refuse to provide their contents.
43528
43529 @item QTDisconnected:@var{value}
43530 @cindex @samp{QTDisconnected} packet
43531 Set the choice to what to do with the tracing run when @value{GDBN}
43532 disconnects from the target. A @var{value} of 1 directs the target to
43533 continue the tracing run, while 0 tells the target to stop tracing if
43534 @value{GDBN} is no longer in the picture.
43535
43536 @item qTStatus
43537 @cindex @samp{qTStatus} packet
43538 Ask the stub if there is a trace experiment running right now.
43539
43540 The reply has the form:
43541
43542 @table @samp
43543
43544 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
43545 @var{running} is a single digit @code{1} if the trace is presently
43546 running, or @code{0} if not. It is followed by semicolon-separated
43547 optional fields that an agent may use to report additional status.
43548
43549 @end table
43550
43551 If the trace is not running, the agent may report any of several
43552 explanations as one of the optional fields:
43553
43554 @table @samp
43555
43556 @item tnotrun:0
43557 No trace has been run yet.
43558
43559 @item tstop[:@var{text}]:0
43560 The trace was stopped by a user-originated stop command. The optional
43561 @var{text} field is a user-supplied string supplied as part of the
43562 stop command (for instance, an explanation of why the trace was
43563 stopped manually). It is hex-encoded.
43564
43565 @item tfull:0
43566 The trace stopped because the trace buffer filled up.
43567
43568 @item tdisconnected:0
43569 The trace stopped because @value{GDBN} disconnected from the target.
43570
43571 @item tpasscount:@var{tpnum}
43572 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
43573
43574 @item terror:@var{text}:@var{tpnum}
43575 The trace stopped because tracepoint @var{tpnum} had an error. The
43576 string @var{text} is available to describe the nature of the error
43577 (for instance, a divide by zero in the condition expression); it
43578 is hex encoded.
43579
43580 @item tunknown:0
43581 The trace stopped for some other reason.
43582
43583 @end table
43584
43585 Additional optional fields supply statistical and other information.
43586 Although not required, they are extremely useful for users monitoring
43587 the progress of a trace run. If a trace has stopped, and these
43588 numbers are reported, they must reflect the state of the just-stopped
43589 trace.
43590
43591 @table @samp
43592
43593 @item tframes:@var{n}
43594 The number of trace frames in the buffer.
43595
43596 @item tcreated:@var{n}
43597 The total number of trace frames created during the run. This may
43598 be larger than the trace frame count, if the buffer is circular.
43599
43600 @item tsize:@var{n}
43601 The total size of the trace buffer, in bytes.
43602
43603 @item tfree:@var{n}
43604 The number of bytes still unused in the buffer.
43605
43606 @item circular:@var{n}
43607 The value of the circular trace buffer flag. @code{1} means that the
43608 trace buffer is circular and old trace frames will be discarded if
43609 necessary to make room, @code{0} means that the trace buffer is linear
43610 and may fill up.
43611
43612 @item disconn:@var{n}
43613 The value of the disconnected tracing flag. @code{1} means that
43614 tracing will continue after @value{GDBN} disconnects, @code{0} means
43615 that the trace run will stop.
43616
43617 @end table
43618
43619 @item qTP:@var{tp}:@var{addr}
43620 @cindex tracepoint status, remote request
43621 @cindex @samp{qTP} packet
43622 Ask the stub for the current state of tracepoint number @var{tp} at
43623 address @var{addr}.
43624
43625 Replies:
43626 @table @samp
43627 @item V@var{hits}:@var{usage}
43628 The tracepoint has been hit @var{hits} times so far during the trace
43629 run, and accounts for @var{usage} in the trace buffer. Note that
43630 @code{while-stepping} steps are not counted as separate hits, but the
43631 steps' space consumption is added into the usage number.
43632
43633 @end table
43634
43635 @item qTV:@var{var}
43636 @cindex trace state variable value, remote request
43637 @cindex @samp{qTV} packet
43638 Ask the stub for the value of the trace state variable number @var{var}.
43639
43640 Replies:
43641 @table @samp
43642 @item V@var{value}
43643 The value of the variable is @var{value}. This will be the current
43644 value of the variable if the user is examining a running target, or a
43645 saved value if the variable was collected in the trace frame that the
43646 user is looking at. Note that multiple requests may result in
43647 different reply values, such as when requesting values while the
43648 program is running.
43649
43650 @item U
43651 The value of the variable is unknown. This would occur, for example,
43652 if the user is examining a trace frame in which the requested variable
43653 was not collected.
43654 @end table
43655
43656 @item qTfP
43657 @cindex @samp{qTfP} packet
43658 @itemx qTsP
43659 @cindex @samp{qTsP} packet
43660 These packets request data about tracepoints that are being used by
43661 the target. @value{GDBN} sends @code{qTfP} to get the first piece
43662 of data, and multiple @code{qTsP} to get additional pieces. Replies
43663 to these packets generally take the form of the @code{QTDP} packets
43664 that define tracepoints. (FIXME add detailed syntax)
43665
43666 @item qTfV
43667 @cindex @samp{qTfV} packet
43668 @itemx qTsV
43669 @cindex @samp{qTsV} packet
43670 These packets request data about trace state variables that are on the
43671 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
43672 and multiple @code{qTsV} to get additional variables. Replies to
43673 these packets follow the syntax of the @code{QTDV} packets that define
43674 trace state variables.
43675
43676 @item qTfSTM
43677 @itemx qTsSTM
43678 @anchor{qTfSTM}
43679 @anchor{qTsSTM}
43680 @cindex @samp{qTfSTM} packet
43681 @cindex @samp{qTsSTM} packet
43682 These packets request data about static tracepoint markers that exist
43683 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
43684 first piece of data, and multiple @code{qTsSTM} to get additional
43685 pieces. Replies to these packets take the following form:
43686
43687 Reply:
43688 @table @samp
43689 @item m @var{address}:@var{id}:@var{extra}
43690 A single marker
43691 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
43692 a comma-separated list of markers
43693 @item l
43694 (lower case letter @samp{L}) denotes end of list.
43695 @item E @var{nn}
43696 An error occurred. The error number @var{nn} is given as hex digits.
43697 @item @w{}
43698 An empty reply indicates that the request is not supported by the
43699 stub.
43700 @end table
43701
43702 The @var{address} is encoded in hex;
43703 @var{id} and @var{extra} are strings encoded in hex.
43704
43705 In response to each query, the target will reply with a list of one or
43706 more markers, separated by commas. @value{GDBN} will respond to each
43707 reply with a request for more markers (using the @samp{qs} form of the
43708 query), until the target responds with @samp{l} (lower-case ell, for
43709 @dfn{last}).
43710
43711 @item qTSTMat:@var{address}
43712 @anchor{qTSTMat}
43713 @cindex @samp{qTSTMat} packet
43714 This packets requests data about static tracepoint markers in the
43715 target program at @var{address}. Replies to this packet follow the
43716 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
43717 tracepoint markers.
43718
43719 @item QTSave:@var{filename}
43720 @cindex @samp{QTSave} packet
43721 This packet directs the target to save trace data to the file name
43722 @var{filename} in the target's filesystem. The @var{filename} is encoded
43723 as a hex string; the interpretation of the file name (relative vs
43724 absolute, wild cards, etc) is up to the target.
43725
43726 @item qTBuffer:@var{offset},@var{len}
43727 @cindex @samp{qTBuffer} packet
43728 Return up to @var{len} bytes of the current contents of trace buffer,
43729 starting at @var{offset}. The trace buffer is treated as if it were
43730 a contiguous collection of traceframes, as per the trace file format.
43731 The reply consists as many hex-encoded bytes as the target can deliver
43732 in a packet; it is not an error to return fewer than were asked for.
43733 A reply consisting of just @code{l} indicates that no bytes are
43734 available.
43735
43736 @item QTBuffer:circular:@var{value}
43737 This packet directs the target to use a circular trace buffer if
43738 @var{value} is 1, or a linear buffer if the value is 0.
43739
43740 @item QTBuffer:size:@var{size}
43741 @anchor{QTBuffer-size}
43742 @cindex @samp{QTBuffer size} packet
43743 This packet directs the target to make the trace buffer be of size
43744 @var{size} if possible. A value of @code{-1} tells the target to
43745 use whatever size it prefers.
43746
43747 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
43748 @cindex @samp{QTNotes} packet
43749 This packet adds optional textual notes to the trace run. Allowable
43750 types include @code{user}, @code{notes}, and @code{tstop}, the
43751 @var{text} fields are arbitrary strings, hex-encoded.
43752
43753 @end table
43754
43755 @subsection Relocate instruction reply packet
43756 When installing fast tracepoints in memory, the target may need to
43757 relocate the instruction currently at the tracepoint address to a
43758 different address in memory. For most instructions, a simple copy is
43759 enough, but, for example, call instructions that implicitly push the
43760 return address on the stack, and relative branches or other
43761 PC-relative instructions require offset adjustment, so that the effect
43762 of executing the instruction at a different address is the same as if
43763 it had executed in the original location.
43764
43765 In response to several of the tracepoint packets, the target may also
43766 respond with a number of intermediate @samp{qRelocInsn} request
43767 packets before the final result packet, to have @value{GDBN} handle
43768 this relocation operation. If a packet supports this mechanism, its
43769 documentation will explicitly say so. See for example the above
43770 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
43771 format of the request is:
43772
43773 @table @samp
43774 @item qRelocInsn:@var{from};@var{to}
43775
43776 This requests @value{GDBN} to copy instruction at address @var{from}
43777 to address @var{to}, possibly adjusted so that executing the
43778 instruction at @var{to} has the same effect as executing it at
43779 @var{from}. @value{GDBN} writes the adjusted instruction to target
43780 memory starting at @var{to}.
43781 @end table
43782
43783 Replies:
43784 @table @samp
43785 @item qRelocInsn:@var{adjusted_size}
43786 Informs the stub the relocation is complete. The @var{adjusted_size} is
43787 the length in bytes of resulting relocated instruction sequence.
43788 @item E @var{NN}
43789 A badly formed request was detected, or an error was encountered while
43790 relocating the instruction.
43791 @end table
43792
43793 @node Host I/O Packets
43794 @section Host I/O Packets
43795 @cindex Host I/O, remote protocol
43796 @cindex file transfer, remote protocol
43797
43798 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
43799 operations on the far side of a remote link. For example, Host I/O is
43800 used to upload and download files to a remote target with its own
43801 filesystem. Host I/O uses the same constant values and data structure
43802 layout as the target-initiated File-I/O protocol. However, the
43803 Host I/O packets are structured differently. The target-initiated
43804 protocol relies on target memory to store parameters and buffers.
43805 Host I/O requests are initiated by @value{GDBN}, and the
43806 target's memory is not involved. @xref{File-I/O Remote Protocol
43807 Extension}, for more details on the target-initiated protocol.
43808
43809 The Host I/O request packets all encode a single operation along with
43810 its arguments. They have this format:
43811
43812 @table @samp
43813
43814 @item vFile:@var{operation}: @var{parameter}@dots{}
43815 @var{operation} is the name of the particular request; the target
43816 should compare the entire packet name up to the second colon when checking
43817 for a supported operation. The format of @var{parameter} depends on
43818 the operation. Numbers are always passed in hexadecimal. Negative
43819 numbers have an explicit minus sign (i.e.@: two's complement is not
43820 used). Strings (e.g.@: filenames) are encoded as a series of
43821 hexadecimal bytes. The last argument to a system call may be a
43822 buffer of escaped binary data (@pxref{Binary Data}).
43823
43824 @end table
43825
43826 The valid responses to Host I/O packets are:
43827
43828 @table @samp
43829
43830 @item F @var{result} [, @var{errno}] [; @var{attachment}]
43831 @var{result} is the integer value returned by this operation, usually
43832 non-negative for success and -1 for errors. If an error has occured,
43833 @var{errno} will be included in the result specifying a
43834 value defined by the File-I/O protocol (@pxref{Errno Values}). For
43835 operations which return data, @var{attachment} supplies the data as a
43836 binary buffer. Binary buffers in response packets are escaped in the
43837 normal way (@pxref{Binary Data}). See the individual packet
43838 documentation for the interpretation of @var{result} and
43839 @var{attachment}.
43840
43841 @item @w{}
43842 An empty response indicates that this operation is not recognized.
43843
43844 @end table
43845
43846 These are the supported Host I/O operations:
43847
43848 @table @samp
43849 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
43850 Open a file at @var{filename} and return a file descriptor for it, or
43851 return -1 if an error occurs. The @var{filename} is a string,
43852 @var{flags} is an integer indicating a mask of open flags
43853 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
43854 of mode bits to use if the file is created (@pxref{mode_t Values}).
43855 @xref{open}, for details of the open flags and mode values.
43856
43857 @item vFile:close: @var{fd}
43858 Close the open file corresponding to @var{fd} and return 0, or
43859 -1 if an error occurs.
43860
43861 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
43862 Read data from the open file corresponding to @var{fd}. Up to
43863 @var{count} bytes will be read from the file, starting at @var{offset}
43864 relative to the start of the file. The target may read fewer bytes;
43865 common reasons include packet size limits and an end-of-file
43866 condition. The number of bytes read is returned. Zero should only be
43867 returned for a successful read at the end of the file, or if
43868 @var{count} was zero.
43869
43870 The data read should be returned as a binary attachment on success.
43871 If zero bytes were read, the response should include an empty binary
43872 attachment (i.e.@: a trailing semicolon). The return value is the
43873 number of target bytes read; the binary attachment may be longer if
43874 some characters were escaped.
43875
43876 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
43877 Write @var{data} (a binary buffer) to the open file corresponding
43878 to @var{fd}. Start the write at @var{offset} from the start of the
43879 file. Unlike many @code{write} system calls, there is no
43880 separate @var{count} argument; the length of @var{data} in the
43881 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
43882 which may be shorter than the length of @var{data}, or -1 if an
43883 error occurred.
43884
43885 @item vFile:fstat: @var{fd}
43886 Get information about the open file corresponding to @var{fd}.
43887 On success the information is returned as a binary attachment
43888 and the return value is the size of this attachment in bytes.
43889 If an error occurs the return value is -1. The format of the
43890 returned binary attachment is as described in @ref{struct stat}.
43891
43892 @item vFile:unlink: @var{filename}
43893 Delete the file at @var{filename} on the target. Return 0,
43894 or -1 if an error occurs. The @var{filename} is a string.
43895
43896 @item vFile:readlink: @var{filename}
43897 Read value of symbolic link @var{filename} on the target. Return
43898 the number of bytes read, or -1 if an error occurs.
43899
43900 The data read should be returned as a binary attachment on success.
43901 If zero bytes were read, the response should include an empty binary
43902 attachment (i.e.@: a trailing semicolon). The return value is the
43903 number of target bytes read; the binary attachment may be longer if
43904 some characters were escaped.
43905
43906 @item vFile:setfs: @var{pid}
43907 Select the filesystem on which @code{vFile} operations with
43908 @var{filename} arguments will operate. This is required for
43909 @value{GDBN} to be able to access files on remote targets where
43910 the remote stub does not share a common filesystem with the
43911 inferior(s).
43912
43913 If @var{pid} is nonzero, select the filesystem as seen by process
43914 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
43915 the remote stub. Return 0 on success, or -1 if an error occurs.
43916 If @code{vFile:setfs:} indicates success, the selected filesystem
43917 remains selected until the next successful @code{vFile:setfs:}
43918 operation.
43919
43920 @end table
43921
43922 @node Interrupts
43923 @section Interrupts
43924 @cindex interrupts (remote protocol)
43925 @anchor{interrupting remote targets}
43926
43927 In all-stop mode, when a program on the remote target is running,
43928 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43929 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43930 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
43931
43932 The precise meaning of @code{BREAK} is defined by the transport
43933 mechanism and may, in fact, be undefined. @value{GDBN} does not
43934 currently define a @code{BREAK} mechanism for any of the network
43935 interfaces except for TCP, in which case @value{GDBN} sends the
43936 @code{telnet} BREAK sequence.
43937
43938 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
43939 transport mechanisms. It is represented by sending the single byte
43940 @code{0x03} without any of the usual packet overhead described in
43941 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43942 transmitted as part of a packet, it is considered to be packet data
43943 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
43944 (@pxref{X packet}), used for binary downloads, may include an unescaped
43945 @code{0x03} as part of its packet.
43946
43947 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43948 When Linux kernel receives this sequence from serial port,
43949 it stops execution and connects to gdb.
43950
43951 In non-stop mode, because packet resumptions are asynchronous
43952 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43953 command to the remote stub, even when the target is running. For that
43954 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43955 packet}) with the usual packet framing instead of the single byte
43956 @code{0x03}.
43957
43958 Stubs are not required to recognize these interrupt mechanisms and the
43959 precise meaning associated with receipt of the interrupt is
43960 implementation defined. If the target supports debugging of multiple
43961 threads and/or processes, it should attempt to interrupt all
43962 currently-executing threads and processes.
43963 If the stub is successful at interrupting the
43964 running program, it should send one of the stop
43965 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43966 of successfully stopping the program in all-stop mode, and a stop reply
43967 for each stopped thread in non-stop mode.
43968 Interrupts received while the
43969 program is stopped are queued and the program will be interrupted when
43970 it is resumed next time.
43971
43972 @node Notification Packets
43973 @section Notification Packets
43974 @cindex notification packets
43975 @cindex packets, notification
43976
43977 The @value{GDBN} remote serial protocol includes @dfn{notifications},
43978 packets that require no acknowledgment. Both the GDB and the stub
43979 may send notifications (although the only notifications defined at
43980 present are sent by the stub). Notifications carry information
43981 without incurring the round-trip latency of an acknowledgment, and so
43982 are useful for low-impact communications where occasional packet loss
43983 is not a problem.
43984
43985 A notification packet has the form @samp{% @var{data} #
43986 @var{checksum}}, where @var{data} is the content of the notification,
43987 and @var{checksum} is a checksum of @var{data}, computed and formatted
43988 as for ordinary @value{GDBN} packets. A notification's @var{data}
43989 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43990 receiving a notification, the recipient sends no @samp{+} or @samp{-}
43991 to acknowledge the notification's receipt or to report its corruption.
43992
43993 Every notification's @var{data} begins with a name, which contains no
43994 colon characters, followed by a colon character.
43995
43996 Recipients should silently ignore corrupted notifications and
43997 notifications they do not understand. Recipients should restart
43998 timeout periods on receipt of a well-formed notification, whether or
43999 not they understand it.
44000
44001 Senders should only send the notifications described here when this
44002 protocol description specifies that they are permitted. In the
44003 future, we may extend the protocol to permit existing notifications in
44004 new contexts; this rule helps older senders avoid confusing newer
44005 recipients.
44006
44007 (Older versions of @value{GDBN} ignore bytes received until they see
44008 the @samp{$} byte that begins an ordinary packet, so new stubs may
44009 transmit notifications without fear of confusing older clients. There
44010 are no notifications defined for @value{GDBN} to send at the moment, but we
44011 assume that most older stubs would ignore them, as well.)
44012
44013 Each notification is comprised of three parts:
44014 @table @samp
44015 @item @var{name}:@var{event}
44016 The notification packet is sent by the side that initiates the
44017 exchange (currently, only the stub does that), with @var{event}
44018 carrying the specific information about the notification, and
44019 @var{name} specifying the name of the notification.
44020 @item @var{ack}
44021 The acknowledge sent by the other side, usually @value{GDBN}, to
44022 acknowledge the exchange and request the event.
44023 @end table
44024
44025 The purpose of an asynchronous notification mechanism is to report to
44026 @value{GDBN} that something interesting happened in the remote stub.
44027
44028 The remote stub may send notification @var{name}:@var{event}
44029 at any time, but @value{GDBN} acknowledges the notification when
44030 appropriate. The notification event is pending before @value{GDBN}
44031 acknowledges. Only one notification at a time may be pending; if
44032 additional events occur before @value{GDBN} has acknowledged the
44033 previous notification, they must be queued by the stub for later
44034 synchronous transmission in response to @var{ack} packets from
44035 @value{GDBN}. Because the notification mechanism is unreliable,
44036 the stub is permitted to resend a notification if it believes
44037 @value{GDBN} may not have received it.
44038
44039 Specifically, notifications may appear when @value{GDBN} is not
44040 otherwise reading input from the stub, or when @value{GDBN} is
44041 expecting to read a normal synchronous response or a
44042 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
44043 Notification packets are distinct from any other communication from
44044 the stub so there is no ambiguity.
44045
44046 After receiving a notification, @value{GDBN} shall acknowledge it by
44047 sending a @var{ack} packet as a regular, synchronous request to the
44048 stub. Such acknowledgment is not required to happen immediately, as
44049 @value{GDBN} is permitted to send other, unrelated packets to the
44050 stub first, which the stub should process normally.
44051
44052 Upon receiving a @var{ack} packet, if the stub has other queued
44053 events to report to @value{GDBN}, it shall respond by sending a
44054 normal @var{event}. @value{GDBN} shall then send another @var{ack}
44055 packet to solicit further responses; again, it is permitted to send
44056 other, unrelated packets as well which the stub should process
44057 normally.
44058
44059 If the stub receives a @var{ack} packet and there are no additional
44060 @var{event} to report, the stub shall return an @samp{OK} response.
44061 At this point, @value{GDBN} has finished processing a notification
44062 and the stub has completed sending any queued events. @value{GDBN}
44063 won't accept any new notifications until the final @samp{OK} is
44064 received . If further notification events occur, the stub shall send
44065 a new notification, @value{GDBN} shall accept the notification, and
44066 the process shall be repeated.
44067
44068 The process of asynchronous notification can be illustrated by the
44069 following example:
44070 @smallexample
44071 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
44072 @code{...}
44073 -> @code{vStopped}
44074 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
44075 -> @code{vStopped}
44076 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
44077 -> @code{vStopped}
44078 <- @code{OK}
44079 @end smallexample
44080
44081 The following notifications are defined:
44082 @multitable @columnfractions 0.12 0.12 0.38 0.38
44083
44084 @item Notification
44085 @tab Ack
44086 @tab Event
44087 @tab Description
44088
44089 @item Stop
44090 @tab vStopped
44091 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
44092 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
44093 for information on how these notifications are acknowledged by
44094 @value{GDBN}.
44095 @tab Report an asynchronous stop event in non-stop mode.
44096
44097 @end multitable
44098
44099 @node Remote Non-Stop
44100 @section Remote Protocol Support for Non-Stop Mode
44101
44102 @value{GDBN}'s remote protocol supports non-stop debugging of
44103 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
44104 supports non-stop mode, it should report that to @value{GDBN} by including
44105 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
44106
44107 @value{GDBN} typically sends a @samp{QNonStop} packet only when
44108 establishing a new connection with the stub. Entering non-stop mode
44109 does not alter the state of any currently-running threads, but targets
44110 must stop all threads in any already-attached processes when entering
44111 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
44112 probe the target state after a mode change.
44113
44114 In non-stop mode, when an attached process encounters an event that
44115 would otherwise be reported with a stop reply, it uses the
44116 asynchronous notification mechanism (@pxref{Notification Packets}) to
44117 inform @value{GDBN}. In contrast to all-stop mode, where all threads
44118 in all processes are stopped when a stop reply is sent, in non-stop
44119 mode only the thread reporting the stop event is stopped. That is,
44120 when reporting a @samp{S} or @samp{T} response to indicate completion
44121 of a step operation, hitting a breakpoint, or a fault, only the
44122 affected thread is stopped; any other still-running threads continue
44123 to run. When reporting a @samp{W} or @samp{X} response, all running
44124 threads belonging to other attached processes continue to run.
44125
44126 In non-stop mode, the target shall respond to the @samp{?} packet as
44127 follows. First, any incomplete stop reply notification/@samp{vStopped}
44128 sequence in progress is abandoned. The target must begin a new
44129 sequence reporting stop events for all stopped threads, whether or not
44130 it has previously reported those events to @value{GDBN}. The first
44131 stop reply is sent as a synchronous reply to the @samp{?} packet, and
44132 subsequent stop replies are sent as responses to @samp{vStopped} packets
44133 using the mechanism described above. The target must not send
44134 asynchronous stop reply notifications until the sequence is complete.
44135 If all threads are running when the target receives the @samp{?} packet,
44136 or if the target is not attached to any process, it shall respond
44137 @samp{OK}.
44138
44139 If the stub supports non-stop mode, it should also support the
44140 @samp{swbreak} stop reason if software breakpoints are supported, and
44141 the @samp{hwbreak} stop reason if hardware breakpoints are supported
44142 (@pxref{swbreak stop reason}). This is because given the asynchronous
44143 nature of non-stop mode, between the time a thread hits a breakpoint
44144 and the time the event is finally processed by @value{GDBN}, the
44145 breakpoint may have already been removed from the target. Due to
44146 this, @value{GDBN} needs to be able to tell whether a trap stop was
44147 caused by a delayed breakpoint event, which should be ignored, as
44148 opposed to a random trap signal, which should be reported to the user.
44149 Note the @samp{swbreak} feature implies that the target is responsible
44150 for adjusting the PC when a software breakpoint triggers, if
44151 necessary, such as on the x86 architecture.
44152
44153 @node Packet Acknowledgment
44154 @section Packet Acknowledgment
44155
44156 @cindex acknowledgment, for @value{GDBN} remote
44157 @cindex packet acknowledgment, for @value{GDBN} remote
44158 By default, when either the host or the target machine receives a packet,
44159 the first response expected is an acknowledgment: either @samp{+} (to indicate
44160 the package was received correctly) or @samp{-} (to request retransmission).
44161 This mechanism allows the @value{GDBN} remote protocol to operate over
44162 unreliable transport mechanisms, such as a serial line.
44163
44164 In cases where the transport mechanism is itself reliable (such as a pipe or
44165 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
44166 It may be desirable to disable them in that case to reduce communication
44167 overhead, or for other reasons. This can be accomplished by means of the
44168 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
44169
44170 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
44171 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
44172 and response format still includes the normal checksum, as described in
44173 @ref{Overview}, but the checksum may be ignored by the receiver.
44174
44175 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
44176 no-acknowledgment mode, it should report that to @value{GDBN}
44177 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
44178 @pxref{qSupported}.
44179 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
44180 disabled via the @code{set remote noack-packet off} command
44181 (@pxref{Remote Configuration}),
44182 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
44183 Only then may the stub actually turn off packet acknowledgments.
44184 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
44185 response, which can be safely ignored by the stub.
44186
44187 Note that @code{set remote noack-packet} command only affects negotiation
44188 between @value{GDBN} and the stub when subsequent connections are made;
44189 it does not affect the protocol acknowledgment state for any current
44190 connection.
44191 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
44192 new connection is established,
44193 there is also no protocol request to re-enable the acknowledgments
44194 for the current connection, once disabled.
44195
44196 @node Examples
44197 @section Examples
44198
44199 Example sequence of a target being re-started. Notice how the restart
44200 does not get any direct output:
44201
44202 @smallexample
44203 -> @code{R00}
44204 <- @code{+}
44205 @emph{target restarts}
44206 -> @code{?}
44207 <- @code{+}
44208 <- @code{T001:1234123412341234}
44209 -> @code{+}
44210 @end smallexample
44211
44212 Example sequence of a target being stepped by a single instruction:
44213
44214 @smallexample
44215 -> @code{G1445@dots{}}
44216 <- @code{+}
44217 -> @code{s}
44218 <- @code{+}
44219 @emph{time passes}
44220 <- @code{T001:1234123412341234}
44221 -> @code{+}
44222 -> @code{g}
44223 <- @code{+}
44224 <- @code{1455@dots{}}
44225 -> @code{+}
44226 @end smallexample
44227
44228 @node File-I/O Remote Protocol Extension
44229 @section File-I/O Remote Protocol Extension
44230 @cindex File-I/O remote protocol extension
44231
44232 @menu
44233 * File-I/O Overview::
44234 * Protocol Basics::
44235 * The F Request Packet::
44236 * The F Reply Packet::
44237 * The Ctrl-C Message::
44238 * Console I/O::
44239 * List of Supported Calls::
44240 * Protocol-specific Representation of Datatypes::
44241 * Constants::
44242 * File-I/O Examples::
44243 @end menu
44244
44245 @node File-I/O Overview
44246 @subsection File-I/O Overview
44247 @cindex file-i/o overview
44248
44249 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
44250 target to use the host's file system and console I/O to perform various
44251 system calls. System calls on the target system are translated into a
44252 remote protocol packet to the host system, which then performs the needed
44253 actions and returns a response packet to the target system.
44254 This simulates file system operations even on targets that lack file systems.
44255
44256 The protocol is defined to be independent of both the host and target systems.
44257 It uses its own internal representation of datatypes and values. Both
44258 @value{GDBN} and the target's @value{GDBN} stub are responsible for
44259 translating the system-dependent value representations into the internal
44260 protocol representations when data is transmitted.
44261
44262 The communication is synchronous. A system call is possible only when
44263 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
44264 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
44265 the target is stopped to allow deterministic access to the target's
44266 memory. Therefore File-I/O is not interruptible by target signals. On
44267 the other hand, it is possible to interrupt File-I/O by a user interrupt
44268 (@samp{Ctrl-C}) within @value{GDBN}.
44269
44270 The target's request to perform a host system call does not finish
44271 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
44272 after finishing the system call, the target returns to continuing the
44273 previous activity (continue, step). No additional continue or step
44274 request from @value{GDBN} is required.
44275
44276 @smallexample
44277 (@value{GDBP}) continue
44278 <- target requests 'system call X'
44279 target is stopped, @value{GDBN} executes system call
44280 -> @value{GDBN} returns result
44281 ... target continues, @value{GDBN} returns to wait for the target
44282 <- target hits breakpoint and sends a Txx packet
44283 @end smallexample
44284
44285 The protocol only supports I/O on the console and to regular files on
44286 the host file system. Character or block special devices, pipes,
44287 named pipes, sockets or any other communication method on the host
44288 system are not supported by this protocol.
44289
44290 File I/O is not supported in non-stop mode.
44291
44292 @node Protocol Basics
44293 @subsection Protocol Basics
44294 @cindex protocol basics, file-i/o
44295
44296 The File-I/O protocol uses the @code{F} packet as the request as well
44297 as reply packet. Since a File-I/O system call can only occur when
44298 @value{GDBN} is waiting for a response from the continuing or stepping target,
44299 the File-I/O request is a reply that @value{GDBN} has to expect as a result
44300 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
44301 This @code{F} packet contains all information needed to allow @value{GDBN}
44302 to call the appropriate host system call:
44303
44304 @itemize @bullet
44305 @item
44306 A unique identifier for the requested system call.
44307
44308 @item
44309 All parameters to the system call. Pointers are given as addresses
44310 in the target memory address space. Pointers to strings are given as
44311 pointer/length pair. Numerical values are given as they are.
44312 Numerical control flags are given in a protocol-specific representation.
44313
44314 @end itemize
44315
44316 At this point, @value{GDBN} has to perform the following actions.
44317
44318 @itemize @bullet
44319 @item
44320 If the parameters include pointer values to data needed as input to a
44321 system call, @value{GDBN} requests this data from the target with a
44322 standard @code{m} packet request. This additional communication has to be
44323 expected by the target implementation and is handled as any other @code{m}
44324 packet.
44325
44326 @item
44327 @value{GDBN} translates all value from protocol representation to host
44328 representation as needed. Datatypes are coerced into the host types.
44329
44330 @item
44331 @value{GDBN} calls the system call.
44332
44333 @item
44334 It then coerces datatypes back to protocol representation.
44335
44336 @item
44337 If the system call is expected to return data in buffer space specified
44338 by pointer parameters to the call, the data is transmitted to the
44339 target using a @code{M} or @code{X} packet. This packet has to be expected
44340 by the target implementation and is handled as any other @code{M} or @code{X}
44341 packet.
44342
44343 @end itemize
44344
44345 Eventually @value{GDBN} replies with another @code{F} packet which contains all
44346 necessary information for the target to continue. This at least contains
44347
44348 @itemize @bullet
44349 @item
44350 Return value.
44351
44352 @item
44353 @code{errno}, if has been changed by the system call.
44354
44355 @item
44356 ``Ctrl-C'' flag.
44357
44358 @end itemize
44359
44360 After having done the needed type and value coercion, the target continues
44361 the latest continue or step action.
44362
44363 @node The F Request Packet
44364 @subsection The @code{F} Request Packet
44365 @cindex file-i/o request packet
44366 @cindex @code{F} request packet
44367
44368 The @code{F} request packet has the following format:
44369
44370 @table @samp
44371 @item F@var{call-id},@var{parameter@dots{}}
44372
44373 @var{call-id} is the identifier to indicate the host system call to be called.
44374 This is just the name of the function.
44375
44376 @var{parameter@dots{}} are the parameters to the system call.
44377 Parameters are hexadecimal integer values, either the actual values in case
44378 of scalar datatypes, pointers to target buffer space in case of compound
44379 datatypes and unspecified memory areas, or pointer/length pairs in case
44380 of string parameters. These are appended to the @var{call-id} as a
44381 comma-delimited list. All values are transmitted in ASCII
44382 string representation, pointer/length pairs separated by a slash.
44383
44384 @end table
44385
44386
44387
44388 @node The F Reply Packet
44389 @subsection The @code{F} Reply Packet
44390 @cindex file-i/o reply packet
44391 @cindex @code{F} reply packet
44392
44393 The @code{F} reply packet has the following format:
44394
44395 @table @samp
44396
44397 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
44398
44399 @var{retcode} is the return code of the system call as hexadecimal value.
44400
44401 @var{errno} is the @code{errno} set by the call, in protocol-specific
44402 representation.
44403 This parameter can be omitted if the call was successful.
44404
44405 @var{Ctrl-C flag} is only sent if the user requested a break. In this
44406 case, @var{errno} must be sent as well, even if the call was successful.
44407 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
44408
44409 @smallexample
44410 F0,0,C
44411 @end smallexample
44412
44413 @noindent
44414 or, if the call was interrupted before the host call has been performed:
44415
44416 @smallexample
44417 F-1,4,C
44418 @end smallexample
44419
44420 @noindent
44421 assuming 4 is the protocol-specific representation of @code{EINTR}.
44422
44423 @end table
44424
44425
44426 @node The Ctrl-C Message
44427 @subsection The @samp{Ctrl-C} Message
44428 @cindex ctrl-c message, in file-i/o protocol
44429
44430 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
44431 reply packet (@pxref{The F Reply Packet}),
44432 the target should behave as if it had
44433 gotten a break message. The meaning for the target is ``system call
44434 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
44435 (as with a break message) and return to @value{GDBN} with a @code{T02}
44436 packet.
44437
44438 It's important for the target to know in which
44439 state the system call was interrupted. There are two possible cases:
44440
44441 @itemize @bullet
44442 @item
44443 The system call hasn't been performed on the host yet.
44444
44445 @item
44446 The system call on the host has been finished.
44447
44448 @end itemize
44449
44450 These two states can be distinguished by the target by the value of the
44451 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
44452 call hasn't been performed. This is equivalent to the @code{EINTR} handling
44453 on POSIX systems. In any other case, the target may presume that the
44454 system call has been finished --- successfully or not --- and should behave
44455 as if the break message arrived right after the system call.
44456
44457 @value{GDBN} must behave reliably. If the system call has not been called
44458 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
44459 @code{errno} in the packet. If the system call on the host has been finished
44460 before the user requests a break, the full action must be finished by
44461 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
44462 The @code{F} packet may only be sent when either nothing has happened
44463 or the full action has been completed.
44464
44465 @node Console I/O
44466 @subsection Console I/O
44467 @cindex console i/o as part of file-i/o
44468
44469 By default and if not explicitly closed by the target system, the file
44470 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
44471 on the @value{GDBN} console is handled as any other file output operation
44472 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
44473 by @value{GDBN} so that after the target read request from file descriptor
44474 0 all following typing is buffered until either one of the following
44475 conditions is met:
44476
44477 @itemize @bullet
44478 @item
44479 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
44480 @code{read}
44481 system call is treated as finished.
44482
44483 @item
44484 The user presses @key{RET}. This is treated as end of input with a trailing
44485 newline.
44486
44487 @item
44488 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
44489 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
44490
44491 @end itemize
44492
44493 If the user has typed more characters than fit in the buffer given to
44494 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
44495 either another @code{read(0, @dots{})} is requested by the target, or debugging
44496 is stopped at the user's request.
44497
44498
44499 @node List of Supported Calls
44500 @subsection List of Supported Calls
44501 @cindex list of supported file-i/o calls
44502
44503 @menu
44504 * open::
44505 * close::
44506 * read::
44507 * write::
44508 * lseek::
44509 * rename::
44510 * unlink::
44511 * stat/fstat::
44512 * gettimeofday::
44513 * isatty::
44514 * system::
44515 @end menu
44516
44517 @node open
44518 @unnumberedsubsubsec open
44519 @cindex open, file-i/o system call
44520
44521 @table @asis
44522 @item Synopsis:
44523 @smallexample
44524 int open(const char *pathname, int flags);
44525 int open(const char *pathname, int flags, mode_t mode);
44526 @end smallexample
44527
44528 @item Request:
44529 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
44530
44531 @noindent
44532 @var{flags} is the bitwise @code{OR} of the following values:
44533
44534 @table @code
44535 @item O_CREAT
44536 If the file does not exist it will be created. The host
44537 rules apply as far as file ownership and time stamps
44538 are concerned.
44539
44540 @item O_EXCL
44541 When used with @code{O_CREAT}, if the file already exists it is
44542 an error and open() fails.
44543
44544 @item O_TRUNC
44545 If the file already exists and the open mode allows
44546 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
44547 truncated to zero length.
44548
44549 @item O_APPEND
44550 The file is opened in append mode.
44551
44552 @item O_RDONLY
44553 The file is opened for reading only.
44554
44555 @item O_WRONLY
44556 The file is opened for writing only.
44557
44558 @item O_RDWR
44559 The file is opened for reading and writing.
44560 @end table
44561
44562 @noindent
44563 Other bits are silently ignored.
44564
44565
44566 @noindent
44567 @var{mode} is the bitwise @code{OR} of the following values:
44568
44569 @table @code
44570 @item S_IRUSR
44571 User has read permission.
44572
44573 @item S_IWUSR
44574 User has write permission.
44575
44576 @item S_IRGRP
44577 Group has read permission.
44578
44579 @item S_IWGRP
44580 Group has write permission.
44581
44582 @item S_IROTH
44583 Others have read permission.
44584
44585 @item S_IWOTH
44586 Others have write permission.
44587 @end table
44588
44589 @noindent
44590 Other bits are silently ignored.
44591
44592
44593 @item Return value:
44594 @code{open} returns the new file descriptor or -1 if an error
44595 occurred.
44596
44597 @item Errors:
44598
44599 @table @code
44600 @item EEXIST
44601 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
44602
44603 @item EISDIR
44604 @var{pathname} refers to a directory.
44605
44606 @item EACCES
44607 The requested access is not allowed.
44608
44609 @item ENAMETOOLONG
44610 @var{pathname} was too long.
44611
44612 @item ENOENT
44613 A directory component in @var{pathname} does not exist.
44614
44615 @item ENODEV
44616 @var{pathname} refers to a device, pipe, named pipe or socket.
44617
44618 @item EROFS
44619 @var{pathname} refers to a file on a read-only filesystem and
44620 write access was requested.
44621
44622 @item EFAULT
44623 @var{pathname} is an invalid pointer value.
44624
44625 @item ENOSPC
44626 No space on device to create the file.
44627
44628 @item EMFILE
44629 The process already has the maximum number of files open.
44630
44631 @item ENFILE
44632 The limit on the total number of files open on the system
44633 has been reached.
44634
44635 @item EINTR
44636 The call was interrupted by the user.
44637 @end table
44638
44639 @end table
44640
44641 @node close
44642 @unnumberedsubsubsec close
44643 @cindex close, file-i/o system call
44644
44645 @table @asis
44646 @item Synopsis:
44647 @smallexample
44648 int close(int fd);
44649 @end smallexample
44650
44651 @item Request:
44652 @samp{Fclose,@var{fd}}
44653
44654 @item Return value:
44655 @code{close} returns zero on success, or -1 if an error occurred.
44656
44657 @item Errors:
44658
44659 @table @code
44660 @item EBADF
44661 @var{fd} isn't a valid open file descriptor.
44662
44663 @item EINTR
44664 The call was interrupted by the user.
44665 @end table
44666
44667 @end table
44668
44669 @node read
44670 @unnumberedsubsubsec read
44671 @cindex read, file-i/o system call
44672
44673 @table @asis
44674 @item Synopsis:
44675 @smallexample
44676 int read(int fd, void *buf, unsigned int count);
44677 @end smallexample
44678
44679 @item Request:
44680 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
44681
44682 @item Return value:
44683 On success, the number of bytes read is returned.
44684 Zero indicates end of file. If count is zero, read
44685 returns zero as well. On error, -1 is returned.
44686
44687 @item Errors:
44688
44689 @table @code
44690 @item EBADF
44691 @var{fd} is not a valid file descriptor or is not open for
44692 reading.
44693
44694 @item EFAULT
44695 @var{bufptr} is an invalid pointer value.
44696
44697 @item EINTR
44698 The call was interrupted by the user.
44699 @end table
44700
44701 @end table
44702
44703 @node write
44704 @unnumberedsubsubsec write
44705 @cindex write, file-i/o system call
44706
44707 @table @asis
44708 @item Synopsis:
44709 @smallexample
44710 int write(int fd, const void *buf, unsigned int count);
44711 @end smallexample
44712
44713 @item Request:
44714 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
44715
44716 @item Return value:
44717 On success, the number of bytes written are returned.
44718 Zero indicates nothing was written. On error, -1
44719 is returned.
44720
44721 @item Errors:
44722
44723 @table @code
44724 @item EBADF
44725 @var{fd} is not a valid file descriptor or is not open for
44726 writing.
44727
44728 @item EFAULT
44729 @var{bufptr} is an invalid pointer value.
44730
44731 @item EFBIG
44732 An attempt was made to write a file that exceeds the
44733 host-specific maximum file size allowed.
44734
44735 @item ENOSPC
44736 No space on device to write the data.
44737
44738 @item EINTR
44739 The call was interrupted by the user.
44740 @end table
44741
44742 @end table
44743
44744 @node lseek
44745 @unnumberedsubsubsec lseek
44746 @cindex lseek, file-i/o system call
44747
44748 @table @asis
44749 @item Synopsis:
44750 @smallexample
44751 long lseek (int fd, long offset, int flag);
44752 @end smallexample
44753
44754 @item Request:
44755 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
44756
44757 @var{flag} is one of:
44758
44759 @table @code
44760 @item SEEK_SET
44761 The offset is set to @var{offset} bytes.
44762
44763 @item SEEK_CUR
44764 The offset is set to its current location plus @var{offset}
44765 bytes.
44766
44767 @item SEEK_END
44768 The offset is set to the size of the file plus @var{offset}
44769 bytes.
44770 @end table
44771
44772 @item Return value:
44773 On success, the resulting unsigned offset in bytes from
44774 the beginning of the file is returned. Otherwise, a
44775 value of -1 is returned.
44776
44777 @item Errors:
44778
44779 @table @code
44780 @item EBADF
44781 @var{fd} is not a valid open file descriptor.
44782
44783 @item ESPIPE
44784 @var{fd} is associated with the @value{GDBN} console.
44785
44786 @item EINVAL
44787 @var{flag} is not a proper value.
44788
44789 @item EINTR
44790 The call was interrupted by the user.
44791 @end table
44792
44793 @end table
44794
44795 @node rename
44796 @unnumberedsubsubsec rename
44797 @cindex rename, file-i/o system call
44798
44799 @table @asis
44800 @item Synopsis:
44801 @smallexample
44802 int rename(const char *oldpath, const char *newpath);
44803 @end smallexample
44804
44805 @item Request:
44806 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
44807
44808 @item Return value:
44809 On success, zero is returned. On error, -1 is returned.
44810
44811 @item Errors:
44812
44813 @table @code
44814 @item EISDIR
44815 @var{newpath} is an existing directory, but @var{oldpath} is not a
44816 directory.
44817
44818 @item EEXIST
44819 @var{newpath} is a non-empty directory.
44820
44821 @item EBUSY
44822 @var{oldpath} or @var{newpath} is a directory that is in use by some
44823 process.
44824
44825 @item EINVAL
44826 An attempt was made to make a directory a subdirectory
44827 of itself.
44828
44829 @item ENOTDIR
44830 A component used as a directory in @var{oldpath} or new
44831 path is not a directory. Or @var{oldpath} is a directory
44832 and @var{newpath} exists but is not a directory.
44833
44834 @item EFAULT
44835 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
44836
44837 @item EACCES
44838 No access to the file or the path of the file.
44839
44840 @item ENAMETOOLONG
44841
44842 @var{oldpath} or @var{newpath} was too long.
44843
44844 @item ENOENT
44845 A directory component in @var{oldpath} or @var{newpath} does not exist.
44846
44847 @item EROFS
44848 The file is on a read-only filesystem.
44849
44850 @item ENOSPC
44851 The device containing the file has no room for the new
44852 directory entry.
44853
44854 @item EINTR
44855 The call was interrupted by the user.
44856 @end table
44857
44858 @end table
44859
44860 @node unlink
44861 @unnumberedsubsubsec unlink
44862 @cindex unlink, file-i/o system call
44863
44864 @table @asis
44865 @item Synopsis:
44866 @smallexample
44867 int unlink(const char *pathname);
44868 @end smallexample
44869
44870 @item Request:
44871 @samp{Funlink,@var{pathnameptr}/@var{len}}
44872
44873 @item Return value:
44874 On success, zero is returned. On error, -1 is returned.
44875
44876 @item Errors:
44877
44878 @table @code
44879 @item EACCES
44880 No access to the file or the path of the file.
44881
44882 @item EPERM
44883 The system does not allow unlinking of directories.
44884
44885 @item EBUSY
44886 The file @var{pathname} cannot be unlinked because it's
44887 being used by another process.
44888
44889 @item EFAULT
44890 @var{pathnameptr} is an invalid pointer value.
44891
44892 @item ENAMETOOLONG
44893 @var{pathname} was too long.
44894
44895 @item ENOENT
44896 A directory component in @var{pathname} does not exist.
44897
44898 @item ENOTDIR
44899 A component of the path is not a directory.
44900
44901 @item EROFS
44902 The file is on a read-only filesystem.
44903
44904 @item EINTR
44905 The call was interrupted by the user.
44906 @end table
44907
44908 @end table
44909
44910 @node stat/fstat
44911 @unnumberedsubsubsec stat/fstat
44912 @cindex fstat, file-i/o system call
44913 @cindex stat, file-i/o system call
44914
44915 @table @asis
44916 @item Synopsis:
44917 @smallexample
44918 int stat(const char *pathname, struct stat *buf);
44919 int fstat(int fd, struct stat *buf);
44920 @end smallexample
44921
44922 @item Request:
44923 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44924 @samp{Ffstat,@var{fd},@var{bufptr}}
44925
44926 @item Return value:
44927 On success, zero is returned. On error, -1 is returned.
44928
44929 @item Errors:
44930
44931 @table @code
44932 @item EBADF
44933 @var{fd} is not a valid open file.
44934
44935 @item ENOENT
44936 A directory component in @var{pathname} does not exist or the
44937 path is an empty string.
44938
44939 @item ENOTDIR
44940 A component of the path is not a directory.
44941
44942 @item EFAULT
44943 @var{pathnameptr} is an invalid pointer value.
44944
44945 @item EACCES
44946 No access to the file or the path of the file.
44947
44948 @item ENAMETOOLONG
44949 @var{pathname} was too long.
44950
44951 @item EINTR
44952 The call was interrupted by the user.
44953 @end table
44954
44955 @end table
44956
44957 @node gettimeofday
44958 @unnumberedsubsubsec gettimeofday
44959 @cindex gettimeofday, file-i/o system call
44960
44961 @table @asis
44962 @item Synopsis:
44963 @smallexample
44964 int gettimeofday(struct timeval *tv, void *tz);
44965 @end smallexample
44966
44967 @item Request:
44968 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
44969
44970 @item Return value:
44971 On success, 0 is returned, -1 otherwise.
44972
44973 @item Errors:
44974
44975 @table @code
44976 @item EINVAL
44977 @var{tz} is a non-NULL pointer.
44978
44979 @item EFAULT
44980 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44981 @end table
44982
44983 @end table
44984
44985 @node isatty
44986 @unnumberedsubsubsec isatty
44987 @cindex isatty, file-i/o system call
44988
44989 @table @asis
44990 @item Synopsis:
44991 @smallexample
44992 int isatty(int fd);
44993 @end smallexample
44994
44995 @item Request:
44996 @samp{Fisatty,@var{fd}}
44997
44998 @item Return value:
44999 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
45000
45001 @item Errors:
45002
45003 @table @code
45004 @item EINTR
45005 The call was interrupted by the user.
45006 @end table
45007
45008 @end table
45009
45010 Note that the @code{isatty} call is treated as a special case: it returns
45011 1 to the target if the file descriptor is attached
45012 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
45013 would require implementing @code{ioctl} and would be more complex than
45014 needed.
45015
45016
45017 @node system
45018 @unnumberedsubsubsec system
45019 @cindex system, file-i/o system call
45020
45021 @table @asis
45022 @item Synopsis:
45023 @smallexample
45024 int system(const char *command);
45025 @end smallexample
45026
45027 @item Request:
45028 @samp{Fsystem,@var{commandptr}/@var{len}}
45029
45030 @item Return value:
45031 If @var{len} is zero, the return value indicates whether a shell is
45032 available. A zero return value indicates a shell is not available.
45033 For non-zero @var{len}, the value returned is -1 on error and the
45034 return status of the command otherwise. Only the exit status of the
45035 command is returned, which is extracted from the host's @code{system}
45036 return value by calling @code{WEXITSTATUS(retval)}. In case
45037 @file{/bin/sh} could not be executed, 127 is returned.
45038
45039 @item Errors:
45040
45041 @table @code
45042 @item EINTR
45043 The call was interrupted by the user.
45044 @end table
45045
45046 @end table
45047
45048 @value{GDBN} takes over the full task of calling the necessary host calls
45049 to perform the @code{system} call. The return value of @code{system} on
45050 the host is simplified before it's returned
45051 to the target. Any termination signal information from the child process
45052 is discarded, and the return value consists
45053 entirely of the exit status of the called command.
45054
45055 Due to security concerns, the @code{system} call is by default refused
45056 by @value{GDBN}. The user has to allow this call explicitly with the
45057 @code{set remote system-call-allowed 1} command.
45058
45059 @table @code
45060 @item set remote system-call-allowed
45061 @kindex set remote system-call-allowed
45062 Control whether to allow the @code{system} calls in the File I/O
45063 protocol for the remote target. The default is zero (disabled).
45064
45065 @item show remote system-call-allowed
45066 @kindex show remote system-call-allowed
45067 Show whether the @code{system} calls are allowed in the File I/O
45068 protocol.
45069 @end table
45070
45071 @node Protocol-specific Representation of Datatypes
45072 @subsection Protocol-specific Representation of Datatypes
45073 @cindex protocol-specific representation of datatypes, in file-i/o protocol
45074
45075 @menu
45076 * Integral Datatypes::
45077 * Pointer Values::
45078 * Memory Transfer::
45079 * struct stat::
45080 * struct timeval::
45081 @end menu
45082
45083 @node Integral Datatypes
45084 @unnumberedsubsubsec Integral Datatypes
45085 @cindex integral datatypes, in file-i/o protocol
45086
45087 The integral datatypes used in the system calls are @code{int},
45088 @code{unsigned int}, @code{long}, @code{unsigned long},
45089 @code{mode_t}, and @code{time_t}.
45090
45091 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
45092 implemented as 32 bit values in this protocol.
45093
45094 @code{long} and @code{unsigned long} are implemented as 64 bit types.
45095
45096 @xref{Limits}, for corresponding MIN and MAX values (similar to those
45097 in @file{limits.h}) to allow range checking on host and target.
45098
45099 @code{time_t} datatypes are defined as seconds since the Epoch.
45100
45101 All integral datatypes transferred as part of a memory read or write of a
45102 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
45103 byte order.
45104
45105 @node Pointer Values
45106 @unnumberedsubsubsec Pointer Values
45107 @cindex pointer values, in file-i/o protocol
45108
45109 Pointers to target data are transmitted as they are. An exception
45110 is made for pointers to buffers for which the length isn't
45111 transmitted as part of the function call, namely strings. Strings
45112 are transmitted as a pointer/length pair, both as hex values, e.g.@:
45113
45114 @smallexample
45115 @code{1aaf/12}
45116 @end smallexample
45117
45118 @noindent
45119 which is a pointer to data of length 18 bytes at position 0x1aaf.
45120 The length is defined as the full string length in bytes, including
45121 the trailing null byte. For example, the string @code{"hello world"}
45122 at address 0x123456 is transmitted as
45123
45124 @smallexample
45125 @code{123456/d}
45126 @end smallexample
45127
45128 @node Memory Transfer
45129 @unnumberedsubsubsec Memory Transfer
45130 @cindex memory transfer, in file-i/o protocol
45131
45132 Structured data which is transferred using a memory read or write (for
45133 example, a @code{struct stat}) is expected to be in a protocol-specific format
45134 with all scalar multibyte datatypes being big endian. Translation to
45135 this representation needs to be done both by the target before the @code{F}
45136 packet is sent, and by @value{GDBN} before
45137 it transfers memory to the target. Transferred pointers to structured
45138 data should point to the already-coerced data at any time.
45139
45140
45141 @node struct stat
45142 @unnumberedsubsubsec struct stat
45143 @cindex struct stat, in file-i/o protocol
45144
45145 The buffer of type @code{struct stat} used by the target and @value{GDBN}
45146 is defined as follows:
45147
45148 @smallexample
45149 struct stat @{
45150 unsigned int st_dev; /* device */
45151 unsigned int st_ino; /* inode */
45152 mode_t st_mode; /* protection */
45153 unsigned int st_nlink; /* number of hard links */
45154 unsigned int st_uid; /* user ID of owner */
45155 unsigned int st_gid; /* group ID of owner */
45156 unsigned int st_rdev; /* device type (if inode device) */
45157 unsigned long st_size; /* total size, in bytes */
45158 unsigned long st_blksize; /* blocksize for filesystem I/O */
45159 unsigned long st_blocks; /* number of blocks allocated */
45160 time_t st_atime; /* time of last access */
45161 time_t st_mtime; /* time of last modification */
45162 time_t st_ctime; /* time of last change */
45163 @};
45164 @end smallexample
45165
45166 The integral datatypes conform to the definitions given in the
45167 appropriate section (see @ref{Integral Datatypes}, for details) so this
45168 structure is of size 64 bytes.
45169
45170 The values of several fields have a restricted meaning and/or
45171 range of values.
45172
45173 @table @code
45174
45175 @item st_dev
45176 A value of 0 represents a file, 1 the console.
45177
45178 @item st_ino
45179 No valid meaning for the target. Transmitted unchanged.
45180
45181 @item st_mode
45182 Valid mode bits are described in @ref{Constants}. Any other
45183 bits have currently no meaning for the target.
45184
45185 @item st_uid
45186 @itemx st_gid
45187 @itemx st_rdev
45188 No valid meaning for the target. Transmitted unchanged.
45189
45190 @item st_atime
45191 @itemx st_mtime
45192 @itemx st_ctime
45193 These values have a host and file system dependent
45194 accuracy. Especially on Windows hosts, the file system may not
45195 support exact timing values.
45196 @end table
45197
45198 The target gets a @code{struct stat} of the above representation and is
45199 responsible for coercing it to the target representation before
45200 continuing.
45201
45202 Note that due to size differences between the host, target, and protocol
45203 representations of @code{struct stat} members, these members could eventually
45204 get truncated on the target.
45205
45206 @node struct timeval
45207 @unnumberedsubsubsec struct timeval
45208 @cindex struct timeval, in file-i/o protocol
45209
45210 The buffer of type @code{struct timeval} used by the File-I/O protocol
45211 is defined as follows:
45212
45213 @smallexample
45214 struct timeval @{
45215 time_t tv_sec; /* second */
45216 long tv_usec; /* microsecond */
45217 @};
45218 @end smallexample
45219
45220 The integral datatypes conform to the definitions given in the
45221 appropriate section (see @ref{Integral Datatypes}, for details) so this
45222 structure is of size 8 bytes.
45223
45224 @node Constants
45225 @subsection Constants
45226 @cindex constants, in file-i/o protocol
45227
45228 The following values are used for the constants inside of the
45229 protocol. @value{GDBN} and target are responsible for translating these
45230 values before and after the call as needed.
45231
45232 @menu
45233 * Open Flags::
45234 * mode_t Values::
45235 * Errno Values::
45236 * Lseek Flags::
45237 * Limits::
45238 @end menu
45239
45240 @node Open Flags
45241 @unnumberedsubsubsec Open Flags
45242 @cindex open flags, in file-i/o protocol
45243
45244 All values are given in hexadecimal representation.
45245
45246 @smallexample
45247 O_RDONLY 0x0
45248 O_WRONLY 0x1
45249 O_RDWR 0x2
45250 O_APPEND 0x8
45251 O_CREAT 0x200
45252 O_TRUNC 0x400
45253 O_EXCL 0x800
45254 @end smallexample
45255
45256 @node mode_t Values
45257 @unnumberedsubsubsec mode_t Values
45258 @cindex mode_t values, in file-i/o protocol
45259
45260 All values are given in octal representation.
45261
45262 @smallexample
45263 S_IFREG 0100000
45264 S_IFDIR 040000
45265 S_IRUSR 0400
45266 S_IWUSR 0200
45267 S_IXUSR 0100
45268 S_IRGRP 040
45269 S_IWGRP 020
45270 S_IXGRP 010
45271 S_IROTH 04
45272 S_IWOTH 02
45273 S_IXOTH 01
45274 @end smallexample
45275
45276 @node Errno Values
45277 @unnumberedsubsubsec Errno Values
45278 @cindex errno values, in file-i/o protocol
45279
45280 All values are given in decimal representation.
45281
45282 @smallexample
45283 EPERM 1
45284 ENOENT 2
45285 EINTR 4
45286 EBADF 9
45287 EACCES 13
45288 EFAULT 14
45289 EBUSY 16
45290 EEXIST 17
45291 ENODEV 19
45292 ENOTDIR 20
45293 EISDIR 21
45294 EINVAL 22
45295 ENFILE 23
45296 EMFILE 24
45297 EFBIG 27
45298 ENOSPC 28
45299 ESPIPE 29
45300 EROFS 30
45301 ENAMETOOLONG 91
45302 EUNKNOWN 9999
45303 @end smallexample
45304
45305 @code{EUNKNOWN} is used as a fallback error value if a host system returns
45306 any error value not in the list of supported error numbers.
45307
45308 @node Lseek Flags
45309 @unnumberedsubsubsec Lseek Flags
45310 @cindex lseek flags, in file-i/o protocol
45311
45312 @smallexample
45313 SEEK_SET 0
45314 SEEK_CUR 1
45315 SEEK_END 2
45316 @end smallexample
45317
45318 @node Limits
45319 @unnumberedsubsubsec Limits
45320 @cindex limits, in file-i/o protocol
45321
45322 All values are given in decimal representation.
45323
45324 @smallexample
45325 INT_MIN -2147483648
45326 INT_MAX 2147483647
45327 UINT_MAX 4294967295
45328 LONG_MIN -9223372036854775808
45329 LONG_MAX 9223372036854775807
45330 ULONG_MAX 18446744073709551615
45331 @end smallexample
45332
45333 @node File-I/O Examples
45334 @subsection File-I/O Examples
45335 @cindex file-i/o examples
45336
45337 Example sequence of a write call, file descriptor 3, buffer is at target
45338 address 0x1234, 6 bytes should be written:
45339
45340 @smallexample
45341 <- @code{Fwrite,3,1234,6}
45342 @emph{request memory read from target}
45343 -> @code{m1234,6}
45344 <- XXXXXX
45345 @emph{return "6 bytes written"}
45346 -> @code{F6}
45347 @end smallexample
45348
45349 Example sequence of a read call, file descriptor 3, buffer is at target
45350 address 0x1234, 6 bytes should be read:
45351
45352 @smallexample
45353 <- @code{Fread,3,1234,6}
45354 @emph{request memory write to target}
45355 -> @code{X1234,6:XXXXXX}
45356 @emph{return "6 bytes read"}
45357 -> @code{F6}
45358 @end smallexample
45359
45360 Example sequence of a read call, call fails on the host due to invalid
45361 file descriptor (@code{EBADF}):
45362
45363 @smallexample
45364 <- @code{Fread,3,1234,6}
45365 -> @code{F-1,9}
45366 @end smallexample
45367
45368 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
45369 host is called:
45370
45371 @smallexample
45372 <- @code{Fread,3,1234,6}
45373 -> @code{F-1,4,C}
45374 <- @code{T02}
45375 @end smallexample
45376
45377 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
45378 host is called:
45379
45380 @smallexample
45381 <- @code{Fread,3,1234,6}
45382 -> @code{X1234,6:XXXXXX}
45383 <- @code{T02}
45384 @end smallexample
45385
45386 @node Library List Format
45387 @section Library List Format
45388 @cindex library list format, remote protocol
45389
45390 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
45391 same process as your application to manage libraries. In this case,
45392 @value{GDBN} can use the loader's symbol table and normal memory
45393 operations to maintain a list of shared libraries. On other
45394 platforms, the operating system manages loaded libraries.
45395 @value{GDBN} can not retrieve the list of currently loaded libraries
45396 through memory operations, so it uses the @samp{qXfer:libraries:read}
45397 packet (@pxref{qXfer library list read}) instead. The remote stub
45398 queries the target's operating system and reports which libraries
45399 are loaded.
45400
45401 The @samp{qXfer:libraries:read} packet returns an XML document which
45402 lists loaded libraries and their offsets. Each library has an
45403 associated name and one or more segment or section base addresses,
45404 which report where the library was loaded in memory.
45405
45406 For the common case of libraries that are fully linked binaries, the
45407 library should have a list of segments. If the target supports
45408 dynamic linking of a relocatable object file, its library XML element
45409 should instead include a list of allocated sections. The segment or
45410 section bases are start addresses, not relocation offsets; they do not
45411 depend on the library's link-time base addresses.
45412
45413 @value{GDBN} must be linked with the Expat library to support XML
45414 library lists. @xref{Expat}.
45415
45416 A simple memory map, with one loaded library relocated by a single
45417 offset, looks like this:
45418
45419 @smallexample
45420 <library-list>
45421 <library name="/lib/libc.so.6">
45422 <segment address="0x10000000"/>
45423 </library>
45424 </library-list>
45425 @end smallexample
45426
45427 Another simple memory map, with one loaded library with three
45428 allocated sections (.text, .data, .bss), looks like this:
45429
45430 @smallexample
45431 <library-list>
45432 <library name="sharedlib.o">
45433 <section address="0x10000000"/>
45434 <section address="0x20000000"/>
45435 <section address="0x30000000"/>
45436 </library>
45437 </library-list>
45438 @end smallexample
45439
45440 The format of a library list is described by this DTD:
45441
45442 @smallexample
45443 <!-- library-list: Root element with versioning -->
45444 <!ELEMENT library-list (library)*>
45445 <!ATTLIST library-list version CDATA #FIXED "1.0">
45446 <!ELEMENT library (segment*, section*)>
45447 <!ATTLIST library name CDATA #REQUIRED>
45448 <!ELEMENT segment EMPTY>
45449 <!ATTLIST segment address CDATA #REQUIRED>
45450 <!ELEMENT section EMPTY>
45451 <!ATTLIST section address CDATA #REQUIRED>
45452 @end smallexample
45453
45454 In addition, segments and section descriptors cannot be mixed within a
45455 single library element, and you must supply at least one segment or
45456 section for each library.
45457
45458 @node Library List Format for SVR4 Targets
45459 @section Library List Format for SVR4 Targets
45460 @cindex library list format, remote protocol
45461
45462 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
45463 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
45464 shared libraries. Still a special library list provided by this packet is
45465 more efficient for the @value{GDBN} remote protocol.
45466
45467 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
45468 loaded libraries and their SVR4 linker parameters. For each library on SVR4
45469 target, the following parameters are reported:
45470
45471 @itemize @minus
45472 @item
45473 @code{name}, the absolute file name from the @code{l_name} field of
45474 @code{struct link_map}.
45475 @item
45476 @code{lm} with address of @code{struct link_map} used for TLS
45477 (Thread Local Storage) access.
45478 @item
45479 @code{l_addr}, the displacement as read from the field @code{l_addr} of
45480 @code{struct link_map}. For prelinked libraries this is not an absolute
45481 memory address. It is a displacement of absolute memory address against
45482 address the file was prelinked to during the library load.
45483 @item
45484 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
45485 @end itemize
45486
45487 Additionally the single @code{main-lm} attribute specifies address of
45488 @code{struct link_map} used for the main executable. This parameter is used
45489 for TLS access and its presence is optional.
45490
45491 @value{GDBN} must be linked with the Expat library to support XML
45492 SVR4 library lists. @xref{Expat}.
45493
45494 A simple memory map, with two loaded libraries (which do not use prelink),
45495 looks like this:
45496
45497 @smallexample
45498 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
45499 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
45500 l_ld="0xe4eefc"/>
45501 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
45502 l_ld="0x152350"/>
45503 </library-list-svr>
45504 @end smallexample
45505
45506 The format of an SVR4 library list is described by this DTD:
45507
45508 @smallexample
45509 <!-- library-list-svr4: Root element with versioning -->
45510 <!ELEMENT library-list-svr4 (library)*>
45511 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
45512 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
45513 <!ELEMENT library EMPTY>
45514 <!ATTLIST library name CDATA #REQUIRED>
45515 <!ATTLIST library lm CDATA #REQUIRED>
45516 <!ATTLIST library l_addr CDATA #REQUIRED>
45517 <!ATTLIST library l_ld CDATA #REQUIRED>
45518 @end smallexample
45519
45520 @node Memory Map Format
45521 @section Memory Map Format
45522 @cindex memory map format
45523
45524 To be able to write into flash memory, @value{GDBN} needs to obtain a
45525 memory map from the target. This section describes the format of the
45526 memory map.
45527
45528 The memory map is obtained using the @samp{qXfer:memory-map:read}
45529 (@pxref{qXfer memory map read}) packet and is an XML document that
45530 lists memory regions.
45531
45532 @value{GDBN} must be linked with the Expat library to support XML
45533 memory maps. @xref{Expat}.
45534
45535 The top-level structure of the document is shown below:
45536
45537 @smallexample
45538 <?xml version="1.0"?>
45539 <!DOCTYPE memory-map
45540 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45541 "http://sourceware.org/gdb/gdb-memory-map.dtd">
45542 <memory-map>
45543 region...
45544 </memory-map>
45545 @end smallexample
45546
45547 Each region can be either:
45548
45549 @itemize
45550
45551 @item
45552 A region of RAM starting at @var{addr} and extending for @var{length}
45553 bytes from there:
45554
45555 @smallexample
45556 <memory type="ram" start="@var{addr}" length="@var{length}"/>
45557 @end smallexample
45558
45559
45560 @item
45561 A region of read-only memory:
45562
45563 @smallexample
45564 <memory type="rom" start="@var{addr}" length="@var{length}"/>
45565 @end smallexample
45566
45567
45568 @item
45569 A region of flash memory, with erasure blocks @var{blocksize}
45570 bytes in length:
45571
45572 @smallexample
45573 <memory type="flash" start="@var{addr}" length="@var{length}">
45574 <property name="blocksize">@var{blocksize}</property>
45575 </memory>
45576 @end smallexample
45577
45578 @end itemize
45579
45580 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
45581 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
45582 packets to write to addresses in such ranges.
45583
45584 The formal DTD for memory map format is given below:
45585
45586 @smallexample
45587 <!-- ................................................... -->
45588 <!-- Memory Map XML DTD ................................ -->
45589 <!-- File: memory-map.dtd .............................. -->
45590 <!-- .................................... .............. -->
45591 <!-- memory-map.dtd -->
45592 <!-- memory-map: Root element with versioning -->
45593 <!ELEMENT memory-map (memory)*>
45594 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
45595 <!ELEMENT memory (property)*>
45596 <!-- memory: Specifies a memory region,
45597 and its type, or device. -->
45598 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
45599 start CDATA #REQUIRED
45600 length CDATA #REQUIRED>
45601 <!-- property: Generic attribute tag -->
45602 <!ELEMENT property (#PCDATA | property)*>
45603 <!ATTLIST property name (blocksize) #REQUIRED>
45604 @end smallexample
45605
45606 @node Thread List Format
45607 @section Thread List Format
45608 @cindex thread list format
45609
45610 To efficiently update the list of threads and their attributes,
45611 @value{GDBN} issues the @samp{qXfer:threads:read} packet
45612 (@pxref{qXfer threads read}) and obtains the XML document with
45613 the following structure:
45614
45615 @smallexample
45616 <?xml version="1.0"?>
45617 <threads>
45618 <thread id="id" core="0" name="name">
45619 ... description ...
45620 </thread>
45621 </threads>
45622 @end smallexample
45623
45624 Each @samp{thread} element must have the @samp{id} attribute that
45625 identifies the thread (@pxref{thread-id syntax}). The
45626 @samp{core} attribute, if present, specifies which processor core
45627 the thread was last executing on. The @samp{name} attribute, if
45628 present, specifies the human-readable name of the thread. The content
45629 of the of @samp{thread} element is interpreted as human-readable
45630 auxiliary information. The @samp{handle} attribute, if present,
45631 is a hex encoded representation of the thread handle.
45632
45633
45634 @node Traceframe Info Format
45635 @section Traceframe Info Format
45636 @cindex traceframe info format
45637
45638 To be able to know which objects in the inferior can be examined when
45639 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
45640 memory ranges, registers and trace state variables that have been
45641 collected in a traceframe.
45642
45643 This list is obtained using the @samp{qXfer:traceframe-info:read}
45644 (@pxref{qXfer traceframe info read}) packet and is an XML document.
45645
45646 @value{GDBN} must be linked with the Expat library to support XML
45647 traceframe info discovery. @xref{Expat}.
45648
45649 The top-level structure of the document is shown below:
45650
45651 @smallexample
45652 <?xml version="1.0"?>
45653 <!DOCTYPE traceframe-info
45654 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45655 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
45656 <traceframe-info>
45657 block...
45658 </traceframe-info>
45659 @end smallexample
45660
45661 Each traceframe block can be either:
45662
45663 @itemize
45664
45665 @item
45666 A region of collected memory starting at @var{addr} and extending for
45667 @var{length} bytes from there:
45668
45669 @smallexample
45670 <memory start="@var{addr}" length="@var{length}"/>
45671 @end smallexample
45672
45673 @item
45674 A block indicating trace state variable numbered @var{number} has been
45675 collected:
45676
45677 @smallexample
45678 <tvar id="@var{number}"/>
45679 @end smallexample
45680
45681 @end itemize
45682
45683 The formal DTD for the traceframe info format is given below:
45684
45685 @smallexample
45686 <!ELEMENT traceframe-info (memory | tvar)* >
45687 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
45688
45689 <!ELEMENT memory EMPTY>
45690 <!ATTLIST memory start CDATA #REQUIRED
45691 length CDATA #REQUIRED>
45692 <!ELEMENT tvar>
45693 <!ATTLIST tvar id CDATA #REQUIRED>
45694 @end smallexample
45695
45696 @node Branch Trace Format
45697 @section Branch Trace Format
45698 @cindex branch trace format
45699
45700 In order to display the branch trace of an inferior thread,
45701 @value{GDBN} needs to obtain the list of branches. This list is
45702 represented as list of sequential code blocks that are connected via
45703 branches. The code in each block has been executed sequentially.
45704
45705 This list is obtained using the @samp{qXfer:btrace:read}
45706 (@pxref{qXfer btrace read}) packet and is an XML document.
45707
45708 @value{GDBN} must be linked with the Expat library to support XML
45709 traceframe info discovery. @xref{Expat}.
45710
45711 The top-level structure of the document is shown below:
45712
45713 @smallexample
45714 <?xml version="1.0"?>
45715 <!DOCTYPE btrace
45716 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
45717 "http://sourceware.org/gdb/gdb-btrace.dtd">
45718 <btrace>
45719 block...
45720 </btrace>
45721 @end smallexample
45722
45723 @itemize
45724
45725 @item
45726 A block of sequentially executed instructions starting at @var{begin}
45727 and ending at @var{end}:
45728
45729 @smallexample
45730 <block begin="@var{begin}" end="@var{end}"/>
45731 @end smallexample
45732
45733 @end itemize
45734
45735 The formal DTD for the branch trace format is given below:
45736
45737 @smallexample
45738 <!ELEMENT btrace (block* | pt) >
45739 <!ATTLIST btrace version CDATA #FIXED "1.0">
45740
45741 <!ELEMENT block EMPTY>
45742 <!ATTLIST block begin CDATA #REQUIRED
45743 end CDATA #REQUIRED>
45744
45745 <!ELEMENT pt (pt-config?, raw?)>
45746
45747 <!ELEMENT pt-config (cpu?)>
45748
45749 <!ELEMENT cpu EMPTY>
45750 <!ATTLIST cpu vendor CDATA #REQUIRED
45751 family CDATA #REQUIRED
45752 model CDATA #REQUIRED
45753 stepping CDATA #REQUIRED>
45754
45755 <!ELEMENT raw (#PCDATA)>
45756 @end smallexample
45757
45758 @node Branch Trace Configuration Format
45759 @section Branch Trace Configuration Format
45760 @cindex branch trace configuration format
45761
45762 For each inferior thread, @value{GDBN} can obtain the branch trace
45763 configuration using the @samp{qXfer:btrace-conf:read}
45764 (@pxref{qXfer btrace-conf read}) packet.
45765
45766 The configuration describes the branch trace format and configuration
45767 settings for that format. The following information is described:
45768
45769 @table @code
45770 @item bts
45771 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
45772 @table @code
45773 @item size
45774 The size of the @acronym{BTS} ring buffer in bytes.
45775 @end table
45776 @item pt
45777 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
45778 PT}) format.
45779 @table @code
45780 @item size
45781 The size of the @acronym{Intel PT} ring buffer in bytes.
45782 @end table
45783 @end table
45784
45785 @value{GDBN} must be linked with the Expat library to support XML
45786 branch trace configuration discovery. @xref{Expat}.
45787
45788 The formal DTD for the branch trace configuration format is given below:
45789
45790 @smallexample
45791 <!ELEMENT btrace-conf (bts?, pt?)>
45792 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
45793
45794 <!ELEMENT bts EMPTY>
45795 <!ATTLIST bts size CDATA #IMPLIED>
45796
45797 <!ELEMENT pt EMPTY>
45798 <!ATTLIST pt size CDATA #IMPLIED>
45799 @end smallexample
45800
45801 @include agentexpr.texi
45802
45803 @node Target Descriptions
45804 @appendix Target Descriptions
45805 @cindex target descriptions
45806
45807 One of the challenges of using @value{GDBN} to debug embedded systems
45808 is that there are so many minor variants of each processor
45809 architecture in use. It is common practice for vendors to start with
45810 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
45811 and then make changes to adapt it to a particular market niche. Some
45812 architectures have hundreds of variants, available from dozens of
45813 vendors. This leads to a number of problems:
45814
45815 @itemize @bullet
45816 @item
45817 With so many different customized processors, it is difficult for
45818 the @value{GDBN} maintainers to keep up with the changes.
45819 @item
45820 Since individual variants may have short lifetimes or limited
45821 audiences, it may not be worthwhile to carry information about every
45822 variant in the @value{GDBN} source tree.
45823 @item
45824 When @value{GDBN} does support the architecture of the embedded system
45825 at hand, the task of finding the correct architecture name to give the
45826 @command{set architecture} command can be error-prone.
45827 @end itemize
45828
45829 To address these problems, the @value{GDBN} remote protocol allows a
45830 target system to not only identify itself to @value{GDBN}, but to
45831 actually describe its own features. This lets @value{GDBN} support
45832 processor variants it has never seen before --- to the extent that the
45833 descriptions are accurate, and that @value{GDBN} understands them.
45834
45835 @value{GDBN} must be linked with the Expat library to support XML
45836 target descriptions. @xref{Expat}.
45837
45838 @menu
45839 * Retrieving Descriptions:: How descriptions are fetched from a target.
45840 * Target Description Format:: The contents of a target description.
45841 * Predefined Target Types:: Standard types available for target
45842 descriptions.
45843 * Enum Target Types:: How to define enum target types.
45844 * Standard Target Features:: Features @value{GDBN} knows about.
45845 @end menu
45846
45847 @node Retrieving Descriptions
45848 @section Retrieving Descriptions
45849
45850 Target descriptions can be read from the target automatically, or
45851 specified by the user manually. The default behavior is to read the
45852 description from the target. @value{GDBN} retrieves it via the remote
45853 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
45854 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
45855 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
45856 XML document, of the form described in @ref{Target Description
45857 Format}.
45858
45859 Alternatively, you can specify a file to read for the target description.
45860 If a file is set, the target will not be queried. The commands to
45861 specify a file are:
45862
45863 @table @code
45864 @cindex set tdesc filename
45865 @item set tdesc filename @var{path}
45866 Read the target description from @var{path}.
45867
45868 @cindex unset tdesc filename
45869 @item unset tdesc filename
45870 Do not read the XML target description from a file. @value{GDBN}
45871 will use the description supplied by the current target.
45872
45873 @cindex show tdesc filename
45874 @item show tdesc filename
45875 Show the filename to read for a target description, if any.
45876 @end table
45877
45878
45879 @node Target Description Format
45880 @section Target Description Format
45881 @cindex target descriptions, XML format
45882
45883 A target description annex is an @uref{http://www.w3.org/XML/, XML}
45884 document which complies with the Document Type Definition provided in
45885 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45886 means you can use generally available tools like @command{xmllint} to
45887 check that your feature descriptions are well-formed and valid.
45888 However, to help people unfamiliar with XML write descriptions for
45889 their targets, we also describe the grammar here.
45890
45891 Target descriptions can identify the architecture of the remote target
45892 and (for some architectures) provide information about custom register
45893 sets. They can also identify the OS ABI of the remote target.
45894 @value{GDBN} can use this information to autoconfigure for your
45895 target, or to warn you if you connect to an unsupported target.
45896
45897 Here is a simple target description:
45898
45899 @smallexample
45900 <target version="1.0">
45901 <architecture>i386:x86-64</architecture>
45902 </target>
45903 @end smallexample
45904
45905 @noindent
45906 This minimal description only says that the target uses
45907 the x86-64 architecture.
45908
45909 A target description has the following overall form, with [ ] marking
45910 optional elements and @dots{} marking repeatable elements. The elements
45911 are explained further below.
45912
45913 @smallexample
45914 <?xml version="1.0"?>
45915 <!DOCTYPE target SYSTEM "gdb-target.dtd">
45916 <target version="1.0">
45917 @r{[}@var{architecture}@r{]}
45918 @r{[}@var{osabi}@r{]}
45919 @r{[}@var{compatible}@r{]}
45920 @r{[}@var{feature}@dots{}@r{]}
45921 </target>
45922 @end smallexample
45923
45924 @noindent
45925 The description is generally insensitive to whitespace and line
45926 breaks, under the usual common-sense rules. The XML version
45927 declaration and document type declaration can generally be omitted
45928 (@value{GDBN} does not require them), but specifying them may be
45929 useful for XML validation tools. The @samp{version} attribute for
45930 @samp{<target>} may also be omitted, but we recommend
45931 including it; if future versions of @value{GDBN} use an incompatible
45932 revision of @file{gdb-target.dtd}, they will detect and report
45933 the version mismatch.
45934
45935 @subsection Inclusion
45936 @cindex target descriptions, inclusion
45937 @cindex XInclude
45938 @ifnotinfo
45939 @cindex <xi:include>
45940 @end ifnotinfo
45941
45942 It can sometimes be valuable to split a target description up into
45943 several different annexes, either for organizational purposes, or to
45944 share files between different possible target descriptions. You can
45945 divide a description into multiple files by replacing any element of
45946 the target description with an inclusion directive of the form:
45947
45948 @smallexample
45949 <xi:include href="@var{document}"/>
45950 @end smallexample
45951
45952 @noindent
45953 When @value{GDBN} encounters an element of this form, it will retrieve
45954 the named XML @var{document}, and replace the inclusion directive with
45955 the contents of that document. If the current description was read
45956 using @samp{qXfer}, then so will be the included document;
45957 @var{document} will be interpreted as the name of an annex. If the
45958 current description was read from a file, @value{GDBN} will look for
45959 @var{document} as a file in the same directory where it found the
45960 original description.
45961
45962 @subsection Architecture
45963 @cindex <architecture>
45964
45965 An @samp{<architecture>} element has this form:
45966
45967 @smallexample
45968 <architecture>@var{arch}</architecture>
45969 @end smallexample
45970
45971 @var{arch} is one of the architectures from the set accepted by
45972 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45973
45974 @subsection OS ABI
45975 @cindex @code{<osabi>}
45976
45977 This optional field was introduced in @value{GDBN} version 7.0.
45978 Previous versions of @value{GDBN} ignore it.
45979
45980 An @samp{<osabi>} element has this form:
45981
45982 @smallexample
45983 <osabi>@var{abi-name}</osabi>
45984 @end smallexample
45985
45986 @var{abi-name} is an OS ABI name from the same selection accepted by
45987 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45988
45989 @subsection Compatible Architecture
45990 @cindex @code{<compatible>}
45991
45992 This optional field was introduced in @value{GDBN} version 7.0.
45993 Previous versions of @value{GDBN} ignore it.
45994
45995 A @samp{<compatible>} element has this form:
45996
45997 @smallexample
45998 <compatible>@var{arch}</compatible>
45999 @end smallexample
46000
46001 @var{arch} is one of the architectures from the set accepted by
46002 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
46003
46004 A @samp{<compatible>} element is used to specify that the target
46005 is able to run binaries in some other than the main target architecture
46006 given by the @samp{<architecture>} element. For example, on the
46007 Cell Broadband Engine, the main architecture is @code{powerpc:common}
46008 or @code{powerpc:common64}, but the system is able to run binaries
46009 in the @code{spu} architecture as well. The way to describe this
46010 capability with @samp{<compatible>} is as follows:
46011
46012 @smallexample
46013 <architecture>powerpc:common</architecture>
46014 <compatible>spu</compatible>
46015 @end smallexample
46016
46017 @subsection Features
46018 @cindex <feature>
46019
46020 Each @samp{<feature>} describes some logical portion of the target
46021 system. Features are currently used to describe available CPU
46022 registers and the types of their contents. A @samp{<feature>} element
46023 has this form:
46024
46025 @smallexample
46026 <feature name="@var{name}">
46027 @r{[}@var{type}@dots{}@r{]}
46028 @var{reg}@dots{}
46029 </feature>
46030 @end smallexample
46031
46032 @noindent
46033 Each feature's name should be unique within the description. The name
46034 of a feature does not matter unless @value{GDBN} has some special
46035 knowledge of the contents of that feature; if it does, the feature
46036 should have its standard name. @xref{Standard Target Features}.
46037
46038 @subsection Types
46039
46040 Any register's value is a collection of bits which @value{GDBN} must
46041 interpret. The default interpretation is a two's complement integer,
46042 but other types can be requested by name in the register description.
46043 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
46044 Target Types}), and the description can define additional composite
46045 and enum types.
46046
46047 Each type element must have an @samp{id} attribute, which gives
46048 a unique (within the containing @samp{<feature>}) name to the type.
46049 Types must be defined before they are used.
46050
46051 @cindex <vector>
46052 Some targets offer vector registers, which can be treated as arrays
46053 of scalar elements. These types are written as @samp{<vector>} elements,
46054 specifying the array element type, @var{type}, and the number of elements,
46055 @var{count}:
46056
46057 @smallexample
46058 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
46059 @end smallexample
46060
46061 @cindex <union>
46062 If a register's value is usefully viewed in multiple ways, define it
46063 with a union type containing the useful representations. The
46064 @samp{<union>} element contains one or more @samp{<field>} elements,
46065 each of which has a @var{name} and a @var{type}:
46066
46067 @smallexample
46068 <union id="@var{id}">
46069 <field name="@var{name}" type="@var{type}"/>
46070 @dots{}
46071 </union>
46072 @end smallexample
46073
46074 @cindex <struct>
46075 @cindex <flags>
46076 If a register's value is composed from several separate values, define
46077 it with either a structure type or a flags type.
46078 A flags type may only contain bitfields.
46079 A structure type may either contain only bitfields or contain no bitfields.
46080 If the value contains only bitfields, its total size in bytes must be
46081 specified.
46082
46083 Non-bitfield values have a @var{name} and @var{type}.
46084
46085 @smallexample
46086 <struct id="@var{id}">
46087 <field name="@var{name}" type="@var{type}"/>
46088 @dots{}
46089 </struct>
46090 @end smallexample
46091
46092 Both @var{name} and @var{type} values are required.
46093 No implicit padding is added.
46094
46095 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
46096
46097 @smallexample
46098 <struct id="@var{id}" size="@var{size}">
46099 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
46100 @dots{}
46101 </struct>
46102 @end smallexample
46103
46104 @smallexample
46105 <flags id="@var{id}" size="@var{size}">
46106 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
46107 @dots{}
46108 </flags>
46109 @end smallexample
46110
46111 The @var{name} value is required.
46112 Bitfield values may be named with the empty string, @samp{""},
46113 in which case the field is ``filler'' and its value is not printed.
46114 Not all bits need to be specified, so ``filler'' fields are optional.
46115
46116 The @var{start} and @var{end} values are required, and @var{type}
46117 is optional.
46118 The field's @var{start} must be less than or equal to its @var{end},
46119 and zero represents the least significant bit.
46120
46121 The default value of @var{type} is @code{bool} for single bit fields,
46122 and an unsigned integer otherwise.
46123
46124 Which to choose? Structures or flags?
46125
46126 Registers defined with @samp{flags} have these advantages over
46127 defining them with @samp{struct}:
46128
46129 @itemize @bullet
46130 @item
46131 Arithmetic may be performed on them as if they were integers.
46132 @item
46133 They are printed in a more readable fashion.
46134 @end itemize
46135
46136 Registers defined with @samp{struct} have one advantage over
46137 defining them with @samp{flags}:
46138
46139 @itemize @bullet
46140 @item
46141 One can fetch individual fields like in @samp{C}.
46142
46143 @smallexample
46144 (gdb) print $my_struct_reg.field3
46145 $1 = 42
46146 @end smallexample
46147
46148 @end itemize
46149
46150 @subsection Registers
46151 @cindex <reg>
46152
46153 Each register is represented as an element with this form:
46154
46155 @smallexample
46156 <reg name="@var{name}"
46157 bitsize="@var{size}"
46158 @r{[}regnum="@var{num}"@r{]}
46159 @r{[}save-restore="@var{save-restore}"@r{]}
46160 @r{[}type="@var{type}"@r{]}
46161 @r{[}group="@var{group}"@r{]}/>
46162 @end smallexample
46163
46164 @noindent
46165 The components are as follows:
46166
46167 @table @var
46168
46169 @item name
46170 The register's name; it must be unique within the target description.
46171
46172 @item bitsize
46173 The register's size, in bits.
46174
46175 @item regnum
46176 The register's number. If omitted, a register's number is one greater
46177 than that of the previous register (either in the current feature or in
46178 a preceding feature); the first register in the target description
46179 defaults to zero. This register number is used to read or write
46180 the register; e.g.@: it is used in the remote @code{p} and @code{P}
46181 packets, and registers appear in the @code{g} and @code{G} packets
46182 in order of increasing register number.
46183
46184 @item save-restore
46185 Whether the register should be preserved across inferior function
46186 calls; this must be either @code{yes} or @code{no}. The default is
46187 @code{yes}, which is appropriate for most registers except for
46188 some system control registers; this is not related to the target's
46189 ABI.
46190
46191 @item type
46192 The type of the register. It may be a predefined type, a type
46193 defined in the current feature, or one of the special types @code{int}
46194 and @code{float}. @code{int} is an integer type of the correct size
46195 for @var{bitsize}, and @code{float} is a floating point type (in the
46196 architecture's normal floating point format) of the correct size for
46197 @var{bitsize}. The default is @code{int}.
46198
46199 @item group
46200 The register group to which this register belongs. It can be one of the
46201 standard register groups @code{general}, @code{float}, @code{vector} or an
46202 arbitrary string. Group names should be limited to alphanumeric characters.
46203 If a group name is made up of multiple words the words may be separated by
46204 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
46205 @var{group} is specified, @value{GDBN} will not display the register in
46206 @code{info registers}.
46207
46208 @end table
46209
46210 @node Predefined Target Types
46211 @section Predefined Target Types
46212 @cindex target descriptions, predefined types
46213
46214 Type definitions in the self-description can build up composite types
46215 from basic building blocks, but can not define fundamental types. Instead,
46216 standard identifiers are provided by @value{GDBN} for the fundamental
46217 types. The currently supported types are:
46218
46219 @table @code
46220
46221 @item bool
46222 Boolean type, occupying a single bit.
46223
46224 @item int8
46225 @itemx int16
46226 @itemx int24
46227 @itemx int32
46228 @itemx int64
46229 @itemx int128
46230 Signed integer types holding the specified number of bits.
46231
46232 @item uint8
46233 @itemx uint16
46234 @itemx uint24
46235 @itemx uint32
46236 @itemx uint64
46237 @itemx uint128
46238 Unsigned integer types holding the specified number of bits.
46239
46240 @item code_ptr
46241 @itemx data_ptr
46242 Pointers to unspecified code and data. The program counter and
46243 any dedicated return address register may be marked as code
46244 pointers; printing a code pointer converts it into a symbolic
46245 address. The stack pointer and any dedicated address registers
46246 may be marked as data pointers.
46247
46248 @item ieee_half
46249 Half precision IEEE floating point.
46250
46251 @item ieee_single
46252 Single precision IEEE floating point.
46253
46254 @item ieee_double
46255 Double precision IEEE floating point.
46256
46257 @item bfloat16
46258 The 16-bit @dfn{brain floating point} format used e.g.@: by x86 and ARM.
46259
46260 @item arm_fpa_ext
46261 The 12-byte extended precision format used by ARM FPA registers.
46262
46263 @item i387_ext
46264 The 10-byte extended precision format used by x87 registers.
46265
46266 @item i386_eflags
46267 32bit @sc{eflags} register used by x86.
46268
46269 @item i386_mxcsr
46270 32bit @sc{mxcsr} register used by x86.
46271
46272 @end table
46273
46274 @node Enum Target Types
46275 @section Enum Target Types
46276 @cindex target descriptions, enum types
46277
46278 Enum target types are useful in @samp{struct} and @samp{flags}
46279 register descriptions. @xref{Target Description Format}.
46280
46281 Enum types have a name, size and a list of name/value pairs.
46282
46283 @smallexample
46284 <enum id="@var{id}" size="@var{size}">
46285 <evalue name="@var{name}" value="@var{value}"/>
46286 @dots{}
46287 </enum>
46288 @end smallexample
46289
46290 Enums must be defined before they are used.
46291
46292 @smallexample
46293 <enum id="levels_type" size="4">
46294 <evalue name="low" value="0"/>
46295 <evalue name="high" value="1"/>
46296 </enum>
46297 <flags id="flags_type" size="4">
46298 <field name="X" start="0"/>
46299 <field name="LEVEL" start="1" end="1" type="levels_type"/>
46300 </flags>
46301 <reg name="flags" bitsize="32" type="flags_type"/>
46302 @end smallexample
46303
46304 Given that description, a value of 3 for the @samp{flags} register
46305 would be printed as:
46306
46307 @smallexample
46308 (gdb) info register flags
46309 flags 0x3 [ X LEVEL=high ]
46310 @end smallexample
46311
46312 @node Standard Target Features
46313 @section Standard Target Features
46314 @cindex target descriptions, standard features
46315
46316 A target description must contain either no registers or all the
46317 target's registers. If the description contains no registers, then
46318 @value{GDBN} will assume a default register layout, selected based on
46319 the architecture. If the description contains any registers, the
46320 default layout will not be used; the standard registers must be
46321 described in the target description, in such a way that @value{GDBN}
46322 can recognize them.
46323
46324 This is accomplished by giving specific names to feature elements
46325 which contain standard registers. @value{GDBN} will look for features
46326 with those names and verify that they contain the expected registers;
46327 if any known feature is missing required registers, or if any required
46328 feature is missing, @value{GDBN} will reject the target
46329 description. You can add additional registers to any of the
46330 standard features --- @value{GDBN} will display them just as if
46331 they were added to an unrecognized feature.
46332
46333 This section lists the known features and their expected contents.
46334 Sample XML documents for these features are included in the
46335 @value{GDBN} source tree, in the directory @file{gdb/features}.
46336
46337 Names recognized by @value{GDBN} should include the name of the
46338 company or organization which selected the name, and the overall
46339 architecture to which the feature applies; so e.g.@: the feature
46340 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
46341
46342 The names of registers are not case sensitive for the purpose
46343 of recognizing standard features, but @value{GDBN} will only display
46344 registers using the capitalization used in the description.
46345
46346 @menu
46347 * AArch64 Features::
46348 * ARC Features::
46349 * ARM Features::
46350 * i386 Features::
46351 * LoongArch Features::
46352 * MicroBlaze Features::
46353 * MIPS Features::
46354 * M68K Features::
46355 * NDS32 Features::
46356 * Nios II Features::
46357 * OpenRISC 1000 Features::
46358 * PowerPC Features::
46359 * RISC-V Features::
46360 * RX Features::
46361 * S/390 and System z Features::
46362 * Sparc Features::
46363 * TIC6x Features::
46364 @end menu
46365
46366
46367 @node AArch64 Features
46368 @subsection AArch64 Features
46369 @cindex target descriptions, AArch64 features
46370
46371 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
46372 targets. It should contain registers @samp{x0} through @samp{x30},
46373 @samp{sp}, @samp{pc}, and @samp{cpsr}.
46374
46375 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
46376 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
46377 and @samp{fpcr}.
46378
46379 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
46380 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
46381 through @samp{p15}, @samp{ffr} and @samp{vg}.
46382
46383 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
46384 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
46385
46386 @node ARC Features
46387 @subsection ARC Features
46388 @cindex target descriptions, ARC Features
46389
46390 ARC processors are so configurable that even core registers and their numbers
46391 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
46392 registers, which are important to @value{GDBN}, are not ``core'' registers in
46393 ARC. Therefore, there are two features that their presence is mandatory:
46394 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
46395
46396 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
46397 contain registers:
46398
46399 @itemize @minus
46400 @item
46401 @samp{r0} through @samp{r25} for normal register file targets.
46402 @item
46403 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
46404 register file targets.
46405 @item
46406 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
46407 @samp{blink}, @samp{lp_count}, @samp{pcl}.
46408 @end itemize
46409
46410 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
46411 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
46412 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
46413 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
46414 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
46415 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
46416 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
46417 because of their inaccessibility during user space debugging sessions.
46418
46419 Extension core registers @samp{r32} through @samp{r59} are optional and their
46420 existence depends on the configuration. When debugging GNU/Linux applications,
46421 i.e.@: user space debugging, these core registers are not available.
46422
46423 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
46424 is the list of registers pertinent to this feature:
46425
46426 @itemize @minus
46427 @item
46428 mandatory: @samp{pc} and @samp{status32}.
46429 @item
46430 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
46431 @end itemize
46432
46433 @node ARM Features
46434 @subsection ARM Features
46435 @cindex target descriptions, ARM features
46436
46437 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
46438 ARM targets.
46439 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
46440 @samp{lr}, @samp{pc}, and @samp{cpsr}.
46441
46442 For M-profile targets (e.g.@: Cortex-M3), the @samp{org.gnu.gdb.arm.core}
46443 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
46444 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
46445 and @samp{xpsr}.
46446
46447 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
46448 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
46449
46450 The @samp{org.gnu.gdb.arm.m-profile-mve} feature is optional. If present, it
46451 must contain register @samp{vpr}.
46452
46453 If the @samp{org.gnu.gdb.arm.m-profile-mve} feature is available, @value{GDBN}
46454 will synthesize the @samp{p0} pseudo register from @samp{vpr} contents.
46455
46456 If the @samp{org.gnu.gdb.arm.vfp} feature is available alongside the
46457 @samp{org.gnu.gdb.arm.m-profile-mve} feature, @value{GDBN} will
46458 synthesize the @samp{q} pseudo registers from @samp{d} register
46459 contents.
46460
46461 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
46462 it should contain at least registers @samp{wR0} through @samp{wR15} and
46463 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
46464 @samp{wCSSF}, and @samp{wCASF} registers are optional.
46465
46466 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
46467 should contain at least registers @samp{d0} through @samp{d15}. If
46468 they are present, @samp{d16} through @samp{d31} should also be included.
46469 @value{GDBN} will synthesize the single-precision registers from
46470 halves of the double-precision registers.
46471
46472 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
46473 need to contain registers; it instructs @value{GDBN} to display the
46474 VFP double-precision registers as vectors and to synthesize the
46475 quad-precision registers from pairs of double-precision registers.
46476 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
46477 be present and include 32 double-precision registers.
46478
46479 @node i386 Features
46480 @subsection i386 Features
46481 @cindex target descriptions, i386 features
46482
46483 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
46484 targets. It should describe the following registers:
46485
46486 @itemize @minus
46487 @item
46488 @samp{eax} through @samp{edi} plus @samp{eip} for i386
46489 @item
46490 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
46491 @item
46492 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
46493 @samp{fs}, @samp{gs}
46494 @item
46495 @samp{st0} through @samp{st7}
46496 @item
46497 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
46498 @samp{foseg}, @samp{fooff} and @samp{fop}
46499 @end itemize
46500
46501 The register sets may be different, depending on the target.
46502
46503 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
46504 describe registers:
46505
46506 @itemize @minus
46507 @item
46508 @samp{xmm0} through @samp{xmm7} for i386
46509 @item
46510 @samp{xmm0} through @samp{xmm15} for amd64
46511 @item
46512 @samp{mxcsr}
46513 @end itemize
46514
46515 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
46516 @samp{org.gnu.gdb.i386.sse} feature. It should
46517 describe the upper 128 bits of @sc{ymm} registers:
46518
46519 @itemize @minus
46520 @item
46521 @samp{ymm0h} through @samp{ymm7h} for i386
46522 @item
46523 @samp{ymm0h} through @samp{ymm15h} for amd64
46524 @end itemize
46525
46526 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
46527 Memory Protection Extension (MPX). It should describe the following registers:
46528
46529 @itemize @minus
46530 @item
46531 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
46532 @item
46533 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
46534 @end itemize
46535
46536 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
46537 describe a single register, @samp{orig_eax}.
46538
46539 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
46540 describe two system registers: @samp{fs_base} and @samp{gs_base}.
46541
46542 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
46543 @samp{org.gnu.gdb.i386.avx} feature. It should
46544 describe additional @sc{xmm} registers:
46545
46546 @itemize @minus
46547 @item
46548 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
46549 @end itemize
46550
46551 It should describe the upper 128 bits of additional @sc{ymm} registers:
46552
46553 @itemize @minus
46554 @item
46555 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
46556 @end itemize
46557
46558 It should
46559 describe the upper 256 bits of @sc{zmm} registers:
46560
46561 @itemize @minus
46562 @item
46563 @samp{zmm0h} through @samp{zmm7h} for i386.
46564 @item
46565 @samp{zmm0h} through @samp{zmm15h} for amd64.
46566 @end itemize
46567
46568 It should
46569 describe the additional @sc{zmm} registers:
46570
46571 @itemize @minus
46572 @item
46573 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
46574 @end itemize
46575
46576 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
46577 describe a single register, @samp{pkru}. It is a 32-bit register
46578 valid for i386 and amd64.
46579
46580 @node LoongArch Features
46581 @subsection LoongArch Features
46582 @cindex target descriptions, LoongArch Features
46583
46584 The @samp{org.gnu.gdb.loongarch.base} feature is required for LoongArch
46585 targets. It should contain the registers @samp{r0} through @samp{r31},
46586 @samp{pc}, and @samp{badv}. Either the architectural names (@samp{r0},
46587 @samp{r1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra}, etc).
46588
46589 @node MicroBlaze Features
46590 @subsection MicroBlaze Features
46591 @cindex target descriptions, MicroBlaze features
46592
46593 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
46594 targets. It should contain registers @samp{r0} through @samp{r31},
46595 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
46596 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
46597 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
46598
46599 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
46600 If present, it should contain registers @samp{rshr} and @samp{rslr}
46601
46602 @node MIPS Features
46603 @subsection @acronym{MIPS} Features
46604 @cindex target descriptions, @acronym{MIPS} features
46605
46606 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
46607 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
46608 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
46609 on the target.
46610
46611 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
46612 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
46613 registers. They may be 32-bit or 64-bit depending on the target.
46614
46615 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
46616 it may be optional in a future version of @value{GDBN}. It should
46617 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
46618 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
46619
46620 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
46621 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
46622 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
46623 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
46624
46625 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
46626 contain a single register, @samp{restart}, which is used by the
46627 Linux kernel to control restartable syscalls.
46628
46629 @node M68K Features
46630 @subsection M68K Features
46631 @cindex target descriptions, M68K features
46632
46633 @table @code
46634 @item @samp{org.gnu.gdb.m68k.core}
46635 @itemx @samp{org.gnu.gdb.coldfire.core}
46636 @itemx @samp{org.gnu.gdb.fido.core}
46637 One of those features must be always present.
46638 The feature that is present determines which flavor of m68k is
46639 used. The feature that is present should contain registers
46640 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
46641 @samp{sp}, @samp{ps} and @samp{pc}.
46642
46643 @item @samp{org.gnu.gdb.coldfire.fp}
46644 This feature is optional. If present, it should contain registers
46645 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
46646 @samp{fpiaddr}.
46647
46648 Note that, despite the fact that this feature's name says
46649 @samp{coldfire}, it is used to describe any floating point registers.
46650 The size of the registers must match the main m68k flavor; so, for
46651 example, if the primary feature is reported as @samp{coldfire}, then
46652 64-bit floating point registers are required.
46653 @end table
46654
46655 @node NDS32 Features
46656 @subsection NDS32 Features
46657 @cindex target descriptions, NDS32 features
46658
46659 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
46660 targets. It should contain at least registers @samp{r0} through
46661 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
46662 and @samp{pc}.
46663
46664 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
46665 it should contain 64-bit double-precision floating-point registers
46666 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
46667 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
46668
46669 @emph{Note:} The first sixteen 64-bit double-precision floating-point
46670 registers are overlapped with the thirty-two 32-bit single-precision
46671 floating-point registers. The 32-bit single-precision registers, if
46672 not being listed explicitly, will be synthesized from halves of the
46673 overlapping 64-bit double-precision registers. Listing 32-bit
46674 single-precision registers explicitly is deprecated, and the
46675 support to it could be totally removed some day.
46676
46677 @node Nios II Features
46678 @subsection Nios II Features
46679 @cindex target descriptions, Nios II features
46680
46681 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
46682 targets. It should contain the 32 core registers (@samp{zero},
46683 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
46684 @samp{pc}, and the 16 control registers (@samp{status} through
46685 @samp{mpuacc}).
46686
46687 @node OpenRISC 1000 Features
46688 @subsection Openrisc 1000 Features
46689 @cindex target descriptions, OpenRISC 1000 features
46690
46691 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
46692 targets. It should contain the 32 general purpose registers (@samp{r0}
46693 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
46694
46695 @node PowerPC Features
46696 @subsection PowerPC Features
46697 @cindex target descriptions, PowerPC features
46698
46699 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
46700 targets. It should contain registers @samp{r0} through @samp{r31},
46701 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
46702 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
46703
46704 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
46705 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
46706
46707 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
46708 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
46709 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
46710 through @samp{v31} as aliases for the corresponding @samp{vrX}
46711 registers.
46712
46713 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
46714 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
46715 combine these registers with the floating point registers (@samp{f0}
46716 through @samp{f31}) and the altivec registers (@samp{vr0} through
46717 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
46718 @samp{vs63}, the set of vector-scalar registers for POWER7.
46719 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
46720 @samp{org.gnu.gdb.power.altivec}.
46721
46722 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
46723 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
46724 @samp{spefscr}. SPE targets should provide 32-bit registers in
46725 @samp{org.gnu.gdb.power.core} and provide the upper halves in
46726 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
46727 these to present registers @samp{ev0} through @samp{ev31} to the
46728 user.
46729
46730 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
46731 contain the 64-bit register @samp{ppr}.
46732
46733 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
46734 contain the 64-bit register @samp{dscr}.
46735
46736 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
46737 contain the 64-bit register @samp{tar}.
46738
46739 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
46740 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
46741 64-bit wide.
46742
46743 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
46744 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
46745 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
46746 server PMU registers provided by @sc{gnu}/Linux.
46747
46748 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
46749 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
46750 64-bit wide.
46751
46752 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
46753 contain the checkpointed general-purpose registers @samp{cr0} through
46754 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
46755 @samp{cctr}. These registers may all be either 32-bit or 64-bit
46756 depending on the target. It should also contain the checkpointed
46757 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
46758 wide.
46759
46760 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
46761 contain the checkpointed 64-bit floating-point registers @samp{cf0}
46762 through @samp{cf31}, as well as the checkpointed 64-bit register
46763 @samp{cfpscr}.
46764
46765 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
46766 should contain the checkpointed altivec registers @samp{cvr0} through
46767 @samp{cvr31}, all 128-bit wide. It should also contain the
46768 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
46769 wide.
46770
46771 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
46772 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
46773 will combine these registers with the checkpointed floating point
46774 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
46775 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
46776 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
46777 @samp{cvs63}. Therefore, this feature requires both
46778 @samp{org.gnu.gdb.power.htm.altivec} and
46779 @samp{org.gnu.gdb.power.htm.fpu}.
46780
46781 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
46782 contain the 64-bit checkpointed register @samp{cppr}.
46783
46784 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
46785 contain the 64-bit checkpointed register @samp{cdscr}.
46786
46787 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
46788 contain the 64-bit checkpointed register @samp{ctar}.
46789
46790
46791 @node RISC-V Features
46792 @subsection RISC-V Features
46793 @cindex target descriptions, RISC-V Features
46794
46795 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
46796 targets. It should contain the registers @samp{x0} through
46797 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
46798 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
46799 etc).
46800
46801 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
46802 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
46803 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
46804 architectural register names, or the ABI names can be used.
46805
46806 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
46807 it should contain registers that are not backed by real registers on
46808 the target, but are instead virtual, where the register value is
46809 derived from other target state. In many ways these are like
46810 @value{GDBN}s pseudo-registers, except implemented by the target.
46811 Currently the only register expected in this set is the one byte
46812 @samp{priv} register that contains the target's privilege level in the
46813 least significant two bits.
46814
46815 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
46816 should contain all of the target's standard CSRs. Standard CSRs are
46817 those defined in the RISC-V specification documents. There is some
46818 overlap between this feature and the fpu feature; the @samp{fflags},
46819 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
46820 expectation is that these registers will be in the fpu feature if the
46821 target has floating point hardware, but can be moved into the csr
46822 feature if the target has the floating point control registers, but no
46823 other floating point hardware.
46824
46825 The @samp{org.gnu.gdb.riscv.vector} feature is optional. If present,
46826 it should contain registers @samp{v0} through @samp{v31}, all of which
46827 must be the same size. These requirements are based on the v0.10
46828 draft vector extension, as the vector extension is not yet final. In
46829 the event that the register set of the vector extension changes for
46830 the final specification, the requirements given here could change for
46831 future releases of @value{GDBN}.
46832
46833 @node RX Features
46834 @subsection RX Features
46835 @cindex target descriptions, RX Features
46836
46837 The @samp{org.gnu.gdb.rx.core} feature is required for RX
46838 targets. It should contain the registers @samp{r0} through
46839 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
46840 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
46841
46842 @node S/390 and System z Features
46843 @subsection S/390 and System z Features
46844 @cindex target descriptions, S/390 features
46845 @cindex target descriptions, System z features
46846
46847 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
46848 System z targets. It should contain the PSW and the 16 general
46849 registers. In particular, System z targets should provide the 64-bit
46850 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
46851 S/390 targets should provide the 32-bit versions of these registers.
46852 A System z target that runs in 31-bit addressing mode should provide
46853 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
46854 register's upper halves @samp{r0h} through @samp{r15h}, and their
46855 lower halves @samp{r0l} through @samp{r15l}.
46856
46857 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
46858 contain the 64-bit registers @samp{f0} through @samp{f15}, and
46859 @samp{fpc}.
46860
46861 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
46862 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
46863
46864 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
46865 contain the register @samp{orig_r2}, which is 64-bit wide on System z
46866 targets and 32-bit otherwise. In addition, the feature may contain
46867 the @samp{last_break} register, whose width depends on the addressing
46868 mode, as well as the @samp{system_call} register, which is always
46869 32-bit wide.
46870
46871 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
46872 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
46873 @samp{atia}, and @samp{tr0} through @samp{tr15}.
46874
46875 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
46876 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
46877 combined by @value{GDBN} with the floating point registers @samp{f0}
46878 through @samp{f15} to present the 128-bit wide vector registers
46879 @samp{v0} through @samp{v15}. In addition, this feature should
46880 contain the 128-bit wide vector registers @samp{v16} through
46881 @samp{v31}.
46882
46883 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
46884 the 64-bit wide guarded-storage-control registers @samp{gsd},
46885 @samp{gssm}, and @samp{gsepla}.
46886
46887 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
46888 the 64-bit wide guarded-storage broadcast control registers
46889 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
46890
46891 @node Sparc Features
46892 @subsection Sparc Features
46893 @cindex target descriptions, sparc32 features
46894 @cindex target descriptions, sparc64 features
46895 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
46896 targets. It should describe the following registers:
46897
46898 @itemize @minus
46899 @item
46900 @samp{g0} through @samp{g7}
46901 @item
46902 @samp{o0} through @samp{o7}
46903 @item
46904 @samp{l0} through @samp{l7}
46905 @item
46906 @samp{i0} through @samp{i7}
46907 @end itemize
46908
46909 They may be 32-bit or 64-bit depending on the target.
46910
46911 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
46912 targets. It should describe the following registers:
46913
46914 @itemize @minus
46915 @item
46916 @samp{f0} through @samp{f31}
46917 @item
46918 @samp{f32} through @samp{f62} for sparc64
46919 @end itemize
46920
46921 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46922 targets. It should describe the following registers:
46923
46924 @itemize @minus
46925 @item
46926 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46927 @samp{fsr}, and @samp{csr} for sparc32
46928 @item
46929 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46930 for sparc64
46931 @end itemize
46932
46933 @node TIC6x Features
46934 @subsection TMS320C6x Features
46935 @cindex target descriptions, TIC6x features
46936 @cindex target descriptions, TMS320C6x features
46937 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46938 targets. It should contain registers @samp{A0} through @samp{A15},
46939 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46940
46941 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46942 contain registers @samp{A16} through @samp{A31} and @samp{B16}
46943 through @samp{B31}.
46944
46945 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46946 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46947
46948 @node Operating System Information
46949 @appendix Operating System Information
46950 @cindex operating system information
46951
46952 Users of @value{GDBN} often wish to obtain information about the state of
46953 the operating system running on the target---for example the list of
46954 processes, or the list of open files. This section describes the
46955 mechanism that makes it possible. This mechanism is similar to the
46956 target features mechanism (@pxref{Target Descriptions}), but focuses
46957 on a different aspect of target.
46958
46959 Operating system information is retrieved from the target via the
46960 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46961 read}). The object name in the request should be @samp{osdata}, and
46962 the @var{annex} identifies the data to be fetched.
46963
46964 @menu
46965 * Process list::
46966 @end menu
46967
46968 @node Process list
46969 @appendixsection Process list
46970 @cindex operating system information, process list
46971
46972 When requesting the process list, the @var{annex} field in the
46973 @samp{qXfer} request should be @samp{processes}. The returned data is
46974 an XML document. The formal syntax of this document is defined in
46975 @file{gdb/features/osdata.dtd}.
46976
46977 An example document is:
46978
46979 @smallexample
46980 <?xml version="1.0"?>
46981 <!DOCTYPE target SYSTEM "osdata.dtd">
46982 <osdata type="processes">
46983 <item>
46984 <column name="pid">1</column>
46985 <column name="user">root</column>
46986 <column name="command">/sbin/init</column>
46987 <column name="cores">1,2,3</column>
46988 </item>
46989 </osdata>
46990 @end smallexample
46991
46992 Each item should include a column whose name is @samp{pid}. The value
46993 of that column should identify the process on the target. The
46994 @samp{user} and @samp{command} columns are optional, and will be
46995 displayed by @value{GDBN}. The @samp{cores} column, if present,
46996 should contain a comma-separated list of cores that this process
46997 is running on. Target may provide additional columns,
46998 which @value{GDBN} currently ignores.
46999
47000 @node Trace File Format
47001 @appendix Trace File Format
47002 @cindex trace file format
47003
47004 The trace file comes in three parts: a header, a textual description
47005 section, and a trace frame section with binary data.
47006
47007 The header has the form @code{\x7fTRACE0\n}. The first byte is
47008 @code{0x7f} so as to indicate that the file contains binary data,
47009 while the @code{0} is a version number that may have different values
47010 in the future.
47011
47012 The description section consists of multiple lines of @sc{ascii} text
47013 separated by newline characters (@code{0xa}). The lines may include a
47014 variety of optional descriptive or context-setting information, such
47015 as tracepoint definitions or register set size. @value{GDBN} will
47016 ignore any line that it does not recognize. An empty line marks the end
47017 of this section.
47018
47019 @table @code
47020 @item R @var{size}
47021 Specifies the size of a register block in bytes. This is equal to the
47022 size of a @code{g} packet payload in the remote protocol. @var{size}
47023 is an ascii decimal number. There should be only one such line in
47024 a single trace file.
47025
47026 @item status @var{status}
47027 Trace status. @var{status} has the same format as a @code{qTStatus}
47028 remote packet reply. There should be only one such line in a single trace
47029 file.
47030
47031 @item tp @var{payload}
47032 Tracepoint definition. The @var{payload} has the same format as
47033 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
47034 may take multiple lines of definition, corresponding to the multiple
47035 reply packets.
47036
47037 @item tsv @var{payload}
47038 Trace state variable definition. The @var{payload} has the same format as
47039 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
47040 may take multiple lines of definition, corresponding to the multiple
47041 reply packets.
47042
47043 @item tdesc @var{payload}
47044 Target description in XML format. The @var{payload} is a single line of
47045 the XML file. All such lines should be concatenated together to get
47046 the original XML file. This file is in the same format as @code{qXfer}
47047 @code{features} payload, and corresponds to the main @code{target.xml}
47048 file. Includes are not allowed.
47049
47050 @end table
47051
47052 The trace frame section consists of a number of consecutive frames.
47053 Each frame begins with a two-byte tracepoint number, followed by a
47054 four-byte size giving the amount of data in the frame. The data in
47055 the frame consists of a number of blocks, each introduced by a
47056 character indicating its type (at least register, memory, and trace
47057 state variable). The data in this section is raw binary, not a
47058 hexadecimal or other encoding; its endianness matches the target's
47059 endianness.
47060
47061 @c FIXME bi-arch may require endianness/arch info in description section
47062
47063 @table @code
47064 @item R @var{bytes}
47065 Register block. The number and ordering of bytes matches that of a
47066 @code{g} packet in the remote protocol. Note that these are the
47067 actual bytes, in target order, not a hexadecimal encoding.
47068
47069 @item M @var{address} @var{length} @var{bytes}...
47070 Memory block. This is a contiguous block of memory, at the 8-byte
47071 address @var{address}, with a 2-byte length @var{length}, followed by
47072 @var{length} bytes.
47073
47074 @item V @var{number} @var{value}
47075 Trace state variable block. This records the 8-byte signed value
47076 @var{value} of trace state variable numbered @var{number}.
47077
47078 @end table
47079
47080 Future enhancements of the trace file format may include additional types
47081 of blocks.
47082
47083 @node Index Section Format
47084 @appendix @code{.gdb_index} section format
47085 @cindex .gdb_index section format
47086 @cindex index section format
47087
47088 This section documents the index section that is created by @code{save
47089 gdb-index} (@pxref{Index Files}). The index section is
47090 DWARF-specific; some knowledge of DWARF is assumed in this
47091 description.
47092
47093 The mapped index file format is designed to be directly
47094 @code{mmap}able on any architecture. In most cases, a datum is
47095 represented using a little-endian 32-bit integer value, called an
47096 @code{offset_type}. Big endian machines must byte-swap the values
47097 before using them. Exceptions to this rule are noted. The data is
47098 laid out such that alignment is always respected.
47099
47100 A mapped index consists of several areas, laid out in order.
47101
47102 @enumerate
47103 @item
47104 The file header. This is a sequence of values, of @code{offset_type}
47105 unless otherwise noted:
47106
47107 @enumerate
47108 @item
47109 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
47110 Version 4 uses a different hashing function from versions 5 and 6.
47111 Version 6 includes symbols for inlined functions, whereas versions 4
47112 and 5 do not. Version 7 adds attributes to the CU indices in the
47113 symbol table. Version 8 specifies that symbols from DWARF type units
47114 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
47115 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
47116
47117 @value{GDBN} will only read version 4, 5, or 6 indices
47118 by specifying @code{set use-deprecated-index-sections on}.
47119 GDB has a workaround for potentially broken version 7 indices so it is
47120 currently not flagged as deprecated.
47121
47122 @item
47123 The offset, from the start of the file, of the CU list.
47124
47125 @item
47126 The offset, from the start of the file, of the types CU list. Note
47127 that this area can be empty, in which case this offset will be equal
47128 to the next offset.
47129
47130 @item
47131 The offset, from the start of the file, of the address area.
47132
47133 @item
47134 The offset, from the start of the file, of the symbol table.
47135
47136 @item
47137 The offset, from the start of the file, of the constant pool.
47138 @end enumerate
47139
47140 @item
47141 The CU list. This is a sequence of pairs of 64-bit little-endian
47142 values, sorted by the CU offset. The first element in each pair is
47143 the offset of a CU in the @code{.debug_info} section. The second
47144 element in each pair is the length of that CU. References to a CU
47145 elsewhere in the map are done using a CU index, which is just the
47146 0-based index into this table. Note that if there are type CUs, then
47147 conceptually CUs and type CUs form a single list for the purposes of
47148 CU indices.
47149
47150 @item
47151 The types CU list. This is a sequence of triplets of 64-bit
47152 little-endian values. In a triplet, the first value is the CU offset,
47153 the second value is the type offset in the CU, and the third value is
47154 the type signature. The types CU list is not sorted.
47155
47156 @item
47157 The address area. The address area consists of a sequence of address
47158 entries. Each address entry has three elements:
47159
47160 @enumerate
47161 @item
47162 The low address. This is a 64-bit little-endian value.
47163
47164 @item
47165 The high address. This is a 64-bit little-endian value. Like
47166 @code{DW_AT_high_pc}, the value is one byte beyond the end.
47167
47168 @item
47169 The CU index. This is an @code{offset_type} value.
47170 @end enumerate
47171
47172 @item
47173 The symbol table. This is an open-addressed hash table. The size of
47174 the hash table is always a power of 2.
47175
47176 Each slot in the hash table consists of a pair of @code{offset_type}
47177 values. The first value is the offset of the symbol's name in the
47178 constant pool. The second value is the offset of the CU vector in the
47179 constant pool.
47180
47181 If both values are 0, then this slot in the hash table is empty. This
47182 is ok because while 0 is a valid constant pool index, it cannot be a
47183 valid index for both a string and a CU vector.
47184
47185 The hash value for a table entry is computed by applying an
47186 iterative hash function to the symbol's name. Starting with an
47187 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
47188 the string is incorporated into the hash using the formula depending on the
47189 index version:
47190
47191 @table @asis
47192 @item Version 4
47193 The formula is @code{r = r * 67 + c - 113}.
47194
47195 @item Versions 5 to 7
47196 The formula is @code{r = r * 67 + tolower (c) - 113}.
47197 @end table
47198
47199 The terminating @samp{\0} is not incorporated into the hash.
47200
47201 The step size used in the hash table is computed via
47202 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
47203 value, and @samp{size} is the size of the hash table. The step size
47204 is used to find the next candidate slot when handling a hash
47205 collision.
47206
47207 The names of C@t{++} symbols in the hash table are canonicalized. We
47208 don't currently have a simple description of the canonicalization
47209 algorithm; if you intend to create new index sections, you must read
47210 the code.
47211
47212 @item
47213 The constant pool. This is simply a bunch of bytes. It is organized
47214 so that alignment is correct: CU vectors are stored first, followed by
47215 strings.
47216
47217 A CU vector in the constant pool is a sequence of @code{offset_type}
47218 values. The first value is the number of CU indices in the vector.
47219 Each subsequent value is the index and symbol attributes of a CU in
47220 the CU list. This element in the hash table is used to indicate which
47221 CUs define the symbol and how the symbol is used.
47222 See below for the format of each CU index+attributes entry.
47223
47224 A string in the constant pool is zero-terminated.
47225 @end enumerate
47226
47227 Attributes were added to CU index values in @code{.gdb_index} version 7.
47228 If a symbol has multiple uses within a CU then there is one
47229 CU index+attributes value for each use.
47230
47231 The format of each CU index+attributes entry is as follows
47232 (bit 0 = LSB):
47233
47234 @table @asis
47235
47236 @item Bits 0-23
47237 This is the index of the CU in the CU list.
47238 @item Bits 24-27
47239 These bits are reserved for future purposes and must be zero.
47240 @item Bits 28-30
47241 The kind of the symbol in the CU.
47242
47243 @table @asis
47244 @item 0
47245 This value is reserved and should not be used.
47246 By reserving zero the full @code{offset_type} value is backwards compatible
47247 with previous versions of the index.
47248 @item 1
47249 The symbol is a type.
47250 @item 2
47251 The symbol is a variable or an enum value.
47252 @item 3
47253 The symbol is a function.
47254 @item 4
47255 Any other kind of symbol.
47256 @item 5,6,7
47257 These values are reserved.
47258 @end table
47259
47260 @item Bit 31
47261 This bit is zero if the value is global and one if it is static.
47262
47263 The determination of whether a symbol is global or static is complicated.
47264 The authorative reference is the file @file{dwarf2read.c} in
47265 @value{GDBN} sources.
47266
47267 @end table
47268
47269 This pseudo-code describes the computation of a symbol's kind and
47270 global/static attributes in the index.
47271
47272 @smallexample
47273 is_external = get_attribute (die, DW_AT_external);
47274 language = get_attribute (cu_die, DW_AT_language);
47275 switch (die->tag)
47276 @{
47277 case DW_TAG_typedef:
47278 case DW_TAG_base_type:
47279 case DW_TAG_subrange_type:
47280 kind = TYPE;
47281 is_static = 1;
47282 break;
47283 case DW_TAG_enumerator:
47284 kind = VARIABLE;
47285 is_static = language != CPLUS;
47286 break;
47287 case DW_TAG_subprogram:
47288 kind = FUNCTION;
47289 is_static = ! (is_external || language == ADA);
47290 break;
47291 case DW_TAG_constant:
47292 kind = VARIABLE;
47293 is_static = ! is_external;
47294 break;
47295 case DW_TAG_variable:
47296 kind = VARIABLE;
47297 is_static = ! is_external;
47298 break;
47299 case DW_TAG_namespace:
47300 kind = TYPE;
47301 is_static = 0;
47302 break;
47303 case DW_TAG_class_type:
47304 case DW_TAG_interface_type:
47305 case DW_TAG_structure_type:
47306 case DW_TAG_union_type:
47307 case DW_TAG_enumeration_type:
47308 kind = TYPE;
47309 is_static = language != CPLUS;
47310 break;
47311 default:
47312 assert (0);
47313 @}
47314 @end smallexample
47315
47316 @node Debuginfod
47317 @appendix Download debugging resources with Debuginfod
47318 @cindex debuginfod
47319
47320 @code{debuginfod} is an HTTP server for distributing ELF, DWARF and source
47321 files.
47322
47323 With the @code{debuginfod} client library, @file{libdebuginfod}, @value{GDBN}
47324 can query servers using the build IDs associated with missing debug info,
47325 executables and source files in order to download them on demand.
47326
47327 For instructions on building @value{GDBN} with @file{libdebuginfod},
47328 @pxref{Configure Options,,--with-debuginfod}. @code{debuginfod} is packaged
47329 with @code{elfutils}, starting with version 0.178. See
47330 @uref{https://sourceware.org/elfutils/Debuginfod.html} for more information
47331 regarding @code{debuginfod}.
47332
47333 @menu
47334 * Debuginfod Settings:: Configuring debuginfod with @value{GDBN}
47335 @end menu
47336
47337 @node Debuginfod Settings
47338 @section Debuginfod Settings
47339
47340 @value{GDBN} provides the following commands for configuring @code{debuginfod}.
47341
47342 @table @code
47343 @kindex set debuginfod enabled
47344 @anchor{set debuginfod enabled}
47345 @item set debuginfod enabled
47346 @itemx set debuginfod enabled on
47347 @cindex enable debuginfod
47348 @value{GDBN} will attempt to query @code{debuginfod} servers when missing debug
47349 info or source files.
47350
47351 @item set debuginfod enabled off
47352 @value{GDBN} will not attempt to query @code{debuginfod} servers when missing
47353 debug info or source files. By default, @code{debuginfod enabled} is set to
47354 @code{off} for non-interactive sessions.
47355
47356 @item set debuginfod enabled ask
47357 @value{GDBN} will prompt the user to enable or disable @code{debuginfod} before
47358 attempting to perform the next query. By default, @code{debuginfod enabled}
47359 is set to @code{ask} for interactive sessions.
47360
47361 @kindex show debuginfod enabled
47362 @item show debuginfod enabled
47363 Display whether @code{debuginfod enabled} is set to @code{on}, @code{off} or
47364 @code{ask}.
47365
47366 @kindex set debuginfod urls
47367 @cindex configure debuginfod URLs
47368 @item set debuginfod urls
47369 @itemx set debuginfod urls @var{urls}
47370 Set the space-separated list of URLs that @code{debuginfod} will attempt to
47371 query. Only @code{http://}, @code{https://} and @code{file://} protocols
47372 should be used. The default value of @code{debuginfod urls} is copied from
47373 the @var{DEBUGINFOD_URLS} environment variable.
47374
47375 @kindex show debuginfod urls
47376 @item show debuginfod urls
47377 Display the list of URLs that @code{debuginfod} will attempt to query.
47378
47379 @kindex set debuginfod verbose
47380 @cindex debuginfod verbosity
47381 @item set debuginfod verbose
47382 @itemx set debuginfod verbose @var{n}
47383 Enable or disable @code{debuginfod}-related output. Use a non-zero value
47384 to enable and @code{0} to disable. @code{debuginfod} output is shown by
47385 default.
47386
47387 @kindex show debuginfod verbose
47388 @item show debuginfod verbose
47389 Show the current verbosity setting.
47390
47391 @end table
47392
47393 @node Man Pages
47394 @appendix Manual pages
47395 @cindex Man pages
47396
47397 @menu
47398 * gdb man:: The GNU Debugger man page
47399 * gdbserver man:: Remote Server for the GNU Debugger man page
47400 * gcore man:: Generate a core file of a running program
47401 * gdbinit man:: gdbinit scripts
47402 * gdb-add-index man:: Add index files to speed up GDB
47403 @end menu
47404
47405 @node gdb man
47406 @heading gdb man
47407
47408 @c man title gdb The GNU Debugger
47409
47410 @c man begin SYNOPSIS gdb
47411 gdb [OPTIONS] [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
47412 @c man end
47413
47414 @c man begin DESCRIPTION gdb
47415 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
47416 going on ``inside'' another program while it executes -- or what another
47417 program was doing at the moment it crashed.
47418
47419 @value{GDBN} can do four main kinds of things (plus other things in support of
47420 these) to help you catch bugs in the act:
47421
47422 @itemize @bullet
47423 @item
47424 Start your program, specifying anything that might affect its behavior.
47425
47426 @item
47427 Make your program stop on specified conditions.
47428
47429 @item
47430 Examine what has happened, when your program has stopped.
47431
47432 @item
47433 Change things in your program, so you can experiment with correcting the
47434 effects of one bug and go on to learn about another.
47435 @end itemize
47436
47437 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
47438 Modula-2.
47439
47440 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
47441 commands from the terminal until you tell it to exit with the @value{GDBN}
47442 command @code{quit} or @code{exit}. You can get online help from @value{GDBN} itself
47443 by using the command @code{help}.
47444
47445 You can run @code{gdb} with no arguments or options; but the most
47446 usual way to start @value{GDBN} is with one argument or two, specifying an
47447 executable program as the argument:
47448
47449 @smallexample
47450 gdb program
47451 @end smallexample
47452
47453 You can also start with both an executable program and a core file specified:
47454
47455 @smallexample
47456 gdb program core
47457 @end smallexample
47458
47459 You can, instead, specify a process ID as a second argument or use option
47460 @code{-p}, if you want to debug a running process:
47461
47462 @smallexample
47463 gdb program 1234
47464 gdb -p 1234
47465 @end smallexample
47466
47467 @noindent
47468 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
47469 can omit the @var{program} filename.
47470
47471 Here are some of the most frequently needed @value{GDBN} commands:
47472
47473 @c pod2man highlights the right hand side of the @item lines.
47474 @table @env
47475 @item break [@var{file}:][@var{function}|@var{line}]
47476 Set a breakpoint at @var{function} or @var{line} (in @var{file}).
47477
47478 @item run [@var{arglist}]
47479 Start your program (with @var{arglist}, if specified).
47480
47481 @item bt
47482 Backtrace: display the program stack.
47483
47484 @item print @var{expr}
47485 Display the value of an expression.
47486
47487 @item c
47488 Continue running your program (after stopping, e.g.@: at a breakpoint).
47489
47490 @item next
47491 Execute next program line (after stopping); step @emph{over} any
47492 function calls in the line.
47493
47494 @item edit [@var{file}:]@var{function}
47495 look at the program line where it is presently stopped.
47496
47497 @item list [@var{file}:]@var{function}
47498 type the text of the program in the vicinity of where it is presently stopped.
47499
47500 @item step
47501 Execute next program line (after stopping); step @emph{into} any
47502 function calls in the line.
47503
47504 @item help [@var{name}]
47505 Show information about @value{GDBN} command @var{name}, or general information
47506 about using @value{GDBN}.
47507
47508 @item quit
47509 @itemx exit
47510 Exit from @value{GDBN}.
47511 @end table
47512
47513 @ifset man
47514 For full details on @value{GDBN},
47515 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47516 by Richard M. Stallman and Roland H. Pesch. The same text is available online
47517 as the @code{gdb} entry in the @code{info} program.
47518 @end ifset
47519 @c man end
47520
47521 @c man begin OPTIONS gdb
47522 Any arguments other than options specify an executable
47523 file and core file (or process ID); that is, the first argument
47524 encountered with no
47525 associated option flag is equivalent to a @option{--se} option, and the second,
47526 if any, is equivalent to a @option{-c} option if it's the name of a file.
47527 Many options have
47528 both long and abbreviated forms; both are shown here. The long forms are also
47529 recognized if you truncate them, so long as enough of the option is
47530 present to be unambiguous.
47531
47532 The abbreviated forms are shown here with @samp{-} and long forms are shown
47533 with @samp{--} to reflect how they are shown in @option{--help}. However,
47534 @value{GDBN} recognizes all of the following conventions for most options:
47535
47536 @table @code
47537 @item --option=@var{value}
47538 @item --option @var{value}
47539 @item -option=@var{value}
47540 @item -option @var{value}
47541 @item --o=@var{value}
47542 @item --o @var{value}
47543 @item -o=@var{value}
47544 @item -o @var{value}
47545 @end table
47546
47547 All the options and command line arguments you give are processed
47548 in sequential order. The order makes a difference when the @option{-x}
47549 option is used.
47550
47551 @table @env
47552 @item --help
47553 @itemx -h
47554 List all options, with brief explanations.
47555
47556 @item --symbols=@var{file}
47557 @itemx -s @var{file}
47558 Read symbol table from @var{file}.
47559
47560 @item --write
47561 Enable writing into executable and core files.
47562
47563 @item --exec=@var{file}
47564 @itemx -e @var{file}
47565 Use @var{file} as the executable file to execute when
47566 appropriate, and for examining pure data in conjunction with a core
47567 dump.
47568
47569 @item --se=@var{file}
47570 Read symbol table from @var{file} and use it as the executable
47571 file.
47572
47573 @item --core=@var{file}
47574 @itemx -c @var{file}
47575 Use @var{file} as a core dump to examine.
47576
47577 @item --command=@var{file}
47578 @itemx -x @var{file}
47579 Execute @value{GDBN} commands from @var{file}.
47580
47581 @item --eval-command=@var{command}
47582 @item -ex @var{command}
47583 Execute given @value{GDBN} @var{command}.
47584
47585 @item --init-eval-command=@var{command}
47586 @item -iex
47587 Execute @value{GDBN} @var{command} before loading the inferior.
47588
47589 @item --directory=@var{directory}
47590 @itemx -d @var{directory}
47591 Add @var{directory} to the path to search for source files.
47592
47593 @item --nh
47594 Do not execute commands from @file{~/.config/gdb/gdbinit},
47595 @file{~/.gdbinit}, @file{~/.config/gdb/gdbearlyinit}, or
47596 @file{~/.gdbearlyinit}
47597
47598 @item --nx
47599 @itemx -n
47600 Do not execute commands from any @file{.gdbinit} or
47601 @file{.gdbearlyinit} initialization files.
47602
47603 @item --quiet
47604 @item --silent
47605 @itemx -q
47606 ``Quiet''. Do not print the introductory and copyright messages. These
47607 messages are also suppressed in batch mode.
47608
47609 @item --batch
47610 Run in batch mode. Exit with status @code{0} after processing all the command
47611 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
47612 Exit with nonzero status if an error occurs in executing the @value{GDBN}
47613 commands in the command files.
47614
47615 Batch mode may be useful for running @value{GDBN} as a filter, for example to
47616 download and run a program on another computer; in order to make this
47617 more useful, the message
47618
47619 @smallexample
47620 Program exited normally.
47621 @end smallexample
47622
47623 @noindent
47624 (which is ordinarily issued whenever a program running under @value{GDBN} control
47625 terminates) is not issued when running in batch mode.
47626
47627 @item --batch-silent
47628 Run in batch mode, just like @option{--batch}, but totally silent. All @value{GDBN}
47629 output is supressed (stderr is unaffected). This is much quieter than
47630 @option{--silent} and would be useless for an interactive session.
47631
47632 This is particularly useful when using targets that give @samp{Loading section}
47633 messages, for example.
47634
47635 Note that targets that give their output via @value{GDBN}, as opposed to writing
47636 directly to @code{stdout}, will also be made silent.
47637
47638 @item --args @var{prog} [@var{arglist}]
47639 Change interpretation of command line so that arguments following this
47640 option are passed as arguments to the inferior. As an example, take
47641 the following command:
47642
47643 @smallexample
47644 gdb ./a.out -q
47645 @end smallexample
47646
47647 @noindent
47648 It would start @value{GDBN} with @option{-q}, not printing the introductory message. On
47649 the other hand, using:
47650
47651 @smallexample
47652 gdb --args ./a.out -q
47653 @end smallexample
47654
47655 @noindent
47656 starts @value{GDBN} with the introductory message, and passes the option to the inferior.
47657
47658 @item --pid=@var{pid}
47659 Attach @value{GDBN} to an already running program, with the PID @var{pid}.
47660
47661 @item --tui
47662 Open the terminal user interface.
47663
47664 @item --readnow
47665 Read all symbols from the given symfile on the first access.
47666
47667 @item --readnever
47668 Do not read symbol files.
47669
47670 @item --dbx
47671 Run in DBX compatibility mode.
47672
47673 @item --return-child-result
47674 @value{GDBN}'s exit code will be the same as the child's exit code.
47675
47676 @item --configuration
47677 Print details about GDB configuration and then exit.
47678
47679 @item --version
47680 Print version information and then exit.
47681
47682 @item --cd=@var{directory}
47683 Run @value{GDBN} using @var{directory} as its working directory,
47684 instead of the current directory.
47685
47686 @item --data-directory=@var{directory}
47687 @item -D
47688 Run @value{GDBN} using @var{directory} as its data directory. The data
47689 directory is where @value{GDBN} searches for its auxiliary files.
47690
47691 @item --fullname
47692 @itemx -f
47693 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
47694 @value{GDBN} to output the full file name and line number in a standard,
47695 recognizable fashion each time a stack frame is displayed (which
47696 includes each time the program stops). This recognizable format looks
47697 like two @samp{\032} characters, followed by the file name, line number
47698 and character position separated by colons, and a newline. The
47699 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
47700 characters as a signal to display the source code for the frame.
47701
47702 @item -b @var{baudrate}
47703 Set the line speed (baud rate or bits per second) of any serial
47704 interface used by @value{GDBN} for remote debugging.
47705
47706 @item -l @var{timeout}
47707 Set timeout, in seconds, for remote debugging.
47708
47709 @item --tty=@var{device}
47710 Run using @var{device} for your program's standard input and output.
47711 @end table
47712 @c man end
47713
47714 @c man begin SEEALSO gdb
47715 @ifset man
47716 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47717 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47718 documentation are properly installed at your site, the command
47719
47720 @smallexample
47721 info gdb
47722 @end smallexample
47723
47724 @noindent
47725 should give you access to the complete manual.
47726
47727 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47728 Richard M. Stallman and Roland H. Pesch, July 1991.
47729 @end ifset
47730 @c man end
47731
47732 @node gdbserver man
47733 @heading gdbserver man
47734
47735 @c man title gdbserver Remote Server for the GNU Debugger
47736 @format
47737 @c man begin SYNOPSIS gdbserver
47738 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47739
47740 gdbserver --attach @var{comm} @var{pid}
47741
47742 gdbserver --multi @var{comm}
47743 @c man end
47744 @end format
47745
47746 @c man begin DESCRIPTION gdbserver
47747 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
47748 than the one which is running the program being debugged.
47749
47750 @ifclear man
47751 @subheading Usage (server (target) side)
47752 @end ifclear
47753 @ifset man
47754 Usage (server (target) side):
47755 @end ifset
47756
47757 First, you need to have a copy of the program you want to debug put onto
47758 the target system. The program can be stripped to save space if needed, as
47759 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
47760 the @value{GDBN} running on the host system.
47761
47762 To use the server, you log on to the target system, and run the @command{gdbserver}
47763 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
47764 your program, and (c) its arguments. The general syntax is:
47765
47766 @smallexample
47767 target> gdbserver @var{comm} @var{program} [@var{args} ...]
47768 @end smallexample
47769
47770 For example, using a serial port, you might say:
47771
47772 @smallexample
47773 @ifset man
47774 @c @file would wrap it as F</dev/com1>.
47775 target> gdbserver /dev/com1 emacs foo.txt
47776 @end ifset
47777 @ifclear man
47778 target> gdbserver @file{/dev/com1} emacs foo.txt
47779 @end ifclear
47780 @end smallexample
47781
47782 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
47783 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
47784 waits patiently for the host @value{GDBN} to communicate with it.
47785
47786 To use a TCP connection, you could say:
47787
47788 @smallexample
47789 target> gdbserver host:2345 emacs foo.txt
47790 @end smallexample
47791
47792 This says pretty much the same thing as the last example, except that we are
47793 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
47794 that we are expecting to see a TCP connection from @code{host} to local TCP port
47795 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
47796 want for the port number as long as it does not conflict with any existing TCP
47797 ports on the target system. This same port number must be used in the host
47798 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
47799 you chose a port number that conflicts with another service, @command{gdbserver} will
47800 print an error message and exit.
47801
47802 @command{gdbserver} can also attach to running programs.
47803 This is accomplished via the @option{--attach} argument. The syntax is:
47804
47805 @smallexample
47806 target> gdbserver --attach @var{comm} @var{pid}
47807 @end smallexample
47808
47809 @var{pid} is the process ID of a currently running process. It isn't
47810 necessary to point @command{gdbserver} at a binary for the running process.
47811
47812 To start @code{gdbserver} without supplying an initial command to run
47813 or process ID to attach, use the @option{--multi} command line option.
47814 In such case you should connect using @kbd{target extended-remote} to start
47815 the program you want to debug.
47816
47817 @smallexample
47818 target> gdbserver --multi @var{comm}
47819 @end smallexample
47820
47821 @ifclear man
47822 @subheading Usage (host side)
47823 @end ifclear
47824 @ifset man
47825 Usage (host side):
47826 @end ifset
47827
47828 You need an unstripped copy of the target program on your host system, since
47829 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
47830 would, with the target program as the first argument. (You may need to use the
47831 @option{--baud} option if the serial line is running at anything except 9600 baud.)
47832 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
47833 new command you need to know about is @code{target remote}
47834 (or @code{target extended-remote}). Its argument is either
47835 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
47836 descriptor. For example:
47837
47838 @smallexample
47839 @ifset man
47840 @c @file would wrap it as F</dev/ttyb>.
47841 (gdb) target remote /dev/ttyb
47842 @end ifset
47843 @ifclear man
47844 (gdb) target remote @file{/dev/ttyb}
47845 @end ifclear
47846 @end smallexample
47847
47848 @noindent
47849 communicates with the server via serial line @file{/dev/ttyb}, and:
47850
47851 @smallexample
47852 (gdb) target remote the-target:2345
47853 @end smallexample
47854
47855 @noindent
47856 communicates via a TCP connection to port 2345 on host `the-target', where
47857 you previously started up @command{gdbserver} with the same port number. Note that for
47858 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
47859 command, otherwise you may get an error that looks something like
47860 `Connection refused'.
47861
47862 @command{gdbserver} can also debug multiple inferiors at once,
47863 described in
47864 @ifset man
47865 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
47866 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
47867 @end ifset
47868 @ifclear man
47869 @ref{Inferiors Connections and Programs}.
47870 @end ifclear
47871 In such case use the @code{extended-remote} @value{GDBN} command variant:
47872
47873 @smallexample
47874 (gdb) target extended-remote the-target:2345
47875 @end smallexample
47876
47877 The @command{gdbserver} option @option{--multi} may or may not be used in such
47878 case.
47879 @c man end
47880
47881 @c man begin OPTIONS gdbserver
47882 There are three different modes for invoking @command{gdbserver}:
47883
47884 @itemize @bullet
47885
47886 @item
47887 Debug a specific program specified by its program name:
47888
47889 @smallexample
47890 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47891 @end smallexample
47892
47893 The @var{comm} parameter specifies how should the server communicate
47894 with @value{GDBN}; it is either a device name (to use a serial line),
47895 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
47896 stdin/stdout of @code{gdbserver}. Specify the name of the program to
47897 debug in @var{prog}. Any remaining arguments will be passed to the
47898 program verbatim. When the program exits, @value{GDBN} will close the
47899 connection, and @code{gdbserver} will exit.
47900
47901 @item
47902 Debug a specific program by specifying the process ID of a running
47903 program:
47904
47905 @smallexample
47906 gdbserver --attach @var{comm} @var{pid}
47907 @end smallexample
47908
47909 The @var{comm} parameter is as described above. Supply the process ID
47910 of a running program in @var{pid}; @value{GDBN} will do everything
47911 else. Like with the previous mode, when the process @var{pid} exits,
47912 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
47913
47914 @item
47915 Multi-process mode -- debug more than one program/process:
47916
47917 @smallexample
47918 gdbserver --multi @var{comm}
47919 @end smallexample
47920
47921 In this mode, @value{GDBN} can instruct @command{gdbserver} which
47922 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
47923 close the connection when a process being debugged exits, so you can
47924 debug several processes in the same session.
47925 @end itemize
47926
47927 In each of the modes you may specify these options:
47928
47929 @table @env
47930
47931 @item --help
47932 List all options, with brief explanations.
47933
47934 @item --version
47935 This option causes @command{gdbserver} to print its version number and exit.
47936
47937 @item --attach
47938 @command{gdbserver} will attach to a running program. The syntax is:
47939
47940 @smallexample
47941 target> gdbserver --attach @var{comm} @var{pid}
47942 @end smallexample
47943
47944 @var{pid} is the process ID of a currently running process. It isn't
47945 necessary to point @command{gdbserver} at a binary for the running process.
47946
47947 @item --multi
47948 To start @code{gdbserver} without supplying an initial command to run
47949 or process ID to attach, use this command line option.
47950 Then you can connect using @kbd{target extended-remote} and start
47951 the program you want to debug. The syntax is:
47952
47953 @smallexample
47954 target> gdbserver --multi @var{comm}
47955 @end smallexample
47956
47957 @item --debug
47958 Instruct @code{gdbserver} to display extra status information about the debugging
47959 process.
47960 This option is intended for @code{gdbserver} development and for bug reports to
47961 the developers.
47962
47963 @item --remote-debug
47964 Instruct @code{gdbserver} to display remote protocol debug output.
47965 This option is intended for @code{gdbserver} development and for bug reports to
47966 the developers.
47967
47968 @item --debug-file=@var{filename}
47969 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
47970 This option is intended for @code{gdbserver} development and for bug reports to
47971 the developers.
47972
47973 @item --debug-format=option1@r{[},option2,...@r{]}
47974 Instruct @code{gdbserver} to include extra information in each line
47975 of debugging output.
47976 @xref{Other Command-Line Arguments for gdbserver}.
47977
47978 @item --wrapper
47979 Specify a wrapper to launch programs
47980 for debugging. The option should be followed by the name of the
47981 wrapper, then any command-line arguments to pass to the wrapper, then
47982 @kbd{--} indicating the end of the wrapper arguments.
47983
47984 @item --once
47985 By default, @command{gdbserver} keeps the listening TCP port open, so that
47986 additional connections are possible. However, if you start @code{gdbserver}
47987 with the @option{--once} option, it will stop listening for any further
47988 connection attempts after connecting to the first @value{GDBN} session.
47989
47990 @c --disable-packet is not documented for users.
47991
47992 @c --disable-randomization and --no-disable-randomization are superseded by
47993 @c QDisableRandomization.
47994
47995 @end table
47996 @c man end
47997
47998 @c man begin SEEALSO gdbserver
47999 @ifset man
48000 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48001 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48002 documentation are properly installed at your site, the command
48003
48004 @smallexample
48005 info gdb
48006 @end smallexample
48007
48008 should give you access to the complete manual.
48009
48010 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48011 Richard M. Stallman and Roland H. Pesch, July 1991.
48012 @end ifset
48013 @c man end
48014
48015 @node gcore man
48016 @heading gcore
48017
48018 @c man title gcore Generate a core file of a running program
48019
48020 @format
48021 @c man begin SYNOPSIS gcore
48022 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
48023 @c man end
48024 @end format
48025
48026 @c man begin DESCRIPTION gcore
48027 Generate core dumps of one or more running programs with process IDs
48028 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
48029 is equivalent to one produced by the kernel when the process crashes
48030 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
48031 limit). However, unlike after a crash, after @command{gcore} finishes
48032 its job the program remains running without any change.
48033 @c man end
48034
48035 @c man begin OPTIONS gcore
48036 @table @env
48037 @item -a
48038 Dump all memory mappings. The actual effect of this option depends on
48039 the Operating System. On @sc{gnu}/Linux, it will disable
48040 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
48041 enable @code{dump-excluded-mappings} (@pxref{set
48042 dump-excluded-mappings}).
48043
48044 @item -o @var{prefix}
48045 The optional argument @var{prefix} specifies the prefix to be used
48046 when composing the file names of the core dumps. The file name is
48047 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
48048 process ID of the running program being analyzed by @command{gcore}.
48049 If not specified, @var{prefix} defaults to @var{gcore}.
48050 @end table
48051 @c man end
48052
48053 @c man begin SEEALSO gcore
48054 @ifset man
48055 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48056 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48057 documentation are properly installed at your site, the command
48058
48059 @smallexample
48060 info gdb
48061 @end smallexample
48062
48063 @noindent
48064 should give you access to the complete manual.
48065
48066 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48067 Richard M. Stallman and Roland H. Pesch, July 1991.
48068 @end ifset
48069 @c man end
48070
48071 @node gdbinit man
48072 @heading gdbinit
48073
48074 @c man title gdbinit GDB initialization scripts
48075
48076 @format
48077 @c man begin SYNOPSIS gdbinit
48078 @ifset SYSTEM_GDBINIT
48079 @value{SYSTEM_GDBINIT}
48080 @end ifset
48081
48082 @ifset SYSTEM_GDBINIT_DIR
48083 @value{SYSTEM_GDBINIT_DIR}/*
48084 @end ifset
48085
48086 ~/.config/gdb/gdbinit
48087
48088 ~/.gdbinit
48089
48090 ./.gdbinit
48091 @c man end
48092 @end format
48093
48094 @c man begin DESCRIPTION gdbinit
48095 These files contain @value{GDBN} commands to automatically execute during
48096 @value{GDBN} startup. The lines of contents are canned sequences of commands,
48097 described in
48098 @ifset man
48099 the @value{GDBN} manual in node @code{Sequences}
48100 -- shell command @code{info -f gdb -n Sequences}.
48101 @end ifset
48102 @ifclear man
48103 @ref{Sequences}.
48104 @end ifclear
48105
48106 Please read more in
48107 @ifset man
48108 the @value{GDBN} manual in node @code{Startup}
48109 -- shell command @code{info -f gdb -n Startup}.
48110 @end ifset
48111 @ifclear man
48112 @ref{Startup}.
48113 @end ifclear
48114
48115 @table @env
48116 @ifset SYSTEM_GDBINIT
48117 @item @value{SYSTEM_GDBINIT}
48118 @end ifset
48119 @ifclear SYSTEM_GDBINIT
48120 @item (not enabled with @code{--with-system-gdbinit} during compilation)
48121 @end ifclear
48122 System-wide initialization file. It is executed unless user specified
48123 @value{GDBN} option @code{-nx} or @code{-n}.
48124 See more in
48125 @ifset man
48126 the @value{GDBN} manual in node @code{System-wide configuration}
48127 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
48128 @end ifset
48129 @ifset SYSTEM_GDBINIT_DIR
48130 @item @value{SYSTEM_GDBINIT_DIR}
48131 @end ifset
48132 @ifclear SYSTEM_GDBINIT_DIR
48133 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
48134 @end ifclear
48135 System-wide initialization directory. All files in this directory are
48136 executed on startup unless user specified @value{GDBN} option @code{-nx} or
48137 @code{-n}, as long as they have a recognized file extension.
48138 See more in
48139 @ifset man
48140 the @value{GDBN} manual in node @code{System-wide configuration}
48141 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
48142 @end ifset
48143 @ifclear man
48144 @ref{System-wide configuration}.
48145 @end ifclear
48146
48147 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
48148 User initialization file. It is executed unless user specified
48149 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
48150
48151 @item @file{.gdbinit}
48152 Initialization file for current directory. It may need to be enabled with
48153 @value{GDBN} security command @code{set auto-load local-gdbinit}.
48154 See more in
48155 @ifset man
48156 the @value{GDBN} manual in node @code{Init File in the Current Directory}
48157 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
48158 @end ifset
48159 @ifclear man
48160 @ref{Init File in the Current Directory}.
48161 @end ifclear
48162 @end table
48163 @c man end
48164
48165 @c man begin SEEALSO gdbinit
48166 @ifset man
48167 gdb(1), @code{info -f gdb -n Startup}
48168
48169 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48170 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48171 documentation are properly installed at your site, the command
48172
48173 @smallexample
48174 info gdb
48175 @end smallexample
48176
48177 should give you access to the complete manual.
48178
48179 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48180 Richard M. Stallman and Roland H. Pesch, July 1991.
48181 @end ifset
48182 @c man end
48183
48184 @node gdb-add-index man
48185 @heading gdb-add-index
48186 @pindex gdb-add-index
48187 @anchor{gdb-add-index}
48188
48189 @c man title gdb-add-index Add index files to speed up GDB
48190
48191 @c man begin SYNOPSIS gdb-add-index
48192 gdb-add-index @var{filename}
48193 @c man end
48194
48195 @c man begin DESCRIPTION gdb-add-index
48196 When @value{GDBN} finds a symbol file, it scans the symbols in the
48197 file in order to construct an internal symbol table. This lets most
48198 @value{GDBN} operations work quickly--at the cost of a delay early on.
48199 For large programs, this delay can be quite lengthy, so @value{GDBN}
48200 provides a way to build an index, which speeds up startup.
48201
48202 To determine whether a file contains such an index, use the command
48203 @kbd{readelf -S filename}: the index is stored in a section named
48204 @code{.gdb_index}. The index file can only be produced on systems
48205 which use ELF binaries and DWARF debug information (i.e., sections
48206 named @code{.debug_*}).
48207
48208 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
48209 in the @env{PATH} environment variable. If you want to use different
48210 versions of these programs, you can specify them through the
48211 @env{GDB} and @env{OBJDUMP} environment variables.
48212
48213 See more in
48214 @ifset man
48215 the @value{GDBN} manual in node @code{Index Files}
48216 -- shell command @kbd{info -f gdb -n "Index Files"}.
48217 @end ifset
48218 @ifclear man
48219 @ref{Index Files}.
48220 @end ifclear
48221 @c man end
48222
48223 @c man begin SEEALSO gdb-add-index
48224 @ifset man
48225 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
48226 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
48227 documentation are properly installed at your site, the command
48228
48229 @smallexample
48230 info gdb
48231 @end smallexample
48232
48233 should give you access to the complete manual.
48234
48235 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
48236 Richard M. Stallman and Roland H. Pesch, July 1991.
48237 @end ifset
48238 @c man end
48239
48240 @include gpl.texi
48241
48242 @node GNU Free Documentation License
48243 @appendix GNU Free Documentation License
48244 @include fdl.texi
48245
48246 @node Concept Index
48247 @unnumbered Concept Index
48248
48249 @printindex cp
48250
48251 @node Command and Variable Index
48252 @unnumbered Command, Variable, and Function Index
48253
48254 @printindex fn
48255
48256 @tex
48257 % I think something like @@colophon should be in texinfo. In the
48258 % meantime:
48259 \long\def\colophon{\hbox to0pt{}\vfill
48260 \centerline{The body of this manual is set in}
48261 \centerline{\fontname\tenrm,}
48262 \centerline{with headings in {\bf\fontname\tenbf}}
48263 \centerline{and examples in {\tt\fontname\tentt}.}
48264 \centerline{{\it\fontname\tenit\/},}
48265 \centerline{{\bf\fontname\tenbf}, and}
48266 \centerline{{\sl\fontname\tensl\/}}
48267 \centerline{are used for emphasis.}\vfill}
48268 \page\colophon
48269 % Blame: doc@@cygnus.com, 1991.
48270 @end tex
48271
48272 @bye